Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
dnl This file is included into all any other acinclude file that needs
dnl to use these macros.

dnl This is copied from autoconf 2.12, but does calls our own AC_PROG_CC_WORKS,
dnl and doesn't call AC_PROG_CXX_GNU, cause we test for that in  AC_PROG_CC_WORKS.
dnl We are probably using a cross compiler, which will not be able to fully
dnl link an executable.  This should really be fixed in autoconf itself.
dnl Find a working G++ cross compiler. This only works for the GNU C++ compiler.
AC_DEFUN([CYG_AC_PROG_CXX_CROSS],
[AC_BEFORE([$0], [AC_PROG_CXXCPP])
AC_CHECK_PROGS(CXX, $CCC c++ g++ gcc CC cxx cc++, gcc)

CYG_AC_PROG_GXX_WORKS

if test $ac_cv_prog_gxx = yes; then
  GXX=yes
dnl Check whether -g works, even if CXXFLAGS is set, in case the package
dnl plays around with CXXFLAGS (such as to build both debugging and
dnl normal versions of a library), tasteless as that idea is.
  ac_test_CXXFLAGS="${CXXFLAGS+set}"
  ac_save_CXXFLAGS="$CXXFLAGS"
  CXXFLAGS=
  AC_PROG_CXX_G
  if test "$ac_test_CXXFLAGS" = set; then
    CXXFLAGS="$ac_save_CXXFLAGS"
  elif test $ac_cv_prog_cxx_g = yes; then
    CXXFLAGS="-g -O2"
  else
    CXXFLAGS="-O2"
  fi
else
  GXX=
  test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
fi
])

dnl See if the G++ compiler we found works.
AC_DEFUN([CYG_AC_PROG_GXX_WORKS],
[AC_MSG_CHECKING([whether the G++ compiler ($CXX $CXXFLAGS $LDFLAGS) actually works])
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
dnl Try a test case. We only compile, because it's close to impossible
dnl to get a correct fully linked executable with a cross compiler. For
dnl most cross compilers, this test is bogus. For G++, we can use various
dnl other compile line options to get a decent idea that the cross compiler
dnl actually does work, even though we can't produce an executable without
dnl more info about the target it's being compiled for. This only works
dnl for the GNU C++ compiler.

dnl Transform the name of the compiler to it's cross variant, unless
dnl CXX is set. This is also what CXX gets set to in the generated
dnl Makefile.
if test x"${CXX}" = xc++ ; then
    CXX=`echo gcc | sed -e "${program_transform_name}"`
fi

dnl Get G++'s full path to libgcc.a
libgccpath=`${CXX} --print-libgcc`

dnl If we don't have a path with libgcc.a on the end, this isn't G++.
if test `echo $libgccpath | sed -e 's:/.*/::'` = libgcc.a ; then
   ac_cv_prog_gxx=yes
else
   ac_cv_prog_gxx=no
fi

dnl If we are using G++, look for the files that need to exist if this
dnl compiler works.
if test x"${ac_cv_prog_gxx}" = xyes ; then
    gccfiles=`echo $libgccpath | sed -e 's:/libgcc.a::'`
    if test -f ${gccfiles}/specs -a -f ${gccfiles}/cpp -a -f ${gccfiles}/cc1plus; then
	gccfiles=yes
    else
	gccfiles=no
    fi
    gcclibs=`echo $libgccpath | sed -e 's:lib/gcc-lib/::' -e 's:/libgcc.a::' -e 's,\(.*\)/.*,\1,g'`/lib
    if test -d ${gcclibs}/ldscripts -a -f ${gcclibs}/libc.a -a -f ${gcclibs}/libstdc++.a ; then
	gcclibs=yes
    else
	gcclibs=no
    fi
fi

dnl If everything is OK, then we can safely assume the compiler works.
if test x"${gccfiles}" = xno -o x"${gcclibs}" = xno; then
    ac_cv_prog_cxx_works=no
    AC_MSG_ERROR(${CXX} is a non-working cross compiler)
else
   ac_cv_prog_cxx_works=yes 
fi

AC_LANG_RESTORE
AC_MSG_RESULT($ac_cv_prog_cxx_works)
if test x"$ac_cv_prog_cxx_works" = xno; then
  AC_MSG_ERROR([installation or configuration problem: C++ compiler cannot create executables.])
fi
AC_MSG_CHECKING([whether the G++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler])
AC_MSG_RESULT($ac_cv_prog_cxx_cross)
cross_compiling=$ac_cv_prog_cxx_cross
AC_SUBST(CXX)
])

dnl ====================================================================
dnl Find a working GCC cross compiler. This only works for the GNU gcc compiler.
dnl This is based on the macros above for G++.
AC_DEFUN([CYG_AC_PROG_CC_CROSS],
[AC_BEFORE([$0], [AC_PROG_CCPP])
AC_CHECK_PROGS(CC, cc, gcc)

CYG_AC_PROG_GCC_WORKS

if test $ac_cv_prog_gcc = yes; then
  GCC=yes
dnl Check whether -g works, even if CFLAGS is set, in case the package
dnl plays around with CFLAGS (such as to build both debugging and
dnl normal versions of a library), tasteless as that idea is.
  ac_test_CFLAGS="${CFLAGS+set}"
  ac_save_CFLAGS="$CFLAGS"
  CFLAGS=
  AC_PROG_CC_G
  if test "$ac_test_CFLAGS" = set; then
    CFLAGS="$ac_save_CFLAGS"
  elif test $ac_cv_prog_cc_g = yes; then
    CFLAGS="-g -O2"
  else
    CFLAGS="-O2"
  fi
else
  GXX=
  test "${CFLAGS+set}" = set || CFLAGS="-g"
fi
])

dnl See if the GCC compiler we found works.
AC_DEFUN([CYG_AC_PROG_GCC_WORKS],
[AC_MSG_CHECKING([whether the Gcc compiler ($CC $CFLAGS $LDFLAGS) actually works])
AC_LANG_SAVE
AC_LANG_C
dnl Try a test case. We only compile, because it's close to impossible
dnl to get a correct fully linked executable with a cross
dnl compiler. For most cross compilers, this test is bogus. For G++,
dnl we can use various other compile line options to get a decent idea
dnl that the cross compiler actually does work, even though we can't
dnl produce an executable without more info about the target it's
dnl being compiled for. This only works for the GNU C++ compiler.

dnl Transform the name of the compiler to it's cross variant, unless
dnl CXX is set. This is also what CC gets set to in the generated Makefile.
if test x"${CC}" = xcc ; then
    CC=`echo gcc | sed -e "${program_transform_name}"`
fi

dnl Get Gcc's full path to libgcc.a
libgccpath=`${CC} --print-libgcc`

dnl If we don't have a path with libgcc.a on the end, this isn't G++.
if test `echo $libgccpath | sed -e 's:/.*/::'` = libgcc.a ; then
   ac_cv_prog_gcc=yes
else
   ac_cv_prog_gcc=no
fi

dnl If we are using Gcc, look for the files that need to exist if this
dnl compiler works.
if test x"${ac_cv_prog_gcc}" = xyes ; then
    gccfiles=`echo $libgccpath | sed -e 's:/libgcc.a::'`
    if test -f ${gccfiles}/specs -a -f ${gccfiles}/cpp -a -f ${gccfiles}/cc1plus; then
	gccfiles=yes
    else
	gccfiles=no
    fi
    gcclibs=`echo $libgccpath | sed -e 's:lib/gcc-lib/::' -e 's:/libgcc.a::' -e 's,\(.*\)/.*,\1,g'`/lib
    if test -d ${gcclibs}/ldscripts -a -f ${gcclibs}/libc.a -a -f ${gcclibs}/libstdc++.a ; then
	gcclibs=yes
    else
	gcclibs=no
    fi
fi

dnl If everything is OK, then we can safely assume the compiler works.
if test x"${gccfiles}" = xno -o x"${gcclibs}" = xno; then
    ac_cv_prog_cc_works=no
    AC_MSG_ERROR(${CC} is a non-working cross compiler)    
else
    ac_cv_prog_cc_works=yes
fi

AC_LANG_RESTORE
AC_MSG_RESULT($ac_cv_prog_cc_works)
if test x"$ac_cv_prog_cc_works" = xno; then
  AC_MSG_ERROR([installation or configuration problem: C++ compiler cannot create executables.])
fi
AC_MSG_CHECKING([whether the Gcc compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler])
AC_MSG_RESULT($ac_cv_prog_cc_cross)
cross_compiling=$ac_cv_prog_cc_cross
AC_SUBST(CC)
])

dnl ====================================================================
dnl Find the BFD library in the build tree. This is used to access and
dnl manipulate object or executable files.
AC_DEFUN([CYG_AC_PATH_BFD], [
AC_MSG_CHECKING(for the bfd header in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
dnl Look for the header file
AC_CACHE_VAL(ac_cv_c_bfdh,[
for i in $dirlist; do
    if test -f "$i/bfd/bfd.h" ; then
	ac_cv_c_bfdh=`(cd $i/bfd; ${PWDCMD-pwd})`
	break
    fi
done
])
if test x"${ac_cv_c_bfdh}" != x; then
    BFDHDIR="-I${ac_cv_c_bfdh}"
    AC_MSG_RESULT(${ac_cv_c_bfdh})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(BFDHDIR)

dnl Look for the library
AC_MSG_CHECKING(for the bfd library in the build tree)
AC_CACHE_VAL(ac_cv_c_bfdlib,[
for i in $dirlist; do
    if test -f "$i/bfd/Makefile" ; then
	ac_cv_c_bfdlib=`(cd $i/bfd; ${PWDCMD-pwd})`
    fi
done
])
dnl We list two directories cause bfd now uses libtool
if test x"${ac_cv_c_bfdlib}" != x; then
    BFDLIB="-L${ac_cv_c_bfdlib} -L${ac_cv_c_bfdlib}/.libs"
    AC_MSG_RESULT(${ac_cv_c_bfdlib})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(BFDLIB)
])

dnl ====================================================================
dnl Find the libiberty library. This defines many commonly used C
dnl functions that exists in various states based on the underlying OS.
AC_DEFUN([CYG_AC_PATH_LIBERTY], [
AC_MSG_CHECKING(for the liberty library in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_liberty,[
for i in $dirlist; do
    if test -f "$i/libiberty/Makefile" ; then
	ac_cv_c_liberty=`(cd $i/libiberty; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_liberty}" != x; then
    LIBERTY="-L${ac_cv_c_liberty}"
    AC_MSG_RESULT(${ac_cv_c_liberty})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(LIBERTY)
])

dnl ====================================================================
dnl Find the opcodes library. This is used to do dissasemblies.
AC_DEFUN([CYG_AC_PATH_OPCODES], [
AC_MSG_CHECKING(for the opcodes library in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_opc,[
for i in $dirlist; do
    if test -f "$i/opcodes/Makefile" ; then
	ac_cv_c_opc=`(cd $i/opcodes; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_opc}" != x; then
    OPCODESLIB="-L${ac_cv_c_opc}"
    AC_MSG_RESULT(${ac_cv_c_opc})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(OPCODESLIB)
])

dnl ====================================================================
dnl Look for the DejaGnu header file in the source tree. This file
dnl defines the functions used to testing support.
AC_DEFUN([CYG_AC_PATH_DEJAGNU], [
AC_MSG_CHECKING(for the testing support files in the source tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_dejagnu,[
for i in $dirlist; do
    if test -f "$srcdir/$i/ecc/ecc/infra/testlib/current/include/dejagnu.h" ; then
	ac_cv_c_dejagnu=`(cd $srcdir/$i/ecc/ecc/infra/testlib/current/include; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_dejagnu}" != x; then
    DEJAGNUHDIR="-I${ac_cv_c_dejagnu}"
    AC_MSG_RESULT(${ac_cv_c_dejagnu})
else
    AC_MSG_RESULT(none)
fi
AC_CACHE_VAL(ac_cv_c_dejagnulib,[
for i in $dirlist; do
    if test -f "$srcdir/$i/infra/testlib/current/lib/hostutil.exp" ; then
	ac_cv_c_dejagnulib=`(cd $srcdir/$i/infra/testlib/current/lib; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_dejagnulib}" != x; then
    DEJAGNULIB="${ac_cv_c_dejagnulib}"
else
    DEJAGNULIB=""
fi
AC_MSG_CHECKING(for runtest in the source tree)
AC_CACHE_VAL(ac_cv_c_runtest,[
for i in $dirlist; do
    if test -f "$srcdir/$i/dejagnu/runtest" ; then
	ac_cv_c_runtest=`(cd $srcdir/$i/dejagnu; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_runtest}" != x; then
    RUNTESTDIR="${ac_cv_c_runtest}"
   AC_MSG_RESULT(${ac_cv_c_runtest})
else
    RUNTESTDIR=""
    AC_MSG_RESULT(none)
fi
AC_SUBST(RUNTESTDIR)
AC_SUBST(DEJAGNULIB)
AC_SUBST(DEJAGNUHDIR)
])

dnl ====================================================================
dnl Find the libintl library in the build tree. This is for
dnl  internationalization support.
AC_DEFUN([CYG_AC_PATH_INTL], [
AC_MSG_CHECKING(for the intl header in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
dnl Look for the header file
AC_CACHE_VAL(ac_cv_c_intlh,[
for i in $dirlist; do
    if test -f "$i/intl/libintl.h" ; then
	ac_cv_c_intlh=`(cd $i/intl; ${PWDCMD-pwd})`
	break
    fi
done
])
if test x"${ac_cv_c_intlh}" != x; then
    INTLHDIR="-I${ac_cv_c_intlh}"
    AC_MSG_RESULT(${ac_cv_c_intlh})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(INTLHDIR)

dnl Look for the library
AC_MSG_CHECKING(for the libintl library in the build tree)
AC_CACHE_VAL(ac_cv_c_intllib,[
for i in $dirlist; do
    if test -f "$i/intl/Makefile" ; then
	ac_cv_c_intllib=`(cd $i/intl; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_intllib}" != x; then
    INTLLIB="-L${ac_cv_c_intllib} -lintl"
    AC_MSG_RESULT(${ac_cv_c_intllib})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(INTLLIB)
])

dnl ====================================================================
dnl Find the simulator library.
AC_DEFUN([CYG_AC_PATH_SIM], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.. ../../../../../../../../../.."
case "$target_cpu" in
    powerpc)	target_dir=ppc ;;
    sparc*)	target_dir=erc32 ;;
    mips*)	target_dir=mips ;;
    *)		target_dir=$target_cpu ;;
esac
dnl First look for the header file
AC_MSG_CHECKING(for the simulator header file)
AC_CACHE_VAL(ac_cv_c_simh,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/include/remote-sim.h" ; then
	ac_cv_c_simh=`(cd ${srcdir}/$i/include; ${PWDCMD-pwd})`
	break
    fi
done
])
if test x"${ac_cv_c_simh}" != x; then
    SIMHDIR="-I${ac_cv_c_simh}"
    AC_MSG_RESULT(${ac_cv_c_simh})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(SIMHDIR)

dnl See whether it's a devo or Foundry branch simulator
AC_MSG_CHECKING(Whether this is a devo simulator )
AC_CACHE_VAL(ac_cv_c_simdevo,[
    CPPFLAGS="$CPPFLAGS $SIMHDIR"
    AC_EGREP_HEADER([SIM_DESC sim_open.*struct _bfd], remote-sim.h,
        ac_cv_c_simdevo=yes,
        ac_cv_c_simdevo=no)
])
if test x"$ac_cv_c_simdevo" = x"yes" ; then
    AC_DEFINE(HAVE_DEVO_SIM)
fi
AC_MSG_RESULT(${ac_cv_c_simdevo})
AC_SUBST(HAVE_DEVO_SIM)

dnl Next look for the library
AC_MSG_CHECKING(for the simulator library)
AC_CACHE_VAL(ac_cv_c_simlib,[
for i in $dirlist; do
    if test -f "$i/sim/$target_dir/Makefile" ; then
	ac_cv_c_simlib=`(cd $i/sim/$target_dir; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_simlib}" != x; then
    SIMLIB="-L${ac_cv_c_simlib}"
else
    AC_MSG_RESULT(none)
    dnl FIXME: this is kinda bogus, cause umtimately the TM will build
    dnl all the libraries for several architectures. But for now, this
    dnl will work till then.
dnl     AC_MSG_CHECKING(for the simulator installed with the compiler libraries)
    dnl Transform the name of the compiler to it's cross variant, unless
    dnl CXX is set. This is also what CXX gets set to in the generated
    dnl Makefile.
    CROSS_GCC=`echo gcc | sed -e "s/^/$target/"`

    dnl Get G++'s full path to libgcc.a
changequote(,)
    gccpath=`${CROSS_GCC} --print-libgcc | sed -e 's:[a-z0-9A-Z\.\-]*/libgcc.a::' -e 's:lib/gcc-lib/::'`lib
changequote([,])
    if test -f $gccpath/libsim.a -o -f $gccpath/libsim.so ; then
        ac_cv_c_simlib="$gccpath/"
        SIMLIB="-L${ac_cv_c_simlib}"
	AC_MSG_RESULT(${ac_cv_c_simlib})
    else
        AM_CONDITIONAL(PSIM, test x$psim = xno)
	SIMLIB=""
	AC_MSG_RESULT(none)
dnl         ac_cv_c_simlib=none
    fi
fi
AC_SUBST(SIMLIB)
])

dnl ====================================================================
dnl Find the libiberty library.
AC_DEFUN([CYG_AC_PATH_LIBIBERTY], [
AC_MSG_CHECKING(for the libiberty library in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_libib,[
for i in $dirlist; do
    if test -f "$i/libiberty/Makefile" ; then
	ac_cv_c_libib=`(cd $i/libiberty/; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_libib}" != x; then
    LIBIBERTY="-L${ac_cv_c_libib}"
    AC_MSG_RESULT(${ac_cv_c_libib})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(LIBIBERTY)
])

dnl ====================================================================
AC_DEFUN([CYG_AC_PATH_DEVO], [
AC_MSG_CHECKING(for devo headers in the source tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_devoh,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/include/remote-sim.h" ; then
	ac_cv_c_devoh=`(cd ${srcdir}/$i/include; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_devoh}" != x; then
    DEVOHDIR="-I${ac_cv_c_devoh}"
    AC_MSG_RESULT(${ac_cv_c_devoh})
else
    AC_MSG_RESULT(none)
fi
AC_SUBST(DEVOHDIR)
])

dnl ====================================================================
dnl find the IDE library and headers.
AC_DEFUN([CYG_AC_PATH_IDE], [
AC_MSG_CHECKING(for IDE headers in the source tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
IDEHDIR=
IDELIB=
AC_CACHE_VAL(ac_cv_c_ideh,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/libide/src/event.h" ; then
	ac_cv_c_ideh=`(cd ${srcdir}/$i/libide/src; ${PWDCMD-pwd})`;
    fi
done
])
if test x"${ac_cv_c_ideh}" != x; then
    IDEHDIR="-I${ac_cv_c_ideh}"
    AC_MSG_RESULT(${ac_cv_c_ideh})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for LIBIDE TCL headers in the source tree)
AC_CACHE_VAL(ac_cv_c_idetclh,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/libidetcl/src/idetcl.h" ; then
	ac_cv_c_idetclh=`(cd ${srcdir}/$i/libidetcl/src; ${PWDCMD-pwd})`;
    fi
done
])
if test x"${ac_cv_c_idetclh}" != x; then
    IDEHDIR="${IDEHDIR} -I${ac_cv_c_idetclh}"
    AC_MSG_RESULT(${ac_cv_c_idetclh})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for IDE headers in the build tree)
AC_CACHE_VAL(ac_cv_c_ideh2,[
for i in $dirlist; do
    if test -f "$i/libide/src/Makefile" ; then
	ac_cv_c_ideh2=`(cd $i/libide/src; ${PWDCMD-pwd})`;
    fi
done
])
if test x"${ac_cv_c_ideh2}" != x; then
    IDEHDIR="${IDEHDIR} -I${ac_cv_c_ideh2}"
    AC_MSG_RESULT(${ac_cv_c_ideh2})
else
    AC_MSG_RESULT(none)
fi

dnl look for the library
AC_MSG_CHECKING(for IDE library)
AC_CACHE_VAL(ac_cv_c_idelib,[
if test x"${ac_cv_c_idelib}" = x ; then
    for i in $dirlist; do
      if test -f "$i/libide/src/Makefile" ; then
        ac_cv_c_idelib=`(cd $i/libide/src; ${PWDCMD-pwd})`
        break
      fi
    done
fi]) 
if test x"${ac_cv_c_idelib}" != x ; then
     IDELIB="-L${ac_cv_c_idelib}"
     AC_MSG_RESULT(${ac_cv_c_idelib})
else
     AC_MSG_RESULT(none)
fi

dnl find libiddetcl.a if it exists
AC_MSG_CHECKING(for IDE TCL library)
AC_CACHE_VAL(ac_cv_c_idetcllib,[
if test x"${ac_cv_c_idetcllib}" = x ; then
    for i in $dirlist; do
      if test -f "$i/libidetcl/src/Makefile" ; then
        ac_cv_c_idetcllib=`(cd $i/libidetcl/src; ${PWDCMD-pwd})`
        break
      fi
    done
fi
]) 
if test x"${ac_cv_c_idetcllib}" != x ; then
     IDELIB="${IDELIB} -L${ac_cv_c_idetcllib}"
     IDETCLLIB="-lidetcl"
     AC_MSG_RESULT(${ac_cv_c_idetcllib})
else
     AC_MSG_RESULT(none)
fi
AC_SUBST(IDEHDIR)
AC_SUBST(IDELIB)
AC_SUBST(IDETCLLIB)
])

dnl ====================================================================
dnl Find all the ILU headers and libraries
AC_DEFUN([CYG_AC_PATH_ILU], [
AC_MSG_CHECKING(for ILU kernel headers in the source tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_iluh,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/ilu/runtime/kernel/method.h" ; then
	ac_cv_c_iluh=`(cd ${srcdir}/$i/ilu/runtime/kernel; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_iluh}" != x; then
    ILUHDIR="-I${ac_cv_c_iluh}"
    AC_MSG_RESULT(${ac_cv_c_iluh})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for ILU kernel headers in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
AC_CACHE_VAL(ac_cv_c_iluh5,[
for i in $dirlist; do
    if test -f "$i/ilu/runtime/kernel/iluconf.h" ; then
	ac_cv_c_iluh5=`(cd $i/ilu/runtime/kernel; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_iluh5}" != x; then
    ILUHDIR="${ILUHDIR} -I${ac_cv_c_iluh5}"
    AC_MSG_RESULT(${ac_cv_c_iluh5})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for ILU C++ headers in the source tree)
AC_CACHE_VAL(ac_cv_c_iluh2,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/ilu/stubbers/cpp/resource.h" ; then
	ac_cv_c_iluh2=`(cd ${srcdir}/$i/ilu/stubbers/cpp; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_iluh2}" != x; then
    ILUHDIR="${ILUHDIR} -I${ac_cv_c_iluh2}"
    AC_MSG_RESULT(${ac_cv_c_iluh2})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for ILU C headers)
AC_CACHE_VAL(ac_cv_c_iluh3,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/ilu/stubbers/c/resource.h" ; then
	ac_cv_c_iluh3=`(cd ${srcdir}/$i/ilu/stubbers/c  ; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_iluh3}" != x; then
    ILUHDIR="${ILUHDIR} -I${ac_cv_c_iluh3}"
    AC_MSG_RESULT(${ac_cv_c_iluh3})
else
    AC_MSG_RESULT(none)
fi

AC_MSG_CHECKING(for ILU C runtime headers)
AC_CACHE_VAL(ac_cv_c_iluh4,[
for i in $dirlist; do
    if test -f "${srcdir}/$i/ilu/runtime/c/ilucstub.h" ; then
	ac_cv_c_iluh4=`(cd ${srcdir}/$i/ilu/runtime/c  ; ${PWDCMD-pwd})`
    fi
done
])
if test x"${ac_cv_c_iluh4}" != x; then
    ILUHDIR="${ILUHDIR} -I${ac_cv_c_iluh4}"
    AC_MSG_RESULT(${ac_cv_c_iluh4})
else
    AC_MSG_RESULT(none)
fi

AC_CACHE_VAL(ac_cv_c_ilupath,[
for i in $dirlist; do
    if test -f "$i/ilu/Makefile" ; then
	ac_cv_c_ilupath=`(cd $i/ilu; ${PWDCMD-pwd})`
	break
    fi
done
])
ILUTOP=${ac_cv_c_ilupath}

AC_MSG_CHECKING(for the ILU library in the build tree)
AC_CACHE_VAL(ac_cv_c_ilulib,[
if test -f "$ac_cv_c_ilupath/runtime/kernel/Makefile" ; then
    ac_cv_c_ilulib=`(cd $ac_cv_c_ilupath/runtime/kernel; ${PWDCMD-pwd})`
    AC_MSG_RESULT(found ${ac_cv_c_ilulib}/libilu.a)
else
    AC_MSG_RESULT(no)
fi])
   
AC_MSG_CHECKING(for the ILU C++ bindings library in the build tree)
AC_CACHE_VAL(ac_cv_c_ilulib2,[
if test -f "$ac_cv_c_ilupath/runtime/cpp/Makefile" ; then
    ac_cv_c_ilulib2=`(cd $ac_cv_c_ilupath/runtime/cpp; ${PWDCMD-pwd})`
    AC_MSG_RESULT(found ${ac_cv_c_ilulib2}/libilu-c++.a)
else
    AC_MSG_RESULT(no)
fi])

AC_MSG_CHECKING(for the ILU C bindings library in the build tree)
AC_CACHE_VAL(ac_cv_c_ilulib3,[
if test -f "$ac_cv_c_ilupath/runtime/c/Makefile" ; then
    ac_cv_c_ilulib3=`(cd $ac_cv_c_ilupath/runtime/c; ${PWDCMD-pwd})`
    AC_MSG_RESULT(found ${ac_cv_c_ilulib3}/libilu-c.a)
else
    AC_MSG_RESULT(no)
fi])

AC_MSG_CHECKING(for the ILU Tk bindings library in the build tree)
AC_CACHE_VAL(ac_cv_c_ilulib4,[
if test -f "$ac_cv_c_ilupath/runtime/mainloop/Makefile" ; then
    ac_cv_c_ilulib4=`(cd $ac_cv_c_ilupath/runtime/mainloop; ${PWDCMD-pwd})`
    AC_MSG_RESULT(found ${ac_cv_c_ilulib4}/libilu-tk.a)
else
    AC_MSG_RESULT(no)
fi])

if test x"${ac_cv_c_ilulib}" = x -a x"${ac_cv_c_ilulib2}" = x; then
  ILUHDIR=""
fi

if test x"${ac_cv_c_ilulib}" != x -a x"${ac_cv_c_ilulib2}" != x; then
    ILULIB="-L${ac_cv_c_ilulib} -L${ac_cv_c_ilulib2} -L${ac_cv_c_ilulib3} -L${ac_cv_c_ilulib4}"
else
    ILULIB=""
fi

if test x"${ILULIB}" = x; then
    AC_MSG_CHECKING(for ILU libraries installed with the compiler)
    AC_CACHE_VAL(ac_cv_c_ilulib5,[
    NATIVE_GCC=`echo gcc | sed -e "${program_transform_name}"`

    dnl Get G++'s full path to it's libraries
    ac_cv_c_ilulib5=`${NATIVE_GCC} --print-libgcc | sed -e 's:lib/gcc-lib/.*::'`lib
    if test -f $ac_cv_c_ilulib5/libilu-c.a -o -f $ac_cv_c_ilulib5/libilu-c.so ; then
        if test x"${ILUHDIR}" = x; then
               ILUHDIR="-I${ac_cv_c_ilulib5}/../include"
        fi
        ILULIB="-L${ac_cv_c_ilulib5}"
        AC_MSG_RESULT(${ac_cv_c_ilulib5})
    else
        ac_cv_c_ilulib=none
        AC_MSG_RESULT(none)
    fi
fi])
AC_SUBST(ILUHDIR)
AC_SUBST(ILULIB)
AC_SUBST(ILUTOP)
])

dnl ====================================================================
dnl This defines the byte order for the host. We can't use
dnl AC_C_BIGENDIAN, cause we want to create a config file and
dnl substitue the real value, so the header files work right
AC_DEFUN([CYG_AC_C_ENDIAN], [
AC_MSG_CHECKING(to see if this is a little endian host)
AC_CACHE_VAL(ac_cv_c_little_endian, [
ac_cv_c_little_endian=unknown
# See if sys/param.h defines the BYTE_ORDER macro.
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/param.h>], [
#if !BYTE_ORDER || !_BIG_ENDIAN || !_LITTLE_ENDIAN
 bogus endian macros
#endif], [# It does; now see whether it defined to _LITTLE_ENDIAN or not.
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/param.h>], [
#if BYTE_ORDER != _LITTLE_ENDIAN
 not big endian
#endif], ac_cv_c_little_endian=yes, ac_cv_c_little_endian=no)
])
if test ${ac_cv_c_little_endian} = unknown; then
old_cflags=$CFLAGS
CFLAGS=-g
AC_TRY_RUN([
main () {
  /* Are we little or big endian?  From Harbison&Steele.  */
  union
  {
    long l;
    char c[sizeof (long)];
  } u;
  u.l = 1;
  exit (u.c[0] == 1);
}],
ac_cv_c_little_endian=no,
ac_cv_c_little_endian=yes,[
dnl Yes, this is ugly, and only used for a canadian cross anyway. This
dnl is just to keep configure from stopping here.
case "${host}" in
changequote(,)
   i[3456789]86-*-*) ac_cv_c_little_endian=yes ;;
   sparc*-*-*)    ac_cv_c_little_endian=no ;;
changequote([,])
  *)    AC_MSG_WARN(Can't cross compile this test) ;;
esac])
CFLAGS=$old_cflags
fi])

if test x"${ac_cv_c_little_endian}" = xyes; then
    AC_DEFINE(LITTLE_ENDIAN_HOST)
    ENDIAN="CYG_LSBFIRST";
else
    ENDIAN="CYG_MSBFIRST";
fi
AC_MSG_RESULT(${ac_cv_c_little_endian})
AC_SUBST(ENDIAN)
])

dnl ====================================================================
dnl Look for the path to libgcc, so we can use it to directly link
dnl in libgcc.a with LD.
AC_DEFUN([CYG_AC_PATH_LIBGCC],
[AC_MSG_CHECKING([Looking for the path to libgcc.a])
AC_LANG_SAVE
AC_LANG_C

dnl Get Gcc's full path to libgcc.a
libgccpath=`${CC} --print-libgcc`

dnl If we don't have a path with libgcc.a on the end, this isn't G++.
if test `echo $libgccpath | sed -e 's:/.*/::'` = libgcc.a ; then
   ac_cv_prog_gcc=yes
else
   ac_cv_prog_gcc=no
fi

dnl 
if test x"${ac_cv_prog_gcc}" = xyes ; then
   gccpath=`echo $libgccpath | sed -e 's:/libgcc.a::'`
   LIBGCC="-L${gccpath}"
   AC_MSG_RESULT(${gccpath})
else
   LIBGCC=""
   AC_MSG_ERROR(Not using gcc)
fi

AC_LANG_RESTORE
AC_SUBST(LIBGCC)
])

dnl ====================================================================
dnl Ok, lets find the tcl source trees so we can use the headers
dnl Warning: transition of version 9 to 10 will break this algorithm
dnl because 10 sorts before 9. We also look for just tcl. We have to
dnl be careful that we don't match stuff like tclX by accident.
dnl the alternative search directory is involked by --with-tclinclude
AC_DEFUN([CYG_AC_PATH_TCL], [
    CYG_AC_PATH_TCLH
    CYG_AC_PATH_TCLCONFIG
    CYG_AC_LOAD_TCLCONFIG
])
AC_DEFUN([CYG_AC_PATH_TCLH], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_tcl=true
AC_MSG_CHECKING(for Tcl headers in the source tree)
AC_ARG_WITH(tclinclude, [  --with-tclinclude       directory where tcl headers are], with_tclinclude=${withval})
AC_CACHE_VAL(ac_cv_c_tclh,[
dnl first check to see if --with-tclinclude was specified
if test x"${with_tclinclude}" != x ; then
  if test -f ${with_tclinclude}/tcl.h ; then
    ac_cv_c_tclh=`(cd ${with_tclinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_tclinclude}/generic/tcl.h ; then
    ac_cv_c_tclh=`(cd ${with_tclinclude}/generic; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_tclinclude} directory doesn't contain headers])
  fi
fi

dnl next check if it came with Tcl configuration file
if test x"${ac_cv_c_tclconfig}" != x ; then
  for i in $dirlist; do
    if test -f $ac_cv_c_tclconfig/$i/generic/tcl.h ; then
      ac_cv_c_tclh=`(cd $ac_cv_c_tclconfig/$i/generic; ${PWDCMD-pwd})`
      break
    fi
  done
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_tclh}" = x ; then
    dnl find the top level Tcl source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/tcl* 2>/dev/null`" ; then
	    tclpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Tcl source dir. We do it this way, cause there
    dnl might be multiple version of Tcl, and we want the most recent one.
    for i in `ls -dr $tclpath/tcl* 2>/dev/null ` ; do
        if test -f $i/generic/tcl.h ; then
          ac_cv_c_tclh=`(cd $i/generic; ${PWDCMD-pwd})`
          break
        fi
    done
fi

dnl check if its installed with the compiler
if test x"${ac_cv_c_tclh}" = x ; then
    dnl Get the path to the compiler
    ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/include
    if test -f $ccpath/tcl.h; then
        ac_cv_c_tclh=$ccpath
    fi
fi

dnl see if one is installed
if test x"${ac_cv_c_tclh}" = x ; then
   AC_MSG_RESULT(none)
   AC_CHECK_HEADER(tcl.h, ac_cv_c_tclh=installed, ac_cv_c_tclh="")
else
   AC_MSG_RESULT(${ac_cv_c_tclh})
fi
])
  TCLHDIR=""
if test x"${ac_cv_c_tclh}" = x ; then
    AC_MSG_ERROR([Can't find any Tcl headers])
fi
if test x"${ac_cv_c_tclh}" != x ; then
    no_tcl=""
    if test x"${ac_cv_c_tclh}" != x"installed" ; then
	if test x"${CC}" = xcl ; then
	    tmp="`cygpath --windows ${ac_cv_c_tclh}`"
	    ac_cv_c_tclh="`echo $tmp | sed -e s#\\\\\\\\#/#g`"
	fi
        AC_MSG_RESULT(${ac_cv_c_tclh})
        TCLHDIR="-I${ac_cv_c_tclh}"
    fi
fi

AC_SUBST(TCLHDIR)
])

dnl ====================================================================
dnl Ok, lets find the tcl configuration
AC_DEFUN([CYG_AC_PATH_TCLCONFIG], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
dnl First, look for one uninstalled.  
dnl the alternative search directory is invoked by --with-tclconfig
if test x"${no_tcl}" = x ; then
  dnl we reset no_tcl in case something fails here
    no_tcl=true
    AC_ARG_WITH(tclconfig, [  --with-tclconfig           directory containing tcl configuration (tclConfig.sh)],
         with_tclconfig=${withval})
    AC_MSG_CHECKING([for Tcl configuration script])
    AC_CACHE_VAL(ac_cv_c_tclconfig,[

    dnl First check to see if --with-tclconfig was specified.
    if test x"${with_tclconfig}" != x ; then
        if test -f "${with_tclconfig}/tclConfig.sh" ; then
            ac_cv_c_tclconfig=`(cd ${with_tclconfig}; ${PWDCMD-pwd})`
        else
            AC_MSG_ERROR([${with_tclconfig} directory doesn't contain tclConfig.sh])
        fi
    fi

    dnl next check if it came with Tcl configuration file in the source tree
    if test x"${ac_cv_c_tclconfig}" = x ; then
        for i in $dirlist; do
            dnl need to test both unix and win directories, since 
            dnl cygwin's tkConfig.sh could be in either directory depending
            dnl on the cygwin port of tcl.
            if test -f $srcdir/$i/unix/tclConfig.sh ; then
                ac_cv_c_tclconfig=`(cd $srcdir/$i/unix; ${PWDCMD-pwd})`
	        break
            fi
            if test -f $srcdir/$i/win/tclConfig.sh ; then
                ac_cv_c_tclconfig=`(cd $srcdir/$i/win; ${PWDCMD-pwd})`
	        break
            fi
        done
    fi
    dnl check in a few other locations
    if test x"${ac_cv_c_tclconfig}" = x ; then
        dnl find the top level Tcl source directory
        for i in $dirlist; do
            if test -n "`ls -dr $i/tcl* 2>/dev/null`" ; then
	        tclconfpath=$i
	        break
	    fi
        done

        dnl find the exact Tcl dir. We do it this way, cause there
        dnl might be multiple version of Tcl, and we want the most recent one.
        for i in `ls -dr $tclconfpath/tcl* 2>/dev/null ` ; do
            dnl need to test both unix and win directories, since 
            dnl cygwin's tclConfig.sh could be in either directory depending
            dnl on the cygwin port of tcl.
            if test -f $i/unix/tclConfig.sh ; then
                ac_cv_c_tclconfig=`(cd $i/unix; ${PWDCMD-pwd})`
                break
            fi
            if test -f $i/win/tclConfig.sh ; then
                ac_cv_c_tclconfig=`(cd $i/win; ${PWDCMD-pwd})`
                break
            fi
        done
    fi

    dnl Check to see if it's installed. We have to look in the $CC path
    dnl to find it, cause our $prefix may not match the compilers.
    if test x"${ac_cv_c_tclconfig}" = x ; then
        dnl Get the path to the compiler
	ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/lib
        if test -f $ccpath/tclConfig.sh; then
	    ac_cv_c_tclconfig=$ccpath
        fi
    fi
    ])	dnl end of cache_val

    if test x"${ac_cv_c_tclconfig}" = x ; then
        TCLCONFIG=""
        AC_MSG_WARN(Can't find Tcl configuration definitions)
    else
        no_tcl=""
        TCLCONFIG=${ac_cv_c_tclconfig}/tclConfig.sh
        AC_MSG_RESULT(${TCLCONFIG})
     fi
fi
AC_SUBST(TCLCONFIG)
])

dnl Defined as a separate macro so we don't have to cache the values
dnl from PATH_TCLCONFIG (because this can also be cached).
AC_DEFUN([CYG_AC_LOAD_TCLCONFIG], [
    . $TCLCONFIG

dnl AC_SUBST(TCL_VERSION)
dnl AC_SUBST(TCL_MAJOR_VERSION)
dnl AC_SUBST(TCL_MINOR_VERSION)
dnl AC_SUBST(TCL_CC)
    AC_SUBST(TCL_DEFS)

dnl not used, don't export to save symbols
    AC_SUBST(TCL_LIB_FILE)
    AC_SUBST(TCL_LIB_FULL_PATH)
    AC_SUBST(TCL_LIBS)
dnl not used, don't export to save symbols
dnl    AC_SUBST(TCL_PREFIX)

    AC_SUBST(TCL_CFLAGS)

dnl not used, don't export to save symbols
dnl    AC_SUBST(TCL_EXEC_PREFIX)

    AC_SUBST(TCL_SHLIB_CFLAGS)
    AC_SUBST(TCL_SHLIB_LD)
dnl don't export, not used outside of configure
dnl AC_SUBST(TCL_SHLIB_LD_LIBS)
dnl AC_SUBST(TCL_SHLIB_SUFFIX)
dnl not used, don't export to save symbols
dnl AC_SUBST(TCL_DL_LIBS)
    AC_SUBST(TCL_LD_FLAGS)
    AC_SUBST(TCL_LD_SEARCH_FLAGS)
dnl don't export, not used outside of configure
dnl AC_SUBST(TCL_COMPAT_OBJS)
    AC_SUBST(TCL_RANLIB)
    AC_SUBST(TCL_BUILD_LIB_SPEC)
    AC_SUBST(TCL_LIB_SPEC)
    AC_SUBST(TCL_BIN_DIR)
dnl AC_SUBST(TCL_LIB_VERSIONS_OK)

dnl not used, don't export to save symbols
dnl    AC_SUBST(TCL_SHARED_LIB_SUFFIX)

dnl not used, don't export to save symbols
dnl    AC_SUBST(TCL_UNSHARED_LIB_SUFFIX)
])

dnl ====================================================================
AC_DEFUN([CYG_AC_PATH_TK], [
    CYG_AC_PATH_TKH
    CYG_AC_PATH_TKCONFIG
    CYG_AC_LOAD_TKCONFIG
])
AC_DEFUN([CYG_AC_PATH_TKH], [
#
# Ok, lets find the tk source trees so we can use the headers
# If the directory (presumably symlink) named "tk" exists, use that one
# in preference to any others.  Same logic is used when choosing library
# and again with Tcl. The search order is the best place to look first, then in
# decreasing significance. The loop breaks if the trigger file is found.
# Note the gross little conversion here of srcdir by cd'ing to the found
# directory. This converts the path from a relative to an absolute, so
# recursive cache variables for the path will work right. We check all
# the possible paths in one loop rather than many separate loops to speed
# things up.
# the alternative search directory is involked by --with-tkinclude
#
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_tk=true
AC_MSG_CHECKING(for Tk headers in the source tree)
AC_ARG_WITH(tkinclude, [  --with-tkinclude       directory where tk headers are], with_tkinclude=${withval})
AC_CACHE_VAL(ac_cv_c_tkh,[
dnl first check to see if --with-tkinclude was specified
if test x"${with_tkinclude}" != x ; then
  if test -f ${with_tkinclude}/tk.h ; then
    ac_cv_c_tkh=`(cd ${with_tkinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_tkinclude}/generic/tk.h ; then
    ac_cv_c_tkh=`(cd ${with_tkinclude}/generic; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_tkinclude} directory doesn't contain headers])
  fi
fi

dnl next check if it came with Tk configuration file
if test x"${ac_cv_c_tkconfig}" != x ; then
  for i in $dirlist; do
    if test -f $ac_cv_c_tkconfig/$i/generic/tk.h ; then
      ac_cv_c_tkh=`(cd $ac_cv_c_tkconfig/$i/generic; ${PWDCMD-pwd})`
      break
    fi
  done
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_tkh}" = x ; then
    dnl find the top level Tk source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/tk* 2>/dev/null`" ; then
	    tkpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Tk source dir. We do it this way, cause there
    dnl might be multiple version of Tk, and we want the most recent one.
    for i in `ls -dr $tkpath/tk* 2>/dev/null ` ; do
        if test -f $i/generic/tk.h ; then
          ac_cv_c_tkh=`(cd $i/generic; ${PWDCMD-pwd})`
          break
        fi
    done
fi

dnl see if one is installed
if test x"${ac_cv_c_tkh}" = x ; then
    AC_MSG_RESULT(none)
    dnl Get the path to the compiler. We do it this way instead of using
    dnl AC_CHECK_HEADER, cause this doesn't depend in having X configured.
    ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/include
    if test -f $ccpath/tk.h; then
	ac_cv_c_tkh=$ccpath
    fi
else
   AC_MSG_RESULT(${ac_cv_c_tkh})
fi
])
  TKHDIR=""
if test x"${ac_cv_c_tkh}" = x ; then
    AC_MSG_ERROR([Can't find any Tk headers])
fi
if test x"${ac_cv_c_tkh}" != x ; then
    no_tk=""
    if test x"${ac_cv_c_tkh}" != x"installed" ; then
	if test x"${CC}" = xcl ; then
	    tmp="`cygpath --windows ${ac_cv_c_tkh}`"
	    ac_cv_c_tkh="`echo $tmp | sed -e s#\\\\\\\\#/#g`"
	fi
        AC_MSG_RESULT([found in ${ac_cv_c_tkh}])
        TKHDIR="-I${ac_cv_c_tkh}"
    fi
fi

AC_SUBST(TKHDIR)
])

AC_DEFUN([CYG_AC_PATH_TKCONFIG], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
dnl First, look for one uninstalled.  
dnl the alternative search directory is invoked by --with-tkconfig
if test x"${no_tk}" = x ; then
  dnl we reset no_tk in case something fails here
    no_tk=true
    AC_ARG_WITH(tkconfig, [  --with-tkconfig           directory containing tk configuration (tkConfig.sh)],
         with_tkconfig=${withval})
    AC_MSG_CHECKING([for Tk configuration script])
    AC_CACHE_VAL(ac_cv_c_tkconfig,[

    dnl First check to see if --with-tkconfig was specified.
    if test x"${with_tkconfig}" != x ; then
        if test -f "${with_tkconfig}/tkConfig.sh" ; then
            ac_cv_c_tkconfig=`(cd ${with_tkconfig}; ${PWDCMD-pwd})`
        else
            AC_MSG_ERROR([${with_tkconfig} directory doesn't contain tkConfig.sh])
        fi
    fi

    dnl next check if it came with Tk configuration file in the source tree
    if test x"${ac_cv_c_tkconfig}" = x ; then
        for i in $dirlist; do
            dnl need to test both unix and win directories, since 
            dnl cygwin's tkConfig.sh could be in either directory depending
            dnl on the cygwin port of tk.
            if test -f $srcdir/$i/unix/tkConfig.sh ; then
                ac_cv_c_tkconfig=`(cd $srcdir/$i/unix; ${PWDCMD-pwd})`
	        break
            fi
            if test -f $srcdir/$i/win/tkConfig.sh ; then
                ac_cv_c_tkconfig=`(cd $srcdir/$i/unix; ${PWDCMD-pwd})`
	        break
            fi
        done
    fi
    dnl check in a few other locations
    if test x"${ac_cv_c_tkconfig}" = x ; then
        dnl find the top level Tk source directory
        for i in $dirlist; do
            if test -n "`ls -dr $i/tk* 2>/dev/null`" ; then
	        tkconfpath=$i
	        break
	    fi
        done

        dnl find the exact Tk dir. We do it this way, cause there
        dnl might be multiple version of Tk, and we want the most recent one.
        for i in `ls -dr $tkconfpath/tk* 2>/dev/null ` ; do
            dnl need to test both unix and win directories, since 
            dnl cygwin's tkConfig.sh could be in either directory depending
            dnl on the cygwin port of tk.
            if test -f $i/unix/tkConfig.sh ; then
                ac_cv_c_tkconfig=`(cd $i/unix; ${PWDCMD-pwd})`
                break
            fi
            if test -f $i/win/tkConfig.sh ; then
                ac_cv_c_tkconfig=`(cd $i/win; ${PWDCMD-pwd})`
                break
            fi
        done
    fi

    dnl Check to see if it's installed. We have to look in the $CC path
    dnl to find it, cause our $prefix may not match the compilers.
    if test x"${ac_cv_c_tkconfig}" = x ; then
        dnl Get the path to the compiler
	ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/lib
        if test -f $ccpath/tkConfig.sh; then
	    ac_cv_c_tkconfig=$ccpath
        fi
    fi
    ])	dnl end of cache_val

    if test x"${ac_cv_c_tkconfig}" = x ; then
        TKCONFIG=""
        AC_MSG_WARN(Can't find Tk configuration definitions)
    else
        no_tk=""
        TKCONFIG=${ac_cv_c_tkconfig}/tkConfig.sh
        AC_MSG_RESULT(${TKCONFIG})
     fi
fi
AC_SUBST(TKCONFIG)
])

dnl Defined as a separate macro so we don't have to cache the values
dnl from PATH_TKCONFIG (because this can also be cached).
AC_DEFUN([CYG_AC_LOAD_TKCONFIG], [
    if test -f "$TKCONFIG" ; then
      . $TKCONFIG
    fi

    AC_SUBST(TK_VERSION)
dnl not actually used, don't export to save symbols
dnl    AC_SUBST(TK_MAJOR_VERSION)
dnl    AC_SUBST(TK_MINOR_VERSION)
    AC_SUBST(TK_DEFS)

dnl not used, don't export to save symbols
    AC_SUBST(TK_LIB_FILE)
    AC_SUBST(TK_LIB_FULL_PATH)
    AC_SUBST(TK_LIBS)
dnl not used, don't export to save symbols
dnl    AC_SUBST(TK_PREFIX)

dnl not used, don't export to save symbols
dnl    AC_SUBST(TK_EXEC_PREFIX)
    AC_SUBST(TK_BUILD_INCLUDES)
    AC_SUBST(TK_XINCLUDES)
    AC_SUBST(TK_XLIBSW)
    AC_SUBST(TK_BUILD_LIB_SPEC)
    AC_SUBST(TK_LIB_SPEC)
])

dnl ====================================================================
dnl Ok, lets find the itcl source trees so we can use the headers
dnl the alternative search directory is involked by --with-itclinclude
AC_DEFUN([CYG_AC_PATH_ITCL], [
    CYG_AC_PATH_ITCLH
    CYG_AC_PATH_ITCLLIB
    CYG_AC_PATH_ITCLSH
    CYG_AC_PATH_ITCLMKIDX
])
AC_DEFUN([CYG_AC_PATH_ITCLH], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_itcl=true
AC_MSG_CHECKING(for Itcl headers in the source tree)
AC_ARG_WITH(itclinclude, [  --with-itclinclude       directory where itcl headers are], with_itclinclude=${withval})
AC_CACHE_VAL(ac_cv_c_itclh,[
dnl first check to see if --with-itclinclude was specified
if test x"${with_itclinclude}" != x ; then
  if test -f ${with_itclinclude}/itcl.h ; then
    ac_cv_c_itclh=`(cd ${with_itclinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_itclinclude}/src/itcl.h ; then
    ac_cv_c_itclh=`(cd ${with_itclinclude}/src; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_itclinclude} directory doesn't contain headers])
  fi
fi

dnl next check if it came with Itcl configuration file
if test x"${ac_cv_c_itclconfig}" != x ; then
  for i in $dirlist; do
    if test -f $ac_cv_c_itclconfig/$i/src/itcl.h ; then
      ac_cv_c_itclh=`(cd $ac_cv_c_itclconfig/$i/src; ${PWDCMD-pwd})`
      break
    fi
  done
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_itclh}" = x ; then
    dnl find the top level Itcl source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/itcl* 2>/dev/null`" ; then
	    itclpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Itcl source dir. We do it this way, cause there
    dnl might be multiple version of Itcl, and we want the most recent one.
    for i in `ls -dr $itclpath/itcl* 2>/dev/null ` ; do
        if test -f $i/src/itcl.h ; then
          ac_cv_c_itclh=`(cd $i/src; ${PWDCMD-pwd})`
          break
        fi
    done
fi

dnl see if one is installed
if test x"${ac_cv_c_itclh}" = x ; then
   AC_MSG_RESULT(none)
   AC_CHECK_HEADER(itcl.h, ac_cv_c_itclh=installed, ac_cv_c_itclh="")
else
   AC_MSG_RESULT(${ac_cv_c_itclh})
fi
])
  ITCLHDIR=""
if test x"${ac_cv_c_itclh}" = x ; then
    AC_MSG_ERROR([Can't find any Itcl headers])
fi
if test x"${ac_cv_c_itclh}" != x ; then
    no_itcl=""
    if test x"${ac_cv_c_itclh}" != x"installed" ; then
        AC_MSG_RESULT(${ac_cv_c_itclh})
        ITCLHDIR="-I${ac_cv_c_itclh}"
    fi
fi

AC_SUBST(ITCLHDIR)
])

dnl Ok, lets find the itcl library
dnl First, look for one uninstalled.  
dnl the alternative search directory is invoked by --with-itcllib
AC_DEFUN([CYG_AC_PATH_ITCLLIB], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
if test x"${no_itcl}" = x ; then
    dnl we reset no_itcl incase something fails here
    no_itcl=true
    AC_ARG_WITH(itcllib,
	[  --with-itcllib           directory where the itcl library is],
        with_itcllib=${withval})
    AC_MSG_CHECKING([for Itcl library])
    AC_CACHE_VAL(ac_cv_c_itcllib,[
    dnl First check to see if --with-itcllib was specified.
    if test x"${with_itcllib}" != x ; then
        if test -f "${with_itcllib}/libitcl$TCL_SHARED_LIB_SUFFIX" ; then
            ac_cv_c_itcllib=`(cd ${with_itcllib}; ${PWDCMD-pwd})`/libitcl$TCL_SHARED_LIB_SUFFIX
	else
	    if test -f "${with_itcllib}/libitcl$TCL_UNSHARED_LIB_SUFFIX"; then
	 	ac_cv_c_itcllib=`(cd ${with_itcllib}; ${PWDCMD-pwd})`/libitcl$TCL_UNSHARED_LIB_SUFFIX
	    fi
	fi
    fi
    dnl then check for a  Itcl library. Since these are uninstalled,
    dnl use the simple lib name root. 
    if test x"${ac_cv_c_itcllib}" = x ; then
        dnl find the top level Itcl build directory
        for i in $dirlist; do
            if test -n "`ls -dr $i/itcl* 2>/dev/null`" ; then
	        itclpath=$i/itcl
	        break
	    fi
        done
        dnl Itcl 7.5 and greater puts library in subdir.  Look there first.
        if test -f "$itclpath/src/libitcl.$TCL_SHLIB_SUFFIX" ; then
	     ac_cv_c_itcllib=`(cd $itclpath/src; ${PWDCMD-pwd})`
        elif test -f "$itclpath/src/libitcl.a"; then
	     ac_cv_c_itcllib=`(cd $itclpath/src; ${PWDCMD-pwd})`
	fi
    fi
    dnl check in a few other private locations
    if test x"${ac_cv_c_itcllib}" = x ; then
        for i in ${dirlist}; do
            if test -n "`ls -dr ${srcdir}/$i/itcl* 2>/dev/null`" ; then
	        itclpath=${srcdir}/$i
	        break
	    fi
        done
        for i in `ls -dr ${itclpath}/itcl* 2>/dev/null` ; do
            dnl Itcl 7.5 and greater puts library in subdir.  Look there first.
            if test -f "$i/src/libitcl$TCL_SHLIB_SUFFIX" ; then
	        ac_cv_c_itcllib=`(cd $i/src; ${PWDCMD-pwd})`
	        break
            elif test -f "$i/src/libitcl.a"; then
	        ac_cv_c_itcllib=`(cd $i/src; ${PWDCMD-pwd})`
	        break
	    fi	
        done
    fi

    dnl see if one is conveniently installed with the compiler
    if test x"${ac_cv_c_itcllib}" = x ; then
        dnl Get the path to the compiler
	ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/lib
        dnl Itcl 7.5 and greater puts library in subdir.  Look there first.
        if test -f "${ccpath}/libitcl$TCL_SHLIB_SUFFIX" ; then
	    ac_cv_c_itcllib=`(cd ${ccpath}; ${PWDCMD-pwd})`
        elif test -f "${ccpath}/libitcl.a"; then
	    ac_cv_c_itcllib=`(cd ${ccpath}; ${PWDCMD-pwd})`
        fi
    fi
    ])
    if test x"${ac_cv_c_itcllib}" = x ; then
        ITCLLIB=""
        AC_MSG_WARN(Can't find Itcl library)
    else
        ITCLLIB="-L${ac_cv_c_itcllib}"
        AC_MSG_RESULT(${ac_cv_c_itcllib})
        no_itcl=""
    fi
fi

AC_PROVIDE([$0])
AC_SUBST(ITCLLIB)
])


dnl ====================================================================
dnl Ok, lets find the itcl source trees so we can use the itcl_sh script
dnl the alternative search directory is involked by --with-itclinclude
AC_DEFUN([CYG_AC_PATH_ITCLSH], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_itcl=true
AC_MSG_CHECKING(for the itcl_sh script)
AC_ARG_WITH(itclinclude, [  --with-itclinclude       directory where itcl headers are], with_itclinclude=${withval})
AC_CACHE_VAL(ac_cv_c_itclsh,[
dnl first check to see if --with-itclinclude was specified
if test x"${with_itclinclude}" != x ; then
  if test -f ${with_itclinclude}/itcl_sh ; then
    ac_cv_c_itclsh=`(cd ${with_itclinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_itclinclude}/src/itcl_sh ; then
    ac_cv_c_itclsh=`(cd ${with_itclinclude}/src; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_itclinclude} directory doesn't contain itcl_sh])
  fi
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_itclsh}" = x ; then
    dnl find the top level Itcl source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/itcl* 2>/dev/null`" ; then
	    itclpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Itcl source dir. We do it this way, cause there
    dnl might be multiple version of Itcl, and we want the most recent one.
    for i in `ls -dr $itclpath/itcl* 2>/dev/null ` ; do
        if test -f $i/src/itcl_sh ; then
          ac_cv_c_itclsh=`(cd $i/src; ${PWDCMD-pwd})`/itcl_sh
          break
        fi
    done
fi

dnl see if one is installed
if test x"${ac_cv_c_itclsh}" = x ; then
   AC_MSG_RESULT(none)
   AC_PATH_PROG(ac_cv_c_itclsh, itcl_sh)
else
   AC_MSG_RESULT(${ac_cv_c_itclsh})
fi
])

if test x"${ac_cv_c_itclsh}" = x ; then
    AC_MSG_ERROR([Can't find the itcl_sh script])
fi
if test x"${ac_cv_c_itclsh}" != x ; then
    no_itcl=""
    AC_MSG_RESULT(${ac_cv_c_itclsh})
    ITCLSH="${ac_cv_c_itclsh}"
fi
AC_SUBST(ITCLSH)
])


dnl ====================================================================
dnl Ok, lets find the itcl source trees so we can use the itcl_sh script
dnl the alternative search directory is involked by --with-itclinclude
AC_DEFUN([CYG_AC_PATH_ITCLMKIDX], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_itcl=true
AC_MSG_CHECKING(for itcl_mkindex.tcl script)
AC_ARG_WITH(itclinclude, [  --with-itclinclude       directory where itcl headers are], with_itclinclude=${withval})
AC_CACHE_VAL(ac_cv_c_itclmkidx,[
dnl first check to see if --with-itclinclude was specified
if test x"${with_itclinclude}" != x ; then
  if test -f ${with_itclinclude}/itcl_sh ; then
    ac_cv_c_itclmkidx=`(cd ${with_itclinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_itclinclude}/src/itcl_sh ; then
    ac_cv_c_itclmkidx=`(cd ${with_itclinclude}/src; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_itclinclude} directory doesn't contain itcl_sh])
  fi
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_itclmkidx}" = x ; then
    dnl find the top level Itcl source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/itcl* 2>/dev/null`" ; then
	    itclpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Itcl source dir. We do it this way, cause there
    dnl might be multiple version of Itcl, and we want the most recent one.
    for i in `ls -dr $itclpath/itcl* 2>/dev/null ` ; do
        if test -f $i/library/itcl_mkindex.tcl ; then
          ac_cv_c_itclmkidx=`(cd $i/library; ${PWDCMD-pwd})`/itcl_mkindex.tcl
          break
        fi
    done
fi
if test x"${ac_cv_c_itclmkidx}" = x ; then
    dnl Get the path to the compiler
    ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/share
    dnl Itcl 7.5 and greater puts library in subdir.  Look there first.
    for i in `ls -dr $ccpath/itcl* 2>/dev/null ` ; do
        if test -f $i/itcl_mkindex.tcl ; then
            ac_cv_c_itclmkidx=`(cd $i; ${PWDCMD-pwd})`/itcl_mkindex.tcl
            break
        fi
    done
fi
])

if test x"${ac_cv_c_itclmkidx}" = x ; then
    AC_MSG_ERROR([Can't find the itcl_mkindex.tcl script])
fi
if test x"${ac_cv_c_itclmkidx}" != x ; then
    no_itcl=""
    AC_MSG_RESULT(${ac_cv_c_itclmkidx})
    ITCLMKIDX="${ac_cv_c_itclmkidx}"
else
   AC_MSG_RESULT(none)
fi
AC_SUBST(ITCLMKIDX)
])

dnl ====================================================================
dnl Ok, lets find the tix source trees so we can use the headers
dnl the alternative search directory is involked by --with-tixinclude
AC_DEFUN([CYG_AC_PATH_TIX], [
    CYG_AC_PATH_TIXH
    CYG_AC_PATH_TIXLIB
])
AC_DEFUN([CYG_AC_PATH_TIXH], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
no_tix=true
AC_MSG_CHECKING(for Tix headers in the source tree)
AC_ARG_WITH(tixinclude, [  --with-tixinclude       directory where tix headers are], with_tixinclude=${withval})
AC_CACHE_VAL(ac_cv_c_tixh,[
dnl first check to see if --with-tixinclude was specified
if test x"${with_tixinclude}" != x ; then
  if test -f ${with_tixinclude}/tix.h ; then
    ac_cv_c_tixh=`(cd ${with_tixinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_tixinclude}/generic/tix.h ; then
    ac_cv_c_tixh=`(cd ${with_tixinclude}/generic; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_tixinclude} directory doesn't contain headers])
  fi
fi

dnl next check if it came with Tix configuration file
if test x"${ac_cv_c_tixconfig}" != x ; then
  for i in $dirlist; do
    if test -f $ac_cv_c_tixconfig/$i/generic/tix.h ; then
      ac_cv_c_tixh=`(cd $ac_cv_c_tixconfig/$i/generic; ${PWDCMD-pwd})`
      break
    fi
  done
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_tixh}" = x ; then
    dnl find the top level Tix source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/tix* 2>/dev/null`" ; then
	    tixpath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Tix source dir. We do it this way, cause there
    dnl might be multiple version of Tix, and we want the most recent one.
    for i in `ls -dr $tixpath/tix* 2>/dev/null ` ; do
        if test -f $i/generic/tix.h ; then
          ac_cv_c_tixh=`(cd $i/generic; ${PWDCMD-pwd})`
          break
        fi
    done
fi

dnl see if one is installed
if test x"${ac_cv_c_tixh}" = x ; then
    AC_MSG_RESULT(none)
    dnl Get the path to the compiler

   dnl Get the path to the compiler. We do it this way instead of using
    dnl AC_CHECK_HEADER, cause this doesn't depend in having X configured.
    ccpath=`which ${CC}  | sed -e 's:/bin/.*::'`/include
    if test -f $ccpath/tix.h; then
	ac_cv_c_tixh=installed
    fi
else
   AC_MSG_RESULT(${ac_cv_c_tixh})
fi
])
if test x"${ac_cv_c_tixh}" = x ; then
    AC_MSG_ERROR([Can't find any Tix headers])
fi
if test x"${ac_cv_c_tixh}" != x ; then
    no_tix=""
    AC_MSG_RESULT(${ac_cv_c_tixh})
    if test x"${ac_cv_c_tixh}" != x"installed" ; then
        TIXHDIR="-I${ac_cv_c_tixh}"
    fi
fi

AC_SUBST(TIXHDIR)
])

AC_DEFUN([CYG_AC_PATH_TIXCONFIG], [
#
# Ok, lets find the tix configuration
# First, look for one uninstalled.  
# the alternative search directory is invoked by --with-tixconfig
#

if test x"${no_tix}" = x ; then
  # we reset no_tix in case something fails here
  no_tix=true
  AC_ARG_WITH(tixconfig, [  --with-tixconfig           directory containing tix configuration (tixConfig.sh)],
         with_tixconfig=${withval})
  AC_MSG_CHECKING([for Tix configuration])
  AC_CACHE_VAL(ac_cv_c_tixconfig,[

  # First check to see if --with-tixconfig was specified.
  if test x"${with_tixconfig}" != x ; then
    if test -f "${with_tixconfig}/tixConfig.sh" ; then
      ac_cv_c_tixconfig=`(cd ${with_tixconfig}; ${PWDCMD-pwd})`
    else
      AC_MSG_ERROR([${with_tixconfig} directory doesn't contain tixConfig.sh])
    fi
  fi

  # then check for a private Tix library
  if test x"${ac_cv_c_tixconfig}" = x ; then
    for i in \
		../tix \
		`ls -dr ../tix[[4]]* 2>/dev/null` \
		../../tix \
		`ls -dr ../../tix[[4]]* 2>/dev/null` \
		../../../tix \
		`ls -dr ../../../tix[[4]]* 2>/dev/null` ; do
      if test -f "$i/tixConfig.sh" ; then
        ac_cv_c_tixconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few common install locations
  if test x"${ac_cv_c_tixconfig}" = x ; then
    for i in `ls -d ${prefix}/lib /usr/local/lib 2>/dev/null` ; do
      if test -f "$i/tixConfig.sh" ; then
        ac_cv_c_tkconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few other private locations
  if test x"${ac_cv_c_tixconfig}" = x ; then
    for i in \
		${srcdir}/../tix \
		`ls -dr ${srcdir}/../tix[[4-9]]* 2>/dev/null` ; do
      if test -f "$i/tixConfig.sh" ; then
        ac_cv_c_tixconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  ])
  if test x"${ac_cv_c_tixconfig}" = x ; then
    TIXCONFIG="# no Tix configs found"
    AC_MSG_WARN(Can't find Tix configuration definitions)
  else
    no_tix=
    TIXCONFIG=${ac_cv_c_tixconfig}/tixConfig.sh
    AC_MSG_RESULT(found $TIXCONFIG)
  fi
fi

])

# Defined as a separate macro so we don't have to cache the values
# from PATH_TIXCONFIG (because this can also be cached).
AC_DEFUN([CYG_AC_LOAD_TIXCONFIG], [
    if test -f "$TIXCONFIG" ; then
      . $TIXCONFIG
    fi

    AC_SUBST(TIX_BUILD_LIB_SPEC)
    AC_SUBST(TIX_LIB_FULL_PATH)
])

AC_DEFUN([CYG_AC_PATH_ITCLCONFIG], [
#
# Ok, lets find the itcl configuration
# First, look for one uninstalled.  
# the alternative search directory is invoked by --with-itclconfig
#

if test x"${no_itcl}" = x ; then
  # we reset no_itcl in case something fails here
  no_itcl=true
  AC_ARG_WITH(itclconfig, [  --with-itclconfig           directory containing itcl configuration (itclConfig.sh)],
         with_itclconfig=${withval})
  AC_MSG_CHECKING([for Itcl configuration])
  AC_CACHE_VAL(ac_cv_c_itclconfig,[

  # First check to see if --with-itclconfig was specified.
  if test x"${with_itclconfig}" != x ; then
    if test -f "${with_itclconfig}/itclConfig.sh" ; then
      ac_cv_c_itclconfig=`(cd ${with_itclconfig}; ${PWDCMD-pwd})`
    else
      AC_MSG_ERROR([${with_itclconfig} directory doesn't contain itclConfig.sh])
    fi
  fi

  # then check for a private itcl library
  if test x"${ac_cv_c_itclconfig}" = x ; then
    for i in \
		../itcl/itcl \
		`ls -dr ../itcl/itcl[[3]]* 2>/dev/null` \
		../../itcl/itcl \
		`ls -dr ../../itcl/itcl[[3]]* 2>/dev/null` \
		../../../itcl/itcl \
		`ls -dr ../../../itcl/itcl[[3]]* 2>/dev/null` ; do
      if test -f "$i/itclConfig.sh" ; then
        ac_cv_c_itclconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few common install locations
  if test x"${ac_cv_c_itclconfig}" = x ; then
    for i in `ls -d ${prefix}/lib /usr/local/lib 2>/dev/null` ; do
      if test -f "$i/itclConfig.sh" ; then
        ac_cv_c_itclconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few other private locations
  if test x"${ac_cv_c_itclconfig}" = x ; then
    for i in \
		${srcdir}/../itcl/itcl \
		`ls -dr ${srcdir}/../itcl/itcl[[3]]* 2>/dev/null` ; do
      if test -f "$i/itcl/itclConfig.sh" ; then
        ac_cv_c_itclconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  ])
  if test x"${ac_cv_c_itclconfig}" = x ; then
    ITCLCONFIG="# no itcl configs found"
    AC_MSG_WARN(Can't find itcl configuration definitions)
  else
    no_itcl=
    ITCLCONFIG=${ac_cv_c_itclconfig}/itclConfig.sh
    AC_MSG_RESULT(found $ITCLCONFIG)
  fi
fi

])

# Defined as a separate macro so we don't have to cache the values
# from PATH_ITCLCONFIG (because this can also be cached).
AC_DEFUN([CYG_AC_LOAD_ITCLCONFIG], [
    if test -f "$ITCLCONFIG" ; then
      . $ITCLCONFIG
    fi

    AC_SUBST(ITCL_BUILD_LIB_SPEC)
    AC_SUBST(ITCL_SH)
    AC_SUBST(ITCL_LIB_FILE)
    AC_SUBST(ITCL_LIB_FULL_PATH)

])


AC_DEFUN([CYG_AC_PATH_ITKCONFIG], [
#
# Ok, lets find the itk configuration
# First, look for one uninstalled.  
# the alternative search directory is invoked by --with-itkconfig
#

if test x"${no_itk}" = x ; then
  # we reset no_itk in case something fails here
  no_itk=true
  AC_ARG_WITH(itkconfig, [  --with-itkconfig           directory containing itk configuration (itkConfig.sh)],
         with_itkconfig=${withval})
  AC_MSG_CHECKING([for Itk configuration])
  AC_CACHE_VAL(ac_cv_c_itkconfig,[

  # First check to see if --with-itkconfig was specified.
  if test x"${with_itkconfig}" != x ; then
    if test -f "${with_itkconfig}/itkConfig.sh" ; then
      ac_cv_c_itkconfig=`(cd ${with_itkconfig}; ${PWDCMD-pwd})`
    else
      AC_MSG_ERROR([${with_itkconfig} directory doesn't contain itkConfig.sh])
    fi
  fi

  # then check for a private itk library
  if test x"${ac_cv_c_itkconfig}" = x ; then
    for i in \
		../itcl/itk \
		`ls -dr ../itcl/itk[[3]]* 2>/dev/null` \
		../../itcl/itk \
		`ls -dr ../../itcl/itk[[3]]* 2>/dev/null` \
		../../../itcl/itk \
		`ls -dr ../../../itcl/itk[[3]]* 2>/dev/null` ; do
      if test -f "$i/itkConfig.sh" ; then
        ac_cv_c_itkconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few common install locations
  if test x"${ac_cv_c_itkconfig}" = x ; then
    for i in `ls -d ${prefix}/lib /usr/local/lib 2>/dev/null` ; do
      if test -f "$i/itcl/itkConfig.sh" ; then
        ac_cv_c_itkconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  # check in a few other private locations
  if test x"${ac_cv_c_itkconfig}" = x ; then
    for i in \
		${srcdir}/../itcl/itk \
		`ls -dr ${srcdir}/../itcl/itk[[3]]* 2>/dev/null` ; do
      if test -f "$i/itkConfig.sh" ; then
        ac_cv_c_itkconfig=`(cd $i; ${PWDCMD-pwd})`
	break
      fi
    done
  fi
  ])
  if test x"${ac_cv_c_itkconfig}" = x ; then
    ITCLCONFIG="# no itk configs found"
    AC_MSG_WARN(Can't find itk configuration definitions)
  else
    no_itk=
    ITKCONFIG=${ac_cv_c_itkconfig}/itkConfig.sh
    AC_MSG_RESULT(found $ITKCONFIG)
  fi
fi

])

# Defined as a separate macro so we don't have to cache the values
# from PATH_ITKCONFIG (because this can also be cached).
AC_DEFUN([CYG_AC_LOAD_ITKCONFIG], [
    if test -f "$ITKCONFIG" ; then
      . $ITKCONFIG
    fi

    AC_SUBST(ITK_BUILD_LIB_SPEC)
    AC_SUBST(ITK_LIB_FILE)
    AC_SUBST(ITK_LIB_FULL_PATH)
])


dnl ====================================================================
dnl Ok, lets find the libgui source trees so we can use the headers
dnl the alternative search directory is involked by --with-libguiinclude
AC_DEFUN([CYG_AC_PATH_LIBGUI], [
    CYG_AC_PATH_LIBGUIH
    CYG_AC_PATH_LIBGUILIB
])
AC_DEFUN([CYG_AC_PATH_LIBGUIH], [
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../..../../../../../../../../../../.."
no_libgui=true
AC_MSG_CHECKING(for Libgui headers in the source tree)
AC_ARG_WITH(libguiinclude, [  --with-libguiinclude       directory where libgui headers are], with_libguiinclude=${withval})
AC_CACHE_VAL(ac_cv_c_libguih,[
dnl first check to see if --with-libguiinclude was specified
if test x"${with_libguiinclude}" != x ; then
  if test -f ${with_libguiinclude}/guitcl.h ; then
    ac_cv_c_libguih=`(cd ${with_libguiinclude}; ${PWDCMD-pwd})`
  elif test -f ${with_libguiinclude}/src/guitcl.h ; then
    ac_cv_c_libguih=`(cd ${with_libguiinclude}/src; ${PWDCMD-pwd})`
  else
    AC_MSG_ERROR([${with_libguiinclude} directory doesn't contain headers])
  fi
fi

dnl next check if it came with Libgui configuration file
if test x"${ac_cv_c_libguiconfig}" != x ; then
  for i in $dirlist; do
    if test -f $ac_cv_c_libguiconfig/$i/src/guitcl.h ; then
      ac_cv_c_libguih=`(cd $ac_cv_c_libguiconfig/$i/src; ${PWDCMD-pwd})`
      break
    fi
  done
fi

dnl next check in private source directory
dnl since ls returns lowest version numbers first, reverse its output
if test x"${ac_cv_c_libguih}" = x ; then
    dnl find the top level Libgui source directory
    for i in $dirlist; do
        if test -n "`ls -dr $srcdir/$i/libgui* 2>/dev/null`" ; then
	    libguipath=$srcdir/$i
	    break
	fi
    done

    dnl find the exact Libgui source dir. We do it this way, cause there
    dnl might be multiple version of Libgui, and we want the most recent one.
    for i in `ls -dr $libguipath/libgui* 2>/dev/null ` ; do
        if test -f $i/src/guitcl.h ; then
          ac_cv_c_libguih=`(cd $i/src; ${PWDCMD-pwd})`
          break
        fi
    done
fi

dnl see if one is installed
if test x"${ac_cv_c_libguih}" = x ; then
   AC_MSG_RESULT(none)
   AC_CHECK_HEADER(guitcl.h, ac_cv_c_libguih=installed, ac_cv_c_libguih="")
fi
])
LIBGUIHDIR=""
if test x"${ac_cv_c_libguih}" = x ; then
    AC_MSG_WARN([Can't find any Libgui headers])
fi
if test x"${ac_cv_c_libguih}" != x ; then
    no_libgui=""
    if test x"${ac_cv_c_libguih}" != x"installed" ; then
        LIBGUIHDIR="-I${ac_cv_c_libguih}"
    fi
fi
AC_MSG_RESULT(${ac_cv_c_libguih})
AC_SUBST(LIBGUIHDIR)
])

dnl ====================================================================
dnl find the GUI library
AC_DEFUN([CYG_AC_PATH_LIBGUILIB], [
AC_MSG_CHECKING(for GUI library  in the build tree)
dirlist=".. ../../ ../../../ ../../../../ ../../../../../ ../../../../../../ ../../../../../../.. ../../../../../../../.. ../../../../../../../../.. ../../../../../../../../../.."
dnl look for the library
AC_MSG_CHECKING(for GUI library)
AC_CACHE_VAL(ac_cv_c_libguilib,[
if test x"${ac_cv_c_libguilib}" = x ; then
    for i in $dirlist; do
      if test -f "$i/libgui/src/Makefile" ; then
        ac_cv_c_libguilib=`(cd $i/libgui/src; ${PWDCMD-pwd})`
        break
      fi
    done
fi
]) 
if test x"${ac_cv_c_libguilib}" != x ; then
     GUILIB="${GUILIB} -L${ac_cv_c_libguilib}"
     LIBGUILIB="-lgui"
     AC_MSG_RESULT(${ac_cv_c_libguilib})
else
     AC_MSG_RESULT(none)
fi

AC_SUBST(GUILIB)
AC_SUBST(LIBGUILIB)
])