summaryrefslogtreecommitdiff
path: root/configure.in
blob: 7397bf983790f7e5cf0b7a851044127b6328a10c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
dnl Process this file with autoconf to produce a configure script.
AC_INIT()

AC_PREREQ(2.50)

AC_DEFUN(RUBY_MINGW32,
[case "$host_os" in
cygwin*)
AC_CACHE_CHECK(for mingw32 environment, rb_cv_mingw32,
[AC_TRY_CPP([
#ifndef __MINGW32__
# error
#endif
], rb_cv_mingw32=yes,rb_cv_mingw32=no)
rm -f conftest*])
test "$rb_cv_mingw32" = yes && target_os="mingw32"
  ;;
esac])

AC_DEFUN(RUBY_CPPOUTFILE,
[cppflags=$CPPFLAGS
AC_CACHE_CHECK(whether ${CPP} accepts -o, rb_cv_cppoutfile,
[CPPFLAGS='-o conftest.i'
AC_TRY_CPP([], rb_cv_cppoutfile="$CPPFLAGS", rb_cv_cppoutfile=' >conftest.i')
rm -f conftest*])
CPPOUTFILE="$rb_cv_cppoutfile"
AC_SUBST(CPPOUTFILE)
CPPFLAGS=$cppflags])

AC_DEFUN(RUBY_PROG_GNU_LD,
[AC_CACHE_CHECK(whether the linker is GNU ld, rb_cv_prog_gnu_ld,
[if `$CC --print-prog-name=ld` -v 2>&1 | grep "GNU ld" > /dev/null; then
  rb_cv_prog_gnu_ld=yes
else
  rb_cv_prog_gnu_ld=no
fi
])
GNU_LD=$rb_cv_prog_gnu_ld
AC_SUBST(GNU_LD)])

rb_version=`grep RUBY_VERSION $srcdir/version.h`
MAJOR=`expr "$rb_version" : '#define RUBY_VERSION "\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*"'`
MINOR=`expr "$rb_version" : '#define RUBY_VERSION "[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*"'`
TEENY=`expr "$rb_version" : '#define RUBY_VERSION "[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)"'`
AC_SUBST(MAJOR)
AC_SUBST(MINOR)
AC_SUBST(TEENY)
dnl checks for alternative programs
AC_ARG_WITH(gcc, [  --without-gcc           never use gcc], [
	case $withval in
	no)	: ${CC=cc}
		;;
	yes)	: ${CC=gcc}
		;;
	*)	CC=$withval
		;;
	esac])
dnl If the user switches compilers, we can't believe the cache
if test ! -z "$ac_cv_prog_CC" -a ! -z "$CC" -a "$CC" != "$ac_cv_prog_CC"
then
  AC_MSG_ERROR(cached CC is different -- throw away $cache_file
(it is also a good idea to do 'make clean' before compiling))
fi

if test "$program_prefix" = NONE; then
  program_prefix=
fi
AC_CANONICAL_TARGET

dnl checks for fat-binary
fat_binary=no
AC_ARG_ENABLE(fat-binary,
       [  --enable-fat-binary     build a NeXT/Apple Multi Architecture Binary. ],
       [fat_binary=$enableval])
 if test "$fat_binary" = yes ; then

    AC_MSG_CHECKING(target architecture)

    case "$target_os" in
    rhapsody*)
        echo -n "MacOS X Server: "
	  	if test "$TARGET_ARCHS" = "" ; then
   	        TARGET_ARCHS="ppc i386"
  		fi
	;;
    nextstep*|openstep*)
  	    echo -n "NeXTSTEP/OPENSTEP: "
	    if test "$TARGET_ARCHS" = "" ; then
	       if test `/usr/bin/arch` = "m68k" ; then
		   TARGET_ARCHS="m68k i486"
	       else # Black and Native one
		   TARGET_ARCHS="m68k `/usr/bin/arch`"
	       fi
	    fi
	# to ensure AC_HEADER_SYS_WAIT works
	AC_DEFINE(_POSIX_SOURCE)
        ;;
    macos*|darwin*)
        echo -n "MacOS X (Darwin): "
            if test "$TARGET_ARCHS" = "" ; then
                TARGET_ARCHS="ppc i386"
            fi
	;;
    esac
    # /usr/lib/arch_tool -archify_list $TARGET_ARCHS
    for archs in $TARGET_ARCHS 
    do
        ARCH_FLAG="$ARCH_FLAG -arch $archs "
        echo -n " $archs"
    done
    AC_DEFINE(NEXT_FAT_BINARY)
    echo "."
fi 

case $target_cpu in
  i?86) frame_address=yes;;
  *)    frame_address=no;;
esac
AC_ARG_ENABLE(frame-address,
       [  --enable-frame-address  use GCC __builtin_frame_address(). ],
       [frame_address=$enableval])
if test $frame_address = yes; then
    AC_DEFINE(USE_BUILTIN_FRAME_ADDRESS)
fi

AC_ARG_PROGRAM

dnl Checks for programs.

if test x"${build}" != x"${host}"; then
  AC_CHECK_TOOL(CC, gcc)
fi
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL

RUBY_PROG_GNU_LD
RUBY_CPPOUTFILE

OUTFLAG='-o '
AC_SUBST(OUTFLAG)

RUBY_MINGW32

AC_PROG_YACC
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(AR, ar)
if test -z "$AR"; then
  AC_CHECK_PROGS(AR, aal, ar)
fi

case "$target_os" in
cygwin*|mingw*)
    AC_CHECK_TOOL(NM, nm)
    AC_CHECK_TOOL(WINDRES, windres)
    AC_CHECK_TOOL(DLLWRAP, dllwrap)
    target_cpu=`echo $target_cpu | sed s/i.86/i386/`
    : ${enable_shared=yes}
    ;;
aix*)
    AC_CHECK_TOOL(NM, nm, /usr/ccs/bin/nm, /usr/ccs/bin:$PATH)
    ;;
esac

# by TOYODA Eizi <toyoda@npd.kishou.go.jp>
case "$target_os" in
hiuxmpp*)
    AC_DEFINE(__HIUX_MPP__)
    ;;
esac

AC_PROG_LN_S
AC_PROG_MAKE_SET

# checks for UNIX variants that set C preprocessor variables
AC_AIX
AC_MINIX

dnl check for large file stuff
AC_SYS_LARGEFILE

AC_CHECK_TYPES([long long, off_t])

AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 0)
AC_CHECK_SIZEOF(__int64, 0)
AC_CHECK_SIZEOF(off_t, 0)
AC_CHECK_SIZEOF(void*, 4)
AC_CHECK_SIZEOF(float, 4)
AC_CHECK_SIZEOF(double, 8)

AC_CACHE_CHECK(for prototypes, rb_cv_have_prototypes,
  [AC_TRY_COMPILE([int foo(int x) { return 0; }], [return foo(10);],
	rb_cv_have_prototypes=yes,
	rb_cv_have_prototypes=no)])
if test "$rb_cv_have_prototypes" = yes; then
  AC_DEFINE(HAVE_PROTOTYPES)
fi

AC_CACHE_CHECK(token paste string, rb_cv_tokenpaste,
  [AC_TRY_COMPILE([#define paste(a,b) a##b],
		  [int xy = 1; return paste(x,y);],
		  rb_cv_tokenpaste=ansi,
		  rb_cv_tokenpaste=knr)])
if test "$rb_cv_tokenpaste" = ansi; then
  AC_DEFINE(TOKEN_PASTE(x,y),[x##y])
else
  AC_DEFINE(TOKEN_PASTE(x,y),[x/**/y])
fi

AC_CACHE_CHECK(for variable length prototypes and stdarg.h, rb_cv_stdarg,
  [AC_TRY_COMPILE([
#include <stdarg.h>
int foo(int x, ...) {
	va_list va;
	va_start(va, x);
	va_arg(va, int);
	va_arg(va, char *);
	va_arg(va, double);
	return 0;
}
], [return foo(10, "", 3.14);],
	rb_cv_stdarg=yes,
	rb_cv_stdarg=no)])
if test "$rb_cv_stdarg" = yes; then
  AC_DEFINE(HAVE_STDARG_PROTOTYPES)
fi

AC_CACHE_CHECK([for noreturn], rb_cv_noreturn,
[rb_cv_noreturn=no
for mac in "x __attribute__ ((noreturn))" "__declspec(noreturn) x" x; do
  AC_TRY_COMPILE(
    [#define NORETURN(x) $mac
NORETURN(void exit(int x));],
    [],
    [rb_cv_noreturn="$mac"; break])
done])
AC_DEFINE_UNQUOTED([NORETURN(x)], $rb_cv_noreturn)

dnl Check whether we need to define sys_nerr locally
AC_CHECK_DECLS([sys_nerr], [], [], [$ac_includes_default
#include <errno.h>])

dnl whether link libc_r or not
AC_ARG_WITH(libc_r, 
	[  --with-libc_r           link libc_r if possible (FreeBSD only)], [
	case $withval in
	yes) with_libc_r=yes;;
	*)   with_libc_r=no;;
	esac], [with_libc_r=no])

dnl Checks for libraries.
case "$target_os" in
nextstep*)	;;
openstep*)	;;
rhapsody*)	;;
darwin*)	LIBS="-lobjc $LIBS";;
human*)		ac_cv_func_getpgrp_void=yes;;
beos*)		;;
cygwin*)	rb_cv_have_daylight=no
		rb_cv_need_io_flush_between_rw=no
		rb_cv_need_io_flush_before_seek=no
		ac_cv_var_tzname=no
		ac_cv_func__setjmp=no
		ac_cv_func_setitimer=no
		;;
mingw*)		LIBS="-lwsock32 -lmsvcrt $LIBS"
		rb_cv_need_io_flush_between_rw=no
		rb_cv_need_io_flush_before_seek=no
		ac_cv_header_a_out_h=no
		ac_cv_header_pwd_h=no
		ac_cv_header_utime_h=no
		ac_cv_header_sys_ioctl_h=no
		ac_cv_header_sys_param_h=no
		ac_cv_header_sys_resource_h=no
		ac_cv_header_sys_select_h=no
		ac_cv_header_sys_times_h=no
		ac_cv_func_times=yes
		ac_cv_func_waitpid=yes
		ac_cv_func_vsnprintf=yes
		ac_cv_func_seekdir=yes
		ac_cv_func_telldir=yes
		ac_cv_func_crypt=no
		;;
os2_emx*)	LIBS="-lm $LIBS"
		ac_cv_lib_dir_opendir=no;;
msdosdjgpp*)	LIBS="-lm $LIBS"
		ac_cv_func_getpgrp_void=yes;;
freebsd*)	LIBS="-lm $LIBS"
		AC_CACHE_CHECK([whether -lxpg4 has to be linked],
		  rb_cv_lib_xpg4_needed,
		  [AC_TRY_CPP([
#include <osreldate.h>
#if __FreeBSD_version < 400020 || \
   (__FreeBSD_version >= 500000 && __FreeBSD_version < 500005)
#error needs libxpg4
#endif
		   ],
		   rb_cv_lib_xpg4_needed=no,
		   rb_cv_lib_xpg4_needed=yes,
		   rb_cv_lib_xpg4_needed=yes)])
		if test "$rb_cv_lib_xpg4_needed" = yes; then
			AC_CHECK_LIB(xpg4, setlocale)
		fi
		if test "$with_libc_r" = yes; then
			AC_CACHE_CHECK([whether libc_r is supplementary to libc],
			  rb_cv_supplementary_lib_c_r,
			  [AC_TRY_CPP([
#include <osreldate.h>
#if 500016 <= __FreeBSD_version
#error libc_r is supplementary to libc
#endif
			   ],
			   rb_cv_supplementary_lib_c_r=no,
			   rb_cv_supplementary_lib_c_r=yes,
			   rb_cv_supplementary_lib_c_r=yes)])
			if test "$rb_cv_supplementary_lib_c_r" = yes; then
				MAINLIBS="-lc_r $MAINLIBS"			
			else
				MAINLIBS="-pthread $MAINLIBS"			
				CFLAGS="-D_THREAD_SAFE $CFLAGS"
			fi
		fi
		;;
linux*)		LIBS="-lm $LIBS"
		case "$target_cpu" in
		alpha*)
		    CFLAGS="-mieee $CFLAGS" ;;
		esac ;;
osf*)		LIBS="-lm $LIBS"
		case "$target_cpu"::"$GCC" in
		alpha*::yes)
		    CFLAGS="-mieee $CFLAGS" ;;
		alpha*::no|alpha*::)
		    CFLAGS="-ieee $CFLAGS" ;;
		esac ;;
*) LIBS="-lm $LIBS";;
esac
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(dl, dlopen)	# Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load)	# Dynamic linking for HP-UX

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
		 fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
		 syscall.h pwd.h a.out.h utime.h memory.h direct.h sys/resource.h \
		 sys/mkdev.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_BLKSIZE
AC_STRUCT_ST_BLOCKS
AC_STRUCT_ST_RDEV

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL
AC_FUNC_ALLOCA
AC_FUNC_MEMCMP
AC_FUNC_FSEEKO
AC_CHECK_FUNCS(ftello)
AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\
		 strchr strstr strtoul crypt flock vsnprintf\
		 isinf isnan finite hypot acosh)
AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync\
	      truncate chsize times utimes fcntl lockf lstat symlink readlink\
	      setitimer setruid seteuid setreuid setresuid setproctitle\
	      setrgid setegid setregid setresgid pause lchown lchmod\
	      getpgrp setpgrp getpgid setpgid getgroups getpriority getrlimit\
	      dlopen sigprocmask sigaction _setjmp setsid telldir seekdir fchmod\
	      mktime timegm cosh sinh tanh)
AC_STRUCT_TIMEZONE
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
  [AC_TRY_COMPILE([#include <time.h>],
    [struct tm t; t.tm_gmtoff = 3600;],
  [rb_cv_member_struct_tm_tm_gmtoff=yes],
  [rb_cv_member_struct_tm_tm_gmtoff=no])])
if test "$rb_cv_member_struct_tm_tm_gmtoff" = yes; then
  AC_DEFINE(HAVE_STRUCT_TM_TM_GMTOFF)
fi
AC_CACHE_CHECK(for external int daylight, rb_cv_have_daylight,
  [AC_TRY_LINK([#include <time.h>
  int i;],
  	[i = daylight;],
	rb_cv_have_daylight=yes,
	rb_cv_have_daylight=no)])
if test "$rb_cv_have_daylight" = yes; then
  AC_DEFINE(HAVE_DAYLIGHT)
fi
AC_CACHE_CHECK(for negative time_t for gmtime(3), rb_cv_negative_time_t,
  [AC_TRY_RUN([
#include <time.h>

void
check(tm, y, m, d, h, s)
    struct tm *tm;
    int y, m, d, h, s;
{
    if (!tm ||
	tm->tm_year != y ||
	tm->tm_mon  != m-1 ||
	tm->tm_mday != d ||
	tm->tm_hour != h ||
	tm->tm_sec  != s) {
	exit(1);
    }
}

int
main()
{
   time_t t = -1;
   struct tm *tm;

   check(gmtime(&t), 69, 12, 31, 23, 59);
   t = ~(time_t)0 << 31;
   check(gmtime(&t), 1, 12, 13, 20, 52);
   return 0;
}
],
	rb_cv_negative_time_t=yes,
	rb_cv_negative_time_t=no,
	rb_cv_negative_time_t=yes)])
if test "$rb_cv_negative_time_t" = yes; then
  AC_DEFINE(NEGATIVE_TIME_T)
fi

if test "$ac_cv_func_sigprocmask" = yes && test "$ac_cv_func_sigaction" = yes; then
   AC_DEFINE(POSIX_SIGNAL)
else
  AC_CACHE_CHECK(for BSD signal semantics, rb_cv_bsd_signal,
    [AC_TRY_RUN([
#include <stdio.h>
#include <signal.h>

void
sig_handler(dummy)
     int dummy;
{
}

int
main()
{
  signal(SIGINT, sig_handler);
  kill(getpid(), SIGINT);
  kill(getpid(), SIGINT);
  return 0;
}
],
	rb_cv_bsd_signal=yes,
	rb_cv_bsd_signal=no,
	rb_cv_bsd_signal=no)])
  if test "$rb_cv_bsd_signal" = yes; then
    AC_DEFINE(BSD_SIGNAL)
  fi
fi

AC_FUNC_GETPGRP
AC_FUNC_SETPGRP  

AC_C_BIGENDIAN
AC_C_CONST
AC_C_CHAR_UNSIGNED
AC_C_INLINE

AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
    [AC_TRY_RUN([
int
main()
{
  if (-1==(-1>>1))
    return 0;
  return 1;
}
],
	rb_cv_rshift_sign=yes,
	rb_cv_rshift_sign=no,
	rb_cv_rshift_sign=yes)])
if test "$rb_cv_rshift_sign" = yes; then
  AC_DEFINE(RSHIFT(x,y), ((x)>>(int)y))
else
  AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>y) : (x)>>y))
fi

AC_MSG_CHECKING(read count field in FILE structures)
AC_CACHE_VAL(rb_cv_fcnt,
[for fcnt in	dnl
     _cnt	dnl
     __cnt	dnl
     _r		dnl
     readCount	dnl
     _rcount	dnl for emx0.9c
; do
    AC_TRY_COMPILE([#include <stdio.h>
],
	[FILE *f = stdin; f->$fcnt = 0;],
	rb_cv_fcnt="$fcnt"; break,
	rb_cv_fcnt="not found")
done])
if test "$rb_cv_fcnt" = "not found"; then
  AC_MSG_RESULT([not found(OK if using GNU libc)])
else
  AC_MSG_RESULT($rb_cv_fcnt)
  AC_DEFINE_UNQUOTED(FILE_COUNT, $rb_cv_fcnt)
fi

AC_MSG_CHECKING(read buffer ptr field in FILE structures)
AC_CACHE_VAL(rb_cv_frptr,
[for frptr in	dnl
     _IO_read_ptr dnl
     _ptr	dnl
     __ptr	dnl
     bufpos	dnl
     _p	dnl
; do
    AC_TRY_COMPILE([#include <stdio.h>
],
	[FILE *f = stdin; char buf[256]; f->$frptr = buf;],
	rb_cv_frptr="$frptr"; break,
	rb_cv_frptr="not found")
done])
if test "$rb_cv_frptr" = "not found"; then
  AC_MSG_RESULT([not found])
else
  AC_MSG_RESULT($rb_cv_frptr)
  AC_DEFINE_UNQUOTED(FILE_READPTR, $rb_cv_frptr)

  if test "$rb_cv_fcnt" = "not found"; then
    AC_MSG_CHECKING(read buffer end field in FILE structures)
    AC_CACHE_VAL(rb_cv_frend,
    [for frend in	dnl
         _IO_read_end	dnl
         bufread 	dnl
    ; do
        AC_TRY_COMPILE([#include <stdio.h>
    ],
  	[FILE *f = stdin; char buf[256]; f->$frend = buf;],
  	rb_cv_frend="$frend"; break,
  	rb_cv_frend="not found")
    done])
    if test "$rb_cv_frend" = "not found"; then
      AC_MSG_RESULT([not found])
    else
      AC_MSG_RESULT($rb_cv_frend)
      AC_DEFINE_UNQUOTED(FILE_READEND, $rb_cv_frend)
    fi
  fi
fi

AC_DEFUN(RUBY_CHECK_IO_NEED_FLUSH,
[AC_CACHE_CHECK(whether need to flush [$1], [$2],
    [AC_TRY_RUN([
#include <stdio.h>

char *fn = "conftest.dat";
char *wombat = "wombat\n";
char *koara = "koara\n";

int main()
{
    char buf[BUFSIZ];
    FILE *f;
    int r = 1;

    if (!(f = fopen(fn, "w+"))) return 1;
    fputs(wombat, f);
    fflush(f);
    fseek(f, 0, 0);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    ]ifelse(index($2,between_rw),-1,fflush(f);)[
    fputs(koara, f);
    ]ifelse(index($2,before_seek),-1,fflush(f);)[
    fseek(f, 0, 0);
    ]ifelse(index($2,between_rw),-1,fflush(f);)[
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara)) goto fail;
    r = 0;
  fail:
    fclose(f);
    unlink(fn);
    return r;
}
], [$2]=no, [$2]=yes, [$2]=yes)])])

RUBY_CHECK_IO_NEED_FLUSH(between R/W, rb_cv_need_io_flush_between_rw)
RUBY_CHECK_IO_NEED_FLUSH(before seek, rb_cv_need_io_flush_before_seek)
if test "$rb_cv_need_io_flush_between_rw" = yes; then
  AC_DEFINE(NEED_IO_FLUSH_BETWEEN_RW, 1)
fi
if test "$rb_cv_need_io_flush_before_seek" = yes; then
  AC_DEFINE(NEED_IO_FLUSH_BEFORE_SEEK, 1)
fi

dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE"

AC_ARG_WITH(default-kcode, 
	[  --with-default-kcode=CODE specify default value for \$KCODE (utf8|euc|sjis|none)], 
	[case $withval in
	utf8) DEFAULT_KCODE="KCODE_UTF8";;
	euc)  DEFAULT_KCODE="KCODE_EUC";;
	sjis) DEFAULT_KCODE="KCODE_SJIS";;
	none) DEFAULT_KCODE="KCODE_NONE";;
        *)    AC_MSG_WARN($withval is not valid kcode; ignored);;
	esac])
AC_DEFINE_UNQUOTED(DEFAULT_KCODE, $DEFAULT_KCODE)

dnl wheather use dln_a_out or not
AC_ARG_WITH(dln-a-out, 
	[  --with-dln-a-out        use dln_a_out if possible], [
	case $withval in
	yes) with_dln_a_out=yes;;
	*)   with_dln_a_out=no;;
	esac], [with_dln_a_out=no])

AC_SUBST(XCFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl

AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
[AC_TRY_RUN([
/* Test for whether ELF binaries are produced */
#include <fcntl.h>
#include <stdlib.h>
main() {
	char buffer[4];
	int i=open("conftest",O_RDONLY);
	if(i==-1)
		exit(1); /* fail */
	if(read(i,&buffer[0],4)<4)
		exit(1); /* fail */
	if(buffer[0] != 127 || buffer[1] != 'E' ||
           buffer[2] != 'L' || buffer[3] != 'F')
		exit(1); /* fail */
	exit(0); /* succeed (yes, it's ELF) */
}
],
rb_cv_binary_elf=yes,
rb_cv_binary_elf=no,
rb_cv_binary_elf=yes)])

if test "$rb_cv_binary_elf" = yes; then
  AC_DEFINE(USE_ELF)
fi

case "$target_os" in
linux*)
    if test "$rb_cv_binary_elf" = no; then
	with_dln_a_out=yes
	target_os=${target_os}-a_out
    else
	LDFLAGS="-rdynamic"
    fi;;
netbsd*)
    if [[ "`$CC -dM -E - </dev/null | grep __ELF__`" != "" ]]
    then
	netbsd_elf=yes
    else
	netbsd_elf=no
    fi
    ;;
esac
LIBEXT=a

AC_SUBST(DLDFLAGS)dnl

AC_SUBST(STATIC)dnl
AC_SUBST(CCDLFLAGS)dnl
AC_SUBST(LDSHARED)dnl
AC_SUBST(DLEXT)dnl
AC_SUBST(DLEXT2)dnl
AC_SUBST(LIBEXT)dnl

STATIC=
LIBPATHFLAG=' -L%s'

if test "$with_dln_a_out" != yes; then
  rb_cv_dlopen=unknown
  AC_MSG_CHECKING(whether OS depend dynamic link works)
  if test "$GCC" = yes; then
    case "$target_os" in
    nextstep*)	;;
    openstep*)	;;
    rhapsody*)	;;
    darwin*)	CCDLFLAGS=-fno-common;;
    human*)	;;
    bsdi*)	;;
    beos*)	;;
    cygwin*)	;;
    mingw*)	;;
    netbsd*) CCDLFLAGS=-fPIC;;
    *) CCDLFLAGS=-fPIC;;
    esac
  else
    case "$target_os" in
	hpux*)		CCDLFLAGS='+z';;
	solaris*|irix*)	CCDLFLAGS='-KPIC' ;;
	sunos*)		CCDLFLAGS='-PIC' ;;
	esix*|uxpds*)   CCDLFLAGS='-KPIC' ;;
	*)		CCDLFLAGS='' ;;
    esac
  fi

  case "$target_os" in
	hpux*)		DLDFLAGS="-E"
			LDSHARED='ld -b'
			LDFLAGS="-Wl,-E"
			rb_cv_dlopen=yes;;
	solaris*) 	if test "$GCC" = yes; then
			   LDSHARED='$(CC) -Wl,-G'
			   if test "$rb_cv_prog_gnu_ld" = yes; then
	 		       LDFLAGS="-Wl,-E"
			       LDSHARED="$LDSHARED -shared"
			   fi
			else
			   LDSHARED='ld -G'
			fi
			rb_cv_dlopen=yes;;
	sunos*) 	LDSHARED='ld -assert nodefinitions'
			rb_cv_dlopen=yes;;
	irix*)		LDSHARED='ld -shared'
			rb_cv_dlopen=yes;;
	sysv4*) 	LDSHARED='ld -G'
			rb_cv_dlopen=yes;;
        nto-qnx*)       LDSHARED="qcc -shared"
                        rb_cv_dlopen=yes ;;
	esix*|uxpds*) 	LDSHARED="ld -G"
			rb_cv_dlopen=yes ;;
	osf*) 		LDSHARED="$CC -shared"
			rb_cv_dlopen=yes ;;
	linux*) 	LDSHARED="$CC -shared"
			rb_cv_dlopen=yes ;;
	gnu*)   	LDSHARED="$CC -shared"
			rb_cv_dlopen=yes
			LDFLAGS="-rdynamic" ;;
	freebsd*)       LDSHARED="$CC -shared"
			if test "$rb_cv_binary_elf" = yes; then
			    LDFLAGS="-rdynamic"
			    DLDFLAGS='-Wl,-soname,$(.TARGET)'
			else
			  test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED="ld -Bshareable"
			fi
			rb_cv_dlopen=yes ;;
	netbsd*)	LDSHARED='${CC} -shared'
			if test "$rb_cv_binary_elf" = yes; then
			    LDFLAGS="-Wl,-export-dynamic"
			    LIBPATHFLAG=' -L%1$-s -Wl,-R%1$-s'
			fi
			rb_cv_dlopen=yes ;;
	openbsd*) 	LDSHARED="ld -Bforcearchive -Bshareable"
			rb_cv_dlopen=yes ;;
	bsdi3*) 	case "$CC" in
			*shlicc*)	LDSHARED="$CC -r"
					rb_cv_dlopen=yes ;;
			esac ;;
	bsdi*)		LDSHARED="ld -shared"
			LDFLAGS='-rdynamic -Wl,-rpath,$(libdir)/ruby/$(MAJOR).$(MINOR)/i386-bsdi4.0'
			rb_cv_dlopen=yes ;;
	nextstep*)	LDSHARED='cc -r -nostdlib'
			LDFLAGS="-u libsys_s"
			DLDFLAGS="$ARCH_FLAG" 
			rb_cv_dlopen=yes ;;
	openstep*)	LDSHARED='cc -dynamic -bundle -undefined suppress'
			LDFLAGS=""
			DLDFLAGS="$ARCH_FLAG"
			rb_cv_dlopen=yes ;;
	rhapsody*)	LDSHARED='cc -dynamic -bundle -undefined suppress'
			LDFLAGS=""
			DLDFLAGS="$ARCH_FLAG"
			rb_cv_dlopen=yes ;;
	darwin*)	LDSHARED='cc -dynamic -bundle -undefined suppress -flat_namespace'
			LDFLAGS=""
			DLDFLAGS="$ARCH_FLAG"
			rb_cv_dlopen=yes ;;
	aix*)		LDSHARED='/usr/ccs/bin/ld'
			XLDFLAGS='-Wl,-bE:ruby.imp'
			DLDFLAGS='-brtl -eInit_$(TARGET) -bI:$(topdir)/ruby.imp -bM:SRE -T512 -H512 -lc'
			LDFLAGS="-brtl"
			rb_cv_dlopen=yes ;;

	human*)		DLDFLAGS=''
			LDSHARED=''
			LDFLAGS=''
			LINK_SO='ar cru $@ $(OBJS)'
			rb_cv_dlopen=yes ;;
	beos*) 		case "$target_cpu" in
			  powerpc*)
			    LDSHARED="ld -xms"
			    DLDFLAGS='-export Init_$(TARGET) -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
                            ;;
			  i586*)
			    LDSHARED="ld -shared"
			    DLDFLAGS="-L/boot/develop/lib/x86 -lbe -lroot"
			    ;;
			esac
			rb_cv_dlopen=yes ;;
	nto-qnx*)	DLDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib"
			LDSHARED='ld -Bshareable -x'
			LDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib"
			rb_cv_dlopen=yes;;
	cygwin*|mingw*)	: ${LDSHARED="${CC} -shared -s"}
			XLDFLAGS='-Wl,--stack,0x02000000'
			DLDFLAGS="${DLDFLAGS} "'$(DEFFILE)'
			rb_cv_dlopen=yes ;;
	hiuxmpp)	LDSHARED='ld -r' ;;
	*) 		LDSHARED='ld' ;;
  esac
  AC_MSG_RESULT($rb_cv_dlopen)
fi
AC_SUBST(LINK_SO)
AC_SUBST(LIBPATHFLAG)

dln_a_out_works=no
if test "$ac_cv_header_a_out_h" = yes; then
  if test "$with_dln_a_out" = yes || test "$rb_cv_dlopen" = unknown; then
    cat confdefs.h > config.h
    AC_CACHE_CHECK(whether matz's dln works, rb_cv_dln_a_out,
    [AC_TRY_COMPILE([
#define USE_DLN_A_OUT
#include "dln.c"
],
	[], 
	rb_cv_dln_a_out=yes,
	rb_cv_dln_a_out=no)])
    if test "$rb_cv_dln_a_out" = yes; then
      dln_a_out_works=yes
      AC_DEFINE(USE_DLN_A_OUT)
    fi
  fi
fi

if test "$dln_a_out_works" = yes; then
  if test "$GCC" = yes; then
    STATIC=-static
  else
    STATIC=-Bstatic
  fi
  DLEXT=so
  AC_DEFINE(DLEXT, ".so")
  CCDLFLAGS=
else
  case "$target_os" in
    hpux*)	DLEXT=sl
	 	AC_DEFINE(DLEXT, ".sl");;
    nextstep*)	DLEXT=bundle
	 	AC_DEFINE(DLEXT, ".bundle");;
    openstep*)	DLEXT=bundle
	 	AC_DEFINE(DLEXT, ".bundle");;
    rhapsody*)	DLEXT=bundle
	 	AC_DEFINE(DLEXT, ".bundle");;
    darwin*)	DLEXT=bundle
	 	AC_DEFINE(DLEXT, ".bundle");;
    os2_emx*)	DLEXT=dll
	 	AC_DEFINE(DLEXT, ".dll");;
    cygwin*|mingw*)	DLEXT=so
	 	AC_DEFINE(DLEXT, ".so")
		DLEXT2=dll
	 	AC_DEFINE(DLEXT2, ".dll");;
    *)		DLEXT=so
    		AC_DEFINE(DLEXT, ".so");;
  esac
fi

AC_SUBST(STRIP)dnl
if test "$with_dln_a_out" = yes; then
  STRIP=true
else
  STRIP=strip
fi

case "$target_os" in
  linux*)
	STRIP='strip -S -x';;
  gnu*)
	STRIP='strip -S -x';;
  nextstep*)
	STRIP='strip -A -n';;
  openstep*)
	STRIP='strip -A -n';;
  rhapsody*)
	STRIP='strip -A -n';;
  darwin*)
	STRIP='strip -A -n';;
esac

EXTSTATIC=
AC_SUBST(EXTSTATIC)dnl
AC_ARG_WITH(static-linked-ext,
	    [  --with-static-linked-ext link external modules statically],
            [case $withval in
	     yes) STATIC=
		  EXTSTATIC=static;;
	     *)	;;
	     esac])

case "$target_os" in
  human*)
    AC_CHECK_LIB(signal, _harderr)
    AC_CHECK_LIB(hmem, hmemset)
    AC_CHECK_FUNCS(select gettimeofday)
    AC_CACHE_CHECK(whether PD libc _dtos18 fail to convert big number,
		   rb_cv_missing__dtos18,
    [AC_TRY_RUN(
changequote(<<, >>)dnl
<<
#include <stdio.h>
main ()
{
   char buf[256];
   sprintf (buf, "%g", 1e+300);
   exit (strcmp (buf, "1e+300") ? 0 : 1);
}
>>,
changequote([, ])dnl
rb_cv_missing__dtos18=yes, rb_cv_missing__dtos18=no, rb_cv_missing__dtos18=no)])
    if test "$rb_cv_missing__dtos18" = yes; then
      AC_DEFINE(MISSING__DTOS18)
    fi
    AC_CACHE_CHECK(whether PD libc fconvert fail to round,
		   rb_cv_missing_fconvert,
    [AC_TRY_RUN(
changequote(<<, >>)dnl
<<
#include <stdio.h>
#include <math.h>
main ()
{
  char buf[256];
  sprintf (buf, "%f", log(exp(1.0)));
  exit (strcmp (buf, "1.000000") ? 0 : 1);
}
>>,
changequote([, ])dnl
rb_cv_missing_fconvert=yes, rb_cv_missing_fconvert=no, rb_cv_missing_fconvert=no)])
    if test "$rb_cv_missing_fconvert" = yes; then
      AC_DEFINE(MISSING_FCONVERT)
    fi
    AC_LIBOBJ([x68.o])
    CFLAGS="$CFLAGS -fansi-only"
    XCFLAGS="-cc1-stack=262144 -cpp-stack=2694144"
    EXEEXT=.x
    OBJEXT=o
    setup=Setup.x68
    ;;
  dnl OS/2 environment w/ Autoconf 2.1x for EMX
  os2_emx)
    AC_LIBOBJ([os2])
    setup=Setup.emx
    ;;
  *djgpp*)
    setup=Setup.dj
    ;;
  atheos*)
    setup=Setup.atheos
    ;;
  *)
    setup=Setup
    ;;
esac

AC_SUBST(setup)

if test "$prefix" = NONE; then
  prefix=$ac_default_prefix
fi

if test "$fat_binary" = yes ; then
  XCFLAGS="$ARCH_FLAG"
fi

if test x"$cross_compiling" = xyes; then
  MINIRUBY="${RUBY-ruby} -I`pwd` -rfake"
  PREP=fake.rb
else
  MINIRUBY='./miniruby$(EXEEXT)'
  PREP=''
fi
AC_SUBST(MINIRUBY)
AC_SUBST(PREP)

FIRSTMAKEFILE=""
LIBRUBY_A='lib$(RUBY_INSTALL_NAME).a'
LIBRUBY='$(LIBRUBY_A)'
LIBRUBYARG='-l$(RUBY_INSTALL_NAME)'
SOLIBS=

case "$target_os" in
  cygwin*|mingw*|beos*|openstep*|nextstep*|rhapsody*|darwin*|os2_emx*)
    DLDLIBS=""
    ;;
  *)
    DLDLIBS="-lc"
    ;;
esac

RUBY_SO_NAME='$(RUBY_INSTALL_NAME)'
LIBRUBY_LDSHARED=$LDSHARED
LIBRUBY_DLDFLAGS=$DLDFLAGS
LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so'
ENABLE_SHARED=no

AC_ARG_ENABLE(shared,
       [  --enable-shared         build a shared library for Ruby. ],
       [enable_shared=$enableval])
if test "$enable_shared" = 'yes'; then
  LIBRUBY='$(LIBRUBY_SO)'
  LIBRUBYARG='-l$(RUBY_SO_NAME)'
  CFLAGS="$CFLAGS $CCDLFLAGS"
  ENABLE_SHARED=yes
  if test "$rb_cv_binary_elf" = yes; then
    SOLIBS='$(LIBS)'
  fi
  case "$target_os" in
    sunos4*)
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).so'
	;;
    linux*)
	LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR)'
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).so'
	;;
    gnu*)
	LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR)'
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).so'
	;;
    freebsd*)
	SOLIBS='$(LIBS)'
	LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR)'
	if test "$rb_cv_binary_elf" != "yes" ; then
	    LIBRUBY_SO="$LIBRUBY_SO.\$(TEENY)"
	    LIBRUBY_ALIASES=''
	fi
	;;
    netbsd*)
	SOLIBS='$(LIBS)'
	LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR).$(TEENY)'
	LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR)'
	LIBRUBYARG='-Wl,-R -Wl,${libdir} -L${libdir} -L. -l$(RUBY_SO_NAME)'
	if test "$rb_cv_binary_elf" = yes; then # ELF platforms
	   LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR) lib$(RUBY_SO_NAME).so'
	else	# a.out platforms
	   LIBRUBY_ALIASES=""
	fi
 	;;
    openbsd*)
	SOLIBS='$(LIBS)'
 	;;
    solaris*)
	XLDFLAGS='-R${libdir}'
 	;;
    hpux*)
	XLDFLAGS='-Wl,+s,+b,$(libdir)'
	LIBRUBY_SO='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR).$(TEENY)'
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_SO_NAME).sl'
	;;
    aix*)
	if test "$GCC" = yes; then
	    LIBRUBY_LDSHARED='$(CC) -shared'
	    LIBRUBY_DLDFLAGS='-Wl,-bE:ruby.imp'
	else
	    LIBRUBY_LDSHARED='/usr/ccs/bin/ld'
	    LIBRUBY_DLDFLAGS='-bE:ruby.imp -bM:SRE -bnoentry'
	    ARCHFILE="ruby.imp"
	fi
	LIBRUBYARG='-L${libdir} -Wl,lib$(RUBY_SO_NAME).so'
	SOLIBS='-lm -lc'
	;;
    beos*)
	case "$target_cpu" in
	powerpc*)
	    LIBRUBY_DLDFLAGS='-f ruby.exp -lnet -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
	    ;;
	esac
	;;
    darwin*)
	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib'
	LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress -flat_namespace'
	LIBRUBY_DLDFLAGS='-install_name $(libdir)/lib$(RUBY_SO_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib'
	;;
    *)
	;;
  esac
fi
XLDFLAGS="$XLDFLAGS -L."
AC_SUBST(ARCHFILE)

case "$target_os" in
    netbsd*)
    	CFLAGS="$CFLAGS -pipe"
	;;
    nextstep*)
    	CFLAGS="$CFLAGS -pipe"
	;;
    openstep*)
    	CFLAGS="$CFLAGS -pipe"
	;;
    rhapsody*)
    	CFLAGS="$CFLAGS -pipe -no-precomp"
	;;
    darwin*)
    	CFLAGS="$CFLAGS -pipe"
	;;
    os2_emx)
    	CFLAGS="$CFLAGS -DOS2"
	;;
    osf*)
	if test "$GCC" != "yes" ; then
	  # compile something small: taint.c is fine for this.
	  # the main point is the '-v' flag of 'cc'.
	  case "`cc -v -I. -c main.c -o /tmp/main.o 2>&1`" in
	  */gemc_cc*)   # we have the new DEC GEM CC
                        CFLAGS="$CFLAGS -oldc"
                        ;;
          *)            # we have the old MIPS CC
                        ;;
          esac
	  # cleanup
	  rm -f /tmp/main.o
	  CFLAGS="$CFLAGS -std"
	fi
		;;
    beos*)
	case "$target_cpu" in
	powerpc*)
	    CFLAGS="$CFLAGS -relax_pointers"
	    ;;
	esac
	;;
    cygwin*|mingw*)
	EXPORT_PREFIX=' '
	case "$target_os" in
	cygwin*)
	    RUBY_SO_NAME=$target_os-'$(RUBY_INSTALL_NAME)'${MAJOR}${MINOR}
	    AC_LIBOBJ([strftime])
	    CCDLFLAGS=-DUSEIMPORTLIB ;;
	mingw*)
	    RUBY_SO_NAME=msvcrt-'$(RUBY_INSTALL_NAME)'${MAJOR}${MINOR}
	    AC_LIBOBJ([win32])
	    COMMON_LIBS=m
	    COMMON_MACROS="WIN32_LEAN_AND_MEAN="
	    COMMON_HEADERS="windows.h winsock.h"
	    CFLAGS="-DNT -D__NO_ISOCEXT $CFLAGS"
	    CCDLFLAGS=-DIMPORT ;;
	esac
	if test x"$enable_shared" = xyes; then
	    LIBRUBY_SO='$(RUBY_SO_NAME)'.dll
	    LIBRUBY_DLDFLAGS='-Wl,--out-implib=$(LIBRUBY) $(RUBYDEF)'
	    LIBRUBY='lib$(LIBRUBY_SO).a'
	else
	    LIBRUBY_SO=dummy
	    LIBRUBY_DLDFLAGS=''
	    LIBRUBY='lib$(RUBY_SO_NAME).a'
	fi
	LIBRUBY_ALIASES=''
	LIBRUBY_A='lib$(RUBY_INSTALL_NAME)s.a'
	FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
	SOLIBS='$(LIBS)'
	;;
    *)
	;;
esac

AC_SUBST(LIBRUBY_LDSHARED)
AC_SUBST(LIBRUBY_DLDFLAGS)
AC_SUBST(RUBY_INSTALL_NAME)
AC_SUBST(rubyw_install_name)
AC_SUBST(RUBYW_INSTALL_NAME)
AC_SUBST(RUBY_SO_NAME)
AC_SUBST(LIBRUBY_A)
AC_SUBST(LIBRUBY_SO)
AC_SUBST(LIBRUBY_ALIASES)
AC_SUBST(LIBRUBY)
AC_SUBST(LIBRUBYARG)
AC_SUBST(SOLIBS)
AC_SUBST(DLDLIBS)
AC_SUBST(ENABLE_SHARED)
AC_SUBST(MAINLIBS)
AC_SUBST(COMMON_LIBS)
AC_SUBST(COMMON_MACROS)
AC_SUBST(COMMON_HEADERS)
AC_SUBST(EXPORT_PREFIX)

MAKEFILES="Makefile `echo $FIRSTMAKEFILE | sed 's/:.*//'`"
MAKEFILES="`echo $MAKEFILES`"
AC_SUBST(MAKEFILES)

ri_prefix=
test "$program_prefix" != NONE &&
  ri_prefix=$program_prefix

ri_suffix=
test "$program_suffix" != NONE &&
  ri_suffix=$program_suffix

RUBY_INSTALL_NAME="${ri_prefix}ruby${ri_suffix}"
case "$target_os" in
  cygwin*|mingw*)
    RUBYW_INSTALL_NAME="${ri_prefix}rubyw${ri_suffix}"
    rubyw_install_name="$RUBYW_INSTALL_NAME"
    ;;
esac
case "$target_os" in
  cygwin*|mingw*|*djgpp*|os2_emx*)
    RUBY_LIB_PREFIX="/lib/ruby"
    ;;
  *)
    RUBY_LIB_PREFIX="${prefix}/lib/ruby"
    ;;
esac
RUBY_LIB_PATH="${RUBY_LIB_PREFIX}/${MAJOR}.${MINOR}"

AC_ARG_WITH(sitedir,
	    [  --with-sitedir=DIR      site libraries in DIR [PREFIX/lib/ruby/site_ruby]],
            [sitedir=$withval],
            [sitedir='${prefix}/lib/ruby/site_ruby'])
SITE_DIR="`eval \"echo ${sitedir}\"`"
case "$target_os" in
  cygwin*|mingw*|*djgpp*|os2_emx*)
    RUBY_SITE_LIB_PATH="`expr "$SITE_DIR" : "$prefix\(/.*\)"`" ||
    RUBY_SITE_LIB_PATH="$SITE_DIR";;
  *)
    RUBY_SITE_LIB_PATH="$SITE_DIR";;
esac
RUBY_SITE_LIB_PATH2="${RUBY_SITE_LIB_PATH}/${MAJOR}.${MINOR}"

AC_DEFINE_UNQUOTED(RUBY_LIB, "${RUBY_LIB_PATH}")
AC_DEFINE_UNQUOTED(RUBY_SITE_LIB, "${RUBY_SITE_LIB_PATH}")
AC_DEFINE_UNQUOTED(RUBY_SITE_LIB2, "${RUBY_SITE_LIB_PATH2}")

AC_SUBST(arch)dnl
AC_SUBST(sitearch)dnl
AC_SUBST(sitedir)dnl

configure_args=$ac_configure_args
AC_SUBST(configure_args)dnl

if test "$fat_binary" = yes ; then
    arch="fat-${target_os}"

    AC_DEFINE_UNQUOTED(RUBY_THIN_ARCHLIB,
                 "${RUBY_LIB_PATH}/" __ARCHITECTURE__ "-${target_os}")

    AC_DEFINE_UNQUOTED(RUBY_SITE_THIN_ARCHLIB,
                 "${RUBY_SITE_LIB_PATH}/" __ARCHITECTURE__ "-${target_os}")
    AC_DEFINE_UNQUOTED(RUBY_PLATFORM, __ARCHITECTURE__ "-${target_os}")
else
    arch="${target_cpu}-${target_os}"
    AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "${arch}")
fi

case "$target_os" in
  mingw*) sitearch="i386-msvcrt" ;;
  *) sitearch="${arch}" ;;
esac

AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${RUBY_LIB_PATH}/${arch}")
AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${RUBY_SITE_LIB_PATH2}/${sitearch}")

AC_ARG_WITH(search-path,
		[  --with-search-path=DIR specify the additional search path],
		[search_path=$withval])
if test "$search_path" != ""; then
    AC_DEFINE_UNQUOTED(RUBY_SEARCH_PATH,"$search_path")
fi

if test -f config.h && tr -d '\015' < confdefs.h | cmp -s config.h -; then
  echo "config.h unchanged"
else
  echo "creating config.h"
  tr -d '\015' < confdefs.h > config.h
fi
: > confdefs.h

AC_CONFIG_FILES([$FIRSTMAKEFILE Makefile])
AC_OUTPUT