File: coin.m4

package info (click to toggle)
coinor-cgl 0.60.3%2Brepack1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,536 kB
  • sloc: cpp: 57,099; sh: 11,245; makefile: 408; ansic: 35
file content (4265 lines) | stat: -rw-r--r-- 156,120 bytes parent folder | download
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
# Copyright (C) 2006, 2009 International Business Machines.
# All Rights Reserved.
# This file is distributed under the Eclipse Public License.
#
## $Id: coin.m4 4026 2019-10-09 14:27:30Z stefan $
#
# Author: Andreas Wachter    IBM      2006-04-14

# This file defines the common autoconf macros for COIN
#

# Check requirements
AC_PREREQ(2.59)

###########################################################################
#                           coin_foreach_w                                #
###########################################################################

# the autoconf version used by COIN-OR is so old that it does not have the M4 macro foreach_w.
# thus, we define our own one which applies the foreach macro to the same arguments but with
# all spaces replaced by ',' in the second argument.
# further, we run the loop only if the second argument is not empty
AC_DEFUN([coin_foreach_w], [m4_ifval([$2], [m4_foreach([$1], [m4_bpatsubsts([$2],[[ 	]+],[, ])], [$3])])])

###########################################################################
#                            COIN_CHECK_FILE                              #
###########################################################################

# A simple replacement for AC_CHECK_FILE that works for cross compilation

AC_DEFUN([AC_COIN_CHECK_FILE],
[if test -r $1; then
  $2
  :
else
  $3
  :
fi
])

###########################################################################
#                           COIN_CHECK_VPATH                              #
###########################################################################

# This macro sets the variable coin_vpath_config to true if this is a
# VPATH configuration, otherwise it sets it to false.

AC_DEFUN([AC_COIN_CHECK_VPATH],
[
AC_MSG_CHECKING(whether this is a VPATH configuration)
if test `cd $srcdir; pwd` != `pwd`; then
  coin_vpath_config=yes;
else
  coin_vpath_config=no;
fi
AC_MSG_RESULT($coin_vpath_config)
]) # AC_COIN_CHECK_VPATH


###########################################################################
#                          COIN_PROJECTVERSION                            #
###########################################################################

# This macro is used by COIN_PROJECTDIR_INIT and sets up variables related
# to versioning numbers of the project.

AC_DEFUN([AC_COIN_PROJECTVERSION],
[m4_ifvaln([$1],[
  AC_DEFINE_UNQUOTED(m4_toupper($1_VERSION), ["$PACKAGE_VERSION"],[Version number of project])
  
  [coin_majorver=`echo $PACKAGE_VERSION | sed -n -e 's/^\([0-9]*\).*/\1/gp'`]
  [coin_minorver=`echo $PACKAGE_VERSION | sed -n -e 's/^[0-9]*\.\([0-9]*\).*/\1/gp'`]
  [coin_releasever=`echo $PACKAGE_VERSION | sed -n -e 's/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/gp'`]
  if test "x$coin_majorver" = x ; then coin_majorver=9999 ; fi
  if test "x$coin_minorver" = x ; then coin_minorver=9999 ; fi
  if test "x$coin_releasever" = x ; then coin_releasever=9999 ; fi
  AC_DEFINE_UNQUOTED(m4_toupper($1_VERSION_MAJOR),   [$coin_majorver],   [Major Version number of project])
  AC_DEFINE_UNQUOTED(m4_toupper($1_VERSION_MINOR),   [$coin_minorver],   [Minor Version number of project])
  AC_DEFINE_UNQUOTED(m4_toupper($1_VERSION_RELEASE), [$coin_releasever], [Release Version number of project])

  # We use the following variable to have a string with the upper case
  # version of the project name
  COIN_PRJCT=m4_toupper($1)

  # Set the project's SVN revision number. The complicated sed expression
  # (made worse by quadrigraphs) ensures that things like 4123:4168MS end up
  # as a single number.
  AC_CHECK_PROG([have_svnversion],[svnversion],[yes],[no])
  if test "x$have_svnversion" = xyes; then
    AC_SUBST(m4_toupper($1_SVN_REV))
    svn_rev_tmp=`LANG=en_EN svnversion $srcdir 2>/dev/null`
    if test "x$svn_rev_tmp" != xexported -a "x$svn_rev_tmp" != x -a "x$svn_rev_tmp" != "xUnversioned directory"; then
      m4_toupper($1_SVN_REV)=`echo $svn_rev_tmp | sed -n -e 's/^@<:@0-9@:>@*://' -e 's/\(@<:@0-9@:>@\)@<:@^0-9@:>@*$/\1/p'`
      AC_DEFINE_UNQUOTED(m4_toupper($1_SVN_REV), $m4_toupper($1_SVN_REV), [SVN revision number of project])
    fi
  fi
 ])
 
# Capture libtool library version, if given.
 m4_ifval([$2],[coin_libversion=$2],[])
])

###########################################################################
#                         COIN_PROJECTDIR_INIT                            #
###########################################################################

# This macro does everything that is required in the early part in the
# configure script, such as defining a few variables.  This should only be used
# in the main directory of a project directory (the one which holds the src
# directory for the project). The first parameter is the project name. The
# second (optional) is the libtool library version (important for releases,
# less so for stable or trunk).

AC_DEFUN([AC_COIN_PROJECTDIR_INIT],
[
# As backup, we make sure we don't loose an FLIBS if it has been set
# by the user
save_FLIBS="$FLIBS"

# A useful makefile conditional that is always false
AM_CONDITIONAL(ALWAYS_FALSE, false)

# We set the following variable so that we know later in AC_COIN_FINALIZE
# that we are in a project main directory
coin_projectdir=yes

# Set the project's version numbers
AC_COIN_PROJECTVERSION($1, $2)
]) # AC_COIN_PROJECTDIR_INIT

###########################################################################
#                          COIN_DEBUG_COMPILE                             #
###########################################################################

# enable the configure flags --enable-debug and --enable-debug-prjct
# (where prcjt is the name of the project in lower case) and set the
# variable coin_debug_compile to true or false This is used by
# COIN_PROG_CXX, COIN_PROG_CC and COIN_PROG_F77 to determine the
# compilation flags.  This macro also makes the switches
# --with-prjct-verbosity and --with-prjct-checklevel available, which
# define the preprocessor macros COIN_PRJCT_VERBOSITY and
# COIN_PRJCT_CHECKLEVEL to the specified value (default is 0).
#
# The project specific flags are only made available, if one gives the
# name of the project as first argument to this macro.

AC_DEFUN([AC_COIN_DEBUG_COMPILE],
[AC_BEFORE([$0],[AC_COIN_PROG_CXX])dnl
AC_BEFORE([$0],[AC_COIN_PROG_CC])dnl
AC_BEFORE([$0],[AC_COIN_PROG_F77])dnl

AC_MSG_CHECKING([whether we want to compile in debug mode])

AC_ARG_ENABLE([debug],
[AC_HELP_STRING([--enable-debug],
                [compile all projects with debug options tests (implies --disable-shared)])],
[case "${enableval}" in
   yes) coin_debug_compile=true
        if test "${enable_shared+set}" = set; then :; else
          enable_shared=no
        fi 
        ;;
   no)  coin_debug_compile=false
        ;;
   *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug)
        ;;
esac],
[coin_debug_compile=false])

m4_ifvaln([$1],
[AC_ARG_ENABLE(debug-m4_tolower($1),
 [AC_HELP_STRING([--enable-debug-m4_tolower($1)],
                 [compile project $1 with debug compiler flags])],
 [case "${enableval}" in
    yes) coin_debug_compile=true
         ;;
    no)  coin_debug_compile=false
         ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug-m4_tolower($1))
         ;;
 esac],[:])
]) # m4_ifvaln([$1],

if test $coin_debug_compile = true; then
  AC_MSG_RESULT([yes])
else
  AC_MSG_RESULT([no])
fi

m4_ifvaln([$1],
[AC_ARG_WITH(m4_tolower($1)-verbosity,
             AC_HELP_STRING([--with-m4_tolower($1)-verbosity],
                            [specify the debug verbosity level for project $1]),
             [if test "$withval" = yes; then
                withval=1
              fi
              m4_tolower(coin_$1_verbosity)=$withval],
             [m4_tolower(coin_$1_verbosity)=0])
 AC_DEFINE_UNQUOTED(m4_toupper(COIN_$1_VERBOSITY),
                    m4_tolower($coin_$1_verbosity),
                    [Define to the debug verbosity level (0 is no output)])

 AC_ARG_WITH(m4_tolower($1)-checklevel,
             AC_HELP_STRING([--with-m4_tolower($1)-checklevel],
                            [specify the sanity check level for project $1]),
             [if test "$withval" = yes; then
                withval=1
              fi
              m4_tolower(coin_$1_checklevel)=$withval],
             [m4_tolower(coin_$1_checklevel)=0])
 AC_DEFINE_UNQUOTED(m4_toupper(COIN_$1_CHECKLEVEL),
                    m4_tolower($coin_$1_checklevel),
                    [Define to the debug sanity check level (0 is no test)])
]) # m4_ifvaln([$1],
 
]) # AC_COIN_DEBUG_COMPILE

###########################################################################
#                          COIN_ENABLE_MSVC                               # 
###########################################################################

# This macro is invoked by any PROG_compiler macro to establish the
# --enable-msvc option.
# The job of this macro is to make sure the option is correct and
# to set enable_msvc. Legal values are yes and no (disabled).
# If set, assume the presence of cl/link. It's the user's responsibility to
# make sure their PATH is correct. In particular, that MSVC link is found
# and not cygwin link (we want to do code linking, not file linking).
# It's the responsibility of individual PROG_compiler macros to ensure that
# they correctly set the compiler search list and preprocess, compile, and
# link flags. This is tied to compiler setup because in practice invocations
# of the preprocessor and linker are made through the compiler.
# For backward compatibility, we also check for --enable-doscompile=msvc.

AC_DEFUN([AC_COIN_ENABLE_MSVC],
[AC_REQUIRE([AC_CANONICAL_BUILD])

  # for backward compatibility
  AC_ARG_ENABLE([doscompile],,[enable_doscompile=$enableval],[enable_doscompile=no])
  
  AC_ARG_ENABLE([msvc],
    [AC_HELP_STRING([--enable-msvc],
                    [Prefer (i)cl/ifort/link over GNU on MinGW/Cygwin.])],
    [enable_msvc=$enableval],
    [enable_msvc=no
     if test "$enable_doscompile" = msvc ; then
       enable_msvc=yes
     elif test "$enable_doscompile" != no ; then
       AC_MSG_ERROR([--enable-doscompile=$enable_doscompile not supported anymore.])
     fi
    ])
    
  if test "$enable_msvc" = MD; then
    enable_shared=yes
    enable_msvc=yes
  fi

  if test "$enable_msvc" = yes; then
    case $build in
      *-cygwin* | *-mingw*) ;;
      *) AC_MSG_ERROR([--enable-msvc option makes sense only under Cygwin or MinGW]) ;;
    esac
  fi
])

###########################################################################
#                             COIN_PROG_CXX                               #
###########################################################################

# Find the compile command by running AC_PROG_CXX (with compiler names for
# different operating systems) and put it into CXX (unless it was given by the
# user). Then find an appropriate value for CXXFLAGS. If either of CXXFLAGS or
# PRJCT_CXXFLAGS is defined, that value is used (replace PRJCT with the upper
# case name of this project).  It is possible to provide additional -D flags
# in the variable CXXDEFS, and additional compilation flags with ADD_CXXFLAGS.

AC_DEFUN([AC_COIN_PROG_CXX],
[AC_REQUIRE([AC_COIN_PROG_CC]) #Let's try if that overcomes configuration problem with VC++ 6.0
AC_REQUIRE([AC_COIN_ENABLE_MSVC])
AC_LANG_PUSH(C++)

AC_ARG_VAR(CXXDEFS,[Additional -D flags to be used when compiling C++ code.])
AC_ARG_VAR(ADD_CXXFLAGS,[Additional C++ compiler options])
AC_ARG_VAR(DBG_CXXFLAGS,[Debug C++ compiler options])
AC_ARG_VAR(OPT_CXXFLAGS,[Optimize C++ compiler options])

coin_has_cxx=yes

save_cxxflags="$CXXFLAGS"
# For *-*-solaris*, promote Studio/Workshop compiler to front of list.
case $build in
  *-cygwin* | *-mingw*)
      if test "$enable_msvc" = yes ; then
         comps="icl cl g++"
      else
         comps="g++ icl cl"
      fi ;;
  *-*-solaris*)
  	     comps="CC xlC_r aCC g++ c++ pgCC icpc gpp cxx cc++ cl FCC KCC RCC" ;;
  *-darwin*) comps="clang++ g++ c++ CC" ;;
  *-linux-gnu*)
             comps="g++ c++ pgCC icpc gpp cxx cc++ cl FCC KCC RCC xlC_r aCC CC" ;;
          *) comps="xlC_r aCC CC g++ c++ pgCC icpc gpp cxx cc++ cl FCC KCC RCC" ;;
esac

# We delete the cached value, since the test might not have been
# performed with our choice of compilers earlier
$as_unset ac_cv_prog_CXX || test "${ac_cv_prog_CXX+set}" != set || { ac_cv_prog_CXX=; export ac_cv_prog_CXX; }
# AC_MSG_NOTICE([C++ compiler candidates: $comps])
AC_PROG_CXX([$comps])

#AC_PROG_CXX sets CXX to g++ if it cannot find a working C++ compiler
#thus, we test here whether $CXX is actually working 
AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether C++ compiler $CXX works]);
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(, [int i=0;])],
  [AC_MSG_RESULT(yes)],
  [AC_MSG_RESULT(no)
   AC_MSG_ERROR(failed to find a C++ compiler or C++ compiler $CXX does not work)]
)
AC_LANG_POP(C++)

coin_cxx_is_cl=false
# It seems that we need to cleanup something here for the Windows
case "$CXX" in
  clang* | */clang*) ;;
  cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
    sed -e 's/^void exit (int);//' confdefs.h >> confdefs.hh
    mv confdefs.hh confdefs.h
    coin_cxx_is_cl=true
    ;;
esac

# add automake conditional so we can recognize cl compiler in makefile
AM_CONDITIONAL(COIN_CXX_IS_CL, [test $coin_cxx_is_cl = true])

# Autoconf incorrectly concludes that cl recognises -g. It doesn't.
case "$CXX" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* )
    if test "$ac_cv_prog_cxx_g" = yes ; then
      ac_cv_prog_cxx_g=no
      AC_MSG_NOTICE([Overruling autoconf; cl does not recognise -g.])
    fi ;;
  * )
    if test x"$CYGPATH_W" = x ; then
      CYGPATH_W=echo
    fi
    ;;
esac
CXXFLAGS="$save_cxxflags"

# Check if a project specific CXXFLAGS variable has been set
if test x$COIN_PRJCT != x; then
  eval coin_tmp=\${${COIN_PRJCT}_CXXFLAGS+set}
  if test x$coin_tmp = xset; then
    eval CXXFLAGS=\${${COIN_PRJCT}_CXXFLAGS}
  fi
fi

if test x"$CXXFLAGS" = x; then

# ToDo decide whether we want -DNDEBUG for optimization
  coin_add_cxxflags=
  coin_opt_cxxflags=
  coin_dbg_cxxflags=
  coin_warn_cxxflags=

  if test "$GXX" = "yes"; then
    case "$CXX" in
      icpc* | */icpc*)
        ;;
      *)
# ToDo decide about unroll-loops
        coin_opt_cxxflags="-O3"
        coin_add_cxxflags="-pipe"
        coin_dbg_cxxflags="-g -O0"
        coin_warn_cxxflags="-Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long"
    esac
  fi

# Note that we do not need to cover GCC in the following tests.

  if test -z "$coin_opt_cxxflags"; then
    case $build in
      *-cygwin* | *-mingw*)
        case "$CXX" in
          clang* ) ;;
          cl* | */cl* | CL* | */CL*)
            # The MT and MTd options are mutually exclusive
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
               coin_opt_cxxflags='-MD -O2'
               coin_dbg_cxxflags='-MDd'
            else
               coin_opt_cxxflags='-MT -O2'
               coin_dbg_cxxflags='-MTd'
            fi
            coin_add_cxxflags='-nologo -EHsc -GR -wd4996 -D_CRT_SECURE_NO_DEPRECATE'
            ;;
          icl* | */icl* | ICL* | */ICL*)
          # The MT and MTd options are mutually exclusive
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
              coin_opt_cxxflags='-MD -Ox'
              coin_dbg_cxxflags='-MDd -debug'
            else
              coin_opt_cxxflags='-MT -Ox'
              coin_dbg_cxxflags='-MTd -debug'
            fi
            coin_add_cxxflags='-nologo -EHsc -GR -D_CRT_SECURE_NO_DEPRECATE'
            ;;
        esac
        ;;
      *-linux-*)
        case "$CXX" in
          icpc* | */icpc*)
            coin_opt_cxxflags="-O3 -ip -mp1"
            coin_add_cxxflags=""
            coin_dbg_cxxflags="-g"
            # Check if -i_dynamic is necessary (for new glibc library)
            CXXFLAGS=
            AC_TRY_LINK(,[int i=0; i++;],[],
                        [coin_add_cxxflags="-i_dynamic $coin_add_cxxflags"])
            ;;
          pgCC* | */pgCC*)
            coin_opt_cxxflags="-fast"
            coin_add_cxxflags="-Kieee -pc 64"
            coin_dbg_cxxflags="-g"
            ;;
        esac
        ;;
      *-ibm-*)
        case "$CXX" in
          xlC* | */xlC* | mpxlC* | */mpxlC*)
            coin_opt_cxxflags="-O -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
            coin_add_cxxflags="-bmaxdata:0x80000000 -qrtti=dyna -qsuppress=1500-036 -qsuppress=1500-029 -qsourcetype=c++"
            coin_dbg_cxxflags="-g"
            ;;
        esac
        ;;
      *-hp-*)
        case "$CXX" in
          aCC* | */aCC* )
            coin_opt_cxxflags="-O"
            coin_add_cxxflags="-AA"
            coin_dbg_cxxflags="-g"
            ;;
        esac
        ;;
      *-*-solaris*)
          coin_opt_cxxflags="-O4"
          coin_dbg_cxxflags="-g"
        ;;
    esac
  fi

# Generic flag settings. If these don't work, add a case above.

  if test "$ac_cv_prog_cxx_g" = yes && test -z "$coin_dbg_cxxflags" ; then
    coin_dbg_cxxflags="-g"
  fi

  if test -z "$coin_opt_cxxflags"; then
    # Try if -O option works if nothing else is set
    CXXFLAGS=-O
    AC_TRY_LINK([],[int i=0; i++;],[coin_opt_cxxflags="-O"])
  fi

  # if PM doesn't want the warning messages, take them out
  if test x"$coin_skip_warn_cxxflags" = xyes; then
    coin_warn_cxxflags=
  fi

# Do final setup of flags based on values determined above.

  if test x${DBG_CXXFLAGS+set} != xset; then
    DBG_CXXFLAGS="$coin_dbg_cxxflags $coin_add_cxxflags $coin_warn_cxxflags"
  fi
  if test x${OPT_CXXFLAGS+set} != xset; then
    OPT_CXXFLAGS="$coin_opt_cxxflags $coin_add_cxxflags -DNDEBUG $coin_warn_cxxflags"
  fi

  DBG_CXXFLAGS="$DBG_CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"
  OPT_CXXFLAGS="$OPT_CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"

  if test "$coin_debug_compile" = "true"; then
    CXXFLAGS="$DBG_CXXFLAGS"
  else
    CXXFLAGS="$OPT_CXXFLAGS"
  fi

# Handle the case where CXXFLAGS was set externally.
else
  CXXFLAGS="$CXXFLAGS $ADD_CXXFLAGS $CXXDEFS"
  if test x${DBG_CXXFLAGS+set} != xset; then
    DBG_CXXFLAGS="$CXXFLAGS"
  fi
  if test x${OPT_CXXFLAGS+set} != xset; then
    OPT_CXXFLAGS="$CXXFLAGS"
  fi
fi

# add -DPROJECT_BUILD to signal compiler preprocessor which config header file to include
if test x$COIN_PRJCT != x; then
  CXXFLAGS="$CXXFLAGS -D${COIN_PRJCT}_BUILD"
fi

# Try if CXXFLAGS works
save_CXXFLAGS="$CXXFLAGS"
AC_TRY_LINK([],[int i=0; i++;],[],[CXXFLAGS=])
if test -z "$CXXFLAGS"; then
  AC_MSG_WARN([The flags CXXFLAGS="$save_CXXFLAGS" do not work.  I will now just try '-O', but you might want to set CXXFLAGS manually.])
  CXXFLAGS='-O'
  AC_TRY_LINK([],[int i=0; i++;],[],[CXXFLAGS=])
  if test -z "$CXXFLAGS"; then
    AC_MSG_WARN([This value for CXXFLAGS does not work.  I will continue with empty CXXFLAGS, but you might want to set CXXFLAGS manually.])
  fi
fi

AC_MSG_NOTICE([C++ compiler options are: $CXXFLAGS])

AC_ARG_VAR(MPICXX,[C++ MPI Compiler])
if test x"$MPICXX" = x; then :; else
  AC_MSG_NOTICE([Will use MPI C++ compiler $MPICXX])
  CXX="$MPICXX"
fi

# correct the LD variable in a build with MS or Intel-windows compiler
case "$CXX" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
    LD=link
    ;;
esac

AC_LANG_POP(C++)
]) # AC_COIN_PROG_CXX


###########################################################################
#                             COIN_CXXLIBS                                #
###########################################################################

# Determine the C++ runtime libraries required for linking a C++ library
# with a Fortran or C compiler.  The result is available in CXXLIBS.

AC_DEFUN([AC_COIN_CXXLIBS],
[AC_REQUIRE([AC_PROG_CXX])dnl
AC_LANG_PUSH(C++)
AC_ARG_VAR(CXXLIBS,[Libraries necessary for linking C++ code with Fortran compiler])
if test -z "$CXXLIBS"; then
  if test "$GXX" = "yes"; then
    case "$CXX" in
      icpc* | */icpc*)
        CXXLIBS="-lstdc++"
        ;;
      *)
        # clang uses libc++ as the default standard C++ library, not libstdc++
        # this test is supposed to recognize whether the compiler is clang
        # 
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ciso646>]], [[
#ifndef _LIBCPP_VERSION
       choke me
#endif
          ]])],
          [CXXLIBS="-lc++"],
          [CXXLIBS="-lstdc++ -lm"])
        ;;
    esac
  else
    case $build in
     *-mingw32 | *-cygwin* )
      case "$CXX" in
      clang* ) ;;
      cl* | */cl* | CL* | */CL*)
        CXXLIBS=nothing;;
      esac;;
     *-linux-*)
      case "$CXX" in
      icpc* | */icpc*)
        CXXLIBS="-lstdc++"
             ;;
      pgCC* | */pgCC*)
        CXXLIBS="-lstd -lC -lc"
             ;;
      esac;;
    *-ibm-*)
      CXXLIBS="-lC -lc"
      ;;
    *-hp-*)
      CXXLIBS="-L/opt/aCC/lib -l++ -lstd_v2 -lCsup_v2 -lm -lcl -lc"
      ;;
    *-*-solaris*)
      CXXLIBS="-lCstd -lCrun"
    esac
  fi
fi
if test -z "$CXXLIBS"; then
  AC_MSG_WARN([Could not automatically determine CXXLIBS (C++ link libraries; necessary if main program is in Fortran or C).])
else
  AC_MSG_NOTICE([Assuming that CXXLIBS is \"$CXXLIBS\".])
fi
if test x"$CXXLIBS" = xnothing; then
  CXXLIBS=
fi
AC_LANG_POP(C++)
]) # AC_COIN_CXXLIBS

###########################################################################
#                           COIN_CHECK_HEADER                             #
###########################################################################

# This macro checks for a header file, but it does so without the
# standard header.  This avoids warning messages like:
#
# configure: WARNING: dlfcn.h: present but cannot be compiled
# configure: WARNING: dlfcn.h:     check for missing prerequisite headers?
# configure: WARNING: dlfcn.h: see the Autoconf documentation
# configure: WARNING: dlfcn.h:     section "Present But Cannot Be Compiled"
# configure: WARNING: dlfcn.h: proceeding with the preprocessor's result
# configure: WARNING: dlfcn.h: in the future, the compiler will take precedence

# My guess that the problem lay with CPPFLAGS seems to be correct. With this
# macro reduced to a direct call to AC_CHECK_HEADERS, there are no warnings
# now that CPPFLAGS contains -mno-cygwin when it needs it. -- lh, 061214 --

# AW 070609: I restored the previous version, since otherwise the warnings
# still pop up for the cl compiler

AC_DEFUN([AC_COIN_CHECK_HEADER],
[#if test x"$4" = x; then
#  hdr="#include <$1>"
#else
#  hdr="$4"
#fi
#AC_CHECK_HEADERS([$1],[$2],[$3],[$hdr])
AC_CHECK_HEADERS([$1],[$2],[$3],[$4])
]) # AC_COIN_CHECK_HEADER

###########################################################################
#                       COIN_CHECK_CXX_CHEADER                             #
###########################################################################

# This macro checks for C header files that are used from C++.  For a give
# stub (e.g., math), it first checks if the C++ library (cmath) is available.
# If it is, it defines HAVE_CMATH (or whatever the stub is).  If it is not
# available, it checks for the old C head (math.h) and defines HAVE_MATH_H
# if that one exists.

AC_DEFUN([AC_COIN_CHECK_CXX_CHEADER],
[AC_LANG_PUSH(C++)
AC_COIN_CHECK_HEADER([c$1],[$2],[$3],[$4])
if test "$ac_cv_header_c$1" != "yes"; then
  AC_COIN_CHECK_HEADER([$1.h],[$2],[$3],[$4])
fi
AC_LANG_POP(C++)
]) # AC_COIN_CHECK_CXX_CHEADER

###########################################################################
#                             COIN_PROG_CC                                #
###########################################################################

# Find the compile command by running AC_PROG_CC (with compiler names
# for different operating systems) and put it into CC (unless it was
# given my the user), and find an appropriate value for CFLAGS.  It is
# possible to provide additional -D flags in the variable CDEFS.

AC_DEFUN([AC_COIN_PROG_CC_HEAD],
[

# For consistency, we set the C compiler to the same value of the C++
# compiler, if the C++ is set, but the C compiler isn't (only for CXX=cl)
if test x"$CXX" != x; then
  case "$CXX" in
    clang* ) ;;
    cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
      if test x"$CC" = x; then
        CC="$CXX"
        AC_MSG_WARN([C++ compiler name provided as $CXX, but CC is unset. Setting CC to $CXX])
      fi
      ;;
  esac
fi

AC_ARG_VAR(CDEFS,[Additional -D flags to be used when compiling C code.])
AC_ARG_VAR(ADD_CFLAGS,[Additional C compiler options])
AC_ARG_VAR(DBG_CFLAGS,[Debug C compiler options])
AC_ARG_VAR(OPT_CFLAGS,[Optimize C compiler options])

coin_has_cc=yes

save_cflags="$CFLAGS"

# For *-*-solaris*, promote Studio/Workshop cc compiler to front of list.
# Depending on the user's PATH, when Studio/Workshop cc is not present we may
# find /usr/ucb/cc, which is almost certainly not a good choice for the C
# compiler. In this case, put cc after gcc.

case $build in
  *-cygwin* | *-mingw*)
  	     if test "$enable_msvc" = yes ; then
	       comps="icl cl gcc"
	     else
	       comps="gcc icl cl"
	     fi ;;
  *-*-solaris*)
	     AC_CHECK_PROG(sol_cc_compiler,cc,cc,[],[],/usr/ucb/cc)
	     if test "$sol_cc_compiler" = "cc" ; then
	       comps="cc xlc gcc pgcc icc"
	     else
	       comps="xlc gcc pgcc icc cc"
	     fi
	     ;;
  *-*-darwin*) comps="clang gcc cc" ;;
  *-linux-gnu*) comps="gcc cc pgcc icc xlc" ;;
  *-linux-*) comps="xlc gcc cc pgcc icc" ;;
  *)         comps="xlc_r xlc cc gcc pgcc icc" ;;
esac

# We delete the cached value, since the test might not have been
# performed with our choice of compilers earlier
$as_unset ac_cv_prog_CC || test "${ac_cv_prog_CC+set}" != set || { ac_cv_prog_CC=; export ac_cv_prog_CC; }
# AC_MSG_NOTICE([C compiler candidates: $comps])
AC_PROG_CC([$comps])
if test -z "$CC" ; then
  AC_MSG_ERROR([Failed to find a C compiler!])
fi
])
AC_DEFUN([AC_COIN_PROG_CC],
[AC_REQUIRE([AC_COIN_ENABLE_MSVC])
dnl Separate the head of this macro to AC_COIN_PROG_CC_HEAD such that it
dnl controls the invocation of AC_PROG_CC instead of the AC_TRY_LINK below.
AC_REQUIRE([AC_COIN_PROG_CC_HEAD])
AC_LANG_PUSH(C)
# Autoconf incorrectly concludes that cl recognises -g. It doesn't.
case "$CC" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* )
    if test "$ac_cv_prog_cc_g" = yes ; then
      ac_cv_prog_cc_g=no
      AC_MSG_NOTICE([Overruling autoconf; cl does not recognise -g.])
    fi ;;
  * )
    if test x"$CYGPATH_W" = x ; then
      CYGPATH_W=echo
    fi
    ;;
esac
CFLAGS="$save_cflags"

# add automake conditional so we can recognize cl compiler in makefile
coin_cc_is_cl=false
case "$CC" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
    coin_cc_is_cl=true
    ;;
esac
AM_CONDITIONAL(COIN_CC_IS_CL, [test $coin_cc_is_cl = true])

# Check if a project specific CFLAGS variable has been set
if test x$COIN_PRJCT != x; then
  eval coin_tmp=\${${COIN_PRJCT}_CFLAGS+set}
  if test x$coin_tmp = xset; then
    eval CFLAGS=\${${COIN_PRJCT}_CFLAGS}
  fi
fi

if test x"$CFLAGS" = x; then

  coin_add_cflags=
  coin_opt_cflags=
  coin_dbg_cflags=
  coin_warn_cflags=

  if test "$GCC" = "yes"; then
    case "$CC" in
      icc* | */icc*)
        ;;
      *)
        coin_opt_cflags="-O3"
        coin_add_cflags="-pipe"
        coin_dbg_cflags="-g -O0"
        coin_warn_cflags="-Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall -Wno-unknown-pragmas -Wno-long-long"
    esac
  fi
  if test -z "$coin_opt_cflags"; then
    case $build in
      *-cygwin* | *-mingw*)
        case "$CC" in
          clang* ) ;;
          cl* | */cl* | CL* | */CL*)
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
              coin_opt_cflags='-MD -O2'
              coin_dbg_cflags='-MDd'
            else
              coin_opt_cflags='-MT -O2'
              coin_dbg_cflags='-MTd'
            fi
            coin_add_cflags='-nologo -wd4996 -D_CRT_SECURE_NO_DEPRECATE'
            ;;
          icl* | */icl* | ICL* | */ICL*)
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
              coin_opt_cflags='-MD -Ox'
              coin_dbg_cflags='-MDd -debug'
            else
              coin_opt_cflags='-MT -Ox'
              coin_dbg_cflags='-MTd -debug'
            fi
            coin_add_cflags='-nologo -D_CRT_SECURE_NO_DEPRECATE'
            ;;
        esac
        ;;
      *-linux-*)
        case "$CC" in
          icc* | */icc*)
            coin_opt_cflags="-O3 -ip -mp1"
            coin_add_cflags=""
            coin_dbg_cflags="-g"
            # Check if -i_dynamic is necessary (for new glibc library)
            CFLAGS=
            AC_TRY_LINK([],[int i=0; i++;],[],
                        [coin_add_cflags="-i_dynamic $coin_add_cflags"])
            ;;
          pgcc* | */pgcc*)
            coin_opt_cflags="-fast"
            coin_add_cflags="-Kieee -pc 64"
            coin_dbg_cflags="-g"
            ;;
        esac
        ;;
      *-ibm-*)
        case "$CC" in
          xlc* | */xlc* | mpxlc* | */mpxlc*)
            coin_opt_cflags="-O -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
            coin_add_cflags="-bmaxdata:0x80000000 -qsuppress=1500-036 -qsuppress=1500-029"
            coin_dbg_cflags="-g"
          ;;
        esac
        ;;
      *-hp-*)
        coin_opt_cflags="-O"
        coin_add_cflags="-Ae"
        coin_dbg_cflags="-g"
        ;;
      *-*-solaris*)
        coin_opt_cflags="-xO4"
        coin_dbg_cflags="-g"
        ;;
      *-sgi-*)
        coin_opt_cflags="-O -OPT:Olimit=0"
        coin_dbg_cflags="-g"
        ;;
    esac
  fi

  if test "$ac_cv_prog_cc_g" = yes && test -z "$coin_dbg_cflags" ; then
    coin_dbg_cflags="-g"
  fi

  if test -z "$coin_opt_cflags"; then
    # Try if -O option works if nothing else is set
    CFLAGS="-O"
    AC_TRY_LINK([],[int i=0; i++;],[coin_opt_cflags="-O"])
  fi

  # if PM doesn't want the warning messages, take them out
  if test x"$coin_skip_warn_cflags" = xyes; then
    coin_warn_cflags=
  fi

  if test x${DBG_CFLAGS+set} != xset; then
    DBG_CFLAGS="$coin_dbg_cflags $coin_add_cflags $coin_warn_cflags"
  fi
  if test x${OPT_CFLAGS+set} != xset; then
    OPT_CFLAGS="$coin_opt_cflags $coin_add_cflags -DNDEBUG $coin_warn_cflags"
  fi

  DBG_CFLAGS="$DBG_CFLAGS $ADD_CFLAGS $CDEFS"
  OPT_CFLAGS="$OPT_CFLAGS $ADD_CFLAGS $CDEFS"

  if test "$coin_debug_compile" = "true"; then
    CFLAGS="$DBG_CFLAGS"
  else
    CFLAGS="$OPT_CFLAGS"
  fi
else
  CFLAGS="$CFLAGS $ADD_CFLAGS $CDEFS"
  if test x${DBG_CFLAGS+set} != xset; then
    DBG_CFLAGS="$CFLAGS"
  fi
  if test x${OPT_CFLAGS+set} != xset; then
    OPT_CFLAGS="$CFLAGS"
  fi
fi

# add -DPROJECT_BUILD to signal compiler preprocessor which config header file to include
if test x$COIN_PRJCT != x; then
  CFLAGS="$CFLAGS -D${COIN_PRJCT}_BUILD"
fi

# Try if CFLAGS works
save_CFLAGS="$CFLAGS"
AC_TRY_LINK([],[int i=0; i++;],[],[CFLAGS=])
if test -z "$CFLAGS"; then
  AC_MSG_WARN([The value CFLAGS="$save_CFLAGS" do not work.  I will now just try '-O', but you might want to set CFLAGS manually.])
  CFLAGS='-O'
  AC_TRY_LINK([],[int i=0; i++;],[],[CFLAGS=])
  if test -z "$CFLAGS"; then
    AC_MSG_WARN([This value for CFLAGS does not work.  I will continue with empty CFLAGS, but you might want to set CFLAGS manually.])
  fi
fi

AC_MSG_NOTICE([C compiler options are: $CFLAGS])

AC_ARG_VAR(MPICC,[C MPI Compiler])
if test x"$MPICC" = x; then :; else
  AC_MSG_NOTICE([Will use MPI C compiler $MPICC])
  CC="$MPICC"
fi

# Correct the LD variable if we are using the MS or Intel-windows compiler
case "$CC" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
    LD=link
    ;;
esac

AC_LANG_POP(C)
]) # AC_COIN_PROG_CC

###########################################################################
#                             COIN_PROG_F77                               #
###########################################################################

# Find the compile command by running AC_PROG_F77 (with compiler names
# for different operating systems) and put it into F77 (unless it was
# given by the user), and find an appropriate value for FFLAGS

AC_DEFUN([AC_COIN_PROG_F77],
[AC_REQUIRE([AC_COIN_ENABLE_MSVC])
AC_REQUIRE([AC_COIN_PROG_CC])
AC_REQUIRE([AC_COIN_F77_COMPS])
AC_LANG_PUSH([Fortran 77])

AC_ARG_VAR(ADD_FFLAGS,[Additional Fortran compiler options])
AC_ARG_VAR(DBG_FFLAGS,[Debug Fortran compiler options])
AC_ARG_VAR(OPT_FFLAGS,[Optimize Fortran compiler options])

coin_has_f77=yes

save_fflags="$FFLAGS"

# We delete the cached value, since the test might not have been
# performed with our choice of compilers earlier
$as_unset ac_cv_prog_F77 || test "${ac_cv_prog_F77+set}" != set || { ac_cv_prog_F77=; export ac_cv_prog_F77; }

# This is a real belt-and-suspenders approach. AC_COIN_FIND_F77 will use
# coin_f77_comps to see if there's a program that matches one of the names.
# If there's no such program, F77 = unavailable. If we match the name,
# feed AC_PROG_F77 the same search list, just to be sure it's a functioning
# compiler.
# AC_MSG_NOTICE([Fortran compiler candidates: $coin_f77_comps])
AC_COIN_FIND_F77
if test "$F77" != "unavailable" ; then
  AC_PROG_F77($coin_f77_comps)
else
  AC_MSG_WARN([Failed to find a Fortran compiler!])
fi

FFLAGS="$save_fflags"

# Check if a project specific FFLAGS variable has been set
if test x$COIN_PRJCT != x; then
  eval coin_tmp=\${${COIN_PRJCT}_FFLAGS+set}
  if test x$coin_tmp = xset; then
    eval FFLAGS=\${${COIN_PRJCT}_FFLAGS}
  fi
fi

if test "$F77" != "unavailable" && test x"$FFLAGS" = x ; then

  coin_add_fflags=
  coin_opt_fflags=
  coin_dbg_fflags=
  coin_warn_fflags=

  if test "$G77" = "yes"; then
    coin_opt_fflags="-O3"
    coin_add_fflags="-pipe"
    coin_dbg_fflags="-g -O0"
  else
    case $build in
      *-cygwin* | *-mingw*)
        case $F77 in
          ifort* | */ifort* | IFORT* | */IFORT* )
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
              coin_opt_fflags='-MD -O3'
              coin_dbg_fflags='-MDd -debug'
            else
              coin_opt_fflags='-MT -O3'
              coin_dbg_fflags='-MTd -debug'
            fi
            coin_add_fflags='-fpp -nologo'
          ;;
          compile_f2c*)
            if test "$coin_disable_shared" = yes || test "$enable_shared" = yes ; then
              coin_opt_fflags='-MD -O2'
              coin_dbg_fflags='-MDd'
            else
              coin_opt_fflags='-MT -O2'
              coin_dbg_fflags='-MTd'
            fi
            coin_add_fflags='-nologo -wd4996'
          ;;
        esac
        ;;
      *-linux-*)
        case $F77 in
          ifc* | */ifc* | ifort* | */ifort*)
            coin_opt_fflags="-O3 -ip"
            coin_add_fflags="-cm -w90 -w95"
            coin_dbg_fflags="-g -CA -CB -CS"
            # Check if -i_dynamic is necessary (for new glibc library)
            FFLAGS=
            AC_TRY_LINK(,[      write(*,*) 'Hello world'],[],
                        [coin_add_fflags="-i_dynamic $coin_add_fflags"])
            ;;
          pgf77* | */pgf77* | pgf90* | */pgf90*)
            coin_opt_fflags="-fast"
            coin_add_fflags="-Kieee -pc 64"
            coin_dbg_fflags="-g"
          ;;
        esac
        ;;
      *-ibm-*)
        case "$F77" in
          xlf* | */xlf* | mpxlf* | */mpxlf* )
            coin_opt_fflags="-O -qarch=auto -qcache=auto -qtune=auto -qmaxmem=-1"
            coin_add_fflags="-bmaxdata:0x80000000 -qsuppress=1500-036 -qsuppress=1500-029"
            coin_dbg_fflags="-g -C"
            ;;
        esac
        ;;
      *-hp-*)
        coin_opt_fflags="+O3"
        coin_add_fflags="+U77"
        coin_dbg_fflags="-C -g"
        ;;
      *-*-solaris*)
        coin_opt_fflags="-O4"
        coin_dbg_fflags="-g"
        ;;
      *-sgi-*)
        coin_opt_fflags="-O5 -OPT:Olimit=0"
        coin_dbg_fflags="-g"
        ;;
    esac
  fi

  if test "$ac_cv_prog_f77_g" = yes && test -z "$coin_dbg_fflags" ; then
    coin_dbg_fflags="-g"
  fi

  if test -z "$coin_opt_fflags"; then
    # Try if -O option works if nothing else is set
    FFLAGS=-O
    AC_TRY_LINK(,[      integer i], [coin_opt_fflags="-O"])
  fi

  # if PM doesn't want the warning messages, take them out
  if test x"$coin_skip_warn_fflags" = xyes; then
    coin_warn_fflags=
  fi

  if test x${DBG_FFLAGS+set} != xset; then
    DBG_FFLAGS="$coin_dbg_fflags $coin_add_fflags $coin_warn_fflags"
  fi
  if test x${OPT_FFLAGS+set} != xset; then
    OPT_FFLAGS="$coin_opt_fflags $coin_add_fflags $coin_warn_fflags"
  fi

  DBG_FFLAGS="$DBG_FFLAGS $ADD_FFLAGS"
  OPT_FFLAGS="$OPT_FFLAGS $ADD_FFLAGS"

  if test "$coin_debug_compile" = "true"; then
    FFLAGS="$DBG_FFLAGS"
  else
    FFLAGS="$OPT_FFLAGS"
  fi
else
  FFLAGS="$FFLAGS $ADD_FFLAGS"
  if test x${DBG_FFLAGS+set} != xset; then
    DBG_FFLAGS="$FFLAGS"
  fi
  if test x${OPT_FFLAGS+set} != xset; then
    OPT_FFLAGS="$FFLAGS"
  fi
fi

# Try if FFLAGS works
if test "$F77" != "unavailable" ; then
  orig_FFLAGS="FFLAGS"
  AC_TRY_LINK(,[      integer i],[],[FFLAGS=])
  if test -z "$FFLAGS"; then
    AC_MSG_WARN([The flags FFLAGS="$orig_FFLAGS" do not work.  I will now just try '-O', but you might want to set FFLAGS manually.])
    FFLAGS='-O'
    AC_TRY_LINK(,[      integer i],[],[FFLAGS=])
    if test -z "$FFLAGS"; then
      AC_MSG_WARN([The flags FFLAGS=-O do not work. I will continue with empty FFLAGS, but you might want to set FFLAGS manually.])
    fi
  fi
fi

AC_MSG_NOTICE([Fortran compiler options are: $FFLAGS])

AC_ARG_VAR(MPIF77,[Fortran MPI Compiler])
if test x"$MPIF77" = x; then :; else
  AC_MSG_NOTICE([Will use MPI Fortran compiler $MPIF77])
  F77="$MPIF77"
fi

# correct the LD variable if we use the intel fortran compiler in windows
case $build in
  *-cygwin* | *-mingw*)
    case "$F77" in
      ifort* | */ifort* | IFORT* | */IFORT*)
        LD=link
      ;;
    esac
  ;;
esac

AC_LANG_POP([Fortran 77])
]) # AC_COIN_PROG_F77

###########################################################################
#                           COIN_F77_WRAPPERS                             #
###########################################################################

# Calls autoconfs AC_F77_LIBRARY_LDFLAGS and does additional corrections to FLIBS.
# Then calls AC_F77_WRAPPERS to get Fortran namemangling scheme.
#
# To ensure that the FLIBS are determined and corrected before linking against
# Fortran compilers is attempted by other macros, we put it into an extra macro
# and call it via AC_REQUIRE. This way it seems to be called before the macros
# required by AC_F77_WRAPPERS.

AC_DEFUN([_AC_COIN_F77_LIBRARY_LDFLAGS],
[AC_BEFORE([AC_PROG_F77],[$0])dnl

# get FLIBS
AC_F77_LIBRARY_LDFLAGS
orig_FLIBS="$FLIBS"

# If FLIBS has been set by the user, we just restore its value here
if test x"$save_FLIBS" != x; then
  FLIBS="$save_FLIBS"
else
  # This is to correct a missing exclusion in autoconf 2.59
  if test x"$FLIBS" != x; then
    my_flibs=
    for flag in $FLIBS; do
      case $flag in
        -lcrt*.o) ;;
        -lcygwin) ;;
        -lgcc*)   ;;
               *) my_flibs="$my_flibs $flag" ;;
      esac
    done
    FLIBS="$my_flibs"
  fi

  case $build in
  # The following is a fix to define FLIBS for ifort on Windows
  # In its original version, it linked in libifcorert.lib or libifcorertd.lib on Windows/ifort explicitly.
  # However, this seem to create a dependency on libifcorert.dll (or libifcorertd.dll) in the executables.
  # This is seem to be unnecessary, libifcorert(d).lib has been removed from the link line.
  # Further, excluding libc.lib from the default libs seemed to be necessary only for VS < 8.
  # Since the corresponding flag seems to make more trouble than it avoids, it has been removed now.
     *-cygwin* | *-mingw*)
       case "$F77" in
#         ifort* | */ifort* | IFORT* | */IFORT*)
#           FLIBS="-link $LIBS /NODEFAULTLIB:libc.lib"
#           if "$coin_debug_compile" = true ; then
#             FLIBS="-link $LIBS /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib"
#           else
#             FLIBS="-link $LIBS /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmtd.lib"
#           fi
#           ;;
         compile_f2c*)
           FLIBS=`$F77 -FLIBS` ;;
       esac;;
     *-hp-*)
         FLIBS="$FLIBS -lm";;
     *-ibm-*)
         FLIBS=`echo $FLIBS | sed 's/-lc)/-lc/g'` ;;
     *-linux-*)
       case "$F77" in
         pgf77* | */pgf77* | pgf90* | */pgf90*)
# ask linker to go through the archives multiple times
# (the Fortran compiler seems to do that automatically...)
           FLIBS="-Wl,--start-group $FLIBS -Wl,--end-group" ;;
       esac
  esac
  ac_cv_f77_libs="$FLIBS"
fi

if test "x$orig_FLIBS" != "x$FLIBS" ; then
  AC_MSG_NOTICE([Corrected Fortran libraries: $FLIBS])
fi
]) # _AC_COIN_F77_LIBRARY_LDFLAGS

AC_DEFUN([AC_COIN_F77_WRAPPERS],
[AC_BEFORE([AC_COIN_PROG_F77],[$0])dnl
AC_REQUIRE([_AC_COIN_F77_LIBRARY_LDFLAGS])dnl

AC_LANG_PUSH([Fortran 77])
AC_F77_WRAPPERS
AC_LANG_POP([Fortran 77])

]) # AC_COIN_F77_WRAPPERS

###########################################################################
#                             COIN_FIND_F77                               #
###########################################################################

# Attempt to preempt autoconf by locating an appropriate F77 program. This
# macro will not trigger a fatal error if a suitable compiler cannot be
# found. It should be called before COIN_PROG_F77 or COIN_TRY_FLINK.

AC_DEFUN([AC_COIN_FIND_F77],
[AC_REQUIRE([AC_COIN_ENABLE_MSVC])
AC_REQUIRE([AC_COIN_F77_COMPS])
AC_MSG_NOTICE([Trying to determine Fortran compiler name])
AC_CHECK_TOOLS([F77],[$coin_f77_comps],[unavailable])
])

# Auxilliary macro to make sure both COIN_PROG_F77 and COIN_FIND_F77 use
# the same search lists for compiler names.
# For *-*-solaris*, promote Studio/Workshop compilers to front of list.
AC_DEFUN([AC_COIN_F77_COMPS],
[case $build in
  *-cygwin* | *-mingw*)
     if test "$enable_msvc" = yes ; then
       coin_f77_comps="ifort fl32 compile_f2c"
     else
       coin_f77_comps="gfortran ifort g95 g77 fl32 compile_f2c"
     fi ;;
  *-*-solaris*)
     coin_f77_comps="f95 f90 g95 f77 xlf_r fort77 gfortran g77 pgf90 pgf77 ifort ifc frt af77" ;;
  *-linux-gnu*)
     coin_f77_comps="gfortran ifort g95 fort77 f77 g77 pgf90 pgf77 ifc frt af77 xlf_r" ;;
  *) coin_f77_comps="xlf_r fort77 gfortran ifort g95 f77 g77 pgf90 pgf77 ifc frt af77" ;;
 esac
])

###########################################################################
#                          COIN_INIT_AUTOMAKE                             #
###########################################################################

# This macro calls the regular INIT_AUTOMAKE and MAINTAINER_MODE
# macros, and defines additional variables and makefile conditionals,
# that are used in the maintainer parts of the makfile.  It also
# checks if the correct versions of the autotools are used.
#
# This also defines the AC_SUBST variables:
# abs_source_dir     absolute path to source code for this package
# abs_bin_dir        absolute path to the directory where binaries are
#                    going to be installed (prefix/bin)
# abs_lib_dir        absolute path to the directory where libraries are
#                    going to be installed (prefix/lib)
# abs_include_dir    absolute path to the directory where the header files
#                    are installed (prefix/include)

AC_DEFUN([AC_COIN_INIT_AUTOMAKE],
[AC_REQUIRE([AC_PROG_EGREP])
AC_REQUIRE([AC_PROG_LN_S])

# AC_MSG_NOTICE([Beginning automake initialisation.])
# Stuff for automake
AM_INIT_AUTOMAKE
AM_MAINTAINER_MODE

coin_have_externals=no
if test "$enable_maintainer_mode" = yes; then

  # If maintainer mode is chosen, we make sure that the correct versions
  # of the tools are used, and that we know where libtool.m4 is (to
  # recreate acinclude.m4)

  AC_SUBST(LIBTOOLM4)
  LIBTOOLM4=
  # Normally, $HOME
  AUTOTOOLS_DFLT=$HOME

  AC_CACHE_CHECK([whether we are using the correct autotools],
                 [ac_cv_use_correct_autotools],
                 [ac_cv_use_correct_autotools=check])

  if test $ac_cv_use_correct_autotools = check; then
    ac_cv_use_correct_autotools=yes
    # Check if we have autoconf
    AC_CHECK_PROG([have_autoconf],[autoconf],[yes],[no])
    if test $have_autoconf = no; then
      AC_MSG_ERROR([You specified you want to use maintainer mode, but I cannot find autoconf in your path.])
    fi

    # Check whether autoconf is the correct version
    correct_version='2.59'
    grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
    AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of autoconf])
    autoconf --version > confauto.out 2>&1
    if $EGREP $grep_version confauto.out >/dev/null 2>&1; then
      AC_MSG_RESULT([yes])
    else
      rm -f confauto.out
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([You don't have the correct version of autoconf as the first one in your path.])
    fi
    rm -f confauto.out

    # Check if the executable autoconf is picked up from the correct location
    AC_MSG_CHECKING([whether autoconf is coming from the correct location])
    autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
    autoconf_dir=`cd $autoconf_dir; pwd`
    if test x$AUTOTOOLS_DIR = x; then
      want_dir=$AUTOTOOLS_DFLT/bin
    else
      want_dir=$AUTOTOOLS_DIR/bin
    fi
    if test $autoconf_dir = `cd $want_dir; pwd`; then
      AC_MSG_RESULT([yes])
    else
      rm -f confauto.out
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([The autoconf executable should be picked up from \$AUTOTOOLS_DFLT/bin or \$AUTOTOOLS_DIR/bin.])
    fi

    # Check if we have automake
    AC_CHECK_PROG([have_automake],[automake],[yes],[no])
    if test $have_automake = no; then
      AC_MSG_ERROR([You specified you want to use maintainer mode, but I cannot find automake in your path.])
    fi
  
    # Check whether automake is the correct version
    correct_version='1.9.6'
    grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
    AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of automake])
    automake --version > confauto.out 2>&1
    if $EGREP $grep_version confauto.out >/dev/null 2>&1; then
      AC_MSG_RESULT([yes])
    else
      rm -f confauto.out
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([You don't have the correct version of automake as the first one in your path.])
    fi
    rm -f confauto.out

    # Check if the executable automake is picked up from the correct location
    AC_MSG_CHECKING([whether automake is coming from the correct location])
    automake_dir=`which automake | sed -e 's=/automake=='`
    automake_dir=`cd $automake_dir; pwd`
    if test x$AUTOTOOLS_DIR = x; then
      want_dir=$AUTOTOOLS_DFLT/bin
    else
      want_dir=$AUTOTOOLS_DIR/bin
    fi
    if test $automake_dir = `cd $want_dir; pwd`; then
      AC_MSG_RESULT([yes])
    else
      rm -f confauto.out
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([The automake executable should be picked up from \$AUTOTOOLS_DFLT/bin or \$AUTOTOOLS_DIR/bin.])
    fi

    # Check if this is the correct version of libtool (with escaped dots)
    if test x$AUTOTOOLS_DIR = x; then
      want_dir=$AUTOTOOLS_DFLT/share
    else
      want_dir=$AUTOTOOLS_DIR/share
    fi
    correct_version='1.5.22'
    grep_version=`echo  $correct_version | sed -e 's/\\./\\\\\\./g'`
    AC_COIN_CHECK_FILE([$want_dir/libtool/ltmain.sh],
	               [have_ltmain=yes],
                       [have_ltmain=no])
    AC_MSG_CHECKING([whether we are using the correct version ($correct_version) of libtool.])
    if test $have_ltmain = yes; then
    if $EGREP $grep_version $want_dir/libtool/ltmain.sh >/dev/null 2>&1; then
        AC_MSG_RESULT([yes])
      else
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([You don't have the correct version of libtool.])
      fi
    else
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([I cannot find the ltmain.sh file.])
    fi
  fi

  # Check if we can find the libtool file
  if test x$AUTOTOOLS_DIR = x; then
    want_dir=$AUTOTOOLS_DFLT/share
  else
    want_dir=$AUTOTOOLS_DIR/share
  fi
  AC_COIN_CHECK_FILE([$want_dir/aclocal/libtool.m4],
                     [LIBTOOLM4="$want_dir/aclocal/libtool.m4"],
                     [AC_MSG_ERROR([I cannot find the libtool.m4 file.])])

  # Check if we have an Dependencies file
  if test -r $srcdir/Dependencies; then
    coin_have_externals=yes
  fi
  # Check if subversion is installed and understands https
  AC_CHECK_PROG([have_svn],[svn],[yes],[no])
  if test x$have_svn = xyes; then
    AC_CACHE_CHECK([whether svn understands https],
                   [ac_cv_svn_understands_https],
                   [svn --version > confauto.out 2>&1
                    if $EGREP https confauto.out >/dev/null 2>&1; then
                      ac_cv_svn_understands_https=yes
                    else
                      ac_cv_svn_understands_https=no
                      have_svn=no
                      ac_cv_prog_have_svn=no
                    fi
                    rm -f confauto.out])
  fi

  # Find the location of the BuildTools directory
  BUILDTOOLSDIR=
  if test -r $srcdir/BuildTools/coin.m4; then
    BUILDTOOLSDIR=$srcdir/BuildTools
  elif test -r $srcdir/../BuildTools/coin.m4; then
    BUILDTOOLSDIR=$srcdir/../BuildTools
  elif test -r $srcdir/../../BuildTools/coin.m4; then
    BUILDTOOLSDIR=$srcdir/../../BuildTools
  elif test -r $srcdir/../../../BuildTools/coin.m4; then
    BUILDTOOLSDIR=$srcdir/../../../BuildTools
  else
    AC_MSG_ERROR(Cannot find the BuildTools directory, better disable maintainer mode.)
  fi
  AC_SUBST(BUILDTOOLSDIR)
  
  # for running automake by make, we need to have Makemain.inc available at the place where it usually can be found during run_autotools
  if test "$BUILDTOOLSDIR" != "$srcdir/BuildTools" ; then
    $LN_S `cd $BUILDTOOLSDIR; pwd` "$srcdir/BuildTools"
  fi

  # The following variable is set to the name of the directory where
  # the autotool scripts are located
  AC_SUBST(AUX_DIR)
  AUX_DIR=$ac_aux_dir
fi

# helpful variable for the base directory of this package
abs_source_dir=`cd $srcdir; pwd`
AC_SUBST(abs_source_dir)

# Stuff for example Makefiles
if test x$prefix = xNONE; then
  full_prefix=$ac_default_prefix
else
  full_prefix=$prefix
fi

AC_SUBST(abs_lib_dir)
abs_lib_dir=$full_prefix/lib
AC_SUBST(abs_include_dir)
abs_include_dir=$full_prefix/include
AC_SUBST(abs_bin_dir)
abs_bin_dir=$full_prefix/bin

AM_CONDITIONAL(HAVE_EXTERNALS,
               test $coin_have_externals = yes && test x$have_svn = xyes)

# AC_MSG_NOTICE([End automake initialisation.])

]) # AC_COIN_INIT_AUTOMAKE

###########################################################################
#                          COIN_CREATE_LIBTOOL                            #
###########################################################################

# This does all the tests necessary to create the libtool script in the
# package base directory.  If this is used, then the COIN_INIT_AUTO_TOOLS
# test in the subdirectories will be able to skip the libtool tests and
# just use the one in the package base directory.

m4_define([AC_COIN_CREATE_LIBTOOL],
[AC_CANONICAL_BUILD

# Check if user wants to produce debugging code
AC_COIN_DEBUG_COMPILE

# Get the name of the C compiler and appropriate compiler options
AC_COIN_PROG_CC

# Get the name of the C++ compiler and appropriate compiler options
AC_COIN_PROG_CXX

# Get the name of the Fortran compiler and appropriate compiler options
AC_COIN_PROG_F77

# Initialize automake and libtool
# AC_MSG_NOTICE([Calling INIT_AUTO_TOOLS from CREATE_LIBTOOL.])
AC_COIN_INIT_AUTO_TOOLS
# AC_MSG_NOTICE([Finished INIT_AUTO_TOOLS from CREATE_LIBTOOL.])
])

###########################################################################
#                         COIN_INIT_AUTO_TOOLS                            #
###########################################################################

# Initialize the auto tools automake and libtool, with all
# modifications we want for COIN packages.
#
# RPATH_FLAGS        link flags for hardcoding path to shared objects

# This is a trick to have this code before AC_COIN_PROG_LIBTOOL
AC_DEFUN([AC_COIN_DISABLE_STATIC],
[
coin_disable_shared=no
# Test if force_shared has been set
if test "x$1" = xforce_shared; then
  if test x$enable_shared = xno; then
    AC_MSG_ERROR([Shared libraries are disabled by user, but this is not feasible with the given options])
  fi
  enable_shared=yes;
else
  case $build in
    *-cygwin* | *-mingw*)
      coin_disable_shared=yes
      if test x"$enable_shared" = xyes; then
        case "$CC" in
          clang* )
            AC_MSG_WARN([Building of DLLs not supported in this configuration.])
            ;;
          cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
            AC_MSG_NOTICE([Building of DLLs not supported in this configuration.])
            ;;
          *gcc*)
            if test x"$enable_dependency_linking" = xyes; then
              coin_disable_shared=no
            else
              AC_MSG_WARN([Dependency linking seems to be disabled, so shared libraries (DLLs) will not be built])
            fi
            ;;
          *)
            AC_MSG_WARN([Building of DLLs not supported in this configuration.])
            ;;
        esac
      fi
    ;;
    *-aix*)
      coin_disable_shared=yes
      platform=AIX
      if test x"$enable_shared" = xyes; then
        AC_MSG_WARN([Shared objects are not supported.])
      fi
    ;;
  esac
fi
if test x"$coin_disable_shared" = xyes; then
  if test x"$enable_shared" = xyes; then
    :
  else
    # we don't disable shared, because it was not selected anyway
    coin_disable_shared=no
  fi
  enable_shared=no
fi
# By default, we only want the shared objects to be compiled
AC_DISABLE_STATIC
])

m4_define([AC_COIN_INIT_AUTO_TOOLS],
[{AC_BEFORE([AC_COIN_PROG_CXX],[$0])
AC_BEFORE([AC_COIN_PROG_CC],[$0])
AC_BEFORE([AC_COIN_PROG_F77],[$0])

# START
AC_COIN_DISABLE_STATIC([$1])

# Initialize automake
AC_COIN_INIT_AUTOMAKE

LIBTOOL=
if test -f ../libtool; then
  coin_config_dir=..
  LIBTOOL='$(SHELL) $(top_builddir)/../libtool'
fi
if test "x$LIBTOOL" = x; then
  if test -f ../../libtool; then
    coin_config_dir=../..
    LIBTOOL='$(SHELL) $(top_builddir)/../../libtool'
  fi
fi

if test "x$LIBTOOL" = x; then
# AC_MSG_NOTICE([Creating libtool script (calling COIN_PROG_LIBTOOL).])
  # Stuff for libtool
  AC_COIN_PROG_LIBTOOL
# AC_MSG_NOTICE([Finished COIN_PROG_LIBTOOL.])
  # set RPATH_FLAGS to the compiler link flags required to hardcode location
  # of the shared objects
  AC_COIN_RPATH_FLAGS([$abs_lib_dir])

else

  AC_MSG_NOTICE([Using libtool script in directory $coin_config_dir])
  # get all missing information from the config.log file 

  # output variables and defines
  as_save_IFS=$IFS
  IFS='
'
  for oneline in `cat $coin_config_dir/config.status`; do
    case "$oneline" in
         # First some automake conditionals
      s,@am__fastdep* | s,@AR@* | s,@CPP@*  | s,@CPPFLAGS@* | s,@CXXCPP@*  | \
      s,@RANLIB@* | s,@STRIP@* | s,@ac_ct_AR@* | s,@ac_ct_RANLIB@* | \
      s,@ac_ct_STRIP@* | s,@host* | s,@LN_S@* | s,@RPATH_FLAGS@* | \
      s,@ac_c_preproc_warn_flag@* |  s,@ac_cxx_preproc_warn_flag@* ) 
        command=`echo $oneline | sed -e 's/^s,@//' -e 's/@,/="/' -e 's/,;t t/"/'`
#        echo "$command"
        eval "$command"
        ;;
      s,@DEFS@* )
        command=`echo $oneline | sed -e 's/^s,@DEFS@,/defsline="/' -e 's/,;t t/"/'`
#        echo "$command"
        eval "$command"
        ;;
    esac
  done
  IFS=$as_save_IFS

  # And some defines (assuming here that the packages base dir
  # doesn't have a config.h file
  for word in $defsline; do
#    echo word $word 
    case $word in
      -DHAVE_@<:@A-Z_@:>@*_H=1 | -DSTDC_HEADERS=1 )
        i=`echo $word | sed -e 's/-D/#define /' -e 's/=/ /'`
#        echo dd $i
        echo $i >>confdefs.h
        ;;
    esac
  done
fi

# AC_MSG_NOTICE([End of INIT_AUTO_TOOLS.])

AC_ARG_ENABLE([dependency-linking],
  [AC_HELP_STRING([--disable-dependency-linking],
                  [disable linking library dependencies into shared libraries])],
  [dependency_linking="$enableval"],
  [dependency_linking=auto])

if test "$dependency_linking" = auto; then
  # On Cygwin and AIX, building DLLs doesn't work
  dependency_linking=no
  if test x"$coin_disable_shared" = xno; then
    case $build in
      *-cygwin* | *-mingw*)
        case "$CC" in
          clang* )
            dependency_linking=yes
            ;;
          cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
            dependency_linking=no
            ;;
          *gcc*)
            dependency_linking=yes
            ;;
          *)
            dependency_linking=yes
            ;;
        esac
        ;;
      *)
        dependency_linking=yes
        ;;
    esac
  fi
fi

if test "$dependency_linking" = yes ;
then
  LT_LDFLAGS="-no-undefined"
else
  LT_LDFLAGS=
fi

AM_CONDITIONAL(DEPENDENCY_LINKING, [test "$dependency_linking" = yes])

# Check if we want to set the library version
AC_MSG_CHECKING([if library version is set])
if test x"$coin_libversion" != x; then
  LT_LDFLAGS="$LT_LDFLAGS -version-info $coin_libversion"
  AC_MSG_RESULT([$coin_libversion])
else
  AC_MSG_RESULT([no])
fi

AC_SUBST(LT_LDFLAGS)

#END
}])

###########################################################################
#                      COIN_PATCH_LIBTOOL_CYGWIN                          #
###########################################################################

# Patches to libtool for cygwin. Lots for cl, a few for GCC.
# For cl:
# - cygpath is not correctly quoted in fix_srcfile_path
# - paths generated for .lib files is not run through cygpath -w


AC_DEFUN([AC_COIN_PATCH_LIBTOOL_CYGWIN],
[ case "$CXX" in
    clang* )
      # we assume that libtool patches for CLANG are the same as for GNU compiler - correct???
      AC_MSG_NOTICE(Applying patches to libtool for CLANG compiler)
      sed -e 's|fix_srcfile_path=\"`cygpath -w \"\$srcfile\"`\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
	  -e 's|"lib /OUT:\\$oldlib\\$oldobjs\\$old_deplibs"|"\\$AR \\$AR_FLAGS \\$oldlib\\$oldobjs\\$old_deplibs~\\$RANLIB \\$oldlib"|' \
	  -e 's|libext="lib"|libext="a"|' \
      libtool > conftest.bla
      ;;
    cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*) 
      AC_MSG_NOTICE(Applying patches to libtool for cl compiler)
      sed -e 's|fix_srcfile_path=\"`cygpath -w \"\$srcfile\"`\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
	  -e 's|fix_srcfile_path=\"\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
	  -e 's%compile_deplibs=\"\$dir/\$old_library \$compile_deplibs\"%compile_deplibs="'\`"$CYGPATH_W"' \$dir/\$old_library | sed -e '"'"'sY\\\\\\\\Y/Yg'"'"\`' \$compile_deplibs\"'% \
	  -e 's%compile_deplibs=\"\$dir/\$linklib \$compile_deplibs\"%compile_deplibs="'\`"$CYGPATH_W"' \$dir/\$linklib | sed -e '"'"'sY\\\\\\\\Y/Yg'"'"\`' \$compile_deplibs\"'% \
	  -e 's%lib /OUT:%lib -OUT:%' \
	  -e "s%cygpath -w%$CYGPATH_W%" \
	  -e 's%$AR x \\$f_ex_an_ar_oldlib%bla=\\$(lib -nologo -list \\$('"$CYGPATH_W \$[]1"') '"$mydos2unix"' | xargs echo); echo \\$bla; for i in \\$bla; do lib -nologo -extract:\\$i \\$('"$CYGPATH_W \$[]1"'); done%' \
	  -e 's%$AR t "$f_ex_an_ar_oldlib"%lib -nologo -list \$('"$CYGPATH_W \$[]1"') '"$mydos2unix"'%' \
	  -e 's%f_ex_an_ar_oldlib="\($?*1*\)"%f_ex_an_ar_oldlib='\`"$CYGPATH_W"' \1`%' \ 
	  -e 's%^archive_cmds=.*%archive_cmds="\\$CC -o \\$lib \\$libobjs \\$compiler_flags \\\\\\`echo \\\\\\"\\$deplibs\\\\\\" | \\$SED -e '"\'"'s/ -lc\\$//'"\'"'\\\\\\` -link -dll~linknames="%' \
	  -e 's%old_archive_cmds="lib -OUT:\\$oldlib\\$oldobjs\\$old_deplibs"%old_archive_cmds="if test -r \\$oldlib; then bla=\\"\\$oldlib\\"; else bla=; fi; lib -OUT:\\$oldlib \\\\\\$bla\\$oldobjs\\$old_deplibs"%' \
      libtool > conftest.bla
      ;;
    *)
      AC_MSG_NOTICE(Applying patches to libtool for GNU compiler)
      sed -e 's|fix_srcfile_path=\"`cygpath -w \"\$srcfile\"`\"|fix_srcfile_path=\"\\\`'"$CYGPATH_W"' \\\"\\$srcfile\\\"\\\`\"|' \
	  -e 's|"lib /OUT:\\$oldlib\\$oldobjs\\$old_deplibs"|"\\$AR \\$AR_FLAGS \\$oldlib\\$oldobjs\\$old_deplibs~\\$RANLIB \\$oldlib"|' \
	  -e 's|libext="lib"|libext="a"|' \
      libtool > conftest.bla
      ;;
  esac
  mv conftest.bla libtool
  chmod 755 libtool
]) # COIN_PATCH_LIBTOOL_CYGWIN

###########################################################################
#                    COIN_PATCH_LIBTOOL_SOLARIS                           #
###########################################################################
# If we want to do a 64-bit build with GCC on Solaris, the system search
# libraries need to point to 64-bit subdirectories. If they do not already do
# that, fix them. This patch is evolving, as are GCC compilers.  GCC 4.2.1
# reports the correct search list, given the correct call. GCC 4.1.1 does not.
# `Correct call' means -m64 is specified. `Correct search list' seems to amount
# to prepending the list of 64-bit subdirectories to the 32-bit directories.
# Both SPARC and x86 have this issue, but a different hardware id string is
# required depending on the underlying CPU. The macro executes isainfo to get
# the string. This will fail, of course, if we're cross-compiling. The
# alternative is to fail on a regular basis each time a new CPU identifier is
# needed. This macro will also fail if the search list reported with
# -print-search-dirs differs between the C, C++, and Fortran compilers; each
# have their own setting in libtool.  If GCC reports the correct search list
# given the -m64 flag, the best solution is to define CC='gcc -m64', and
# similarly for CXX, F77, so that libtool will make the correct call.
###########################################################################
AC_DEFUN([AC_COIN_PATCH_LIBTOOL_SOLARIS],
[ if test "$GCC" = yes && \
     (echo $CXXFLAGS $CFLAGS $FFLAGS | $EGREP 'm64' >/dev/null 2>&1) ; then
    hdwisa=`isainfo | sed -e 's/\(@<:@^ @:>@*\) .*$/\1/'`
    if `$EGREP 'sys_lib_search_path_spec=' libtool | $EGREP -v $hdwisa >/dev/null 2>&1` ; then
      AC_MSG_NOTICE([Applying patches to libtool for 64-bit GCC compilation])
      fixlibtmp=`$CC -m64 -print-search-dirs | $EGREP '^libraries:'`
      fixlibtmp=`echo $fixlibtmp | sed -e 's/libraries: =//' -e 's/:/ /g'`
      if `echo "$fixlibtmp" | $EGREP -v $hdwisa  >/dev/null 2>&1` ; then
	# AC_MSG_NOTICE(Compensating for broken gcc)
	for lib in $fixlibtmp ; do
	  if test -d "${lib}${hdwisa}" ; then
	    syslibpath64="$syslibpath64 ${lib}${hdwisa}/"
	  fi
	done
	syslibpath64="${syslibpath64} ${fixlibtmp}"
      else
	syslibpath64="$fixlibtmp"
      fi
      sed -e 's|sys_lib_search_path_spec=".*"|sys_lib_search_path_spec="'"$syslibpath64"'"|' libtool > conftest.bla
      mv conftest.bla libtool
      chmod 755 libtool  
    fi
    # AC_MSG_NOTICE(Result is )
    # $EGREP 'sys_lib_search_path_spec=' libtool
  fi ])	# COIN_PATCH_LIBTOOL_SOLARIS

###########################################################################
#                           COIN_PROG_LIBTOOL                             #
###########################################################################

# Setup the libtool stuff together with any modifications to make it
# work on additional platforms

AC_DEFUN([AC_COIN_PROG_LIBTOOL],
[# No longer needed now that CPPFLAGS is correctly set -- lh, 061214 --
 # AC_REQUIRE([AC_COIN_DLFCN_H])

# NEW: If libtool exists in the directory higher up, we use that one
#      instead of creating a new one

# It turns out that the code for AC_PROG_LIBTOOL is somehow AC_REQUIRED
# out in front of this macro body. You'll notice that LIBTOOL is already
# defined here.  We'll have to count on this macro not being called if libtool
# already exists, or at least move the libtool fixes outside the conditional.
# AC_MSG_NOTICE([Entering coin_prog_libtool, LIBTOOL = "$LIBTOOL".])
# This test is therefore removed.  -- lh, 061214 --
# if test "x$LIBTOOL" = x; then

# AC_MSG_NOTICE([Calling PROG_LIBTOOL.])
  AC_PROG_LIBTOOL
# AC_MSG_NOTICE([Finished PROG_LIBTOOL.])
  AC_SUBST(ac_c_preproc_warn_flag)
  AC_SUBST(ac_cxx_preproc_warn_flag)

  AC_MSG_NOTICE([Build is "$build".])
  AC_CHECK_PROG([dos2unix], [dos2unix], [dos2unix])
  if test "$dos2unix" = dos2unix ; then
    mydos2unix="| dos2unix"
  fi
  case $build in
    *-mingw*)
      CYGPATH_W=echo
      ;;
  esac

  case $build in
    # Here we need to check if -m32 is specified.  If so, we need to correct
    # sys_lib_search_path_spec
    *-cygwin* | *-mingw*)
      AC_COIN_PATCH_LIBTOOL_CYGWIN
      ;;
    *x86_64-*)
      if test "$GCC" = yes && (echo $CXXFLAGS $CFLAGS $FFLAGS | $EGREP 'm32' >& /dev/null); then 
        AC_MSG_NOTICE(Applying patches to libtool for 32bit compilation)
        sed -e 's|sys_lib_search_path_spec=".*"|sys_lib_search_path_spec="/lib /usr/lib"|' libtool > conftest.bla
        mv conftest.bla libtool
        chmod 755 libtool  
      fi
      ;;

    *-solaris*)
      AC_COIN_PATCH_LIBTOOL_SOLARIS
      ;;
    # Cygwin. Ah, cygwin. Too big and ugly to inline; see the macro.
    *-darwin*)
      AC_MSG_NOTICE(Applying patches to libtool for Darwin)
      sed -e 's/verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"/verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"/' \
        -e 's/ -dynamiclib / -dynamiclib -single_module /g' \
      libtool > conftest.bla

      mv conftest.bla libtool
      chmod 755 libtool
      ;;
  esac
# This fi matches the commented `if test "x$LIBTOOL" = x;' up at the head of
# the macro. -- lh, 061214 --
# fi

# AC_MSG_NOTICE([End libtool initialisation.])
]) # AC_COIN_PROG_LIBTOOL

# This is a trick to force the check for the dlfcn header to be done before
# the checks for libtool
# No longer needed now that CPPFLAGS is correctly set.  -- lh, 061214 --
# ACDEFUN([AC_COIN_DLFCN_H],
# [AC_LANG_PUSH(C)
# AC_COIN_CHECK_HEADER([dlfcn.h])
# AC_LANG_POP(C)
# ]) # AC_COIN_DLFCN_H

###########################################################################
#                            COIN_RPATH_FLAGS                             #
###########################################################################

# This macro, in case shared objects are used, defines a variable
# RPATH_FLAGS that can be used by the linker to hardwire the library
# search path for the given directories.  This is useful for example
# Makefiles

AC_DEFUN([AC_COIN_RPATH_FLAGS],
[RPATH_FLAGS=

if test $enable_shared = yes; then
  case $build in
    *-linux-*)
      if test "$GXX" = "yes"; then
        RPATH_FLAGS=
        for dir in $1; do
          RPATH_FLAGS="$RPATH_FLAGS -Wl,--rpath -Wl,$dir"
        done
      fi ;;
    *-darwin*)
        RPATH_FLAGS=nothing ;;
    *-ibm-*)
      case "$CXX" in
      xlC* | */xlC* | mpxlC* | */mpxlC*)
        RPATH_FLAGS=nothing ;;
      esac ;;
    *-hp-*)
        RPATH_FLAGS=nothing ;;
    *-mingw32)
        RPATH_FLAGS=nothing ;;
    *-*-solaris*)
        RPATH_FLAGS=
        for dir in $1; do
          RPATH_FLAGS="$RPATH_FLAGS -R$dir"
        done
  esac

  if test "$RPATH_FLAGS" = ""; then
    AC_MSG_WARN([Could not automatically determine how to tell the linker about automatic inclusion of the path for shared libraries.  The test examples might not work if you link against shared objects.  You will need to set the LD_LIBRARY_PATH, DYLP_LIBRARY_PATH, or LIBDIR variable manually.])
  fi
  if test "$RPATH_FLAGS" = "nothing"; then
    RPATH_FLAGS=
  fi
fi

AC_SUBST(RPATH_FLAGS)
]) # AC_COIN_RPATH_FLAGS

###########################################################################
#                        COIN_LINK_INPUT_CMD                              #
###########################################################################

# This macro determines which command should be used to "link" files
# that are input to the generated executables.  On Windows, the codes
# using the native Windows system libraries, cannot understand symbolic
# links, and a copy should be used instead of 'ln -s'.
# The result is stored in coin_link_input_cmd

AC_DEFUN([AC_COIN_LINK_INPUT_CMD],
[AC_REQUIRE([AC_PROG_LN_S])
AC_BEFORE([AC_COIN_PROG_CC], [$0])
AC_BEFORE([AC_COIN_ENABLE_MSVC], [$0])

AC_MSG_CHECKING([which command should be used to link input files])
coin_link_input_cmd="$LN_S"
case "$CC" in
  clang* ) ;;
  cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
    coin_link_input_cmd=cp ;;
esac
AC_MSG_RESULT($coin_link_input_cmd)
])

###########################################################################
#                              COIN_FINALIZE                              #
###########################################################################

# This macro should be called at the very end of the configure.ac file.
# It creates the output files (by using AC_OUTPUT), and might do some other
# things (such as generating links to data files in a VPATH configuration).
# It also prints the "success" message.
# Note: If the variable coin_skip_ac_output is set to yes, then no output
# files are written.

AC_DEFUN([AC_COIN_FINALIZE],
[
AC_REQUIRE([AC_COIN_LINK_INPUT_CMD])
if test x$coin_skip_ac_output != xyes; then

  # library extension
  AC_SUBST(LIBEXT)
  case "$CC" in
    clang* )
         LIBEXT=a ;;
    cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
         LIBEXT=lib ;;
      *) LIBEXT=a ;;
  esac

  # Define VPATH_DISTCLEANFILES to be everything that needs to be
  # cleaned for distclean in a vpath configuration
  AC_SUBST(VPATH_DISTCLEANFILES)
  VPATH_DISTCLEANFILES="$coin_vpath_link_files"

  # Take out subdirectories if their configuration concluded that they
  # don't need to be compiled
  if test x"$coin_ac_skip_subdirs" != x; then
    new_subdirs=
    for i in $subdirs; do
      skipme=no
      for j in $coin_ac_skip_subdirs; do
        if test $i = $j; then
          skipme=yes;
        fi
      done
      if test $skipme = no; then
        new_subdirs="$new_subdirs $i"
      fi
    done
    subdirs="$new_subdirs"
  fi

  # need to come before AC_OUTPUT
  if test x$coin_projectdir != xyes; then
    # write coin_subdirs to a file so that project configuration knows where to find uninstalled projects
    echo $coin_subdirs > coin_subdirs.txt
  else
    # substitute for OBJDIR, needed to setup .pc file for uninstalled project
    ABSBUILDDIR="`pwd`"
    AC_SUBST(ABSBUILDDIR)
  fi
  
  AC_OUTPUT

  if test x"$coin_vpath_link_files" = x; then : ; else
    lnkcmd="$coin_link_input_cmd"
    if test "$lnkcmd" = cp; then
      AC_MSG_NOTICE(Copying data files for VPATH configuration)
    else
      AC_MSG_NOTICE(Creating VPATH links for data files)
    fi
    for file in $coin_vpath_link_files; do
      dir=`AS_DIRNAME(["./$file"])`
      if test -d $dir; then : ; else
        AS_MKDIR_P($dir)
      fi
      rm -f $file
      $lnkcmd $abs_source_dir/$file $file
    done
  fi

  AC_MSG_NOTICE([In case of trouble, first consult the troubleshooting page at https://projects.coin-or.org/BuildTools/wiki/user-troubleshooting])
  if test x$coin_projectdir = xyes; then
    AC_MSG_NOTICE([Configuration of $PACKAGE_NAME successful])
  else
    AC_MSG_NOTICE([Main configuration of $PACKAGE_NAME successful])
  fi
else
  AC_MSG_NOTICE([No configuration of $PACKAGE_NAME necessary])
fi

]) #AC_COIN_FINALIZE

###########################################################################
#                             COIN_VPATH_LINK                             #
###########################################################################

# This macro queues source files that need to be available in the build
# directory. In a VPATH configuration, the files will be made available by
# symbolic link or copy (when the platform does not support links). The list
# is processed by COIN_FINALIZE. The parameter is a whitespace-separated
# list of files.

AC_DEFUN([AC_COIN_VPATH_LINK],
[
AC_REQUIRE([AC_COIN_CHECK_VPATH])
# Allow for newlines in the parameter
if test $coin_vpath_config = yes; then
  cvl_tmp="$1"
  for file in $cvl_tmp ; do
    coin_vpath_link_files="$coin_vpath_link_files $file"
  done
fi
]) #AC_COIN_VPATH_LINK

###########################################################################
#                       COIN_ENABLE_GNU_PACKAGES                          #
###########################################################################

# This macro defined the --enable-gnu-packages flag.  This can be used
# to check if a user wants to compile GNU packges (such as readline)
# into the executable.  By default, GNU packages are disabled.

AC_DEFUN([AC_COIN_ENABLE_GNU_PACKAGES],
[AC_ARG_ENABLE([gnu-packages],
               [AC_HELP_STRING([--enable-gnu-packages],
                               [compile with GNU packages (disabled by default)])],
	       [coin_enable_gnu=$enableval],
	       [coin_enable_gnu=no])
]) # AC_COIN_ENABLE_GNU_PACKAGES

#######################################################################
#                           COIN_CHECK_LIBM                           #
#######################################################################

# For a (space separated) list of arguments X, this macro adds the flags
# for linking against the math library to a X_LIBS and X_PCLIBS.

AC_DEFUN([AC_COIN_CHECK_LIBM],
[AC_BEFORE([AC_COIN_PROG_CC],[$0])

if test $coin_cc_is_cl != true ; then
  coin_foreach_w([myvar], [$1], [
    m4_toupper(myvar)_LIBS="-lm $m4_toupper(myvar)_LIBS"
    m4_toupper(myvar)_PCLIBS="-lm $m4_toupper(myvar)_PCLIBS"
    m4_toupper(myvar)_LIBS_INSTALLED="-lm $m4_toupper(myvar)_LIBS_INSTALLED"
  ])
fi

]) # AC_COIN_CHECK_LIBM

###########################################################################
#                           COIN_CHECK_GNU_ZLIB                           #
###########################################################################

# This macro checks for the libz library.  If found, it sets the automake
# conditional COIN_HAS_ZLIB and defines the C preprocessor variable
# COIN_HAS_ZLIB.  Further, for a (space separated) list of arguments X,
# it adds the linker flag to the variables X_LIBS, X_PCLIBS, and X_LIBS_INSTALLED.

# TODO the macro name should be changed to AC_COIN_CHECK_ZLIB

AC_DEFUN([AC_COIN_CHECK_GNU_ZLIB],
[
AC_BEFORE([AC_COIN_PROG_CXX],[$0])
AC_BEFORE([AC_COIN_PROG_CC],[$0])
AC_BEFORE([AC_COIN_PROG_F77],[$0])
AC_BEFORE([$0],[AC_COIN_FINALIZE])

coin_has_zlib=no

AC_ARG_ENABLE([zlib],
              [AC_HELP_STRING([--disable-zlib],[do not compile with compression library zlib])],
              [coin_enable_zlib=$enableval],
              [coin_enable_zlib=yes])

if test $coin_enable_zlib = yes; then
  AC_COIN_CHECK_HEADER([zlib.h],[coin_has_zlib=yes])

  if test $coin_has_zlib = yes; then
    AC_CHECK_LIB([z],[gzopen],[:],[coin_has_zlib=no])
  fi

  if test $coin_has_zlib = yes; then
    coin_foreach_w([myvar], [$1], [
                    m4_toupper(myvar)_LIBS="-lz $m4_toupper(myvar)_LIBS"
                    m4_toupper(myvar)_PCLIBS="-lz $m4_toupper(myvar)_PCLIBS"
                    m4_toupper(myvar)_LIBS_INSTALLED="-lz $m4_toupper(myvar)_LIBS_INSTALLED"
                   ])
    AC_DEFINE([COIN_HAS_ZLIB],[1],[Define to 1 if zlib is available])
  fi
fi

AM_CONDITIONAL(COIN_HAS_ZLIB,test x$coin_has_zlib = xyes)
]) # AC_COIN_CHECK_GNU_ZLIB


###########################################################################
#                          COIN_CHECK_GNU_BZLIB                           #
###########################################################################

# This macro checks for the libbz2 library.  If found, it defines the C
# preprocessor variable COIN_HAS_BZLIB.  Further, for a (space separated) list
# of arguments X, it adds the linker flag to the variables X_LIBS, X_PCLIBS, and X_LIBS_INSTALLED.

# TODO the macro name should be changed to AC_COIN_CHECK_BZLIB

AC_DEFUN([AC_COIN_CHECK_GNU_BZLIB],
[
AC_BEFORE([AC_COIN_PROG_CXX],[$0])
AC_BEFORE([AC_COIN_PROG_CC],[$0])
AC_BEFORE([AC_COIN_PROG_F77],[$0])
AC_BEFORE([$0],[AC_COIN_FINALIZE])

AC_ARG_ENABLE([bzlib],
              [AC_HELP_STRING([--disable-bzlib],[do not compile with compression library bzlib])],
              [coin_enable_bzlib=$enableval],
              [coin_enable_bzlib=yes])

coin_has_bzlib=no
if test $coin_enable_bzlib = yes; then
  AC_COIN_CHECK_HEADER([bzlib.h],[coin_has_bzlib=yes])

  if test $coin_has_bzlib = yes; then
    AC_CHECK_LIB([bz2],[BZ2_bzReadOpen],[:],[coin_has_bzlib=no])
  fi

  if test $coin_has_bzlib = yes; then
    coin_foreach_w([myvar], [$1], [
                    m4_toupper(myvar)_LIBS="-lbz2 $m4_toupper(myvar)_LIBS"
                    m4_toupper(myvar)_PCLIBS="-lbz2 $m4_toupper(myvar)_PCLIBS"
                    m4_toupper(myvar)_LIBS_INSTALLED="-lbz2 $m4_toupper(myvar)_LIBS_INSTALLED"
                  ])
    AC_DEFINE([COIN_HAS_BZLIB],[1],[Define to 1 if bzlib is available])
  fi
fi
]) # AC_COIN_CHECK_GNU_BZLIB


###########################################################################
#                         COIN_CHECK_GNU_READLINE                         #
###########################################################################

# This macro checks for GNU's readline.  It verifies that the header
# readline/readline.h is available, and that the -lreadline library
# contains "readline".  It is assumed that #include <stdio.h> is included
# in the source file before the #include<readline/readline.h>
# If found, it defines the C preprocessor variable COIN_HAS_READLINE.
# Further, for a (space separated) list of arguments X, it adds the
# linker flag to the variable X_LIBS, X_PCLIBS, and X_LIBS_INSTALLED.

AC_DEFUN([AC_COIN_CHECK_GNU_READLINE],
[AC_REQUIRE([AC_COIN_ENABLE_GNU_PACKAGES])
AC_BEFORE([AC_COIN_PROG_CXX],[$0])
AC_BEFORE([AC_COIN_PROG_CC],[$0])
AC_BEFORE([AC_COIN_PROG_F77],[$0])
AC_BEFORE([$0],[AC_COIN_FINALIZE])

coin_has_readline=no
if test $coin_enable_gnu = yes; then
  AC_COIN_CHECK_HEADER([readline/readline.h],
                       [coin_has_readline=yes],[],
                       [#include <stdio.h>])

  coin_save_LIBS="$LIBS"
  LIBS=
  # First we check if tputs and friends are available
  if test $coin_has_readline = yes; then
    AC_SEARCH_LIBS([tputs],[ncurses termcap curses],[],
                   [coin_has_readline=no])
  fi

  # Now we check for readline
  if test $coin_has_readline = yes; then
    AC_CHECK_LIB([readline],[readline],[:],[coin_has_readline=no])
  fi

  if test $coin_has_readline = yes; then
    coin_foreach_w([myvar], [$1], [
                    m4_toupper(myvar)_LIBS="-lreadline $LIBS $m4_toupper(myvar)_LIBS"
                    m4_toupper(myvar)_PCLIBS="-lreadline $LIBS $m4_toupper(myvar)_PCLIBS"
                    m4_toupper(myvar)_LIBS_INSTALLED="-lreadline $LIBS $m4_toupper(myvar)_LIBS_INSTALLED"
                   ])
    AC_DEFINE([COIN_HAS_READLINE],[1],[Define to 1 if readline is available])
  fi

  LIBS="$coin_save_LIBS"
fi
]) # AC_COIN_CHECK_GNU_READLINE

###########################################################################
#                              COIN_CHECK_GMP                             #
###########################################################################

# This macro checks for the gmp library.  If found, it defines the C
# preprocessor variable COIN_HAS_GMP.  Further, for a (space separated) list
# of arguments X, it adds the linker flag to the variables X_LIBS, X_PCLIBS, and X_LIBS_INSTALLED.

AC_DEFUN([AC_COIN_CHECK_GMP],
[
AC_BEFORE([AC_COIN_PROG_CXX],[$0])
AC_BEFORE([AC_COIN_PROG_CC],[$0])
AC_BEFORE([AC_COIN_PROG_F77],[$0])
AC_BEFORE([$0],[AC_COIN_FINALIZE])

AC_ARG_ENABLE([gmp],
              [AC_HELP_STRING([--disable-gmp],[do not compile with GNU multiple precision library])],
              [coin_enable_gmp=$enableval],
              [coin_enable_gmp=yes])

coin_has_gmp=no
if test $coin_enable_gmp = yes; then
  AC_COIN_CHECK_HEADER([gmp.h],[AC_CHECK_LIB([gmp],[__gmpz_init],[coin_has_gmp=yes])])
  
  if test $coin_has_gmp = yes ; then
    coin_foreach_w([myvar], [$1], [
                    m4_toupper(myvar)_LIBS="-lgmp $m4_toupper(myvar)_LIBS"
                    m4_toupper(myvar)_PCLIBS="-lgmp $m4_toupper(myvar)_PCLIBS"
                    m4_toupper(myvar)_LIBS_INSTALLED="-lgmp $m4_toupper(myvar)_LIBS_INSTALLED"
                   ])
    AC_DEFINE([COIN_HAS_GMP],[1],[Define to 1 if GMP is available])
  fi
fi
]) # AC_COIN_CHECK_GMP

###########################################################################
#                            COIN_CHECK_ISFINITE                          #
###########################################################################

# This macro checks for a usable implementation of a function to check
# whether a given floating point number is finite.
# If a function is found, then the macro defines the symbol
# toupper($1)_C_FINITE to the name of this function.

AC_DEFUN([AC_COIN_CHECK_ISFINITE],[

AC_LANG_PUSH(C++)

AC_COIN_CHECK_CXX_CHEADER(math)
AC_COIN_CHECK_CXX_CHEADER(float)
AC_COIN_CHECK_CXX_CHEADER(ieeefp)

COIN_C_FINITE=
AC_CHECK_DECL([isfinite],[COIN_C_FINITE=isfinite],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
if test -z "$COIN_C_FINITE"; then
  AC_CHECK_DECL([finite],[COIN_C_FINITE=finite],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
  if test -z "$COIN_C_FINITE"; then
    AC_CHECK_DECL([_finite],[COIN_C_FINITE=_finite],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
  fi
fi
if test -z "$COIN_C_FINITE"; then
  AC_MSG_WARN(Cannot find C-function for checking Inf.)
else
  AC_DEFINE_UNQUOTED(COIN_C_FINITE,[$COIN_C_FINITE],
                     [Define to be the name of C-function for Inf check])
fi

AC_LANG_POP(C++)
])

###########################################################################
#                              COIN_CHECK_ISNAN                           #
###########################################################################

# This macro checks for a usable implementation of a function to check
# whether a given floating point number represents NaN.
# If a function is found, then the macro defines the symbol COIN_C_ISNAN
# to the name of this function.

AC_DEFUN([AC_COIN_CHECK_ISNAN],[

AC_LANG_PUSH(C++)

AC_COIN_CHECK_CXX_CHEADER(math)
AC_COIN_CHECK_CXX_CHEADER(float)
AC_COIN_CHECK_CXX_CHEADER(ieeefp)

COIN_C_ISNAN=
AC_CHECK_DECL([isnan],[COIN_C_ISNAN=isnan],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])

# It appears that for some systems (e.g., Mac OSX), cmath will provide only
# std::isnan, and bare isnan will be unavailable. Typically we need a parameter
# in the test to allow C++ to do overload resolution.

if test -z "$COIN_C_ISNAN"; then
  AC_CHECK_DECL([std::isnan(42.42)],[COIN_C_ISNAN=std::isnan],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
fi

if test -z "$COIN_C_ISNAN"; then
  AC_CHECK_DECL([_isnan],[COIN_C_ISNAN=_isnan],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
fi
if test -z "$COIN_C_ISNAN"; then
  AC_CHECK_DECL([isnand],[COIN_C_ISNAN=isnand],,[
#ifdef HAVE_CMATH
# include <cmath>
#else
# ifdef HAVE_MATH_H
#  include <math.h>
# endif
#endif
#ifdef HAVE_CFLOAT
# include <cfloat>
#else
# ifdef HAVE_FLOAT_H
#  include <float.h>
# endif
#endif
#ifdef HAVE_CIEEEFP
# include <cieeefp>
#else
# ifdef HAVE_IEEEFP_H
#  include <ieeefp.h>
# endif
#endif])
fi
if test -z "$COIN_C_ISNAN"; then
  AC_MSG_WARN(Cannot find C-function for checking NaN.)
else
  AC_DEFINE_UNQUOTED(COIN_C_ISNAN,[$COIN_C_ISNAN],
                     [Define to be the name of C-function for NaN check])
fi

AC_LANG_POP(C++)
])

###########################################################################
#                             COIN_DATA_PATH                              #
###########################################################################

# This macro defines a preprocessor macro with the absolute path to a
# subdirectory of Data.  The argument of this macro is the name of the
# subdirectory (in correct case), and the name of the macro is
# COIN_DATA_DIR_PATH, where dir is replaced by the capitalized name of
# the directory.  The path ends with a separator ("/" for linux and
# '\\' for Windows).  The default value for this path can be
# overwritten with the input variable with the same name
# (COIN_DATA_DIR_PATH).  At this point we chech only for the
# $srcdir/../Data subdirectory.

AC_DEFUN([AC_COIN_DATA_PATH],
[AC_MSG_CHECKING([absolute path to data directory $1])

AC_ARG_VAR(m4_toupper(COIN_DATA_$1_PATH),[Set to absolute path to Data/$1 subdirectory])

if test x"$m4_toupper(COIN_DATA_$1_PATH)" = x; then
  if test -d $srcdir/../Data/$1 ; then
    m4_toupper(COIN_DATA_$1_PATH)=`cd $srcdir/../Data/$1; pwd`
  else
    m4_toupper(COIN_DATA_$1_PATH)=`cd $srcdir/../../Data/$1; pwd`
  fi
fi

# Under Cygwin, use Windows path.  Add separator
case $build in
  *-cygwin*)
    m4_toupper(COIN_DATA_$1_PATH)=`cygwin -w $m4_toupper(COIN_DATA_$1_PATH)`\\
    ;;
  *)
    m4_toupper(COIN_DATA_$1_PATH)="$m4_toupper(COIN_DATA_$1_PATH)/"
    ;;
esac

if test -d $m4_toupper(COIN_DATA_$1_PATH); then
  AC_DEFINE_UNQUOTED(m4_toupper(COIN_DATA_$1_PATH),["$m4_toupper(COIN_DATA_$1_PATH)"],
            [Define to absolute path for Data subdirectory $1])
  AC_MSG_RESULT($m4_toupper(COIN_DATA_$1_PATH))
else
  AC_MSG_ERROR(Directory $m4_toupper(COIN_DATA_$1_PATH) does not exist)
fi
]) # AC_COIN_DATA_PATH

###########################################################################
#                       COIN_LINK_FROM_FILELIST                           #
###########################################################################

# This macro creates links (or copies, if necessary) to files listed
# as content in a text file (second argument) into a target directory
# (first argument), which is created if it doesn't exist yet.  If s link
# already exists, nothing happens.

AC_DEFUN([AC_COIN_LINKCOPY_FROM_FILELIST],
[cmd="$3"
if test -r $srcdir/$2 ; then
  my_target_dir="$1"
  my_link_files=`cat $srcdir/$2`
  my_dirname=`AS_DIRNAME($2)`
#  if test -e $my_target_dir; then : ; else
#    AS_MKDIR_P($my_target_dir)
#  fi
  for i in $my_link_files; do
    #rm -rf $my_target_dir/$i
    if test -e $my_target_dir/$i; then : ; else
      dirn2=`AS_DIRNAME($my_target_dir/$i)`
      if test -d $dirn2; then : ; else
        AS_MKDIR_P($dirn2)
      fi
      $cmd $abs_source_dir/$my_dirname/$i $my_target_dir/$i
    fi
  done
else
  AC_MSG_WARN([File list file $2 missing!])
fi
])

AC_DEFUN([AC_COIN_LINK_FROM_FILELIST], 
[
AC_REQUIRE([AC_COIN_LINK_INPUT_CMD])
echo Creating links in $1 ...
AC_COIN_LINKCOPY_FROM_FILELIST($1, $2, $coin_link_input_cmd)
])

###########################################################################
#                       COIN_COPY_FROM_FILELIST                           #
###########################################################################

# Like COIN_LINK_FROM_FILELIST, but copies the files.

AC_DEFUN([AC_COIN_COPY_FROM_FILELIST], 
[
echo Creating copies in $1 ...
AC_COIN_LINKCOPY_FROM_FILELIST($1, $2, [cp])
])

###########################################################################
#                          COIN_EXAMPLE_FILES                             #
###########################################################################

# This macro determines the names of the example files (using the
# argument in an "ls" command) and sets up the variables EXAMPLE_FILES
# and EXAMPLE_CLEAN_FILES.  If this is a VPATH configuration, it also
# creates soft links to the example files.

AC_DEFUN([AC_COIN_EXAMPLE_FILES],
[AC_REQUIRE([AC_COIN_CHECK_VPATH])
AC_REQUIRE([AC_COIN_ENABLE_MSVC])
AC_REQUIRE([AC_PROG_LN_S])

files=`cd $srcdir; ls $1`
# We need to do the following loop to make sure that are no newlines
# in the variable
for file in $files; do
  EXAMPLE_FILES="$EXAMPLE_FILES $file"
done
if test $coin_vpath_config = yes; then
  lnkcmd=
  if test "$enable_msvc" = yes; then
    lnkcmd=cp
  fi
  case "$CC" in
    clang* ) ;;
    cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
      lnkcmd=cp ;;
  esac
  if test "x$lnkcmd" = xcp; then
    AC_MSG_NOTICE([Copying example files ($1)])
  else
    AC_MSG_NOTICE([Creating links to the example files ($1)])
    lnkcmd="$LN_S"
  fi
  for file in $EXAMPLE_FILES; do
    rm -f $file
    $lnkcmd $srcdir/$file $file
  done
  EXAMPLE_CLEAN_FILES="$EXAMPLE_CLEAN_FILES $1"
else
  EXAMPLE_CLEAN_FILES="$EXAMPLE_CLEAN_FILES"
fi

# In case there are compressed files, we create a variable with the
# uncompressed names
EXAMPLE_UNCOMPRESSED_FILES=
for file in $EXAMPLE_FILES; do
  case $file in
    *.gz)
      EXAMPLE_UNCOMPRESSED_FILES="$EXAMPLE_UNCOMPRESSED_FILES `echo $file | sed -e s/.gz//`"
      ;;
  esac
done

AC_SUBST(EXAMPLE_UNCOMPRESSED_FILES)
AC_SUBST(EXAMPLE_FILES)
AC_SUBST(EXAMPLE_CLEAN_FILES)
]) #AC_COIN_EXAMPLE_FILES

###########################################################################
#                      COIN_CHECK_USER_LIBRARY                            #
###########################################################################
# This macro sets up usage of a user library with header files. The assumption
# is that the header file(s) and library do not reside in standard system
# directories, hence both the include directory and link flags must be
# specified. There are two mandatory arguments and two optional arguments.
#
# The first argument (mandatory) should be a name (LibraryName) for the
# library.  The second argument (mandatory) should be an abbreviation in
# upper case letters (LBRY) for the library. Ultimately, the macro will
# specify two variables, LBRYINCDIR and LBRYLIB, to be substituted in files
# generated during configuration; a preprocessor symbol COIN_HAS_LBRY; and a
# matching automake conditional COIN_HAS_LBRY. LBRYINCDIR should specify the
# directory containing include files for the library. LBRYLIB should specify
# the flags necessary to link to the library. A variable coin_has_lbry will
# be set to true or false, as appropriate. A variable lbry_libcheck will be
# be set to yes or no; no indicates link checks should not be attempted.
#
# The macro defines three configure arguments, --with-libraryname-incdir,
# --with-libraryname-lib, and --disable-libraryname-libcheck, by converting
# LibraryName to lower case.
#
# LBRYINCDIR and LBRYLIB can be specified as environment variables or as
# part of the configure command using --with-libraryname-incdir and
# --with-libraryname-lib, respectively. Command line arguments override
# environment variables.
#
# If a third argument is given, it should specify a file in LBRYINCDIR.  The
# macro will check for the presence of the file. If a fourth argument is given,
# it should specify a function name, `fname'.  The macro will attempt to link a
# trivial program containing a parameterless call to the function, `fname()',
# using the LBRYLIB flags. The link check uses C as the language; this has been
# adequate to date but has limitations. It is possible to disable the link
# check by specifying --disable-libraryname-libcheck. This is a workaround for
# instances where the link check does not work properly, for whatever reason.
# If you're trying to link to a Fortran library, consider using F77_FUNC or
# FC_FUNC to obtain a mangled fname appropriate for use from C code. For a C++
# library, you're on your own unless the library declares some function with
# extern "C" linkage. Otherwise, you'll have to somehow find the mangled C++
# name.
# A fifth argument can be specified to include linker flags that may be required
# to sucessfully perform the linking check.
#
# An optional sixth argument can be given to specify a list of targets.
# For each target X, the variables X_LIBS and X_PCLIBS will be extended by $LBRYLIB,
# if the library has been found and seems to work.

AC_DEFUN([AC_COIN_CHECK_USER_LIBRARY],
[ AC_REQUIRE([AC_COIN_PROJECTDIR_INIT])
  AC_MSG_CHECKING(if user provides library for $1)

# Check for header file directory

  AC_ARG_WITH(m4_tolower($1)-incdir,
      AS_HELP_STRING([--with-m4_tolower($1)-incdir],
		     [specify the header file directory for library $1]),
      [$2INCDIR=`cd $withval; pwd`])

# Check for library directory

  AC_ARG_WITH(m4_tolower($1)-lib,
      AS_HELP_STRING([--with-m4_tolower($1)-lib],
		     [specify the flags used to link with the library $1]),
      [$2LIB=$withval])

# Switch to disable library check if requested

  AC_ARG_ENABLE(m4_tolower($1)-libcheck,
      AS_HELP_STRING([--disable-m4_tolower($1)-libcheck],
		     [skip the link check at configuration time]),
      [m4_tolower($1)_libcheck=$enableval],
      [m4_tolower($1)_libcheck=yes])

# At this point, if we're going to use the library, both LBRYINCDIR and
# LBRYLIB must be defined and not empty.

  if test x"$$2INCDIR" != x || test x"$$2LIB" != x; then
    if test x"$$2INCDIR" = x || test x"$$2LIB" = x; then
      AC_MSG_ERROR([You need to specify both an include directory and link flags to use library $1. Use --with-m4_tolower($1)-incdir of environment variable $$2INCDIR to specify the include directory. Use --with-m4_tolower($1)-lib or environment variable $$2LIB to specify link flags.])
    fi
    m4_tolower(coin_has_$2)=true
    AC_MSG_RESULT(yes)
  else
    m4_tolower(coin_has_$2)=false
    AC_MSG_RESULT(no)
  fi

# If we have instructions for use, consider header and link checks.

  if test $m4_tolower(coin_has_$2) = true; then

# If argument 3 (file) is given, check for the file. Typically this will be a
# header file, but that's not assumed.

    m4_ifval([$3],
        [AC_COIN_CHECK_FILE([$$2INCDIR/$3],[],
	     [AC_MSG_ERROR([Cannot find file $3 in $$2INCDIR])])])

# Now see if we can link the function. There are arguments for and against
# assuming argument 3 is a header file declaring the function. A correct
# function declaration is the main argument in favour. Having to cope with
# possible dependencies or other oddities are the main arguments against.
# Force the use of C as the best single choice amongst C++, C, and Fortran.
# Obviously, this has limits.

    m4_ifvaln([$4],
        [if test x"$m4_tolower($1)_libcheck" != xno; then
	   coin_save_LIBS="$LIBS"
	   LIBS="$$2LIB $5"
	   coin_$2_link=no
	   AC_LANG_PUSH(C)
	   for fnm in $4 ; do
	     AC_MSG_CHECKING([whether symbol $fnm is available with $2])
	     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[$fnm()]])],
		 [AC_MSG_RESULT(yes)
		  coin_$2_link=yes
		  break],
		 [AC_MSG_RESULT(no)])
	   done
	   AC_LANG_POP(C)
           LIBS="$coin_save_LIBS"
	   if test x"$coin_$2_link" != xyes ; then
	     AC_MSG_ERROR([Cannot find symbol(s) $4 with $2])
	   fi
	 fi])

# If we make it this far, we've verified the file and linked the function. Add
# the necessary link flags to $6_{PC}LIBS and define the preprocessor symbol
# COIN_HAS_LBRY.

    coin_foreach_w([myvar], [$6], [
      m4_toupper(myvar)_LIBS="$$2LIB $m4_toupper(myvar)_LIBS"
      m4_toupper(myvar)_PCLIBS="$$2LIB $m4_toupper(myvar)_PCLIBS"
      m4_toupper(myvar)_LIBS_INSTALLED="$$2LIB $m4_toupper(myvar)_LIBS_INSTALLED"
    ])
    
    AC_DEFINE(COIN_HAS_$2,[1],[Define to 1 if the $1 package is available])
  fi

# Arrange for configure to substitute LBRYINCDIR and LBRYLIB and create the
# automake conditional. These actions must occur unconditionally.

  AC_SUBST($2INCDIR)
  AC_SUBST($2LIB)
  AM_CONDITIONAL(COIN_HAS_$2, test $m4_tolower(coin_has_$2) = true)
]) #AC_COIN_CHECK_USER_LIBRARY 

###########################################################################
#                            COIN_TRY_FLINK                               #
###########################################################################

# Auxilliary macro to test if a Fortran function name can be linked,
# given the current settings of LIBS.  We determine from the context, what
# the currently active programming language is, and cast the name accordingly.
# The first argument is the name of the function/subroutine, in small letters,
# the second argument are the actions taken when the test works, and the
# third argument are the actions taken if the test fails.

AC_DEFUN([AC_COIN_TRY_FLINK],
[case $ac_ext in
  f)
    AC_TRY_LINK(,[      call $1],[$2],[$3])
    ;;
  c)
    AC_F77_FUNC($1,cfunc$1)
    if test x"$coin_need_flibs" = xyes; then
      flink_try=no;
    else
      AC_TRY_LINK([void $cfunc$1();],[$cfunc$1()],
                  [flink_try=yes],[flink_try=no])
    fi
    if test $flink_try = yes; then
      $2
    else
      if test x"$FLIBS" != x; then
        flink_save_libs="$LIBS"
        LIBS="$LIBS $FLIBS"
        AC_TRY_LINK([void $cfunc$1();],[$cfunc$1()],
                    [LIBS="$flink_save_libs"
                     coin_need_flibs=yes
                     $2
                    ],
                    [LIBS="$flink_save_libs"
                     $3])
      else
        $3
      fi
    fi
    ;;
  cc|cpp)
    AC_F77_FUNC($1,cfunc$1)
    if test x"$coin_need_flibs" = xyes; then
      flink_try=no;
    else
      AC_TRY_LINK([extern "C" {void $cfunc$1();}],[$cfunc$1()],
                  [flink_try=yes],[flink_try=no])
    fi
    if test $flink_try = yes; then
      $2
    else
      if test x"$FLIBS" != x; then
        flink_save_libs="$LIBS"
        LIBS="$LIBS $FLIBS"
        AC_TRY_LINK([extern "C" {void $cfunc$1();}],[$cfunc$1()],
                    [LIBS="$flink_save_libs"
                     coin_need_flibs=yes
                     $2
                    ],
                    [LIBS="$flink_save_libs"
                     $3])
      else
        $3
      fi
    fi
    ;;
esac
]) # AC_COIN_TRY_FLINK

###########################################################################
#                           COIN_DOXYGEN                                  #
###########################################################################
#
# This macro determines the configuration information for doxygen, the tool
# used to generate online documentation of COIN code. It takes one parameter,
# a list of projects (mixed-case, to match the directory names) that should
# be processed as external tag files. E.g., COIN_DOXYGEN([Clp Osi]).
#
# This macro will define the following variables:
#  coin_have_doxygen	Yes if doxygen is found, no otherwise
#  coin_doxy_usedot     Defaults to `yes'; --with-dot will still check to see
#			if dot is available
#  coin_doxy_tagname	Name of doxygen tag file (placed in doxydoc directory)
#  coin_doxy_logname    Name of doxygen log file (placed in doxydoc directory)
#  coin_doxy_tagfiles   List of doxygen tag files used to reference other
#                       doxygen documentation
#  coin_doxy_excludes	Directories to exclude from doxygen processing

AC_DEFUN([AC_COIN_DOXYGEN],
[

AC_MSG_NOTICE([configuring doxygen documentation options])

# Check to see if doxygen is available.

AC_CHECK_PROG([coin_have_doxygen],[doxygen],[yes],[no])
AC_CHECK_PROG([coin_have_latex],[latex],[yes],[no])

# Look for the dot tool from the graphviz package, unless the user has
# disabled it.

AC_ARG_WITH([dot],
  AS_HELP_STRING([--with-dot],
		 [use dot (from graphviz) when creating documentation with
		  doxygen if available; --without-dot to disable]),
  [],[withval=yes])
if test x"$withval" = xno ; then
  coin_doxy_usedot=NO
  AC_MSG_CHECKING([for dot ])
  AC_MSG_RESULT([disabled])
else
  AC_CHECK_PROG([coin_doxy_usedot],[dot],[YES],[NO])
fi

# Generate a tag file name and a log file name

AC_SUBST([coin_doxy_tagname],[doxydoc/${PACKAGE}_doxy.tag])
AC_SUBST([coin_doxy_logname],[doxydoc/${PACKAGE}_doxy.log])
AM_CONDITIONAL(COIN_HAS_DOXYGEN, [test $coin_have_doxygen = yes])
AM_CONDITIONAL(COIN_HAS_LATEX, [test $coin_have_latex = yes])

# Process the list of project names and massage them into possible doxygen
# doc'n directories. Prefer 1) classic external, source processed using
# a project-specific doxygen.conf, we use the tag file; 2) classic
# external, source processed using package doxygen.conf; 3) installed
# doxydoc. Alternatives 1) and 2) are only possible if the directory will be
# configured, which we can't know unless this is the package base configure,
# since coin_subdirs is only set there. Hence it's sufficient to check for
# membership. If we use a tag file from a classic external, exclude the
# source from doxygen processing when doxygen runs in the base directory.

coin_doxy_tagfiles=
coin_doxy_excludes=
tmp="$1"
for proj in $tmp ; do
  lc_proj=`echo $proj | [tr [A-Z] [a-z]]`
  AC_MSG_CHECKING([for doxygen doc'n for $proj ])
  doxytag=${lc_proj}_doxy.tag
  doxyfound=no
  # proj will be configured, hence doxydoc present in build tree
  doxysrcdir="${srcdir}/../${proj}"
  # AC_MSG_NOTICE([Considering $doxysrcdir (base)])
  if test -d "$doxysrcdir" ; then
    # with a doxydoc directory?
    doxydir="$doxysrcdir/doxydoc"
    # AC_MSG_NOTICE([Considering $doxydir (base)])
    # AC_MSG_NOTICE([Subdirs: $coin_subdirs)])
    if test -d "$doxydir" ; then
      # use tag file; don't process source
      doxydir="../${proj}/doxydoc"
      coin_doxy_tagfiles="$coin_doxy_tagfiles $doxydir/$doxytag=../../$doxydir/html"
      AC_MSG_RESULT([$doxydir (tag)])
      coin_doxy_excludes="$coin_doxy_excludes */${proj}"
    else
      # will process the source -- nothing further to be done here
      AC_MSG_RESULT([$doxysrcdir (src)])
    fi
    doxyfound=yes
  fi
  # Not built, fall back to installed tag file
  if test $doxyfound = no ; then
    eval doxydir="${datadir}/coin/doc/${proj}/doxydoc"
    # AC_MSG_NOTICE([Considering $doxydir (install)])
    # AC_MSG_NOTICE([Subdirs: $coin_subdirs)])
    coin_doxy_tagfiles="$coin_doxy_tagfiles $doxydir/$doxytag=$doxydir/html"
    AC_MSG_RESULT([$doxydir (tag)])
  fi
done
AC_SUBST([coin_doxy_tagfiles])
AC_SUBST([coin_doxy_excludes])

]) # AC_COIN_DOXYGEN


###########################################################################
#                           COIN_HAS_PKGCONFIG                            #
###########################################################################

# This macro checks whether a pkg-config tool with a minimal version number
# is available.  If so, then the variable PKGCONFIG is set to its path.
# If not, PKGCONFIG is set to "".  The minimal version number can be given
# as first parameter, by default it is 0.16.0, since COIN-OR .pc files now
# include an URL field, which breaks pkg-config version <= 0.15.
# This macro is a modified version of PKG_PROG_PKG_CONFIG in pkg.m4.
# Further, the AM_CONDITIONAL COIN_HAS_PKGCONFIG is set and PKGCONFIG is
# AC_SUBST'ed.  Finally, if this setup belongs to a project directory, then
# the search path for .pc files is assembled from the value of
# $PKG_CONFIG_PATH, the values of --prefix, --coin-instdir, and the directories
# named in a file ../coin_subdirs.txt or ../../coin_subdirs.txt in a variable
# COIN_PKG_CONFIG_PATH, which is also AC_SUBST'ed. For a path xxx given in the
# coin-subdirs.txt, also the directory xxx/pkgconfig is added, if existing.

AC_DEFUN([AC_COIN_HAS_PKGCONFIG],
[AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])

AC_ARG_ENABLE([pkg-config],
  [AC_HELP_STRING([--disable-pkg-config],[disable use of pkg-config (if available)])],
  [use_pkgconfig="$enableval"],
  [if test x$coin_cc_is_cl = xtrue; then
     use_pkgconfig=no
   else
     use_pkgconfig=yes
   fi])

if test $use_pkgconfig = yes ; then
  if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
    AC_CHECK_TOOL([PKG_CONFIG], [pkg-config])
  fi
  if test -n "$PKG_CONFIG"; then
    _pkg_min_version=m4_default([$1], [0.16.0])
    AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
    if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
      AC_MSG_RESULT([yes])
    else
      AC_MSG_RESULT([no])
      PKG_CONFIG=""
    fi
  fi

  # check if pkg-config supports the short-errors flag
  if test -n "$PKG_CONFIG" && \
    $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
    pkg_short_errors=" --short-errors "
  else
    pkg_short_errors=""
  fi
fi

AM_CONDITIONAL([COIN_HAS_PKGCONFIG], [test -n "$PKG_CONFIG"])
AC_SUBST(PKG_CONFIG)

# assemble pkg-config search path for installed projects
COIN_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"

# let's assume that when installing into $prefix, then the user may have installed some other coin projects there before, so it's worth to have a look into there
# best would actually to use ${libdir}, since .pc files get installed into ${libdir}/pkgconfig,
# unfortunately, ${libdir} expands to ${exec_prefix}/lib and ${exec_prefix} to ${prefix}...
if test "x${prefix}" = xNONE ; then
  COIN_PKG_CONFIG_PATH="${ac_default_prefix}/lib64/pkgconfig:${ac_default_prefix}/lib/pkgconfig:${ac_default_prefix}/share/pkgconfig:${COIN_PKG_CONFIG_PATH}"
else
  COIN_PKG_CONFIG_PATH="${prefix}/lib64/pkgconfig:${prefix}/lib/pkgconfig:${prefix}/share/pkgconfig:${COIN_PKG_CONFIG_PATH}"
fi

AC_ARG_WITH([coin-instdir],
  AC_HELP_STRING([--with-coin-instdir],
                 [prefix of installation directory for precompiled COIN packages]),
  [if test -d "$withval"; then : ; else
     AC_MSG_ERROR([argument for --with-coin-instdir not a directory])
   fi
   COIN_PKG_CONFIG_PATH="$withval/lib/pkgconfig:$withval/share/pkgconfig:${COIN_PKG_CONFIG_PATH}"
  ],[])

AC_SUBST(COIN_PKG_CONFIG_PATH)

# assemble additional pkg-config search paths for uninstalled projects
if test x$coin_projectdir = xyes ; then
  # if we are in a project setup, then in a classic setup, we want to find uninstalled projects
  # their (relative) location is written to coin_subdirs.txt by the configure in the project base directory
  # unfortunately, if the user set prefix, then we do not know where the project base directory is located
  # but it is likely to be either .. (if we are a usual coin project) or ../.. (if we are a unusual coin project like ThirdParty or Data)
  COIN_PKG_CONFIG_PATH_UNINSTALLED=
  if test -f ../coin_subdirs.txt ; then
    for i in `cat ../coin_subdirs.txt` ; do
      if test -d ../$i ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../$i; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
      if test -d ../$i/pkgconfig ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../$i/pkgconfig; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
    done
  fi

  if test -f ../../coin_subdirs.txt ; then
    for i in `cat ../../coin_subdirs.txt` ; do
      if test -d ../../$i ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../../$i; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
      if test -d ../../$i/pkgconfig ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../../$i/pkgconfig; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
    done
  fi

  if test -f ../../../coin_subdirs.txt ; then
    for i in `cat ../../../coin_subdirs.txt` ; do
      if test -d ../../../$i ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../../../$i; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
      if test -d ../../../$i/pkgconfig ; then
        COIN_PKG_CONFIG_PATH_UNINSTALLED="`cd ../../../$i/pkgconfig; pwd`:${COIN_PKG_CONFIG_PATH_UNINSTALLED}"
      fi
    done
  fi

  AC_SUBST(COIN_PKG_CONFIG_PATH_UNINSTALLED)
fi

if test -n "$PKG_CONFIG" && test x$coin_cc_is_cl = xtrue; then
  AC_MSG_WARN([Using pkg-config together with MS or Intel Compiler on Windows is not support by example Makefiles. Consider using --disable-pkg-config.])
fi

])

###########################################################################
#                           COIN_PKG_CHECK_PROJECT_EXISTS                 #
###########################################################################

# COIN_PKG_CHECK_PROJECT_EXISTS(PROJECT, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# Check to see whether a particular project exists.  Similar
# to PKG_CHECK_MODULES(), but set only the variables $1_VERSION and $1_PKG_ERRORS variables
#
AC_DEFUN([AC_COIN_PKG_CHECK_PROJECT_EXISTS],
[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
if test -n "$PKG_CONFIG" ; then
  if $PKG_CONFIG --exists "m4_tolower($1)"; then
    m4_toupper($1)[]_VERSION=`$PKG_CONFIG --modversion "m4_tolower($1)" 2>/dev/null`
    m4_ifval([$2], [$2], [:])
  else
    m4_toupper($1)_PKG_ERRORS=`$PKG_CONFIG $pkg_short_errors --errors-to-stdout --print-errors "m4_tolower($1)"`
    $3
  fi
else
  AC_MSG_ERROR("Cannot check for existance of module $1 without pkg-config")
fi
])

###########################################################################
#                           COIN_PKG_CHECK_MODULE_EXISTS                  #
###########################################################################

# COIN_PKG_CHECK_MODULES_EXISTS(MODULE, PACKAGES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# Check to see whether a particular set of packages exists.
# Similar to PKG_CHECK_MODULES(), but set only the variable $1_VERSIONS and $1_PKG_ERRORS
#
AC_DEFUN([AC_COIN_PKG_CHECK_MODULE_EXISTS],
[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
if test -n "$PKG_CONFIG" ; then
  if $PKG_CONFIG --exists "$2"; then
    m4_toupper($1)[]_VERSIONS=`$PKG_CONFIG --modversion "$2" 2>/dev/null | tr '\n' ' '`
    $3
  else
    m4_toupper($1)_PKG_ERRORS=`$PKG_CONFIG $pkg_short_errors --errors-to-stdout --print-errors "$2"`
    $4
  fi
else
  AC_MSG_ERROR("Cannot check for existance of module $1 without pkg-config")
fi
])

###########################################################################
#                           COIN_PKG_HAS_MODULE                           #
###########################################################################

# COIN_PKG_HAS_MODULE(MODULE, PACKAGES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# Checks whether pkg-config files for a given set of packages is available.
# If so, sets MODULE_CFLAGS, MODULE_LIBS, and MODULES_DATA and executes ACTION-IF-FOUND.
# If not, then ACTION-IF-NOT-FOUND is executed.
# A reason for not finding a package is stored in MODULE_PKG_ERRORS
#
# --------------------------------------------------------------
AC_DEFUN([AC_COIN_PKG_HAS_MODULE],
[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])

AC_COIN_PKG_CHECK_MODULE_EXISTS([$1],[$2],
  [ cflags=`$PKG_CONFIG --cflags "$2" 2>/dev/null`
    # pkg-config cannot handle spaces, so CYGPATH_W cannot be put into .pc files
	# thus, we modify the cflags extracted from pkg-config by putting CYGPATH_W behind -I's
	# but only do this if is not trivial
    if test "$CYGPATH_W" != "echo" ; then
      # need to put into brackets since otherwise autoconf replaces the brackets in the sed command
      [cflags=`echo $cflags | sed -e 's/-I\([^ ]*\)/-I\`${CYGPATH_W} \1\`/g'`]
    fi
    m4_toupper($1)[]_CFLAGS="$cflags"
    m4_toupper($1)[]_LIBS=`$PKG_CONFIG --libs "$2" 2>/dev/null`
    m4_toupper($1)[]_DATA=`$PKG_CONFIG --variable=datadir "$2" 2>/dev/null`
    $3
  ],
  [ $4 ])

])# PKG_CHECK_MODULES

###########################################################################
#                           COIN_MAIN_PACKAGEDIR                          #
###########################################################################

# This macro substitutes COIN_MAIN_SUBDIR.
# If $2/$1 or $1 is in COIN_SKIP_PROJECTS, do nothing.
# If --with-$1-lib, --with-$1-incdir, or --with-$1-datadir is given, then assume that the package is installed.
# Otherwise, if the directory $2/$1 and the file $2/$1/$3 exist, check whether $2/$1/configure exists.
#   If so, include this directory into the list of directories where configure and make recourse into.
# tolower(coin_has_$1) is set to "no" if the project source is not available or will not be compiled.
# Otherwise, it will be set to "yes".

AC_DEFUN([AC_COIN_MAIN_PACKAGEDIR],[
AC_MSG_CHECKING([whether source of project $1 is available and should be compiled])

m4_tolower(coin_has_$1)=notGiven
coin_reason=

# check if user wants to skip project in any case
AC_ARG_VAR([COIN_SKIP_PROJECTS],[Set to the subdirectories of projects that should be skipped in the configuration])
if test x"$COIN_SKIP_PROJECTS" != x; then
  for dir in $COIN_SKIP_PROJECTS; do
    if test $dir = "$1"; then
      m4_tolower(coin_has_$1)="no"
      coin_reason="$1 has been specified in COIN_SKIP_PROJECTS"
    fi
    m4_ifval($2,[
    if test $dir = "$2/$1"; then
      m4_tolower(coin_has_$1)="no"
      coin_reason="$2/$1 has been specified in COIN_SKIP_PROJECTS"
    fi])
  done
fi

if test "$m4_tolower(coin_has_$1)" != no; then
  AC_ARG_WITH([m4_tolower($1)],,
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)="no"
       coin_reason="--without-m4_tolower($1) has been specified"
     fi
    ])
fi

if test "$m4_tolower(coin_has_$1)" != no; then
  AC_ARG_WITH([m4_tolower($1)-lib],
    AC_HELP_STRING([--with-m4_tolower($1)-lib],
                   [linker flags for using project $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)="no"
       coin_reason="--without-m4_tolower($1)-lib has been specified"
     else
       m4_tolower(coin_has_$1)="no"
       coin_reason="--with-m4_tolower($1)-lib has been specified"
     fi],
    [])
fi

if test "$m4_tolower(coin_has_$1)" != no; then
  AC_ARG_WITH([m4_tolower($1)-incdir],
    AC_HELP_STRING([--with-m4_tolower($1)-incdir],
                   [directory with header files for using project $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)="no"
       coin_reason="--without-m4_tolower($1)-incdir has been specified"
     else
       m4_tolower(coin_has_$1)="no"
       coin_reason="--with-m4_tolower($1)-incdir has been specified"
     fi],
    [])
fi

if test "$m4_tolower(coin_has_$1)" != no; then
  AC_ARG_WITH([m4_tolower($1)-datadir],
    AC_HELP_STRING([--with-m4_tolower($1)-datadir],
                   [directory with data files for using project $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)="no"
       coin_reason="--without-m4_tolower($1)-datadir has been specified"
     else
       m4_tolower(coin_has_$1)="no"
       coin_reason="--with-m4_tolower($1)-datadir has been specified"
     fi],
    [])
fi

m4_if(m4_tolower($1), blas, [
  if test $m4_tolower(coin_has_$1) != no; then
    #--with-blas can overwrite --with-blas-lib, and can be set to BUILD to enforce building blas
    AC_ARG_WITH([blas],
      AC_HELP_STRING([--with-blas], [specify BLAS library (or BUILD to enforce use of ThirdParty/Blas)]),
        [if test x"$withval" = "xno" ; then
           coin_has_blas="no"
           coin_reason="--without-blas has been specified"
         elif test x"$withval" != "xBUILD" ; then
           coin_has_blas="no"
           coin_reason="--with-blas has been specified"
         fi],
        [])
  fi
])

m4_if(m4_tolower($1), lapack, [
  if test $m4_tolower(coin_has_$1) != no; then
    #--with-lapack can overwrite --with-lapack-lib, and can be set to BUILD to enforce building lapack
    AC_ARG_WITH([lapack],
      AC_HELP_STRING([--with-lapack], [specify LAPACK library (or BUILD to enforce use of ThirdParty/Lapack)]),
        [if test x"$withval" = "xno" ; then
           coin_has_lapack="no"
           coin_reason="--without-lapack has been specified"
         elif test x"$withval" != "xBUILD" ; then
           coin_has_lapack="no"
           coin_reason="--with-lapack has been specified"
         fi],
        [])
  fi
])

# check if project is available in present directory
if test "$m4_tolower(coin_has_$1)" = notGiven; then
  m4_tolower(coin_has_$1)=no
  if test -d $srcdir/m4_ifval($2,[$2/],)$1; then
    coin_reason="source in m4_ifval($2,[$2/],)$1"
    # If a third argument is given, then we have to check if one one the files given in that third argument is present.
    # If none of the files in the third argument is available, then we consider the project directory as non-existing.
    # However, if no third argument is given, then this means that there should be no check, and existence of the directory is sufficient.
    m4_ifvaln([$3],
      [for i in $srcdir/m4_ifval($2,[$2/],)$1/$3; do
         if test -r $i; then
           m4_tolower(coin_has_$1)="yes"
         else
           m4_tolower(coin_has_$1)="no"
           coin_reason="source file $i not available"
           break
         fi
       done],
      [ m4_tolower(coin_has_$1)="yes" ])
  fi
fi

if test -z "$coin_reason" ; then
  AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
else
  AC_MSG_RESULT([$m4_tolower(coin_has_$1), $coin_reason])
fi

if test "$m4_tolower(coin_has_$1)" = yes ; then
  if test -r $srcdir/m4_ifval($2,[$2/],)$1/configure; then
    coin_subdirs="$coin_subdirs m4_ifval($2,[$2/],)$1"
    AC_CONFIG_SUBDIRS(m4_ifval($2,[$2/],)$1)
  fi
fi
])

###########################################################################
#                            COIN_CHECK_PACKAGE                           #
###########################################################################

# This macro checks for the existance of a COIN-OR package and provides compiler and linker flags to compile against this package.
# A package can consists of one or more COIN-OR or other projects.
# It defines the PACKAGE_CFLAGS, PACKAGE_LIBS, PACKAGE_DEPENDENCIES, and PACKAGE_DATA variables, referring to the compiler and linker
# flags to use when linking against this module, the libraries the package depends on, and the directories where the module data resists.
# The difference between PACKAGE_LIBS and PACKAGE_DEPENDENCIES is that PACKAGE_DEPENDENCIES does not contain arguments starting with '-',
# so it can be used to setup the _DEPENDENCIES variable in a Makefile.am.
# It also defines a COIN_HAS_PACKAGE preprocessor macro and makefile conditional.
# Further, tolower(coin_has_$1) is set to "yes".
# If a list of build targets using this projects is given in the third argument,
# then the compiler and linker variables and .pc file setup variable corresponding to this build target
# are extended with the values for this package.
# That is, for each build target X, the variables X_CFLAGS, X_LIBS, X_DEPENDENCIES, X_PCLIBS, X_PCREQUIRES are setup,
# whereas the last two specify the values to put into the "Libs:" and "Requires:" fields of the .pc file, resp.
#
# The first argument should be the name (PACKAGE) of the package (in correct lower
# and upper case).
# The second argument should be a (space separated) list of projects which this
# package consists of. Optionally, required version numbers can be added.
# The optional third argument should be a (space separated) list of build targets
# which use this package, if available.
#
# It is also possible to specify a preinstalled version of this package
# or to specify only the linker and compiler flags and data directory.
#
# If the user did not specify --with-$1-... flags and pkg-config is not available,
# COIN_CHECK_PACKAGE_FALLBACK($1, $2, $3) is called.

AC_DEFUN([AC_COIN_CHECK_PACKAGE],
[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
AC_MSG_CHECKING([for COIN-OR package $1])

m4_tolower(coin_has_$1)=notGiven

# check if user wants to skip package in any case
if test x"$COIN_SKIP_PROJECTS" != x; then
  for dir in $COIN_SKIP_PROJECTS; do
    if test $dir = "$1"; then
      m4_tolower(coin_has_$1)=skipping
    fi
  done
fi

if test "$m4_tolower(coin_has_$1)" != skipping; then
  AC_ARG_WITH([m4_tolower($1)],,
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)=skipping
     fi
    ])
fi

m4_toupper($1_LIBS)=
m4_toupper($1_CFLAGS)=
m4_toupper($1_DATA)=
m4_toupper($1_DEPENDENCIES)=
m4_toupper($1_PCLIBS)=
m4_toupper($1_PCREQUIRES)=
AC_SUBST(m4_toupper($1_LIBS))
AC_SUBST(m4_toupper($1_CFLAGS))
AC_SUBST(m4_toupper($1_DATA))
AC_SUBST(m4_toupper($1_DEPENDENCIES))
AC_SUBST(m4_toupper($1_LIBS_INSTALLED))
AC_SUBST(m4_toupper($1_CFLAGS_INSTALLED))
AC_SUBST(m4_toupper($1_DATA_INSTALLED))
coin_foreach_w([myvar], [$3], [
  AC_SUBST(m4_toupper(myvar)_CFLAGS)
  AC_SUBST(m4_toupper(myvar)_LIBS)
  AC_SUBST(m4_toupper(myvar)_PCLIBS)
  AC_SUBST(m4_toupper(myvar)_PCREQUIRES)
  AC_SUBST(m4_toupper(myvar)_DEPENDENCIES)
  AC_SUBST(m4_toupper(myvar)_CFLAGS_INSTALLED)
  AC_SUBST(m4_toupper(myvar)_LIBS_INSTALLED)
])

#check if user provided LIBS, CFLAGS, or DATA for package or disables use of package
if test $m4_tolower(coin_has_$1) != skipping; then
  AC_ARG_WITH([m4_tolower($1)-lib],
    AC_HELP_STRING([--with-m4_tolower($1)-lib],
                   [linker flags for using package $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)=skipping
     else
       m4_tolower(coin_has_$1)=yes
       m4_toupper($1_LIBS)="$withval"
       m4_toupper($1_PCLIBS)="$withval"
       coin_foreach_w([myvar], [$3], [
         m4_toupper(myvar)_PCLIBS="$withval $m4_toupper(myvar)_PCLIBS"
         m4_toupper(myvar)_LIBS="$withval $m4_toupper(myvar)_LIBS"
       ])
       # if project flags are given by user and we build without pkg-config, then we need to setup the _INSTALLED variables
       if test -z "$PKG_CONFIG" ; then
         m4_toupper($1_LIBS_INSTALLED)="$withval"
         coin_foreach_w([myvar], [$3], [m4_toupper(myvar)_LIBS_INSTALLED="$withval $m4_toupper(myvar)_LIBS_INSTALLED"])
       fi
     fi
    ],
    [])
fi

if test $m4_tolower(coin_has_$1) != skipping; then
  AC_ARG_WITH([m4_tolower($1)-incdir],
    AC_HELP_STRING([--with-m4_tolower($1)-incdir],
                   [directory with header files for using package $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)=skipping
     else
       m4_tolower(coin_has_$1)=yes
       m4_toupper($1_CFLAGS)="-I`${CYGPATH_W} $withval`"
       coin_foreach_w([myvar], [$3], [m4_toupper(myvar)_CFLAGS="-I`${CYGPATH_W} $withval` $m4_toupper(myvar)_CFLAGS"])
       # if project flags are given by user and we build without pkg-config, then we need to setup the _INSTALLED variables
       if test -z "$PKG_CONFIG" ; then
         m4_toupper($1_CFLAGS_INSTALLED)="$m4_toupper($1_CFLAGS)"
         coin_foreach_w([myvar], [$3], [m4_toupper(myvar)_CFLAGS_INSTALLED="$m4_toupper($1_CFLAGS) $m4_toupper(myvar)_CFLAGS_INSTALLED"])
       fi
     fi
    ],
    [])
fi

if test $m4_tolower(coin_has_$1) != skipping; then
  AC_ARG_WITH([m4_tolower($1)-datadir],
    AC_HELP_STRING([--with-m4_tolower($1)-datadir],
                   [directory with data files for using package $1]),
    [if test "$withval" = no ; then
       m4_tolower(coin_has_$1)=skipping
     else
       m4_tolower(coin_has_$1)=yes
       m4_toupper($1_DATA)="$withval"
       # if project flags are given by user and we build without pkg-config, then we need to setup the _INSTALLED variables
       if test -z "$PKG_CONFIG" ; then
         m4_toupper($1_DATA_INSTALLED)="$withval"
       fi
     fi
    ],
    [])
fi

if test $m4_tolower(coin_has_$1) = notGiven; then
  if test -n "$PKG_CONFIG" ; then
    # set search path for pkg-config
    # need to export variable to be sure that the following pkg-config gets these values
    coin_save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
    PKG_CONFIG_PATH="$COIN_PKG_CONFIG_PATH:$COIN_PKG_CONFIG_PATH_UNINSTALLED"
    export PKG_CONFIG_PATH
    
    # let pkg-config do it's magic
    AC_COIN_PKG_HAS_MODULE([$1],[$2],
      [ m4_tolower(coin_has_$1)=yes
        AC_MSG_RESULT([yes: $m4_toupper($1)_VERSIONS])

        # adjust linker flags for (i)cl compiler
        # for the LIBS, we replace everything of the form "/somepath/name.lib" by "`$(CYGPATH_W) /somepath/`name.lib | sed -e s|\|/|g" (where we have to use excessive many \ to get the \ into the command line for cl)
        if test x$coin_cxx_is_cl = xtrue || test x$coin_cc_is_cl = xtrue ;
        then
          m4_toupper($1_LIBS)=`echo " $m4_toupper($1_LIBS) " | [sed -e 's/ \(\/[^ ]*\/\)\([^ ]*\)\.lib / \`$(CYGPATH_W) \1 | sed -e "s|\\\\\\\\\\\\\\\\\\\\|\/|g"\`\2.lib /g']`
        fi
        m4_toupper($1_PCREQUIRES)="$2"
   
        # augment X_PCREQUIRES, X_CFLAGS, and X_LIBS for each build target X in $3
        coin_foreach_w([myvar], [$3], [
          m4_toupper(myvar)_PCREQUIRES="$2 $m4_toupper(myvar)_PCREQUIRES"
          m4_toupper(myvar)_CFLAGS="$m4_toupper($1)_CFLAGS $m4_toupper(myvar)_CFLAGS"
          m4_toupper(myvar)_LIBS="$m4_toupper($1)_LIBS $m4_toupper(myvar)_LIBS"
        ])
      ],
      [ m4_tolower(coin_has_$1)=notGiven
        AC_MSG_RESULT([not given: $m4_toupper($1)_PKG_ERRORS])
      ])

    # reset PKG_CONFIG_PATH variable 
    PKG_CONFIG_PATH="$coin_save_PKG_CONFIG_PATH"
    export PKG_CONFIG_PATH

  else
    AC_MSG_RESULT([skipped check via pkg-config, redirect to fallback])
    AC_COIN_CHECK_PACKAGE_FALLBACK([$1], [$2], [$3])
  fi

else
  AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
fi

if test $m4_tolower(coin_has_$1) != skipping &&
   test $m4_tolower(coin_has_$1) != notGiven ; then
  AC_DEFINE(m4_toupper(COIN_HAS_$1),[1],[Define to 1 if the $1 package is available])

  AC_ARG_ENABLE([interpackage-dependencies],
    AC_HELP_STRING([--disable-interpackage-dependencies], [disables deduction of Makefile dependencies from package linker flags]),
    [], [enable_interpackage_dependencies=yes])
    
  if test $enable_interpackage_dependencies = yes ; then
     # construct dependencies variables from LIBS variables
     # we add an extra space in LIBS so we can substitute out everything starting with " -"
     # remove everything of the form -framework xxx as used on Mac and mkl* and libiomp5* and wsock32.lib as used on Windows
     # then remove everything of the form -xxx
     # also remove everything of the form `xxx`yyy (may have been added for cygwin/cl)
     m4_toupper($1)_DEPENDENCIES=`echo " $m4_toupper($1)_LIBS" | [sed -e 's/ mkl[^ ]*//g' -e 's/ libiomp5[^ ]*//g' -e 's/ wsock32[^ ]*//g' -e 's/ -framework  *[^ ]*//g' -e 's/ -[^ ]*//g' -e 's/\`[^\`]*\`[^ ]* //g']`
     coin_foreach_w([myvar], [$3], [
       m4_toupper(myvar)_DEPENDENCIES=`echo " $m4_toupper(myvar)_LIBS " | [sed -e 's/ mkl[^ ]*//g' -e 's/ libiomp5[^ ]*//g' -e 's/ wsock32[^ ]*//g' -e 's/ -framework  *[^ ]*//g' -e 's/ -[^ ]*//g' -e 's/\`[^\`]*\`[^ ]* //g']`
     ])
  fi

  if test 1 = 0 ; then  #change this test to enable a bit of debugging output
    if test -n "$m4_toupper($1)_CFLAGS" ; then
      AC_MSG_NOTICE([$1 CFLAGS are $m4_toupper($1)_CFLAGS])
    fi
    if test -n "$m4_toupper($1)_LIBS" ; then
      AC_MSG_NOTICE([$1 LIBS   are $m4_toupper($1)_LIBS])
    fi
    if test -n "$m4_toupper($1)_DEPENDENCIES" ; then
      AC_MSG_NOTICE([$1 DEPENDENCIES are $m4_toupper($1)_DEPENDENCIES])
    fi
    if test -n "$m4_toupper($1)_DATA" ; then
      AC_MSG_NOTICE([$1 DATA   is  $m4_toupper($1)_DATA])
    fi
    if test -n "$m4_toupper($1)_PCLIBS" ; then
      AC_MSG_NOTICE([$1 PCLIBS are $m4_toupper($1)_PCLIBS])
    fi
    if test -n "$m4_toupper($1)_PCREQUIRES" ; then
      AC_MSG_NOTICE([$1 PCREQUIRES are $m4_toupper($1)_PCREQUIRES])
    fi
    coin_foreach_w([myvar], [$3], [
      AC_MSG_NOTICE([myvar CFLAGS are $m4_toupper(myvar)_CFLAGS])
      AC_MSG_NOTICE([myvar LIBS   are $m4_toupper(myvar)_LIBS])
      AC_MSG_NOTICE([myvar DEPENDENCIES are $m4_toupper(myvar)_DEPENDENCIES])
    ])
  fi
fi

# Define the Makefile conditional
AM_CONDITIONAL(m4_toupper(COIN_HAS_$1),
               [test $m4_tolower(coin_has_$1) != notGiven &&
                test $m4_tolower(coin_has_$1) != skipping])

]) # AC_COIN_CHECK_PACKAGE

###########################################################################
#                       COIN_CHECK_PACKAGE_FALLBACK                       #
###########################################################################

# This macro is used by COIN_CHECK_PACKAGE, if it fails to find a package
# because pkg-config was disabled or is not available.
#
# For each project xxx specified in $2, it searches for a xxx-uninstalled.pc
# file in the directories specified in $COIN_PKG_CONFIG_PATH_UNINSTALLED. The
# latter variable is setup by COIN_HAS_PKGCONFIG and consists of the content
# of the coin_subdirs.txt file which has been created by configure in the
# base directory.  The content of xxx-uninstalled.pc is parsed in order
# to defines the variables PACKAGE_CFLAGS, PACKAGE_LIBS, and PACKAGE_DATA,
# referring to the compiler and linker flags to use when linking against this
# package and the directory where the package data resists.  Further, for each
# build target X specified in the third argument, the variables X_CFLAGS and
# X_LIBS are extended with the compiler and linker flags of this package and
# the variables X_PCLIBS and X_PCREQUIRES are extended by the list of linker
# flags and dependent projects as needed to setup a .pc file.  The macros
# checks also dependencies of $2.  Note that the PACKAGE_DATA variable is
# set to the content of datadir of the first .pc file that is parsed.
# Finally, for each X in the third argument, also variables
# X_CFLAGS_INSTALLED and X_LIBS_INSTALLED are setup. They contain the compiler
# and linker flags for X when all projects have been installed. Their content
# is assembled from the .pc files that correspond to installed projects. I.e.,
# whenever a file proj-uninstalled.pc is parsed, then also a corresponding
# proj.pc file is parsed for compiler and linker flags, if available in the
# same directory.
# Similar, a variable PACKAGE_DATA_INSTALLED is setup to the content of datadir
# of the first .pc file that is parsed.
#
# If .pc files for all projects in $2 and their dependencies is found,
# tolower(coin_has_$1) is set to "yes".  Otherwise, if some dependency
# is not found, tolower(coin_has_$1) is set to "notGiven".  Further, a
# COIN_HAS_PACKAGE preprocessor macro and a makefile conditional are defined.
#
# The first argument should be the name (PACKAGE) of the package (in correct
# lower and upper case).  The second argument should be the base names of the
# projects .pc file which define this package.  The optional third argument
# should be a (space separated) list of build targets which use this package,
# if available.
#
# $1 is not checked for $COIN_SKIP_PROJECTS, since we only look into
# $COIN_PKG_CONFIG_PATH_UNINSTALLED.  When the content of this variable was
# setup in the base directory, $COIN_SKIP_PROJECTS has already been considered.

AC_DEFUN([AC_COIN_CHECK_PACKAGE_FALLBACK],
[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
AC_MSG_CHECKING([for COIN-OR package $1 (fallback)])

m4_tolower(coin_has_$1)=notGiven
m4_toupper($1_LIBS)=
m4_toupper($1_LIBS_INSTALLED)=
m4_toupper($1_CFLAGS)=
m4_toupper($1_CFLAGS_INSTALLED)=
m4_toupper($1_DATA)=
m4_toupper($1_DATA_INSTALLED)=
m4_toupper($1_PCLIBS)=
m4_toupper($1_PCREQUIRES)=

# initial list of dependencies is "$2", but we need to filter out version number specifications (= x, <= x, >= x, != x)
projtoprocess="m4_bpatsubsts([$2], [<?>?!?=[ 	]*[^ 	]+])"

# we first expand the list of projects to process by adding all dependencies just behind the project which depends on it
# further, we collect the list of corresponding .pc files, but do this in reverse order, because we need this order afterwards
# the latter we also do with .pc files corresponding to the installed projects, which will be needed to setup Makefiles for examples
# also, we setup the DATA variable
allproj=""
allpcfiles=""
allpcifiles=""
while test "x$projtoprocess" != x ; do

  for proj in $projtoprocess ; do
    # if $proj is available and configured, then a project-uninstalled.pc file should have been created, so search for it
    pcfile=""
    save_IFS="$IFS"
    IFS=":"
    for dir in $COIN_PKG_CONFIG_PATH_UNINSTALLED ; do
      # the base directory configure should have setup coin_subdirs.txt in a way that it does not contain projects that should be skipped, so we do not need to test this here again
      if test -r "$dir/${proj}-uninstalled.pc" ; then
        pcfile="$dir/$proj-uninstalled.pc"
        if test -r "$dir/${proj}.pc" ; then
          pcifile="$dir/${proj}.pc"
        else
          AC_MSG_WARN([Found $pcfile, but $dir/${proj}.pc is not available. This may break Makefile's of examples.])
          pcifile=
        fi
        break
      fi
    done
    IFS="$save_IFS"

    if test "x$pcfile" != x ; then
      # read dependencies from $pcfile and filter it
      projrequires=[`sed -n -e 's/Requires://gp' "$pcfile" | sed -e 's/<\{0,1\}>\{0,1\}=[ 	]\{0,\}[^ 	]\{1,\}//g'`]

      # add projrequires to the front of the list of projects that have to be processed next
      # at the same time, remove $proj from this list
      projtoprocess=[`echo $projtoprocess | sed -e "s/$proj/$projrequires/"`]

      # read DATA from $pcfile, if _DATA is still empty
      if test "x$m4_toupper($1_DATA)" = x ; then
        projdatadir=
        [pcfilemod=`sed -e '/[a-zA-Z]:/d' -e 's/datadir=\(.*\)/echo projdatadir=\\\\"\1\\\\"/g' $pcfile`]
        eval `sh -c "$pcfilemod"`
        m4_toupper($1_DATA)="$projdatadir"
      fi

      allproj="$allproj $proj"
      allpcfiles="$pcfile:$allpcfiles"

    else
      AC_MSG_RESULT([no, dependency $proj not available])
      allproj=fail
      break 2
    fi
    
    if test "x$pcifile" != x ; then
      allpcifiles="$pcifile:$allpcifiles"
      
      # read DATA_INSTALLED from $pcifile, if _DATA_INSTALLED is still empty
      if test "x$m4_toupper($1_DATA_INSTALLED)" = x ; then
        projdatadir=
        [pcifilemod=`sed -e '/[a-zA-Z]:/d' -e 's/datadir=\(.*\)/echo projdatadir=\\\\"\1\\\\"/g' $pcifile`]
        eval `sh -c "$pcifilemod"`
        if test "${CYGPATH_W}" != "echo"; then
          projdatadir="\`\$(CYGPATH_W) ${projdatadir} | sed -e 's/\\\\\\\\/\\\\\\\\\\\\\\\\/g'\`"
        fi
        m4_toupper($1_DATA_INSTALLED)="$projdatadir"
      fi
      
    fi

    break
  done

  # remove spaces on begin of $projtoprocess
  projtoprocess=`echo $projtoprocess | sed -e 's/^[ ]*//'`

done

if test "$allproj" != fail ; then

  # now go through the list of .pc files and assemble compiler and linker flags
  # important is here to obey the reverse order that has been setup before,
  # since then libraries that are required by several others should be after these other libraries
  pcfilesprocessed=""

  save_IFS="$IFS"
  IFS=":"
  for pcfile in $allpcfiles ; do

    # if $pcfile has been processed already, skip this round
    if test "x$pcfilesprocessed" != x ; then
      for pcfiledone in $pcfilesprocessed ; do
        if test "$pcfiledone" = "$pcfile" ; then
          continue 2
        fi
      done
    fi

    # modify .pc file to a shell script that prints shell commands for setting the compiler and library flags:
    #   replace "Libs:" by "echo projlibs="
    #   replace "Cflags:" by "echo projcflags="
    #   remove every line starting with <some word>:
    [pcfilemod=`sed -e 's/Libs:\(.*\)$/echo projlibs=\\\\"\1\\\\"/g' -e 's/Cflags:\(.*\)/echo projcflags=\\\\"\1\\\\"/g' -e '/^[a-zA-Z]*:/d' $pcfile`]

    # set projcflags and projlibs variables by running $pcfilemod
    # under mingw, the current IFS seem to make the : in the paths of the gfortran libs go away, so we temporarily set IFS back to its default
    projcflags=
    projlibs=
    IFS="$save_IFS"
    eval `sh -c "$pcfilemod"`
    IFS=":"

    # add CYGPATH_W cludge into include flags and set CFLAGS variable
    if test "${CYGPATH_W}" != "echo"; then
      projcflags=[`echo "$projcflags" | sed -e 's/-I\([^ ]*\)/-I\`${CYGPATH_W} \1\`/g'`]
    fi
    m4_toupper($1_CFLAGS)="$projcflags $m4_toupper($1_CFLAGS)"

    # set LIBS variable
    m4_toupper($1_LIBS)="$projlibs $m4_toupper($1_LIBS)"

    # remember that we have processed $pcfile
    pcfilesprocessed="$pcfilesprocessed:$pcfile"

  done
  IFS="$save_IFS"


  # now go through the list of .pc files for installed projects and assemble compiler and linker flags
  # important is here again to obey the reverse order that has been setup before,
  # since then libraries that are required by several others should be after these other libraries
  pcfilesprocessed=""

  save_IFS="$IFS"
  IFS=":"
  for pcfile in $allpcifiles ; do

    # if $pcfile has been processed already, skip this round
    if test "x$pcfilesprocessed" != x ; then
      for pcfiledone in $pcfilesprocessed ; do
        if test "$pcfiledone" = "$pcfile" ; then
          continue 2
        fi
      done
    fi

    # modify .pc file to a shell script that prints shell commands for setting the compiler and library flags:
    #   replace "Libs:" by "echo projlibs="
    #   replace "Cflags:" by "echo projcflags="
    #   remove every line starting with <some word>:
    [pcfilemod=`sed -e 's/Libs:\(.*\)$/echo projlibs=\\\\"\1\\\\"/g' -e 's/Cflags:\(.*\)/echo projcflags=\\\\"\1\\\\"/g' -e '/^[a-zA-Z]*:/d' $pcfile`]

    # set projcflags and projlibs variables by running $pcfilemod
    # under mingw, the current IFS seem to make the : in the paths of the gfortran libs go away, so we temporarily set IFS back to its default
    projcflags=
    projlibs=
    IFS="$save_IFS"
    eval `sh -c "$pcfilemod"`
    IFS=":"

    # add CYGPATH_W cludge into include flags and set CFLAGS variable
    if test "${CYGPATH_W}" != "echo"; then
      projcflags=[`echo "$projcflags" | sed -e 's/-I\([^ ]*\)/-I\`${CYGPATH_W} \1\`/g'`]
    fi
    m4_toupper($1_CFLAGS_INSTALLED)="$projcflags $m4_toupper($1_CFLAGS_INSTALLED)"

    # set LIBS variable
    m4_toupper($1_LIBS_INSTALLED)="$projlibs $m4_toupper($1_LIBS_INSTALLED)"
    
    # remember that we have processed $pcfile
    pcfilesprocessed="$pcfilesprocessed:$pcfile"

  done
  IFS="$save_IFS"


  # finish up
  m4_tolower(coin_has_$1)=yes
  AC_MSG_RESULT([yes])
  AC_DEFINE(m4_toupper(COIN_HAS_$1),[1],[Define to 1 if the $1 package is available])

  # adjust linker flags for (i)cl compiler
  # for the LIBS, we replace everything of the form "/somepath/name.lib" by "`$(CYGPATH_W) /somepath/`name.lib | sed -e s|\|/|g" (where we have to use excessive many \ to get the \ into the command line for cl),
  # for the LIBS_INSTALLED, we replace everything of the form "/somepath/" by "`$(CYGPATH_W) /somepath/`",
  #    everything of the form "-lname" by "libname.lib", and
  #    everything of the form "-Lpath" by "-libpath:`$(CYGPATH_W) path`
  if test x$coin_cxx_is_cl = xtrue || test x$coin_cc_is_cl = xtrue ;
  then
    m4_toupper($1_LIBS)=`echo " $m4_toupper($1_LIBS) " | [sed -e 's/ \(\/[^ ]*\/\)\([^ ]*\)\.lib / \`$(CYGPATH_W) \1 | sed -e "s|\\\\\\\\\\\\\\\\\\\\|\/|g"\`\2.lib /g']`
    m4_toupper($1_LIBS_INSTALLED)=`echo " $m4_toupper($1_LIBS_INSTALLED)" | [sed -e 's/ \(\/[^ ]*\/\)/ \`$(CYGPATH_W) \1\`/g' -e 's/ -l\([^ ]*\)/ lib\1.lib/g' -e 's/ -L\([^ ]*\)/ -libpath:\`$(CYGPATH_W) \1\`/g']`
  fi

  m4_toupper($1_PCREQUIRES)="$2"
  coin_foreach_w([myvar], [$3], [
    m4_toupper(myvar)_PCREQUIRES="$2 $m4_toupper(myvar)_PCREQUIRES"
    m4_toupper(myvar)_CFLAGS="$m4_toupper($1)_CFLAGS $m4_toupper(myvar)_CFLAGS"
    m4_toupper(myvar)_LIBS="$m4_toupper($1)_LIBS $m4_toupper(myvar)_LIBS"
    m4_toupper(myvar)_CFLAGS_INSTALLED="$m4_toupper($1)_CFLAGS_INSTALLED $m4_toupper(myvar)_CFLAGS_INSTALLED"
    m4_toupper(myvar)_LIBS_INSTALLED="$m4_toupper($1)_LIBS_INSTALLED $m4_toupper(myvar)_LIBS_INSTALLED"
  ])

fi

AM_CONDITIONAL(m4_toupper(COIN_HAS_$1),
               [test $m4_tolower(coin_has_$1) != notGiven &&
                test $m4_tolower(coin_has_$1) != skipping])

]) # AC_COIN_CHECK_PACKAGE_FALLBACK

###########################################################################
#                         COIN_CHECK_PACKAGE_BLAS                         #
###########################################################################

# This macro checks for a library containing the BLAS library.  It
# 1. checks the --with-blas argument
# 2. if --with-blas=BUILD has been specified goes to point 5
# 3. if --with-blas has been specified to a working library, sets BLAS_LIBS
#    to its value
# 4. tries standard libraries
# 5. calls COIN_CHECK_PACKAGE(Blas, [coinblas], [$1]) to check for
#    ThirdParty/Blas
# The makefile conditional and preprocessor macro COIN_HAS_BLAS is defined.
# BLAS_LIBS is set to the flags required to link with a Blas library.
# For each build target X in $1, X_LIBS is extended with $BLAS_LIBS.
# In case 3 and 4, the flags to link to Blas are added to X_PCLIBS too.
# In case 5, Blas is added to X_PCREQUIRES.

AC_DEFUN([AC_COIN_CHECK_PACKAGE_BLAS],
[
AC_ARG_WITH([blas],
            AC_HELP_STRING([--with-blas],
                           [specify BLAS library (or BUILD to enforce use of ThirdParty/Blas)]),
            [use_blas="$withval"], [use_blas=])

# if user specified --with-blas-lib, then we should give COIN_CHECK_PACKAGE
# preference
AC_ARG_WITH([blas-lib],,[use_blas=BUILD])

# Check if user supplied option makes sense
if test x"$use_blas" != x; then
  if test "$use_blas" = "BUILD"; then
    # we come to this later
    :
  elif test "$use_blas" != "no"; then
    coin_save_LIBS="$LIBS"
    LIBS="$use_blas $LIBS"
    if test "$F77" != unavailable ; then
      coin_need_flibs=no
      AC_MSG_CHECKING([whether user supplied BLASLIB=\"$use_blas\" works])
      AC_COIN_TRY_FLINK([daxpy],
                        [if test $coin_need_flibs = yes ; then
                           use_blas="$use_blas $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_blas])],
                        [AC_MSG_RESULT([no])
                         AC_MSG_ERROR([user supplied BLAS library \"$use_blas\" does not work])])
      use_blas="$use_blas $FLIBS"
    else
      AC_MSG_NOTICE([checking whether user supplied BLASLIB=\"$use_blas\" works with C linkage])
      AC_LANG_PUSH(C)
      AC_CHECK_FUNC([daxpy],[],[AC_MSG_ERROR([user supplied BLAS library \"$use_blas\" does not work])])
      AC_LANG_POP(C)
    fi
    LIBS="$coin_save_LIBS"
  fi
else
# Try to autodetect the library for blas based on build system
  #AC_MSG_CHECKING([default locations for BLAS])
  case $build in
    *-sgi-*) 
      AC_MSG_CHECKING([whether -lcomplib.sgimath has BLAS])
      coin_need_flibs=no
      coin_save_LIBS="$LIBS"
      LIBS="-lcomplib.sgimath $LIBS"
      AC_COIN_TRY_FLINK([daxpy],
                        [use_blas="-lcomplib.sgimath"
                         if test $coin_need_flibs = yes ; then
                           use_blas="$use_blas $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_blas])
                        ],
                        [AC_MSG_RESULT([no])])
      LIBS="$coin_save_LIBS"
      ;;

# Ideally, we'd use -library=sunperf, but it's an imperfect world. Studio
# cc doesn't recognise -library, it wants -xlic_lib. Studio 12 CC doesn't
# recognise -xlic_lib. Libtool doesn't like -xlic_lib anyway. Sun claims
# that CC and cc will understand -library in Studio 13. The main extra
# function of -xlic_lib and -library is to arrange for the Fortran run-time
# libraries to be linked for C++ and C. We can arrange that explicitly.
    *-*-solaris*)
      AC_MSG_CHECKING([for BLAS in libsunperf])
      coin_need_flibs=no
      coin_save_LIBS="$LIBS"
      LIBS="-lsunperf $FLIBS $LIBS"
      AC_COIN_TRY_FLINK([daxpy],
                        [use_blas='-lsunperf'
                         if test $coin_need_flibs = yes ; then
                           use_blas="$use_blas $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_blas])
                        ],
                        [AC_MSG_RESULT([no])])
      LIBS="$coin_save_LIBS"
      ;;
      
    *-cygwin* | *-mingw*)
      case "$CC" in
        clang* ) ;;
        cl* | */cl* | CL* | */CL* | icl* | */icl* | ICL* | */ICL*)
          coin_save_LIBS="$LIBS"
          LIBS="mkl_intel_c.lib mkl_sequential.lib mkl_core.lib $LIBS"
          if test "$F77" != unavailable ; then
            AC_MSG_CHECKING([for BLAS in MKL (32bit)])
            AC_COIN_TRY_FLINK([daxpy],
                              [use_blas='mkl_intel_c.lib mkl_sequential.lib mkl_core.lib'
                               AC_MSG_RESULT([yes: $use_blas])
                              ],
                              [AC_MSG_RESULT([no])])
          else
            AC_MSG_NOTICE([for BLAS in MKL (32bit) using C linkage])
            AC_LANG_PUSH(C)
            AC_CHECK_FUNC([daxpy],[use_blas='mkl_intel_c.lib mkl_sequential.lib mkl_core.lib'])
            AC_LANG_POP(C)
          fi
          LIBS="$coin_save_LIBS"
          
          if test "x$use_blas" = x ; then
            LIBS="mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib $LIBS"
            if test "$F77" != unavailable ; then
              AC_MSG_CHECKING([for BLAS in MKL (64bit)])
              AC_COIN_TRY_FLINK([daxpy],
                                [use_blas='mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib'
                                 AC_MSG_RESULT([yes: $use_blas])
                                ],
                                [AC_MSG_RESULT([no])])
            else
              AC_MSG_NOTICE([for BLAS in MKL (64bit) using C linkage])
              # unset cached outcome of test with 32bit MKL
              unset ac_cv_func_daxpy
              AC_LANG_PUSH(C)
              AC_CHECK_FUNC([daxpy],[use_blas='mkl_intel_lp64.lib mkl_sequential.lib mkl_core.lib'])
              AC_LANG_POP(C)
            fi
            LIBS="$coin_save_LIBS"
          fi
          ;;
      esac
      ;;
      
     *-darwin*)
      AC_MSG_CHECKING([for BLAS in Veclib])
      coin_need_flibs=no
      coin_save_LIBS="$LIBS"
      LIBS="-framework Accelerate $LIBS"
      AC_COIN_TRY_FLINK([daxpy],
                        [use_blas='-framework Accelerate'
                         if test $coin_need_flibs = yes ; then
                           use_blas="$use_blas $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_blas])
                        ],
                        [AC_MSG_RESULT([no])])
      LIBS="$coin_save_LIBS"
      ;;
  esac

  if test -z "$use_blas" ; then
    AC_MSG_CHECKING([whether -lblas has BLAS])
    coin_need_flibs=no
    coin_save_LIBS="$LIBS"
    LIBS="-lblas $LIBS"
    AC_COIN_TRY_FLINK([daxpy],
                      [use_blas='-lblas'
                       if test $coin_need_flibs = yes ; then
                         use_blas="$use_blas $FLIBS"
                       fi
                       AC_MSG_RESULT([yes: $use_blas])
                      ],
                      [AC_MSG_RESULT([no])])
    LIBS="$coin_save_LIBS"
  fi

  # If we have no other ideas, consider building BLAS.
  if test -z "$use_blas" ; then
    use_blas=BUILD
  fi
fi

if test "x$use_blas" = xBUILD ; then
  AC_COIN_CHECK_PACKAGE(Blas, [coinblas], [$1])
  
elif test "x$use_blas" != x && test "$use_blas" != no; then
  coin_has_blas=yes
  AM_CONDITIONAL([COIN_HAS_BLAS],[test 0 = 0])
  AC_DEFINE([COIN_HAS_BLAS],[1], [If defined, the BLAS Library is available.])
  BLAS_LIBS="$use_blas"
  BLAS_CFLAGS=
  BLAS_DATA=
  AC_SUBST(BLAS_LIBS)
  AC_SUBST(BLAS_CFLAGS)
  AC_SUBST(BLAS_DATA)
  coin_foreach_w([myvar], [$1], [
    m4_toupper(myvar)_PCLIBS="$BLAS_LIBS $m4_toupper(myvar)_PCLIBS"
    m4_toupper(myvar)_LIBS="$BLAS_LIBS $m4_toupper(myvar)_LIBS"
    m4_toupper(myvar)_LIBS_INSTALLED="$BLAS_LIBS $m4_toupper(myvar)_LIBS_INSTALLED"
  ])
  
else
  coin_has_blas=no
  AM_CONDITIONAL([COIN_HAS_BLAS],[test 0 = 1])
fi

coin_foreach_w([myvar], [$1], [
  AC_SUBST(m4_toupper(myvar)_PCLIBS)
  AC_SUBST(m4_toupper(myvar)_LIBS)
  AC_SUBST(m4_toupper(myvar)_LIBS_INSTALLED)
])

]) # AC_COIN_CHECK_PACKAGE_BLAS

###########################################################################
#                       COIN_CHECK_PACKAGE_LAPACK                         #
###########################################################################

# This macro checks for a library containing the LAPACK library.  It
# 1. checks the --with-lapack argument
# 2. if --with-lapack=BUILD has been specified goes to point 5
# 3. if --with-lapack has been specified to a working library, sets
#    LAPACK_LIBS to its value
# 4. tries standard libraries
# 5. calls COIN_CHECK_PACKAGE(Lapack, [coinlapack], [$1]) to check for
#    ThirdParty/Lapack
# The makefile conditional and preprocessor macro COIN_HAS_LAPACK is defined.
# LAPACK_LIBS is set to the flags required to link with a Lapack library.
# For each build target X in $1, X_LIBS is extended with $LAPACK_LIBS.
# In case 3 and 4, the flags to link to Lapack are added to X_PCLIBS too.
# In case 5, Lapack is added to X_PCREQUIRES.
#
# TODO: Lapack usually depends on Blas, so if we check for a system lapack library,
#   shouldn't we include AC_COIN_CHECK_PACKAGE_BLAS first?
#   However, if we look for coinlapack via AC_COIN_CHECK_PACKAGE(Lapack, [coinlapack], [$1]),
#   then we will get Blas as dependency of coinlapack.

AC_DEFUN([AC_COIN_CHECK_PACKAGE_LAPACK],
[
AC_ARG_WITH([lapack],
            AC_HELP_STRING([--with-lapack],
                           [specify LAPACK library (or BUILD to enforce use of ThirdParty/Lapack)]),
            [use_lapack=$withval], [use_lapack=])

#if user specified --with-lapack-lib, then we should give COIN_HAS_PACKAGE preference
AC_ARG_WITH([lapack-lib],,[use_lapack=BUILD])

# Check if user supplied option makes sense
if test x"$use_lapack" != x; then
  if test "$use_lapack" = "BUILD"; then
    # we come to this later
    :
  elif test "$use_lapack" != no; then
    use_lapack="$use_lapack $BLAS_LIBS"
    coin_save_LIBS="$LIBS"
    LIBS="$use_lapack $LIBS"
    if test "$F77" != unavailable; then
      AC_MSG_CHECKING([whether user supplied LAPACKLIB=\"$use_lapack\" works])
      coin_need_flibs=no
      AC_COIN_TRY_FLINK([dsyev],
                        [if test $coin_need_flibs = yes ; then
                           use_lapack="$use_lapack $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_lapack])
                        ],
                        [AC_MSG_RESULT([no])
                         AC_MSG_ERROR([user supplied LAPACK library \"$use_lapack\" does not work])])
    else
      AC_MSG_NOTICE([whether user supplied LAPACKLIB=\"$use_lapack\" works with C linkage])
      AC_LANG_PUSH(C)
      AC_CHECK_FUNC([dsyev],[],[AC_MSG_ERROR([user supplied LAPACK library \"$use_lapack\" does not work])])
      AC_LANG_POP(C)
    fi
    LIBS="$coin_save_LIBS"
  fi
else
  if test x$coin_has_blas = xyes; then
    # First try to see if LAPACK is already available with BLAS library
    coin_save_LIBS="$LIBS"
    LIBS="$BLAS_LIBS $LIBS"
    if test "$F77" != unavailable; then
      coin_need_flibs=no
      AC_MSG_CHECKING([whether LAPACK is already available with BLAS library])
      AC_COIN_TRY_FLINK([dsyev],
                        [use_lapack="$BLAS_LIBS"
                         if test $coin_need_flibs = yes ; then
                           use_lapack="$use_lapack $FLIBS"
                         fi
                         AC_MSG_RESULT([yes: $use_lapack])
                        ],
                        [AC_MSG_RESULT([no])])
    else
      AC_MSG_NOTICE([checking whether LAPACK is already available with BLAS library])
      AC_LANG_PUSH(C)
      AC_CHECK_FUNC([dsyev],[use_lapack="$BLAS_LIBS"])
      AC_LANG_POP(C)
    fi
    LIBS="$coin_save_LIBS"
  fi
  if test -z "$use_lapack"; then
    # Try to autodetect the library for lapack based on build system
    case $build in
      # TODO: Is this check actually needed here, since -lcomplib.sigmath should have been recognized as Blas library,
      #       and above it is checked whether the Blas library already contains Lapack
      *-sgi-*) 
        AC_MSG_CHECKING([whether -lcomplib.sgimath has LAPACK])
        coin_save_LIBS="$LIBS"
        coin_need_flibs=no
        LIBS="-lcomplib.sgimath $BLAS_LIBS $LIBS"
        AC_COIN_TRY_FLINK([dsyev],
                          [use_lapack="-lcomplib.sgimath $BLAS_LIBS"
                           if test $coin_need_flibs = yes ; then
                             use_lapack="$use_lapack $FLIBS"
                           fi
                           AC_MSG_RESULT([yes: $use_lapack])
                          ],
                          [AC_MSG_RESULT([no])])
        LIBS="$coin_save_LIBS"
        ;;

      # See comments in COIN_CHECK_PACKAGE_BLAS.
      # TODO: Is this check actually needed here, since -lsunperf should have been recognized as Blas library,
      #       and above it is checked whether the Blas library already contains Lapack
      *-*-solaris*)
        AC_MSG_CHECKING([for LAPACK in libsunperf])
        coin_need_flibs=no
        coin_save_LIBS="$LIBS"
        LIBS="-lsunperf $BLAS_LIBS $FLIBS $LIBS"
        AC_COIN_TRY_FLINK([dsyev],
                          [use_lapack='-lsunperf $BLAS_LIBS'
                           if test $coin_need_flibs = yes ; then
                             use_lapack="$use_lapack $FLIBS"
                           fi
                           AC_MSG_RESULT([yes: $use_lapack])
                          ],
                          [AC_MSG_RESULT([no])])
        LIBS="$coin_save_LIBS"
        ;;
        # On cygwin, do this check only if doscompile is disabled. The prebuilt library
        # will want to link with cygwin, hence won't run standalone in DOS.
    esac
  fi

  if test -z "$use_lapack" ; then
    AC_MSG_CHECKING([whether -llapack has LAPACK])
    coin_need_flibs=no
    coin_save_LIBS="$LIBS"
    LIBS="-llapack $BLAS_LIBS $LIBS"
    AC_COIN_TRY_FLINK([dsyev],
                      [use_lapack='-llapack'
                       if test $coin_need_flibs = yes ; then
                         use_lapack="$use_lapack $FLIBS"
                       fi
                       AC_MSG_RESULT([yes: $use_lapack])
                      ],
                      [AC_MSG_RESULT([no])])
    LIBS="$coin_save_LIBS"
  fi

  # If we have no other ideas, consider building LAPACK.
  if test -z "$use_lapack" ; then
    use_lapack=BUILD
  fi
fi

if test "x$use_lapack" = xBUILD ; then
  AC_COIN_CHECK_PACKAGE(Lapack, [coinlapack], [$1])

elif test "x$use_lapack" != x && test "$use_lapack" != no; then
  coin_has_lapack=yes
  AM_CONDITIONAL([COIN_HAS_LAPACK],[test 0 = 0])
  AC_DEFINE([COIN_HAS_LAPACK],[1], [If defined, the LAPACK Library is available.])
  LAPACK_LIBS="$use_lapack"
  LAPACK_CFLAGS=
  LAPACK_DATA=
  AC_SUBST(LAPACK_LIBS)
  AC_SUBST(LAPACK_CFLAGS)
  AC_SUBST(LAPACK_DATA)
  coin_foreach_w([myvar], [$1], [
    m4_toupper(myvar)_PCLIBS="$LAPACK_LIBS $m4_toupper(myvar)_PCLIBS"
    m4_toupper(myvar)_LIBS="$LAPACK_LIBS $m4_toupper(myvar)_LIBS"
    m4_toupper(myvar)_LIBS_INSTALLED="$LAPACK_LIBS $m4_toupper(myvar)_LIBS_INSTALLED"
  ])
  
else
  coin_has_lapack=no
  AM_CONDITIONAL([COIN_HAS_LAPACK],[test 0 = 1])
fi

coin_foreach_w([myvar], [$1], [
  AC_SUBST(m4_toupper(myvar)_PCLIBS)
  AC_SUBST(m4_toupper(myvar)_LIBS)
  AC_SUBST(m4_toupper(myvar)_LIBS_INSTALLED)
])

]) # AC_COIN_CHECK_PACKAGE_LAPACK