File: configure

package info (click to toggle)
hylafax 3:6.0.6-8.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,508 kB
  • sloc: sh: 15,371; ansic: 13,242; makefile: 1,545; cpp: 781; awk: 529
file content (4964 lines) | stat: -rwxr-xr-x 135,604 bytes parent folder | download | duplicates (4)
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
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
#!/bin/sh
#	$Id$
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1988-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

# Configuration script for HylaFAX (tm) (aka FlexFAX)

#
# Shell script to setup machine-dependent files in
# preparation for building HylaFax source.
#

#
# Setup general configuration parameters.
#
DIR_BIN=/usr/local/bin
DIR_SBIN=/usr/local/sbin
DIR_LIBDATA=/usr/local/lib/fax
DIR_LIB=/usr/local/lib
DIR_LIBEXEC=$DIR_SBIN
DIR_SPOOL=/var/spool/hylafax
DIR_LOCALE=/usr/local/share/locale
DIR_CGI=/var/httpd/cgi-bin
PATH_DPSRIP=$DIR_LIBEXEC/ps2fax.exe
PATH_IMPRIP=/usr/lib/print/psrip
CGIPATH=/cgi-bin
LOCALE_DOMAIN=hylafax
DEFVRES=98
PAGESIZE="North American Letter"
FAXUID=uucp
FAXGID=
SYSUID=bin
SYSGID=
DSO=auto
GETTY=auto
PS=auto
SYSVINIT=auto
FAXQ_SERVER=yes			# init script starts faxq
HFAXD_SERVER=yes		# init script starts hfaxd
HFAXD_SNPP_SERVER=no		# don't start paging protocol
SGI2FAX=auto
LIBMALLOC=auto
LOCKS=auto
DPS=no
GS=no
IMP=no
UTMP=auto
NLS=auto
OPTIMIZER="-O"
LIBCRYPT=
LIBPAM=
LIBTIFF="-ltiff"
TIFFINC=
TIFFBIN=
LIBUTIL=
LIBZ=-lz
ZLIBINC=
LIBINTL=
INTLINC=
REGEX=yes
LIBREGEX='-L${DEPTH}/regex -lregex'
REGEXINC='-I${DEPTH}/${TOPSRCDIR}/regex'
CONFIG_OSFCNH=auto
MANNUM4_5=4F
MANNUM1_8=1M
XGETTEXT="xgettext --foreign-user -ctranslator --no-wrap --sort-by-file --omit-header --strict --indent --force-po"
MSGMERGE="msgmerge --no-wrap --sort-by-file"
MSGFMT=msgfmt
MSGCAT=msgcat

# SVR4 packaging stuff
PKG_ARCH=				# ARCH variable in pkginfo file
PKG_EMAIL=someone@somehost.somedomain	# EMAIL variable in pkginfo file
PKG_VENDOR="Your Name Here"		# VENDOR variable in pkginfo file

: ${MAKE=make}				# make to use
# screws up the test of `-f -'
unset MAKEFLAGS
RM="rm -f"

#
# Note VARX parameters cannot contain more that 100 entries as it
# breaks HP's sed
#
VAR1="ANSICPP
ANSICXXPP
ABI_VERSION
ABI_PATCH
AR
AROPTS
AWK
BASE64ENCODE
BIN		DIR_BIN
CAT
CGIDIR		DIR_CGI
CGIPATH
CHGRP
CHMOD
CHOWN
CC
CCOMPILER
CMP
COL
CP
CXX
CXXCOMPILER
CXXFILE
DATE
DEFPAGESIZE
DEFVRES
DIST_ALPHA
DIST_MAJOR
DIST_MINOR
DIST_TYPE
DPS
DPSRIP 		PATH_DPSRIP
DSO
DSOSUF
DSODELAY
DSOOPTS
ECHO
ENABLE_NLS
ENCODING
ENVOPTS
FAXGID
FAXUID
FAXQ_SERVER
FILLORDER
FONTMAP
FONTPATH	PATH_AFM
FUSER
GCOPTS
GCXXOPTS
GENDIST
GETTY
GREP
GS
GSRIP 		PATH_GSRIP
HFAXD_SERVER
HFAXD_SNPP_SERVER
IMP
IMPRIP		PATH_IMPRIP
INSTALL
INTLINC
LIBDATA		DIR_LIBDATA
LIBDIR		DIR_LIB
LIBEXEC		DIR_LIBEXEC
LIBCRYPT
LIBINTL
LIBPORT
LIBREGEX
LIBTIFF
LIBUTIL
LIBZ
LIBDB
LLDOPTS
LN
LN_S
LOCALEDIR       DIR_LOCALE
LOCALE_DOMAIN
HAVE_PAM
LIBPAM
HAVE_JBIG
HAVE_JBIGTIFF
LIBJBIG"

VAR2="MACHDEPLIBS
MAKECXXOVERRIDE
MAKEDEPINCLUDE
MAKEDSOINCLUDE
MAKEINCLUDE
MAKELQUOTE
MAKERQUOTE
MAN
MANDIR DIR_MAN
MANAPPS
MANCAPPNAME
MANCFILENAME
MANCVT
MANFILES
MANNUM4_5
MANNUM1_8
MANSAPPNAME
MANSCHEME
MANSFILENAME
MANSYS
MIMENCODE
MKDEPCOPTS
MKDEPCXXOPTS
MKDEPEND
MKDIR
MKFIFO
MV
MV_F
NLS
NOCLOBBER_OFF
NOCLOBBER_ON
OPTIMIZER
PAGESIZE
PATHGETTY	PATH_GETTY
PATHVGETTY	PATH_VGETTY
PATHEGETTY	PATH_EGETTY
PCL6CMD
PKG_ARCH
PKG_EMAIL
PKG_VENDOR
PORTFUNCS
PROTOTYPES
PSPACKAGE	PS
PWDCMD
QPENCODE
RANLIB
REGEX
REGEXINC
RM		RMCMD
SBIN		DIR_SBIN
SCRIPT_SH
SED
SENDMAIL	PATH_SENDMAIL
SETMAKE
SGI2FAX
SHDLIBC
SORT
SPOOL		DIR_SPOOL
SRCDIR
STRIP
SYSGID
SYSUID
SYSVINIT
SYSVINITDIR	DIR_SYSVINIT
SYSVINITSTARTDIR	DIR_SYSVINITSTART
SYSVINITSTARTNAME	NAME_SYSVINITSTART
SYSVINITSTOPDIR	DIR_SYSVINITSTOP
SYSVINITSTOPNAME	NAME_SYSVINITSTOP
TARGET
TIFF2PDF
TIFFBIN
TIFFINC
TTYCMD
UTMP
UUCP_LOCKDIR	DIR_LOCKS
UUCP_LOCKTYPE	LOCKS
UUENCODE
VERSION
WARNING
MSGMERGE
MSGFMT
MSGCAT
XGETTEXT
ZLIBINC"

dumpvars()
{
    (for i do echo "$i"; done) |
	while read a b; do eval c=\$${b:-$a}; echo "/@$a@/s;;$c;g"; done
}
dumpvals()
{
    (echo "$VAR1"; echo "$VAR2") |
	while read a b; do eval c=\$${b:-$a}; echo "${b:-$a}='$c'"; done
}

#
# We do this little dance with the search path to insure
# that programs that we select for use by installed programs
# (which may be run by the super-user) come from trusted
# locations before they come from the user's private area.
# This should help avoid accidentally configuring some
# random version of a program in someone's personal bin.
#
OPATH=$PATH
PATH=/bin:/usr/bin:/etc
test -d /usr/ccs/bin && PATH=$PATH:/usr/ccs/bin		# SVR4/Solaris2
test -d /usr/sbin && PATH=$PATH:/usr/sbin		# SGI and others
test -d /usr/bsd && PATH=$PATH:/usr/bsd			# SGI
test -d /usr/ucb && PATH=$PATH:/usr/ucb			# Sun and others
test -d /usr/contrib/bin && PATH=$PATH:/usr/contrib/bin	# BSDi
test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc	# Sun and others
test -d /usr/local/bin && PATH=/usr/local/bin:$PATH	# for GNU stuff
PATH=$PATH:$OPATH

POSIXLY_CORRECT=1; export POSIXLY_CORRECT		# disable GNU extensions
LC_ALL=C; export LC_ALL					# set a common language

#
# Error diagnostics that should go to the terminal are
# done with this interface (or cat).
#
bitch()
{
    echo "$@" 1>&2
}

die()
{
    kill -1 $$				# use kill so trap handler is called
}

#
# This is the preferred interface for
# configure to terminate abnormally.
#
boom()
{
    bitch ""
    bitch "Unrecoverable error!  Once you've corrected the problem rerun this script."
    die
}

usage()
{
    cat<<'EOF'
Usage: configure [options] [host]
Options: [defaults in brackets after descriptions]
  --help                  print this message
  --quiet                 do not print `Using ...' messages
  --nointeractive         do not prompt for input [INTERACTIVE=no]
  --verbose		  opposite of --quiet
  --version               print the version of autoconf that created configure
  --target=TARGET         configure for TARGET [TARGET=HOST]
  --srcdir=DIR            find the sources in DIR [configure dir or ..]
  --disable-nls           disable NLS support
  --disable-pam           disable all PAM support
  --with-PARAM[=ARG]      set configuration PARAM [ARG=yes]
EOF
}

QUIET=no
INTERACTIVE=${INTERACTIVE:="yes"}
SITE=
TARGET=
RELEASE=
SRCDIR=
WITHARGS=no
#
# Crack command line arguments.  We purposely
# use syntax and options that are compatible
# with GNU autoconf.
#
ac_prev=
for ac_option
do
    if [ -n "$ac_prev" ]; then		# assign the argument to previous option
	eval "$ac_prev=\$ac_option"
	ac_prev=
	continue
    fi
    case "$ac_option" in		# collect optional argument
    -*=*)	ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'`;;
    *)		ac_optarg=;;
    esac
    case "$ac_option" in
    -with-*|--with-*)
	ac_with=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
	# Reject names that are not valid shell variable names.
	if [ -n "`echo $ac_with| sed 's/[-_a-zA-Z0-9]//g'`" ]; then
	    bitch "configure: $ac_with: invalid parameter name."
	    die
	fi
	ac_with=`echo $ac_with| sed 's/-/_/g'`
	case "$ac_option" in
	*=*)	;;
	*)	ac_optarg=yes;;
	esac
	eval "${ac_with}='$ac_optarg'"
	WITHARGS=yes
	;;
    -enable-nls|--enable-nls)	NLS=yes;;
    -disable-nls|--disable-nls)	NLS=no;;
    -quiet|--quiet)		QUIET=yes;;
    -nointeractive|--nointeractive)	INTERACTIVE=no;;
    -verbose|--verbose)		QUIET=no;;
    -site|--site)		ac_prev=SITE;;
    -site=*|--site=*)		SITE="$ac_optarg";;
    -srcdir|--srcdir)		ac_prev=SRCDIR;;
    -srcdir=*|--srcdir=*)	SRCDIR="$ac_optarg";;
    -target|--target)		ac_prev=TARGET;;
    -target=*|--target=*)	TARGET="$ac_optarg" ;;
	-disable-pam|--disable-pam) DISABLE_PAM="yes" ;;
    -version|--version)
	echo "This is HylaFAX configure $Revision$"
	exit 0
	;;
    -help|--help)		usage; exit 0;;
    -*)
	bitch "configure: $ac_option: invalid option; use -help for usage."
	die
	;;
    *)
	if [ x"$TARGET" != x ]; then
	    bitch "configure: Can only configure for one target at a time."
	    kill -1 $$
	fi
	TARGET="$ac_option"
	;;
    esac
done

if [ -n "$ac_prev" ]; then
    bitch "configure: missing argument to --`echo $ac_prev | sed 's/_/-/g'`"
    die
fi

#
# Locate source directory by looking for the VERSION file.
# The directory must either be specified through the
# environment or be located in the current directory or a
# parent of the current directory.
#
test "$SRCDIR" || {
    configure=$0
    # NB: don't use dirname since it may not exist
    SRCDIR=`echo $configure | sed 's;/[^/][^/]*$;;'`
    if [ @"$SRCDIR" = @"$configure" ]; then
        SRCDIR=.
    fi
    while [ ! -r $SRCDIR/VERSION ]; do
	# strip last directory from pathname
	newdir=`echo $SRCDIR | sed 's;/[^/]*$;;'`
	if [ -z "$newdir" ] || [ "$newdir" = $SRCDIR ]; then
	    break;
	fi
	SRCDIR=$newdir
    done
}
if [ ! -r $SRCDIR/VERSION ]; then
    bitch "Can not locate sources in $SRCDIR; the file $SRCDIR/VERSION"
    bitch "does not exist or is unreadable."
    boom
fi
SRCDIR=`echo "$SRCDIR" | sed 's;\([^/]\)/*$;\1;'`

#
# Descriptor usage:
# 1: ???
# 2: messages that should be seen even if we're in the background.
# 3: [stdout from test runs]
# 4: verbose-style messages (Using ...)
# 5: compiler stderr when running tests
#
if [ $QUIET = yes ]; then
    exec 4>/dev/null			# chuck messages
else
    exec 4>&1				# messages go to stdout
fi
$RM ./config.log
exec 5>./config.log			# compiler messages and the like

DATE=`date`

eval `cat $SRCDIR/VERSION | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)[.-]\([0-9]*\)\(.*\)/DIST_MAJOR=\1; DIST_MINOR=\2; DIST_PATCH=\3; DIST_TYPE=\4/'`
DIST_ALPHA=`awk '{print $3}' $SRCDIR/dist/hylafax.alpha`
VERSION="${DIST_MAJOR}.${DIST_MINOR}.${DIST_PATCH}${DIST_TYPE}"
if [ "$DIST_TYPE" = beta ]; then
    VERSION="${VERSION}${DIST_ALPHA}"
fi
ABI_VERSION="${DIST_MAJOR}.${DIST_MINOR}"
if [ -n "$DIST_PATCH" ]
then
        ABI_PATCH="${DIST_PATCH}"
else
        ABI_PATCH="0"
fi

Note()
{
    echo "$@" 1>&4
}

capture()
{
    (eval "set -x; $*") >&5 2>&1
    return
}
captureX()
{
    (eval "set -x; $*") 2>&5
    return
}

date >&5
cat 1>&5 <<'EOF'

This file contains information that was captured from running the configure
script.  Lines that begin with a "+" are command lines echoed by the
shell.  Other lines are the output of commands; usually the contents of
test case files or the output from compilers.  If configure does the
wrong thing, use the information captured here to aid in debugging.

EOF

Note ""
Note "Configuring HylaFAX (tm) (aka FlexFAX) $VERSION."
Note ""
Note "If configure does the wrong thing, check the file config.log for"
Note "information that may help you understand what went wrong."
Note ""

# test for broken expr (Tru64 UNIX)
x="00"
match=`expr "$x" : "\([0-9]*\)"`
if [ "$match" != "$x" ]; then
	bitch "Your expr is broken. It strips leading zeroes"
	bitch "This may cause problems with configure, faxsetup, & faxaddmodem"
	bitch "Perhaps there is an environment variable you can set"
	bitch "to get the desired behavior."
fi

#
# Read site and local configuration parameters.
#
CONFIG_FILES=
if [ -f $SITE/config.site ]; then
    Note "Reading site-wide parameters from $SITE/config.site."
    . $SITE/config.site
    capture . $SITE/config.site
    CONFIG_FILES=$SITE/config.site
elif [ -f $SRCDIR/config.site ]; then
    Note "Reading site-wide parameters from $SRCDIR/config.site."
    . $SRCDIR/config.site
    capture . $SRCDIR/config.site
    CONFIG_FILES=$SRCDIR/config.site
fi
if [ -f config.local ]; then
    Note "Reading local parameters from config.local."
    . ./config.local
    capture . ./config.local
    CONFIG_FILES="$CONFIG_FILES config.local"
elif [ -f $SRCDIR/config.local ]; then
    Note "Reading local parameters from $SRCDIR/config.local."
    . $SRCDIR/config.local
    capture . $SRCDIR/config.local
    CONFIG_FILES="$CONFIG_FILES $SRCDIR/config.local"
fi
#
# Flush cached values if something was specified on the
# command line or if the contents of a config parameter
# file was changed more recently.
#
REASON=
if [ $WITHARGS = yes ]; then 
    REASON="of command line parameters"
elif [ "$CONFIG_FILES" ]; then
    REASON=`find $CONFIG_FILES -newer config.cache -print 2>/dev/null`
    test "$REASON" && REASON="$REASON has been updated"
fi
if [ "$REASON" ] && [ -f config.cache ]; then
   Note "Flushing cached parameters because $REASON."
   Note ""
   rm -f config.cache
fi
if [ -f config.cache ]; then
    Note "Reading cached parameters from config.cache."
    Note ""
    ODATE="$DATE"; OVERSION="$VERSION"
    OPORTFUNCS="$PORTFUNCS"; OMACHDEPLIBS="$MACHDEPLIBS"
    OTIFFINC="$TIFFINC"; OLIBTIFF="$LIBTIFF"
    OZLIBINC="$ZLIBINC"; OLIBZ="$LIBZ"
    OREGEXINC="$REGEXINC"; OLIBREGEX="$LIBREGEX"
    OINTLINC="$INTLINC"; OLIBINTL="$LIBINTL"
    . ./config.cache
    capture . ./config.cache
    # NB: these are calculated each time from scratch
    DATE="$ODATE"; VERSION="$OVERSION"
    MACHDEPLIBS="$OMACHDEPLIBS"; PORTFUNCS="$OPORTFUNCS"
    # NB: these are relativized each time so beware of cached value
    TIFFINC="$OTIFFINC"; LIBTIFF="$OLIBTIFF"
    ZLIBINC="$OZLIBINC"; LIBZ="$OLIBZ"
    REGEXINC="$OREGEXINC"; LIBREGEX="$OLIBREGEX"
    INTLINC="$OINTLINC"; LIBINTL="$ILIBINTL"
fi

identifyTarget()
{
    random=`date | awk '{print $4}' | sed -e 's/.*://'` 2>/dev/null
    case "$random" in
    *0) Note "Wow, you've got a $1 system!";;
    *1) Note "Hmm, looks like a $1 system.";;
    *2) Note "Oh no, not another $1 system...";;
    *3) Note "Well I'll be, a $1 system.";;
    *4) Note "Fee, fie, foe, this smells like a $1 system.";;
    *5)	Note "Gosh, aren't you lucky to have a $1 system!";;
    *6)	Note "YOW!!  Did something bad happen or am I on a $1 system?";;
    *7)	Note "Do they really still make $1 systems?!";;
    *8)	Note "I'm always happy to encounter another $1 system.";;
    *9)	Note "Here we are again, this time on a $1 system.";;
    esac
}

#
# If no target is specified, try to deduce the system.
# We use the GNU scripts for guessing and canonicalizing
# the system identification, if available.
#
if [ -z "$TARGET" ]; then
    test -f $SRCDIR/config.guess && TARGET=`sh $SRCDIR/config.guess` 2>/dev/null
    if [ -z "$TARGET" ]; then
	bitch "Sorry, no target was specified on the command line and I don't seem to"
	bitch "have the GNU config.guess script that is used to deduce your system type."
	boom
    fi
    identifyTarget $TARGET
elif [ -f $SRCDIR/config.sub ]; then
    TARGET=`sh $SRCDIR/config.sub "$TARGET"`
else
    Note "WARNING, the GNU config.sub script does not seem to be present.  This"
    Note "         script is used to canonicalize your target specification; not"
    Note "         having it may cause problems later on..."
fi
echo "TARGET: $TARGET" >&5
RELEASE=`(uname -r) 2>/dev/null` || RELEASE=unknown
echo "RELEASE: $RELEASE" >&5

#
# Find the full pathname of a file
# using the specified test operation.
#
findThing()
{
    t="$1"; app=$2; path=$3;
    case $app in
    /*) eval $t $app && { echo $app; return; };;
    esac
    IFS=:
    for i in $path; do
	eval $t $i/$app && { echo $i/$app; return 0; }
    done
    return 1
}

#
# Find the full pathname of a plain file.
#
findFile()
{
    findThing "test -f" $1 $2
}

#
# Find the full pathname of an executable.
#
findApp()
{
    t="$1"; app=$1; path=$2;
    case $app in
    /*) eval test -x $app && test ! -d $app && { echo $app; return; };;
    esac
    IFS=:
    for i in $path; do
	eval  test -x $i/$app && test ! -d $i/$app && { echo $i/$app; return 0; }
    done
    return 1
}

#
# Find the full pathname of an executable;
# supply a default if nothing is found.
#
findAppDef()
{
    app=$1; path=$2; def=$3
    case $app in
    /*) test -x $app && { echo $app; return; };;
    esac
    IFS=:
    for i in $path; do
	test -x $i/$app && { echo $i/$app; return; }
    done
    echo $def
}

#
# Fixup a list of potentially relative pathnames so
# that they work when used in a subdirectory.  The
# string sent to stdout has no extraneous spaces so
# it can be used, for example, in building pathnames.
#
# NB: There's an extra echo done here so we get a
#     \n-terminated string passed to sed.
#
relativize()
{
    echo `(for i do
	case "$i" in
	-Wl*)			echo "$i" ;;
	/*|-l*|-l[$]{DEPTH}/*)	echo "$i" ;;
	-L|-L/*|-L[$]{DEPTH}/*)	echo "$i" ;;
	-I|-I/*|-I[$]{DEPTH}/*)	echo "$i" ;;
	-R|-R/*|-R[$]{DEPTH}/*)	echo "$i" ;;
	[$][{]DEPTH[}]/*) echo "$i" ;;
	-L*)		echo "$i" | sed 's;^-L;-L../;' ;;
	-R*)		echo "$i" | sed 's;^-R;-R../;' ;;
	-I*)		echo "$i" | sed 's;^-I;-I../;' ;;
	*)		echo "../$i" ;;
	esac
    done) | tr '\012' ' '` | \
	sed -e 's;/[.]/;/;g' -e 's;[ ][ ]*$;;' -e 's;/[.]$;;'
}

#
# Locate a C and C++ compiler and verify they work and
# satisfy our needs (using assorted heuristics).
#
JUNK="
    a.out
    conffifo
    confsed1
    confsed2
    conftestmmap
    confx confy
    confMakefile
    conf.db
    core
    dummy
    dummy.C
    dummy.a
    dummy.c
    dummy.o
    foo
    m.c
    so_locations
    t.c
    t.c++
    t.o
    t
    xMakedepend
    xdefs
    xgnu.c
    xmakeinc
    xport.h
    xtermios.h
"
trap "$RM \$JUNK; exit 1" 1 2 15

$RM $JUNK

#
# Before we go too far, check some features required by the software
#

if [ -z "$MKFIFO" ]; then
    MKFIFO=`findApp mkfifo $PATH`
    if [ "$MKFIFO" ]; then
	mkfifo()
	{
	    $MKFIFO $1
	}
    else
	MKFIFO=`findApp mknod /sbin:$PATH`
	if [ -z "$MKFIFO" ]; then
	    cat <<EOF
No support for creating a FIFO special file.

There does not appear to be a way to create a FIFO special file.
No mkfifo program or mknod program was located in the expected
locations.  One of these programs is required for proper operation
of this software.  If these programs are located in a non-standard
location then you can setup the MKFIFO configuration parameter to
reflect the appropriate location.  Otherwise you may need to install
additional software on your system to support FIFO special files
before you can configure the building of this software.
EOF
	    boom
	fi
	mkfifo()
	{
	    $MKFIFO $1 p
	}
    fi
fi

cat>xgnu.c<<EOF
#ifdef __GNUC__
yes;
#endif
EOF

#
# Check if the specified compiler is from GNU 
#
isGNU()
{
    capture "cat xgnu.c; ($1 -E xgnu.c 2>&5 | egrep yes)"
}

checkGCCVersion()
{
    app=$1; shift
    eval `$app -v 2>&1 | \
	sed -n -e '/[Vv]ersion/s/[^(]* [a-z\-]*\([0-9]*\)\.\([0-9]*\).\([0-9]*\).*/GCCdist=\1;GCCmajor=\2;GCCminor=\3/p'`
    GCCversion="${GCCdist}.${GCCmajor}.${GCCminor}"; export GCCversion
    if [ ${GCCdist} -gt $1 ]; then
        return 0
    fi
    if [ ${GCCdist} -eq $1 ]; then
        if [ ${GCCmajor} -gt $2 ]; then
            return 0
        fi
        if [ ${GCCmajor} -eq $2 ] && [ ${GCCminor} -ge $3 ]; then
            return 0
        fi
    fi
    return 1
}

#
# NB: use ANSI C prototype to weed out non-ANSI compilers.
#
cat>dummy.c<<EOF
main(int argc, char* argv) { exit(0); }
EOF

checkCompiler()
{
    compiler=$1
    if isGNU $compiler; then
	ISGCC=yes
    else
	ISGCC=no
    fi
    #
    # Guess special options needed to get an
    # ANSI C compiler and/or similar.  Must
    # be combined with above checks so we only
    # select an ANSI C compiler.
    #
    if [ -z "${ENVOPTS:-}" ]; then
	case $ISGCC-$TARGET in
	no-*-hpux11*)	C_ANSI="-Aa -D_HPUX_SOURCE -Dhpux -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED";;
	yes-*-hpux11*)  C_ANSI="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED";;
	no-*-hp*)	C_ANSI="-Aa -D_HPUX_SOURCE -Dhpux";;
	no-*-sco3.2v5.*)	C_ANSI="-Dsco -Dsco5 -b elf";;
	yes-*-sco3.2v5.*)	C_ANSI="-Dsco -Dsco5 -m486";;
	*-*-sco*)		C_ANSI="-Dsco";;
	*-isc*)		C_ANSI="-posix -D_SYSV3 -DISC";;
	yes-*-solaris*)	C_ANSI="-L/usr/local/lib -R/usr/local/lib";;
	esac
    else
	C_ANSI="$ENVOPTS"
    fi
    $RM dummy dummy.o
    capture $compiler -o dummy ${C_ANSI} dummy.c && {
	CC=$compiler;
	test -z "${CCOMPILER:-}" && CCOMPILER=`findApp $compiler $PATH`
	test -z "${ENVOPTS:-}"   && ENVOPTS="${C_ANSI:-}"
	return 0
    }
    return 1
}

CCtested=
capture cat dummy.c
if [ -z "${CC:-}" ]; then
    CCOMPILER=
    for i in gcc cc ncc dcc xlc c89 gcc2 acc; do
	CCtested="$CCtested $i"
	checkCompiler $i && break
    done
else
    CCtested="$CCtested $CC"
    checkCompiler $CC
fi
if [ -z "$CCOMPILER" ]; then
    cat<<EOF

Cannot locate a working ANSI C compiler.

We attempted to compile the following test program:

----------------------------------------------------------
EOF
    cat dummy.c
    cat<<EOF
----------------------------------------------------------

with these compilers:

    $CCtested

but none of them were successful.

If your compiler is in a non-standard location, you can specify its
location in several ways:

    o set the environment variable CC
    o create a config.local or config.site file that includes a
      definition for CC
    o supply it on the command line using -with-CC=<pathname>

If command line options are required for ANSI C compilation, set the
ENVOPTS parameter to these options in a similar way (either through
an environment variable or config.local/config.site) and then rerun
this script.
EOF
    boom
fi
Note "Using $CCOMPILER for a C compiler (set CC to override)."

test "$ENVOPTS" && {
    Note "Using $ENVOPTS to get the appropriate compilation environment."
}

CheckForGandO()
{
    f=$1
    if test -s $f; then
	capture grep -i \(error\|warning\) $f || return 1
    fi
    return 0
}

if [ -z "$GCOPTS" ]; then
    capture $CCOMPILER $ENVOPTS -g -c dummy.c && {
	Note "Looks like $CCOMPILER supports the -g option."
	# NB: cannot use captureX here 'cuz we lose stderr
	if $CCOMPILER $ENVOPTS $GCOPTS -c -g -O dummy.c >t 2>&1 && CheckForGandO t; then
	    GCOPTS="$GCOPTS -g"
	else
	    Note "... but not together with the -O option, not using it."
	fi
    }
fi
if [ "$GCOPTS" ]; then
    Note "Using \"$GCOPTS\" for C compiler options."
fi

# 
# Figure out if there is an ANSI C-preprocessor and,
# if __ANSI_CPP__ is not automatically set, configure
# it to be set.
#
cat>dummy.c<<EOF
#define ansiIDENT(a) a
#define ansiCAT(a,b) a##b
A=ansiCAT(ANSI,CPP);
EOF
capture cat dummy.c
if capture "$CCOMPILER $ENVOPTS -E dummy.c | grep ANSICPP"; then
    Note "Looks like $CCOMPILER has an ANSI C preprocessor."
    cat>dummy.c<<EOF
#ifdef __ANSI_CPP__
yes
#else
no
#endif
EOF
    capture cat dummy.c
    if capture "$CCOMPILER $ENVOPTS -E dummy.c | grep no"; then
	ANSICPP='-D__ANSI_CPP__'
	Note "... but __ANSI_CPP__ is not automatically defined, will compensate."
    fi
else
    Note "Looks like $CCOMPILER has a non-ANSI C preprocessor, will try to compensate."
fi

#
# Figure out if the C compiler supports a -M option for generating
# Make dependency information.
#
cat>dummy.c<<EOF
main(int argc, char* argv) { exit(0); }
EOF
capture cat dummy.c
if capture "$CCOMPILER -c -M $MKDEPCOPTS dummy.c | grep '^dummy.o[ 	]*:[ 	]*dummy.c'"; then
    Note "Looks like $CCOMPILER supports the -M option for generating make dependencies."
    MKDEPEND='\${SHELL} \${PORT}/mkdepend'
else
    Note "Looks like $CCOMPILER does not support the -M option for generating"
    Note "make dependencies; will disable automatic make dependency building."
    MKDEPEND=":"
fi

cat>dummy.C<<EOF
class foo {
public:
    struct bar {
	int a;
	bar();
    };
    foo();
};
foo::bar::bar() { a = 0; }
foo::foo() { bar x; }
int main() { foo t; return 0; }
EOF

checkCompiler()
{
    compiler=$1
    if isGNU $compiler; then
	ISGXX=yes
	checkGCCVersion $compiler 2 6 1 || return 1
    else
	ISGXX=no
    fi
    $RM dummy dummy.o
    capture $compiler -o dummy dummy.C && {
	CXX=$compiler;
	test -z "${CXXCOMPILER:-}" && CXXCOMPILER=`findApp $compiler $PATH`
	return 0
    }
    return 1
}

CCtested=; ISGXX=no
capture cat dummy.C
if [ -z "${CXX:-}" ]; then
    CXXCOMPILER=
	CXXCOMPILERS="g++ gcc CC NCC DCC gcc2 xlC"
    for i in $CXXCOMPILERS; do
	    CCtested="$CCtested $i"
	    checkCompiler $i && break
    done
else
    CCtested="$CCtested $CXX"
    checkCompiler $CXX
fi
if [ -z "$CXXCOMPILER" ]; then
    cat<<EOF

Cannot locate a suitable C++ compiler.

We attempted to compile the following test program:

----------------------------------------------------------
EOF
    cat dummy.C
    cat<<EOF
----------------------------------------------------------

with these compilers:

    $CCtested

but none of them were successful.

To build this software you need a C++ compiler that supports a
reasonably modern version of C++.  In particular the compiler must
support nested types and process temporary variables according to the
ANSI Reference Manual (the ARM).

If such a compiler is in a non-standard location, you can specify its
location in several ways:

    o set the environment variable CXX
    o create a config.local or config.site file that includes a
      definition for CXX
    o supply it on the command line using -with-CXX=<pathname>

If you are trying to use GNU gcc, but you do not have version 2.6.1
or newer, then you must update your compiler (and probably libg++ as
well) before you can compile this software.  Consult the documentation
for information about obtaining an up-to-date version of gcc.
EOF
    boom
fi
Note "Using $CXXCOMPILER for a C++ compiler (set CXX to override)."

if [ -z "$GCXXOPTS" ]; then
    case $CXX-$TARGET in
    *CC-*-irix*)		# cfront-based or cfront-compatible
	GCXXOPTS='+a1 +w +p'
	;;
    *xlC-*-aix*)
	GCXXOPTS='-qlanglvl=compat -I/usr/lpp/xlC/include -I/usr/include'
	;;
    *CC-*-sco3.2v5.*)		# cfront-based or cfront-compatible
	GCXXOPTS='+a1 +p'
	;;
    *CC-*-sysv5*)                # CC here needs this, cc doesn't
        GCXXOPTS='-Wf,--variadic_macro'
        ;;
    *)
	GCXXOPTS=
	;;
    esac
    capture $CXXCOMPILER $ENVOPTS -c -g dummy.C && {
	Note "Looks like $CXXCOMPILER supports the -g option."
	# NB: cannot use captureX here 'cuz we lose stderr
	if $CXXCOMPILER $ENVOPTS -c -g -O dummy.C >t 2>&1 && CheckForGandO t; then
	    GCXXOPTS="$GCXXOPTS -g"
	else
	    Note "... but not together with the -O option, not using it."
	fi
    }
fi
if [ "$GCXXOPTS" ]; then
    Note "Using \"$GCXXOPTS\" for C++ compiler options."
fi

# 
# Figure out if there is an ANSI preprocessor for the C++
# compiler and, if __ANSI_CPP__ is not automatically set,
# configure it to be set.
#
cat>dummy.C<<EOF
#define ansiIDENT(a) a
#define ansiCAT(a,b) a##b
A=ansiCAT(ANSI,CPP);
EOF
capture cat dummy.C
if capture "$CXXCOMPILER $ENVOPTS -E dummy.C | grep ANSICPP"; then
    Note "Looks like $CXXCOMPILER has an ANSI C preprocessor."
    cat>dummy.C<<EOF
#ifdef __ANSI_CPP__
yes
#else
no
#endif
EOF
    if capture "$CXXCOMPILER $ENVOPTS -E dummy.C | grep no"; then
	ANSICXXPP='-D__ANSI_CPP__'
	Note "... but __ANSI_CPP__ is not automatically defined, will compensate."
    fi
else
    Note "Looks like $CXXCOMPILER has a non-ANSI C++ preprocessor, will try to compensate."
fi

#
# Some pre-processors (e.g. SunPRO prior to version 3.0.1)
# leave comments in a file when invoked with the -E option. 
# This messes up the default scheme used below to check for
# function declarations.  Consequently we check for this
# behaviour here and try to work around the problem with
# some sed hackery.
#
cat>dummy.C<<EOF
/* this comment should be stripped */
something else just in case
and another line also
EOF
capture cat dummy.C
if capture "$CXXCOMPILER $ENVOPTS -E dummy.C | grep comment"; then
    Note "WARNING, \"$CXX -E\" does not strip comments, will try to compensate."
    Note "         Beware that this may not work and you may need to edit port.h"
    Note "         to remove extraneous function declarations."
    stripComments()
    {
	sed -e '/\/\*/,/\*\//d' -e 's;//.*$;;'
    }
else
    stripComments()
    {
	cat
    }
fi

#
# Check to see if the C++ compiler has an inbuilt 'bool' type
#
cat>dummy.C<<EOF
int main()
{
    bool success = false;
    return 0;
}
EOF
capture cat dummy.C
if capture "$CXXCOMPILER $ENVOPTS dummy.C"; then
    CONFIG_NEEDBOOL=no
else
    Note "Looks like will need to define the 'bool' type."
    CONFIG_NEEDBOOL=yes
fi

#
# Verify that $MAKE is accessible
#
PATHMAKE=`findApp ${MAKE} $PATH`
if [ "$PATHMAKE" ]; then
    Note "Using $PATHMAKE to configure the software."
else
    cat<<EOF
No $MAKE located in the search path.

There was no $MAKE program in the search path used by this script.
If $MAKE is in a non-standard location, then set the MAKE environment
variable to the pathname of the appropriate program or change your
shell search path to include the directory where the program is located.
EOF
    boom
fi

#
# Deduce the include syntax supported by make.
#
CheckForMakeIncludeSyntax()
{
    cat>confMakefile<<EOF
$1
all:
EOF
    capture "cat confMakefile; ${MAKE} -f confMakefile"
}
if [ -z "$MAKEINCLUDE" ] || [ -z "$MAKELQUOTE" ] || [ -z "$MAKERQUOTE" ]; then
    INC=xmakeinc
    $RM $INC; echo "" >$INC
    if CheckForMakeIncludeSyntax "include $INC"; then
	MAKEINCLUDE="include"
	MAKELQUOTE=
	MAKERQUOTE=
    elif CheckForMakeIncludeSyntax ".include <$INC>"; then
	MAKEINCLUDE=".include"
	MAKELQUOTE="<"
	MAKERQUOTE=">"
    elif CheckForMakeIncludeSyntax "#include \"$INC\""; then
	MAKEINCLUDE="#include"
	MAKELQUOTE='"'
	MAKERQUOTE='"'
    else
	cat 1>&2 <<EOF
$MAKE does not support a known include syntax.

The make program configured for use in building this software does not
support a known syntax for including other files in a Makefile.  The
Makefiles distributed with this software depend on the ability to include
other files and will not work without this functionaliy.  The following
syntaxes are understood and configure automatically selects one for use
if $MAKE looks to support it:

include file
.include <file>
#include "file"

If $MAKE does support including files then you should use a different
program to build this software; consult the documentation for help in
locating a suitable make program.  Otherwise if $MAKE supports include
files, but using a different syntax, then you can setup the MAKEINCLUDE,
MAKELQUOTE, and MAKERQUOTE configuration parameters to define the
appropriate syntax.
EOF
	boom
    fi
fi
Note "Using \"${MAKEINCLUDE} ${MAKELQUOTE}file${MAKERQUOTE}\" syntax for Makefiles."

if [ -z "$MAKEDEPINCLUDE" ]; then
    if [ "$MKDEPEND" != ":" ]; then
	$RM xMakedepend
	if CheckForMakeIncludeSyntax "sinclude xMakedepend"; then
	    Note "Looks like $MAKE supports \"sinclude\" for conditional includes."
	    MAKEDEPINCLUDE="sinclude"
	else
	    MAKEDEPINCLUDE="$MAKEINCLUDE"
	fi
    else
	MAKEDEPINCLUDE='#'
    fi
fi

#
# Check whether or not $MAKE automatically sets MAKE
# in the Makefiles.  If not, we add an explicit define
# for places where recursive calls are made.
#
if [ -z "$SETMAKE" ]; then
    cat>confMakefile<<EOF
all:
	@echo M="${MAKE}"
EOF
    M=; eval `$MAKE -f confMakefile` >&5 2>&1
    if [ "$M" ]; then
	SETMAKE=
    else
	Note "Looks like $MAKE does not setup MAKE in Makefiles, will compensate."
	SETMAKE="MAKE	= ${MAKE}"
    fi
fi

if [ -z "$MAKECXXOVERRIDE" ]; then
    case $ISGXX-$TARGET in
    no-*-solaris*|no-*-sunos*)			# SunPRO C++ compiler
	#
	# Yech, the SunPro C++ compiler < v5 has no option to force a source
	# file w/ a .c++ suffix to be treated as C++ source code; instead one
	# must specify file.c++=.C.  We patch the Makefiles with explicit
	# construction rules to do this...
	#
	if [ "`$CXX -V 2>&1 | sed 'q' | sed 's/.* C++ \([^ .]*\).*/\1/g'`" -lt "5" ]; then
	    MAKECXXOVERRIDE="=.C";
	fi
	;;
    esac
fi
if [ -z "$CXXFILE" ]; then
    case $CXX-$TARGET in
    xlC-*-aix*)		CXXFILE="-+";;
    gcc-*)		CXXFILE="-x c++";;
    *-*darwin*)		CXXFILE="-x c++";;
    CC-*-sco3.2v5.*)	CXXFILE="+.c++";;
    esac
fi

test "$AR" || AR=`findApp ar $PATH`
if [ -z "$AR" ]; then
    Note "WARNING, could not locate a suitable ar command; using a default."
    AR=ar
fi
test "$AROPTS" || AROPTS=rc
test "$RANLIB" || RANLIB=`findApp ranlib $PATH`
if [ -z "$RANLIB" ]; then
    Note "WARNING, no ranlib, assuming it's not needed."
    RANLIB=":"
    $RM dummy.a
    if capture $AR rcs dummy.a; then
       AROPTS=crs
       Note "Looks like ar has an s option to build symbol tables."
    fi
fi

cat>dummy.C<<EOF
#include "new.h"
struct foo {
    int x;
    foo();
    ~foo();
};
foo::foo() {}
foo::~foo() {}
int main()
{
    foo* ptr = 0;
    foo* a = new(ptr) foo;
    a->x = 0;
    delete a;
    return 0;
}
EOF

#
# Look for appropriate C++ runtime support library.
#
CXXRUNTIME=
capture cat dummy.C
capture $CXXCOMPILER $ENVOPTS -o dummy dummy.C || {
    #
    # Compiler does not provide it automatically, check known libraries.
    #
    if [ "$ISGXX" = yes ]; then
	capture $CXXCOMPILER $ENVOPTS -o dummy dummy.C -lg++ && \
	    { CXXRUNTIME="-lg++"; }
    else
	capture $CXXCOMPILER $ENVOPTS -o dummy dummy.C -lC && \
	    { CXXRUNTIME="-lC"; }
    fi
}
test "$CXXRUNTIME" && {
    Note "Using explicit $CXXRUNTIME reference for C++ runtime support."
}

#
# XXX we should deduce the shell bugs that require us to use
# bash and ksh instead of sh on certain platforms (notably the
# BSD-crowd: Linux, BSDI, FreeBSD, NetBSD) but they are very
# hard to isolate.  We choose bash over ksh over sh; though
# this may be iffy (ksh appears to be just as busted some places).
#
test "$SCRIPT_SH" || SCRIPT_SH=`findApp bash $PATH`
test "$SCRIPT_SH" || SCRIPT_SH=`findApp ksh $PATH`
test "$SCRIPT_SH" || SCRIPT_SH=`findApp sh $PATH`
if [ -z "$SCRIPT_SH" ]; then
    Note ""
    Note "WARNING, could not locate a suitable shell for processing the command"
    Note "         scripts included in this distribution; using a default value"
    Note "         /bin/sh."
    Note ""
    SCRIPT_SH=/bin/sh
else
    Note "Using $SCRIPT_SH to process command scripts."
# Security stuff
    case $SCRIPT_SH in
	*/sh)	;;
	*/ksh)	NOCLOBBER_ON='"set -o noclobber"'
		NOCLOBBER_OFF='"set +o noclobber"' ;;
	*/bash)	NOCLOBBER_ON='"set -o noclobber"'
		NOCLOBBER_OFF='"set +o noclobber"' ;;
    esac
fi

makeDefs()
{
    WARNING="Warning, this file was automatically created by the HylaFAX configure script"
    $RM confsed1; dumpvars "$VAR1" | sort>confsed1
    $RM confsed2; dumpvars "$VAR2" | sort>confsed2
    unset POSIXLY_CORRECT
    $RM xdefs; sed -f confsed1 $SRCDIR/defs.in | sed -f confsed2 >$1
    POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
}

# NB: save original values for use in checks below
OTIFFINC="${TIFFINC}"; x="`relativize ${TIFFINC}`"; TIFFINC="$x"
OZLIBINC="${ZLIBINC}"; x="`relativize ${ZLIBINC}`"; ZLIBINC="$x"
OREGEXINC="${REGEXINC}"; x="`relativize ${REGEXINC}`"; REGEXINC="$x"
makeDefs xdefs

#
# runMake target rules ...
#
runMakeX()
{
    target="$1"; shift
    $RM $target
    (echo DEPTH=.; echo SRCDIR=.; cat xdefs;
       for i in "$@"; do
	  echo "$i";
       done
    )>confMakefile
    captureX ${MAKE} -f confMakefile $target
    return
}
runMake()
{
    runMakeX "$@" >&5
    return
}

#
# Verify everything is setup for the C++ runtime environment.
#
CheckForCXXRuntime()
{
cat>t.c++<<EOF
#include <iostream>
int main(){ std::cout << "Hello World!" << std::endl; return 0;}
EOF
    runMake t "t:; \${C++F} \${C++FILE} t.c++${MAKECXXOVERRIDE}" || return $?
    Note "Looks like the system has a CXX runtime"
}
CheckForDeprecatedCXXRuntime()
{
cat>t.c++<<EOF
#include <iostream.h>
int main(){ cout << "Hello World!" << endl; return 0;}
EOF
    runMake t "t:; \${C++F} \${C++FILE} t.c++${MAKECXXOVERRIDE}" || return $?
    s=$?
    Note "Looks like the system has a CXX runtime with deprecated headers"
    HAS_DEPRECATED_CXX=yes
}
CheckForCXXRuntime || CheckForDeprecatedCXXRuntime || {
    cat 1>&2 <<EOF

Missing C++ runtime support for $CXX ($CXXCOMPILER).

Compilation of the following test program failed:

----------------------------------------------------------
EOF
    cat t.c++ 1>&2
	cat 1>&2 <<EOF
----------------------------------------------------------

Usually this is because you do not have a standard C++ library
installed on your system or you have installed it in a non-standard
location.  If you do not have a C++ library installed, then you must
install it.  If it is installed in a non-standard location, then you
should configure the compiler so that it will automatically be found.

(For recent gcc releases this is libstdc++, for older gcc - libg++)
EOF
    boom
}

#
# Verify C++ built executables properly handle global
# static variables with constructors.
#
CheckForCXXGlobalConstructors()
{
cat>t.c++<<EOF
class foo {
private:
    int a;
public:
    foo() { a = -1; }
    int isInitialized() { return a == -1; }
};
static foo instanceOfFoo;
int main() { return instanceOfFoo.isInitialized() ? 0 : 1; }
EOF
    runMake t "t:; \${C++F} \${C++FILE} t.c++${MAKECXXOVERRIDE}" && ./a.out
}
CheckForCXXGlobalConstructors || {
    cat 1>&2 <<EOF

Broken C++ handling of global constructors ($CXX/$CXXCOMPILER).

Compilation or execution of the following test program failed:

----------------------------------------------------------
EOF
    cat t.c++ 1>&2
    cat 1>&2 <<EOF
----------------------------------------------------------

This program tests whether or not the C++ compilation support properly
handles global static variables with constructors.  A working C++
compilation environment is expected to arrange that global variables
that have a constructor function (foo::foo() above) be called prior to
the start of main().  HylaFAX will not operate properly if the C++
compilation environment does not correctly implement this.

EOF
    if [ $ISGXX = yes ]; then
	if expr $CXX : '.*g++.*' >/dev/null 2>&1; then
	    cat 1>&2 <<EOF
When using GNU gcc this can sometimes happen if gcc is improperly
configured; consult your local GNU guru/support person for help with
this problem.

EOF
	else
	    cat 1>&2 <<EOF
When using GNU gcc to compile C++ programs this can sometimes happen
when g++ is not used to link executables.  You might try setting
CXX to "g++" (or similar) in a config.local file or on the command
line.  Otherwise you should consult your local GNU guru/support person
for help with this problem.

EOF
	fi
    fi
    boom
}

#
# Look for a library using a known (unique) function.
#
CheckForLibrary()
{
    f=$1; shift
    libs="$@";
    cat>t.c<<EOF
int t() { $f(); return 0; }
int main(){ t(); return 0; }
EOF
    capture cat t.c
    runMake t "t:; \${CCF} t.c $libs"
}

#
# Look for a library using a known (unique) function.
#
CheckForLibraryWithArgs()
{
    f=$1; shift
    a=$1; shift
    libs="$@";
    cat>t.c<<EOF
int t() { $f($a); return 0; }
int main(){ t(); return 0; }
EOF
    capture cat t.c
    runMake t "t:; \${CCF} t.c $libs"
}

#
# Look for an include file.
#
CheckForIncludeFile()
{
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} -E t.c++${MAKECXXOVERRIDE}"
}

if [ "$SGI2FAX" = auto ]; then
    if CheckForLibrary iopen -limage && CheckForIncludeFile gl/image.h; then
	Note "Looks like there is support for SGI RGB images, configuring sgi2fax."
	SGI2FAX=yes
    else
	SGI2FAX=no
    fi
fi
if [ "$LIBMALLOC" = auto ]; then
    if CheckForLibrary mallopt -lmalloc; then
	Note "Looks like -lmalloc is here, using it for memory allocation."
	LIBMALLOC=yes
    else
	LIBMALLOC=no
    fi
fi
if [ "$LIBSUN" = auto ]; then
    if CheckForLibrary getpwnam -lsun; then
	Note "Looks like -lsun is here, using it for NIS passwd & group stuff."
	LIBSUN=yes
    else
	LIBSUN=no
    fi
fi

#
# PAM libraries are slightly different.  So we run some tests to try to
# distinguish between them.
#
CheckPAMType()
{
    Note "... checking PAM library version"
    cat>t.c++<<EOF
#include "security/pam_appl.h"
int
pamconv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata)
{
    return(0);
}
main()
{
    struct pam_conv conv = { pamconv };
}
EOF
    if runMake t "t:; \${C++F} $LIBPAM \${C++FILE} t.c++${MAKECXXOVERRIDE}"; then
	echo '#define STRUCT_PAM_MESSAGE const struct pam_message'
    else
	echo '#define STRUCT_PAM_MESSAGE struct pam_message'
    fi
    case $TARGET in
	*-hpux11*)	echo '#define PAM_MSG_VERSION';;
    esac
}

HAVE_PAM="/*#define HAVE_PAM 1*/"
if [ "$DISABLE_PAM" != "yes" ]; then
	Note "Checking for PAM (Pluggable Authentication Module) support"
	CheckForLibrary pam_authenticate -lpam &&
		CheckForIncludeFile security/pam_appl.h && {
			HAVE_PAM="#define HAVE_PAM 1"
			LIBPAM="-lpam"
		}
	if [ "x$LIBPAM" = "x" ]; then
		Note "... not found. Disabling PAM support"
		else
		Note "... found. Enabling PAM support"
	fi
else
	Note "Disabling PAM support"
fi
HAVE_JBIG="/*#define HAVE_JBIG 1*/"
LIBJBIG=""
if [ "$DISABLE_JBIG" != "yes" ]; then
	Note "Checking for JBIG library support"
	CheckForLibrary jbg_enc_init -ljbig &&
		CheckForIncludeFile jbig.h && {
			HAVE_JBIG="#define HAVE_JBIG 1"
			LIBJBIG="-ljbig"
		}
	if [ "x$LIBJBIG" = "x" ]; then
		Note "... not found. Disabling JBIG support"
	else
		Note "... found. Enabling JBIG support"
	fi
else
	Note "Disabling JBIG support"
fi
ENABLE_NLS="/* #define ENABLE_NLS 1 */"
if [ "$NLS" != "no" ]; then
	Note "Checking for NLS (gettext) library support"
	CheckForIncludeFile locale.h && 
	    CheckForIncludeFile libintl.h &&
            runMake t "t:; $MSGMERGE /dev/null /dev/null> /dev/null" && {
		ENABLE_NLS="#define ENABLE_NLS 1"
                NLS='yes'
		CheckForLibraryWithArgs gettext '""' $LIBINTL || {
		    CheckForLibraryWithArgs gettext '""' -lintl || {
			Note "Couldn't find anything to link for gettext"
			cat 1>&2 <<EOF
Missing INTL Library.

Compilation of the following test program failed:

----------------------------------------------------------
EOF
        cat t.c 1>&2
        cat 1>&2 <<EOF
----------------------------------------------------------

LIBINTL=${LIBINTL}

Verify that you have the LIBINTL configuration parameters
set correctly for your system (see above) and that any environment
variables are setup that are needed to locate a libtiff DSO at runtime
(e.g. LD_LIBRARY_PATH). Also be sure that any relative pathnames are
made relative to the top of the build area.

If you don't want NLS support, you can disable it with --disable-nls
EOF
			boom
			return 1
                    }
		    Note "Looks like -lintl is needed for gettext support."
		    LIBINTL="-lintl"
                }
		Note "... found. Enabling NLS support"
		CheckForLibraryWithArgs ngettext '"", "", 1' ${LIBINTL} || {
			Note "Need ngettext support"
			CONFIG_NEEDNGETTEXT=yes
		}
		if [ -n "$LIBINTL" ]; then
		    MACHDEPLIBS="$MACHDEPLIBS $LIBINTL"
		fi
	} ||
		Note "... not found. Disabling NLS support"
else
	Note "Disabling NLS (gettext) support"
fi

CheckForLibrary crypt -lc || {
    #
    # FreeBSD-2.1 in particular needs -lcrypt.
    # SCO sometime has -lcrypt_d (domestic) and
    #    sometimes -lcrypt_i (import?)
    #
    for i in -lcrypt -lcrypt_d -lcrypt_i; do
	if CheckForLibrary crypt $i; then
	    Note "Looks like $i is needed for crypt."
	    LIBCRYPT="$i"
	    break;
	fi
    done
}
CheckForLibraryWithArgs strftime "(void*)0, 0, (void*)0, (void*)0" -lc || {
    #
    # SCO has strftime in -lintl.
    #
    if CheckForLibrary strftime -lintl; then
	Note "Looks like -lintl is needed for strftime."
	MACHDEPLIBS="$MACHDEPLIBS -lintl"
    else
	cat 1>&2 <<EOF
No strftime function located in system libraries.

The strftime function used to format date&time information was not located
in the normal C library or in the -lintl library (present on some systems).
This software expects this to be available and will not compile without it.
If this function is located in a non-standard location you can specify the
library in the MACHDEPLIBS configuration parameter.  Otherwise you should
figure out why the usual testing done by this script failed; consult the
diagnostics in the config.log file for more information.
EOF
	boom
    fi
}
CheckForLibrary socket -lc || {
    #
    # Socket support is not in normal C library, check
    # for SVR4-style networking w/ -lsocket & -lnsl
    #
    if CheckForLibrary socket -lsocket -lnsl; then
	Note "Looks like -lsocket & -lnsl are needed for socket support."
	MACHDEPLIBS="$MACHDEPLIBS -lsocket -lnsl"
    elif CheckForLibrary socket -linet -lnsl_s; then
	Note "Looks like -linet & -lnsl_s are needed for socket support."
	MACHDEPLIBS="$MACHDEPLIBS -linet -lnsl_s"
    elif CheckForLibrary socket -lsocket; then
	Note "Looks like -lsocket is needed for socket support."
	MACHDEPLIBS="$MACHDEPLIBS -lsocket"
    else
	cat 1>&2 <<EOF
No socket networking support located in system libraries.

The socket function used to create a network connection was not located
in the normal C library or in the -lsocket or -linet libraries (present
mainly on SVR4-style systems).  This software expects this to be
available and will not compile without it.  If this function is located
in a non-standard location you can specify the needed libraries in the
MACHDEPLIBS configuration parameter.  Otherwise you should figure out
why the usual testing done by this script failed; consult the
diagnostics in the config.log file for more information.
EOF
	boom
    fi
}

CheckForLibrary inet_aton -lc || {
    CheckForLibrary inet_aton -lresolv && {
	MACHDEPLIBS="$MACHDEPLIBS -lresolv"
    }
}

if CheckForLibrary logwtmp -lutil; then
    Note "Looks like -lutil is needed for wtmp file logging."
    LIBUTIL="-lutil"
    HAS_LOGWTMP=yes
else
    HAS_LOGWTMP=no
fi
CheckForLibrary ftruncate -lc || {
    CheckForLibrary chsize -lx && {
	Note "Looks like -lx is needed for chsize (used to emulate ftruncate)."
	MACHDEPLIBS="$MACHDEPLIBS -lx"
    }
}
CheckForLibrary flock -lc || {
    CheckForLibrary flock -lbsd && {
	Note "Looks like -lbsd is needed for flock."
	MACHDEPLIBS="$MACHDEPLIBS -lbsd"
    }
}
for f in openlog pututxline; do
    CheckForLibrary $f -lc || {
	CheckForLibrary $f -lgen && {
	    Note "Looks like -lgen is needed for $f."
	    MACHDEPLIBS="$MACHDEPLIBS -lgen"
	    break;
	}
    }
done
if [ "$ISGXX" = yes ]; then
    if [ -z "$CXXRUNTIME" ]; then
	for f in memmove strdup; do
	    CheckForLibrary $f -lc || {
		CheckForLibrary $f -lg++ && {
		    Note "Looks like we need -lg++ for $f"
		    MACHDEPLIBS="$MACHDEPLIBS -lg++"
		    break;
		}
	    }
	done
    fi
    for f in strtoul strerror memmove random; do
	CheckForLibrary $f -lc || {
	    CheckForLibrary $f -liberty && {
		Note "Looks like we need -liberty for $f"
		MACHDEPLIBS="$MACHDEPLIBS -liberty"
		break;
	    }
	}
    done
fi
CheckForLibrary floor -lm && {
    Note "Looks like -lm is the library for math functions."
    MACHDEPLIBS="$MACHDEPLIBS -lm"
}
MACHDEPLIBS="$MACHDEPLIBS $CXXRUNTIME"
test "$LIBSUN" = yes && MACHDEPLIBS="$MACHDEPLIBS -lsun"
test "$LIBMALLOC" = yes && MACHDEPLIBS="$MACHDEPLIBS -lmalloc"

#
# Figure out if certain system-specific interfaces are
# supported.  We craft a port.h file that has external
# declarations for missing routines that are required by
# the system and modify defs to reflect which optional
# interfaces are supported.
#

EmitCPlusPlusPrologue()
{
    echo '/*'
    echo ' * Warning, this file was automatically created by the HylaFAX configure script'
    echo ' * VERSION:	' $VERSION
    echo ' * DATE:	' $DATE
    echo ' * TARGET:	' $TARGET
    echo ' * RELEASE:	' $RELEASE
    if [ $ISGCC = yes ]; then
	echo ' * CCOMPILER:	' ${CCOMPILER}-${GCCversion}
    else
	echo ' * CCOMPILER:	' $CCOMPILER
    fi
    if [ $ISGXX = yes ]; then
	echo ' * CXXCOMPILER:	' ${CXXCOMPILER}-${GCCversion}
    else
	echo ' * CXXCOMPILER:	' $CXXCOMPILER
    fi
    echo ' */'
    echo "#ifndef $1"
    echo "#define $1 1"
    echo '#ifdef __cplusplus'
    echo 'extern "C" {'
    echo '#endif'
}

EmitCPlusPlusEpilogue()
{
    echo '#ifdef __cplusplus'
    echo '}'
    echo '#endif'
    echo '#endif'
}

releaseAtLeast()
{
    expr $RELEASE \>= $1 >/dev/null 2>&1
}

#
# Emit the port.h definitions that reflect
# the system configuration.
#
EmitConfigurationDefinitions()
{
    #
    # Do bool stuff
    #
    if [ "$CONFIG_NEEDBOOL" = "yes" ]; then
        Note "... adding definition for C++ bool type"
        echo
        echo "#define NEED_BOOL"
        echo
    fi

    #
    # Select the mode to use when opening FIFO files
    # in a server process.  One should be able to open
    # them read-only, but on some systems, select will
    # go into a loop when a client does a close.  This
    # problem can sometimes be avoided by opening the FIFO
    # read+write on the server side.  Otherwise, the
    # FIFO must be closed after each incoming message
    # which can lead to delays and/or lost messages
    # (though we try to compensate by doing some sleeps).
    #
    test "$CONFIG_OPENFIFO" || {
	case $TARGET in
	*-irix*)	if releaseAtLeast 5.2; then
			    CONFIG_OPENFIFO=O_RDWR;
			else
			    CONFIG_OPENFIFO=O_RDONLY;
			fi
			;;
	*-ultrix*)	CONFIG_OPENFIFO=O_RDWR;;
	*-solaris*)	CONFIG_OPENFIFO=O_RDWR;;
	*-*-sco*|*-isc*)	CONFIG_OPENFIFO=O_RDWR;;
	*-aix*|*-hpux*)	CONFIG_OPENFIFO=O_RDWR;;
	alpha-dec*)     CONFIG_OPENFIFO=O_RDWR;;
	*-linux*)	if releaseAtLeast 1.3.80; then
			    CONFIG_OPENFIFO=O_RDWR;
			else
			    CONFIG_OPENFIFO=O_RDONLY;
			fi
			;;
	*-freebsd*)	if releaseAtLeast 3.0; then
			    CONFIG_OPENFIFO=O_RDWR;
			else
			    CONFIG_OPENFIFO=O_RDONLY;
			fi
			;;
	*sysv4.2uw2.1.3)	CONFIG_OPENFIFO=O_RDWR;;	# UnixWare 2.1.3
	*-sysv5UnixWare*)	CONFIG_OPENFIFO=O_RDWR;;	# UnixWare 7
	*-sysv5OpenUNIX*)	CONFIG_OPENFIFO=O_RDWR;;	# OpenUNIX 8
	*-sysv5SCO_SV*)		CONFIG_OPENFIFO=O_RDWR;;	# OpenServer 6
	*)		CONFIG_OPENFIFO=O_RDONLY;;
	esac
    }
    if [ "$CONFIG_OPENFIFO" = "O_RDWR" ]; then
	Note "... open FIFO files read+write to avoid select bug"
    else
	Note "... open FIFO files read-only"
    fi
    echo "#define CONFIG_OPENFIFO $CONFIG_OPENFIFO"
    test "$CONFIG_FIFOBUG" || {
	case $TARGET in
	*-solaris*)	CONFIG_FIFOBUG=yes;;
	*-irix5.[01]*)	CONFIG_FIFOBUG=yes;;
	*)		CONFIG_FIFOBUG=no;;
	esac
    }
    if [ "$CONFIG_FIFOBUG" = yes ]; then
	Note "... enable workaround for FIFO select bug"
	echo '#define FIFOSELECTBUG 1'
    fi

    #
    # On some systems the argument for ioctl(fd, TIOCMBIS, arg)
    # is passed by value and some by reference.
    # This can not be deduced with a dynamic check.
    #
    test "$CONFIG_TIOCMBIS_ARG_REF" || {
	case $TARGET in
	*-sysv4*)	CONFIG_TIOCMBISBYREF=yes;;
	*-sysv5*)	CONFIG_TIOCMBISBYREF=yes;;
	*-linux*)	CONFIG_TIOCMBISBYREF=yes;;
	*-sunos*)	CONFIG_TIOCMBISBYREF=yes;;
	*)		CONFIG_TIOCMBISBYREF=yes;;
	esac
    }
    if [ "$CONFIG_TIOCMBISBYREF" = yes ]; then
	Note "... using call-by-reference for TIOCMBIS ioctl"
	echo "#define CONFIG_TIOCMBISBYREF $CONFIG_TIOCMBISBYREF"
    else
	Note "... using call-by-value for TIOCMBIS ioctl"
    fi
	
    #
    # On some systems it's necessary to include
    # <sys/stream.h> and <sys/ptem.h> to get the
    # necessary definitions for TIOCWINSZ.  This
    # should be deduced with a dynamic check.
    #
    test "$CONFIG_WINSZHACK" || {
	case $TARGET in
	*-*-sco*)	CONFIG_WINSZHACK=yes;;
	*-isc*)		CONFIG_WINSZHACK=yes;;
	*)		CONFIG_WINSZHACK=no;;
	esac
    }
    if [ "$CONFIG_WINSZHACK" = yes ]; then
	Note "... enable additional include files for TIOCGWINSZ"
	echo "#define CONFIG_WINSZHACK"
    fi

    #
    # On some systems the server does not work properly
    # if a recursive call is made to the dispatcher to
    # poll for an message on the FIFO file that says to
    # abort an outbound or inbound job.   The only know
    # workaround for this problem is to ignore messages
    # while processing a job.
    #
    test "$CONFIG_ABORTBUG" || {
	case $TARGET in
	*-aix*)		CONFIG_ABORTBUG=yes;;
	*-hpux*)	CONFIG_ABORTBUG=yes;;
	*)		CONFIG_ABORTBUG=no;;
	esac
    }
    if [ "$CONFIG_ABORTBUG" = yes ]; then
	Note "... disable support for aborting sends & receives"
	echo '#define SERVERABORTBUG'
    fi

    #
    # On some systems redirecting stdout to the controlling
    # tty causes stty to issue an annoying warning message.
    # This should probably be deduced with a dynamic test.
    #
    test "$CONFIG_NOSTDINDUP" || {
	case $TARGET in
	*-freebsd*)	CONFIG_NOSTDINDUP=yes;;
	*)		CONFIG_NOSTDINDUP=no;;
	esac
    }
    if [ "$CONFIG_NOSTDINDUP" = yes ]; then
	Note "... assuming stty bitches when stdout is set to stdin"
	echo "#define ONDELAY_NOSTDINDUP"
    fi
    #
    # Some systems cannot handle re-opening the tty device
    # after the modem is reset.  This is true for modems
    # attached to some terminal servers and also on HP-UX
    # where the modem control state is lost across opens.
    # Basically if the OS and modem correctly handle toggling
    # DTR to reset the modem then it's safe to configure
    # the software to not re-open the device.
    #
    test "$CONFIG_NOREOPEN" || {
	case $TARGET in
	*-hpux*)	CONFIG_NOREOPEN=yes;;
	*)		CONFIG_NOREOPEN=no;;
	esac
    }
    if [ "$CONFIG_NOREOPEN" = yes ]; then
	Note "... don't reopen the tty device after reset"
	echo "#define CONFIG_NOREOPEN"
    fi
    #
    # Workarounds for systems with system include files
    # that have incorrect function declarations (wrong
    # parameter types that require explicit casts to make
    # the code compile with certain compilers).
    #
    test "$CONFIG_BADEXECVPROTO" || {		# char* const* vs. const char**
	case $TARGET in
	*-*-sco3.2v5.*)	CONFIG_BADEXECVPROTO=no;;
	*-*-sco*)	CONFIG_BADEXECVPROTO=yes;;
	*)		CONFIG_BADEXECVPROTO=no;;
	esac
    }
    if [ "$CONFIG_BADEXECVPROTO" = yes ]; then
	Note "... workaround incorrect execv function declaration"
	echo "#define CONFIG_BADEXECVPROTO"
    fi
    test "$CONFIG_BADEXECVEPROTO" || {		# char* const* vs. const char**
	case $TARGET in
	*-*-sco3.2v5.*)	CONFIG_BADEXECVEPROTO=no;;
	*-*-sco*)	CONFIG_BADEXECVEPROTO=yes;;
	*)		CONFIG_BADEXECVEPROTO=no;;
	esac
    }
    if [ "$CONFIG_BADEXECVEPROTO" = yes ]; then
	Note "... workaround incorrect execve function declaration"
	echo "#define CONFIG_BADEXECVEPROTO"
    fi
    test "$CONFIG_BADGETOPTPROTO" || {		# char* const* vs. char**
	case $TARGET in
	*-aix*)		CONFIG_BADGETOPTPROTO=yes;;
	*-*-sco3.2v4.*)	CONFIG_BADGETOPTPROTO=yes;;
	*)		CONFIG_BADGETOPTPROTO=no;;
	esac
    }
    if [ "$CONFIG_GETOPTPROTO" = yes ]; then
	Note "... workaround incorrect getopt function declaration"
	echo "#define CONFIG_GETOPTPROTO"
    fi
    test "$CONFIG_BADSELECTPROTO" || {		# int* vs. fd_set*
	case $TARGET in
	*-hpux10.20*)	CONFIG_BADSELECTPROTO=no;;
	*-hpux11*)	CONFIG_BADSELECTPROTO=no;;
	*-hpux*)	CONFIG_BADSELECTPROTO=yes;;
	*)		CONFIG_BADSELECTPROTO=no;;
	esac
    }
    if [ "$CONFIG_BADSELECTPROTO" = yes ]; then
	Note "... workaround incorrect select function declaration"
	echo "#define CONFIG_BADSELECTPROTO"
    fi
    #
    # Select the maximum fax UID.  This value is stored
    # in the GID of files so must be constrained by any
    # system limitations.  The maximum value is used for
    # anonymous logins.  The default value of 60002 comes
    # from NFS/nobody usage on various systems.
    #
    test "$CONFIG_MAXGID" || {
	case $TARGET in
	*-*-sco*)	CONFIG_MAXGID=60000;;
	*-sysv5UnixWare*)	CONFIG_MAXGID=60000;;	# UnixWare 7
	*-sysv5OpenUNIX*)	CONFIG_MAXGID=60000;;	# OpenUNIX 8
	*-sysv5SCO_SV*)		CONFIG_MAXGID=60000;;	# OpenServer 6
	*-hpux*)	CONFIG_MAXGID=60000;;
	*)		CONFIG_MAXGID=60002;;	# default
	esac
    }
    if [ "$CONFIG_MAXGID" ]; then
	if [ "$CONFIG_MAXGID" -le 60002 ]; then
	    Note "... constrain client IDs to be <= $CONFIG_MAXGID"
	    echo "#define CONFIG_MAXGID $CONFIG_MAXGID"
	else
	    Note "... max client ID too large ($CONFIG_MAXGID); using default"
	fi
    fi
    if [ "$CONFIG_NEEDNGETTEXT" ]; then
	Note "... need ngettext"
	echo "#define NEED_NGETTEXT"
    fi
    test "$CONFIG_DARWIN_BROKEN_FD_ISSET" || {
       case $TARGET in
       *-darwin*)      CONFIG_DARWIN_BROKEN_FD_ISSET=yes;;
       *)              ;;
       esac
    }
    if [ "$CONFIG_DARWIN_BROKEN_FD_ISSET" ]; then
       Note "... work around broken Darwin FD_ISSET"
       echo "#include <sys/select.h>"
       echo "#define __darwin_fd_isset(a,b) __darwin_fd_isset(a, (fd_set*)b)"
    fi
}

#
# Look for a function in one of the standard libraries
# or one of the machine-dependent libraries selected above.
#
CheckForFunc()
{
    echo "extern int $1(); main(){$1($2);exit(0);}" >t.c
    capture cat t.c
    runMake t "t:; \${CC} t.c ${MACHDEPLIBS}"
}

#
# Look for a function declaration in system include files.
#
AddFuncDecl()
{
    echo "$2";
    Note "... add function prototype for $1"
}
CheckForFuncDecl()
{
    f=$1; shift
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    capture cat t.c++
    runMakeX t "t:; \${C++F} \${C++FILE} -E t.c++${MAKECXXOVERRIDE}" |\
     stripComments |\
     awk '{while($0~/[,(][ \t]*$/){printf"%s",$0;getline}print}' |\
     grep "$f[ ]*(.*)" >&5
    return
}
CheckFuncDecl()
{
    f=$1; shift
    decl=$1; shift
    CheckForFuncDecl "$f" "$@" || AddFuncDecl "$f" "$decl"
}

#
# Look for a variable declaration in system include files.
#
CheckForVarDecl()
{
    v="$1"; shift
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    capture cat t.c++
    runMakeX t "t:; \${C++F} \${C++FILE} -E t.c++${MAKECXXOVERRIDE}" |\
	stripComments |\
	grep "$v" >&5
    return
}
CheckVarDecl()
{
    v="$1"; shift
    decl="$1"; shift
    CheckForVarDecl "$v" "$@" || \
	(echo "$decl"; Note "... add declaration $decl")
}

#
# Look for a #define in system include files.
#
AddDefine()
{
   echo '#ifndef' $1
   echo '#define' "$2"
   echo '#endif'
   Note '... add #define for' "$1"
}
CheckForDefine()
{
    def=$1; shift
    (for i do
	echo "#include \"$i\""
     done
     for i in "#ifdef $def" "FOUND" "#endif"; do
	echo "$i"
     done
    )>t.c
    capture cat t.c
    runMakeX t 't:; ${CCF} -E t.c' | grep FOUND >&5
}
CheckDefine()
{
    def=$1; shift
    decl=$1; shift
    CheckForDefine "$def" "$@" || AddDefine "$def" "$decl"
}

#
# Look for a #define with a positive value in system include files.
# This is especially useful for POSIX defines which may be defined
# to -1 or 0 when the functionnality is not supported.
#
CheckForPositiveDefine()
{
    def=$1; shift
    (for i do
	echo "#include \"$i\""
     done
     for i in "#if defined($def) && ($def > 0L)" "FOUND" "#endif"; do
	echo "$i"
     done
    )>t.c
    capture cat t.c
    runMakeX t 't:; ${CCF} -E t.c' | grep FOUND >&5
}

CheckTermioFuncDecls()
{
    CheckFuncDecl cfsetospeed \
	'extern int cfsetospeed(const struct termios*, speed_t);' $@
    CheckFuncDecl cfsetispeed \
	'extern int cfsetispeed(const struct termios*, speed_t);' $@
    CheckFuncDecl tcgetattr 'extern int tcgetattr(int, struct termios*);' $@
    CheckFuncDecl tcsetattr \
	'extern int tcsetattr(int, int, const struct termios*);' $@
    CheckFuncDecl tcsendbreak 'extern int tcsendbreak(int, int);' $@
    CheckFuncDecl tcdrain 'extern int tcdrain(int);' $@
    CheckFuncDecl tcflush 'extern int tcflush(int, int);' $@
    CheckFuncDecl tcflow 'extern int tcflow(int, int);' $@
}

BuildTermiosDotH()
{
    CheckForIncludeFile termios.h || {
	CheckForIncludeFile sys/termios.h || {
	    bitch "Cannot locate termios.h or sys/termios.h."
	    boom
	}
	Note ""
	Note "No termios.h found; creating one with necessary definitions."
	(EmitCPlusPlusPrologue _TERMIOS_
	 echo '#include "sys/termios.h"'
	 CheckTermioFuncDecls sys/termios.h
	 EmitCPlusPlusEpilogue
	)>xtermios.h
	mv xtermios.h termios.h; chmod 444 termios.h
    }
}

CheckSigvecHandler()
{
    cat>t.c++<<EOF
#include <sys/types.h>
#include <signal.h>
void sigHUP(int) {}
void f() {
    struct sigvec sv;
    sv.sv_handler = $1 (sigHUP);
    (void) sigvec(SIGHUP, &sv, (struct sigvec*) 0);
}
int main() { f(); return 0; }
EOF
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} -c t.c++${MAKECXXOVERRIDE}"
}
CheckSigactionHandler()
{
    cat>t.c++<<EOF
#include <sys/types.h>
#include <signal.h>
void sigHUP(int) {}
void f() {
    struct sigaction sa;
    sa.sa_handler = $1 (sigHUP);
    (void) sigaction(SIGHUP, &sa, (struct sigaction*) 0);
}
int main() { f(); return 0; }
EOF
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} -c t.c++${MAKECXXOVERRIDE}"
}
CheckSignalHandler()
{
    cat>t.c++<<EOF
#include <sys/types.h>
#include <signal.h>
void sigHUP(int) {}
void f() { (void) signal(SIGHUP, $1 (sigHUP)); }
int main() { f(); return 0; }
EOF
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} -c t.c++${MAKECXXOVERRIDE}"
}

CheckForMMAP()
{
    (cat<<'EOF'
/* part of this was lifted from GNU autoconf */
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
EOF
    CheckForFunc getpagesize || {
	cat<<'EOF'
#ifdef BSD
# ifndef BSD4_1
#  define HAVE_GETPAGESIZE
# endif
#endif

#ifndef HAVE_GETPAGESIZE
# include <sys/param.h>
# ifdef EXEC_PAGESIZE
#  define getpagesize() EXEC_PAGESIZE
# else
#  ifdef NBPG
#   define getpagesize() NBPG * CLSIZE
#   ifndef CLSIZE
#    define CLSIZE 1
#   endif
#  else
#   ifdef NBPC
#    define getpagesize() NBPC
#   else
#    define getpagesize() PAGESIZE /* SVR4 */
#   endif
#  endif
# endif
#endif
EOF
    }
cat<<'EOF'
extern char* malloc();
static void
boom(const char* msg)
{
    printf("%s.\n", msg);
    exit(1);
}

int
main()
{
    const char* filename = "conftestmmap";
    char* buf;
    char* addr;
    int i, fd, cc;

    cc = getpagesize();
    buf = malloc(cc);
    for (i = 0; i < cc; ++i)
	buf[i] = rand();
    fd = open(filename, O_WRONLY|O_CREAT, 0666);
    if (fd < 0)
	boom("Cannot open test file");
    if (write(fd, buf, cc) != cc)
	boom("Write to test file failed");
    close(fd);
    fd = open(filename, O_RDONLY);
    if (fd < 0)
	boom("Cannot reopen test file");
    addr = (char*) mmap(0, cc, PROT_READ, MAP_SHARED, fd, 0);
    if (addr == (char*) -1)
	boom("Cannot mmap test file");
    for (i = 0; i < cc; ++i)
	if (buf[i] != addr[i])
	    boom("Compare of mmap-file contents failed");
    exit(0);
}
EOF
    )>m.c
    capture cat m.c
    runMake m "m:; \${CC} m.c ${MACHDEPLIBS}" && capture ./a.out
}

CheckForStructExitStatus()
{
    decl=$1; shift
    (echo '#include <utmp.h>'
    for i do
	echo "$i"
    done
    cat<<EOF
main()
{
    struct $decl x;
    x.ut_exit.e_exit = 0;
    x.ut_exit.e_termination = 0;
    return 0;
}
EOF
    )>t.c++
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} t.c++${MAKECXXOVERRIDE}"
}

CheckForTimeZoneHandling()
{
    (echo '#include <time.h>'
    cat<<EOF
main()
{
    struct tm x;
    char* cp;
    long off;
    cp = x.tm_zone;
    off = x.tm_gmtoff;
    return 0;
}
EOF
    )>t.c++
    capture cat t.c++
    runMake t "t:; \${C++F} \${C++FILE} t.c++${MAKECXXOVERRIDE}"
}

CheckForTXCD()
{
    cat>t.c<<EOF
#include <sys/ioctl.h>
main()
{
    ioctl(0, TXADDCD, "rts");
    ioctl(0, TXDELCD, "rts");
}
EOF
    capture cat t.c
    runMake t 't:; ${CC} t.c'
}

#
# Check for a function declaration in <stdio.h>
# and if it is missing emit the appropriate decl
# along with an include of <stdio.h> (for any
# FILE definition).  Apparently some combinations
# of systems+compilers do not react well to
# function declarations w/o various definitions
# that appear only in stdio.h.
#
STDIO_H=no
CheckStdio()
{
    f=$1
    decl="$2"
    CheckForFuncDecl $f stdio.h || {
	if [ $STDIO_H = no ]; then
	    echo '#include <stdio.h>'
	    STDIO_H=yes
	fi
	AddFuncDecl $f "$decl"
    }
}

getConfigTag()
{
    param=`grep "$1:" $2 | sed -e 's/.*:[ 	]*\([^ 	]*\).*/\1/'`
}

#
# Check if TIFF library is compatible, checking:
#   $tiff_runlen_t: "uint16" or "uint32"
#   $tiff_offset_t: "uint32" or "uint64"
#   $tiff_bytecount_t: "uint32" or "uint64"
#   "Classic" structure names
#
CheckLibtiff()
{
    Note "... checking TIFF library version"
    tiff_runlen_t=""
    tiff_offset_t=""
    tiff_bytecount_t=""
    cat>t.c<<EOF
#include <stdio.h>
#include "tiffio.h"
main()
{
    printf( "header_ver=%d lib_ver=%s", TIFFLIB_VERSION, TIFFGetVersion() );
    exit(0);
}
EOF
    capture cat t.c
    if runMake t "t:; \${CC} \${CVERSION} ${OTIFFINC} t.c ${LIBTIFF} ${MACHDEPLIBS}"; then
        header_ver=0
        lib_ver=""
	eval `./a.out | \
	    sed -n -e 's/header_ver=\([0-9][0-9]*\) lib_ver=.*Version *\([0-9][0-9]*\.[0-9]\).*/\
                       header_ver=\1;lib_ver=\2/p'`
	Note "  Found tiffio.h version ${header_ver}"
	Note "  Found libtiff version ${lib_ver}"
	if [ ${header_ver} -ge 19960307 ]; then
	    case ${lib_ver} in
		3.4)		tiff_runlen_t="uint16"
				tiff_offset_t="uint32"
				tiff_bytecount_t="uint32"
				;;
		3.[56789])	tiff_runlen_t="uint32"
				tiff_offset_t="uint32"
				tiff_bytecount_t="uint32"
				;;
		4.[0])		tiff_runlen_t="uint32"
				tiff_offset_t="uint64"
				tiff_bytecount_t="uint64"
				echo '#define TIFFHeader	TIFFHeaderClassic'
				echo '#define TIFF_VERSION	TIFF_VERSION_CLASSIC'
				echo '#define NEED_TIFFDIRENTRY'
				;;
	    esac
	fi
    else
	cat 1>&2 <<EOF

Missing TIFF Library.

Compilation of the following test program failed:

----------------------------------------------------------
EOF
        cat t.c 1>&2
        cat 1>&2 <<EOF
----------------------------------------------------------

TIFFINC=${OTIFFINC}
LIBTIFF=${LIBTIFF}

Verify that you have the TIFFINC and LIBTIFF configuration parameters
set correctly for your system (see above) and that any environment
variables are setup that are needed to locate a libtiff DSO at runtime
(e.g. LD_LIBRARY_PATH). Also be sure that any relative pathnames are
made relative to the top of the build area.
EOF
	boom
	return 1
    fi
    if [ "${tiff_runlen_t}" != "" ]; then
	export tiff_runlen_t
	export tiff_offset_t
	export tiff_bytecount_t
	return 0
    else
	cat 1>&2 <<EOF

Incompatible TIFF Library.

HylaFAX ${VERSION} requires TIFF software distribution versions 3.4 through
3.9.  If you do not have up to date TIFF software on your system
then you can retrieve it from the location where you obtained this software.
The Home Page for version 3.5 and later is http://www.remotesensing.org/libtiff/
EOF
	boom
	return 1
    fi
}

#
# Check an existing port.h to see if it was created
# for the target and compiler we're using.
#
CheckPortDotH()
{
    getConfigTag TARGET port.h; target="$param"
    getConfigTag CCOMPILER port.h; ccompiler="$param"
    getConfigTag CXXCOMPILER port.h; cxxcompiler="$param"
    CCOMP=$CCOMPILER;
	test $ISGCC = yes && CCOMP="${CCOMP}-${GCCversion}"
    CXXCOMP=$CXXCOMPILER;
	test $ISGXX = yes && CXXCOMP="${CXXCOMP}-${GCCversion}"
    test "$target" = "$TARGET" && \
    test "$ccompiler" = "$CCOMP" && \
    test "$cxxcompiler" = "$CXXCOMP"
}

#
# Built port.h and, optionally, termios.h based on
# the system and compiler setup.
#
BuildPortDotH()
{
    Note ""
    Note "Creating port.h with necessary definitions."

    (EmitCPlusPlusPrologue _PORT_
    EmitConfigurationDefinitions

    echo '#include <sys/types.h>'
    TYPES_H="sys/types.h"
    if CheckForIncludeFile sys/bsdtypes.h; then
	Note "... configure use of <sys/bsdtypes.h>"
        echo '#include <sys/bsdtypes.h>'
	TYPES_H="$TYPES_H sys/bsdtypes.h"
    fi
    CheckVarDecl uid_t 'typedef int uid_t;' $TYPES_H
    CheckVarDecl gid_t 'typedef int gid_t;' $TYPES_H
    CheckVarDecl mode_t 'typedef int mode_t;' $TYPES_H stdlib.h
    CheckVarDecl off_t 'typedef long off_t;' $TYPES_H stdlib.h
    CheckVarDecl pid_t 'typedef int pid_t;' $TYPES_H stdlib.h
    CheckVarDecl size_t 'typedef unsigned size_t;' $TYPES_H stdlib.h
    CheckVarDecl dev_t 'typedef int dev_t;' $TYPES_H stdlib.h
    if CheckForIncludeFile stdint.h; then
	Note "... configure use of <stdint.h>"
        echo '#define HAVE_STDINT_H 1'
	TYPES_H="$TYPES_H stdint.h"
    fi
    CheckVarDecl intptr_t 'typedef long intptr_t;' $TYPES_H

    if [ $CONFIG_OSFCNH = auto ]; then
        if CheckForIncludeFile osfcn.h; then
	        CONFIG_OSFCNH=yes
        else
            CONFIG_OSFCNH=no
        fi
    fi
    if [ $CONFIG_OSFCNH = yes ]; then
	Note "... configure use of <osfcn.h>"
	echo '#define HAS_OSFCN_H 1'
	OSFCNH='osfcn.h'
    else
	OSFCNH=
    fi
    if CheckForIncludeFile sys/select.h; then
	Note "... configure use of <sys/select.h>"
	echo '#define HAS_SELECT_H 1'
	SELECTH='sys/select.h'
    else
	SELECTH=
    fi

    #
    # Some vendors have changed the socket API so that
    # call-by-reference parameters that give buffer
    # lengths are not int; this must be dealt with to
    # get the code to compile.  Note that we only emit
    # the define if the type is not an int; we do this
    # so Socket.h can include code that assumes the
    # default so folks don't have to rerun configure.
    #
    # The HP-UX case is a bit peculiar.  There socklen_t
    # is defined as size_t, but in order to use it...
    # "To use UNIX95/98 style sockets in HP-UX, the libxnet
    # library needs to be added to the link line. Also, the
    # macro, _XOPEN_SOURCE, needs to be defined, and the
    # macro, _XOPEN_SOURCE_EXTENDED, needs to be defined as 1.
    # Refer to HP-UX manpage, xopen_networking(7) for further
    # details."  Otherwise, we must define
    # CONFIG_HPUX_SOCKLEN_T_BRAINDAMAGE.
    #
    test "$CONFIG_SOCKARGLENTYPE" || {		# int vs unsigned long vs ...
        case $TARGET in
	    # XXX fill in for busted systems
        *-aix4*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *-hpux11*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *sysv4.2uw2*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *-univel-*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *-sysv5UnixWare*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *-sysv5OpenUNIX*)	CONFIG_SOCKARGLENTYPE=size_t;;
        *-sysv5SCO_SV*)	CONFIG_SOCKARGLENTYPE=size_t;;
	*-freebsd4*)	CONFIG_SOCKARGLENTYPE=u_int32_t;;
	*-freebsd5*)	CONFIG_SOCKARGLENTYPE=u_int32_t;;
        *)		CONFIG_SOCKARGLENTYPE=int;;
        esac
    }
    TYPES_H="$TYPES_H sys/socket.h"
    CheckVarDecl socklen_t "typedef $CONFIG_SOCKARGLENTYPE socklen_t;" $TYPES_H

    #
    # Select signal handler type casts.
    #
    if [ $ISGXX = yes ]; then
        #
        # Must use -pendantic-errors with gcc to insure (sig_t) (...)
        # is treated as an error instead of a warning when searching
        # for the proper signal handler types below.
        #
        OGCXXOPTS="$GCXXOPTS"
        GCXXOPTS="$GCXXOPTS -pedantic-errors"
        makeDefs xdefs
    fi
    SIGHANDLERTYPES="
        $SIGHANDLERTYPES
        (sig_t)
        (SIG_PF)
        (void(*)(int))
        (void(*)())
        (int)
    "
    SIGHANDLERTYPE=
    for i in $SIGHANDLERTYPES; do
        CheckSigactionHandler "$i" && {
            SIGHANDLERTYPE="#define fxSIGACTIONHANDLER $i"
            Note "... use $i for sigaction handler type"
            break;
	    }
    done
    # Only look for sigvec if we cannot find a sigaction() type
    if [ -z "$SIGHANDLERTYPE" ]; then
        for i in $SIGHANDLERTYPES; do
            CheckSigvecHandler "$i" && {
                SIGHANDLERTYPE="#define fxSIGVECHANDLER $i"
                Note "... use $i for sigvec handler type"
                break;
	        }
        done
    fi
    echo $SIGHANDLERTYPE
    SIGHANDLERTYPE=
    for i in $SIGHANDLERTYPES; do
        CheckSignalHandler "$i" && {
            SIGHANDLERTYPE="#define fxSIGHANDLER $i"
            Note "... use $i for signal handler type"
            break;
        }
    done
    echo $SIGHANDLERTYPE

    if [ $ISGXX = yes ]; then
	GCXXOPTS="$OGCXXOPTS"
	makeDefs xdefs
    fi

    CheckForMMAP && {
	echo '#define HAS_MMAP 1'
	Note "... configure use of mmap for memory-mapped files"
	CheckFuncDecl mmap \
	    'extern void* mmap(void*, size_t, int, int, int, off_t);' sys/mman.h
	CheckFuncDecl munmap 'extern int munmap (caddr_t, int);' sys/mman.h
    }

    CheckFuncDecl bzero 'extern void bzero(void *, int);' string.h
    CheckFuncDecl mkstemp 'extern int mkstemp(char *);' stdlib.h stdio.h unistd.h
    CheckFuncDecl mkdtemp 'extern char* mkdtemp(char *);' stdlib.h stdio.h unistd.h
    CheckFuncDecl strerror 'extern char* strerror(int);' string.h
    CheckFuncDecl strncasecmp \
	'extern int strncasecmp(const char*, const char*, size_t);' string.h
    CheckFuncDecl strcasecmp \
	'extern int strcasecmp(const char*, const char*);' string.h
    CheckFuncDecl strdup 'extern char* strdup(const char*);' string.h
    CheckFuncDecl memset 'extern void* memset(void*, int, size_t);' string.h
    CheckFuncDecl getpass 'extern char* getpass(const char *);' stdlib.h unistd.h
    CheckFuncDecl random 'extern long random(void);' math.h stdlib.h
    CheckFuncDecl srandom 'extern void srandom(int);' math.h stdlib.h
    CheckFuncDecl floor 'extern double floor(double);' math.h
    CheckFuncDecl waitpid 'extern pid_t waitpid(pid_t, int *, int);' sys/wait.h
    CheckForFunc sysconf && {
	echo '#define HAS_SYSCONF 1'
	Note "... configure use of sysconf"
	CheckFuncDecl sysconf 'extern long sysconf(int);' unistd.h
    }
    CheckForFunc ulimit && {
	echo '#define HAS_ULIMIT 1'
	Note "... configure use of ulimit"
	CheckFuncDecl ulimit 'extern long ulimit(int, ...);' ulimit.h
    }
    CheckForFunc getdtablesize && {
	echo '#define HAS_GETDTABLESIZE 1'
	Note "... configure use of getdtablesize"
	CheckFuncDecl getdtablesize 'extern int getdtablesize(void);' unistd.h
    }
    CheckDefine _POSIX_OPEN_MAX '_POSIX_OPEN_MAX 16' limits.h
    CheckDefine howmany 'howmany(x, y)	(((x)+((y)-1))/(y))' $TYPES_H
    CheckForFuncDecl sigvec signal.h || {
	echo 'struct sigvec;'
	AddFuncDecl sigvec \
	    'extern int sigvec(int, const struct sigvec*, struct sigvec*);'
    }
    CheckForFuncDecl sigaction signal.h || {
	echo 'struct sigaction;'
	AddFuncDecl sigaction \
	    'extern int sigaction(int, const struct sigaction*, struct sigaction*);'
    }
    CheckFuncDecl kill 'extern int kill(pid_t, int);' signal.h
    CheckFuncDecl close 'extern int close(int);' unistd.h
    CheckFuncDecl getuid 'extern uid_t getuid(void);' unistd.h
    CheckFuncDecl geteuid 'extern uid_t geteuid(void);' unistd.h
    CheckFuncDecl seteuid 'extern int seteuid(uid_t);' unistd.h
    CheckFuncDecl setegid 'extern int setegid(gid_t);' unistd.h
    CheckFuncDecl setenv 'int setenv(const char *, const char *, int);' stdlib.h
    CheckFuncDecl ftruncate 'extern int ftruncate(int, off_t);' unistd.h
    CheckFuncDecl getdtablesize 'extern int getdtablesize(void);' unistd.h
    CheckFuncDecl chroot 'extern int chroot(const char *path);' unistd.h
    #
    # unistd.h is where many people put it
    # sys/select.h is for USL-derived code
    # sys/time.h is for HP systems (sigh)
    # sys/types.h is for yet other systems (sigh sigh)
    #
    CheckForFuncDecl select unistd.h $SELECTH sys/time.h $TYPES_H || {
	echo 'struct fd_set;'
	echo 'struct timeval;'
	AddFuncDecl select \
	    'extern int select(int,struct fd_set*,struct fd_set*,struct fd_set*,struct timeval*);'
    }
    CheckFuncDecl unlink 'extern int unlink(const char*);' unistd.h
    CheckFuncDecl read 'extern int read(int, const void*, unsigned int);' unistd.h
    CheckFuncDecl ioctl 'extern int ioctl(int, int, ...);' unistd.h sys/ioctl.h
    CheckForFunc fchown && {
	echo '#define HAS_FCHOWN 1'
	Note "... configure use of fchown"
	CheckFuncDecl fchown 'extern int fchown(int, uid_t, gid_t);' unistd.h
    }
    CheckFuncDecl gethostname 'extern int gethostname(char*, int);' unistd.h $OSFCNH
    CheckFuncDecl malloc 'extern void* malloc(size_t);' stdlib.h
    CheckFuncDecl realloc 'extern void* realloc(void*, size_t);' stdlib.h
    CheckFuncDecl free 'extern void free(void*);' stdlib.h
    CheckFuncDecl strtoul \
	'extern unsigned long strtoul(const char*, char**, int);' stdlib.h
    #
    # unistd.h is for sco3.2v4.[0-2] and GNU libc (yech!)
    #
    CheckFuncDecl getopt \
	'extern int getopt(int, char* const*, const char*);' stdlib.h unistd.h
    CheckFuncDecl isatty 'extern int isatty(int);' stdlib.h unistd.h
    CheckVarDecl 'char.*optarg' 'extern char* optarg;' stdlib.h unistd.h
    CheckVarDecl 'int.*opterr' 'extern int opterr;' stdlib.h unistd.h
    CheckVarDecl 'int.*optind' 'extern int optind;' stdlib.h unistd.h
    CheckFuncDecl system 'extern int system(const char*);' stdlib.h
    CheckFuncDecl mktemp 'extern char* mktemp(char*);' stdlib.h stdio.h unistd.h
    CheckStdio popen 'extern FILE* popen(const char *, const char *);'
    CheckStdio pclose 'extern int pclose(FILE*);'
    CheckStdio fdopen 'extern FILE* fdopen(int, const char*);'
    CheckStdio snprintf 'extern int snprintf(char*, size_t, const char*,...);'
    CheckForFuncDecl vsnprintf stdio.h || {
	echo '#include <stdarg.h>'
	AddFuncDecl vsnprintf 'extern int vsnprintf(char*, size_t, const char*, va_list);'
    }
    CheckForDefine fileno stdio.h || {
	CheckStdio fileno 'extern int fileno(FILE*);'
    }
    CheckFuncDecl opendir 'extern DIR* opendir(const char*);' dirent.h
    CheckFuncDecl syslog 'extern void syslog(int, const char*, ...);' syslog.h
    CheckForFuncDecl vsyslog syslog.h || {
	echo '#include <stdarg.h>'
	AddFuncDecl vsyslog 'extern void vsyslog(int, const char*, va_list);'
    }
    CheckFuncDecl closelog 'extern void closelog(void);' syslog.h
    CheckFuncDecl openlog 'extern void openlog(const char*, int, int);' syslog.h
    CheckForFunc fchmod && {
	echo '#define HAS_FCHMOD 1'
	Note "... configure use of fchmod"
	CheckFuncDecl fchmod 'extern int fchmod(int, mode_t);' \
	    unistd.h $OSFCNH sys/stat.h libc.h
    }
    CheckFuncDecl mknod 'extern int mknod(const char*, mode_t, dev_t);' \
	unistd.h sys/stat.h
    CheckForFuncDecl gettimeofday sys/time.h || {
	echo 'struct timezone;'
	echo 'struct timeval;'
	AddFuncDecl gettimeofday \
	    'extern int gettimeofday(struct timeval*, struct timezone*);'
    }
    CheckForFuncDecl strftime time.h || {
	echo 'struct tm;'
	AddFuncDecl strftime \
	    'extern size_t strftime(char*,size_t,const char*,const struct tm*);'
    }
    CheckForFuncDecl localtime time.h || {
	echo 'struct tm;'
	AddFuncDecl localtime 'struct tm* localtime(const time_t* clock);'
    }
    CheckForTimeZoneHandling && {
	echo '#define HAS_TM_ZONE 1'
	Note "... configure use of struct tm timezone information"
    }
    CheckForFuncDecl setitimer sys/time.h || {
	echo '#ifdef ITIMER_REAL'
	echo 'struct itimerval;'
	AddFuncDecl setitimer \
	    'extern int setitimer(int,struct itimerval*,struct itimerval*);'
	echo '#endif'
    }
    CheckFuncDecl setpwent 'extern void setpwent(void);' pwd.h
    CheckFuncDecl endpwent 'extern void endpwent(void);' pwd.h
    CheckFuncDecl getpwnam 'extern struct passwd* getpwnam(const char*);' pwd.h
    case "$TARGET" in
    *-reno*)
	;;
    *)
	for i in toupper tolower; do
	    CheckFuncDecl $i "extern int $i(int);" ctype.h
	done
	;;
    esac
    CheckForIncludeFile net/errno.h && {
	Note "... configure use of <net/errno.h>"
        echo '#define HAS_NETERRNO_H 1'
    }
    CheckForFuncDecl getpeername sys/socket.h || {
	echo 'struct sockaddr;'
	AddFuncDecl getpeername 'extern int getpeername(int,struct sockaddr*,int*);'
    }
    CheckForFuncDecl getsockname sys/socket.h || {
	echo 'struct sockaddr;'
	AddFuncDecl getsockname 'extern int getsockname(int,struct sockaddr*,int*);'
    }
    CheckFuncDecl socket 'extern int socket(int, int, int);' sys/socket.h
    CheckFuncDecl connect 'extern int connect(int, const void*, int);' sys/socket.h
    CheckForFuncDecl bind sys/socket.h || {
	echo 'struct sockaddr;'
	AddFuncDecl bind 'extern int bind(int, const struct sockaddr*, int);'
    }
    CheckFuncDecl listen 'extern int listen(int, int);' sys/socket.h
    CheckFuncDecl getsockopt \
	'extern int getsockopt(int, int, int, const char*, int*);' sys/socket.h
    CheckFuncDecl setsockopt \
	'extern int setsockopt(int, int, int, const char*, int);' sys/socket.h
    CheckForFuncDecl accept sys/socket.h || {
	echo 'struct sockaddr;'
	AddFuncDecl accept 'extern int accept(int, struct sockaddr*, int*);'
    }
    CheckFuncDecl send \
	'extern int send(int, const void*, int, int);' sys/socket.h
    CheckFuncDecl setutent 'extern void setutent(void);' utmp.h
    CheckFuncDecl endutent 'extern void endutent(void);' utmp.h
    CheckForFuncDecl getutent utmp.h || {
	echo 'struct utmp;'
	AddFuncDecl getutent 'extern struct utmp* getutent(void);'
    }
    CheckForFuncDecl pututline utmp.h || {
	echo 'struct utmp;'
	AddFuncDecl pututline \
	    'extern struct utmp* pututline(const struct utmp*);'
    }
    CheckForFuncDecl gethostbyname netdb.h || {
	echo 'struct hostent;'
	AddFuncDecl gethostbyname \
	    'extern struct hostent* gethostbyname(const char*);'
    }
    CheckForFuncDecl gethostbyaddr netdb.h || {
	echo 'struct hostent;'
	AddFuncDecl gethostbyaddr \
	    'extern struct hostent* gethostbyaddr(const void*, int, int);'
    }
    CheckForFuncDecl getservbyname netdb.h || {
	echo 'struct servent;'
	AddFuncDecl getservbyname \
	    'extern struct servent* getservbyname(const char*, const char*);'
    }
    CheckForDefine LOCK_SH sys/file.h || {
	AddDefine LOCK_SH 'LOCK_SH	1	/* shared lock */'
	AddDefine LOCK_EX 'LOCK_EX	2	/* exclusive lock */'
	AddDefine LOCK_NB 'LOCK_NB	4	/* dont block when locking */'
	AddDefine LOCK_UN 'LOCK_UN	8	/* unlock */'
    }
    CheckFuncDecl flock 'extern int flock(int, int);' sys/file.h
    CheckForFuncDecl sigsetjmp setjmp.h || {
	echo '#include <setjmp.h>'
	echo '#ifndef sigsetjmp'
	AddDefine sigjmp_buf 'sigjmp_buf jmp_buf	/* hopefully compatible */'
	AddFuncDecl sigsetjmp 'extern int sigsetjmp(sigjmp_buf, int);'
	AddFuncDecl siglongjmp 'extern void siglongjmp(sigjmp_buf, int);'
	echo '#endif'
    }
    CheckForFuncDecl inet_ntoa arpa/inet.h || {
	echo 'struct in_addr;'
	AddFuncDecl inet_ntoa 'extern char* inet_ntoa(struct in_addr);'
    }
    CheckForIncludeFile sys/mkdev.h && {
	Note "... configure use of <sys/mkdev.h> (for SVR4-style lock files)"
	echo '#define HAS_MKDEV 1'
    }
    CheckForIncludeFile locale.h && {
	Note "... configure use of <locale.h> (internationalization support)"
	echo '#define HAS_LOCALE 1'
    }
    CheckForIncludeFile paths.h && {
	Note "... configure use of <paths.h>"
	echo '#include <paths.h>'
    }
    CheckForIncludeFile sys/modem.h && {
	Note "... configure use of <sys/modem.h>"
	echo '#define HAS_MODEM_H 1'
    }
    CheckForIncludeFile sys/termiox.h && {
	case $TARGET in
	*-*-sco3.2v5.*)	;;
	*)		Note "... configure use of SVR4 termiox support"
			echo '#define HAS_TERMIOX 1'
			;;
	esac
    }
    CheckForFunc flock || {
	#
	# Emit the necessary #defines for emulating flock
	#
	if CheckForFunc fcntl; then
	    echo '#define HAS_FCNTL 1'
	fi
	if CheckForFunc lockf; then
	    echo '#define HAS_LOCKF 1'
	fi
    }
    # NB: logwtmp checked above when looking for -lutil
    test $HAS_LOGWTMP = yes && {
	#
	# Configure use of logwtmp in the BSD getty support and
	# verify that the accompanying logout function is present
	# also.  Note that we put out proper declarations for the
	# functions since they don't appear to be declared anywhere.
	#
	echo '#define HAS_LOGWTMP 1'
	Note "... configure use of logwtmp (BSD-style wtmp logging)"
	CheckForFuncDecl logwtmp utmp.h || {
	    AddFuncDecl logwtmp \
		'int logwtmp(const char*, const char*, const char*);'
	}
	CheckForLibrary logout -lutil && {
	    echo '#define HAS_LOGOUT 1'
        Note "... configure use of logout (BSD-style utmp support)"
        CheckForFuncDecl logout utmp.h || {
            AddFuncDecl logout 'int logout(const char*);'
        }
	}
    }
    CheckDefine _PATH_DEV     '_PATH_DEV	"/dev/"'	paths.h
    CheckDefine _PATH_DEVNULL '_PATH_DEVNULL	"/dev/null"'	paths.h
    CheckDefine _PATH_TMP     '_PATH_TMP	"/tmp/"'	paths.h
    if [ $UTMP = auto ]; then
	if CheckForIncludeFile utmpx.h; then
	    case $TARGET in
	    *-hpux10.20*)	UTMP=utmp;;
	    *-hpux11*)		UTMP=utmp;;
	    *-aix4*)		UTMP=utmp;;
	    *-aix5*)		UTMP=utmp;;
	    *-dec-osf4.0*)	UTMP=utmp;;
	    *-osf-5.1a*)	UTMP=utmp;;
	    *-linux*)		UTMP=utmp;;
	    *)			UTMP=utmpx;;
	    esac
	else
	    UTMP=utmp;
	fi
    fi
    if [ $UTMP = utmpx ]; then
	Note "... configure use of <utmpx.h> (extended utmp interface)"
	echo '#define HAS_UTMPX 1'
	CheckForDefine _PATH_WTMPX paths.h utmp.h utmpx.h || {
	    if CheckForDefine WTMPX_FILE utmpx.h; then
		AddDefine _PATH_WTMPX '_PATH_WTMPX	WTMPX_FILE'
	    else
		PATHWTMPX=`findFile wtmpx /etc:/var/adm:/usr/adm`
		test "$PATHWTMPX" && {
		    AddDefine _PATH_WTMPX "_PATH_WTMPX	\"${PATHWTMPX}\""
		}
	    fi
	}
	#
	# struct exit_status is defined for all systems with
	# utmpx support, but SVR4.0.3 headers define the extended
	# exit status structure *within* struct utmp and then reuse
	# it within struct utmpx.  This does not work for all
	# compilers so we must look for this case and, if present,
	# enable a workaround declaration of struct exit_status (sigh).
	#
	if CheckForStructExitStatus utmpx '#include <utmpx.h>'; then
	    echo '#define HAS_UTEXIT 1'
	    echo '#define HAS_EXIT_STATUS 1'
	elif CheckForStructExitStatus utmpx \
	    'struct exit_status { short e_termination; short e_exit; };' \
	    '#include <utmpx.h>'; then
	    Note "... add declaration for struct exit_status"
	    echo '#define HAS_UTEXIT 1'
	    echo '#define HAS_EXIT_STATUS 0'
	fi
    else
	Note "... configure use of <utmp.h> (normal utmp interface)"
	CheckForDefine _PATH_UTMP paths.h utmp.h || {
	    if CheckForDefine UTMP_FILE utmp.h; then
		AddDefine _PATH_UTMP '_PATH_UTMP	UTMP_FILE'
	    else
		PATHUTMP=`findFile utmp /etc:/var/adm:/usr/adm`
		test "$PATHUTMP" && {
		    AddDefine _PATH_UTMP "_PATH_UTMP	\"${PATHUTMP}\""
		}
	    fi
	}
	CheckForStructExitStatus utmp && {
	    Note "... configure use of extended exit status in utmp"
	    echo '#define HAS_UTEXIT 1'
	}
	CheckForDefine _PATH_WTMP paths.h utmp.h || {
	    if CheckForDefine WTMP_FILE utmp.h; then
		AddDefine _PATH_WTMP '_PATH_WTMP	WTMP_FILE'
	    else
		PATHWTMP=`findFile wtmp /etc:/var/adm:/usr/adm`
		test "$PATHWTMP" && {
		    AddDefine _PATH_WTMP "_PATH_WTMP	\"${PATHWTMP}\""
		}
	    fi
	}
    fi
    CheckForDefine RT_NOCHANGE sys/priocntl.h sys/rtpriocntl.h && \
    CheckForDefine TS_NOCHANGE sys/priocntl.h sys/tspriocntl.h && {
	case $TARGET in
	*-*-sco3.2v5.*)	;;
	*)	Note "... configure use of SVR4 realtime process control interface"
		echo '#define HAS_PRIOCNTL 1'
			;;
	esac
    }
    CheckForDefine FP_NOCHANGE sys/priocntl.h sys/fppriocntl.h && {
	Note "... called FP instead of RT"
	echo '#define HAS_FPPRIOCNTL 1'
    }
    CheckForDefine NDPRI sys/schedctl.h && {
	Note "... configure use of IRIX realtime process control interface"
	echo '#define HAS_SCHEDCTL 1'
    }
    CheckForDefine RTPRIO_RTOFF sys/rtprio.h && {
	Note "... configure use of HP-UX realtime process control interface"
	echo '#define HAS_RTPRIO 1'
    }
    CheckForPositiveDefine _POSIX_PRIORITY_SCHEDULING unistd.h sched.h && {
	Note "... configure use of POSIX realtime process control interface"
	echo '#define HAS_POSIXSCHED 1'
	case $TARGET in
		*-*-sco3.2v5.*)	echo '#define RT_PRIORITY 96';;
		*-linux*)	echo '#define RT_PRIORITY 1';;
		*)		echo '#define RT_PRIORITY 1';;
	esac
    }
    CheckForTXCD && {
	Note "... configure use of TXADDCD and TXDELCD ioctls"
	echo '#define HAS_TXCD 1'
    }
    if CheckForIncludeFile crypt.h; then
	Note "... configure use of <crypt.h>"
	echo '#define HAS_CRYPT_H 1'
	CheckFuncDecl crypt 'extern const char* crypt(const char*, const char*);' unistd.h crypt.h
    else
	CheckFuncDecl crypt 'extern const char* crypt(const char*, const char*);' unistd.h stdlib.h
    fi
    CheckTermioFuncDecls termios.h
    if CheckLibtiff; then
	Note "... add declaration for tiff compatibility"
	echo "#define tiff_runlen_t ${tiff_runlen_t}"
	echo "#define tiff_offset_t ${tiff_offset_t}"
	echo "#define tiff_bytecount_t ${tiff_bytecount_t}"
    fi
    if [ "x$LIBPAM" != "x" ]; then
	CheckPAMType
    fi

    CheckForDefine s6_addr32 net/if.h  ||  {
	case $TARGET in
		*-*-sysv5*)	AddDefine s6_addr32 's6_addr32	S6_un.S6_l' ;;
		sparc-sun-*)	AddDefine s6_addr32 's6_addr32	S6_un.S6_l' ;;
	esac
    }

    if [ "x$HAS_DEPRECATED_CXX" != "x" ]; then
	Note "... use deprecated CXX headers"
        echo '#define HAS_DEPRECATED_CXX 1'
    fi

    # Emit the version variable that port will always give us.
    echo "extern const char* HYLAFAX_VERSION_STRING;"

    EmitCPlusPlusEpilogue
    )>xport.h
    mv xport.h port.h; chmod 444 port.h
    Note "Done creating port.h."
}

if test -f port.h && CheckPortDotH; then
    Note ""
    Note "Using previously created port.h."
else
    $RM xport.h xtermios.h t.c t.c++ a.out port.h termios.h
    BuildTermiosDotH
    BuildPortDotH
fi

Note ""
Note "Checking system libraries for functionality to emulate."

FUNCS="
    flock
    ftruncate
    getopt
    mkstemp
    mkdtemp
    random
    srandom
    setegid
    seteuid
    setvbuf
    setenv
    snprintf
    strcasecmp
    strtod
    strtoul
    writev
"

for i in $FUNCS; do
    CheckForFunc $i || {
	Note "... emulate $i"
	PORTFUNCS="$PORTFUNCS $i.c"
    }
done

#
# Now for those functions that need args.
#
CheckForFunc vsnprintf "(void*)0, 0, (void*)0, (void*)0" || {
    Note "... emulate vsnprintf"
    PORTFUNCS="$PORTFUNCS vsnprintf.c"
}

#
# SCO OS 5 #defines syslog as another function
# so it is necessary to include syslog.h when
# checking if the function is present in the
# library (sigh).
#
CheckForSyslog()
{
    (echo '#include <syslog.h>';
     echo '#include "port.h"';
     echo 'main(){syslog(0,"foo");exit(0);}') >t.c
    capture cat t.c
    runMake t "t:; \${CC} t.c ${MACHDEPLIBS}"
}
CheckForVSyslog()
{
    (echo '#include <syslog.h>';
     echo '#include <stdarg.h>';
     echo '#include "port.h"';
     echo 'main(){va_list ap; vsyslog(0,"foo", ap);exit(0);}') >t.c
    capture cat t.c
    runMake t "t:; \${CC} t.c ${MACHDEPLIBS}"
}
if CheckForSyslog; then
    CheckForVSyslog || {
	Note "... emulate vsyslog"
	PORTFUNCS="$PORTFUNCS vsyslog.c"
    }
else
    Note "... emulate syslog&co."
    PORTFUNCS="$PORTFUNCS syslog.c"
fi
LIBPORT='${PORT}/libport.a'

Note "Done checking system libraries."

Note ""
Note "Checking ZLIB support."
#
# Verify library is compatible.
#
cat>t.c<<EOF
#include "zlib.h"
main()
{
    if (strcmp(ZLIB_VERSION, "0.95") < 0) {     /* include file version */
        printf("old include files: version %u\n", ZLIB_VERSION);
        exit(-1);
    }
    if (strncmp(zlib_version, ZLIB_VERSION, 4) != 0) {
        printf("library/header file incompatibility: %s %s\n",
        zlib_version, ZLIB_VERSION);
        exit(-1);
    } else {
        exit(0);
    }
}
EOF
capture cat t.c
if runMake t "t:; \${CC} \${CVERSION} ${OZLIBINC} t.c ${LIBZ} ${MACHDEPLIBS}" && capture ./a.out; then
                ZLIBINC="${OZLIBINC}"
    Note "Using ZLIB include files from $OZLIBINC"
    Note "Using pre-built ZLIB library $LIBZ"
else
    LIBZ=
    DIRS="/usr/local /opt/zlib"
    for i in $DIRS; do
        if runMake t "t:; \${CC} \${CVERSION} -I${i}/include t.c -L${i}/lib -lz ${MACHDEPLIBS}" && capture ./a.out; then
            OZLIBINC="-I${i}/include"
            ZLIBINC="-I${i}/include"
            LIBZ="-L${i}/lib -lz"
            Note "Using ZLIB include files from ${i}/include"
            Note "Using pre-built ZLIB library $LIBZ"
            break
        fi
    done
    if [ -z "$LIBZ" ]; then
        cat 1>&2 <<EOF

Incompatible/missing ZLIB Library.

Compilation or execution of the following test program failed:

----------------------------------------------------------
EOF
	cat t.c 1>&2
	cat 1>&2 <<EOF
----------------------------------------------------------

With the following directories tried:
DIRS=<default compiler search path> ${DIRS}

The above program checks the version of the ZLIB library to ensure it
is suitable for use with HylaFAX.  HylaFAX ${VERSION} requires a recent
ZLIB software distribution; version 0.95 or newer.  If you have the right
software, verify that you have the ZLIBINC(location of zlib.h) and
LIBZ(location of libz.a/libz.so) configuration parameters set correctly
for your system and that any environment variables are setup that are
needed to locate a libz DSO at runtime (e.g.  LD_LIBRARY_PATH).
Also be sure that any relative pathnames are made relative to the top of
the build area.

EOF
        boom
    fi
fi
Note "Done checking ZLIB support."

Note ""
Note "Checking TIFF support."
#
# Location of TIFF binaries
#
if [ -z "$TIFFBIN" ]; then
    DIRS="/usr/local/bin /usr/contrib/bin /usr/gnu/bin /usr/bin"
    for i in $DIRS; do
        test -x $i/tiff2ps && { TIFFBIN=$i; break; }
    done
fi
if [ -z "$TIFFBIN" ]; then
    cat 1>&2 <<EOF
    Cannot locate the TIFF binary files(ie tiff2ps) anywhere.

    Please install the TIFF binaries and set the TIFFBIN parameter 
    to the correct path.
EOF
    boom
else
    Note "Using TIFF binary files from $TIFFBIN"
fi

HAVE_JBIGTIFF="/*#define HAVE_JBIGTIFF 1*/"
if [ "$DISABLE_JBIG" != "yes" ]; then
    Note "Checking JBIG-in-TIFF conversion support."
    $TIFFBIN/tiffcp -c g4 misc/jbig.tif misc/foo.tif > /dev/null 2>&1
    if [ $? = 0 ]; then
	$TIFFBIN/tiffcp misc/jbig.tif misc/foo.tif > /dev/null
	if [ -n "`$TIFFBIN/tiffinfo misc/foo.tif | grep 'Fax DCS'`" ]; then
	    HAVE_JBIGTIFF="#define HAVE_JBIGTIFF 1"
	    Note "JBIG-in-TIFF conversion support found."
	else
	    Note "JBIG-in-TIFF fax support not found."
	fi
    else
	Note "JBIG-in-TIFF conversion support not found."
    fi
    rm -f misc/foo.tif
fi

Note "Done checking TIFF support."

if [ "$DSO" = auto ]; then
    Note ""
    Note "Checking for Dynamic Shared Object (DSO) support."
    case $TARGET in
    *-irix*)
	if (findApp rld /lib:/usr/lib:$PATH) >/dev/null 2>&1; then
	    DSOSUF=so
	    DSOOPTS="${CVERSION} -shared -rdata_shared -check_registry \${DEPTH}/${SRCDIR}/port/irix/so_locations -quickstart_info"
	    DSODELAY=-delay_load
	    LLDOPTS='-rpath ${LIBEXEC}'
	    DSO=IRIX
	    CheckCCDSO()
	    {
		$RM t.c t.o t.${DSOSUF}
		echo 'int f() { return 0; }'>t.c
		capture cat t.c
		runMake t \
		    't.o:; ${CCF} -c t.c' \
		    "t: t.o; \${CCF} ${DSOOPTS} -o t.${DSOSUF} t.o"
	    }
	    CheckCXXDSO()
	    {
		$RM t.c++ t.o t.${DSOSUF}
		echo 'int f() { return 0; }'>t.c++
		capture cat t.c++
		runMake t \
		    "t.o:; \${C++F} -c \${C++FILE} t.c++${MAKECXXOVERRIDE}" \
		    "t:t.o; \${C++F} ${DSOOPTS} -o t.${DSOSUF} t.o"
	    }
	else
	    Note "No runtime loader found, looks like your system does not supports DSOs."
	    DSO=no
	fi
	;;
    *-linux*|*-k*bsd*-gnu*)
	if [ "X${DIR_LIB}" != "X/usr/lib" ]; then
	    USE_RPATH=' -Wl,-rpath,${LIBDIR}'
	else
	    USE_RPATH=''
	fi
	DSOSUF=so
	DSOOPTS='-shared -fpic -Wl,-soname,$@'
	LLDOPTS=$USE_RPATH
	GCOPTS="${GCOPTS} -fpic"
	GCXXOPTS="${GCXXOPTS} -fpic"
	DSO=LINUX
	CheckCCDSO()
	{
	$RM t.c t.o t.${DSOSUF}
	echo 'int f() { return 0; }'>t.c
	capture cat t.c
	runMake t \
	    't.o:; ${CCF} -c t.c' \
	    "t: t.o; \${CCF} ${DSOOPTS} -o t.${DSOSUF} t.o"
	}
	CheckCXXDSO()
	{
	$RM t.c++ t.o t.${DSOSUF}
	echo 'int f() { return 0; }'>t.c++
	capture cat t.c++
	runMake t \
	    "t.o:; \${C++F} -c \${C++FILE} t.c++${MAKECXXOVERRIDE}" \
	    "t:t.o; \${C++F} ${DSOOPTS} -o t.${DSOSUF} t.o"
	}
	;;
    *-solaris*)
	if [ "X${DIR_LIB}" != "X/usr/lib" ]; then
	    USE_RPATH=' -R${LIBDIR}'
	else
	    USE_RPATH=''
	fi
	DSOSUF=so
	# options here are passed directly to ld, not through g++ first
	if [ ${ISGCC} = "yes" ] ; then
	    DSOOPTS='-shared -Wl,-G,-h,$@'
	    LLDOPTS="$USE_RPATH -lstdc++"
	    GCOPTS="${GCOPTS} -fpic"
	    GCXXOPTS="${GCXXOPTS} -fpic"
	else
	    DSOOPTS='-G -h $@'
	    LLDOPTS='-L${UTIL} -R${LIBDIR} -lhylafax-${ABI_VERSION} -lCrun'
	    GCOPTS="${GCOPTS} -Kpic"
	    GCXXOPTS="${GCXXOPTS} -Kpic"
	fi
	DSO=SOLARIS
	CheckCCDSO()
	{
	$RM t.c t.o t.${DSOSUF}
	echo 'int f() { return 0; }'>t.c
	capture cat t.c
	runMake t \
	    't.o:; ${CCF} -c t.c' \
	    "t: t.o; \${CCF} ${DSOOPTS} -o t.${DSOSUF} t.o"
	}
	CheckCXXDSO()
	{
	$RM t.c++ t.o t.${DSOSUF}
	echo 'int f() { return 0; }'>t.c++
	capture cat t.c++
	runMake t \
	    "t.o:; \${C++F} -c \${C++FILE} t.c++${MAKECXXOVERRIDE}" \
	    "t:t.o; \${C++F} ${DSOOPTS} -o t.${DSOSUF} t.o"
	}
	;;
    *)	Note "There is no support for building HylaFAX as DSOs on your system."
	DSO=no
	;;
    esac
    if [ "$DSO" != no ]; then
	JUNK="$JUNK t.${DSOSUF}"
	#We need the new shared/DSO OPTS/FLAGS
	makeDefs xdefs
	if CheckCCDSO; then
	    if CheckCXXDSO; then
		Note "Looks like your system supports $DSO-style DSOs."
	    else
		cat 1>&4 <<EOF
Looks like your system supports DSOs...
... but $CXXCOMPILER does not support them in the expected way.
EOF
		DSO=no
	    fi
	else
	    cat 1>&4 <<EOF
Looks like your system supports DSOs...
... sigh, but $CCOMPILER does not support them in the expected way.
EOF
	    DSO=no
	fi
    fi
elif [ "$DSO" != no ]; then
    Note ""
    Note "Looks like your system supports $DSO-style DSOs."
fi

if [ "$DSO" = no ]; then
    MAKEDSOINCLUDE='#'
    DSOSUF=a DSOOPTS= DSODELAY= LLDOPTS=
else
    MAKEDSOINCLUDE="$MAKEINCLUDE"
fi

Note ""
Note "Selecting programs used during installation and operation."

if [ -z "$AWK" ]; then
    # we need an awk that supports functions and -v
    CheckAwk()
    {
	(set -x; $1 -v BAR=bar '
function foo(x) {
    print "GOT" x
}
BEGIN { foo(BAR) }
' </dev/null | grep GOTbar) >&5 2>&1
	return
    }
    for i in mawk nawk gawk awk; do
	x=`findApp $i $PATH`
	if test "$x" && CheckAwk "$x"; then
	    AWK=$x
	    break
	fi
    done
fi
if [ -z "$AWK" ]; then
    AWK=awk
    Note ""
    Note "WARNING, could not locate a suitable AWK for processing the command"
    Note "         scripts included in this software distribution; using $AWK."
else
    Note "Looks like $AWK should be used in command scripts."
fi

test "$SED" || SED=`findApp sed $PATH`
if [ -z "$SED" ]; then
    SED=sed
    Note "WARNING, could not locate a suitable SED command; using $SED."
fi

test "$PATH_SENDMAIL" || \
    PATH_SENDMAIL=`findApp sendmail $PATH:/usr/lib:/usr/ucblib`
if [ -z "$PATH_SENDMAIL" ]; then
    cat<<EOF
WARNING, could not locate sendmail on your system.

Beware that the mail notification work done by this software uses
sendmail-specific command line options.  If you do not have a
sendmail-compatible mailer things will break.
EOF
    PATH_SENDMAIL=/usr/lib/sendmail
    Note "Using $PATH_SENDMAIL to deliver mail."
else
    Note "Looks like $PATH_SENDMAIL should be used to deliver mail."
fi

#
# Miscellaneous ``little'' programs.  We want absolute
# pathnames so that work done by the super-user (e.g.
# installation) is safer.
#
test "$CAT"	|| CAT=`findAppDef cat $PATH cat`
test "$CHGRP"	|| CHGRP=`findAppDef chgrp $PATH chgrp`
test "$CHMOD"	|| CHMOD=`findAppDef chmod $PATH chmod`
test "$CHOWN"	|| CHOWN=`findAppDef chown $PATH chown`
test "$CMP"	|| CMP=`findAppDef cmp $PATH cmp`
test "$COL"	|| COL=`findAppDef col $PATH col`
test "$CP"	|| CP=`findAppDef cp $PATH cp`
test "$ECHO"	|| ECHO=`findAppDef echo $PATH echo`
test "$FUSER"	|| FUSER=`findAppDef fuser /sbin:$PATH fuser`
test "$GENDIST"	|| GENDIST=`findAppDef gendist $PATH gendist`
test "$GREP"	|| GREP=`findAppDef grep $PATH grep`
test "$LN"	|| LN=`findAppDef ln $PATH ln`
test "$MAN"	|| MAN=`findAppDef man $PATH man`
test "$MKDIR"	|| MKDIR=`findAppDef mkdir $PATH mkdir`
test "$MV"	|| MV=`findAppDef mv $PATH mv`
test "$PCL6CMD"	|| PCL6CMD=`findAppDef pcl6 $PATH pcl6`
test "$PWDCMD"	|| PWDCMD=`findAppDef pwd $PATH pwd`
test "$RMCMD"	|| RMCMD=`findAppDef rm $PATH rm`
test "$SORT"	|| SORT=`findAppDef sort $PATH sort`
test "$STRIP"	|| STRIP=`findAppDef strip $PATH strip`
test "$TIFF2PDF" || TIFF2PDF=`findAppDef tiff2pdf $PATH bin/tiff2pdf`
test "$TTYCMD"	|| TTYCMD=`findAppDef tty $PATH tty`

#
# Test/verify we know how to create FIFO special files.
#
$RM conffifo;
if capture mkfifo conffifo && test -p conffifo >/dev/null 2>&1; then
    Note "Looks like $MKFIFO creates FIFO special files."
elif test -f conffifo; then			# NB: not everyone has test -p
    Note "Looks like $MKFIFO creates FIFO special files (unable to verify)."
else
    # NB: we can't be certain of this because on some systems
    # only root can create a FIFO special file
    Note "WARNING, $MKFIFO may create FIFO special files, but testing failed."
fi

#
# Check if mv -f is supported
#
if [ -z "$MV_F" ]; then
    $RM t.c; echo "">t.c
    if capture $MV -f t.c t.o; then
	Note "Looks like $MV supports the -f option to force a move."
	MV_F=-f
    else
	Note "WARNING, looks like $MV has no -f option to force move operations;"
	Note "         this may cause problems during installation."
	MV_F=
    fi
fi

#
# Check if ln -s creates a symbolic link.
#
if [ -z "$LN_S" ]; then
    capture "$RM t.c; $LN -s foo t.c" && LN_S=-s
fi
if [ -n "$LN_S" ]; then
    Note "Looks like $LN supports the -s option to create a symbolic link."
else
    Note "WARNING, looks like $LN has no -s option to create symbolic links;"
    Note "         this may cause problems during installation."
fi

#
# Check for email encoders.
#
test -n "$UUENCODE" && Note "Using uuencode encoder: $UUENCODE"
test -n "$BASE64ENCODE" && Note "Using base64 encoder: $BASE64ENCODE"
test -n "$QPENCODE" && Note "Using Quoted-Printable encoder: $QPENCODE"
test -n "$MIMENCODE" && Note "Using mimencode for compatibility: $QPENCODE"

#
# Pick install mechanism.
#
if [ -z "$INSTALL" ]; then
    case $TARGET in
    *-irix*)	INSTALL=`findApp install /sbin:$PATH`;;
    *)		INSTALL='${SHELL} ${PORT}/install.sh';;
    esac
fi

# Location SysV style init scripts
if [ -z "$DIR_SYSVINIT" ]; then
    DIR_SYSVINITS="
	/etc/rc.d/init.d
	/etc/init.d
    "
    case $TARGET in
	*-sunos*)	DIR_SYSVINITS="$DIR_SYSVINITS $DIR_SBIN";;
	*-hpux*)	DIR_SYSVINITS="/sbin/init.d $DIR_SYSVINITS";;
	*-dec-osf*)	DIR_SYSVINITS="/sbin/init.d $DIR_SYSVINITS";;
	*)		;;
    esac
    DIR_SYSVINIT=
    for i in $DIR_SYSVINITS; do
	test -d $i && { DIR_SYSVINIT=$i; break; }
    done
fi

if [ "$SYSVINIT" = auto ]; then
    if test -d "$DIR_SYSVINIT"; then
	SYSVINIT=yes
	Note "Looks like a SysV-style init is used, enabling installation of startup code."
    else
	SYSVINIT=no
    fi
fi

if [ "$SYSVINIT" = yes ]; then
	Note "Looks like SysV init scripts go in $DIR_SYSVINIT."
fi

if [ "$SYSVINIT" = yes ]; then
    if [ -z "$DIR_SYSVINITSTART" ]; then
	case $TARGET in
	    *-linux*)	DIR_SYSVINITSTART="../rc2.d ../rc3.d ../rc4.d ../rc5.d";;
	    *)		DIR_SYSVINITSTART="../rc2.d";;
	esac
    fi
    if [ -z "$DIR_SYSVINITSTOP" ]; then
	case $TARGET in
	    *-linux*)	DIR_SYSVINITSTOP="../rc0.d ../rc1.d ../rc6.d";;
	    *-solaris*)	DIR_SYSVINITSTOP="../rc0.d ../rc1.d ../rcS.d";;
	    *sysv4.2uw2*)	DIR_SYSVINITSTOP="../rc0.d ../rc1.d";;
	    *-sysv5UnixWare*)	DIR_SYSVINITSTOP="../rc0.d ../rc1.d";;
	    *-sysv5OpenUNIX*)	DIR_SYSVINITSTOP="../rc0.d ../rc1.d";;
	    *)		DIR_SYSVINITSTOP="../rc0.d";;
	esac
    fi
    if [ -z "$NAME_SYSVINITSTART" ]; then
	case $TARGET in
	    *-hpux*)		NAME_SYSVINITSTART="S905hylafax" ;;
	    *-linux*)		NAME_SYSVINITSTART="S97hylafax" ;;
	    *-*-sco3.2v5*)	NAME_SYSVINITSTART="S90hylafax" ;;
	    *-sysv5SCO_SV*)	NAME_SYSVINITSTART="S90hylafax" ;;
	    *)			NAME_SYSVINITSTART="S80hylafax" ;;
	esac
    fi
    if [ -z "$NAME_SYSVINITSTOP" ]; then
	case $TARGET in
	    *-hpux*)		NAME_SYSVINITSTOP="K095hylafax" ;;
	    *-solaris*)		NAME_SYSVINITSTOP="K20hylafax" ;;
	    *)			NAME_SYSVINITSTOP="K05hylafax" ;;
	esac
    fi
fi

# now to keep from breaking etc/Makefile
if [ -z "$DIR_SYSVINITSTART" ]; then
    DIR_SYSVINITSTART="dir_sysvinitstart_set_to_non_null_string"
fi
if [ -z "$DIR_SYSVINITSTOP" ]; then
    DIR_SYSVINITSTOP="dir_sysvinitstop_set_to_non_null_string"
fi

Note "Done selecting programs."

#
# User-changable configuration parameters section.
# Anything selected here is presented to the user
# and may be interactively changed.
#

Note ""
Note "Selecting default HylaFAX configuration parameters."
Note ""

#
# Fill in any other configuration parameters not
# setup in the site and local files.
#

#
# Fax user GID
#
if [ -z "$FAXGID" ]; then
    case $TARGET in
    *-aix*)	FAXGID=uucp;;
    *-bsdi*)	FAXGID=uucp;;
    *freebsd2.1*) FAXGID=uucp; break;; # Not sure when this changed..
    *bsd*)	FAXGID=dialer;;
    *-hpux*)	FAXGID=sys;;
    *-irix*)	FAXGID=nuucp;;
    *-isc*)	FAXGID=uucp;;
    *-linux*)	FAXGID=uucp;;
    *-*-sco*)	FAXGID=uucp;;
    *-solaris*)	FAXGID=uucp;;
    *-sunos*)	FAXGID=uucp;;
    *-sysv4*)	FAXGID=uucp;;
    *-sysv5*)	FAXGID=uucp;;
    *-ultrix*)	FAXGID=uucp;;
    *)	
	FAXGID=uucp
	for i in uucp dialer nuucp sys; do
	    grep "^${i}:" /etc/group >/dev/null 2>&1 && { FAXGID=$i; break; }
	done
	;;
    esac
fi
Note "Using uid $FAXUID and gid $FAXGID for controlling access to fax stuff."

#
# System installation group ID.
#
if [ -z "$SYSGID" ]; then
    case $TARGET in
    *-aix*)	SYSGID=sys;;
    *netbsd*)	SYSGID=wheel;;
    *bsd*)	SYSGID=bin;;
    *-hpux*)	SYSGID=bin;;
    *-irix*)	SYSGID=sys;;
    *-isc*)	SYSGID=sys;;
    *-linux*)	SYSGID=bin;;
    *-*-sco*)	SYSGID=sys;;
    *-solaris*)	SYSGID=sys;;
    *-sunos*)	SYSGID=bin;;
    *-sysv4*)	SYSGID=sys;;
    *-sysv5*)	SYSGID=sys;;
    *-ultrix*)	SYSGID=bin;;
    *)	
	SYSGID=sys
	for i in sys bin; do
	    grep "^${i}:" /etc/group >/dev/null 2>&1 && { SYSGID=$i; break; }
	done
	;;
    esac
fi
Note "Using uid $SYSUID and gid $SYSGID for installing programs."

if [ -z "$FILLORDER" ]; then
    #
    # Host bit order within a word.
    #
    case $TARGET in
    mips-dec-*)	FILLORDER=LSB2MSB;;
    i[3-6]86-*)	FILLORDER=LSB2MSB;;
    *)		FILLORDER=MSB2LSB;;
    esac
fi
CPU=`echo $TARGET | sed 's/-.*//'`
Note "Using $FILLORDER bit order for your $CPU cpu."

# SVR4 packaging stuff
if [ -z "$PKG_ARCH" ]; then
	PKG_ARCH=$CPU
fi

#
# Style of getty support.
#
if [ "$GETTY" = auto ]; then
    case $TARGET in
    *bsd*)	GETTY=BSD;;
    *-sunos*)	GETTY=BSD;;
    *-ultrix*)	GETTY=BSD;;
    *darwin*)   GETTY=BSD;;
    *)		GETTY=SysV;;
    esac
fi
Note "Looks like you need $GETTY getty support."
if [ -z "$PATH_GETTY" ]; then
    if CheckForDefine _PATH_GETTY paths.h; then
	Note "Using _PATH_GETTY from <paths.h> as the program to exec for a data call."
    else
	#
	# NB: use findFile instead of findApp because on some
	#     systems this file is mode 544; so if configure
	#     is run by an unprivileged user the file will not
	#     be located.
	#
	PATH_GETTY=`findFile ttymon /usr/lib/saf:/usr/libexec:/sbin:$PATH`
	test -z "$PATH_GETTY" && \
	    PATH_GETTY=`findApp agetty /usr/libexec:/sbin:$PATH`
	test -z "$PATH_GETTY" && \
	    PATH_GETTY=`findApp mgetty /usr/libexec:/sbin:$PATH`
	test -z "$PATH_GETTY" && \
	    PATH_GETTY=`findApp getty /usr/libexec:/sbin:$PATH`
	if [ -z "$PATH_GETTY" ]; then
	    PATH_GETTY=/etc/getty
	    Note ""
	    Note "WARNING, could not locate a suitable getty program to exec for a"
	    Note "         data call; using a default value $PATH_GETTY."
	    Note ""
	else
	    Note "Looks like $PATH_GETTY is the program to exec for a data call."
	fi
    fi
else
    Note "Using $PATH_GETTY as the program to exec for a data call."
fi

# vgetty support
if [ -z "$PATH_VGETTY" ]; then
    PATH_VGETTY=`findApp vgetty /usr/libexec:/sbin:$PATH` 
    if [ -z "$PATH_VGETTY" ]; then
	PATH_VGETTY=/bin/vgetty
	Note "WARNING, no vgetty program found to handle a voice call, using $PATH_VGETTY."
    else
	Note "Looks like $PATH_VGETTY is the program to exec for a voice call."
    fi
else
    Note "Using $PATH_VGETTY as the program to exec for a voice call."
fi

# egetty support
if [ -z "$PATH_EGETTY" ]; then
    PATH_EGETTY=`findApp egetty /usr/libexec:/sbin:$PATH` 
    if [ -z "$PATH_EGETTY" ]; then
	PATH_EGETTY=/bin/egetty
	Note "WARNING, no egetty program found, using $PATH_EGETTY."
    else
	Note "Looks like $PATH_EGETTY is the program to exec for an extern call."
    fi
else
    Note "Using $PATH_EGETTY as the program to exec for an extern call."
fi

#
# UUCP lock file type and location.
#
if [ "$LOCKS" = auto ]; then
    case $TARGET in
    *-aix*)	LOCKS=ascii;;
    *-*-sco*)	LOCKS="-ascii";;
    *-sysv2*)	LOCKS=binary;;
    *-hpux*)	LOCKS=binary;;
    *-sysv4*)	LOCKS="+ascii";;
    *-sysv5SCO_SV6*)	LOCKS="-ascii";;
    *-sysv5*)	LOCKS="+ascii";;
    *-solaris*)	LOCKS="+ascii";;
    *-freebsd*)	LOCKS=ascii;;
    *-netbsd*)	LOCKS=ascii;;
    *bsd*)	LOCKS=binary;;
    *)		LOCKS=ascii;;
    esac
fi
Note "Looks like you use ${LOCKS}-style UUCP lock files."
if [ -z "$DIR_LOCKS" ]; then
    LOCKDIRS="
	/var/spool/locks
	/usr/spool/locks
	/var/spool/lock
	/usr/spool/lock
	/var/spool/uucp
	/usr/spool/uucp
    "
    case $TARGET in
    *-aix*)     LOCKDIRS="/etc/locks $LOCKDIRS";;
    *-linux*)   LOCKDIRS="/var/lock/uucp /var/lock $LOCKDIRS";;
    *-*-sco*)     LOCKDIRS="/usr/spool/uucp $LOCKDIRS";;
    esac
    DIR_LOCKS=
    for i in $LOCKDIRS; do
	test -d $i && { DIR_LOCKS=$i; break; }
    done
fi
if [ -z "$DIR_LOCKS" ]; then
    DIR_LOCKS=/var/spool/uucp
    Note "WARNING, could not locate a directory for UUCP lock files,"
    Note "guessing that UUCP lock files go in $DIR_LOCKS."
else
    Note "Looks like UUCP lock files go in $DIR_LOCKS."
fi

bitchExecutable()
{
    echo ""
    echo "WARNING, $1 does not seem to be an executable program;"
    echo "         you may need to correct this before starting up the fax server."
    ls -lL $1
    echo ""
}

#
# PostScript package and RIP location.
#
PickRIP()
{
    if [ -z "$PATH_GSRIP" ]; then
	GSLOCS="
	    /usr/local/bin/gs
	    /usr/contrib/bin/gs
	    /usr/gnu/bin/gs
	    /opt/gnu/bin/gs
	    /usr/bin/gs
	"
	for i in $GSLOCS; do
	    # verify Ghostscript was linked with the tiffg3 device driver
	    capture "$i -h 2>&1 | grep tiffg3" && { PATH_GSRIP=$i; break; }
	done
    fi
    case $PS in
    dps)	PATH_PSRIP=$PATH_DPSRIP;;
    imp)	PATH_PSRIP=$PATH_IMPRIP;;
    gs)		PATH_PSRIP=$PATH_GSRIP;;
    esac
}
CheckRIP()
{
    if [ -x "$PATH_PSRIP" ]; then
	if [ $PS = gs ]; then
	    # verify Ghostscript was linked with the tiffg3 device driver
	    capture "$PATH_PSRIP -h 2>&1 | grep tiffg3" || cat<<EOF

WARNING, no tiffg3 driver in $PATH_PSRIP.

The PostScript imaging program $PATH_PSRIP does not appear to be
to be configured with the tiffg3 device driver.  This is necessary for the
fax software to operate correctly.  See the documentation for information
on building Ghostscript with the necessary TIFF driver.
EOF
	fi
    elif [ -n "$PATH_PSRIP" ]; then
	bitchExecutable $PATH_PSRIP
    else
	cat<<EOF

WARNING, no PostScript imaging program.

No suitable PostScript imaging program was located on your system.
This may be due to your not having Ghostscript installed or not having
Ghostscript configured with the tiffg3 device driver.  A default pathname
will be used for the moment.  You must correct this situation for the
fax software to operate correctly.  See the WWW documentation for information
on building Ghostscript with the necessary TIFF driver.

EOF
	PATH_PSRIP=/usr/local/bin/gs
	PATH_GSRIP=$PATH_PSRIP
    fi
}

if [ "$PS" = auto ]; then
    case $TARGET in
    *-irix*)	if expr $RELEASE \>= 6.2 >/dev/null; then
		    PS=gs;
		else
		    PS=dps;
		fi
		;;
    *)		PS=gs;;
    esac
fi
Note "Looks like the $PS imager package should be used."
PickRIP
Note "Looks like $PATH_PSRIP is the PostScript RIP to use."
CheckRIP

#
# Ghostscript Fontmap File
#

getGSFonts()
{
	if [ ! "$PS" = gs ] && [ -n $PATH_PSRIP ];then
		return 1
	fi
	$PATH_PSRIP -h | $AWK -F '[ ]' '
		BEGIN { start = 0; }
		/Search path:/ { start = 1 }
		{
			if (start == 1) {
				if ($1 == "") {
					gsub(" ","")
					gsub("^[.]","")
					gsub("^:","")
					printf "%s", $0
				} else if ($1 != "Search") start = 0
			}
		}	
	'
	return 0
}

case $TARGET in
	*-freebsd*)     PATH_AFM=/usr/local/lib/afm ;;
	*)      if [ -z "$FONTMAP" ]; then
			FONTMAP=`getGSFonts`;
		fi
		;;
esac
Note "Setting the Fontmap path to $FONTMAP"

#
# Location of Adobe Font Metric files.
#
if [ -z "$PATH_AFM" ]; then
    # if the fontmap path is available use that
    # else just guess
    if [ -n "$FONTMAP" ]; then
	PATH_AFM=$FONTMAP
    else
        DIR_AFMS="
	    /usr/lib/afm
	    /usr/local/lib/afm
	    /usr/local/share/ghostscript/fonts
	    /usr/local/lib/ghostscript/fonts
	    /usr/share/ghostscript/fonts
	    /usr/gnu/lib/ghostscript/fonts
	    /opt/gnu/lib/ghostscript/fonts
	    /usr/lib/ghostscript/fonts
	    /usr/lib/gnu/ghostscript/fonts
        "
        case $TARGET in
        *-irix*)	DIR_AFMS="/usr/lib/DPS/AFM $DIR_AFMS";;
        *-bsdi*)	DIR_AFMS="/usr/contrib/lib/flexfax/afm $DIR_AFMS";;
        *-sunos*)	DIR_AFMS="/usr/openwin/lib/fonts/afm $DIR_AFMS";;
        esac
        PATH_AFM=
        for i in $DIR_AFMS; do
	    test -d $i && { PATH_AFM=$i; break; }
        done
    fi
fi
if [ -z "$PATH_AFM" ]; then
    # put it where ghostscript normally puts things
    PATH_AFM=/usr/local/lib/ghostscript/fonts
    Note "WARNING, could not locate a directory with font metric information,"
    Note "guessing that font metric information goes in $PATH_AFM."
else
    Note "Looks like font metric information goes in $PATH_AFM."
fi

#
# Setup manual page-related stuff.
#
# Manual pages are processed according to:
# 1. Section organization (BSD or System V)
# 2. Pre-formatted (w/ nroff) or source.
# 3. Compressed (compress, gzip, pack) or uncompressed.
# 4. Whether or not the FlexFAX ``F'' suffix must be
#    stripped for pages to be found (only for 4F pages).
#
if [ -z "$DIR_MAN" ]; then
    MANPATH="
	$MANPATH
	/usr/local/man
	/usr/contrib/man
	/usr/catman/local
    "
    DIR_MAN=
    for i in $MANPATH; do
	test -d $i && { DIR_MAN=$i; break; }
    done
    test -z "$DIR_MAN" && DIR_MAN=/usr/local/man
fi
Note "Looks like manual pages go in $DIR_MAN."
if [ -z "$MANSCHEME" ]; then
    case $TARGET in
    *-bsdi*|*-netbsd*)		MANSCHEME=bsd-nroff-gzip-0.gz;;
    *-freebsd*)			MANSCHEME=bsd-source-cat;;
    *-linux*)			MANSCHEME=bsd-source-cat;;
    *-ultrix*)			MANSCHEME=bsd-source-cat;;
    *-sunos*)			MANSCHEME=bsd-source-cat-strip;;
    *-sysv[234]*)		MANSCHEME=sysv-source-cat-strip;;
    *-hpux*)			MANSCHEME=sysv-source-cat-strip;;
    *-solaris*)			MANSCHEME=sysv-source-cat-strip;;
    *-aix*)			MANSCHEME=sysv-source-strip;;
    *-isc*|*-*-sco*)		MANSCHEME=sysv-source-cat;;
    *-irix*)			MANSCHEME=sysv-nroff-compress-Z;;
    *)
	#
	# Try to deduce the setup from existing manual pages.
	# XXX needs more work XXX
	#
	MANSCHEME=sysv-source-cat
	if [ -d /usr/share/man ]; then
	    if [ -d /usr/share/man/u_man ]; then
	       MANSCHEME=sysv-source-cat
	    elif [ -d /usr/share/man/man8 ]; then
	       MANSCHEME=bsd-source-cat
	    fi
	elif [ -d /usr/share/catman ]; then
	    if [ -d /usr/share/catman/u_man ]; then
	       MANSCHEME=sysv-nroff-cat
	    elif [ -d /usr/share/catman/man8 ]; then
	       MANSCHEME=bsd-nroff-cat
	    fi
	fi
	;;
    esac
fi
Note "Looks like manual pages should be installed with $MANSCHEME."

#
# Figure out which brand of echo we have and define
# prompt and print shell functions accordingly.
#
if [ `echo foo\\\c`@ = "foo@" ]; then
    prompt()
    {
	echo "$* \\c"
    }
elif [ "`echo -n foo`@" = "foo@" ]; then
    prompt()
    {
	echo -n "$* "
    }
else
    prompt()
    {
	echo "$*"
    }
fi

#
# Prompt the user for a string that can not be null.
#
promptForNonNullStringParameter()
{
    x="" val="$1" desc="$2"
    while [ -z "$x" ]; do
	prompt "$desc [$val]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	else
	    x="$val"
	fi
    done
    param="$x"
}

#
# Prompt the user for a numeric value.
#
promptForNumericParameter()
{
    x="" val="$1" desc="$2"
    while [ -z "$x" ]; do
	prompt "$desc [$val]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    match=`expr "$x" : "\([0-9]*\)"`
	    if [ "$match" != "$x" ]; then
		echo ""
		echo "This must be entirely numeric; please correct it."
		echo ""
		x="";
	    fi
	else
	    x="$val"
	fi
    done
    param="$x"
}

promptForImagerPackage()
{
    x=""
    while [ -z "$x" ]; do
	prompt "PostScript imager package [$PS]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    [dD]ps|DPS)			x="dps";;
	    [gG]s|[gG]host[sS]cript)	x="gs";;
	    imp)			x="imp";;
	    *)
cat <<EOF

"$x" is not a PostScript imager package; choose one of:

dps	for Display PostScript on a Silicon Graphics machine running
	any version of IRIX *prior* to 6.2
gs	for the freely available Ghostscript package
imp	for Impressario 2.1 on a Silicon Graphics machine

EOF
		x="";;
	    esac
	else
	    x="$PS"
	fi
    done
    PS="$x"
}

promptForPageSize()
{
    file=$1 x=""
    while [ -z "$x" ]; do
	prompt "Default page size [$PAGESIZE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    # search pagesizes file for an entry
	    y=`sed -e '/^#/d' $file | grep -i "$x" | sed -e 's/	.*//;q'`
	    if [ -z "$y" ]; then
		cat<<EOF

"$x" is not a known page size; the following are known page sizes:

Name			Abbrev	Width	Height	Width	Height	Top	Left
EOF
		sed -e '/^#/d' -e '/@DEFPAGESIZE@/d' $file
		echo ""
		x=""
	    else
		x="$y"
	    fi
	else
	    x="$PAGESIZE"
	fi
    done
    PAGESIZE="$x"
}

#
# Prompt the user for a numeric value.
#
promptForVRes()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Default vertical res (lpi) [$DEFVRES]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    98|low|med*)	x="98";;
	    196|high|fine)	x="196";;
	    *)
cat <<EOF

"$x" is not a valid vertical resolution; choose either "98" lines/inch
(low resolution) or "196" lines/inch (often called fine resolution).

EOF
		x="";;
	    esac
	else
	    x="$DEFVRES"
	fi
    done
    DEFVRES="$x"
}

promptForUUCPLockScheme()
{
    x=""
    while [ -z "$x" ]; do
	prompt "UUCP lock file scheme [$LOCKS]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    ascii|[-+]ascii)	;;
	    binary|[-+]binary)	;;
	    *)
cat <<EOF

"$x" is not a valid UUCP lock file scheme; choose "ascii" or
"binary" to get lock files with the process ID of the lock holder
written as ASCII or binary values and optionally prefix this with
"+" for SVR4-style lock file names (LK.xxx.yyy.zzz) or "-" for
SCO-style lock file names (convert tty names from upper to lower
case when forming the lock file name).

EOF
		x="";;
	    esac
	else
	    x="$LOCKS"
	fi
    done
    LOCKS="$x"
}

promptForManPageScheme()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Manual page installation scheme [$MANSCHEME]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    # XXX do a better job of validating...
	    case "$x" in
	    bsd-nroff-cat*|sysv-nroff-cat*)	;;
	    bsd-nroff-gzip*|sysv-nroff-gzip*)	;;
	    bsd-nroff-comp*|sysv-nroff-comp*)	;;
	    bsd-nroff-pack*|sysv-nroff-pack*)	;;
	    bsd-source-cat*|sysv-source-cat*)	;;
	    bsd-source-gzip*|sysv-source-gzip*)	;;
	    bsd-source-comp*|sysv-source-comp*)	;;
	    bsd-source-pack*|sysv-source-pack*)	;;
	    *)
cat <<EOF

"$x" is not a valid manual page installation scheme.  Schemes are
constructed according to:

    <organization>-<formatting>-<compression>[-<suffix>]

where:

<organization>  is either "bsd" for BSD-style section organization (e.g.
		file formats in section 5) or "sysv" for System V-style
		organization (e.g. file formats in section 4).

<formatting>    is either "nroff" to force installation of formatted
                materials (using nroff) or "source" to get the nroff
		source installed.

<compression>   is either the name of a program to compress the manual
                pages (gipz, compress, pack) or "cat" for uncompressed data.

<suffix>        is either the file suffix to convert installed pages to
                (e.g. 0.gz for gzip-compressed pages under BSD) or "strip"
		to force the normal ".4f" suffix to be converted to ".4"
		(or ".5" if using the BSD organization).  If no -<suffix>
		is specified then filenames are not converted when they
		are installed.

Common schemes are:

bsd-nroff-gzip-0.gz	compressed formatted pages for BSD 
bsd-source-cat		nroff source w/ BSD organization
sysv-source-cat-strip	nroff source for SysV w/o .4f suffix
sysv-source-cat		nroff source for SysV as-is

EOF
		x="";;
	    esac
	else
	    x="$MANSCHEME"
	fi
    done
    MANSCHEME="$x"
}

getPageSizeInfo()
{
    pat=`grep '^default' $1 | \
	sed -e 's/default[	 ]*//' -e 's/[ 	][ 	]*/\[ 	\]*/g'`
    param=`grep "$pat" $1 | sed -e 's/	.*//;q'`
}

printConfig1()
{
    cat<<EOF

HylaFAX configuration parameters (part 1 of 2) are:

[ 1] Directory for applications:        $DIR_BIN
[ 2] Directory for lib data files:      $DIR_LIBDATA
[ 3] Directory for lib executables:     $DIR_LIBEXEC
[ 4] Directory for system apps:  	$DIR_SBIN
[ 5] Directory for manual pages:        $DIR_MAN
[ 7] Directory for spooling:            $DIR_SPOOL
[ 8] Directory for uucp lock files:     $DIR_LOCKS
[ 9] Uucp lock file scheme:             $LOCKS
[10] PostScript imager package:         $PS
[11] PostScript imager program:         $PATH_PSRIP
[12] Manual page installation scheme:   $MANSCHEME
[13] Default page size:                 $PAGESIZE
[14] Default vertical res (lpi):        $DEFVRES

EOF
}

printConfig2()
{
    cat<<EOF

HylaFAX configuration parameters (part 2 of 2) are:

[15] Location of getty program:         $PATH_GETTY
[16] Location of voice getty program:   $PATH_VGETTY
[17] Location of sendmail program:      $PATH_SENDMAIL
[18] Location of TIFF tools:            $TIFFBIN
[19] Location of SysV init scripts:	$DIR_SYSVINIT
[20] Location of SysV start scripts:	$DIR_SYSVINITSTART
[21] Location of SysV stop scripts:	$DIR_SYSVINITSTOP
[22] Name of SysV start script:		$NAME_SYSVINITSTART
[23] Name of SysV stop script:		$NAME_SYSVINITSTOP
[24] Init script starts faxq:		$FAXQ_SERVER
[25] Init script starts hfaxd		$HFAXD_SERVER
[26] Start paging protocol:		$HFAXD_SNPP_SERVER
EOF
}
  

promptForParameter()
{
    case $1 in
    1)	promptForNonNullStringParameter "$DIR_BIN" \
	    "Directory to install applications";	DIR_BIN="$param"
	;;
    2)	promptForNonNullStringParameter "$DIR_LIBDATA" \
	    "Directory to install library data files";	DIR_LIBDATA="$param"
	;;
    3)	promptForNonNullStringParameter "$DIR_LIBEXEC" \
	    "Directory to install library executables";	DIR_LIBEXEC="$param"
	;;
    4)	promptForNonNullStringParameter "$DIR_SBIN" \
	    "Directory to install system apps";		DIR_SBIN="$param"
	;;
    5)	promptForNonNullStringParameter "$DIR_MAN" \
	    "Directory to install manual pages";	DIR_MAN="$param"
	;;
    7)	promptForNonNullStringParameter "$DIR_SPOOL" \
	    "Directory to setup server spooling area";	DIR_SPOOL="$param"
	;;
    8)	promptForNonNullStringParameter "$DIR_LOCKS" \
	    "Directory for uucp lock files";		DIR_LOCKS="$param"
	;;
    9)	promptForUUCPLockScheme;;
    10)	promptForImagerPackage; PickRIP; CheckRIP;;
    11)	promptForNonNullStringParameter "$PATH_PSRIP" \
	    "PostScript imager program";		PATH_PSRIP="$param"
	case "$PS" in
	dps)	PATH_DPSRIP=$PATH_PSRIP;;
	imp)	PATH_IMPRIP=$PATH_PSRIP;;
	gs)	PATH_GSRIP=$PATH_PSRIP;;
	esac
	;;
    12)	promptForManPageScheme;;
    13)	promptForPageSize $SRCDIR/libhylafax/pagesizes.in;;
    14)	promptForVRes;;
    15)	promptForNonNullStringParameter "$PATH_GETTY" \
	    "Location of getty program";		PATH_GETTY="$param"
	;;
    16) promptForNonNullStringParameter "$PATH_VGETTY" \
	    "Location of vgetty program";	        PATH_VGETTY="$param"
	;;
    17)	promptForNonNullStringParameter "$PATH_SENDMAIL" \
	    "Location of sendmail program";		PATH_SENDMAIL="$param"
	;;
    18) promptForNonNullStringParameter "$TIFFBIN" \
	    "Location of TIFF tools";			TIFFBIN="$param"
	;;
    19) promptForNonNullStringParameter "$DIR_SYSVINIT" \
	    "Location of SysV init scripts";		DIR_SYSVINIT="$param"
	;;
    20) promptForNonNullStringParameter "$DIR_SYSVINITSTART" \
	    "Location of SysV start scripts";		DIR_SYSVINITSTART="$param"
	;;
    21) promptForNonNullStringParameter "$DIR_SYSVINITSTOP" \
	    "Location of SysV stop scripts";		DIR_SYSVINITSTOP="$param"
	;;
    22) promptForNonNullStringParameter "$NAME_SYSVINITSTART" \
	    "Name of SysV start script";		NAME_SYSVINITSTART="$param"
	;;
    23) promptForNonNullStringParameter "$NAME_SYSVINITSTOP" \
	    "Name of SysV stop script";			NAME_SYSVINITSTOP="$param"
	;;
    24) promptForNonNullStringParameter "$FAXQ_SERVER" \
	    "Init script starts faxq";			FAXQ_SERVER="$param"
	;;
    25) promptForNonNullStringParameter "$HFAXD_SERVER" \
	    "Init script starts hfaxd";			HFAXD_SERVER="$param"
	;;
    26) promptForNonNullStringParameter "$HFAXD_SNPP_SERVER" \
	    "Start paging protocol";			HFAXD_SNPP_SERVER="$param"
	;;
    esac
}

checkForExecutable()
{
    test -x $1 || bitchExecutable $1
}

if [ $QUIET = no ] && [ $INTERACTIVE != no ]; then
	Note "Press Return to Continue "
	read ok
fi

if [ $QUIET = no ]; then
    ok=skip
    while [ "$ok" != y ] && [ "$ok" != yes ]; do
	if [ "$ok" != skip ]; then
	    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
		promptForParameter $i;
	    done
	fi
	printConfig1
	if [ $INTERACTIVE = no ]; then
	    ok=yes
	else
	    prompt "Are these ok [yes]?"; read ok
	    test -z "$ok" && ok=yes
	    case "$ok" in
	    [1-9]|1[0-4])	promptForParameter $ok;;
	    [yY]*|[nN]*)	continue;;
	    ?*)
		echo ""
		echo "\"y\", \"yes\", or <RETURN> accepts the displayed parameters."
		echo "A number lets you change the numbered parameter."
		echo ""
		;;
	    esac
	    ok=skip
	fi
    done
fi

if [ $QUIET = no ]; then
    ok=skip
    while [ "$ok" != y ] && [ "$ok" != yes ]; do
	if [ "$ok" != skip ]; then
	    for i in 15 16 17 18 19 20 21 22 23 24 25 26 27 ; do
		promptForParameter $i;
	    done
	fi
	printConfig2
	checkForExecutable $PATH_SENDMAIL
	checkForExecutable $PATH_GETTY
	if [ $INTERACTIVE = no ]; then
	    ok=yes
	else
	    prompt "Are these ok [yes]?"; read ok
	    test -z "$ok" && ok=yes
	    case "$ok" in
	    1[5-9]|2[0-7])	promptForParameter $ok;;
	    [yY]*|[nN]*)	continue;;
	    ?*)
		echo ""
		echo "\"y\", \"yes\", or <RETURN> accepts the displayed parameters."
		echo "A number lets you change the numbered parameter."
		echo ""
		;;
	    esac
	    ok=skip
	fi
    done
fi

$RM config.cache; dumpvals |sort> config.cache
case $MANSCHEME in
bsd-source-*)	MANAPPS=man1 MANSYS=man8 MANFILES=man5;;
bsd-nroff-*)	MANAPPS=cat1 MANSYS=cat8 MANFILES=cat5;;
sysv-source-*)	MANAPPS=man1 MANSYS=man1 MANFILES=man4;;
sysv-nroff-*)	MANAPPS=cat1 MANSYS=cat1 MANFILES=cat4;;
esac
case $MANSCHEME in
bsd-*-strip)	MANNUM4_5=5  MANNUM1_8=8;;
bsd-*)		MANNUM4_5=5F MANNUM1_8=8C;;
sysv-*-strip)	MANNUM4_5=4  MANNUM1_8=1;;
sysv-*)		MANNUM4_5=4F MANNUM1_8=1M;;
esac
case $MANSCHEME in
*-source-*)	MANCVT='${MANSED} $? >$@';;
*-nroff-gzip-*)	MANCVT='${MANSED} $? | nroff -man | gzip > $@';;
*-nroff-pack-*)	MANCVT='${MANSED} $? | nroff -man | pack > $@';;
*-nroff-com*-*)	MANCVT='${MANSED} $? | nroff -man | compress > $@';;
*-nroff-cat-*)	MANCVT='${MANSED} $? | nroff -man > $@';;
esac
case $MANSCHEME in
*-0|*-0.gz|*-0.Z|*-gz|*-Z|*-z)
    suf=`echo $MANSCHEME | $SED 's/.*-/./'`
    A='`echo $$i | sed' B='`'		# workaround shell bugs
    MANCAPPNAME="$A s/\\\\.1\$\$/$suf/$B"
    MANCFILENAME="$A s/\\\\.4f\$\$/$suf/$B"
    MANSAPPNAME="$A s/\\\\.1m\$\$/$suf/$B"
    MANSFILENAME="$A s/\\\\.4f\$\$/$suf/$B"
    ;;
bsd-*-strip)
    MANCAPPNAME='$$i'
    MANCFILENAME='`echo $$i | sed s/\\.4f$$/.5/`'
    MANSAPPNAME='`echo $$i | sed s/\\.1m$$/.8/`'
    MANSFILENAME='`echo $$i | sed s/\\.4f$$/.5/`'
    ;;
*-strip)
    MANCAPPNAME='$$i'
    MANCFILENAME='`echo $$i | sed s/\\.4f$$/.4/`'
    MANSAPPNAME='`echo $$i | sed s/\\.1m$$/.1/`'
    MANSFILENAME='`echo $$i | sed s/\\.4f$$/.4/`'
    ;;
bsd-*)
    MANCAPPNAME='$$i'
    MANCFILENAME='`echo $$i | sed s/\\.4f$$/.5f/`'
    MANSAPPNAME='`echo $$i | sed s/\\.1m$$/.8c/`'
    MANSFILENAME='`echo $$i | sed s/\\.4f$$/.5f/`'
    ;;
*)
    MANCAPPNAME='$$i' MANCFILENAME='$$i'
    MANSAPPNAME='$$i' MANSFILENAME='$$i'
    ;;
esac

Note ""

if [ $GS = yes ]; then
    test -d $SRCDIR/gs || {
	Note ""
	Note "WARNING, no Ghostscript build directory exists; disabling building"
	Note "and installation of Ghostscript from source (GS=no)."
	Note ""
	GS=no
    }
fi
if [ $DPS = yes ]; then
    test -d $SRCDIR/dps || {
	Note ""
	Note "WARNING, no DPS build directory exists; disabling building"
	Note "and installation of ps2fax for IRIX (DPS=no)."
	Note ""
	DPS=no
    }
fi
if [ $IMP = yes ]; then
    test -d $SRCDIR/imp || {
	Note ""
	Note "WARNING, no Impressario build directory exists; disabling building"
	Note "and installation of the Impressario 2.1 back-end for IRIX (IMP=no)."
	Note ""
	IMP=no
    }
fi

#
# Convert default page size name to an entry that goes
# in the pagesizes database file.
#
F=$SRCDIR/libhylafax/pagesizes
test -f $F.in || {
    bitch "$F.in is missing; this should be part of the distribution."
    boom
}
DEFPAGESIZE=`grep "$PAGESIZE" $F.in | $SED -e 's/[^	]*/default/;q'`
x="`relativize ${LIBTIFF}`"; LIBTIFF="$x"
x="`relativize ${LIBZ}`"; LIBZ="$x"
x="`relativize ${LIBREGEX}`"; LIBREGEX="$x"
x="`relativize ${LIBDB}`"; LIBDB="$x"
x="`relativize ${LIBINTL}`"; LIBINTL="$x"

# NB: these should be sorted alphabetically
$RM confsed1; dumpvars "$VAR1" | sort > confsed1
$RM confsed2; dumpvars "$VAR2" | sort > confsed2


SedConfigFiles()
{
    for F do
	test -f $SRCDIR/$F.in || {
	    bitch "$SRCDIR/$F.in is missing; this should be part of the distribution."
	    boom
	}
	dir=`echo $F | $SED 's;/[^/]*$;;'`
	if [ $dir != $F ] && [ ! -d $dir ]; then
	    Note "Creating $dir directory"
	    $MKDIR $dir
	fi
	suffix=`echo $F | $SED 's/.*\.//'`
	if [ "$suffix" = h ] || [ "$suffix" = po ]; then
	    #
	    # Compare old and new versions so that include files
	    # are only updated when something has changed--this
	    # saves time for subsequent makes.  Note we screen
	    # out use of @DATE@ 'cuz otherwise that'll mess up
	    # the comparison (this assumes dates are used in lines
	    # of the form DATE: @DATE@).
	    #
	    unset POSIXLY_CORRECT
	    $RM $F.new; $SED -f confsed1 $SRCDIR/$F.in | $SED -f confsed2 > $F.new
	    POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
	    $RM confx; $SED '/D[aA][tT][eE]:/d' $F.new >confx
	    $RM confy; $SED '/D[aA][tT][eE]:/d' $F >confy 2>/dev/null
	    if cmp -s confx confy >/dev/null 2>&1; then
		$RM $F.new
	    else
		Note "Creating $F from $SRCDIR/$F.in"
		$RM $F; $MV $F.new $F; $CHMOD 444 $F
	    fi
	else
	    Note "Creating $F from $SRCDIR/$F.in"
	    unset POSIXLY_CORRECT
	    if $SED -f confsed1 $SRCDIR/$F.in  | $SED -f confsed2 >$F.new; then
		POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
		$RM $F; $MV $F.new $F; $CHMOD 444 $F
	    else
		POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
		cat 1>&2 <<EOF
Help, there was a problem crafting $F from $F.in.
The command:

    $SED -f confsed1 $SRCDIR/$F.in | $SED -f confsed2 >$F.new

failed.  Aborting without cleaning up files so you can take a look...
EOF
		exit 1			# NB: don't use boom/die
	    fi
	fi
    done
}

#
# Configuration File Generation
#
# The following files are created using the parameters determined above:
#
# defs			master make include file for the source code
# rules			make definitions for building from source code
# config.h		master definitions compiled into code
# */Makefile		make rules files
# port/install.sh	SGI install program emulation script
# port/mkdepend		makefile dependency generator (if configured)
# etc/faxsetup.sh	script for setting up a machine
# etc/faxaddmodem.sh	script for adding/configuring a modem
# etc/probemodem.sh	script for probing a modem for its capabilities
# etc/hylafax		SysV-style init script for HylaFAX servers
# faxcover/edit-faxcover.sh script to edit faxcover.ps
# util/xferfaxstats.sh	script for transmit statistics accounting
# util/recvstats.sh	script for receive statistics accounting
# util/faxcron.sh	script for cleaning up the spooling area (run from cron)
# libhylafax/pagesizes	client page dimensions database (has default page size)
# pkg/cpkginfo		SVR4 package stuff (client package info)
# pkg/cproto.stub	SVR4 package stuff (client prototype stub)
# pkg/crequest		SVR4 package stuff
# pkg/make_proto.sh	SVR4 package stuff (script for making prototype files)
# pkg/postinstall	SVR4 package stuff
# pkg/postremove	SVR4 package stuff
# pkg/spkginfo		SVR4 package stuff (server package info)
# pkg/sproto.stub	SVR4 package stuff (server prototype stub)
# pkg/srequest		SVR4 package stuff
#
CONF_FILES="
    defs
    config.h
    rules

    Makefile
    config/Makefile
    etc/Makefile
    faxalter/Makefile
    faxcover/Makefile
    faxd/Makefile
    faxmail/Makefile
    faxrm/Makefile
    faxstat/Makefile
    hfaxd/Makefile
    libhylafax/Makefile
    man/Makefile
    sendfax/Makefile
    sendpage/Makefile
    util/Makefile

    port/Makefile
    port/install.sh
    port/version.c

    libhylafax/pagesizes

    etc/faxsetup.sh
    etc/faxaddmodem.sh
    etc/probemodem.sh
    etc/hylafax

    faxcover/edit-faxcover.sh

    util/xferfaxstats.sh
    util/recvstats.sh
    util/faxcron.sh
    util/archive.sh
    util/dictionary.sh
    util/common-functions.sh
    util/faxrcvd.sh
    util/mkcover.sh
    util/notify.sh
    util/notify-4.1.sh
    util/notify-4.2.sh
    util/pcl2fax.sh
    util/pollrcvd.sh
    util/ps2fax.dps.sh
    util/ps2fax.gs.sh
    util/pdf2fax.gs.sh
    util/ps2fax.imp.sh
    util/tiff2fax.sh
    util/wedged.sh
    util/tiff2pdf.sh

    pkg/Makefile
    pkg/cpkginfo
    pkg/cproto.stub
    pkg/crequest
    pkg/make_proto.sh
    pkg/postinstall
    pkg/postremove
    pkg/spkginfo
    pkg/sproto.stub
    pkg/srequest
"
SedConfigFiles $CONF_FILES
test $DPS = yes &&		   SedConfigFiles dps/Makefile
test $GS = yes &&		   SedConfigFiles gs/Makefile
test $IMP = yes &&		   SedConfigFiles imp/Makefile
test "$MKDEPEND" != ":" &&	   SedConfigFiles port/mkdepend
test $SGI2FAX = yes &&	   	   SedConfigFiles sgi2fax/Makefile
test $REGEX = yes &&		   SedConfigFiles regex/Makefile
test $NLS = yes &&		   SedConfigFiles po/Makefile po/version.po
test -f $SRCDIR/MLA/VERSION &&	   SedConfigFiles MLA/Makefile

if [ "$MAKEDEPINCLUDE" != "sinclude" ]; then
    Note "Setting up make dependency files."
    #
    # Setup null make dependency files so that we can include
    # it w/o problem.  Some systems have conditional include
    # support in their make, but others do not, so we use an
    # unconditional include and setup everthing as null here
    #
    DEPEND=".
	faxalter
	faxcover
	faxd
	faxmail
	faxrm
	faxstat
	hfaxd
	libhylafax
	sendfax
	sendpage
	util
	man
	etc
	config
	port
	"
    test $GS = yes	&& DEPEND="$DEPEND gs"
    test $SGI2FAX = yes	&& DEPEND="$DEPEND sgi2fax"
    test $REGEX = yes	&& DEPEND="$DEPEND regex"
    test $NLS = yes	&& DEPEND="$DEPEND po"
    test -f $SRCDIR/MLA/VERSION && DEPEND="$DEPEND MLA"
    test -d $SRCDIR/faxview && test -d faxview && DEPEND="$DEPEND faxview"
    for i in $DEPEND; do
	test -f $i/Makedepend || cp /dev/null $i/Makedepend
    done
fi

Note "Done."

$RM $JUNK
exit 0