summaryrefslogtreecommitdiff
path: root/configure.in
blob: 502e07d60f464dec49edbfb1b51c93f5cbc6f72d (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
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
dnl Process this file with autoconf to produce a configure script.
AC_INIT()

AC_PREREQ(2.60)

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],
[AC_CACHE_CHECK(whether ${CPP} accepts -o, rb_cv_cppoutfile,
[cppflags=$CPPFLAGS
CPPFLAGS='-o conftest.i'
AC_TRY_CPP([], rb_cv_cppoutfile=yes, rb_cv_cppoutfile=no)
CPPFLAGS=$cppflags
rm -f conftest*])
if test "$rb_cv_cppoutfile" = yes; then
  CPPOUTFILE='-o conftest.i'
elif test "$rb_cv_cppoutfile" = no; then
  CPPOUTFILE='> conftest.i'
elif test -n "$rb_cv_cppoutfile"; then
  CPPOUTFILE="$rb_cv_cppoutfile"
fi
AC_SUBST(CPPOUTFILE)])

AC_DEFUN([RUBY_PROG_GNU_LD],
[AC_CACHE_CHECK(whether the linker is GNU ld, rb_cv_prog_gnu_ld,
[if `$CC $CFLAGS $CPPFLAGS $LDFLAGS --print-prog-name=ld 2>&1` -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)])

eval `sed -n 's/^#define RUBY_VERSION_\([A-Z][A-Z_0-9]*\) \([0-9][0-9]*\)/\1=\2/p' $srcdir/version.h`
for v in MAJOR MINOR TEENY; do
    if eval "test \"\$$v\" = ''"; then
	AC_MSG_ERROR(could not determine $v number from version.h)
    fi
done
AC_SUBST(MAJOR)
AC_SUBST(MINOR)
AC_SUBST(TEENY)
dnl checks for alternative programs
AC_ARG_WITH(gcc, AS_HELP_STRING([--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
AS_CASE(["$build_os"],
  [darwin11.*], [
    AS_CASE(["x$CC"],
      [xgcc-4.2|x/usr/bin/gcc-4.2], [: ${CXX=g++-4.2}],
      [xgcc|x/usr/bin/gcc],         [: ${CXX=g++}],
      [xcc|x/usr/bin/cc],           [: ${CXX=c++}],
      [xclang|x/usr/bin/clang],     [: ${CXX=clang++}])
  ])
test -z "$CC" || ac_cv_prog_CC="$CC"

if test "$program_prefix" = NONE; then
  program_prefix=
fi
AC_CANONICAL_TARGET
target_os=`echo $target_os | sed 's/linux-gnu$/linux/;s/linux-gnu/linux-/'`
ac_install_sh='' # unusable for extension libraries.

ifelse(currently,disabled, [
dnl checks for fat-binary
AC_ARG_ENABLE(fat-binary,
    AS_HELP_STRING([--enable-fat-binary=ARCHS],
                         [build an Apple/NeXT Multi Architecture Binary (MAB);
                          ARCHS is a comma-delimited list of architectures for
                          which to build; if ARCHS is omitted, then the package
                          will be built for all architectures supported by the
                          platform ("ppc" for MacOS/X and Darwin; "ppc,i386"
                          for Rhapsody; "m68k,i386,sparc" for OpenStep;
                          "m68k,i386,sparc,hppa" for NextStep); if this option
                          is disabled or omitted entirely, then the package
                          will be built only for the target platform]),
       [fat_binary=$enableval], [fat_binary=no])
if test "$fat_binary" != no; then

    AC_MSG_CHECKING([target architectures])

    # Respect TARGET_ARCHS setting from environment if available.
    if test -z "$TARGET_ARCHS"; then
	# Respect ARCH given to --enable-fat-binary if present.
	if test "$fat_binary" != yes; then
	    TARGET_ARCHS=`echo "$fat_binary" | tr ',' ' '`
	else
	    # Choose a default set of architectures based upon platform.
	    case "$target_os" in
	    darwin*)
		TARGET_ARCHS="ppc"
		;;
	    rhapsody*)
		TARGET_ARCHS="ppc i386"
		;;
	    openstep*)
		TARGET_ARCHS="m68k i386 sparc"
		;;
	    nextstep*)
		TARGET_ARCHS="m68k i386 sparc hppa"
		;;
	    *)
		TARGET_ARCHS=`arch`
	    esac
	fi
    fi

    AC_MSG_RESULT([$TARGET_ARCHS])

    # /usr/lib/arch_tool -archify_list $TARGET_ARCHS
    ARCH_FLAG=
    for archs in $TARGET_ARCHS 
    do
        ARCH_FLAG="$ARCH_FLAG -arch $archs"
    done
    AC_DEFINE(NEXT_FAT_BINARY)
fi
], [fat_binary=no])

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

threadswitch_hook=no
AC_ARG_ENABLE(macosx-unofficial-threadswitch-hook,
	AS_HELP_STRING([--enable-macosx-unofficial-threadswitch-hook],
		[enable Mac OS X unofficial thread switch hook, the use of this option is discouraged.]),
	[threadswitch_hook=$enableval])
AS_CASE($threadswitch_hook:$target_os,
[yes:darwin*], [
    AC_MSG_WARN([enabled Mac OS X unofficial thread switch hook])
    AC_DEFINE(RUBY_ENABLE_MACOSX_UNOFFICIAL_THREADSWITCH)
],
[yes:*], [
    AC_MSG_ERROR([--enable-macosx-unofficial-threadswitch-hook is valid only for Mac OS X.])
])

AC_ARG_PROGRAM

dnl Checks for programs.

if test -z "${CFLAGS+set}"; then
    orig_cflags="$cflags"
    cflags="$cflags "'${optflags} ${debugflags} ${warnflags}'
fi
if test -z "${CXXFLAGS+set}"; then
    orig_cxxflags="$cxxflags"
    cxxflags="$cxxflags "'${optflags} ${debugflags} ${warnflags}'
fi

if test x"${build}" != x"${host}"; then
  AC_CHECK_TOOL(CC, gcc)
fi
AC_PROG_CC
AC_PROG_CXX
AC_PROG_GCC_TRADITIONAL
test $ac_cv_prog_cc_g = yes && : ${debugflags=-g}
if test "$GCC" = yes; then
    linker_flag=-Wl,
    : ${optflags=-O2} ${warnflags="-Wall -Wno-parentheses -Wno-long-long"}
else
    linker_flag=
fi
test -z "${ac_env_CFLAGS_set}" -a -n "${cflags+set}" && CFLAGS="`eval echo $cflags`"
test -z "${ac_env_CXXFLAGS_set}" -a -n "${cxxflags+set}" && CXXFLAGS="`eval echo $cxxflags`"

RUBY_PROG_GNU_LD
RUBY_CPPOUTFILE

: ${OUTFLAG='-o '}
AC_SUBST(OUTFLAG)

RUBY_MINGW32

AC_PROG_YACC
if test "$YACC" = "yacc"; then
  AC_DEFINE([OLD_YACC])
fi

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

AC_CHECK_TOOL(AS, as)
ASFLAGS=$ASFLAGS
AC_SUBST(ASFLAGS)

case "$target_os" in
cygwin*|mingw*)
    AC_CHECK_TOOL(NM, nm)
    AC_CHECK_TOOL(WINDRES, windres)
    AC_CHECK_TOOL(DLLWRAP, dllwrap)
    target=`echo $target | sed "s/^$target_cpu-/-/"`
    target_alias=`echo $target_alias | sed "s/^$target_cpu-/-/"`
    target_cpu=`echo $target_cpu | sed s/i.86/i386/`
    case "$target" in (-*) target="$target_cpu${target}";; esac
    case "$target_alias" in (-*) target_alias="$target_cpu${target_alias}";; esac
    case "$target_os" in
    mingw*)
	test "$rb_cv_msvcrt" = "" && unset rb_cv_msvcrt
	AC_CHECK_TOOL(OBJDUMP, objdump)
	AC_CACHE_CHECK(for mingw32 runtime DLL, rb_cv_msvcrt, [
	AC_TRY_LINK([#include <stdio.h>],
		    [FILE* volatile f = stdin; return 0;],
		    [rb_cv_msvcrt=`$OBJDUMP -p conftest$ac_exeext |
				   tr A-Z a-z |
				   sed -n '/^[[ 	]]*dll name: \(msvc.*\)\.dll$/{s//\1/p;q;}'`],
		    [rb_cv_msvcrt=msvcrt])
	test "$rb_cv_msvcrt" = "" && rb_cv_msvcrt=msvcrt])
	AC_ARG_WITH(winsock2,
		AS_HELP_STRING([--with-winsock2], [link winsock2 (MinGW only)]), [
		case $withval in
		yes) with_winsock2=yes;;
		*)   with_winsock2=no;;
		esac], [with_winsock2=no])
	if test "$with_winsock2" = yes; then
	  AC_DEFINE(USE_WINSOCK2)
	  COMMON_HEADERS="ws2tcpip.h winsock2.h windows.h"
	else
	  COMMON_HEADERS="windows.h winsock.h"
	fi
    esac
    : ${enable_shared=yes}
    ;;
aix*)
    AC_CHECK_TOOL(NM, nm, /usr/ccs/bin/nm, /usr/ccs/bin:$PATH)
    ;;
hiuxmpp*)
    # by TOYODA Eizi <toyoda@npd.kishou.go.jp>
    AC_DEFINE(__HIUX_MPP__)
    ;;
esac

AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_MKDIR_P

# checks for UNIX variants that set C preprocessor variables
AC_USE_SYSTEM_EXTENSIONS

AC_SUBST(RM, ['rm -f'])
AC_SUBST(CP, ['cp'])
if test "x$MKDIR_P" != "x -d"; then
  MAKEDIRS="$MKDIR_P"
elif test -n "$INSTALL"; then
  MAKEDIRS="$INSTALL -d"
else
  MAKEDIRS='install -d'
fi
AC_SUBST(MAKEDIRS)

AC_MSG_CHECKING([for cd using phisical directory])
rm -fr conf$$.dir
mkdir conf$$.dir &&
(cd conf$$.dir && mkdir src build && cd src &&
$as_ln_s ../build . > /dev/null 2>&1 && cd build &&
for chdir in 'cd -P' 'PWD= cd'; do
    /bin/sh -c "$chdir ../src && echo '$chdir' > cdcmd" 2> /dev/null && break
done)
if test -e conf$$.dir/src/cdcmd; then
    read CHDIR < conf$$.dir/src/cdcmd 2> /dev/null
else
    CHDIR=cd
fi
rm -fr conf$$.dir
AC_MSG_RESULT([$CHDIR])
AC_SUBST(CHDIR)

dnl check for large file stuff
mv confdefs.h confdefs1.h
: > confdefs.h
AC_SYS_LARGEFILE
mv confdefs.h largefile.h
mv confdefs1.h confdefs.h
cat largefile.h >> confdefs.h

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_CHECK_SIZEOF(time_t, 0)

for id in pid_t gid_t uid_t; do
    AC_CHECK_TYPE($id, [typ=$id], [typ=int])
    AC_DEFINE_UNQUOTED(rb_$id, $typ)
done

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(stringization, rb_cv_stringization, [
  rb_cv_stringization=no
  for string in "#expr" '"expr"'; do
    AC_COMPILE_IFELSE([
      AC_LANG_BOOL_COMPILE_TRY([
#define STRINGIZE0(expr) $string
#define STRINGIZE(expr) STRINGIZE0(expr)
#undef real_test_for_stringization
#define test_for_stringization -.real_test_for_stringization.-
const char stringized[[]] = STRINGIZE(test_for_stringization);
], [sizeof(stringized) == 32])],
      [rb_cv_stringization="$string"; break],
      [rb_cv_stringization=no])
  done]
)
AC_DEFINE(STRINGIZE(expr),STRINGIZE0(expr))
if test x"$rb_cv_stringization" != xno -a "$rb_cv_stringization" != "#expr"; then
  AC_DEFINE_UNQUOTED(STRINGIZE0(expr),$rb_cv_stringization)
  AC_DEFINE(OLD_FASHIONED_STRINGIZATION,1)
fi

AC_CACHE_CHECK([string literal concatenation],
  rb_cv_string_literal_concatenation, [
  AC_COMPILE_IFELSE([
    AC_LANG_BOOL_COMPILE_TRY([
const char concatenated_literal[[]] = "literals" "to"
  "be" "concatenated.";
], [sizeof(concatenated_literal) == 26])],
    [rb_cv_string_literal_concatenation=yes],
    [rb_cv_string_literal_concatenation=no])]
)
if test "$rb_cv_string_literal_concatenation" = no; then
  AC_DEFINE(NO_STRING_LITERAL_CONCATENATION,1)
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_DEFUN([RUBY_FUNC_ATTRIBUTE], [dnl
m4_ifval([$2], dnl
  [AS_VAR_PUSHDEF([attrib],[$2])], dnl
  [AS_VAR_PUSHDEF([attrib],[FUNC_]AS_TR_CPP($1))] dnl
)dnl
m4_ifval([$3], dnl
  [AS_VAR_PUSHDEF([rbcv],[$3])], dnl
  [AS_VAR_PUSHDEF([rbcv],[rb_cv_func_][$1])]dnl
)dnl
AC_CACHE_CHECK(for [$1] function attribute, rbcv,
[rbcv=x
if test "${ac_c_werror_flag+set}"; then
  rb_c_werror_flag="$ac_c_werror_flag"
else
  unset rb_c_werror_flag
fi
ac_c_werror_flag=yes
for mac in "__attribute__ (($1)) x" "x __attribute__ (($1))" "__declspec($1) x" x; do
  AC_TRY_COMPILE(
    [#define ]attrib[(x) $mac
    ]attrib[(void conftest_attribute_check(void));], [],
    [rbcv="$mac"; break])
done
if test "${rb_c_werror_flag+set}"; then
  ac_c_werror_flag="$rb_c_werror_flag"
else
  unset ac_c_werror_flag
fi
])
AC_DEFINE_UNQUOTED(attrib[(x)], $rbcv)
AS_VAR_POPDEF([attrib])
AS_VAR_POPDEF([rbcv])
])

RUBY_FUNC_ATTRIBUTE(noreturn, NORETURN)
RUBY_FUNC_ATTRIBUTE(deprecated, DEPRECATED)
RUBY_FUNC_ATTRIBUTE(noinline, NOINLINE)

AC_CACHE_CHECK([for RUBY_EXTERN], rb_cv_ruby_extern,
[rb_cv_ruby_extern=no
for mac in "__attribute__((dllimport))" "__declspec(dllimport)"; do
  AC_TRY_COMPILE(
    [extern $mac void conftest(void);],
    [rb_cv_ruby_extern="extern $mac"; break])
done])
test "x$rb_cv_ruby_extern" = xno || AC_DEFINE_UNQUOTED(RUBY_EXTERN, $rb_cv_ruby_extern)

XCFLAGS="$XCFLAGS -DRUBY_EXPORT"

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, 
	AS_HELP_STRING([--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])

AC_ARG_ENABLE(pthread,
       AS_HELP_STRING([--enable-pthread], [use pthread library.]),
       [enable_pthread=$enableval], [enable_pthread=no])

AC_ARG_ENABLE(fastthread,
       AS_HELP_STRING([--disable-fastthread], [do not use the fastthread mutex]), [
	: handled by ext/thread/extconf.rb
        ])

dnl Checks for libraries.
case "$target_os" in
nextstep*)	;;
openstep*)	;;
rhapsody*)	;;
darwin*)	LIBS="-lobjc $LIBS"
		CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE"
		AC_TRY_CPP([#include <AvailabilityMacros.h>
		    #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1040
		    #error pre OS X 10.4
		    [!<===== pre OS X 10.4 =====>]
		    #endif
		    ],
		    [
		    test "x$target_cpu" = xpowerpc && ac_cv_header_ucontext_h=no
		    ],
		    [
		    AC_DEFINE(BROKEN_SETREUID, 1)
		    AC_DEFINE(BROKEN_SETREGID, 1)
		    ])
		;;
hpux*)		LIBS="-lm $LIBS"
		ac_cv_c_inline=no;;
human*)		ac_cv_func_getpgrp_void=yes
		ac_cv_func_setitimer=no
		;;
beos*)		ac_cv_func_link=no;;
cygwin*)	;;
mingw*)		if test "$with_winsock2" = yes; then
		  LIBS="-lws2_32 $LIBS"
		else
		  LIBS="-lwsock32 $LIBS"
		fi
		LIBS="-lshell32 $LIBS"
		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_time_h=no
		ac_cv_header_sys_times_h=no
		ac_cv_func_times=yes
		ac_cv_func_waitpid=yes
		ac_cv_func_fsync=yes
		ac_cv_func_vsnprintf=yes
		ac_cv_func_seekdir=yes
		ac_cv_func_telldir=yes
		ac_cv_func_isinf=yes
		ac_cv_func_isnan=yes
		ac_cv_func_finite=yes
		ac_cv_func_link=yes
		ac_cv_lib_crypt_crypt=no
		ac_cv_func_getpgrp_void=no
		ac_cv_func_setpgrp_void=yes
		ac_cv_func_memcmp_working=yes
		ac_cv_lib_dl_dlopen=no
		rb_cv_binary_elf=no
		rb_cv_negative_time_t=no
		enable_pthread=no
		ac_cv_func_fcntl=yes
		;;
os2-emx*)	LIBS="-lm $LIBS"
		ac_cv_lib_dir_opendir=no;;
msdosdjgpp*)	LIBS="-lm $LIBS"
		ac_cv_func_getpgrp_void=yes
		ac_cv_func_setitimer=no
                ac_cv_sizeof_rlim_t=4
		ac_cv_func_setrlimit=no
		;;
bsdi*)          LIBS="-lm $LIBS"
		AC_DEFINE(BROKEN_SETREUID, 1)
		AC_DEFINE(BROKEN_SETREGID, 1)
                ac_cv_sizeof_rlim_t=8;;
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"
			fi
		fi
		;;
dragonfly*)	LIBS="-lm $LIBS"
		;;
bow)		ac_cv_func_setitimer=no
		;;
superux*)     ac_cv_func_setitimer=no
              ;;
solaris*2.1*) if test -z "$GCC"; then
	           ac_cv_func_isinf=yes
              fi
              LIBS="-lm $LIBS"
              ;;
*) 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
AC_CHECK_LIB(rt, clock_gettime)	# GNU/Linux

AS_CASE(["$target_cpu"],
[alpha*|sh4|sh4el|sh4eb], [AS_CASE(["$target_os"::"$GCC"],
		[*::yes],  # gcc
			[CFLAGS="-mieee $CFLAGS"],
		[osf*],    # ccc
			[CFLAGS="-ieee $CFLAGS"],
		)])

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 sys/syscall.h\
		 fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h sys/param.h\
		 syscall.h pwd.h grp.h a.out.h utime.h memory.h direct.h sys/resource.h \
		 sys/mkdev.h sys/utime.h netinet/in_systm.h float.h ieeefp.h \
		 intrinsics.h time.h)

dnl Check additional types.
AC_CHECK_SIZEOF(rlim_t, 0, [
  #ifdef HAVE_SYS_TYPES_H
  # include <sys/types.h>
  #endif
  #ifdef HAVE_SYS_TIME_H
  # include <sys/time.h>
  #endif
  #ifdef HAVE_SYS_RESOURCE_H
  # include <sys/resource.h>
  #endif
  #ifdef HAVE_UNISTD_H
  # include <unistd.h>
  #endif
  #include <stdio.h>
])

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

AC_CHECK_TYPES([struct timezone], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@ include <sys/time.h>
@%:@endif])

dnl RUBY_DEFINT TYPENAME, SIZE, [SIGNED-OR-UNSIGNED], [INCLUDES = DEFAULT-INCLUDES]
AC_DEFUN([RUBY_DEFINT], [dnl
AC_CACHE_CHECK([for $1], [rb_cv_type_$1],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])
typedef $1 t; int s = sizeof(t) == 42;])],
   [rb_cv_type_$1=yes],
   [AS_CASE([m4_bmatch([$2], [^[1-9][0-9]*$], $2, [$ac_cv_sizeof_]AS_TR_SH($2))],
    ["1"], [ rb_cv_type_$1="m4_if([$3], [], [signed ], [$3 ])char"],
    ["$ac_cv_sizeof_short"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])short"],
    ["$ac_cv_sizeof_int"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])int"],
    ["$ac_cv_sizeof_long"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])long"],
    ["$ac_cv_sizeof_long_long"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])long long"],
    ["$ac_cv_sizeof___int64"], [ rb_cv_type_$1="m4_if([$3], [], [], [$3 ])__int64"],
    [ rb_cv_type_$1=no])])])
if test "${rb_cv_type_$1}" != no; then
    AC_DEFINE([HAVE_]AS_TR_CPP($1), 1)
    if test "${rb_cv_type_$1}" = yes; then
        m4_bmatch([$2], [^[1-9][0-9]*$], [AC_CHECK_SIZEOF([$1], 0, [AC_INCLUDES_DEFAULT([$4])])],
                        [RUBY_CHECK_SIZEOF([$1], [$2], [], [AC_INCLUDES_DEFAULT([$4])])])
    else
        AC_DEFINE_UNQUOTED($1, [$rb_cv_type_$1])
        AC_DEFINE_UNQUOTED([SIZEOF_]AS_TR_CPP($1), [SIZEOF_]AS_TR_CPP([$rb_cv_type_$1]))
    fi
fi
])

RUBY_DEFINT(int8_t, 1)
RUBY_DEFINT(uint8_t, 1, unsigned)
RUBY_DEFINT(int16_t, 2)
RUBY_DEFINT(uint16_t, 2, unsigned)
RUBY_DEFINT(int32_t, 4)
RUBY_DEFINT(uint32_t, 4, unsigned)
RUBY_DEFINT(int64_t, 8)
RUBY_DEFINT(uint64_t, 8, unsigned)
RUBY_DEFINT(int128_t, 16)
RUBY_DEFINT(uint128_t, 16, unsigned)

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL
case "${target_cpu}-${target_os}" in
powerpc-darwin*)
  AC_LIBSOURCES(alloca.c)
  AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
  AC_DEFINE(C_ALLOCA)
  AC_DEFINE_UNQUOTED(alloca, alloca)
  ;;
*)
  AC_FUNC_ALLOCA
  ;;
esac
AC_FUNC_MEMCMP
AC_FUNC_FSEEKO
AC_CHECK_FUNCS(ftello)

# http://sources.redhat.com/ml/libc-hacker/2005-08/msg00008.html
# Debian GNU/Linux Etch's libc6.1 2.3.6.ds1-13etch5 has this problem.
# Debian GNU/Linux Lenny's libc6.1 2.7-10 has no problem.
AC_CACHE_CHECK(for broken erfc of glibc-2.3.6 on IA64, rb_cv_broken_glibc_ia64_erfc,
  [AC_TRY_RUN([
#include <math.h>
int
main()
{
   erfc(10000.0);
   return 0;
}
],
	rb_cv_broken_glibc_ia64_erfc=no,
	rb_cv_broken_glibc_ia64_erfc=yes,
	rb_cv_broken_glibc_ia64_erfc=no)])
case $rb_cv_broken_glibc_ia64_erfc in
  yes) ac_cv_func_erf=no;;
esac

AC_REPLACE_FUNCS(dup2 memmove strcasecmp strncasecmp strerror strftime\
		 strchr strstr strtoul crypt flock vsnprintf\
		 isnan finite isinf hypot acosh erf)
AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync getcwd eaccess\
	      truncate ftruncate chsize times utimes fcntl lockf lstat symlink link\
	      readlink setitimer setruid seteuid setreuid setresuid\
	      setproctitle setrgid setegid setregid setresgid issetugid pause\
	      lchown lchmod getpgrp setpgrp getpgid setpgid initgroups\
	      getgroups setgroups getpriority getrlimit setrlimit sysconf\
	      dlopen sigprocmask\
	      sigaction sigsetjmp _setjmp _longjmp setsid telldir seekdir fchmod\
	      mktime timegm gettimeofday\
	      cosh sinh tanh round setuid setgid setenv unsetenv)

AC_CACHE_CHECK(for __builtin_setjmp, ac_cv_func___builtin_setjmp,
[AC_TRY_LINK([@%:@include <setjmp.h>
    jmp_buf jb; void t(v) int v; {__builtin_longjmp(jb, v);}],
    [__builtin_setjmp(jb);],
    [ac_cv_func___builtin_setjmp=yes],
    [ac_cv_func___builtin_setjmp=no])
])

test x$ac_cv_func__longjmp = xno && ac_cv_func__setjmp=no

AC_MSG_CHECKING(for setjmp type)
AC_ARG_WITH(setjmp-type, 
	AS_HELP_STRING([--with-setjmp-type], [select setjmp type]), [
	case $withval in
	__builtin_setjmp) setjmp_prefix=__builtin_;;
	_setjmp) setjmp_prefix=_;;
	sigsetjmp) setjmp_prefix=sig;;
	setjmp) setjmp_prefix=;;
	'') unset setjmp_prefix;;
	*)   AC_MSG_ERROR(invalid setjmp type: $withval);;
	esac], [unset setjmp_prefix])
if test ${setjmp_prefix+set}; then
    if test "${setjmp_prefix}" && eval test '$ac_cv_func_'${setjmp_prefix}setjmp = no; then
	AC_MSG_ERROR(${setjmp_prefix}setjmp is not available)
    fi
elif test "$ac_cv_func___builtin_setjmp" = yes; then
    setjmp_prefix=__builtin_
elif test "$ac_cv_func__setjmp" = yes; then
    setjmp_prefix=_
elif test "$ac_cv_func_sigsetjmp" = yes; then
    case $target_os in
    solaris*|cygwin*)
	setjmp_prefix=;;
    *)
	setjmp_prefix=sig;;
    esac
else
    setjmp_prefix=
fi
if test x$setjmp_prefix = xsig; then
    setjmp_sigmask=yes
else
    unset setjmp_sigmask
fi
AC_MSG_RESULT(${setjmp_prefix}setjmp)
AC_DEFINE_UNQUOTED([RUBY_SETJMP(env)], [${setjmp_prefix}setjmp(env${setjmp_sigmask+,0})])
AC_DEFINE_UNQUOTED([RUBY_LONGJMP(env,val)], [${setjmp_prefix}longjmp(env,val)])
AC_DEFINE_UNQUOTED(RUBY_JMP_BUF, ${setjmp_sigmask+${setjmp_prefix}}jmp_buf)

AC_ARG_ENABLE(setreuid,
       AS_HELP_STRING([--enable-setreuid], [use setreuid()/setregid() according to need even if obsolete.]),
       [use_setreuid=$enableval])
if test "$use_setreuid" = yes; then
    AC_DEFINE(USE_SETREUID)
    AC_DEFINE(USE_SETREGID)
fi
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_DEFUN([RUBY_CHECK_VARTYPE], [dnl
AC_CACHE_CHECK([for external $1], rb_cv_var_$1,
  [rb_cv_var_$1=no
  AC_TRY_COMPILE([
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
#endif
$2
;
const volatile void *volatile t;],
    [t = &(&$1)[0];],
    [for t in $3; do
      AC_TRY_COMPILE([
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 1
#endif
$2
;
extern $t $1;
const volatile void *volatile t;],
        [t = &(&$1)[0];],
        [rb_cv_var_$1=$t; break])
    done])])
if test "[$rb_cv_var_]$1" != no; then
  AC_DEFINE([HAVE_VAR_]m4_toupper($1))
  AC_DEFINE_UNQUOTED([TYPEOF_VAR_]m4_toupper($1), $rb_cv_var_$1)
fi])
RUBY_CHECK_VARTYPE(timezone, [@%:@include <time.h>], [long int])
RUBY_CHECK_VARTYPE(altzone, [@%:@include <time.h>], [long int])
if test "$rb_cv_var_timezone" = no; then
  AC_CHECK_FUNCS(timezone)
  if test "$ac_cv_func_timezone" = yes; then
    AC_CACHE_CHECK([whether timezone requires zero arguments], rb_cv_func_timezone_void,
      [AC_TRY_COMPILE([@%:@include <time.h>],
	[(void)timezone(0, 0);],
	[rb_cv_func_timezone_void=no],
	[rb_cv_func_timezone_void=yes])]
    )
    if test $rb_cv_func_timezone_void = yes; then
      AC_DEFINE(TIMEZONE_VOID)
    fi
  fi
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_CHECK_FUNCS(sigsetmask)
  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=$ac_cv_func_sigsetmask)])
  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_C_VOLATILE

if test x"$target_cpu" = xia64; then
    AC_LIBOBJ([ia64])
    AC_CACHE_CHECK(for __libc_ia64_register_backing_store_base,
                   rb_cv___libc_ia64_register_backing_store_base,
    [rb_cv___libc_ia64_register_backing_store_base=no
    AC_TRY_LINK(
      [extern unsigned long __libc_ia64_register_backing_store_base;],
      [unsigned long p = __libc_ia64_register_backing_store_base;
       printf("%ld\n", p);],
      [rb_cv___libc_ia64_register_backing_store_base=yes])])
    if test $rb_cv___libc_ia64_register_backing_store_base = yes; then
      AC_DEFINE(HAVE___LIBC_IA64_REGISTER_BACKING_STORE_BASE)
    fi
fi

AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
    [AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [(-1==(-1>>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
     __bufpos	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
         __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],
[AC_CACHE_CHECK(whether need to [$1], [$2],
    [AC_TRY_RUN([
#include <stdio.h>
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#define before_seek(f) ]ifelse(index($2,flush_before_seek),-1,[fflush(f)],[(f,0)])[
#define reset_rw(f) ]ifelse(index($2,seek_between_rw),-1,[do_seek(f,SEEK_CUR)],[(f,0)])[
#define do_seek(f, w) (before_seek(f), fseek(f,0,w))

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

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

    if (!(f = fopen(fn, "w+"))) return 1;
    fputs(wombat, f);
    do_seek(f, SEEK_SET);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    reset_rw(f);
    fputs(koara, f);
    fputs(kangaroo, f);
    do_seek(f, SEEK_SET);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
    do_seek(f, SEEK_SET);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    reset_rw(f);
    fputc('X', f);
    reset_rw(f);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara+1)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
    do_seek(f, SEEK_SET);
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || buf[0] != 'X' || strcmp(buf+1, koara+1)) goto fail;
    if (!fgets(buf, BUFSIZ, f) || strcmp(buf, kangaroo)) goto fail;
    r = 0;
  fail:
    fclose(f);
    unlink(fn);
    return r;
}
], [$2]=no, [$2]=yes, [$2]=[$3])])])
RUBY_CHECK_IO_NEED(seek between R/W, rb_cv_need_io_seek_between_rw, yes)
if test "$rb_cv_need_io_seek_between_rw" = yes; then
  AC_DEFINE(NEED_IO_SEEK_BETWEEN_RW, 1)
fi
dnl RUBY_CHECK_IO_NEED(flush before seek, rb_cv_need_io_flush_before_seek, no)
dnl if test "$rb_cv_need_io_flush_before_seek" = yes; then
dnl   AC_DEFINE(NEED_IO_FLUSH_BEFORE_SEEK, 1)
dnl fi

AC_CACHE_CHECK([whether st_ino is huge], rb_cv_huge_st_ino,
[AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([
#include <sys/stat.h>
struct stat test_stat;
], [sizeof(test_stat.st_ino)>sizeof(long)])],
rb_cv_huge_st_ino=yes,
rb_cv_huge_st_ino=no)
])
if test $rb_cv_huge_st_ino = yes; then
  AC_DEFINE(HUGE_ST_INO)
fi

if test "$ac_cv_func_sysconf" = yes; then
  AC_DEFUN([RUBY_CHECK_SYSCONF], [dnl
  AC_CACHE_CHECK([whether _SC_$1 is supported], rb_cv_have_sc_[]m4_tolower($1),
    [AC_TRY_COMPILE([#include <unistd.h>
      ],
      [_SC_$1 >= 0],
      rb_cv_have_sc_[]m4_tolower($1)=yes,
      rb_cv_have_sc_[]m4_tolower($1)=no)
    ])
  if test "$rb_cv_have_sc_[]m4_tolower($1)" = yes; then
    AC_DEFINE(HAVE__SC_$1)
  fi
  ])
  RUBY_CHECK_SYSCONF(CLK_TCK)
fi

case "$target_cpu" in
m68*|i?86|ia64|sparc*|alpha*) rb_cv_stack_grow_dir=-1;;
hppa*) rb_cv_stack_grow_dir=+1;;
esac
AC_CACHE_CHECK(stack growing direction, rb_cv_stack_grow_dir,
  [AC_TRY_RUN([
/* recurse to get rid of inlining */
static int
stack_growup_p(addr, n)
    volatile int *addr, n;
{
    volatile int end;
    if (n > 0)
	return *addr = stack_growup_p(addr, n - 1);
    else
	return (&end > addr);
}
int main()
{
    int x;
    return stack_growup_p(&x, 10);
}
], rb_cv_stack_grow_dir=-1, rb_cv_stack_grow_dir=+1, rb_cv_stack_grow_dir=0)])
AC_DEFINE_UNQUOTED(STACK_GROW_DIRECTION, $rb_cv_stack_grow_dir)

if test x"$enable_pthread" = xyes; then
    AC_CHECK_HEADERS([pthread.h])
    for pthread_lib in pthread pthreads c c_r; do
	AC_CHECK_LIB($pthread_lib, pthread_kill,
		     rb_with_pthread=yes, rb_with_pthread=no)
	if test "$rb_with_pthread" = "yes"; then break; fi
    done
    if test x"$rb_with_pthread" = xyes; then
	AC_DEFINE(_REENTRANT)
	AC_DEFINE(_THREAD_SAFE)
	AC_DEFINE(HAVE_LIBPTHREAD)
	case $pthread_lib in
	c)
	    ;;
	c_r)
	    MAINLIBS="-pthread $MAINLIBS"
	    ;;
	*)
	    LIBS="-l$pthread_lib $LIBS"
	    ;;
	esac
    else
	AC_MSG_WARN("Don't know how to find pthread library on your system -- thread support disabled")
    fi
    AC_CHECK_FUNCS(nanosleep)
    if test x"$ac_cv_func_nanosleep" = xno; then
       AC_CHECK_LIB(rt, nanosleep)
       if test x"$ac_cv_lib_rt_nanosleep" = xyes; then
           AC_DEFINE(HAVE_NANOSLEEP)
       fi
    fi
fi

use_context=no
if test x"$rb_with_pthread" = xyes; then
    AS_CASE("$target_cpu:$target_os:$cross_compiling",
    [*:linux*:no], [
        if test -n "`(/lib/libc.so.6 2>/dev/null | fgrep 'linuxthreads') 2> /dev/null`"; then
	    use_context=yes
	fi
    ],
    [sparc*], [
    	use_context=yes
    ])
fi
if test x"$use_context" = xyes; then
    AC_CHECK_HEADERS(ucontext.h)
    if test x"$ac_cv_header_ucontext_h" = xyes; then
	AC_CHECK_FUNCS(getcontext setcontext)
    fi
fi

dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE"

AC_ARG_WITH(default-kcode, 
	AS_HELP_STRING([--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, 
	AS_HELP_STRING([--with-dln-a-out], [use dln_a_out if possible]), [
	case $withval in
	dnl (
	yes)
	    if test "$enable_shared" = yes; then
		AC_MSG_ERROR(dln_a_out can not make shared library)
	    fi
	    with_dln_a_out=yes;;
	dnl (
	*)   with_dln_a_out=no;;
	esac], [with_dln_a_out=no])

AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
[AC_TRY_LINK([],[], [
case "`head -1 conftest$EXEEXT | cat -e`" in
dnl (
'^?ELF'*)
    rb_cv_binary_elf=yes;;
dnl (
*)
    rb_cv_binary_elf=no;;
esac],
rb_cv_binary_elf=no)])

if test "$rb_cv_binary_elf" = yes; then
  AC_DEFINE(USE_ELF)
  if test "$with_dln_a_out" = yes; then
    AC_MSG_ERROR(dln_a_out does not work with ELF)
  fi
fi

case "$target_os" in
linux* | gnu* | k*bsd*-gnu | bsdi*)
    if test "$rb_cv_binary_elf" = no; then
	with_dln_a_out=yes
    else
	LDFLAGS="$LDFLAGS -rdynamic"
    fi;;
esac
LIBEXT=a

AC_SUBST(DLDFLAGS)dnl
AC_SUBST(ARCH_FLAG)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=
: ${PATHFLAG=''}

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*)	CCDLFLAGS="$CCDLFLAGS -fno-common";;
    openstep*)	CCDLFLAGS="$CCDLFLAGS -fno-common";;
    rhapsody*)	CCDLFLAGS="$CCDLFLAGS -fno-common";;
    darwin*)	CCDLFLAGS="$CCDLFLAGS -fno-common";;
    human*|bsdi*|beos*|cygwin*|mingw*|aix*|interix*) ;;
    *) CCDLFLAGS="$CCDLFLAGS -fPIC";;
    esac
  else
    case "$target_os" in
	hpux*)		CCDLFLAGS="$CCDLFLAGS +Z";;
	solaris*|irix*)	CCDLFLAGS="$CCDLFLAGS -KPIC" ;;
	sunos*)		CCDLFLAGS="$CCDLFLAGS -PIC" ;;
	esix*|uxpds*)   CCDLFLAGS="$CCDLFLAGS -KPIC" ;;
	*)		: ${CCDLFLAGS=""} ;;
    esac
  fi


  AC_ARG_ENABLE(rpath,
       AS_HELP_STRING([--disable-rpath], [embed run path into extension libraries.]),
       [enable_rpath=$enableval], [enable_rpath="$rb_cv_binary_elf"])
  if test "$enable_rpath" = yes; then
    RPATHFLAG=" ${linker_flag}-R%1\$-s"
  fi

  case "$target_os" in
	hpux*)		DLDFLAGS="$DLDFLAGS -E"
			: ${LDSHARED='ld -b'}
			XLDFLAGS="$XLDFLAGS -Wl,-E"
			: ${LIBPATHENV=SHLIB_PATH}
			if test "$rb_cv_prog_gnu_ld" = no; then
			    RPATHFLAG=' +b %1$-s'
			fi
			rb_cv_dlopen=yes;;
	solaris*) 	if test "$GCC" = yes; then
                          : ${LDSHARED='$(CC) -shared'}
			   if test "$rb_cv_prog_gnu_ld" = yes; then
			       LDFLAGS="$LDFLAGS -Wl,-E"
			   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="ld -shared -expect_unresolved \"*\""}
			rb_cv_dlopen=yes ;;
	bsdi3*) 	case "$CC" in
			*shlicc*)	: ${LDSHARED='$(CC) -r'}
					rb_cv_dlopen=yes ;;
			esac ;;
	linux* | gnu* | k*bsd*-gnu | netbsd* | bsdi* | minix*)
			: ${LDSHARED='$(CC) -shared'}
			if test "$rb_cv_binary_elf" = yes; then
			    LDFLAGS="$LDFLAGS -Wl,-export-dynamic"
			fi
			rb_cv_dlopen=yes ;;
	interix*) 	: ${LDSHARED='$(CC) -shared'}
			XLDFLAGS="$XLDFLAGS -Wl,-E"
			LIBPATHFLAG=" -L%1\$-s"
			rb_cv_dlopen=yes ;;
	freebsd*|dragonfly*)       : ${LDSHARED='$(CC) -shared'}
			if test "$rb_cv_binary_elf" = yes; then
			    LDFLAGS="$LDFLAGS -rdynamic"
			    DLDFLAGS="$DLDFLAGS "'-Wl,-soname,$(.TARGET)'
			else
			  test "$GCC" = yes && test "$rb_cv_prog_gnu_ld" = yes || LDSHARED="ld -Bshareable"
			fi
			rb_cv_dlopen=yes ;;
	openbsd*) 	: ${LDSHARED='$(CC) -shared $(CCDLFLAGS)'}
			if test "$rb_cv_binary_elf" = yes; then
			    LDFLAGS="$LDFLAGS -Wl,-E"
			fi
			rb_cv_dlopen=yes ;;
	nextstep*)	: ${LDSHARED='cc -r -nostdlib'}
			LDFLAGS="$LDFLAGS -u libsys_s"
			rb_cv_dlopen=yes ;;
	openstep*)	: ${LDSHARED='cc -dynamic -bundle -undefined suppress'}
			: ${LDFLAGS=""}
			rb_cv_dlopen=yes ;;
	rhapsody*)	: ${LDSHARED='cc -dynamic -bundle -undefined suppress'}
			: ${LDFLAGS=""}
			rb_cv_dlopen=yes ;;
	darwin*)	: ${LDSHARED='$(CC) -dynamic -bundle -undefined suppress -flat_namespace'}
			: ${LDFLAGS=""}
			: ${LIBPATHENV=DYLD_LIBRARY_PATH}
			# /usr/local/include is always searched for
			# some reason, but /usr/local/lib is not.
			hdr=`find /usr/local/include -name \*.h -type f | sed 's:^/usr/local/include/::;q'`
			if test -n "$hdr" && $CC -E -include "$hdr" -xc /dev/null | fgrep -q "$hdr"; then
			    $CC -print-search-dirs | grep -q '^libraries:.*:/usr/local/lib/*' ||
			    echo " $LDFLAGS " | grep -q ' -L */usr/local/lib/* ' ||
			    LDFLAGS="${LDFLAGS:+$LDFLAGS }-L/usr/local/lib"
			fi
			rb_cv_dlopen=yes ;;
        aix*)           if test "$GCC" = yes; then
			    : ${LDSHARED='$(CC) -shared'}
			else
			    : ${LDSHARED='$(CC)'}
			fi
			LDSHARED="$LDSHARED ${linker_flag}-G"
			DLDFLAGS='-eInit_$(TARGET)'
			XLDFLAGS="${linker_flag}-bE:ruby.imp ${linker_flag}-brtl"
			XLDFLAGS="$XLDFLAGS ${linker_flag}-blibpath:${prefix}/lib:${LIBPATH:-/usr/lib:/lib}"
                        : ${ARCHFILE="ruby.imp"}
                        TRY_LINK='$(CC) $(LDFLAGS) -oconftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS)'
                        TRY_LINK="$TRY_LINK"' $(CFLAGS) $(src) $(LIBPATH) $(LOCAL_LIBS) $(LIBS)'
                        : ${LIBPATHENV=SHLIB_PATH}
			RPATHFLAG=" ${linker_flag}-blibpath:%1\$-s"
                        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="$DLDFLAGS "'-export Init_$(TARGET) -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
			    LDFLAGS="$LDFLAGS -L/boot/home/config/lib -lbe -lroot"
			    ;;
			  i586*)
			    : ${LDSHARED="ld -shared"}
			    DLDFLAGS="$DLDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib \$(topdir)/_APP_ -lbe -lroot"
			    LDFLAGS="$LDFLAGS -L/boot/develop/lib/x86 -L/boot/home/config/lib -lbe -lroot"
			    ;;
			esac
			: ${LIBPATHENV=LIBRARY_PATH}
			rb_cv_dlopen=yes ;;
	nto-qnx*)	DLDFLAGS="$DLDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
			: ${LDSHARED='ld -Bshareable -x'}
			LDFLAGS="$LDFLAGS -L/lib -L/usr/lib -L/usr/local/lib"
			rb_cv_dlopen=yes;;
	cygwin*|mingw*)	: ${LDSHARED='$(CC) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)'}
			XLDFLAGS="$XLDFLAGS -Wl,--stack,0x02000000,--enable-auto-import"
			DLDFLAGS="${DLDFLAGS} -Wl,--enable-auto-image-base,--enable-auto-import,--export-all"
			: ${LIBPATHENV=""}
			rb_cv_dlopen=yes ;;
	hiuxmpp)	: ${LDSHARED='ld -r'} ;;
	atheos*) 	: ${LDSHARED='$(CC) -shared'}
			rb_cv_dlopen=yes ;;
	os2-emx*)	LDFLAGS="$LDFLAGS -Zomf"
			;;
	*) 		: ${LDSHARED='ld'} ;;
  esac
  AC_MSG_RESULT($rb_cv_dlopen)
fi
case " $CPP " in *" $CC "*) CPP=`echo " $CPP " | sed "s| $CC |"' $(CC) |;s/^ *//;s/  *$//'`;; esac
case ${RPATHFLAG} in
*'%1$'*)
    : ${LIBPATHFLAG=' -L%1$-s'};;
*)
    : ${LIBPATHFLAG=' -L%s'};;
esac
AC_SUBST(LINK_SO)
AC_SUBST(LIBPATHFLAG)
AC_SUBST(RPATHFLAG)
AC_SUBST(LIBPATHENV, "${LIBPATHENV-LD_LIBRARY_PATH}")
AC_SUBST(TRY_LINK)

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
  CCDLFLAGS=
else
  case "$target_os" in
    hpux*)	DLEXT=sl;;
    nextstep*|openstep*|rhapsody*|darwin*)
		DLEXT=bundle;;
    os2-emx*)	DLEXT=dll;;
    cygwin*|mingw*)
		DLEXT=so DLEXT2=dll;;
    *)		DLEXT=so;;
  esac
fi
len=2 # .rb
n=`expr "$DLEXT"  : '.*'`; test "$n" -gt "$len" && len=$n
n=`expr "$DLEXT2" : '.*'`; test "$n" -gt "$len" && len=$n
AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
test ".$DLEXT"  = "." || AC_DEFINE_UNQUOTED(DLEXT,  ".$DLEXT")
test ".$DLEXT2" = "." || AC_DEFINE_UNQUOTED(DLEXT2, ".$DLEXT2")

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

AS_CASE(["$target_os"],
  [linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu], [
	STRIP="$STRIP -S -x"],
  [nextstep* | openstep* | rhapsody* | darwin*], [
	STRIP="$STRIP -A -n"])

EXTSTATIC=
AC_SUBST(EXTSTATIC)dnl
AC_ARG_WITH(static-linked-ext,
	    AS_HELP_STRING([--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)
    AC_CACHE_CHECK(whether PD libc _dtos18 fail to convert big number,
		   rb_cv_missing__dtos18,
    [AC_TRY_RUN(
changequote(<<, >>)dnl
<<
#include <stdio.h>
int
main()
{
   char buf[256];
   sprintf(buf, "%g", 1e+300);
   return (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>
int
main()
{
  char buf[256];
  sprintf(buf, "%f", log(exp(1.0)));
  return (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="$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
    ;;
  *)
    setup=Setup
    ;;
esac

AC_SUBST(setup)

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

#if test "$fat_binary" != no ; then
#  CFLAGS="$CFLAGS $ARCH_FLAG"
#fi

if test x"$cross_compiling" = xyes; then
  test x"$MINIRUBY" = x && MINIRUBY="${RUBY-ruby} -I`pwd` "-r'$(arch)-fake'
  PREP='$(arch)-fake.rb'
  RUNRUBY='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
else
  MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib'
  MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common -I./- -r$(srcdir)/ext/purelib.rb'
  PREP='miniruby$(EXEEXT)'
  RUNRUBY='$(MINIRUBY) $(srcdir)/runruby.rb --extout=$(EXTOUT)'
fi
AC_SUBST(MINIRUBY)
AC_SUBST(PREP)
AC_SUBST(RUNRUBY)
AC_SUBST(EXTOUT, [${EXTOUT-.ext}])

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

case "$target_os" in
  cygwin*|mingw*|beos*|openstep*|nextstep*|rhapsody*|darwin*|os2-emx*)
    : ${DLDLIBS=""}
    ;;
  *)
    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,
       AS_HELP_STRING([--enable-shared], [build a shared library for Ruby. ]),
       [enable_shared=$enableval])
LIBRUBYARG_SHARED='-l$(RUBY_SO_NAME)'
if test "$enable_shared" = 'yes'; then
  LIBRUBY='$(LIBRUBY_SO)'
  LIBRUBYARG='$(LIBRUBYARG_SHARED)'
  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* | gnu* | k*bsd*-gnu | atheos*)
	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*|dragonfly*)
	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*|minix*)
	SOLIBS='$(LIBS)'
	LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR).$(TEENY)'
	LIBRUBY_DLDFLAGS='-Wl,-soname,lib$(RUBY_SO_NAME).so.$(MAJOR)$(MINOR)'
	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)'
	LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).'`expr ${MINOR} \* 10 + ${TEENY}`
	;;
    solaris*)
	SOLIBS='$(LIBS)'
	LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR)'
	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY) lib$(RUBY_SO_NAME).so'
	if test "$GCC" = yes; then
	    LIBRUBY_DLDFLAGS="$DLDFLAGS "'-Wl,-h,$(@F)'
	fi
	XLDFLAGS="$XLDFLAGS "'-R${libdir}'
	;;
    hpux*)
	XLDFLAGS="$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*)
	LIBRUBY_DLDFLAGS="${linker_flag}-bnoentry $XLDFLAGS"
	LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
	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'
	;;
    interix*)
	LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
	;;
    *)
	;;
  esac
fi
if test "$enable_rpath" = yes; then
    LIBRUBY_RPATHFLAGS="${linker_flag}-R ${linker_flag}\$(libdir) -L\$(libdir)"
    LIBRUBYARG_SHARED="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_SHARED"
    LIBRUBYARG_STATIC="$LIBRUBY_RPATHFLAGS $LIBRUBYARG_STATIC"
fi

LDFLAGS="-L. $LDFLAGS"
AC_SUBST(ARCHFILE)

if test "$EXEEXT" = .exe; then
    EXECUTABLE_EXTS='".exe",".com",".cmd",".bat"'
    AC_DEFINE_UNQUOTED(EXECUTABLE_EXTS, $EXECUTABLE_EXTS)
    AC_SUBST(EXECUTABLE_EXTS)
fi

dnl build rdoc index if requested
RDOCTARGET=""
AC_ARG_ENABLE(install-doc,
       AS_HELP_STRING([--enable-install-doc], [build and install rdoc indexes during install]),
       [install_doc=$enableval], [install_doc=no])
if test "$install_doc" != no; then
    RDOCTARGET="rdoc"
else
    RDOCTARGET="nodoc"
    CAPITARGET="nodoc"
fi
AC_SUBST(RDOCTARGET)

case "$target_os" in
    linux*)
	;;
    netbsd*|minix*)
	CFLAGS="$CFLAGS -pipe"
	;;
    nextstep*|openstep*)
	# The -fno-common is needed if we wish to embed the Ruby interpreter
	# into a plugin module of some project (as opposed to embedding it
	# within the project's application).  The -I/usr/local/include is
	# needed because CPP as discovered by configure (cc -E -traditional)
	# fails to consult /usr/local/include by default.  This causes
	# mkmf.rb's have_header() to fail if the desired resource happens to be
	# installed in the /usr/local tree.
	CFLAGS="$CFLAGS -pipe"
	CPPFLAGS="$CPPFLAGS -I/usr/local/include"
	;;
    rhapsody*)
	CFLAGS="$CFLAGS -pipe -no-precomp"
	;;
    darwin*)
	CFLAGS="$CFLAGS -pipe"
	;;
    os2-emx)
    	CFLAGS="$CFLAGS -DOS2"
	LIBRUBY_A=`echo $LIBRUBY_A | sed 's/^lib//'`
	LIBRUBY_SO=`echo $LIBRUBY_SO | sed 's/^lib//'`
	LIBRUBY_ALIASES=`for i in $LIBRUBY_ALIASES; do echo "$i"; done | sed 's/^lib//'`
	;;
    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
	CPPFLAGS="$CPPFLAGS -I/boot/home/config/include"
	;;
    cygwin*|mingw*)
	case "$target_os" in
	cygwin*)
	    if test x"$enable_shared" = xyes; then
		LIBRUBY_SO='cyg$(RUBY_SO_NAME)'${MAJOR}${MINOR}.dll
		LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
	    fi
	    ;;
	mingw*)
	    RUBY_SO_NAME=${rb_cv_msvcrt}-'$(RUBY_INSTALL_NAME)'${MAJOR}${MINOR}
	    if test x"$enable_shared" = xyes; then
		LIBRUBY_SO='$(RUBY_SO_NAME)'.dll
		LIBRUBY='lib$(LIBRUBY_SO).a'
	    fi
	    AC_LIBOBJ([win32])
	    COMMON_LIBS=m
#	    COMMON_MACROS="WIN32_LEAN_AND_MEAN="
	    ;;
	esac
	LIBRUBY_DLDFLAGS="${DLDFLAGS}"' -Wl,--out-implib=$(LIBRUBY)'
	LIBRUBY_ALIASES=''
	FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
	SOLIBS='$(LIBS)'
	if test x"$enable_shared" = xno; then
	    LIBRUBY_SO=dummy
	    LIBRUBY='lib$(RUBY_SO_NAME).a'
	    LIBRUBYARG='-l$(RUBY_SO_NAME)'
	fi
	;;
    hpux*)
	case "$YACC" in
	  *yacc*)
	    XCFLAGS="$XCFLAGS -DYYMAXDEPTH=300"
	    YACC="$YACC -Nl40000 -Nm40000"
	    ;;
	esac
	;;
    *)
	;;
esac
MINIOBJS=dmydln.o

case "$build_os" in
  *msdosdjgpp*) FIRSTMAKEFILE=GNUmakefile:djgpp/GNUmakefile.in;;
esac

CPPFLAGS="$CPPFLAGS "'$(DEFS)'
test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
if test -n "${cflags+set}"; then
    cflagspat=`eval echo '"'"${cflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^  */ /;s/^  *$/ /'`
    CFLAGS=`echo " $CFLAGS " | sed "s|$cflagspat"'|${cflags}|;s/^ *//;s/ *$//'`
fi
if test -n "${cxxflags+set}"; then
    cxxflagspat=`eval echo '"'"${cxxflags}"'"' | sed 's/[[][|.*]]/\\&/g;s/^  */ /;s/^  *$/ /'`
    CXXFLAGS=`echo " $CXXFLAGS " | sed "s|$cxxflagspat"'|${cxxflags}|;s/^ *//;s/ *$//'`
fi
AC_SUBST(cppflags, [])dnl
AC_SUBST(cflags, ["$orig_cflags "'${optflags} ${debugflags} ${warnflags}'])dnl
AC_SUBST(cxxflags, ["$orig_cxxflags "'${optflags} ${debugflags} ${warnflags}'])dnl
AC_SUBST(optflags)dnl
AC_SUBST(debugflags)dnl
AC_SUBST(warnflags)dnl
AC_SUBST(XCFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl
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(LIBRUBYARG_STATIC)
AC_SUBST(LIBRUBYARG_SHARED)
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)
AC_SUBST(MINIOBJS)

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
RUBY_LIB_PREFIX=`eval echo \\"${libdir}/ruby\\"`

AC_ARG_WITH(ruby-version,
	    AS_HELP_STRING([--with-ruby-version=STR], [ruby version string for version specific directories [[minor]] (full|minor|STR)]),
            [ruby_version=$withval],
            [ruby_version=minor])
case "$ruby_version" in
  full)
    ruby_version="${MAJOR}.${MINOR}.${TEENY}"
    ;;
  minor)
    ruby_version="${MAJOR}.${MINOR}"
    ;;
esac

AC_ARG_WITH(sitedir,
	    AS_HELP_STRING([--with-sitedir=DIR], [site libraries in DIR [[LIBDIR/ruby/site_ruby]]]),
            [sitedir=$withval],
            [sitedir='${libdir}/ruby/site_ruby'])
SITE_DIR=`eval echo \\"${sitedir}\\"`

AC_ARG_WITH(vendordir,
	    AS_HELP_STRING([--with-vendordir=DIR], [vendor libraries in DIR [[LIBDIR/ruby/vendor_ruby]]]),
            [vendordir=$withval],
            [vendordir='${libdir}/ruby/vendor_ruby'])
VENDOR_DIR=`eval echo \\"${vendordir}\\"`

case "$target_os" in
  cygwin*|mingw*|*djgpp*|os2-emx*)
    RUBY_EXEC_PREFIX=""
    RUBY_LIB_PREFIX="`eval echo "$RUBY_LIB_PREFIX" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
    RUBY_SITE_LIB_PATH="`eval echo "$SITE_DIR" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
    RUBY_VENDOR_LIB_PATH="`eval echo "$VENDOR_DIR" | sed 's|^NONE/|/|;s|^'"$prefix"'/|/|'`"
    ;;
  *)
    RUBY_EXEC_PREFIX="`eval echo \\"$exec_prefix/\\" | sed 's|^NONE/|'"$prefix"'/|;s|/$||'`"
    RUBY_LIB_PREFIX="`eval echo \\"$RUBY_LIB_PREFIX\\" | sed 's|^NONE/|'"$prefix"'/|'`"
    RUBY_SITE_LIB_PATH="`eval echo \\"$SITE_DIR\\" | sed 's|^NONE/|'"$prefix"'/|'`"
    RUBY_VENDOR_LIB_PATH="`eval echo \\"$VENDOR_DIR\\" | sed 's|^NONE/|'"$prefix"'/|'`"
    ;;
esac
RUBY_LIB_PATH="${RUBY_LIB_PREFIX}/${ruby_version}"
RUBY_SITE_LIB_PATH2="${RUBY_SITE_LIB_PATH}/${ruby_version}"
RUBY_VENDOR_LIB_PATH2="${RUBY_VENDOR_LIB_PATH}/${ruby_version}"

AC_DEFINE_UNQUOTED(RUBY_EXEC_PREFIX, "${RUBY_EXEC_PREFIX}")
AC_DEFINE_UNQUOTED(RUBY_LIB_PREFIX, "${RUBY_LIB_PREFIX}")
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_DEFINE_UNQUOTED(RUBY_VENDOR_LIB, "${RUBY_VENDOR_LIB_PATH}")
AC_DEFINE_UNQUOTED(RUBY_VENDOR_LIB2, "${RUBY_VENDOR_LIB_PATH2}")

AC_SUBST(arch)dnl
AC_SUBST(sitearch)dnl
AC_SUBST(ruby_version)dnl
AC_SUBST(sitedir)dnl
AC_SUBST(vendordir)dnl

configure_args=$ac_configure_args
AC_SUBST(configure_args)dnl

if test "$fat_binary" != no ; 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_VENDOR_THIN_ARCHLIB,
                 "${RUBY_VENDOR_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="$target_cpu-$rb_cv_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_DEFINE_UNQUOTED(RUBY_VENDOR_ARCHLIB, "${RUBY_VENDOR_LIB_PATH2}/${sitearch}")

AC_ARG_WITH(search-path,
		AS_HELP_STRING([--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

AC_ARG_WITH(opt-dir,
	AS_HELP_STRING([--with-opt-dir=DIR], [add optional headers and libraries DIR]))

AC_ARG_WITH(mantype,
	AS_HELP_STRING([--with-mantype=TYPE], [specify man page type; TYPE is one of man and doc]),
		[
			case "$withval" in
			man|doc)
				MANTYPE=$withval
				;;
			*)
				AC_MSG_ERROR(invalid man type: $withval)
				;;
			esac
		])
if test -z "$MANTYPE"; then
	AC_PATH_PROGS(NROFF, nroff awf, /bin/false, "/usr/bin:/usr/ucb")
	if ${NROFF} -mdoc ${srcdir}/ruby.1 >/dev/null 2>&1; then
		MANTYPE=doc
	else
		MANTYPE=man
	fi
fi
AC_SUBST(MANTYPE)

guard=INCLUDE_RUBY_CONFIG_H
{
  echo "#ifndef $guard"
  echo "#define $guard 1"
  cat confdefs.h
  echo "#endif /* $guard */"
} | tr -d '\015' > config.h.tmp
if test -f config.h && cmp -s config.h config.h.tmp; then
  echo "config.h unchanged"
  rm config.h.tmp
else
  echo "creating config.h"
  mv config.h.tmp config.h
fi
tr -d '\015' < largefile.h > confdefs.h
rm largefile.h

AC_CONFIG_FILES($FIRSTMAKEFILE)
AC_CONFIG_FILES(Makefile, [{
	sed '/^MISSING/s/\$U\././g' Makefile
	echo; test x"$EXEEXT" = x || echo 'miniruby: miniruby$(EXEEXT)'
	test "$RUBY_INSTALL_NAME$EXEEXT" = ruby || echo 'ruby: $(PROGRAM);'
	if_no_string_literal_concatenation=""
	test "$rb_cv_string_literal_concatenation" = yes ||
	    if_no_string_literal_concatenation=';/^-IF-NO-STRING-LITERAL-CONCATENATION-:/d'
	sed ['s/{\$([^(){}]*)[^{}]*}//g'"$if_no_string_literal_concatenation"] ${srcdir}/common.mk
      } >> confmk$$.tmp && mv -f confmk$$.tmp Makefile],
[RUBY_INSTALL_NAME='$RUBY_INSTALL_NAME' EXEEXT='$EXEEXT'
 rb_cv_string_literal_concatenation='$rb_cv_string_literal_concatenation'])
AC_OUTPUT