Codebase list swi-prolog / debian/6.2.5-5 src / configure.in
debian/6.2.5-5

Tree @debian/6.2.5-5 (Download .tar.gz)

configure.in @debian/6.2.5-5raw · history · blame

   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
dnl Process this file with autoconf to produce a configure script.

AC_INIT(pl-wam.c)
AC_PREREQ([2.50])

AC_CONFIG_HEADER(config.h)
AC_SUBST(COFLAGS)
AC_SUBST(CWFLAGS)
AC_SUBST(CMFLAGS)
AC_SUBST(CIFLAGS)
AC_SUBST(AR)
AC_SUBST(MKDIR)
AC_SUBST(ETAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(PROGLDFLAGS)
AC_SUBST(STACKFLAGS)
AC_SUBST(SUBSYSTEMFLAGS)
AC_SUBST(PLBUILD)
AC_SUBST(PLBASE)
AC_SUBST(PLARCH)
AC_SUBST(INSTALL_PLARCH)
AC_SUBST(PLSHARED)
AC_SUBST(PLTHREADS)
AC_SUBST(PL)
AC_SUBST(PLVERSION)
AC_SUBST(PLLIBDIR)		dnl either @PL@-@PLVERSION@ or @PL@
AC_SUBST(VPATH)
AC_SUBST(COUTOPT)
AC_SUBST(INSTALLTARGET)
AC_SUBST(EXTRAOBJ)
AC_SUBST(BOOTFILE)
AC_SUBST(PLLIB)			dnl libswipl.a
AC_SUBST(PLSO)			dnl libswipl.so
AC_SUBST(SONAMEOPT)		dnl ld options for linking shared objects
AC_SUBST(USEPLLIB)		dnl -lswipl
AC_SUBST(LNLIBS)		dnl libs to link with Prolog
AC_SUBST(XLIBS)                 dnl libs to link with plterm
AC_SUBST(LDEXE)
AC_SUBST(EXTRAHDR)
AC_SUBST(SO_EXT)		dnl e.g., "so"
AC_SUBST(SO_LDFLAGS)		dnl e.g., "-shared"
AC_SUBST(SOLIB)
AC_SUBST(TXTEXT)
AC_SUBST(MKLIBS)		dnl system libraries to make
AC_SUBST(BUILDDIR)
AC_SUBST(CNFG)
AC_SUBST(DLLIBVAR)
AC_SUBST(RLPREFIX)
AC_SUBST(OPTIMISE)
AC_SUBST(MINGW)
AC_SUBST(WINDRES)
AC_SUBST(WINEPATHEXE)
AC_SUBST(HOST_TOOLCHAIN_FLAG)
AC_SUBST(HOST_OS_FLAG)
AC_SUBST(DEFSTARTUP)
AC_SUBST(EXEFORMAT)

if test -z "$CIFLAGS"; then
    CIFLAGS="$CPPFLAGS"
else
    CFLAGS="$CIFLAGS $CFLAGS"
    CPPFLAGS="$CIFLAGS $CPPFLAGS"
fi

if test ! -z "$COFLAGS"; then
    CFLAGS="$COFLAGS $CFLAGS"
    CPPFLAGS="$COFLAGS $CPPFLAGS"
fi

if test -z "$CIFLAGS" -a -z "$COFLAGS"; then
  if test ! -z "$CFLAGS"; then
    CIFLAGS="$CFLAGS"
  fi
fi

EXTRAOBJ=""
EXTRAHDR=""
INSTALLTARGET=dv-install
if test -z "$PL"; then PL=swipl; fi
PLLIB=libswipl.a
MKLIBS=""
PLVERSION=`cat ../VERSION`
CNFG=""				dnl Package configuration options
DEFSTARTUP=.plrc
MT=yes

dnl ****************************************************************
dnl Some systems don't appear to have true.  Hope all like this ...
dnl ****************************************************************

true()
{ test a = a
}

dnl ****************************************************************
dnl Find the build directory, needed for building the packages
dnl ****************************************************************

AC_MSG_CHECKING(builddir)
wd=`pwd`
BUILDDIR=`basename $wd`
touch conftest.unique
if test -r ../$BUILDDIR/conftest.unique; then
    AC_MSG_RESULT($BUILDDIR)
else
    AC_MSG_RESULT(no)
    BUILDDIR=src
fi
rm -f conftest.unique

AC_PROG_CC
AC_PROG_CXX		dnl used for packages
LDEXE="$CC"
AC_CANONICAL_HOST
changequote(,)dnl
if test "x$PLARCH" = "x"; then
  case "$host" in
    *linux*)
      PLARCH=`echo $host | sed 's/-.*/-linux/'`
      ;;
    i?86-*mingw32*)
      # Make PLARCH match the definition in src/config/win32.h
      PLARCH=i386-win32
      ;;
    x86_64-*mingw32*)
      # Make PLARCH match the definition in src/config/win64.h
      PLARCH=x64-win64
      ;;
    *-gnu)
      PLARCH=`echo $host | sed 's/\([^-]*\)-[^-]*-\([^-]*\)-gnu/\1-\2/'`
      ;;
    *)
      PLARCH=`echo $host | sed 's/\([^-]*\)-[^-]*-\([^-]*\)/\1-\2/'`
      ;;
  esac
fi
changequote([,])dnl

changequote(,)dnl
if test "x$PLBUILD" = "x"; then
  case "$build" in
    *linux*)
      PLBUILD=`echo $build | sed 's/-.*/-linux/'`
      ;;
    i?86-*mingw32*)
      # Make PLBUILD match the definition of PLARCH in src/config/win32.h
      PLBUILD=i386-win32
      ;;
    x86_64-*mingw32*)
      # Make PLBUILD match the definition of PLARCH in src/config/win64.h
      PLBUILD=x64-win64
      ;;
    *-gnu)
      PLBUILD=`echo $build | sed 's/\([^-]*\)-[^-]*-\([^-]*\)-gnu/\1-\2/'`
      ;;
    *)
      PLBUILD=`echo $build | sed 's/\([^-]*\)-[^-]*-\([^-]*\)/\1-\2/'`
      ;;
  esac
fi
changequote([,])dnl

# Determine the C compiler and executable suffix on the build system.
SWI_PROG_CC_FOR_BUILD
SWI_PROG_EXEEXT_FOR_BUILD

AC_ARG_ENABLE(shared, [  --enable-shared	  Prolog kernel as shared obj],
	      [case "$enableval" in
		   yes) MKSHARED=yes
			;;
		   no)  MKSHARED=no
			;;
		   *)   ;;
	       esac])

AC_ARG_ENABLE(static, [  --disable-static	  Do not install static library],
	      [case "$enableval" in
		   yes) MKSTATIC=yes
			;;
		   no)  MKSTATIC=no
			;;
		   *)   ;;
	       esac],
               MKSTATIC=yes)

if test "$MKSHARED" != yes -a "$MKSTATIC" != yes; then
  AC_MSG_ERROR("--disable-static selected without explicitly selecting --enable-shared")
fi

if test "$MKSTATIC" = yes; then
  MKLIBS=staticlib
fi

readline_ok=no
AC_ARG_ENABLE(readline, [  --disable-readline	  Do NOT include GNU readline],
	      configreadline="$enableval",
	      configreadline=yes)

AC_ARG_ENABLE(gmp, [  --disable-gmp		  Disable Multi-precision arithmetic],
	      configgmp="$enableval",
	      configgmp=yes)

AC_ARG_ENABLE(dmalloc, [  --enable-dmalloc	  Enable DMALLOC debugging],
	      dmalloc="$enableval",
	      dmalloc=no)

AC_ARG_ENABLE(boehm-gc, [  --enable-boehm-gc	  Enable using Boehm-GC],
	      boehmgc="$enableval",
	      boehmgc=no)

AC_ARG_ENABLE(useprofile, [  --enable-useprofile	  GCC: recompile with profile],
	      useprofile="$enableval",
	      useprofile=no)
AC_ARG_ENABLE(libdirversion, [  --disable-libdirversion	Do not version installation dir],
	      libdirversion="$enableval",
	      libdirversion=yes)

if test "$libdirversion" = no; then
   PLLIBDIR="$PL"
else
   PLLIBDIR="$PL-$PLVERSION"
fi

OPTIMISE=noprof


dnl ****************************************************************
dnl Setup PLBASE.  Need to expand prefix first as this isn't yet set. Yek
dnl ****************************************************************

test "x$prefix" = xNONE && prefix=$ac_default_prefix

dnl Set directory structure parameters
case "$PLARCH" in
    *-win32|*-win64)
        PLBASE=$prefix/$PLLIBDIR
        SOLIB=bin
        TXTEXT=.TXT
        ;;
    *)
        PLBASE=$libdir/$PLLIBDIR
        INSTALL_PLARCH=$PLARCH
        SOLIB=lib
        ;;
esac

dnl ****************************************************************
dnl Checking for GNU make vpath construct
dnl ****************************************************************

AC_CHECK_PROGS(MAKE, gmake make, "make")
AC_MSG_CHECKING("whether make is GNU-make")
if ($MAKE -v 2>&1) | grep GNU > /dev/null; then
    AC_MSG_RESULT(yes)
    VPATH="vpath %.c"
else
    VPATH="VPATH = "
    AC_MSG_RESULT(no)
fi

dnl ****************************************************************
dnl Checking mkdir -p
dnl ****************************************************************

AC_MSG_CHECKING("whether mkdir accepts -p")
if (mkdir -p config.tmpdir/p && mkdir -p config.tmpdir/p 2>&1) > /dev/null; then
    AC_MSG_RESULT(yes)
    MKDIR="mkdir -p"
else
    AC_MSG_RESULT(no)
    MKDIR=mkdir
fi
rm -rf config.tmpdir

dnl ****************************************************************
dnl Finding various programs
dnl ****************************************************************

AC_CHECK_TOOLS(AR, ar, ar)
AC_CHECK_TOOLS(RANLIB, ranlib, ranlib)
AC_CHECK_TOOLS(WINDRES, windres, ":")
AC_CHECK_PROG(CHRPATH, chrpath, chrpath, ":")
AC_CHECK_PROGS(ETAGS, emacs-etags etags ctags, ":")
AC_PROG_AWK
AC_PATH_PROG(SED, sed, /bin/sed)
AC_PATH_PROG(PERL, perl, /usr/bin/perl)
AC_PROG_INSTALL
dnl Make all paths absolute as we are running some of these scripts
dnl from different locations.  Note this can also be ../src/install-sh
case "$INSTALL" in
    .*) INSTALL="`pwd`/$INSTALL" ;;
esac
case "$INSTALL_PROGRAM" in
    .*) INSTALL_PROGRAM="`pwd`/$INSTALL_PROGRAM" ;;
esac
case "$INSTALL_SCRIPT" in
    .*) INSTALL_SCRIPT="`pwd`/$INSTALL_SCRIPT" ;;
esac
case "$INSTALL_DATA" in
    .*) INSTALL_DATA="`pwd`/$INSTALL_DATA" ;;
esac
AC_PROG_CPP
AC_DEFINE_UNQUOTED(PROG_CPP, "$CPP",
		   [Program to run the C preprocessor])
AC_ISC_POSIX
AC_HEADER_STDC
AC_SYS_LARGEFILE

dnl ****************************************************************
dnl * Test for ELF
dnl ****************************************************************

AC_RUN_IFELSE(
    [ AC_LANG_PROGRAM(
	  [],
	  [
#ifdef __ELF__
return 0;
#else
return 1;
#endif
	  ])
    ],
    [EXEFORMAT=ELF],
    [EXEFORMAT=unknown],
    [EXEFORMAT=unknown])

if test "x$useprofile" = "xyes"; then
  AC_MSG_CHECKING("whether to use GCC -fprofile-use")
  if test "$GCC" = "yes"; then
    AC_MSG_RESULT(yes)
    OPTIMISE=prof
  else
    AC_MSG_RESULT(no)
  fi
fi

AC_ARG_ENABLE(custom-flags, [  --disable-custom-flags  Do not add custom build optimization flags],
	custom_flags=$enableval,
	custom_flags=yes)
if test "x$custom_flags" = "xyes" ; then
	if test "$GCC" = "yes"; then
		COFLAGS="${COFLAGS--O2}"
		CMFLAGS="${CMFLAGS--fno-strict-aliasing}"
		LDFLAGS="${LDFLAGS--O2}"
		CWFLAGS="${CWFLAGS--Wall}"
	else
		COFLAGS="${COFLAGS--O}"

		case "$PLARCH" in
			*mips-irix*)
				COFLAGS="${COFLAGS--O -OPT:Olimit_opt=on}"
			;;
		esac
	fi
else
	COFLAGS=$CFLAGS
fi

PROGLDFLAGS="$LDFLAGS"

dnl ****************************************************************
dnl Other special flags
dnl
dnl On SCO Unix, there are ELF and COFF binaries.  We want elf to
dnl provide for dlopen() and friends.  With help from Tamas Laufer!
dnl
dnl On Alpha machines we need to enable IEEE float arithmetic to avoid
dnl FPE signals on float underflow/overflow
dnl ****************************************************************

case "$PLARCH" in
    *sco*|*SCO*)
	AC_MSG_CHECKING("SCO-Unix.  See if we need -belf")
	old_cflags="$CFLAGS"
	CFLAGS="$CFLAGS -belf"
	AC_TRY_COMPILE(
	[
	],
	[
	],
	CMFLAGS="$CMFLAGS -belf"
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no)
	CFLAGS="$old_cflags")
	;;
    *alpha*)
	if test "$GCC" = "yes"; then
	  CMFLAGS="$CMFLAGS -mieee"
	else
	  CMFLAGS="$CMFLAGS -ieee"
	fi
        ;;
    *-win32)
	CMFLAGS="$CMFLAGS -D__WINDOWS__ -DWIN32"
	;;
    *-win64)
	CMFLAGS="$CMFLAGS -D__WINDOWS__ -DWIN64"
	;;
esac

dnl Set swipl-ld host parameters
case "$PLARCH" in
    *-win32|*-win64)
        HOST_TOOLCHAIN_FLAG=-DHOST_TOOLCHAIN_MINGW
        HOST_OS_FLAG=-DHOST_OS_WINDOWS
       ;;
esac

AC_C_INLINE
AC_FUNC_ALLOCA
AC_C_BIGENDIAN

dnl This fragment is from the glibc configure script

if test "$GCC" = "yes"; then
  AC_CACHE_CHECK(whether __attribute__((visibility())) is supported,
		 libc_cv_visibility_attribute,
                 [cat > conftest.c <<EOF
                  int foo __attribute__ ((visibility ("hidden"))) = 1;
                  int bar __attribute__ ((visibility ("protected"))) = 1;
EOF
                  libc_cv_visibility_attribute=no
                  if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
                    if grep '\.hidden.*foo' conftest.s >/dev/null; then
                      if grep '\.protected.*bar' conftest.s >/dev/null; then
                        libc_cv_visibility_attribute=yes
                      fi
                    fi
                  fi
                  rm -f conftest.[cs]
                 ])
  if test $libc_cv_visibility_attribute = yes; then
    AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE, 1,
	      [Define if __attribute__ visibility is supported])
  fi
fi

case "$PLARCH" in
    *cygwin*)
	EXTRAHDR=def
        ;;
    *aix*)
	EXTRAHDR=exports
	;;
esac


dnl ****************************************************************
dnl How script args are handled
dnl ****************************************************************

AC_MSG_CHECKING(Script arguments)
cat > testconf.args << EOS
#!$SED -e s/foo/bar/ -f

s/x/y/
EOS
chmod +x testconf.args

if ( echo foo | ./testconf.args ) >/dev/null 2>&1; then
    AC_DEFINE(SCRIPT_BREAKDOWN_ARGS, 1,
	      [breaks arguments ])
    AC_MSG_RESULT(breaks down arguments)
else
    AC_MSG_RESULT(does not breakdown arguments)
fi
rm -f testconf.args

dnl ****************************************************************
dnl See whether we can use git versions
dnl ****************************************************************

AC_MSG_CHECKING([Use git-based version stamps])
if "$srcdir/mkversion.sh" && \
   test -r version.h && \
   grep GIT_VERSION version.h > /dev/null; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(USE_GIT_VERSION_H, 1,
	    [Define to use include actual git version])
else
  AC_MSG_RESULT(no)
fi

dnl ****************************************************************
dnl Setup shared library and dynamic linking
dnl ****************************************************************

PLSHARED=no
AC_CHECK_HEADERS(dlfcn.h)
AC_CHECK_LIB(dl, dlopen)
if test "$ac_cv_lib_dl_dlopen" = "yes"; then
  AC_CHECK_FUNCS(dlopen)
  AC_CHECK_FUNCS(dladdr)
else
  AC_CHECK_LIB(dld, shl_load)
  AC_CHECK_FUNCS(shl_load)
fi

dnl On SCO, dlopen is in libc.so and requires dlfcn.h to compile.  Thanks
dnl to Tamas Laufer.

if test ! "$ac_cv_func_dlopen" = "yes"; then
AC_MSG_CHECKING("dlopen in libc")
AC_TRY_COMPILE(
[
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif
],
[ dlopen("foobar", RTLD_NOW);
], ac_cv_func_dlopen=yes
   AC_DEFINE(HAVE_DLOPEN, 1,
	     [Define if you have a working dlopen()])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi

if test "$ac_cv_func_dlopen" = yes -o "$ac_cv_func_shl_load" = yes; then
  PLSHARED=yes
fi

if test "$PLSHARED" = "yes"; then

dnl Some versions of (g)cc need to export the symbols from the main program
dnl using -rdynamic.  See whether this gcc understands this flag.

case "$PLARCH" in
  *darwin*|*-win32|*-win64)
	rdynamic=done
	;;
esac

if test "$rdynamic" != "done"; then
AC_MSG_CHECKING("whether LDFLAGS need -rdynamic")
  old_ldflags="$LDFLAGS"
  LDFLAGS="-rdynamic $LDFLAGS"
  AC_TRY_RUN(
main()
{ exit(0);
},
     if grep 'unrecognized option `-rdynamic'"'" config.log >/dev/null; then
       AC_MSG_RESULT(no)
       LDFLAGS="$old_ldflags"
     else
       AC_MSG_RESULT(yes)
     fi,
     AC_MSG_RESULT(no)
     LDFLAGS="$old_ldflags",
     AC_MSG_RESULT(no)
     LDFLAGS="$old_ldflags")
fi

dnl Some specific OS stuff

RPATH_EXTRA=
if test "x$RPATH_RESERVE" != "x"; then
  RPATH_EXTRA=":"
  n=$RPATH_RESERVE
  while test $n -gt 0; do
    RPATH_EXTRA="${RPATH_EXTRA}x"
    n=$(($n-1))
  done
fi

SO_LDFLAGS="-shared"
SO_pic="-fpic"
SO_PIC="-fPIC"
SO_LD="$CC"
SO_EXT="so"
SO_PATH="-Wl,-rpath=$PLBASE/lib/$PLARCH$RPATH_EXTRA"
DLLIBVAR=LD_LIBRARY_PATH
MINGW="false"

case "$PLARCH" in
  *solaris* | *sunos*)
	SO_LDFLAGS="-G"
	if test "$GCC" != "yes"; then
	    SO_pic="-Kpic"
	    SO_PIC="-KPIC"
	fi
	;;
  *hpux*)
	SO_EXT="sl"
	LDFLAGS="$LDFLAGS -Wl,-E"
	if test "$GCC" != "yes"; then
	    SO_LDFLAGS="-Wl,-b"
	fi
	;;
  *osf*)
	SO_LD=ld
	SO_LDFLAGS="-shared -expect_unresolved \*"
	SO_pic="-std"
	if test "$MT" = yes; then
	  AC_CHECK_LIB(exc, main)
	fi
	;;
  *aix*)
	SO_EXT="o"
	DLLIBVAR=LIBPATH
	if test "$GCC" = "yes"; then
	    LDFLAGS="$LDFLAGS -Wl,-bE:../include/SWI-Exports"
	    SO_LDFLAGS="-Wl,-bI:$PLBASE/include/SWI-Exports"
	else
	    LDFLAGS="$LDFLAGS -bE:../include/SWI-Exports"
	    SO_LDFLAGS="-bI:$PLBASE/include/SWI-Exports"
	fi
	;;
  *x86_64*linux|*hppa*linux|*arm*linux)
	if test "x$MKSHARED" = "x"; then
	    MKSHARED=yes
	fi
	;;
  *darwin*)
	if test "x$MKSHARED" = "x"; then
	    MKSHARED=yes
	fi
	SO_EXT=dylib
	SO_pic="-fno-common"
	SO_PIC="-fno-common"
	SO_LDFLAGS="-bundle -dynamic -flat_namespace -undefined suppress"
	SO_PATH=""
	DLLIBVAR=DYLD_LIBRARY_PATH
	AC_DEFINE(USE_SEM_OPEN, 1,
		  [Define if we must use sem_open() instead of the preferred sem_init()])
	AC_DEFINE(LD_SYMBOL_PREFIX, "_",
		  [String used to prefix all symbols requested through dlsym()])
	CMFLAGS="$CMFLAGS -no-cpp-precomp"
	;;
  *cygwin*)
	SO_EXT="dll"
	SO_pic=""
	SO_PIC=""
	DLLIBVAR=PATH
	;;
  *-win32|*-win64)
	SO_EXT="dll"
	SO_pic=""
	SO_PIC=""
	case $(uname) in
	    MINGW*)
		DLLIBVAR=PATH
		;;
	    *)
		DLLIBVAR=WINEPATH
		;;
	esac
	AC_CHECK_PROG(WINEPATHEXE, winepath, winepath, ":")
	DEFSTARTUP=swipl.ini
	CHRPATH=:
        AC_MSG_CHECKING(whether linker supports --stack)
        oldflags="$LDFLAGS"
        LDFLAGS="$LDFLAGS -Wl,--stack,4000000"
        AC_TRY_LINK([], [],
                    [AC_MSG_RESULT(yes)
                     STACKFLAGS=-Wl,--stack,4000000],
                    [AC_MSG_RESULT(no)])
        LDFLAGS="$oldflags"
        AC_MSG_CHECKING(whether linker supports --subsystem)
        oldflags="$LDFLAGS"
        LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
        AC_TRY_LINK([], [],
                    [AC_MSG_RESULT(yes)
                     SUBSYSTEMFLAGS=-Wl,--subsystem,windows],
                    [AC_MSG_RESULT(no)])
        LDFLAGS="$oldflags"
	MINGW=true
	;;
  *)
	;;
esac

if test "x$WINEPATHEXE" = "x"; then WINEPATHEXE=":"; fi

AC_DEFINE_UNQUOTED(SO_EXT,     "$SO_EXT",
		   [Define to the extension of shared objects (often .so)])
AC_DEFINE_UNQUOTED(SO_PATH,    "$DLLIBVAR",
		   [Search path for shared objects (often LD_LIBRARY_PATH)])
AC_DEFINE_UNQUOTED(SO_LD,      "$SO_LD",
		   [Program to link shared objects])
AC_DEFINE_UNQUOTED(SO_LDFLAGS, "$SO_LDFLAGS",
		   [Flags to use for linking shared objects])
AC_DEFINE_UNQUOTED(SO_pic,     "$SO_pic",
		   [Flags for compiling position-independent small object])
AC_DEFINE_UNQUOTED(SO_PIC,     "$SO_PIC",
		   [Flags for compiling position-independent BIG object])
AC_DEFINE_UNQUOTED(PROG_PL,    "$PL$EXEEXT",
		   [Name of the SWI-Prolog executable (normally swipl[.exe])])
case "$PLARCH" in
  *cygwin*)
	PLSO=cygpl.$SO_EXT
	SONAMEOPT='-Wl,--out-implib,$(RUNTIMEDIR)/libswipl.dll.a $(DEF)'
	;;
  *-win32|*-win64)
	PLSO=libswipl.$SO_EXT
	SONAMEOPT='-Wl,-soname=$(SHAREDV) -Wl,--out-implib,$(RUNTIMEDIR)/libswipl.$(SOEXT).a'
	;;
  *)
	PLSO=libswipl.$SO_EXT
	SONAMEOPT='-Wl,-soname=$(SHAREDV)'
	;;
esac

fi	dnl PLSHARED


dnl ****************************************************************
dnl Finding libraries
dnl ****************************************************************

changequote(,)dnl
USEPLLIB=`echo $PLLIB | sed 's/lib\([a-z]*\).a/-l\1/'`
changequote([,])dnl

case "$PLARCH" in
    *-win32|*-win64)
	AC_CHECK_LIB(shell32, main)
	AC_CHECK_LIB(winmm, main)
	AC_CHECK_LIB(wsock32, main)
	AC_CHECK_LIB(gdi32, main, [XLIBS="$XLIBS -lgdi32"])
	AC_CHECK_LIB(comdlg32, main, [XLIBS="$XLIBS -lcomdlg32"])
	EXTRAOBJ="pl-nt.o pl-ntconsole.o pl-dde.o"
	;;
esac


PLTHREADS=no
if test "$MT" = "yes"; then
pthread_ok=false

case "$PLARCH" in
    *freebsd*)
	AC_DEFINE(_THREAD_SAFE, 1,
		  [Required in FreeBSD for compiling thread-safe code])
	;;
    *-win32|*-win64)
        pthread_ok=true
	AC_CHECK_LIB(pthreadGC2, pthread_create)
        if test ! "$ac_cv_lib_pthreadGC2_pthread_create" = "yes"; then
          AC_CHECK_LIB(pthreadGC, pthread_create)
          if test ! "$ac_cv_lib_pthreadGC_pthread_create" = "yes"; then
            AC_CHECK_LIB(pthread, pthread_create)
          fi
        fi
	;;
esac

  if test "$GCC" = "yes"; then
  for PTHREAD in -pthread -pthreads; do
    if test "$pthread_ok" = "false"; then
      AC_MSG_CHECKING("whether gcc supports $PTHREAD")
      ocflags="$CFLAGS"
      CFLAGS="$CFLAGS $PTHREAD"
      AC_TRY_LINK([
#include <pthread.h>
		  ],
		  [ static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
		    pthread_mutex_lock(&m);
		    pthread_mutex_unlock(&m);
#if !(defined(_REENTRANT) || defined(_THREAD_SAFE) || defined(_POSIX_THREADS))
	this should not be compiled
#endif
		  ],
		  pthread_ok=true
		  CMFLAGS="$CMFLAGS $PTHREAD"
		  LDFLAGS="$LDFLAGS $PTHREAD"
		  AC_MSG_RESULT(yes),
		  CFLAGS="$ocflags"
		  AC_MSG_RESULT(no))
      fi
    done
  fi

  if test "$pthread_ok" = "false"; then
  AC_CHECK_LIB(pthread, main)
    if test "$ac_cv_lib_pthread_main" = "yes"; then
      pthread_ok=true
      CMFLAGS="$CMFLAGS -D_REENTRANT"
    fi
  fi

  if test "$pthread_ok" = "true"; then
    AC_DEFINE(O_PLMT, 1,
	      [Define to include support for multi-threading])
    PLTHREADS=yes
  fi

  AC_CHECK_LIB(rt, sem_init)
  AC_CHECK_FUNCS(sem_init)
  if test ! "$ac_cv_lib_rt_sem_init" = "yes"; then
	AC_CHECK_LIB(thread,sema_init)
	AC_CHECK_FUNCS(sema_init)
  fi
  AC_CHECK_FUNCS(pthread_mutexattr_setkind_np pthread_mutexattr_settype)
  AC_CHECK_FUNCS(pthread_kill)
  AC_MSG_CHECKING([whether mutex support recursive locking])
  case "$PLARCH" in
    *-win32|*-win64)
      AC_MSG_RESULT(yes)
      AC_DEFINE(RECURSIVE_MUTEXES, 1,
        [Define to make use of standard (UNIX98) pthread recursive mutexes])
      ;;
    *)
      echo '#include "confdefs.h"' > conftest.c
      cat $srcdir/test/recmutex.c >> conftest.c
      (eval $ac_link) 2>&5
      if test -s conftest && ./conftest; then
        AC_MSG_RESULT(yes)
        AC_DEFINE(RECURSIVE_MUTEXES, 1,
          [Define to make use of standard (UNIX98) pthread recursive mutexes])
      else
        AC_MSG_RESULT(no)
      fi
      ;;
  esac
  AC_CHECK_FUNCS(pthread_sigmask pthread_setconcurrency)

dnl ATOMIC inc/dec for reference counts

dnl   AC_CHECK_HEADERS(asm/atomic.h)
dnl   AC_MSG_CHECKING("atomic increment/decrement")
dnl   AC_TRY_RUN(
dnl   [
dnl #ifdef HAVE_ASM_ATOMIC_H
dnl # include <asm/atomic.h>
dnl #endif
dnl     main()
dnl     { int i = 0;
dnl       if ( sizeof(atomic_t) != sizeof(int) )
dnl         exit(1);
dnl       atomic_inc((atomic_t *)&i);
dnl       if ( i != 1 ) exit(1);
dnl       atomic_dec((atomic_t *)&i);
dnl       if ( i != 0 ) exit(1);
dnl       return 0;
dnl     }
dnl   ],
dnl   AC_MSG_RESULT(yes)
dnl   AC_DEFINE(HAVE_ATOMIC_INC, 1,
dnl	    [Define if you have atomic_inc() and atomic_dec() with atomic_t == int]),
dnl   AC_MSG_RESULT(no),
dnl   AC_MSG_RESULT(assuming no))

AC_CHECK_FUNCS(sysconf)

AC_MSG_CHECKING("copy stack size")
AC_TRY_RUN(
[
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <pthread.h>

#define ROUND(p, n)		((((p) + (n) - 1) & ~((n) - 1)))

static void *
dummy(void *closure)
{ return closure;
}

static size_t
round_pages(size_t n)
{ size_t psize;

#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
  if ( (psize = sysconf(_SC_PAGESIZE)) == (size_t)-1 )
    psize = 8192;
#else
  psize = 8192;
#endif

  return ROUND(n, psize);
}

int
main()
{ pthread_attr_t attr;
  struct rlimit rlim;
  size_t stack;
  pthread_t tid;
  void *r;

  pthread_attr_init(&attr);
  if ( getrlimit(RLIMIT_STACK, &rlim) != 0 )
    exit(1);
  if ( rlim.rlim_cur != RLIM_INFINITY )
    stack = rlim.rlim_cur;
  stack = round_pages(stack);
  if ( pthread_attr_setstacksize(&attr, stack) != 0 )
    exit(1);
  if ( pthread_create(&tid, &attr, dummy, NULL) != 0 )
    exit(1);
  if ( pthread_join(tid, &r) != 0 )
    exit(1);

  return 0;
}
],
AC_MSG_RESULT(yes)
AC_DEFINE(USE_COPY_STACK_SIZE, 1,
	  [Define if to copy thread stack size from main]),
AC_MSG_RESULT(no),
AC_MSG_RESULT(assuming no))


fi	dnl End of MT configuration


AC_CHECK_LIB(m, main)
AC_CHECK_LIB(ncursesw, main)
if test ! "$ac_cv_lib_ncursesw_main" = "yes"; then
  AC_CHECK_LIB(ncurses, main)
  if test ! "$ac_cv_lib_ncurses_main" = "yes"; then
    AC_CHECK_LIB(curses, main)
    if test ! "$ac_cv_lib_curses_main" = "yes"; then
      AC_CHECK_LIB(termcap, main)
      if test "$ac_cv_lib_termcap_main" = "yes"; then
	AC_MSG_CHECKING("whether -ltermcap needs -lucb")
	AC_TRY_LINK([],
		    [ tgetent();
		    ],
		    AC_MSG_RESULT(no)
		    true,
		    AC_MSG_RESULT(maybe ...)
		    checkucb=yes)
      fi
    fi
  fi
fi

AC_CHECK_HEADERS(term.h ncurses/term.h curses.h ncurses/curses.h)

if test "$checkucb" = "yes"; then
    AC_CHECK_LIB(ucb, rindex)
fi

dnl Hacks for MacOS handling of libreadline.  We want to prefer the MacOS X
dnl libraries, but we need to get libreadline from Macports, as the BSD
dnl version is severely limited.

case "$PLARCH" in
  *darwin*)
	if test -z "$RLPREFIX"; then
	  RLPREFIX=/opt/local
        fi
	;;
esac

AC_DEFUN([pl_RL_CHECK_VAR],
[AS_VAR_PUSHDEF([ac_var], [ac_cv_libreadline_var_$1])dnl
AC_CACHE_CHECK([for $1], [ac_var],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
#include <readline/readline.h>], [$1 = 0;])],
       [AS_VAR_SET([ac_var], [yes])],
       [AS_VAR_SET([ac_var], [no])])])
 AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
        [Define to 1 if libreadline has the `$1' variable.])
 AS_IF([test AS_VAR_GET([ac_var]) = yes],
       [AC_DEFINE(AS_TR_CPP([HAVE_$1]))])
 AS_VAR_POPDEF([ac_var])dnl
])

if test "$configreadline" = "yes" -a ! $readline_ok = "yes" ; then
  if test ! -z "$RLPREFIX"; then
    AC_MSG_CHECKING(Whether setting for RLPREFIX is ok)
    if test -f $RLPREFIX/include/readline/readline.h -a \
	    -f $RLPREFIX/lib/libreadline.$SO_EXT; then
      LIBS="$LIBS $RLPREFIX/lib/libreadline.$SO_EXT"
      AC_MSG_RESULT(Using $RLPREFIX)
      AC_DEFINE(HAVE_LIBREADLINE, 1,
		[Define to 1 if you have libreadline])
      AC_DEFINE(HAVE_READLINE_READLINE_H, 1,
		[Define to 1 if you have <readline/readline.h>])
      ocflags="$CFLAGS"
      CFLAGS="-I$RLPREFIX/include $CFLAGS"
      AC_CHECK_FUNCS(rl_completion_matches rl_insert_close)
      AC_CHECK_FUNCS(rl_set_prompt rl_clear_pending_input)
      AC_CHECK_FUNCS(rl_event_hook rl_cleanup_after_signal)
      AC_CHECK_FUNCS(rl_filename_completion_function)
      AC_CHECK_FUNCS(rl_set_keyboard_input_timeout)
      AC_CHECK_DECLS([rl_done])
      FreeBSD="$ocflags"
      readline_ok=yes
    else
      AC_MSG_RESULT(no)
      RLPREFIX=
    fi
  fi

  if test -z "$RLPREFIX"; then
    AC_CHECK_LIB(readline, main,
		 have_libreadline=yes)

    if test "$have_libreadline" = yes; then
      AC_CHECK_HEADERS(readline/readline.h)
      if test "$ac_cv_header_readline_readline_h" = no; then
	  unset ac_cv_header_readline_readline_h
	  CFLAGS="$CFLAGS -I/usr/local/include"
	  AC_CHECK_HEADERS(readline/readline.h)
	  if test "$ac_cv_header_readline_readline_h" = yes; then
	      CIFLAGS="$CIFLAGS -I/usr/local/include"
	  fi
      fi

      if test "$ac_cv_header_readline_readline_h" = yes; then
	AC_CHECK_HEADERS(readline/history.h)
	if test "$ac_cv_header_readline_history_h" = yes; then
	  readline_ok=yes
	  LIBS="-lreadline $LIBS"
	  AC_DEFINE(HAVE_LIBREADLINE, 1,
		    [ Define if you have libreadline and headers ])
	  AC_CHECK_FUNCS(rl_completion_matches rl_insert_close)
	  AC_CHECK_FUNCS(rl_set_prompt rl_clear_pending_input)
	  AC_CHECK_FUNCS(rl_cleanup_after_signal)
	  AC_CHECK_FUNCS(rl_filename_completion_function)
	  pl_RL_CHECK_VAR([rl_readline_state])
	  pl_RL_CHECK_VAR([rl_done])
	  pl_RL_CHECK_VAR([rl_event_hook])
	fi
      fi
    fi
  fi
else
  readline_ok=yes			# specified absent
fi

dnl ================================================================

AC_MSG_CHECKING(for cc -c -o)
  cat > conftest.c << _EOP_
main()
{ exit(0);
}
_EOP_
  if ${CC-cc} $CFLAGS -c conftest.c -o conftest.o 1>&5 2>&5 && test -r conftest.o; then
    COUTOPT='-o $@'
    AC_MSG_RESULT(yes)
  else
    COUTOPT=
    AC_MSG_RESULT(no)
  fi
  rm -rf conftest.*

AC_CHECK_HEADERS(unistd.h string.h memory.h sys/time.h sys/stat.h pwd.h)
AC_CHECK_HEADERS(sys/select.h sys/param.h sys/file.h sys/resource.h)
AC_CHECK_HEADERS(malloc.h sys/stropts.h wchar.h execinfo.h)
AC_CHECK_HEADERS(sys/termios.h sys/termio.h bstring.h sys/mman.h)
AC_CHECK_HEADERS(mach-o/rld.h mach/thread_act.h locale.h)
AC_CHECK_HEADERS(float.h floatingpoint.h ieeefp.h SupportDefs.h)
AC_CHECK_HEADERS(crtdbg.h shlobj.h winsock2.h)

AC_CHECK_FUNCS(access fchmod chmod dossleep fstat readlink getwd getcwd)
AC_CHECK_FUNCS(getpagesize getpwnam getrlimit gettimeofday opendir sysconf)
AC_CHECK_FUNCS(popen putenv random remove rename select fcntl getrusage)
AC_CHECK_FUNCS(signal sigset sigprocmask sleep usleep srand srandom stat)
AC_CHECK_FUNCS(memmove stricmp strlwr sigaction sigsetmask siggetmask sigblock)
AC_CHECK_FUNCS(rint aint floor ceil isnan isinf tcsetattr cfmakeraw getpid)
AC_CHECK_FUNCS(strerror tgetent times unsetenv grantpt nanosleep waitpid)
AC_CHECK_FUNCS(setlocale fpgetmask fpresetsticky mtrace localtime_r asctime_r)
AC_CHECK_FUNCS(mmap confstr strcasecmp mbscoll mbscasecoll fpclassify fpclass)
AC_CHECK_FUNCS(setenv posix_openpt wcsxfrm sysctlbyname mbsnrtowcs)
AC_CHECK_FUNCS(mallinfo ftruncate localtime_s)
AC_CHECK_DECLS([mbsnrtowcs])
AC_HEADER_TIME
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT
AC_FUNC_VFORK

dnl AC_CHECK_FUNCS() doesn't work due to type errors.  Seems there is some
dnl discussion for a better solution, but for now this should do.

AC_MSG_CHECKING(for __builtin_clz)
AC_TRY_LINK([],
	    [ __builtin_clz(0); ],
	    [ AC_MSG_RESULT(yes)
	      AC_DEFINE(HAVE__BUILTIN_CLZ, 1,
			[Define if you have __builtin_clz])
	    ],
	    [ AC_MSG_RESULT(no) ])
AC_MSG_CHECKING(for __sync_synchronize)
AC_TRY_LINK([],
	    [ __sync_synchronize(); ],
	    [ AC_MSG_RESULT(yes)
	      AC_DEFINE(HAVE__SYNC_SYNCHRONIZE, 1,
			[Define if you have __sync_synchronize])
	    ],
	    [ AC_MSG_RESULT(no) ])
AC_MSG_CHECKING(for signbit)
AC_TRY_LINK([#include <math.h>],
	    [ signbit(0.0); ],
	    [ AC_MSG_RESULT(yes)
	      AC_DEFINE(HAVE_SIGNBIT, 1,
			[Define if you have signbit])
	    ],
	    [ AC_MSG_RESULT(no) ])


if test ! "x$boehmgc" = xno; then
  oldlibs="$LIBS"
  AC_CHECK_LIB(gc, GC_malloc, check_gc_h=yes)
  if test "x$check_gc_h" = "xyes"; then
    AC_CHECK_HEADER(gc/gc.h,
		    AC_DEFINE(HAVE_BOEHM_GC, 1,
			      [ Define to 1 if you have Boehm GC. ])
		    LIBS="-lgc $LIBS")
    AC_CHECK_FUNCS(GC_set_flags)	dnl Custom extensions
  fi
fi

case "$PLARCH" in
    *-win32|*-win64)
      if test "x$ac_cv_func_select" = xno; then
        # Under MinGW, select() is not in the default libraries.
        for select_lib in ws2_32; do
          AC_MSG_CHECKING([for select in $select_lib])
          ac_save_LIBS="$LIBS"
          LIBS="-l$select_lib $LIBS"
          AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([[#ifdef HAVE_WINSOCK2_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#endif]],
                             [[select(0,
                                      (fd_set *) NULL, (fd_set *) NULL,
                                      (fd_set *) NULL,
                                      (struct timeval *) NULL);]])
            ],
            [
              AC_MSG_RESULT([yes])
              AC_DEFINE([HAVE_SELECT])
              break
            ],
            [
              AC_MSG_RESULT([no])
              LIBS="$ac_save_LIBS"
            ]
          )
        done
      fi
      AC_CHECK_LIB(dbghelp, StackWalk64,
		   check_dbghelp_h=yes)
      if test "$check_dbghelp_h" = yes; then
	AC_CHECK_HEADERS(dbghelp.h,
			 LIBS="-ldbghelp $LIBS",
			 [],
[#include <windows.h>
])
      fi
      ;;
esac

AC_CHECK_TYPE(intptr_t)

if test "x$ac_cv_func_unsetenv" = "xyes"; then
  AC_MSG_CHECKING("whether unsetenv is void")
  AC_TRY_COMPILE(
[
#include <stdlib.h>
],
		 [ int i = unsetenv("test");
		 ],
		 AC_MSG_RESULT(no),
		 AC_DEFINE(VOID_UNSETENV, 1,
			   [Define if unsetenv() is void])
		 AC_MSG_RESULT(yes))
fi

AC_CHECK_HEADERS(sys/syscall.h)
AC_CHECK_FUNCS(syscall)

AC_MSG_CHECKING(whether <sys/syscall.h> has __NR_gettid)
AC_TRY_COMPILE(
[ #include <sys/syscall.h> ],
[ int i = __NR_gettid;
], AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

AC_MSG_CHECKING(for syscall support for gettid)
AC_TRY_COMPILE(
[ #include <unistd.h>
  #include <sys/syscall.h> ],
[ syscall(__NR_gettid);
], ac_syscall_gettid="yes"
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

if test "x$ac_syscall_gettid" = "xyes"; then
   AC_DEFINE(HAVE_GETTID_SYSCALL, 1,
             [Define to 1 if you have syscall support for gettid()])
else

AC_MSG_CHECKING("linux gettid _syscall0 macro")
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <linux/unistd.h>
_syscall0(pid_t,gettid)
],
[ pid_t t = gettid();
], AC_DEFINE(HAVE_GETTID_MACRO, 1,
	     [Define to 1 if you have the Linux gettid() _syscall0 macro])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi

AC_CHECK_LIB(rt, clock_gettime)
AC_CHECK_FUNCS(clock_gettime)

AC_MSG_CHECKING(for pthread support for cpu clocks)
AC_TRY_RUN(
[
#include <stdio.h>
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
#define ts2d(ts) \
	((double)(ts).tv_sec + (double)(ts).tv_nsec/(double)1000000000.0)
main()
{
  clockid_t clock_id;
  struct timespec ts = {1,1};
  if ( pthread_getcpuclockid(pthread_self(), &clock_id) != 0 )
  { perror("pthread_getcpuclockid");
    exit(1);
  }
  sleep(1);
  if ( clock_gettime(clock_id, &ts) != 0 )
  { perror("clock_gettime");
    exit(1);
  }
  fprintf(stderr, "Used %f sec\n", ts2d(ts));
  exit (ts.tv_sec == 0 ? 0 : 1);
}], ac_pthread_cpuclocks="yes"
    AC_MSG_RESULT(yes),
    AC_MSG_RESULT(no))

if test "x$ac_pthread_cpuclocks" = "xyes"; then
   AC_DEFINE(PTHREAD_CPUCLOCKS, 1,
             [Define if you have pthread cpu clocks (glibc 2.4 and greater)])
else

AC_MSG_CHECKING(whether <sys/syscall.h> has __NR_clock_gettime)
AC_TRY_COMPILE(
[ #include <sys/syscall.h> ],
[ int i = __NR_clock_gettime;
], AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

AC_MSG_CHECKING(for syscall support for cpu clocks)
AC_TRY_RUN(
[
#include <stdio.h>
#include <time.h>
#include <sys/syscall.h>
#include <stdlib.h>
#define ts2d(ts) \
	((double)(ts).tv_sec + (double)(ts).tv_nsec/(double)1000000000.0)
main()
{ struct timespec ts0;
  struct timespec ts1;
  double t;
  if ( syscall(__NR_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &ts0) )
    exit(1);
  sleep(1);
  syscall(__NR_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &ts1);
  t = ts2d(ts1) - ts2d(ts0);
  fprintf(stderr, "sleep(1) used %f sec\n", t);
  if ( t > 0.5 )
  { exit(1);
  }
  exit(0);
}], ac_linux_cpuclocks="yes"
    AC_MSG_RESULT(yes),
    AC_MSG_RESULT(no))

if test "x$ac_linux_cpuclocks" = "xyes"; then
   AC_DEFINE(LINUX_CPUCLOCKS, 1,
             [Define if you have Linux cpu clocks (2.6.12 and greater)])
else

AC_MSG_CHECKING(linux 2.6 /proc)
if { test -f /proc/$$/task/$$/stat && \
     test `cat /proc/$$/task/$$/stat | wc -w` -gt 41; }; then
   AC_MSG_RESULT(yes)
   AC_DEFINE(LINUX_PROCFS, 26,
	     [Define if you have Linux 2.6 compatible /proc])
else
   AC_MSG_RESULT(no)
fi
fi
fi

AC_MSG_CHECKING(for sysconf support for _SC_NPROCESSORS_CONF)
AC_TRY_COMPILE(
[ #include <unistd.h> ],
[ long n = sysconf(_SC_NPROCESSORS_CONF);
], ac_sc_nprocessors_conf="yes"
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

if test "x$ac_sc_nprocessors_conf" = "xyes"; then
   AC_DEFINE(HAVE_SC_NPROCESSORS_CONF, 1,
             [Define if you have sysconf support for _SC_NPROCESSORS_CONF])
else

AC_MSG_CHECKING(linux /proc/cpuinfo)
if { test -f /proc/cpuinfo && \
     grep 'processor[	 ]*: 0' /proc/cpuinfo 2>&1 > /dev/null; }; then
   AC_MSG_RESULT(yes)
   AC_DEFINE(PROCFS_CPUINFO, 1,
	     [Define if you have Linux compatible /proc/cpuinfo])
else
   AC_MSG_RESULT(no)
fi
fi

AC_CHECK_LIB(unwind, main,
	     check_unwind_h=yes)
if test "$check_unwind_h" = yes; then
  AC_CHECK_HEADER(libunwind.h,
		  AC_DEFINE(HAVE_LIBUNWIND, 1,
			    [ Define if you have libunwind and libunwind.h ])
		  LIBS="-lunwind $LIBS")
fi

dnl Used in OpenBSD
AC_CHECK_LIB(execinfo, backtrace_symbols)

AC_CHECK_SIZEOF(void*, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(int,  4)
AC_CHECK_SIZEOF(long long, 8)
AC_CHECK_SIZEOF(wchar_t, 4)

if test "$ac_cv_sizeof_long" = 8; then
  AC_DEFINE(INT64_FORMAT, ["%ld"],
	    [printf format for int64_t datatype])
else
  case "$PLARCH" in
    *-win32|*-win64)
      AC_DEFINE(INT64_FORMAT, ["%I64d"],
                              [printf format for int64_t datatype])
      ;;
    *)
      AC_DEFINE(INT64_FORMAT, ["%lld"],
                              [printf format for int64_t datatype])
      ;;
  esac
fi

if test "$configgmp" = "yes"; then
  AC_CHECK_LIB(gmp, main,
	       check_gmp_h=yes,
	       WARN_NO_GMP=yes)
  if test "$check_gmp_h" = "yes"; then
    AC_CHECK_HEADER(gmp.h,
		    AC_DEFINE(HAVE_GMP_H, 1,
			      [ Define to 1 if you have the <gmp.h> header file. ])
		    LIBS="-lgmp $LIBS",
		    WARN_NO_GMP=yes)
  fi

  AC_MSG_CHECKING("For gmp_randinit_mt()");
  AC_TRY_LINK(
      [#include <gmp.h>
      ],
      [ gmp_randstate_t state;
	gmp_randinit_mt(&state);
      ],
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_GMP_RANDINIT_MT, 1,
		[ Define you you have gmp_randinit_mt (gmp > 4.2.0) ]),
      AC_MSG_RESULT(no))
fi

dnl Setup DMALLOC

if test "$dmalloc" = "yes"; then
  AC_CHECK_LIB(dmalloc, main,
	       AC_DEFINE(DMALLOC, 1,
			 [Define if you want to use dmalloc])
	       LIBS="$LIBS -ldmalloc",
	       true)
fi

dnl tszet and timezone trouble

AC_MSG_CHECKING("variable timezone in tzset")
AC_TRY_RUN(
[ #include <time.h>
  #include <stdlib.h>
  #if defined(__CYGWIN__) || defined(__MINGW32__)
  #define timezone _timezone
  #else
  extern long timezone;
  #endif

  main()
  { tzset();

    if ( timezone > -15*3600 &&
	 timezone < 15*3600 &&
	 timezone % 60 == 0 )
      return 0;

    exit(1);
  }
],
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_VAR_TIMEZONE, 1,
	  [Define if tzset sets timezone variable]),
AC_MSG_RESULT(no),
AC_MSG_RESULT(assuming no))

AC_CHECK_MEMBER(struct tm.tm_gmtoff,
		AC_DEFINE(HAVE_STRUCT_TIME_TM_GMTOFF, [],
			  [Define is struct tm has tm_gmtoff]),
		[],
		[#include <time.h>])

AC_MSG_CHECKING("Boot filename");
BOOTFILE=boot`expr ${ac_cv_sizeof_voidp} \* 8`.prc
AC_DEFINE_UNQUOTED(BOOTFILE, "$BOOTFILE",
		   [Name of the file to boot from])
AC_MSG_RESULT($BOOTFILE)

if test "$ac_cv_func_fcntl" = yes; then
  AC_MSG_CHECKING("fcntl based locking");
  AC_TRY_COMPILE(
[
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
],
[ struct flock buf;
  fcntl(0, F_SETLKW, &buf);
], AC_DEFINE(FCNTL_LOCKS, 1,
	     [we have fcntl() and it supports F_SETLKW])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi


AC_MSG_CHECKING("alignment restrictions on doubles")
AC_TRY_RUN(
[
#include <inttypes.h>
  main()
  { void *l[10];
    double *p = (double*)l;

    if ( sizeof(double) == sizeof(void*) )
      return 0;

#if defined(__alpha__) || defined(__alpha) || defined(__ia64__) || defined(__sparc__)
    return 1;
#endif

    if ( (intptr_t)p % sizeof(double) == 0 )
      p += sizeof(void*);
    *p = 1.0;

    return 0;
  }
],
AC_MSG_RESULT(as void*),
AC_MSG_RESULT(sizeof(double))
AC_DEFINE(DOUBLE_ALIGNMENT, sizeof(double),
	  [Define if doubles cannot be aligned as pointers]),
AC_MSG_RESULT(assuming sizeof(double))
AC_DEFINE(DOUBLE_ALIGNMENT, sizeof(double)))

AC_MSG_CHECKING("alignment restrictions on int64_t")
AC_TRY_RUN(
[
#include <inttypes.h>
  main()
  { void *l[10];
    int64_t *p = (int64_t*)l;

    if ( sizeof(int64_t) == sizeof(void*) )
      return 0;

#if defined(__alpha__) || defined(__alpha) || defined(__ia64__) || defined(__sparc__)
    return 1;
#endif

    if ( (intptr_t)p % sizeof(int64_t) == 0 )
      p += sizeof(void*);
    *p = 0x123456789abcdefLL;

    return 0;
  }
],
AC_MSG_RESULT(as void*),
AC_MSG_RESULT(sizeof(int64_t))
AC_DEFINE(INT64_ALIGNMENT, sizeof(int64_t),
	  [Define if int64_t cannot be aligned as pointers]),
AC_MSG_RESULT(assuming sizeof(int64_t))
AC_DEFINE(INT64_ALIGNMENT, sizeof(int64_t)))

dnl See whether we can access intptr_t values over non-aligned pointers.  This
dnl should also check whether it is actually faster to do so.  Note that on
dnl the ARM processor it works, but the pointer is truncated, overwriting
dnl what is in front of it.  The current check validates this.
dnl
dnl Seems we can better play safe and set this to yes on for the Intel
dnl processors and no otherwise.  On some systems it works, but is sloooow,
dnl on others it works kind-of, but not relyable, etc.  I've left the
dnl old test for reference.

AC_MSG_CHECKING("unaligned access")
AC_TRY_RUN(
[
#include <inttypes.h>
  main()
  { char l[sizeof(intptr_t)*2];
    intptr_t *p;

#if defined(__alpha__) || defined(__alpha) || defined(__ia64__) || defined(__sparc__)
    exit(1);
#endif

    l[0] = 10;
    p = (intptr_t *)(l+1);
    *p = 0x20406080;

    if ( l[0] == 10 && *p == 0x20406080 )
    {
#if defined(__i386__)
      exit(0);
#endif
    }

    exit(1);
  }
],
AC_MSG_RESULT(allowed)
AC_DEFINE(NON_ALIGNED_ACCESS, 1,
	  [Define if it is allowed to access intptr_t integers with non-aligned pointers]),
AC_MSG_RESULT(not allowed),
AC_MSG_RESULT(assuming not allowed))

if test "$ac_cv_func_getrlimit" = "yes"; then
AC_MSG_CHECKING("type rlim_t")
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
],
[ rlim_t datasize;
], AC_DEFINE(HAVE_RLIM_T, 1,
	     [Define if the type rlim_t is defined by <sys/resource.h>])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi

if test "$ac_cv_func_getrusage" = "yes"; then
AC_MSG_CHECKING("ru_idrss in struct rusage")
AC_TRY_COMPILE(
[
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
],
[ static struct rusage usage;
  unsigned long rss;

  rss = usage.ru_idrss;
], AC_DEFINE(HAVE_RU_IDRSS, 1,
	     [Define if struct rusage contains the field ru_idrss])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi

AC_MSG_CHECKING("whether assert.h needs stdio.h")
AC_TRY_COMPILE(
[
#include <assert.h>
],
[ assert(1);
], AC_MSG_RESULT(no),
   AC_MSG_RESULT(yes);
   AC_DEFINE(ASSERT_H_REQUIRES_STDIO_H, 1,
	     [Define if <assert.h> requires <stdio.h>]))

AC_CHECKING("for including sys/ioctl.h after sys/termios.h")
if test "$GCC" = "yes"; then
    ac_oldcflags="$CFLAGS"
    CFLAGS="$CFLAGS -Werror"
fi
AC_TRY_COMPILE(
[
#include <stdio.h>
#include <sys/types.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
],
[;
], true, AC_DEFINE(NO_SYS_IOCTL_H_WITH_SYS_TERMIOS_H, 1,
		   [Define if <sys/ioctl> should *not* be included after <sys/termios.h>]))
if test "$GCC" = "yes"; then CFLAGS="$ac_oldcflags"; fi

if test -z "$ac_cv_header_sys_termio_h" -a -z "$ac_cv_header_sys_termios_h"; then
AC_MSG_CHECKING("struct sgttyb")
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <sys/ioctl.h>
],
[ struct sgttyb buf;
  ;
], AC_DEFINE(HAVE_SGTTYB, 1,
	     [Define if you don't have termio(s), but struct sgttyb])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))
fi


AC_MSG_CHECKING("for type uchar")
AC_TRY_COMPILE(
[
#include <sys/types.h>
typedef unsigned char uchar;
],
[;], AC_DEFINE(NEED_UCHAR, 1, Define if uchar is not defined in <sys/types.h>)
     AC_MSG_RESULT("need typedef uchar"),
     AC_MSG_RESULT("uchar predefined"))

AC_MSG_CHECKING("whether we need extern int errno")
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
],
[ return errno;
], AC_MSG_RESULT(no),
   AC_DEFINE(NEED_DECL_ERRNO, 1,
	     [Define if, in addition to <errno.h>, extern int errno; is needed])
   AC_MSG_RESULT(yes))

AC_MSG_CHECKING("for symbolic links")
if test "$MINGW" = false && touch conftest.x && ln -s conftest.x conftest.lns && cmp conftest.x conftest.lns; then
    AC_DEFINE(HAVE_SYMLINKS, 1,
	      [Define if the ln command supports -s])
    AC_MSG_RESULT(yes)
else
    AC_MSG_RESULT(no)
fi

AC_TYPE_SIGNAL
AC_MSG_CHECKING("for BSD signal handlers")
AC_TRY_RUN(
[
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
static int signalled;
static RETSIGTYPE catch (s) int s; { signalled = 1; }
main()
{ signal(SIGINT, catch);
  kill(getpid(), SIGINT);
  while(!signalled)
    sleep(1);
  if ( signal(SIGINT, catch) == catch )
    exit(0);
  exit(1);
}], AC_DEFINE(BSD_SIGNALS, 1,
	      [Define if BSD compatible signals (i.e. no reset when fired)])
    AC_MSG_RESULT("BSD signals"),
    AC_MSG_RESULT("Posix signals"),
    AC_MSG_RESULT("assuming Posix signals"))

AC_MSG_CHECKING("for SIGPROF profiler support")
AC_TRY_RUN([
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#include <signal.h>
int n; /*global to avoid optimizing too much */
int done;
typedef RETSIGTYPE (*handler_t)(int);

static RETSIGTYPE
prof(int s)
{ done++;

#if !defined(BSD_SIGNALS) && !defined(HAVE_SIGACTION)
  signal(SIGPROF, prof);
#endif
}

handler_t
set_sighandler(int sig, handler_t func)
{
#ifdef HAVE_SIGACTION
  struct sigaction old;
  struct sigaction new;

  memset(&new, 0, sizeof(new));	/* deal with other fields */
  new.sa_handler = func;

  if ( sigaction(sig, &new, &old) == 0 )
    return old.sa_handler;
  else
    return SIG_DFL;
#else
  return signal(sig, func);
#endif
}

main()
{ struct itimerval value, ovalue;
  time_t t0 = time(NULL);
  int i;
  value.it_interval.tv_sec  = 0;
  value.it_interval.tv_usec = 1000;
  value.it_value.tv_sec  = 0;
  value.it_value.tv_usec = 1000;

  set_sighandler(SIGPROF, prof);

  if (setitimer(ITIMER_PROF, &value, &ovalue) != 0)
    exit(1);

  for(;;)
  { for(n=0; n<50000000; n++)
      ;
    if ( time(NULL) > t0+1 )
      break;
  }
  if ( done )
  { printf("(%d interrupts) ", done);
    exit(0);
  } else
    exit(1);
}], AC_DEFINE(O_PROFILE, 1, Define if SIGPROF and setitimer() are available)
    AC_MSG_RESULT(yes),
    AC_MSG_RESULT(no),
    true)

AC_MSG_CHECKING("for union wait")
AC_TRY_COMPILE(
[
#include <sys/wait.h>
],
[ union wait status;
  waitpid(1, &status, WNOHANG);
], AC_MSG_RESULT(yes)
   AC_DEFINE(UNION_WAIT, 1,
	     [Define if wait() uses union wait]),
   AC_MSG_RESULT(no))

AC_MSG_CHECKING("for tagged lvalues")
AC_TRY_COMPILE(
[
],
[ int x;
  *(char *)&x = 'a';
  exit(0);
], AC_DEFINE(TAGGED_LVALUE, 1, [Define if (type)var = value is allowed])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

AC_MSG_CHECKING("for label addresses")
AC_TRY_COMPILE(
[
],
[ int x=0;
  void *addr;

#ifdef __llvm__
  ERROR: Label addresses compile on LLVM, but they are *very* slow.
#endif

  addr = &&label2;
  goto *addr;

  label1:
	x = 1;
	goto label3;
  label2:
	x = 2;

  label3:
	if ( x == 2 )
	  exit(0);

        exit(1);
], AC_DEFINE(O_LABEL_ADDRESSES, 1,
	     [Define to 1 if &&label and goto *var is supported (GCC-2)])
   AC_MSG_RESULT(yes),
   AC_DEFINE(O_LABEL_ADDRESSES, 0)
   AC_MSG_RESULT(no))


dnl ****************************************************************
dnl Very specific SWI-Prolog tests.
dnl ****************************************************************

dnl ****************************************************************
dnl Test whether we can use asm("nop") to separate instructions.
dnl Needed for gcc version 2 (see pl-wam.c)
dnl ****************************************************************

AC_MSG_CHECKING("for nop");
echo '#include "confdefs.h"' > conftest.c
cat $srcdir/test/nop.c >> conftest.c
(eval $ac_link) 2>&5
if test -s conftest && eval `./conftest`; then
    AC_MSG_RESULT(yes)
else
    AC_DEFINE(NO_ASM_NOP, 1,
	      "Define if you can't use asm("nop") to separate two labels")
    AC_MSG_RESULT(no)
fi
rm -fr conftest*


if test "$ac_cv_func_mmap" = "yes"; then
  AC_MSG_CHECKING("whether mmap maps regular files")
  echo "dummy file" >> conftest.dummy
  AC_TRY_RUN(
  [
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifndef MAP_FAILED
#define MAP_FAILED ((void *)-1)
#endif
#ifndef MAP_NORESERVE
#define MAP_NORESERVE 0
#endif

    main()
    { int fd = open("conftest.dummy", O_RDONLY);
      void *ptr;

      ptr = mmap(NULL, 100,
		 PROT_READ,
		 MAP_SHARED|MAP_NORESERVE,
		 fd,
		 0);

      if ( ptr == MAP_FAILED )
        exit(1);
      exit(0);
    }
  ],
  AC_MSG_RESULT(yes)
  AC_DEFINE(CAN_MMAP_FILES, 1,
	    Define if regular files can be mapped),
  AC_MSG_RESULT(no),
  AC_DEFINE(CAN_MMAP_FILES)
  AC_MSG_RESULT(assuming yes))
rm -f conftest.dummy
fi


dnl ****************************************************************
dnl Are our signal handler is POSIX.1b?
dnl ****************************************************************

AC_CHECK_HEADERS(siginfo.h)

AC_MSG_CHECKING("for SA_SIGINFO");
AC_TRY_COMPILE(
[ #include <signal.h>
  #ifdef HAVE_SIGINFO_H
  #include <siginfo.h>
  #endif
  extern void handler(int sig, siginfo_t *info, void *);
],
[ struct sigaction act;

  act.sa_sigaction = handler;
  act.sa_flags = SA_SIGINFO;

  sigaction(SIGSEGV, (void *)0, &act);
], AC_DEFINE(HAVE_SIGINFO, 1,
	     [Define if signal handler is compliant to POSIX.1b])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))


dnl ================================================================
dnl LNLIBS is the set of libraries you need for linking with the SWI-Prolog
dnl kernel.  If this kernel is a shared object, this is typically empty.
dnl If the kernel is a static library it is the set of libraries needed
dnl by the static library.

if test "$MKSHARED" = yes; then
  MKLIBS="$MKLIBS sharedlib"
  CMFLAGS="$CMFLAGS $SO_PIC"
  LDFLAGS="$LDFLAGS $SO_PATH"
  LNLIBS=""
  AC_DEFINE(O_SHARED_KERNEL, 1,
	    "Define if Prolog kernel is in shared object")
else
  CHRPATH=":"
  LNLIBS="$LIBS"
fi dnl MKSHARED

dnl ================================================================

echo "	CFLAGS=$CWFLAGS $COFLAGS $CIFLAGS $CMFLAGS"
echo "	LDFLAGS=$LDFLAGS"
echo "	LIBS=$LIBS"

OutputFiles="Makefile rc/Makefile libtai/Makefile ../man/Makefile ../man/correctindex swipl.1 swipl.sh swipl.pc"

case "$PLARCH" in
    i386-win32|x64-win64)
        OutputFiles="$OutputFiles os/windows/Makefile win32/console/Makefile"
	;;
esac

# Prepare the package configuration if present

if test -r ../packages/Makefile.in; then
  OutputFiles="$OutputFiles ../packages/Makefile ../packages/swipl-ld.sh ../packages/swipl.sh"
fi

if test -r ../packages/configure.in; then
  OutputFiles="$OutputFiles ../packages/configure ../packages/Makefile.defs ../packages/Dialect.defs"
fi

AC_CONFIG_COMMANDS([exe],
		   [ if test -r ../packages/configure; then
		       chmod +x ../packages/configure
		       chmod +x ../packages/swipl-ld.sh
		       chmod +x ../packages/swipl.sh
		       chmod +x ../man/correctindex
		     fi
		     chmod +x swipl.sh
		   ])
AC_OUTPUT($OutputFiles)

if test "$readline_ok" = no; then
cat << _EOM_
****************************************************************
* Could not find a working readline library.  Without this library
* command-line editing is not supported.  You can continue building
* SWI-Prolog or first install readline.  After installing
* readline do "make distclean" and re-configure SWI-Prolog.
*
* On SuSE Linux, readline is in the RPM package readline-devel
****************************************************************

_EOM_
fi

if test "$WARN_NO_GMP" = yes; then
cat << _EOM_
****************************************************************
* Could not find libgmp or gmp.h.  GMP enables SWI-Prolog
* support for unbounded integer arithmetic and rational numbers.
*
* See README.gmp for details.
****************************************************************

_EOM_
fi

cat << _EOM_
****************************************************************
* Now type the following to make and install the basic environment
*
*	% make
*	% make install
*
* To complete the environment, goto the packages directory and check
* the README file for further instructions.
****************************************************************

_EOM_