File: bash-based-configure

package info (click to toggle)
dvdisaster 0.79.5-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 42,960 kB
  • sloc: ansic: 33,411; sh: 4,898; makefile: 138
file content (2166 lines) | stat: -rw-r--r-- 56,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
#  Bash based configure - library of test functions
#  Copyright (C) 2004-2015 Carsten Gn�rlich
#
#  Email: carsten@dvdisaster.org  -or-  cgnoerlich@fsfe.org
#  Project homepage: http://www.dvdisaster.org
#
#  Bash based configure is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Bash based configure is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Bash based configure. If not, see <http://www.gnu.org/licenses/>.
#/


# Command overview:
# 
# PACKAGE               Define package name and version
# DEFINE_STRING str foo adds -Dstr=foo to CFG_OTHER_OPTIONS
# DEFINE_VAR str foo	adds CFG_str = foo to Makefile
#
# PRINT_MSG		Prints a message to the console and log file 
#
# GET_SRCDIR		Determine and verify root dir of this distribution
# GET_PKGNAME		Retrieves name of package directory
# GET_PREFIX default	Where to install our stuff. The --prefix option will
#			override the default setting.
# GET_BINDIR [default]	Where to install our binaries. The --bindir option will
#			override the default setting; the default parameter is optional.
# GET_DOCDIR default	Where to install our documentation. The --docdir option will
#			override the default setting.
# GET_LOCALEDIR default	Where to install our local. The --localedir option will
#			override the default setting.
# GET_MANDIR default	Where to install our man pages. The --mandir option will
#			override the default setting.
# GET_BUILDROOT		Temporary build directory for creating packages
# GET_BUILDTMP		Scratch dir for .o files and other temporary build files
# GET_DIR default name ... Creates a --namedir option for querying misc directories 
# REQUIRE_X11 with-Xt	Require the X11 library and friends, if with-Xt is given.
# REQUIRE_XPM		Require the Xpm library
# REQUIRE_MOTIF n m o	Require the Motif library version >= n.m.o
# REQUIRE_OPENGL	Require the OpenGL library
# REQUIRE_GLIB2 n m o	Require GLIB2.x and accompanying components >= n.m.o
# REQUIRE_GTK2 n m o	Require GTK2.x and accompanying components 
# REQUIRE_SDL n m o	Require the SDL library
# REQUIRE_PNG           Require the PNG library
#
# REQUIRE_INCLUDE	Require specified include file
# REQUIRE_LIBRARY	Require specified library
#
# CHECK_INCLUDE		Check for include file, but don't exit on negative test
# CHECK_LIBRARY		Check for library, but don't exit on negative test
# CHECK_FUNCTION	Check for a specific function, but don't exit on neg. test
# CHECK_SYMBOL		Check for a specific symbol, but don't exit on neg. test
# EXECUTE_SOURCE	Execute a test program to test a specific function
# EXECUTE_PROGRAM	Invoke a command to see if a certain program is available
#
# CHECK_ENDIAN		Test whether system is little or big endian
# CHECK_BITNESS		Test whether system is 32bit or 64bit
# CHECK_SSE2		Test whether we can compile for SSE2 extensions
# CHECK_ALTIVEC		Test whether we can compile for AltiVec extensions
# FINALIZE_HELP		Finish --help output (optional, but user friendly)
#
# WITH_OPTION name default  adds -DWITH_OPTION_VALUE for -with-option=value args
#			    to CFG_WITH_OPTIONS

CONFIGURE_VERSION="0.58"

echo "Bash based configure V$CONFIGURE_VERSION"
echo

# sed command to transform pipe contents into upcase
# could be better done with tr ;-)

SED_UPCASE="y%abcdefghijklmnopqrstuvwxyz%ABCDEFGHIJKLMNOPQRSTUVWXYZ%"

# Cleanup from older runs

rm -f Makefile.config config.log

# Determine the build environment
# and set some system-dependent shell functions.

cfg_uname=`uname`
cfg_system=unknown-system
echo -n "Build environment: $cfg_uname, "

case "$cfg_uname" in
  CYGWIN*) CFG_EXE_SUFFIX=".exe" 
        if test $CFG_USE_CYGWIN = "no"; then
	     cfg_system=cygwin-mingw 
             CFG_SYS_CFLAGS="-mms-bitfields -mno-cygwin"
	     CFG_SYS_NAME="-DSYS_NAME=\\\"Cygwin-Mingw \\\""
	else cfg_system=cygwin-std 
             CFG_SYS_OPTIONS="-DSYS_CYGWIN"
	     CFG_SYS_NAME="-DSYS_NAME=\\\"Cygwin\\\""
        fi

	function add_linker_flags()
	{  lflags_return="-L$1 $2"
	}
	;;

  MINGW*) cfg_system=mingw-std 
        CFG_SYS_OPTIONS="-DSYS_MINGW"
	CFG_SYS_NAME="-DSYS_NAME=\\\"Mingw\\\""
        CFG_EXE_SUFFIX=".exe"
        CFG_SYS_CFLAGS="-mms-bitfields"
#	CFG_SYS_LDFLAGS="-mwindows"
	function add_linker_flags()
	{  lflags_return="-L$1 $2"
	}
	;;

  Linux*) cfg_system=linux-std 
        CFG_SYS_OPTIONS="-DSYS_LINUX"
	CFG_SYS_NAME="-DSYS_NAME=\\\"GNU/Linux\\\""
        CFG_EXE_SUFFIX=""
	function add_linker_flags()
        {  lflags_return="-L$1 -Wl,-rpath,$1 $2"
        } 
	;;

  FreeBSD*) cfg_system=freebsd-std
        CFG_SYS_OPTIONS="-DSYS_FREEBSD"
	CFG_SYS_NAME="-DSYS_NAME=\\\"FreeBSD\\\""
        CFG_EXE_SUFFIX=""
	function add_linker_flags()
	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
	}
	;;

  GNU/kFreeBSD*) cfg_system=kfreebsd
	CFG_SYS_OPTIONS="-DSYS_KFREEBSD"
	CFG_SYS_NAME="-DSYS_NAME=\\\"GNU/kFreeBSD\\\""
	CFG_EXE_SUFFIX=""
	function add_linker_flags()
	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
	}
	;;

  NetBSD*) cfg_system=netbsd
        CFG_SYS_OPTIONS="-DSYS_NETBSD"
	CFG_SYS_NAME="-DSYS_NAME=\\\"NetBSD\\\""
        CFG_EXE_SUFFIX=""
	CFG_SYS_LDFLAGS="-lutil"
	function add_linker_flags()
	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
	}
	;;

  GNU*) cfg_system=hurd
	CFG_SYS_OPTIONS="-DSYS_HURD"
	CFG_SYS_NAME="-DSYS_NAME=\\\"GNU/Hurd\\\""
	CFG_EXE_SUFFIX=""
	function add_linker_flags()
	{  lflags_return="-L$1 -Wl,-rpath,$1 $2"
	}
	;;

  *) cfg_system=unknown-system
        CFG_SYS_OPTIONS="-DSYS_UNKNOWN"
	CFG_SYS_NAME="-DSYS_NAME=\\\"Unknown\\\""
        CFG_EXE_SUFFIX=""
	function add_linker_flags()
	{  lflags_return="-L$1 $2"
	}

	;;
esac
echo "using settings: $cfg_system"
echo 

# Sort in the arguments.
# Draws a lot of inspiration from autoconf, 
# and tries to use the same names for common features.
# However, only "[-]-foo=bar" argument style is allowed;
# and not "-foo bar" which would also be accepted by autoconf-generated scripts.

for cfg_opt
do

  # get the "bar" part in "-foo=bar" style arguments 

  case "$cfg_opt" in
  -*=*) cfg_optarg=`echo "$cfg_opt" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *) cfg_optarg= ;;
  esac

  # process the command line options

  case "$cfg_opt" in
  -help | --help)
    echo "Usage: bash configure [options]"
    echo
    echo "Options:"
    echo " --help                 print this message"
    echo " --version              just print the version number of configure" 
    echo " --debug                overrides \$CFLAGS with canned options for debugging"
    cfg_help_mode=1 ;;

  -prefix=* | --prefix=*)
    cfg_user_prefix=1
    cfg_prefix=$cfg_optarg ;;

  -bindir=* | --bindir=*)
    cfg_bindir=$cfg_optarg ;;

  -mandir=* | --mandir=*)
    cfg_mandir=$cfg_optarg ;;

  -docdir=* | --docdir=*)
    cfg_docdir=$cfg_optarg ;;

  -localedir=* | --localedir=*)
    cfg_localedir=$cfg_optarg ;;
  
  -buildroot=* | --buildroot=*)
    cfg_buildroot=$cfg_optarg ;;

  -buildtmp=* | --buildtmp=*)
    cfg_buildtmp=$cfg_optarg ;;

  # process the -with-foo=bar into $cfg_with_foo=bar

  -with-*=* | --with-*=*)
    eval `echo "$cfg_opt" | sed -e 's/[-]*with-/cfg_with_/' -e 'y/-/_/'` ;;

  # process -with-foo into $cfg_with_foo=yes

  -with-* | --with-*)
    cfg_eval=`echo "$cfg_opt" | sed -e 's/[-]*with-/cfg_with_/' -e 'y/-/_/'`
    cfg_eval="$cfg_eval=yes"
    eval "$cfg_eval" ;;

  -*dir=* | --*dir=*)
    eval `echo "$cfg_opt" | sed -e 's/[-]*/cfg_/' ` ;;

  # process the -foolib-includes=/path/bar into $cfg_foolib_incl=/path/bar

  -*-includes=*)
    eval `echo "$cfg_opt" | sed -e 's/[-]*/cfg_/' -e 's/-includes/_incl/'` ;;

  # process the -foolib-libraries=/path/bar into $cfg_foolib_lib=/path/bar

  -*-libraries=*)
    eval `echo "$cfg_opt" | sed -e 's/[-]*/cfg_/' -e 's/-libraries/_lib/'` ;;

  -version | --version)
    exit 0 ;;

  -debug | --debug)
    cfg_debug=1
    CFG_CFLAGS="$DEBUG_CFLAGS $REQUIRED_CFLAGS $CFG_SYS_CFLAGS"
    echo "CFLAGS = $CFG_CFLAGS" >>Makefile.config ;;

  *)
    echo "* configure warning: unknown option $cfg_opt" ;;

  esac
done

# See if we should add our default $CFLAGS and $LDFLAGS

if test -z $cfg_debug; then
  if test -n "$CFLAGS"; then
     CFG_CFLAGS="$CFLAGS $REQUIRED_CFLAGS $CFG_SYS_CFLAGS"
  else
     CFG_CFLAGS="$RECOMMENDED_CFLAGS $REQUIRED_CFLAGS $CFG_SYS_CFLAGS"
  fi
  if test -n "$LDFLAGS"; then
     CFG_LDFLAGS="$LDFLAGS $REQUIRED_LDFLAGS $CFG_SYS_LDFLAGS"
  else
     CFG_LDFLAGS="$RECOMMENDED_LDFLAGS $REQUIRED_LDFLAGS $CFG_SYS_LDFLAGS"
  fi
fi

# Find out where bash resides

echo "SHELL = `which bash`" >>Makefile.config

# Setup the log file

LOGFILE=configure.log
rm -f $LOGFILE

#
# Finalize the --help output 
#

function FINALIZE_HELP()
{
  echo -e "\nSome influential environment variables:\n"
  echo "CFLAGS   C compiler flags, e.g. -I<include dir>"
  echo "         if you have include files in nonstandard places" 
  echo "LDFLAGS  linker flags, e.g. -L<lib dir>"
  echo "         if you have libraries in nonstandard places" 
  echo 
}

#
# Message printing
#

function PRINT_MESSAGE()
{  local message="$1"

   if test -n "$cfg_help_mode"; then
      return 0
   fi

   echo -e "$message"
   echo -e "$message" >>$LOGFILE
}

#
# Check for tools
#

function REQUIRE_GMAKE()
{ 
   if test -n "$cfg_help_mode"; then
      return 0
   fi

   echo -n "Checking for gmake: "

   if (gmake -v 2>&1 | grep "GNU Make") > /dev/null 2>&1 ;
     then echo "yes"
	  echo "MAKE = `which gmake`" >>Makefile.config
	  return 0
   fi;

   if (make -v 2>&1 | grep "GNU Make") > /dev/null 2>&1 ;
     then echo "yes"
	  echo "MAKE = `which make`" >>Makefile.config
	  return 0
   fi;

   echo "no"
   echo "This package requires GNU make (gmake)."
   exit 1;
}

function REQUIRE_GCC()
{
   if test -n "$cfg_help_mode"; then
      return 0
   fi

   echo -n "Checking for gcc: "

   # Try $CC first

   if test -n "$CC" && $CC -v >/dev/null 2>&1; then
     if ($CC -v 2>&1 | grep "gcc") > /dev/null 2>&1 ;
       then CC=`which $CC`
       	    echo "yes ($CC)"
	    echo "CC = `which $CC`" >>Makefile.config
     	    return 0
     fi	   
   fi

   # Try gcc binary

   CC=gcc
   if test -n "$CC" && $CC -v >/dev/null 2>&1; then
     if ($CC -v 2>&1 | grep "gcc") > /dev/null 2>&1 ;
       then CC=`which $CC`
	    echo "yes ($CC)"
	    echo "CC = $CC" >>Makefile.config
     	    return 0
     fi	   
   fi

   # FreeBSD has not gcc symlink, just gccxx binaries

   if test "$cfg_uname" == "FreeBSD"; then
     CC=$(ls /usr/local/bin | grep -E "^gcc[0-9]*$" | sort -n -r | head -n 1)
     if test -n "$CC" && $CC -v >/dev/null 2>&1; then
     	if ($CC -v 2>&1 | grep "gcc") > /dev/null 2>&1 ;
       	then CC=`which $CC`
	     echo "yes ($CC)"
	     echo "CC = $CC" >>Makefile.config
     	     return 0
	fi 
     fi	   
   fi

   echo "no"
   echo "This package requires the GNU C compiler (gcc)."
   exit 1;
}

#
# General configuration options
#

# Pass -with-option=value args to the CFG_WITH_OPTION variable
# Note that the upcase conversion is not done here, but rather
# in one sweep at the Makefile.config generation.

function WITH_OPTION()
{  local option_name=$1
   local cooked_name=`echo $1 | sed -e 'y/-/_/'`
   local default="$2"
   local description="$3"

   # first check number of arguments and deal with help mode

   if test -z "$cooked_name" || test -z "$default"; then 
      echo "WITH_OPTION $option_name needs at last two arguments"
      exit 1
   fi

   if test -n "$cfg_help_mode"; then
      echo " --with-$option_name=$description"
      return 0
   fi

   # see if some other test forces us to stick with a certain value

   echo -n " with $option_name: "

   eval "cfg_forced_arg=\$cfg_force_with_$cooked_name"
   if test -n "$cfg_forced_arg"; then
      echo "$cfg_forced_arg (forced by previous tests)"
      CFG_WITH_OPTIONS="$CFG_WITH_OPTIONS -Dwith_${cooked_name}_$cfg_forced_arg"
      eval "cfg_with_$cooked_name=\$cfg_forced_arg"
      export "cfg_with_$cooked_name"
      return 0
   fi

   # now start the real processing
   # if $cfg_with_$cooked_name is unset, we set it to the default value
   # so that the programmer can write custom shell functions depending on it.

   eval "cfg_user_arg=\$cfg_with_$cooked_name"

   if test -z "$cfg_user_arg"; then
	echo "$default"
	CFG_WITH_OPTIONS="$CFG_WITH_OPTIONS -Dwith_${cooked_name}_$default"
	eval "cfg_with_$cooked_name=\$default"
   else
	echo "$cfg_user_arg (user supplied)"
	CFG_WITH_OPTIONS="$CFG_WITH_OPTIONS -Dwith_${cooked_name}_$cfg_user_arg"
   fi

   export "cfg_with_$cooked_name"
   return 0
}

# Define the package name and version

function PACKAGE() 
{  
   export PACKAGE=$1
   export VERSION=$2

   if test -n "$cfg_help_mode"; then return 0; fi

   echo "Configuring package $PACKAGE, version $VERSION."
   echo
   echo "CFG_PACKAGE = $PACKAGE" >> Makefile.config
   echo "CFG_VERSION = $VERSION" >> Makefile.config
}

# Add -D$1=$2 to CFG_OTHER_OPTIONS

function DEFINE_STRING()
{  
   if test -z "$1" || test -z "$2"; then
     echo "DEFINE_STRING $1 $2:"
     echo "  needs two arguments"
     exit 1;
   fi

   CFG_OTHER_OPTIONS="$CFG_OTHER_OPTIONS -D$1=\\\"$2\\\""
}

# Add CFG_$1 = $2 to makefile

function DEFINE_VAR()
{  
   if test -z "$1" || test -z "$2"; then
     echo "DEFINE_VAR $1 $2:"
     echo "  needs two arguments"
     exit 1;
   fi

   echo "CFG_$1 = $2" >> Makefile.config
}

# Find out the basedir of source installation,
# and verify that it contains the given sample file.

function GET_SRCDIR() 
{  if test -n "$cfg_help_mode"; then return 0; fi

   if ! test -e $1; then
     echo "Configure: Please cd into the root directory"
     echo "           of your software distribution"
     exit 1
   fi

   export SRCDIR=`pwd`
   echo "Source directory: " $SRCDIR
   echo "CFG_SRCDIR = $SRCDIR" >> Makefile.config
}

# Retrieve the package name (which is the name of the
# source directory).

function GET_PKGNAME() 
{  
   PKGNAME=`pwd`
   PKGNAME=`basename $PKGNAME`

   if test -n "$cfg_help_mode"; then return 0; fi

   echo "Package name: " $PKGNAME
   echo "CFG_PKGNAME = $PKGNAME" >> Makefile.config
}

# Preset the general installation directory

function GET_PREFIX() 
{  local default="$1"

   if test -n "$cfg_prefix"; then
        PREFIX=$cfg_prefix
   else PREFIX=$default
   fi

   if test -n "$cfg_help_mode"; then
     echo " --prefix=PREFIX        general installation directory"
     echo "                        [$PREFIX]"
     return 0
   fi

   echo "Installation prefix: " $PREFIX
   echo "CFG_PREFIX = $PREFIX" >> Makefile.config
}

# Determine path from defaults
# - default is given by the functions below (e.g. "bin")
# - conf_default is the default value given in the configure skript (e.g. "/opt/bin")
# - user_value is the value "bar" given by the user via --foodir=bar

function path_from_default()
{  local default="$1"
   local conf_default="$2"
   local user_value="$3"

   ret_path=$default

   # value from configure script overrides built-in default
   # unless the user has changed the -prefix

   if test ! $cfg_user_prefix && test -n "$conf_default"; then
     ret_path="$conf_default"
   fi

   # value from user overrides configure script default

   if test -n "$user_value"; then
     ret_path="$user_value"
   fi

   # paths without a leading slash are appended to $prefix

   if test ${ret_path:0:1} != '/'; then
     ret_path="$PREFIX/$ret_path"
   fi
}

# Preset the installation (binary) directory

function GET_BINDIR() 
{  local default="$1"

   path_from_default "bin" "$default" $cfg_bindir
   BINDIR=$ret_path

   if test -n "$cfg_help_mode"; then
     echo " --bindir=BINDIR        install binary files in BINDIR"
     echo "                        [$BINDIR]"
     return 0
   fi

   echo "Binary directory: " $BINDIR
   echo "CFG_BINDIR = $BINDIR" >> Makefile.config
}

# Preset the installation (documentation) directory

function GET_DOCDIR() 
{  local default="$1"

   path_from_default "doc" "$default" $cfg_docdir
   DOCDIR=$ret_path

   if test -n "$cfg_help_mode"; then
     echo " --docdir=DOCDIR        install documentation in DOCDIR"
     echo "                        [$DOCDIR]"
     return 0
   fi

   echo "Documentation directory: " $DOCDIR
   echo "CFG_DOCDIR = $DOCDIR" >> Makefile.config
}

# Preset the locale directory

function GET_LOCALEDIR() 
{  local default="$1"

   path_from_default "locale" "$default" $cfg_localedir
   LOCALEDIR=$ret_path

   if test -n "$cfg_help_mode"; then
     echo " --localedir=LPREFIX    install locale file in LPREFIX"
     echo "                        [$LOCALEDIR]"
     return 0
   fi

   echo "Locale directory: " $LOCALEDIR
   echo "CFG_LOCALEDIR = $LOCALEDIR" >> Makefile.config
}

# Preset the man page directory

function GET_MANDIR() 
{  local default="$1"

   path_from_default "man" "$default" $cfg_mandir
   MANDIR=$ret_path

   if test -n "$cfg_help_mode"; then
     echo " --mandir=MPREFIX       install manual pages in MPREFIX"
     echo "                        [$MANDIR]"
     return 0
   fi

   echo "Man page directory: " $MANDIR
   echo "CFG_MANDIR = $MANDIR" >> Makefile.config
}

# Preset the build root directory

function GET_BUILDROOT() 
{  
   if test -n "$cfg_help_mode"; then
     echo " --buildroot=DIR        install everything relative to given directory"
     echo "                        ONLY for creating packages, NOT for direct installation!"
     return 0
   fi

   BUILDROOT="$cfg_buildroot"
   if test -z "$BUILDROOT"; then
        echo "Build root: none (this is what you normally want)"
   else echo "Build root: " $BUILDROOT
   fi
   echo "CFG_BUILDROOT = $BUILDROOT" >> Makefile.config
}

# Preset the scratch directory for temporary build files

function GET_BUILDTMP() 
{  
   BUILDTMP="$cfg_buildtmp"
   if test -z "$BUILDTMP"; then
        BUILDTMP=$(pwd)
   fi	

   if test -n "$cfg_help_mode"; then
     echo " --buildtmp=DIR         put temporary build files (e.g. *.o files) into given directory"
     echo "                        [$BUILDTMP]"
     return 0
   fi

   echo "Build tmp: " $BUILDTMP
   echo "CFG_BUILDTMP = $BUILDTMP" >> Makefile.config
}

# Query a misc directory.
# name is used for the --namedir command;
# explanation is printed in --help mode.

function GET_DIR()
{  local default="$1"
   local name="$2"
   local longname="$3"
   local explanation="$4"
   local upcase=`echo $name | sed -e "$SED_UPCASE"`

   eval "DIRRESULT=\$cfg_${name}dir"
   if test -z "$DIRRESULT"; then
      DIRRESULT=$default
   fi

   if test -n "$cfg_help_mode"; then
     echo -e " --${name}dir=DIR $explanation[$DIRRESULT]"
     return 0
   fi

   echo "$longname directory: " $DIRRESULT
   echo "CFG_${upcase}DIR = $DIRRESULT" >> Makefile.config
}

#
# General compilation test functions
#

# Try to compile conftest.c

function try_compile()
{ echo "$CC $CFG_CFLAGS conftest.c $CFG_LDFLAGS $CFG_LIBS -lm -o conftest" >>$LOGFILE
  cat conftest.c >>$LOGFILE
  { (eval "$CC $CFG_CFLAGS conftest.c $CFG_LDFLAGS $CFG_LIBS -lm -o conftest") 2>>$LOGFILE; } && test -s conftest
}

function try_preprocess()
{ echo "$CC $CFG_CFLAGS -E conftest.c -o conftest.out" >>$LOGFILE
  cat conftest.c >>$LOGFILE
  { (eval "$CC $CFG_CFLAGS -E conftest.c -o conftest.out") 2>>$LOGFILE; } && test -s conftest.out
}

# Try to compile a main() with a given function

function try_function()
{  local check_function=$1

   rm -f conftest.c conftest conftest.exe
   echo "char ${check_function}();" >>conftest.c 
   echo "int main() { ${check_function}(); return 0;}" >>conftest.c
   try_compile
}

# Look for a library in common places

function try_common_library_locations
{  local library=$1
   local check_function=$2
   local lib_a=lib${library}.a
   local lib_so=lib${library}.so

   for test_dir in \
    /usr/X11*/lib \
    /usr/lib/X11* \
    /usr/local/X11*/lib \
    /usr/local/lib/X11* \
    /usr/?386/lib \
    /usr/XFree86/lib/X11 \
    /usr/lib \
    /usr/local/lib \
    /usr/pkg/lib \
    ; \
  do
    if test -r "$test_dir/$lib_a" || test -r "$test_dir/$lib_so"; then
	local lflags_save=$CFG_LDFLAGS
	add_linker_flags "$test_dir" "$CFG_LDFLAGS"
	CFG_LDFLAGS="$lflags_return"
	if try_function $check_function; then
	   libdir_return=$test_dir
           return 0
        fi
        CFG_LDFLAGS=$lflags_save
    fi
  done
  return 1
}

# Try to locate a library

function get_library
{  local wanted_lib=$1
   local check_function=$2
   eval "cfg_user_arg=\$cfg_$3_lib"
   echo -n " lib${wanted_lib}: "

   local libs_save=$CFG_LIBS
   CFG_LIBS="-l$wanted_lib $CFG_LIBS"

   # If the user specified a path, only try that and report back

   if test -n "$cfg_user_arg"; then
      local lflags_save=$CFG_LDFLAGS
      add_linker_flags "$cfg_user_arg" "$CFG_LDFLAGS"
      CFG_LDFLAGS="$lflags_return"
      if try_function $check_function; then
	 echo "$cfg_user_arg (user supplied)"
	 add_linker_flags "$cfg_user_arg"  #only return new flags!
         libs_return=-l$wanted_lib
	 return 0;
      else
	 echo "$cfg_user_arg (user supplied, but seems not to work)"
	 lflags_return=
	 libs_return=
	 CFG_LDFLAGS=lflags_save
	 CFG_LIBS=libs_save
	 return 1
      fi
   fi

   # See if it is in the linker paths assembled so far

   if try_function $check_function; then
      echo "yes"
      lflags_return=
      libs_return=-l$wanted_lib
      return 0
   fi

   # Test some common locations

   if try_common_library_locations $wanted_lib $check_function; then
      echo $libdir_return
      add_linker_flags "$libdir_return"
      libs_return=-l$wanted_lib
      return 0
   fi

   echo no
   CFG_LIBS=$libs_save
   return 1
}

# See if the given header file can be included

function try_header()
{  local header=$1

   rm -f conftest.c conftest conftest.exe
   if test -e conftest.pre; then 
      cat conftest.pre >>conftest.c
      rm conftest.pre
   fi
   echo "#include <$header>" >>conftest.c
   echo "int main() { return 0; }" >>conftest.c
   try_compile
}

# Look for a header file in common places
# $1 = wanted include file

function try_common_header_locations()
{  local header=$1

   for test_dir in \
    /usr/X11*/include \
    /usr/X11*/include/X11 \
    /usr/include/X11* \
    /usr/local/X11*/include \
    /usr/local/include/X11* \
    /usr/?386/include \
    /usr/XFree86/include/X11 \
    /usr/include \
    /usr/local/include \
    /usr/pkg/include \
    ; \
  do
    test_header=$test_dir/$header
    if test -r $test_header; then
	local cflags_save=$CFG_CFLAGS
	CFG_CFLAGS="-I$test_dir $CFG_CFLAGS"
	if try_header $header; then
	   header_return=$test_dir
	   return 0
	fi
	CFG_CFLAGS=$cflags_save
    fi
  done
  return 1
}

# Try to locate a header file

function get_header()
{  wanted_header=$1
   eval "cfg_user_arg=\$cfg_$2_incl"
   echo -n " ${wanted_header}: "

   # If the user specified a path, only try that and report back

   if test -n "$cfg_user_arg"; then
      test_header=$cfg_user_arg/$wanted_header
      if test -r $test_header; then
	 local cflags_save=$CFG_CFLAGS
	 CFG_CFLAGS="-I$cfg_user_arg $CFG_CFLAGS"
	 if try_header $wanted_header; then
             echo "$cfg_user_arg (user supplied)"
	     header_return=-I$cfg_user_arg
             return 0
         fi
      fi
      CFG_CFLAGS=$cflags_save
      echo "$cfg_user_arg (user supplied, but seems not to work)"
      return 1
   fi

   # See if it is in the standard include path first

   if try_header $wanted_header; then
   	echo "yes"
	header_return=
	return 0
   fi

   # Test some common locations

   if try_common_header_locations $wanted_header; then
	echo $header_return
	header_return=-I$header_return
	return 0
   fi

   # Failure, didn't find anything suitable

   echo no
   return 1
}

#
# Check whether the version string given in $5
# is lower than $2 $3 $4

function check_version()
{  echo -n " Checking for $1 version >= $2.$3.$4. Found version $5. "

   version_major=`echo $5 | sed -e 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'`
   version_minor=`echo $5 | sed -e 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'`
   version_micro=`echo $5 | sed -e 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'`

   if test $2 -lt $version_major; then 
      echo "Okay."
      return 0
   fi

   if test $2 -eq $version_major; then
      if test $3 -lt $version_minor; then
	 echo "Okay."
         return 0
      fi
      if test $3 -eq $version_minor; then
         if test $4 -le $version_micro; then
	    echo "Okay."
	    return 0
         fi
      fi
   fi

   echo "Bad."
   return 1
}

#
# Check for the X11 headers and libraries
#
# Cygwin lays out a landmine by keeping a copy of Xlib.h in /usr/include,
# so we must do an additional check for Shell.h in order to find the real
# location of the X includes.

function get_xincl()
{  local real_includes=
   local header_found=

   case "$cfg_system" in
     cygwin-std)  
	if get_header X11/Shell.h x; then
           real_includes=$header_return
	   if get_header X11/Xlib.h x; then
	     header_return="$real_includes $header_return"
	     header_found=yes
	   fi
        fi ;;

     *)
        if get_header X11/Xlib.h x; then
	   header_found=yes
	fi ;;
   esac

   if test -n "$header_found"; then
      echo "CFG_X_INCL = $header_return" >> Makefile.config
   else
      echo
      echo "Header file X11/Xlib.h not found."
      echo "Please specify the header location using the following option:"
      echo "--x-includes=DIR"
      exit 1
   fi
}

function get_xlib()
{  local xt_arg="$1"

   if get_library X11 XOpenDisplay x; then
      CFG_X_LFLAGS=$lflags_return
      CFG_X_LIBS=$libs_return
      if test "$xt_arg" = "with-Xt"; then
	 if get_library ICE IceConnectionNumber ice; then
	    CFG_X_LFLAGS="$lflags_return $CFG_X_LFLAGS"
	    CFG_X_LIBS="$libs_return $CFG_X_LIBS"
	 else 
	    echo "libICE not found. Use --ice-libraries=DIR."
	    exit 1
	 fi
	 if get_library SM SmFreeReasons sm; then
	    CFG_X_LFLAGS="$lflags_return $CFG_X_LFLAGS"
	    CFG_X_LIBS="$libs_return $CFG_X_LIBS"
	 else 
	    echo "libSM not found. Use --sm-libraries=DIR."
	    exit 1
	 fi
	 if get_library Xt XtToolkitInitialize xt; then
	    CFG_X_LFLAGS="$lflags_return $CFG_X_LFLAGS"
	    CFG_X_LIBS="$libs_return $CFG_X_LIBS"
	 else 
	    echo "libXt not found. Use --xt-libraries=DIR."
	    exit 1
	 fi
      fi
      echo "CFG_X_LFLAGS = $CFG_X_LFLAGS" >> Makefile.config
      echo "CFG_X_LIBS = $CFG_X_LIBS" >> Makefile.config
   else
      echo "libX11 not found."
      echo "Please specify the library location using the following option:"
      echo "--x-libraries=DIR"
      exit 1
  fi
}

function REQUIRE_X11()
{  local xt_arg="$1"

   if test -n "$cfg_help_mode"; then
     echo " --x-includes=DIR       X include files are in DIR"
     echo " --x-libraries=DIR      X library files are in DIR"
     return 0
   fi

   echo -e "\n/* *** REQUIRE_X11 $xt_arg */\n" >>$LOGFILE

   echo -n "X11 is required"
   if test "$xt_arg" = "with-Xt"; then
      echo " (with Xt)..." 
      else  echo "..." 
   fi

   get_xincl
   get_xlib "$xt_arg"
}

#
# Check for Xpm headers and libraries
#

function get_xpm_incl()
{  if get_header xpm.h xpm; then
      echo "CFG_XPM_INCL = $header_return" >> Makefile.config
   else
      echo
      echo "Header file xpm.h not found."
      echo "Please specify the header location using the following option:"
      echo "--xpm-includes=DIR"
      exit 1
   fi
}

function get_xpm_lib()
{  if get_library Xpm XpmCreatePixmapFromData xpm; then
      CFG_XPM_LFLAGS=$lflags_return
      CFG_XPM_LIBS=$libs_return
      echo "CFG_XPM_LFLAGS = $CFG_XPM_LFLAGS" >> Makefile.config
      echo "CFG_XPM_LIBS = $CFG_XPM_LIBS" >> Makefile.config
   else
      echo "libXpm not found."
      echo "Please specify the library location using the following option:"
      echo "--xpm-libraries=DIR"
      exit 1
  fi
}

function REQUIRE_XPM()
{  if test -n "$cfg_help_mode"; then
     echo " --xpm-includes=DIR     xpm include files are in DIR"
     echo " --xpm-libraries=DIR    xpm library files are in DIR"
     return 0
   fi

   echo -e "\n/* *** REQUIRE_XPM */\n" >>$LOGFILE

   echo "Xpm is required..."
   get_xpm_incl
   get_xpm_lib
}

#
# Check for the Motif headers and libraries
#

function get_motif_incl()
{  if get_header Xm/Xm.h motif; then

      echo "CFG_MOTIF_INCL = $header_return" >> Makefile.config
   else
      echo
      echo "Header file Xm/Xm.h not found."
      echo "Please specify the header location using the following option:"
      echo "--motif-includes=DIR"
      exit 1
   fi
}

function get_motif_libs()
{  if get_library Xext XShapeCombineMask xext; then
      CFG_MOTIF_LFLAGS="$lflags_return $CFG_MOTIF_LFLAGS"
      CFG_MOTIF_LIBS="$libs_return $CFG_MOTIF_LIBS"
   else
      echo "libXext not found (required by libXmu)."
      echo "Please specify the library location using the following option:"
      echo "--xext-libraries=DIR"
      exit 1
   fi
   if get_library Xmu XmuInternAtom xmu; then
      CFG_MOTIF_LFLAGS="$lflags_return $CFG_MOTIF_LFLAGS"
      CFG_MOTIF_LIBS="$libs_return $CFG_MOTIF_LIBS"
   else
      echo "libXmu not found (required by Motif)."
      echo "Please specify the library location using the following option:"
      echo "--xmu-libraries=DIR"
      exit 1
   fi

   if test $cfg_motif_major -eq 2 && test $cfg_motif_minor -gt 0; then
     if get_library Xp XpCreateContext xp; then
        CFG_MOTIF_LFLAGS="$lflags_return $CFG_MOTIF_LFLAGS"
        CFG_MOTIF_LIBS="$libs_return $CFG_MOTIF_LIBS"
     else
	if test -z "$cfg_lesstif"; then
           echo "libXp not found (required by Motif 2.1 and higher)."
           echo "Please specify the library location using the following option:"
           echo "--xp-libraries=DIR"
           exit 1
        fi
     fi
   fi

   if get_library Xm XmStringGenerate motif; then
      CFG_MOTIF_LFLAGS="$lflags_return $CFG_MOTIF_LFLAGS"
      CFG_MOTIF_LIBS="$libs_return $CFG_MOTIF_LIBS"
   else
      echo
      echo "libXm not found (Version 2.0 or higher needed)."
      echo "Please specify the library location using the following option:"
      echo "--motif-libraries=DIR"
      exit 1
   fi

   echo "CFG_MOTIF_LFLAGS = $CFG_MOTIF_LFLAGS" >> Makefile.config
   echo "CFG_MOTIF_LIBS = $CFG_MOTIF_LIBS" >> Makefile.config
   CFG_MOTIF=yes
}

function REQUIRE_MOTIF()
{  if test -n "$cfg_help_mode"; then
     echo " --motif-includes=DIR   Motif include files are in DIR"
     echo " --motif-libraries=DIR  Motif library files are in DIR"
     return 0
   fi

   echo -e "\n/* *** REQUIRE_MOTIF */\n" >>$LOGFILE

   echo "Motif is required..."
   get_motif_incl

   # Query and store version information.
   # We can't "sed" the Xm.h include file since its location is not known
   # if it is already in the standard compiler include path,
   # so we invoke a small test program to extract the version information.

   cat >conftest.c <<EOF
#include <Xm/Xm.h>
int main()
{  printf("%d.%d.%d\n",XmVERSION,XmREVISION,XmUPDATE_LEVEL);
}
EOF

   found_version="0.0.0"
   if try_compile; then found_version=`./conftest`; fi

   if ! check_version "Motif" $1 $2 $3 "$found_version"; then
     echo -e "\n Did not find a suitable version of Motif."
     exit 1
   fi
   cfg_motif_major=$version_major
   cfg_motif_minor=$version_minor
   cfg_motif_micro=$version_micro

   # OpenMotif 2.2 seems to be a bit flawed

   if test $cfg_motif_major -eq 2 && test $cfg_motif_minor -eq 2; then
     echo "* Warning: Use of Motif 2.2.x is not recommended;"
     echo "*          Read the installation notes for more info." 
   fi

   # LessTif is a bit unstable yet. Report its internal version.

   cat >conftest.c <<EOF
#include <Xm/Xm.h>
int main()
{  printf("%s\n",LesstifVERSION_STRING);
}
EOF

   if try_compile; then 
      lesstif_version=`./conftest`;
      echo " Actually, it's $lesstif_version."
      cfg_lesstif=1
      CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_LESSTIF"
   fi

   # finally check for the libs and return

   get_motif_libs
}

#
# Check for the OpenGL headers and libraries
#

function get_opengl_incl()
{  if get_header GL/gl.h opengl; then
      CFG_OPENGL_INCL=$header_return
   else
      echo
      echo "Header file GL/gl.h not found."
      echo "Please specify the header location using the following option:"
      echo "--opengl-includes=DIR"
      exit 1
   fi

   if [ $CFG_MOTIF==yes ]; then
     echo "#include <Xm/Xm.h>" >> conftest.pre
     if get_header GL/GLwMDrawA.h glwm; then
	CFG_OPENGL_INCL="$header_return $CFG_OPENGL_INCL"
     else
       echo
       echo "Header file GL/GLwMDrawA.h not found."
       echo "Please specify the header location using the following option:"
       echo "--glwm-includes=DIR"
       exit 1
     fi
   fi

   echo "CFG_OPENGL_INCL = $CFG_OPENGL_INCL" >> Makefile.config	
}

function get_opengl_libs()
{  if get_library GL glOrtho opengl; then
      CFG_OPENGL_LFLAGS=$lflags_return
      CFG_OPENGL_LIBS=$libs_return
   else
      echo "libGL not found."
      echo "Please specify the library location using the following option:"
      echo "--opengl-libraries=DIR"
      exit 1
   fi

   if [ $CFG_MOTIF==yes ]; then
      if get_library GLwM glXMakeCurrent glwm; then
        CFG_OPENGL_LFLAGS="$lflags_return $CFG_OPENGL_LFLAGS"
  	CFG_OPENGL_LIBS="$libs_return $CFG_OPENGL_LIBS"
# MesaGLwM is broken
#      elif get_library MesaGLwM glXMakeCurrent glwm; then
#        CFG_OPENGL_LFLAGS="$lflags_return $CFG_OPENGL_LFLAGS"
#  	CFG_OPENGL_LIBS="$libs_return $CFG_OPENGL_LIBS"
      elif get_library GLw glXMakeCurrent glwm; then
        CFG_OPENGL_LFLAGS="$lflags_return $CFG_OPENGL_LFLAGS"
  	CFG_OPENGL_LIBS="$libs_return $CFG_OPENGL_LIBS"
      else
        echo "No suitable Motif drawing area for OpenGL found."
	echo "Please specify the library location using the following option:"
	echo "--glwm-libraries=DIR"
	echo "Read INSTALL for hints about this error."
        exit 1
      fi
   fi

   echo "CFG_OPENGL_LFLAGS = $CFG_OPENGL_LFLAGS" >> Makefile.config
   echo "CFG_OPENGL_LIBS = $CFG_OPENGL_LIBS" >> Makefile.config
}

function REQUIRE_OPENGL()
{  if test -n "$cfg_help_mode"; then
     echo " --opengl-includes=DIR  OpenGL include files are in DIR"
     echo " --opengl-libraries=DIR OpenGL library files are in DIR"
     return 0
   fi

   echo -e "\n/* *** REQUIRE_OPENGL */\n" >>$LOGFILE

   echo "OpenGL is required..."
   get_opengl_incl
   get_opengl_libs
}

#
# Require the GLIB2 includes and libraries.
# Unlike with the other packages, we don't have to find out about the includes
# and libraries by ourselves, but just query pkg-config about them.

function REQUIRE_GLIB2()
{  local want_major="$1"
   local want_minor="$2"
   local want_micro="$3"
   local want_threads="$4"
   local found_version="0.0.0"

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   if test "$want_threads" == "WITH_THREADS"; then threads="--libs gthread-2.0"; fi

   echo -e "\n/* *** REQUIRE_GLIB2 */\n" >>$LOGFILE

   echo "GLib ${want_major}.${want_minor}.${want_micro} is required... "

   # See if pkgconfig returns something

   echo -n " pkg-config... "
   if pkg-config --cflags glib-2.0 >>config.tmp 2>&1 && pkg-config $threads --libs glib-2.0 >>config.tmp 2>&1 ; then
        echo "works"
        rm config.tmp
   else 
	echo "failed"
	echo -e "\nError message(s) from pkg-config were:"
	cat config.tmp
	rm config.tmp
cat <<EOF

Make sure you have the following packages installed:
- pkg-config (sometimes, the obvious is overlooked ;-)
- glib2

Some GNU/Linux distributions distinguish between
end-user packages of the libraries (e.g. 'glib2') and
versions suitable for building programs (e.g. 'glib2-devel').
You might have to install the development versions explicitly
even if you have already GTK+ or Gnome applications running
on your system.

EOF
	  exit 1
   fi


   # Do a test compile to make sure they did not return some junk

   CFG_GLIB2_CFLAGS=`pkg-config --cflags glib-2.0`
   CFG_GLIB2_LIBS=`pkg-config --libs glib-2.0`

   CFG_CFLAGS="$CFG_CFLAGS $CFG_GLIB2_CFLAGS"
   CFG_LIBS="$CFG_LIBS $CFG_GLIB2_LIBS"

   cat >conftest.c <<EOF
#include <glib.h>
int main(int argc, char *argv[])
{ g_malloc(1024); 

  printf("%d.%d.%d\n",GLIB_MAJOR_VERSION,GLIB_MINOR_VERSION,GLIB_MICRO_VERSION);
  return 0;
}
EOF

   echo -n " test compile... "

   if try_compile; then
        echo "works"
	rm -f conftest.c
 	found_version=`./conftest`
        if ! check_version "GLIB" "$want_major" "$want_minor" "$want_micro" "$found_version"; then
          echo -e "\n Did not find a suitable version of GLIB."
          exit 1
        fi
   else
	echo "failed"
	echo -e "\nThe tail of configure.log might contain hints\nabout the compilation problem."
	rm -f conftest.c
	exit 1
   fi

   # Successfully finished

   echo "CFG_GLIB2_CFLAGS = $CFG_GLIB2_CFLAGS" >> Makefile.config
   echo "CFG_GLIB2_LIBS = $CFG_GLIB2_LIBS" >> Makefile.config
   bindir=`pkg-config --libs-only-L glib-2.0 | sed -e 's/-L//' -e 's/lib */bin/'`
   echo "CFG_GLIB2_BINDIR = $bindir" >> Makefile.config

   return 1
}

#
# Require the GTK2 includes and libraries.
# Unlike with the other packages, we don't have to fid out about the includes
# and libraries by ourselves, but just query pkg-config about them.
# It seems that people have more trouble with getting GTK+ to work
# than with other toolkits, so we try a bit harder to diagnose them here.

function REQUIRE_GTK2()
{  local want_major="$1"
   local want_minor="$2"
   local want_micro="$3"
   local want_threads="$4"
   local found_version="0.0.0"

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   if test "$want_threads" == "WITH_THREADS"; then threads="--libs gthread-2.0"; fi

   echo -e "\n/* *** REQUIRE_GTK2 */\n" >>$LOGFILE

   echo "Gtk+ ${want_major}.${want_minor}.${want_micro} is required..."

   # See if pkgconfig returns something

   echo -n " pkg-config... "
   if pkg-config --cflags gtk+-2.0 >>config.tmp 2>&1 && pkg-config $threads --libs gtk+-2.0 >>config.tmp 2>&1 ; then
        echo "works"
	rm config.tmp
   else 
	echo "failed"
	echo -e "\nError message(s) from pkg-config were:"
	cat config.tmp
	rm config.tmp
 	cat <<EOF

Make sure you have the following packages installed:
- pkg-config (sometimes, the obvious is overlooked ;-)
- glib2
- pango
- atk
- gtk2

Some GNU/Linux distributions (e.g. SuSE) distinguish between
end-user packages of the libraries (e.g. 'gtk2') and
versions suitable for building programs (e.g. 'gtk2-devel').
You might have to install the development versions explicitly
even if you have already GTK+ or Gnome applications running
on your system.

EOF
	  exit 1
   fi

   # Do a test compile to make sure they did not return some junk

   CFG_GTK2_CFLAGS=`pkg-config --cflags gtk+-2.0`
   CFG_GTK2_LIBS=`pkg-config $threads --libs gtk+-2.0`

   CFG_GTK2_BINDIR=`which pkg-config`
   CFG_GTK2_BINDIR=`echo $CFG_GTK2_BINDIR | sed -e 's/.exe//' | sed -e 's/\/pkg-config//'`

   CFG_CFLAGS="$CFG_CFLAGS $CFG_GTK2_CFLAGS"
   CFG_LIBS="$CFG_LIBS $CFG_GTK2_LIBS"

   cat >conftest.c <<EOF
#include <gtk/gtkversion.h>

CPPABUSE GTK_MAJOR_VERSION.GTK_MINOR_VERSION.GTK_MICRO_VERSION
EOF

   echo -n " test preprocessing... "

   if try_preprocess; then
	echo "works"
	rm -f conftest.c
 	found_version=$(grep CPPABUSE ./conftest.out | tr -d "CPABUSE ()")
	rm -f conftest.out
        if ! check_version "GTK+" "$want_major" "$want_minor" "$want_micro" "$found_version"; then
          echo -e "\n Did not find a suitable version of GTK+."
          exit 1
        fi
   else
	echo "failed"
	echo -e "\nThe tail of configure.log might contain hints\nabout the compilation problem."
	rm -f conftest.c
	exit 1
   fi

   # Successfully finished

   echo "CFG_GTK2_CFLAGS = $CFG_GTK2_CFLAGS" >> Makefile.config
   echo "CFG_GTK2_LIBS = $CFG_GTK2_LIBS" >> Makefile.config
   echo "CFG_GTK2_BINDIR = $CFG_GTK2_BINDIR" >> Makefile.config
   return 1
}

#
# Require the SDL includes and libraries.
# Unlike with the other packages, we don't have to fid out about the includes
# and libraries by ourselves, but just query sdl-config about them.

function REQUIRE_SDL()
{  local want_major="$1"
   local want_minor="$2"
   local want_micro="$3"
   local found_version="0.0.0"

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   echo -e "\n/* *** REQUIRE_SDL */\n" >>$LOGFILE

   echo "SDL ${want_major}.${want_minor}.${want_micro} is required..."

   # See if sdl-config returns something

   echo -n " sdl-config... "
   if sdl-config --cflags >>config.tmp 2>&1 && sdl-config --libs >>config.tmp 2>&1 ; then
        echo "works"
	rm config.tmp
   else 
	echo "failed"
	echo -e "\nError message(s) from sdl-config were:"
	cat config.tmp
	rm config.tmp
cat <<EOF

Make sure you have sdl installed.

Some GNU/Linux distributions (e.g. Debian) distinguish between
end-user packages of the libraries (e.g. 'libsdl1.2') and
versions suitable for building programs (e.g. 'libsdl1.2-dev').
You might have to install the development versions explicitly
even if you have already SDL applications running on your system.
EOF
	  exit 1
   fi

   # Do a test compile to make sure they did not return some junk

   CFG_SDL_CFLAGS=`sdl-config --cflags`
   CFG_SDL_LIBS=`sdl-config --libs`

   CFG_CFLAGS="$CFG_CFLAGS $CFG_SDL_CFLAGS"
   CFG_LIBS="$CFG_LIBS $CFG_SDL_LIBS"

   cat >conftest.c <<EOF
#include <SDL.h>

CPPABUSE SDL_MAJOR_VERSION.SDL_MINOR_VERSION.SDL_PATCHLEVEL
EOF

   echo -n " test preprocessing... "

   if try_preprocess; then
	echo "works"
	rm -f conftest.c
 	found_version=$(grep CPPABUSE ./conftest.out | tr -d "CPABUSE ()")
	rm -f conftest.out
        if ! check_version "SDL" "$want_major" "$want_minor" "$want_micro" "$found_version"; then
          echo -e "\n Did not find a suitable version of SDL."
          exit 1
        fi
   else
	echo "failed"
	echo -e "\nThe tail of configure.log might contain hints\nabout the compilation problem."
	rm -f conftest.c
	exit 1
   fi

   # Successfully finished

   echo "CFG_SDL_CFLAGS = $CFG_SDL_CFLAGS" >> Makefile.config
   echo "CFG_SDL_LIBS = $CFG_SDL_LIBS" >> Makefile.config
   return 1
}

# Check for a generic header.
# First arg is the #include file to test for,
# Second arg is a short name to be used in --name-includes=DIR.

function CHECK_INCLUDE()
{  local file_name=$1
   local short_name=$2
   local upcase=`echo $short_name | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     echo " --${short_name}-includes=DIR   $short_name include file is in DIR"
     return 0
   fi;

   echo -e "\n/* *** CHECK_INCLUDE $file_name $short_name */\n" >>$LOGFILE

   echo -n "Checking for"

   if get_header $file_name $short_name; then
      echo "CFG_${upcase}_INCL = $header_return" >> Makefile.config
      return 0
   fi

   echo "CFG_${upcase}_INCL = " >> Makefile.config
   return 1
}

function REQUIRE_INCLUDE
{
   if ! CHECK_INCLUDE $1 $2 ; then
      echo "$1 not found."
      echo "Please specify the include file location using the following option:"
      echo "--$2-includes=DIR"
      exit 1
   fi
}

# Check for a generic library.
# First arg is the library to test for,
# Second arg is a function to look for in the library,
# Third arg is a short name to be used in --name-libraries=DIR.

function CHECK_LIBRARY()
{  local test_lib=$1
   local test_fun=$2
   local short_name=$3
   local upcase=`echo $short_name | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     echo " --${short_name}-libraries=DIR   ${short_name} library is in DIR"
     return 0
   fi

   echo -e "\n/* *** CHECK_LIBRARY $test_lib $test_fun $short_name */\n" >>$LOGFILE

   echo -n "Checking for"

   if get_library $test_lib $test_fun $short_name; then
      eval "CFG_${upcase}_LFLAGS=\$lflags_return"
      eval "CFG_${upcase}_LIBS=\$libs_return"
      echo "CFG_${upcase}_LFLAGS = $lflags_return" >> Makefile.config
      echo "CFG_${upcase}_LIBS = $libs_return" >> Makefile.config
      return 0
  fi

  echo "CFG_${upcase}_LFLAGS = " >> Makefile.config
  echo "CFG_${upcase}_LIBS = " >> Makefile.config
  return 1
}

function REQUIRE_LIBRARY
{
   if ! CHECK_LIBRARY $1 $2 $3 ; then
      echo "lib$1 not found."
      echo "Please specify the library location using the following option:"
      echo "--$3-libraries=DIR"
      exit 1
   fi
}

# Require the libpng library
# using the pkg-config mechanism

function REQUIRE_PNG
{ 
   if test -n "$cfg_help_mode"; then
     return 0
   fi

   echo -n "libpng is required... "

   echo -e "\n/* *** REQUIRE_PNG */\n" >>$LOGFILE

   # See whether pkg-config works

   if pkg-config --cflags libpng >>config.tmp 2>&1 && pkg-config --libs libpng >>config.tmp 2>&1 ; then
	rm config.tmp
   else 
	echo "pkg-config failed"
	echo -e "\nError message(s) from pkg-config were:"
	cat config.tmp
	rm config.tmp
   fi

   # Do a test compile

   CFG_PNG_CFLAGS=`pkg-config --cflags libpng`
   CFG_PNG_LIBS=`pkg-config --libs libpng`

   CFG_CFLAGS="$CFG_CFLAGS $CFG_PNG_CFLAGS"
   CFG_LIBS="$CFG_LIBS $CFG_PNG_LIBS"

   cat >conftest.c <<EOF
#include <zlib.h>
#include <png.h>
int main() { png_sig_cmp(NULL,0,0); return 0;}
EOF

   if try_compile; then
     echo "OK"
   else
     echo "FAILED"
     exit 1
   fi

   echo "CFG_PNG_CFLAGS = $CFG_PNG_CFLAGS" >> Makefile.config
   echo "CFG_PNG_LIBS = $CFG_PNG_LIBS" >> Makefile.config
}

# Check for a specific function,
# assuming that the corresponding library has already been specified
# by the preceeding configuration commands.

function CHECK_FUNCTION()
{  local fname=$1 
   local answer="none"
   local fname_upcase=`echo "$fname" | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   echo -e "\n/* *** CHECK_FUNCTION $1 */\n" >>$LOGFILE

   if try_function $fname; then
     answer="yes"
     CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_$fname_upcase"
     echo " $fname: $answer"
     return 0
   else
     answer="no"
     echo " $fname: $answer"
     return 1
   fi
}

# Check for a specific symbol in an include file.
# assuming that the corresponding library has already been specified
# by the preceeding configuration commands.

function CHECK_SYMBOL()
{  local incl_name=$1
   local symb_name=$2 
   local answer="none"
   local symb_upcase=`echo "$symb_name" | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   echo -e "\n/* *** CHECK_SYMBOL $1 $2 */\n" >>$LOGFILE

   rm -f conftest.c conftest conftest.exe
   cat > conftest.c <<EOF
#include <$incl_name>
int main(){
#ifdef $symb_name
   return 0; }
#else
 #error no symbol }
#endif
EOF

   if try_compile ; then
     answer="yes"
     CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_$symb_upcase"
     echo " $symb_name in $incl_name: $answer"
     return 0
   else
     answer="no"
     echo " $symb_name in $incl_name: $answer"
     return 1
   fi
}

# Compile and execute a test program (usually to find out if a function
# provides a certain feature). Previous tests should already have made
# sure that the program compiles correctly.
# The test program is assumed to be supplied in the file conftest.c

function EXECUTE_SOURCE()
{  local feature=$1	# natural language description of the feature
   local flag=$2	# how it's called in the HAVE defines
   local answer="none"
   local flag_upcase=`echo "$flag" | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   if try_compile; then
     if ./conftest; then
       answer="works"
       CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_$flag_upcase"
       echo " $feature: $answer"
       return 0
     else
       answer="failed"
       echo " $feature: $answer"
       return 1
     fi
   else
     answer="didn't compile"
     echo " $feature: $answer"
     return 1
   fi
}

# Execute a test program (usually to find out if a certain tool exists).

function EXECUTE_PROGRAM()
{  local command=$1	# How to invoke the program
   local flag=$2	# how it's called in the HAVE defines
   local answer="none"
   local flag_upcase=`echo "$flag" | sed -e "$SED_UPCASE"`

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   if eval $command > /dev/null 2>&1; then
     CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_$flag_upcase"
     echo " $flag: present"
     return 0
   else
     echo " $flag: missing"
     return 1
   fi
}

#
# Figure out endianess of system (not all have <endian.h>)
#

function CHECK_ENDIAN()
{
   if test -n "$cfg_help_mode"; then
     echo " --with-byte-order=[little | big]"
     return 0
   fi

   echo -e "\n/* *** CHECK_ENDIAN */\n" >>$LOGFILE
   echo -n "Checking byte order..."

   # See if user wants to override our test

   if test -n "$cfg_with_byte_order"; then
      case "$cfg_with_byte_order" in
	little) echo " little endian (user supplied)"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_LITTLE_ENDIAN"
	        ;;
	big) echo " big endian (user supplied)"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_BIG_ENDIAN"
	        ;;
        *) echo -e " $cfg_with_byte_order (illegal value)\n"
	   echo "Please use one of the following values:"
	   echo "--with-byte-order=[little | big]"
	   exit 1
	   ;;
      esac
      return 0;
   fi

   # Try automatic detection

   cat > conftest.c <<EOF
int main()
{  if(sizeof(int)==4)
   {  char *c = "1234";
      switch(*(int*)c)
      {  case 0x34333231:  printf("little\n"); break;
         case 0x31323334:  printf("big\n"); break;
         default: printf("failure"); break;
      }
   }
   else printf("failure");
}
EOF

   if try_compile; then
      endian=`./conftest`
      case "$endian" in
	little) echo " little endian"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_LITTLE_ENDIAN"
	        ;;
	big) echo " big endian"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_BIG_ENDIAN"
	        ;;
        *) echo -e " error\n"
	   echo "Byte order could not be determined."
	   echo "Please specify one using the following option:"
	   echo "--with-byte-order=[little|big]"
	   exit 1
	   ;;
      esac
  fi
}

#
# Figure out bitness of system
#

function CHECK_BITNESS()
{
   if test -n "$cfg_help_mode"; then
     echo " --with-bitness=[32 | 64]"
     return 0
   fi

   echo -e "\n/* *** CHECK_BITNESS */\n" >>$LOGFILE
   echo -n "Checking bitness..."

   # See if user wants to override our test

   if test -n "$cfg_with_bitness"; then
      case "$cfg_with_bitness" in
	32) echo " 32bit (user supplied)"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_32BIT"
	        ;;
	64) echo " 64bit (user supplied)"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_64BIT"
	        ;;
        *) echo -e " $cfg_with_bitness (illegal value)\n"
	   echo "Please use one of the following values:"
	   echo "--with-bitness=[32 | 64]"
	   exit 1
	   ;;
      esac
      return 0;
   fi

   # Try automatic detection

   cat > conftest.c <<EOF
int main()
{  switch(sizeof(char*))
   {  case 4: printf("32\n"); break;
      case 8: printf("64\n"); break;
      default: printf("failure\n"); break;
   }
}
EOF

   if try_compile; then
      bitness=`./conftest`
      case "$bitness" in
	32) echo " 32bit"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_32BIT"
	        ;;
	64) echo " 64bit"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_64BIT"
	        ;;
        *) echo -e " error\n"
	   echo "System bitness could not be determined."
	   echo "Please specify one using the following option:"
	   echo "--with-bitness=[32|64]"
	   exit 1
	   ;;
      esac
  fi
}

#
# Check for SSE2.
#

function CHECK_SSE2()
{
   if test -n "$cfg_help_mode"; then
     echo " --with-sse2=[yes | no]"
     return 0
   fi

   CHECK_SSE2_INVOKED=1

   echo -e "\n/* *** CHECK_SSE2 */\n" >>$LOGFILE
   echo -n "Checking for SSE2..."

   # See if user wants to override our test

   if test -n "$cfg_with_sse2"; then
      case "$cfg_with_sse2" in
	no)  echo " no (user supplied)"
	        ;;
	yes) echo " yes (user supplied)"
	        CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_SSE2"
	        CFG_SSE2_OPTIONS="-msse2"
	        ;;
        *) echo -e " $cfg_with_sse2 (illegal value)\n"
	   echo "Please use one of the following values:"
	   echo "--with-sse2=[yes | no]"
	   exit 1
	   ;;
      esac
      return 0;
   fi

   # Do automatic detection

   cat > conftest.c <<EOF
#include <emmintrin.h>

int main()
{ __m128i a, b, c;

  c = _mm_xor_si128(a, b);
}
EOF

   local cflags_save=$CFG_CFLAGS
   CFG_CFLAGS="-msse2 $CFG_CFLAGS"
   if try_compile; then
      echo " yes"
      CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_SSE2"
      CFG_SSE2_OPTIONS="-msse2"
   else
      echo " no"
   fi
   CFG_CFLAGS=$cflags_save
}

#
# Check for AltiVec.
#

function CHECK_ALTIVEC()
{
   if test -n "$cfg_help_mode"; then
     echo " --with-altivec=[yes | no]"
     return 0
   fi

   CHECK_ALTIVEC_INVOKED=1

   echo -e "\n/* *** CHECK_ALTIVEC */\n" >>$LOGFILE
   echo -n "Checking for AltiVec..."

   # See if user wants to override our test

   if test -n "$cfg_with_altivec"; then
      case "$cfg_with_altivec" in
       no)  echo " no (user supplied)"
               ;;
       yes) echo " yes (user supplied)"
               CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_ALTIVEC"
               CFG_ALTIVEC_OPTIONS="-maltivec"
               ;;
        *) echo -e " $cfg_with_altivec (illegal value)\n"
          echo "Please use one of the following values:"
          echo "--with-altivec=[yes | no]"
          exit 1
          ;;
      esac
      return 0;
   fi

   # Do automatic detection

   cat > conftest.c <<EOF
#include <altivec.h>

int main()
{ vector unsigned char a, b, c;

  c = vec_or(a, b);
}
EOF

   local cflags_save=$CFG_CFLAGS
   CFG_CFLAGS="-maltivec $CFG_CFLAGS"
   if try_compile; then
      echo " yes"
      CFG_HAVE_OPTIONS="$CFG_HAVE_OPTIONS -DHAVE_ALTIVEC"
      CFG_ALTIVEC_OPTIONS="-maltivec"
   else
      echo " no"
   fi
   CFG_CFLAGS=$cflags_save
}


#
# Check whether a certain program is there and executable.
#

function CHECK_PROGRAM()
{  local name=$1

   if test -n "$cfg_help_mode"; then
     return 0
   fi

   if (which $name) > /dev/null 2>&1; 
   then
     echo " $name: yes"
     return 0
   else
     echo " $name: no"
     return 1
   fi
}

#
# Clean up and build the Makefile.
#

function CREATE_MAKEFILES()
{  if test -n "$cfg_help_mode"; then
     return 0
   fi

   echo -e "\n/* *** CREATE_MAKEFILES */" >>$LOGFILE

   rm -f conftest.c conftest conftest.exe
   echo >> Makefile.config
   echo "CFLAGS = $CFG_CFLAGS" >>Makefile.config
   echo "LDFLAGS = $CFG_LDFLAGS" >>Makefile.config
   echo "CFG_SYS_OPTIONS  = $CFG_SYS_OPTIONS" >> Makefile.config
   echo "CFG_SYS_NAME     = $CFG_SYS_NAME" >> Makefile.config
   echo "CFG_EXE_SUFFIX   = $CFG_EXE_SUFFIX" >> Makefile.config
   echo "CFG_HAVE_OPTIONS = $CFG_HAVE_OPTIONS" >> Makefile.config
   echo "CFG_WITH_OPTIONS = $CFG_WITH_OPTIONS" | sed -e "$SED_UPCASE" >> Makefile.config
   echo "CFG_OTHER_OPTIONS = $CFG_OTHER_OPTIONS" >> Makefile.config
   if test -n "$CHECK_SSE2_INVOKED"; then
     echo "CFG_SSE2_OPTIONS = $CFG_SSE2_OPTIONS" >> Makefile.config
   fi
   if test -n "$CHECK_ALTIVEC_INVOKED"; then
     echo "CFG_ALTIVEC_OPTIONS = $CFG_ALTIVEC_OPTIONS" >> Makefile.config
   fi
   echo >> Makefile.config

   for i in $@; do 
     rm -f $i
     cat >> $i <<EOF
#############################################################################
#
# The settings below have been inserted by the configure command.
#
# If they do not work, you can either
#
# - try to specify the right settings to configure via the "configure" 
#   command line options
# - or edit Makefile.template directly. E.g., if CFG_MOTIF_LIBS seems
#   to hold the wrong values, search for CFG_MOTIF_LIBS in Makefile.template,
#   read the comments in the respective section, and specify the right value 
#   for MOTIF_LIBS there.
#
#   DO NOT EDIT THIS FILE OR ANY OF THE CFG_* VALUES, as they will be deleted
#   or overridden by certain make options (such as 'make distclean')
#
#############################################################################

EOF
     cat Makefile.config $i.template >> $i
  done
}