summaryrefslogtreecommitdiff
path: root/configure.ac
blob: a58403b3b611c5401b025af81f6fef5742a99435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; fill-column: 102 -*-
dnl configure.ac serves as input for the GNU autoconf package
dnl in order to create a configure script.

# The version number in the second argument to AC_INIT should be four numbers separated by
# periods. Some parts of the code requires the first one to be less than 128 and the others to be less
# than 256. The four numbers can optionally be followed by a period and a free-form string containing
# no spaces or periods, like "frobozz-mumble-42" or "alpha0". If the free-form string ends with one or
# several non-alphanumeric characters, those are split off and used only for the
# ABOUTBOXPRODUCTVERSIONSUFFIX in openoffice.lst. Why that is necessary, no idea.

AC_INIT([Collabora Office],[6.0.10.32],[],[],[https://collaboraoffice.com/])

AC_PREREQ([2.59])

if test -n "$BUILD_TYPE"; then
    AC_MSG_ERROR([You have sourced config_host.mk in this shell.  This may lead to trouble, please run in a fresh (login) shell.])
fi

save_CC=$CC
save_CXX=$CXX

BUILD_TYPE="LibO"
SCPDEFS=""
GIT_NEEDED_SUBMODULES=""
LO_PATH= # used by path_munge to construct a PATH variable

FilterLibs()
{
    filteredlibs=
    for f in $1; do
        case "$f" in
            # let's start with Fedora's paths for now
            -L/lib|-L/lib/|-L/lib64|-L/lib64/|-L/usr/lib|-L/usr/lib/|-L/usr/lib64|-L/usr/lib64/)
                # ignore it: on UNIXoids it is searched by default anyway
                # but if it's given explicitly then it may override other paths
                # (on Mac OS X it would be an error to use it instead of SDK)
                ;;
            *)
                filteredlibs="$filteredlibs $f"
                ;;
        esac
    done
}

PathFormat()
{
    formatted_path="$1"
    if test "$build_os" = "cygwin"; then
        pf_conv_to_dos=
        # spaces,parentheses,brackets,braces are problematic in pathname
        # so are backslashes
        case "$formatted_path" in
            *\ * | *\)* | *\(* | *\{* | *\}* | *\[* | *\]* | *\\* )
                pf_conv_to_dos="yes"
            ;;
        esac
        if test "$pf_conv_to_dos" = "yes"; then
            if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
                formatted_path=`cygpath -sm "$formatted_path"`
            else
                formatted_path=`cygpath -d "$formatted_path"`
            fi
            if test $? -ne 0;  then
                AC_MSG_ERROR([path conversion failed for "$1".])
            fi
        fi
        fp_count_colon=`echo "$formatted_path" | $GREP -c "[:]"`
        fp_count_slash=`echo "$formatted_path" | $GREP -c "[/]"`
        if test "$fp_count_slash$fp_count_colon" != "00"; then
            if test "$fp_count_colon" = "0"; then
                new_formatted_path=`realpath "$formatted_path"`
                if test $? -ne 0;  then
                    AC_MSG_WARN([realpath failed for "$1", not necessarily a problem.])
                else
                    formatted_path="$new_formatted_path"
                fi
            fi
            formatted_path=`cygpath -m "$formatted_path"`
            if test $? -ne 0;  then
                AC_MSG_ERROR([path conversion failed for "$1".])
            fi
        fi
    fi
}

AbsolutePath()
{
    # There appears to be no simple and portable method to get an absolute and
    # canonical path, so we try creating the directory if does not exist and
    # utilizing the shell and pwd.
    rel="$1"
    absolute_path=""
    test ! -e "$rel" && mkdir -p "$rel"
    if test -d "$rel" ; then
        cd "$rel" || AC_MSG_ERROR([absolute path resolution failed for "$rel".])
        absolute_path="$(pwd)"
        cd - > /dev/null
    else
        AC_MSG_ERROR([Failed to resolve absolute path.  "$rel" does not exist or is not a directory.])
    fi
}

rm -f warn
have_WARNINGS="no"
add_warning()
{
    if test "$have_WARNINGS" = "no"; then
        echo "*************************************" > warn
        have_WARNINGS="yes"
        if which tput >/dev/null 2>/dev/null && test `tput colors` -ge 8; then
            dnl <esc> as actual byte (U+1b), [ escaped using quadrigraph @<:@
            COLORWARN='*@<:@1;33;40m WARNING @<:@0m:'
        else
            COLORWARN="* WARNING :"
        fi
    fi
    echo "$COLORWARN $@" >> warn
}

dnl Some Mac User have the bad habbit of letting a lot fo crap
dnl accumulate in their PATH and even adding stuff in /usr/local/bin
dnl that confuse the build.
dnl For the ones that use LODE, let's be nice and protect them
dnl from themselves

mac_sanitize_path()
{
    mac_path="$LODE_HOME/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin"
dnl a common but nevertheless necessary thing that may be in a fancy
dnl path location is git, so make sure we have it
    mac_git_path=`which git 2>/dev/null`
    if test -n "$mac_git_path" -a -x "$mac_git_path" -a "$mac_git_path" != "/usr/bin/git" ; then
        mac_path="$mac_path:`dirname $mac_git_path`"
    fi
dnl a not so common but nevertheless quite helpful thing that may be in a fancy
dnl path location is gpg, so make sure we find it
    mac_gpg_path=`which gpg 2>/dev/null`
    if test -n "$mac_gpg_path" -a -x "$mac_gpg_path" -a "$mac_gpg_path" != "/usr/bin/gpg" ; then
        mac_path="$mac_path:`dirname $mac_gpg_path`"
    fi
    PATH="$mac_path"
    unset mac_path
    unset mac_git_path
    unset mac_gpg_path
}

echo "********************************************************************"
echo "*"
echo "*   Running ${PACKAGE_NAME} build configuration."
echo "*"
echo "********************************************************************"
echo ""

dnl ===================================================================
dnl checks build and host OSes
dnl do this before argument processing to allow for platform dependent defaults
dnl ===================================================================
AC_CANONICAL_HOST

AC_MSG_CHECKING([for product name])
PRODUCTNAME="AC_PACKAGE_NAME"
if test -n "$with_product_name" -a "$with_product_name" != no; then
    PRODUCTNAME="$with_product_name"
fi
if test "$enable_release_build" = "" -o "$enable_release_build" = "no"; then
    PRODUCTNAME="${PRODUCTNAME}Dev"
fi
AC_MSG_RESULT([$PRODUCTNAME])
AC_SUBST(PRODUCTNAME)
PRODUCTNAME_WITHOUT_SPACES=$(echo "$PRODUCTNAME" | sed 's/ //g')
AC_SUBST(PRODUCTNAME_WITHOUT_SPACES)

dnl ===================================================================
dnl Our version is defined by the AC_INIT() at the top of this script.
dnl ===================================================================

AC_MSG_CHECKING([for package version])
if test -n "$with_package_version" -a "$with_package_version" != no; then
    PACKAGE_VERSION="$with_package_version"
fi
AC_MSG_RESULT([$PACKAGE_VERSION])

set `echo "$PACKAGE_VERSION" | sed "s/\./ /g"`

LIBO_VERSION_MAJOR=$1
LIBO_VERSION_MINOR=$2
LIBO_VERSION_MICRO=$3
LIBO_VERSION_PATCH=$4

# The CFBundleShortVersionString in Info.plist consists of three integers, so encode the third
# as the micro version times 1000 plus the patch number. Unfortunately the LIBO_VERSION_SUFFIX can be anything so
# no way to encode that into an integer in general.
MACOSX_BUNDLE_SHORTVERSION=$LIBO_VERSION_MAJOR.$LIBO_VERSION_MINOR.`expr $LIBO_VERSION_MICRO '*' 1000 + $LIBO_VERSION_PATCH`

LIBO_VERSION_SUFFIX=$5
# Split out LIBO_VERSION_SUFFIX_SUFFIX... horrible crack. But apparently wanted separately in
# openoffice.lst as ABOUTBOXPRODUCTVERSIONSUFFIX. Note that the double brackets are for m4's sake,
# they get undoubled before actually passed to sed.
LIBO_VERSION_SUFFIX_SUFFIX=`echo "$LIBO_VERSION_SUFFIX" | sed -e 's/.*[[a-zA-Z0-9]]\([[^a-zA-Z0-9]]*\)$/\1/'`
test -n "$LIBO_VERSION_SUFFIX_SUFFIX" && LIBO_VERSION_SUFFIX="${LIBO_VERSION_SUFFIX%${LIBO_VERSION_SUFFIX_SUFFIX}}"
# LIBO_VERSION_SUFFIX, if non-empty, should include the period separator
test -n "$LIBO_VERSION_SUFFIX" && LIBO_VERSION_SUFFIX=".$LIBO_VERSION_SUFFIX"

AC_SUBST(LIBO_VERSION_MAJOR)
AC_SUBST(LIBO_VERSION_MINOR)
AC_SUBST(LIBO_VERSION_MICRO)
AC_SUBST(LIBO_VERSION_PATCH)
AC_SUBST(MACOSX_BUNDLE_SHORTVERSION)
AC_SUBST(LIBO_VERSION_SUFFIX)
AC_SUBST(LIBO_VERSION_SUFFIX_SUFFIX)

AC_DEFINE_UNQUOTED(LIBO_VERSION_MAJOR,$LIBO_VERSION_MAJOR)
AC_DEFINE_UNQUOTED(LIBO_VERSION_MINOR,$LIBO_VERSION_MINOR)
AC_DEFINE_UNQUOTED(LIBO_VERSION_MICRO,$LIBO_VERSION_MICRO)
AC_DEFINE_UNQUOTED(LIBO_VERSION_PATCH,$LIBO_VERSION_PATCH)

LIBO_THIS_YEAR=`date +%Y`
AC_DEFINE_UNQUOTED(LIBO_THIS_YEAR,$LIBO_THIS_YEAR)

dnl ===================================================================
dnl Product version
dnl ===================================================================
AC_MSG_CHECKING([for product version])
PRODUCTVERSION="$LIBO_VERSION_MAJOR.$LIBO_VERSION_MINOR"
AC_MSG_RESULT([$PRODUCTVERSION])
AC_SUBST(PRODUCTVERSION)

AC_PROG_EGREP
# AC_PROG_EGREP doesn't set GREP on all systems as well
AC_PATH_PROG(GREP, grep)

BUILDDIR=`pwd`
cd $srcdir
SRC_ROOT=`pwd`
cd $BUILDDIR
x_Cygwin=[\#]

dnl ======================================
dnl Required GObject introspection version
dnl ======================================
INTROSPECTION_REQUIRED_VERSION=1.32.0

dnl ===================================================================
dnl Search all the common names for GNU Make
dnl ===================================================================
AC_MSG_CHECKING([for GNU Make])

# try to use our own make if it is available and GNUMAKE was not already defined
if test -z "$GNUMAKE"; then
    if test -n "$LODE_HOME" -a -x "$LODE_HOME/opt/bin/make" ; then
        GNUMAKE="$LODE_HOME/opt/bin/make"
    elif test -x "/opt/lo/bin/make"; then
        GNUMAKE="/opt/lo/bin/make"
    fi
fi

GNUMAKE_WIN_NATIVE=
for a in "$MAKE" "$GNUMAKE" make gmake gnumake; do
    if test -n "$a"; then
        $a --version 2> /dev/null | grep GNU  2>&1 > /dev/null
        if test $? -eq 0;  then
            if test "$build_os" = "cygwin"; then
                if test -n "$($a -v | grep 'Built for Windows')" ; then
                    GNUMAKE="$(cygpath -m "$(which "$(cygpath -u $a)")")"
                    GNUMAKE_WIN_NATIVE="TRUE"
                else
                    GNUMAKE=`which $a`
                fi
            else
                GNUMAKE=`which $a`
            fi
            break
        fi
    fi
done
AC_MSG_RESULT($GNUMAKE)
if test -z "$GNUMAKE"; then
    AC_MSG_ERROR([not found. install GNU Make.])
else
    if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
        AC_MSG_NOTICE([Using a native Win32 GNU Make version.])
    fi
fi

win_short_path_for_make()
{
    local_short_path="$1"
    if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
        cygpath -sm "$local_short_path"
    else
        cygpath -u "$(cygpath -d "$local_short_path")"
    fi
}


if test "$build_os" = "cygwin"; then
    PathFormat "$SRC_ROOT"
    SRC_ROOT="$formatted_path"
    PathFormat "$BUILDDIR"
    BUILDDIR="$formatted_path"
    x_Cygwin=
    AC_MSG_CHECKING(for explicit COMSPEC)
    if test -z "$COMSPEC"; then
        AC_MSG_ERROR([COMSPEC not set in environment, please set it and rerun])
    else
        AC_MSG_RESULT([found: $COMSPEC])
    fi
fi

AC_SUBST(SRC_ROOT)
AC_SUBST(BUILDDIR)
AC_SUBST(x_Cygwin)
AC_DEFINE_UNQUOTED(SRCDIR,"$SRC_ROOT")
AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")

if test "z$EUID" = "z0" -a "`uname -o 2>/dev/null`" = "Cygwin"; then
    AC_MSG_ERROR([You must build LibreOffice as a normal user - not using an administrative account])
fi

# need sed in os checks...
AC_PATH_PROGS(SED, sed)
if test -z "$SED"; then
    AC_MSG_ERROR([install sed to run this script])
fi

# Set the ENABLE_LTO variable
# ===================================================================
AC_MSG_CHECKING([whether to use link-time optimization])
if test -n "$enable_lto" -a "$enable_lto" != "no"; then
    ENABLE_LTO="TRUE"
    AC_MSG_RESULT([yes])
    AC_DEFINE(STATIC_LINKING)
else
    ENABLE_LTO=""
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_LTO)

AC_ARG_ENABLE(fuzz-options,
    AS_HELP_STRING([--enable-fuzz-options],
        [Randomly enable or disable each of those configurable options
         that are supposed to be freely selectable without interdependencies,
         or where bad interaction from interdependencies is automatically avoided.])
)

dnl ===================================================================
dnl When building for Android, --with-android-ndk,
dnl --with-android-ndk-toolchain-version and --with-android-sdk are
dnl mandatory
dnl ===================================================================

AC_ARG_WITH(android-ndk,
    AS_HELP_STRING([--with-android-ndk],
        [Specify location of the Android Native Development Kit. Mandatory when building for Android.]),
,)

AC_ARG_WITH(android-ndk-toolchain-version,
    AS_HELP_STRING([--with-android-ndk-toolchain-version],
        [Specify which toolchain version to use, of those present in the
        Android NDK you are using. The default (and only supported version currently) is "clang5.0"]),,
        with_android_ndk_toolchain_version=clang5.0)

AC_ARG_WITH(android-sdk,
    AS_HELP_STRING([--with-android-sdk],
        [Specify location of the Android SDK. Mandatory when building for Android.]),
,)

ANDROID_NDK_HOME=
if test -z "$with_android_ndk" -a -e "$SRC_ROOT/external/android-ndk" -a "$build" != "$host"; then
    with_android_ndk="$SRC_ROOT/external/android-ndk"
fi
if test -n "$with_android_ndk"; then
    ANDROID_NDK_HOME=$with_android_ndk

    # Set up a lot of pre-canned defaults

    if test ! -f $ANDROID_NDK_HOME/RELEASE.TXT; then
        if test ! -f $ANDROID_NDK_HOME/source.properties; then
            AC_MSG_ERROR([Unrecognized Android NDK. Missing RELEASE.TXT or source.properties file in $ANDROID_NDK_HOME.])
        fi
        ANDROID_NDK_VERSION=`sed -n -e 's/Pkg.Revision = //p' $ANDROID_NDK_HOME/source.properties`
    else
        ANDROID_NDK_VERSION=`cut -f1 -d' ' <$ANDROID_NDK_HOME/RELEASE.TXT`
    fi
    if test -z "$ANDROID_NDK_VERSION";  then
        AC_MSG_ERROR([Failed to determine Android NDK version. Please check your installation.])
    fi
    case $ANDROID_NDK_VERSION in
    r9*|r10*)
        AC_MSG_ERROR([Building for Android is only supported with NDK versions above 16.x*])
        ;;
    11.1.*|12.1.*|13.1.*|14.1.*)
        AC_MSG_ERROR([Building for Android is only supported with NDK versions above 16.x.*])
        ;;
    16.*)
        ;;
    *)
        AC_MSG_WARN([Untested Android NDK version $ANDROID_NDK_VERSION, only version 16.* have been used successfully. Proceed at your own risk.])
        add_warning "Untested Android NDK version $ANDROID_NDK_VERSION, only version 16.* have been used successfully. Proceed at your own risk."
        ;;
    esac

    ANDROID_API_LEVEL=14
    android_cpu=$host_cpu
    ANDROID_ARCH=$android_cpu
    if test $host_cpu = arm; then
        android_platform_prefix=$android_cpu-linux-androideabi
        android_gnu_prefix=$android_platform_prefix
        LLVM_TRIPLE=armv7-none-linux-androideabi
        ANDROID_APP_ABI=armeabi-v7a
        ANDROIDCFLAGS="-mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon -Wl,--fix-cortex-a8"
    elif test $host_cpu = aarch64; then
        android_platform_prefix=$android_cpu-linux-android
        android_gnu_prefix=$android_platform_prefix
        LLVM_TRIPLE=aarch64-none-linux-android
        # minimum android version that supports aarch64
        ANDROID_API_LEVEL=21
        ANDROID_APP_ABI=arm64-v8a
        ANDROID_ARCH=arm64
    elif test $host_cpu = mips; then
        android_platform_prefix=mipsel-linux-android
        android_gnu_prefix=$android_platform_prefix
        LLVM_TRIPLE=mipsel-none-linux-android
        ANDROID_APP_ABI=mips
    else
        # host_cpu is something like "i386" or "i686" I guess, NDK uses
        # "x86" in some contexts
        android_cpu=x86
        android_platform_prefix=$android_cpu
        android_gnu_prefix=i686-linux-android
        LLVM_TRIPLE=i686-none-linux-android
        ANDROID_APP_ABI=x86
        ANDROID_ARCH=$android_cpu
        ANDROIDCFLAGS="-march=atom"
    fi

    case "$with_android_ndk_toolchain_version" in
    clang5.0)
        ANDROID_GCC_TOOLCHAIN_VERSION=4.9
        ANDROID_BINUTILS_DIR=$ANDROID_NDK_HOME/toolchains/$android_platform_prefix-$ANDROID_GCC_TOOLCHAIN_VERSION
        ANDROID_COMPILER_DIR=$ANDROID_NDK_HOME/toolchains/llvm
        ;;
    *)
        AC_MSG_ERROR([Unrecognized value for the --with-android-ndk-toolchain-version option. Building for Android is only supported with Clang 5.*])
    esac

    if test ! -d $ANDROID_BINUTILS_DIR; then
        AC_MSG_ERROR([No directory $ANDROID_BINUTILS_DIR])
    elif test ! -d $ANDROID_COMPILER_DIR; then
        AC_MSG_ERROR([No directory $ANDROID_COMPILER_DIR])
    fi

    # NDK 15 or later toolchain is 64bit-only, except for Windows that we don't support. Using a 64-bit
    # linker is required if you compile large parts of the code with -g. A 32-bit linker just won't
    # manage to link the (app-specific) single huge .so that is built for the app in
    # android/source/ if there is debug information in a significant part of the object files.
    # (A 64-bit ld.gold grows to much over 10 gigabytes of virtual space when linking such a .so if
    # all objects have been built with debug information.)
    case $build_os in
    linux-gnu*)
        ndk_build_os=linux
        ;;
    darwin*)
        ndk_build_os=darwin
        ;;
    *)
        AC_MSG_ERROR([We only support building for Android from Linux or OS X])
        ;;
    esac
    ANDROID_COMPILER_BIN=$ANDROID_COMPILER_DIR/prebuilt/$ndk_build_os-x86_64/bin
    ANDROID_BINUTILS_PREBUILT_ROOT=$ANDROID_BINUTILS_DIR/prebuilt/$ndk_build_os-x86_64
    AC_SUBST(ANDROID_BINUTILS_PREBUILT_ROOT)

    test -z "$SYSBASE" && SYSBASE=$ANDROID_NDK_HOME/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_ARCH}
    test -z "$AR" && AR=$ANDROID_BINUTILS_PREBUILT_ROOT/bin/$android_gnu_prefix-ar
    test -z "$NM" && NM=$ANDROID_BINUTILS_PREBUILT_ROOT/bin/$android_gnu_prefix-nm
    test -z "$OBJDUMP" && OBJDUMP=$ANDROID_BINUTILS_PREBUILT_ROOT/bin/$android_gnu_prefix-objdump
    test -z "$RANLIB" && RANLIB=$ANDROID_BINUTILS_PREBUILT_ROOT/bin/$android_gnu_prefix-ranlib
    test -z "$STRIP" && STRIP=$ANDROID_BINUTILS_PREBUILT_ROOT/bin/$android_gnu_prefix-strip

    ANDROIDCFLAGS="$ANDROIDCFLAGS -gcc-toolchain $ANDROID_BINUTILS_PREBUILT_ROOT -target $LLVM_TRIPLE$ANDROID_API_LEVEL -no-canonical-prefixes"
    # android is using different sysroots for compilation and linking, but as
    # there is no full separation in configure and elsewehere, use isystem for
    # compilation stuff and sysroot for linking
    ANDROIDCFLAGS="$ANDROIDCFLAGS -D__ANDROID_API__=$ANDROID_API_LEVEL -isystem $ANDROID_NDK_HOME/sysroot/usr/include"
    ANDROIDCFLAGS="$ANDROIDCFLAGS -isystem $ANDROID_NDK_HOME/sysroot/usr/include/$android_gnu_prefix"
    ANDROIDCFLAGS="$ANDROIDCFLAGS --sysroot=$SYSBASE -ffunction-sections -fdata-sections -Qunused-arguments"
    ANDROIDCFLAGS="$ANDROIDCFLAGS -L$ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++/libs/$ANDROID_APP_ABI"
    if test "$ENABLE_LTO" = TRUE; then
        # -flto comes from com_GCC_defs.mk, too, but we need to make sure it gets passed as part of
        # $CC and $CXX when building external libraries
        ANDROIDCFLAGS="$ANDROIDCFLAGS -flto -fuse-linker-plugin -O2"
    fi

    ANDROIDCXXFLAGS="$ANDROIDCFLAGS -I$ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++/include -I$ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++abi/include -I$ANDROID_NDK_HOME/sources/android/support/include -std=c++11"

    if test -z "$CC"; then
        CC="$ANDROID_COMPILER_BIN/clang $ANDROIDCFLAGS"
    fi
    if test -z "$CXX"; then
        CXX="$ANDROID_COMPILER_BIN/clang++ $ANDROIDCXXFLAGS"
    fi

    # remember to download the ownCloud Android library later
    BUILD_TYPE="$BUILD_TYPE OWNCLOUD_ANDROID_LIB"
fi
AC_SUBST(ANDROID_NDK_HOME)
AC_SUBST(ANDROID_APP_ABI)
AC_SUBST(ANDROID_GCC_TOOLCHAIN_VERSION)

dnl ===================================================================
dnl --with-android-sdk
dnl ===================================================================
ANDROID_SDK_HOME=
if test -z "$with_android_sdk" -a -e "$SRC_ROOT/external/android-sdk-linux" -a "$build" != "$host"; then
    with_android_sdk="$SRC_ROOT/external/android-sdk-linux"
fi
if test -n "$with_android_sdk"; then
    ANDROID_SDK_HOME=$with_android_sdk
    PATH="$ANDROID_SDK_HOME/platform-tools:$ANDROID_SDK_HOME/tools:$PATH"
fi
AC_SUBST(ANDROID_SDK_HOME)

libo_FUZZ_ARG_ENABLE([android-editing],
    AS_HELP_STRING([--enable-android-editing],
        [Enable the experimental editing feature on Android.])
)
ENABLE_ANDROID_EDITING=
if test "$enable_android_editing" = yes; then
    ENABLE_ANDROID_EDITING=TRUE
fi
AC_SUBST([ENABLE_ANDROID_EDITING])

dnl ===================================================================
dnl The following is a list of supported systems.
dnl Sequential to keep the logic very simple
dnl These values may be checked and reset later.
dnl ===================================================================
#defaults unless the os test overrides this:
test_randr=yes
test_xrender=yes
test_cups=yes
test_dbus=yes
test_fontconfig=yes
test_cairo=no

# Default values, as such probably valid just for Linux, set
# differently below just for Mac OSX,but at least better than
# hardcoding these as we used to do. Much of this is duplicated also
# in solenv for old build system and for gbuild, ideally we should
# perhaps define stuff like this only here in configure.ac?

LINKFLAGSSHL="-shared"
PICSWITCH="-fpic"
DLLPOST=".so"

LINKFLAGSNOUNDEFS="-Wl,-z,defs"

INSTROOTBASESUFFIX=
INSTROOTCONTENTSUFFIX=
SDKDIRNAME=sdk

case "$host_os" in

solaris*)
    test_gtk=yes
    build_gstreamer_1_0=yes
    build_gstreamer_0_10=yes
    test_freetype=yes
    _os=SunOS

    dnl ===========================================================
    dnl Check whether we're using Solaris 10 - SPARC or Intel.
    dnl ===========================================================
    AC_MSG_CHECKING([the Solaris operating system release])
    _os_release=`echo $host_os | $SED -e s/solaris2\.//`
    if test "$_os_release" -lt "10"; then
        AC_MSG_ERROR([use Solaris >= 10 to build LibreOffice])
    else
        AC_MSG_RESULT([ok ($_os_release)])
    fi

    dnl Check whether we're using a SPARC or i386 processor
    AC_MSG_CHECKING([the processor type])
    if test "$host_cpu" = "sparc" -o "$host_cpu" = "i386"; then
        AC_MSG_RESULT([ok ($host_cpu)])
    else
        AC_MSG_ERROR([only SPARC and i386 processors are supported])
    fi
    ;;

linux-gnu*|k*bsd*-gnu*)
    test_gtk=yes
    build_gstreamer_1_0=yes
    build_gstreamer_0_10=yes
    test_kde4=yes
    test_qt5=yes
    if test "$enable_fuzzers" != yes; then
        test_freetype=yes
        test_fontconfig=yes
    else
        test_freetype=no
        test_fontconfig=no
        BUILD_TYPE="$BUILD_TYPE FONTCONFIG FREETYPE"
    fi
    _os=Linux
    ;;

gnu)
    test_randr=no
    test_xrender=no
    _os=GNU
     ;;

cygwin*|interix*)

    # When building on Windows normally with MSVC under Cygwin,
    # configure thinks that the host platform (the platform the
    # built code will run on) is Cygwin, even if it obviously is
    # Windows, which in Autoconf terminology is called
    # "mingw32". (Which is misleading as MinGW is the name of the
    # tool-chain, not an operating system.)

    # Somewhat confusing, yes. But this configure script doesn't
    # look at $host etc that much, it mostly uses its own $_os
    # variable, set here in this case statement.

    test_cups=no
    test_dbus=no
    test_randr=no
    test_xrender=no
    test_freetype=no
    test_fontconfig=no
    _os=WINNT

    DLLPOST=".dll"
    LINKFLAGSNOUNDEFS=
    ;;

darwin*) # Mac OS X or iOS
    test_gtk=yes
    test_randr=no
    test_xrender=no
    test_freetype=no
    test_fontconfig=no
    test_dbus=no
    if test -n "$LODE_HOME" ; then
        mac_sanitize_path
        AC_MSG_NOTICE([sanitized the PATH to $PATH])
    fi
    if test "$host_cpu" = "arm64" -o "$enable_ios_simulator" = "yes"; then
        _os=iOS
        test_gtk=no
        test_cups=no
        enable_mpl_subset=yes
        enable_lotuswordpro=no
        enable_coinmp=no
        enable_lpsolve=no
        enable_postgresql_sdbc=no
        enable_extension_integration=no
        enable_report_builder=no
        with_ppds=no
        if test "$enable_ios_simulator" = "yes"; then
            host=x86_64-apple-darwin
        fi
    else
        _os=Darwin
        INSTROOTBASESUFFIX=/$PRODUCTNAME_WITHOUT_SPACES.app
        INSTROOTCONTENTSUFFIX=/Contents
        SDKDIRNAME=AC_PACKAGE_NAME${PRODUCTVERSION}_SDK
    fi
    enable_systray=no
    # See comment above the case "$host_os"
    LINKFLAGSSHL="-dynamiclib -single_module"

    # -fPIC is default
    PICSWITCH=""

    DLLPOST=".dylib"

    # -undefined error is the default
    LINKFLAGSNOUNDEFS=""
;;

freebsd*)
    test_gtk=yes
    build_gstreamer_1_0=yes
    build_gstreamer_0_10=yes
    test_kde4=yes
    test_qt5=yes
    test_freetype=yes
    AC_MSG_CHECKING([the FreeBSD operating system release])
    if test -n "$with_os_version"; then
        OSVERSION="$with_os_version"
    else
        OSVERSION=`/sbin/sysctl -n kern.osreldate`
    fi
    AC_MSG_RESULT([found OSVERSION=$OSVERSION])
    AC_MSG_CHECKING([which thread library to use])
    if test "$OSVERSION" -lt "500016"; then
        PTHREAD_CFLAGS="-D_THREAD_SAFE"
        PTHREAD_LIBS="-pthread"
    elif test "$OSVERSION" -lt "502102"; then
        PTHREAD_CFLAGS="-D_THREAD_SAFE"
        PTHREAD_LIBS="-lc_r"
    else
        PTHREAD_CFLAGS=""
        PTHREAD_LIBS="-pthread"
    fi
    AC_MSG_RESULT([$PTHREAD_LIBS])
    _os=FreeBSD
    ;;

*netbsd*)
    test_gtk=yes
    build_gstreamer_1_0=yes
    build_gstreamer_0_10=yes
    test_kde4=yes
    test_qt5=yes
    test_freetype=yes
    PTHREAD_LIBS="-pthread -lpthread"
    _os=NetBSD
    ;;

aix*)
    test_randr=no
    test_freetype=yes
    PTHREAD_LIBS=-pthread
    _os=AIX
    ;;

openbsd*)
    test_gtk=yes
    test_freetype=yes
    PTHREAD_CFLAGS="-D_THREAD_SAFE"
    PTHREAD_LIBS="-pthread"
    _os=OpenBSD
    ;;

dragonfly*)
    test_gtk=yes
    build_gstreamer_1_0=yes
    build_gstreamer_0_10=yes
    test_kde4=yes
    test_qt5=yes
    test_freetype=yes
    PTHREAD_LIBS="-pthread"
    _os=DragonFly
    ;;

linux-android*)
    build_gstreamer_1_0=no
    build_gstreamer_0_10=no
    enable_lotuswordpro=no
    enable_mpl_subset=yes
    enable_coinmp=yes
    enable_lpsolve=no
    enable_report_builder=no
    enable_odk=no
    enable_postgresql_sdbc=no
    enable_python=no
    test_cups=no
    test_dbus=no
    test_fontconfig=no
    test_freetype=no
    test_gtk=no
    test_kde4=no
    test_qt5=no
    test_randr=no
    test_xrender=no
    _os=Android

    AC_DEFINE(HAVE_FT_FACE_GETCHARVARIANTINDEX)
    BUILD_TYPE="$BUILD_TYPE CAIRO FONTCONFIG FREETYPE"
    ;;

*)
    AC_MSG_ERROR([$host_os operating system is not suitable to build LibreOffice for!])
    ;;
esac

if test "$_os" = "Android" ; then
    # Verify that the NDK and SDK options are proper
    if test -z "$with_android_ndk"; then
        AC_MSG_ERROR([the --with-android-ndk option is mandatory, unless it is available at external/android-ndk/.])
    elif test ! -f "$ANDROID_NDK_HOME/platforms/android-${ANDROID_API_LEVEL}/arch-${ANDROID_ARCH}/usr/lib/libc.a"; then
        AC_MSG_ERROR([the --with-android-ndk option does not point to an Android NDK])
    fi

    if test -z "$ANDROID_SDK_HOME"; then
        AC_MSG_ERROR([the --with-android-sdk option is mandatory, unless it is available at external/android-sdk-linux/.])
    elif test ! -d "$ANDROID_SDK_HOME/platforms"; then
        AC_MSG_ERROR([the --with-android-sdk option does not point to an Android SDK])
    fi

    BUILD_TOOLS_VERSION=`$SED -n -e 's/.*buildToolsVersion "\(.*\)"/\1/p' $SRC_ROOT/android/source/build.gradle`
    if test ! -d "$ANDROID_SDK_HOME/build-tools/$BUILD_TOOLS_VERSION"; then
        AC_MSG_WARN([android build-tools $BUILD_TOOLS_VERSION not found - install with
                         $ANDROID_SDK_HOME/tools/android update sdk -u --all --filter build-tools-$BUILD_TOOLS_VERSION
                    or adjust change $SRC_ROOT/android/source/build.gradle accordingly])
        add_warning "android build-tools $BUILD_TOOLS_VERSION not found - install with"
        add_warning "    $ANDROID_SDK_HOME/tools/android update sdk -u --all --filter build-tools-$BUILD_TOOLS_VERSION"
        add_warning "or adjust $SRC_ROOT/android/source/build.gradle accordingly"
    fi
    if test ! -f "$ANDROID_SDK_HOME/extras/android/m2repository/source.properties"; then
        AC_MSG_WARN([android support repository not found - install with
                         $ANDROID_SDK_HOME/tools/android update sdk -u --filter extra-android-m2repository
                     to allow the build to download the specified version of the android support libraries])
        add_warning "android support repository not found - install with"
        add_warning "    $ANDROID_SDK_HOME/tools/android update sdk -u --filter extra-android-m2repository"
        add_warning "to allow the build to download the specified version of the android support libraries"
    fi
fi

if test "$_os" = "AIX"; then
    AC_PATH_PROG(GAWK, gawk)
    if test -z "$GAWK"; then
        AC_MSG_ERROR([gawk not found in \$PATH])
    fi
fi

AC_SUBST(SDKDIRNAME)

AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_LIBS)

# Check for explicit A/C/CXX/OBJC/OBJCXX/LDFLAGS.
# By default use the ones specified by our build system,
# but explicit override is possible.
AC_MSG_CHECKING(for explicit AFLAGS)
if test -n "$AFLAGS"; then
    AC_MSG_RESULT([$AFLAGS])
    x_AFLAGS=
else
    AC_MSG_RESULT(no)
    x_AFLAGS=[\#]
fi
AC_MSG_CHECKING(for explicit CFLAGS)
if test -n "$CFLAGS"; then
    AC_MSG_RESULT([$CFLAGS])
    x_CFLAGS=
else
    AC_MSG_RESULT(no)
    x_CFLAGS=[\#]
fi
AC_MSG_CHECKING(for explicit CXXFLAGS)
if test -n "$CXXFLAGS"; then
    AC_MSG_RESULT([$CXXFLAGS])
    x_CXXFLAGS=
else
    AC_MSG_RESULT(no)
    x_CXXFLAGS=[\#]
fi
AC_MSG_CHECKING(for explicit OBJCFLAGS)
if test -n "$OBJCFLAGS"; then
    AC_MSG_RESULT([$OBJCFLAGS])
    x_OBJCFLAGS=
else
    AC_MSG_RESULT(no)
    x_OBJCFLAGS=[\#]
fi
AC_MSG_CHECKING(for explicit OBJCXXFLAGS)
if test -n "$OBJCXXFLAGS"; then
    AC_MSG_RESULT([$OBJCXXFLAGS])
    x_OBJCXXFLAGS=
else
    AC_MSG_RESULT(no)
    x_OBJCXXFLAGS=[\#]
fi
AC_MSG_CHECKING(for explicit LDFLAGS)
if test -n "$LDFLAGS"; then
    AC_MSG_RESULT([$LDFLAGS])
    x_LDFLAGS=
else
    AC_MSG_RESULT(no)
    x_LDFLAGS=[\#]
fi
AC_SUBST(AFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(OBJCFLAGS)
AC_SUBST(OBJCXXFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(x_AFLAGS)
AC_SUBST(x_CFLAGS)
AC_SUBST(x_CXXFLAGS)
AC_SUBST(x_OBJCFLAGS)
AC_SUBST(x_OBJCXXFLAGS)
AC_SUBST(x_LDFLAGS)

dnl These are potentially set for MSVC, in the code checking for UCRT below:
my_original_CFLAGS=$CFLAGS
my_original_CXXFLAGS=$CXXFLAGS
my_original_CPPFLAGS=$CPPFLAGS

dnl The following checks for gcc, cc and then cl (if it weren't guarded for win32)
dnl Needs to precede the AC_SEARCH_LIBS call below, which apparently calls
dnl AC_PROG_CC internally.
if test "$_os" != "WINNT"; then
    # AC_PROG_CC sets CFLAGS to -g -O2 if not set, avoid that
    save_CFLAGS=$CFLAGS
    AC_PROG_CC
    CFLAGS=$save_CFLAGS
fi

if test $_os != "WINNT"; then
    save_LIBS="$LIBS"
    AC_SEARCH_LIBS([dlsym], [dl],
        [case "$ac_cv_search_dlsym" in -l*) DLOPEN_LIBS="$ac_cv_search_dlsym";; esac],
        [AC_MSG_ERROR([dlsym not found in either libc nor libdl])])
    LIBS="$save_LIBS"
fi
AC_SUBST(DLOPEN_LIBS)

###############################################################################
# Extensions switches --enable/--disable
###############################################################################
# By default these should be enabled unless having extra dependencies.
# If there is extra dependency over configure options then the enable should
# be automagic based on whether the requiring feature is enabled or not.
# All this options change anything only with --enable-extension-integration.

# The name of this option and its help string makes it sound as if
# extensions are built anyway, just not integrated in the installer,
# if you use --disable-extension-integration. Is that really the
# case?

AC_ARG_ENABLE(ios-simulator,
    AS_HELP_STRING([--enable-ios-simulator],
        [build i386 or x86_64 for ios simulator])
)

libo_FUZZ_ARG_ENABLE(extension-integration,
    AS_HELP_STRING([--disable-extension-integration],
        [Disable integration of the built extensions in the installer of the
         product. Use this switch to disable the integration.])
)

AC_ARG_ENABLE(avmedia,
    AS_HELP_STRING([--disable-avmedia],
        [Disable displaying and inserting AV media in documents. Work in progress, use only if you are hacking on it.])
)

AC_ARG_ENABLE(database-connectivity,
    AS_HELP_STRING([--disable-database-connectivity],
        [Disable various database connectivity. Work in progress, use only if you are hacking on it.])
)

# This doesn't mean not building (or "integrating") extensions
# (although it probably should; i.e. it should imply
# --disable-extension-integration I guess), it means not supporting
# any extension mechanism at all
libo_FUZZ_ARG_ENABLE(extensions,
    AS_HELP_STRING([--disable-extensions],
        [Disable all add-on extension functionality. Work in progress, use only if you are hacking on it.])
)

AC_ARG_ENABLE(scripting,
    AS_HELP_STRING([--disable-scripting],
        [Disable BASIC, Java and Python. Work in progress, use only if you are hacking on it.])
)

# This is mainly for Android and iOS, but could potentially be used in some
# special case otherwise, too, so factored out as a separate setting

AC_ARG_ENABLE(dynamic-loading,
    AS_HELP_STRING([--disable-dynamic-loading],
        [Disable any use of dynamic loading of code. Work in progress, use only if you are hacking on it.])
)

libo_FUZZ_ARG_ENABLE(report-builder,
    AS_HELP_STRING([--disable-report-builder],
        [Disable the Report Builder.])
)

libo_FUZZ_ARG_ENABLE(ext-wiki-publisher,
    AS_HELP_STRING([--enable-ext-wiki-publisher],
        [Enable the Wiki Publisher extension.])
)

libo_FUZZ_ARG_ENABLE(lpsolve,
    AS_HELP_STRING([--disable-lpsolve],
        [Disable compilation of the lp solve solver ])
)
libo_FUZZ_ARG_ENABLE(coinmp,
    AS_HELP_STRING([--disable-coinmp],
        [Disable compilation of the CoinMP solver ])
)

libo_FUZZ_ARG_ENABLE(pdfimport,
    AS_HELP_STRING([--disable-pdfimport],
        [Disable building the PDF import feature.])
)

libo_FUZZ_ARG_ENABLE(pdfium,
    AS_HELP_STRING([--disable-pdfium],
        [Disable building PDFium.])
)

###############################################################################

dnl ---------- *** ----------

libo_FUZZ_ARG_ENABLE(mergelibs,
    AS_HELP_STRING([--enable-mergelibs],
        [Merge several of the smaller libraries into one big, "merged", one.])
)

libo_FUZZ_ARG_ENABLE(breakpad,
    AS_HELP_STRING([--enable-breakpad],
        [Enables breakpad for crash reporting.])
)

AC_ARG_ENABLE(fetch-external,
    AS_HELP_STRING([--disable-fetch-external],
        [Disables fetching external tarballs from web sources.])
)

AC_ARG_ENABLE(fuzzers,
    AS_HELP_STRING([--enable-fuzzers],
        [Enables building libfuzzer targets for fuzz testing.])
)

libo_FUZZ_ARG_ENABLE(pch,
    AS_HELP_STRING([--enable-pch],
        [Enables precompiled header support for C++. Forced default on Windows/VC build])
)

libo_FUZZ_ARG_ENABLE(epm,
    AS_HELP_STRING([--enable-epm],
        [LibreOffice includes self-packaging code, that requires epm, however epm is
         useless for large scale package building.])
)

libo_FUZZ_ARG_ENABLE(odk,
    AS_HELP_STRING([--disable-odk],
        [LibreOffice includes an ODK, office development kit which some packagers may
         wish to build without.])
)

AC_ARG_ENABLE(mpl-subset,
    AS_HELP_STRING([--enable-mpl-subset],
        [Don't compile any pieces which are not MPL or more liberally licensed])
)

libo_FUZZ_ARG_ENABLE(evolution2,
    AS_HELP_STRING([--enable-evolution2],
        [Allows the built-in evolution 2 addressbook connectivity build to be
         enabled.])
)

AC_ARG_ENABLE(avahi,
    AS_HELP_STRING([--enable-avahi],
        [Determines whether to use Avahi to advertise Impress to remote controls.])
)

libo_FUZZ_ARG_ENABLE(werror,
    AS_HELP_STRING([--enable-werror],
        [Turn warnings to errors. (Has no effect in modules where the treating
         of warnings as errors is disabled explicitly.)]),
,)

libo_FUZZ_ARG_ENABLE(assert-always-abort,
    AS_HELP_STRING([--enable-assert-always-abort],
        [make assert() failures abort even when building without --enable-debug or --enable-dbgutil.]),
,)

libo_FUZZ_ARG_ENABLE(dbgutil,
    AS_HELP_STRING([--enable-dbgutil],
        [Provide debugging support from --enable-debug and include additional debugging
         utilities such as object counting or more expensive checks.
         This is the recommended option for developers.
         Note that this makes the build ABI incompatible, it is not possible to mix object
         files or libraries from a --enable-dbgutil and a --disable-dbgutil build.]))

libo_FUZZ_ARG_ENABLE(debug,
    AS_HELP_STRING([--enable-debug],
        [Include debugging information, disable compiler optimization and inlining plus
         extra debugging code like assertions. Extra large build! (enables -g compiler flag).]))

libo_FUZZ_ARG_ENABLE(sal-log,
    AS_HELP_STRING([--enable-sal-log],
        [Make SAL_INFO and SAL_WARN calls do something even in a non-debug build.]))

AC_ARG_ENABLE(selective-debuginfo,
    AS_HELP_STRING([--enable-selective-debuginfo],
        [If --enable-debug or --enable-dbgutil is used, build debugging information
         (-g compiler flag) only for the specified gbuild build targets
         (where all means everything, - prepended means not to enable, / appended means
         everything in the directory; there is no ordering, more specific overrides
         more general, and disabling takes precedence).
         Example: --enable-selective-debuginfo="all -sw/ -Library_sc".]))

libo_FUZZ_ARG_ENABLE(symbols,
    AS_HELP_STRING([--enable-symbols],
        [Generate debug information.
         By default, enabled for --enable-debug and --enable-dbgutil, disabled
         otherwise.]))

libo_FUZZ_ARG_ENABLE(optimized,
    AS_HELP_STRING([--disable-optimized],
        [Whether to compile with optimization flags.
         By default, disabled for --enable-debug and --enable-dbgutil, enabled
         otherwise.]))

libo_FUZZ_ARG_ENABLE(runtime-optimizations,
    AS_HELP_STRING([--disable-runtime-optimizations],
        [Statically disable certain runtime optimizations (like rtl/alloc.h or
         JVM JIT) that are known to interact badly with certain dynamic analysis
         tools (like -fsanitize=address or Valgrind).  By default, disabled iff
         CC contains "-fsanitize=*".  (For Valgrind, those runtime optimizations
         are typically disabled dynamically via RUNNING_ON_VALGRIND.)]))

AC_ARG_WITH(valgrind,
    AS_HELP_STRING([--with-valgrind],
        [Make availability of Valgrind headers a hard requirement.]))

libo_FUZZ_ARG_ENABLE(compiler-plugins,
    AS_HELP_STRING([--enable-compiler-plugins],
        [Enable compiler plugins that will perform additional checks during
         building. Enabled automatically by --enable-dbgutil.]))

libo_FUZZ_ARG_ENABLE(ooenv,
    AS_HELP_STRING([--disable-ooenv],
        [Disable ooenv for the instdir installation.]))

AC_ARG_ENABLE(lto,
    AS_HELP_STRING([--enable-lto],
        [Enable link-time optimization. Suitable for (optimised) product builds. Building might take
         longer but libraries and executables are optimized for speed. For GCC, best to use the 'gold'
         linker. For MSVC, this option is broken at the moment. This is experimental work
         in progress that shouldn't be used unless you are working on it.)]))

AC_ARG_ENABLE(python,
    AS_HELP_STRING([--enable-python=<no/auto/system/internal/fully-internal>],
        [Enables or disables Python support at run-time and build-time.
         Also specifies what Python to use. 'auto' is the default.
         'fully-internal' even forces the internal version for uses of Python
         during the build.]))

libo_FUZZ_ARG_ENABLE(gtk,
    AS_HELP_STRING([--disable-gtk],
        [Determines whether to use Gtk+ vclplug on platforms where Gtk+ is available.]),
,test "${enable_gtk+set}" = set || enable_gtk=yes)

libo_FUZZ_ARG_ENABLE(gtk3,
    AS_HELP_STRING([--disable-gtk3],
        [Determines whether to use Gtk+ 3.0 vclplug on platforms where Gtk+ 3.0 is available.
         This is experimental and may not work.]),
,test "${enable_gtk3+set}" = set || enable_gtk3=yes)

libo_FUZZ_ARG_ENABLE(systray,
    AS_HELP_STRING([--disable-systray],
        [Determines whether to build the systray quickstarter.]),
,test "${enable_systray+set}" = set || enable_systray=yes)

AC_ARG_ENABLE(split-app-modules,
    AS_HELP_STRING([--enable-split-app-modules],
        [Split file lists for app modules, e.g. base, calc.
         Has effect only with make distro-pack-install]),
,)

AC_ARG_ENABLE(split-opt-features,
    AS_HELP_STRING([--enable-split-opt-features],
        [Split file lists for some optional features, e.g. pyuno, testtool.
         Has effect only with make distro-pack-install]),
,)

libo_FUZZ_ARG_ENABLE(cairo-canvas,
    AS_HELP_STRING([--disable-cairo-canvas],
        [Determines whether to build the Cairo canvas on platforms where Cairo is available.]),
,)

libo_FUZZ_ARG_ENABLE(dbus,
    AS_HELP_STRING([--disable-dbus],
        [Determines whether to enable features that depend on dbus.
         e.g. Presentation mode screensaver control, bluetooth presentation control, automatic font install]),
,test "${enable_dbus+set}" = set || enable_dbus=yes)

libo_FUZZ_ARG_ENABLE(sdremote,
    AS_HELP_STRING([--disable-sdremote],
        [Determines whether to enable Impress remote control (i.e. the server component).]),
,test "${enable_sdremote+set}" = set || enable_sdremote=yes)

libo_FUZZ_ARG_ENABLE(sdremote-bluetooth,
    AS_HELP_STRING([--disable-sdremote-bluetooth],
        [Determines whether to build sdremote with bluetooth support.
         Requires dbus on Linux.]))

libo_FUZZ_ARG_ENABLE(gio,
    AS_HELP_STRING([--disable-gio],
        [Determines whether to use the GIO support.]),
,test "${enable_gio+set}" = set || enable_gio=yes)

AC_ARG_ENABLE(kde4,
    AS_HELP_STRING([--enable-kde4],
        [Determines whether to use Qt4/KDE4 vclplug on platforms where Qt4 and
         KDE4 are available.]),
,)

AC_ARG_ENABLE(qt5,
    AS_HELP_STRING([--enable-qt5],
        [Determines whether to use Qt5 vclplug on platforms where Qt5 is
         available.]),
,)

libo_FUZZ_ARG_ENABLE(gui,
    AS_HELP_STRING([--disable-gui],
        [Disable use of X11 or Wayland to reduce dependencies. Not related to the --headless
         command-line option. Not related to LibreOffice Online functionality. Don't use
         unless you are certain you need to. Nobody will help you if you insist on trying
         this and run into problems.]),
,test "${enable_gui+set}" = set || enable_gui=yes)

libo_FUZZ_ARG_ENABLE(randr,
    AS_HELP_STRING([--disable-randr],
        [Disable RandR support in the vcl project.]),
,test "${enable_randr+set}" = set || enable_randr=yes)

libo_FUZZ_ARG_ENABLE(gstreamer-1-0,
    AS_HELP_STRING([--disable-gstreamer-1-0],
        [Disable building with the new gstreamer 1.0 avmedia backend.]),
,test "${enable_gstreamer_1_0+set}" = set || enable_gstreamer_1_0=yes)

AC_ARG_ENABLE(gstreamer-0-10,
    AS_HELP_STRING([--enable-gstreamer-0-10],
        [Enable building with the gstreamer 0.10 avmedia backend.]),
,enable_gstreamer_0_10=no)

libo_FUZZ_ARG_ENABLE(vlc,
    AS_HELP_STRING([--enable-vlc],
        [Enable building with the (experimental) VLC avmedia backend.]),
,test "${enable_vlc+set}" = set || enable_vlc=no)

libo_FUZZ_ARG_ENABLE(neon,
    AS_HELP_STRING([--disable-neon],
        [Disable neon and the compilation of webdav binding.]),
,)

libo_FUZZ_ARG_ENABLE([eot],
    [AS_HELP_STRING([--enable-eot],
        [Enable support for Embedded OpenType fonts.])],
,test "${enable_eot+set}" = set || enable_eot=no)

libo_FUZZ_ARG_ENABLE(cve-tests,
    AS_HELP_STRING([--disable-cve-tests],
        [Prevent CVE tests to be executed]),
,)

libo_FUZZ_ARG_ENABLE(chart-tests,
    AS_HELP_STRING([--enable-chart-tests],
        [Executes chart XShape tests. In a perfect world these tests would be
         stable and everyone could run them, in reality it is best to run them
         only on a few machines that are known to work and maintained by people
         who can judge if a test failure is a regression or not.]),
,)

AC_ARG_ENABLE(build-unowinreg,
    AS_HELP_STRING([--enable-build-unowinreg],
        [Do not use the prebuilt unowinreg.dll. Build it instead. The MinGW C++
         compiler is needed on Linux.]),
,)

AC_ARG_ENABLE(dependency-tracking,
    AS_HELP_STRING([--enable-dependency-tracking],
        [Do not reject slow dependency extractors.])[
  --disable-dependency-tracking
                          Disables generation of dependency information.
                          Speed up one-time builds.],
,)

AC_ARG_ENABLE(icecream,
    AS_HELP_STRING([--enable-icecream],
        [Use the 'icecream' distributed compiling tool to speedup the compilation.
         It defaults to /opt/icecream for the location of the icecream gcc/g++
         wrappers, you can override that using --with-gcc-home=/the/path switch.]),
,)

libo_FUZZ_ARG_ENABLE(cups,
    AS_HELP_STRING([--disable-cups],
        [Do not build cups support.])
)

AC_ARG_ENABLE(ccache,
    AS_HELP_STRING([--disable-ccache],
        [Do not try to use ccache automatically.
         By default, unless on Windows, we will try to detect if ccache is available; in that case if
         CC/CXX are not yet set, and --enable-icecream is not given, we
         attempt to use ccache. --disable-ccache disables ccache completely.
]),
,)

AC_ARG_ENABLE(64-bit,
    AS_HELP_STRING([--enable-64-bit],
        [Build a 64-bit LibreOffice on platforms where the normal build is 32-bit.
         At the moment meaningful only for Windows.]), ,)

libo_FUZZ_ARG_ENABLE(online-update,
    AS_HELP_STRING([--enable-online-update],
        [Enable the online update service that will check for new versions of
         LibreOffice. By default, it is enabled on Windows and Mac, disabled on Linux.
         If the value is "mar", the experimental Mozilla-like update will be
         enabled instead of the traditional update mechanism.]),
,)

AC_ARG_WITH(update-config,
    AS_HELP_STRING([--with-update-config=/tmp/update.ini],
                   [Path to the update config ini file]))

libo_FUZZ_ARG_ENABLE(extension-update,
    AS_HELP_STRING([--disable-extension-update],
        [Disable possibility to update installed extensions.]),
,)

libo_FUZZ_ARG_ENABLE(release-build,
    AS_HELP_STRING([--enable-release-build],
        [Enable release build. Note that the "release build" choice is orthogonal to
         whether symbols are present, debug info is generated, or optimization
         is done.
         See http://wiki.documentfoundation.org/Development/DevBuild]),
,)

AC_ARG_ENABLE(windows-build-signing,
    AS_HELP_STRING([--enable-windows-build-signing],
        [Enable signing of windows binaries (*.exe, *.dll)]),
,)

AC_ARG_ENABLE(silent-msi,
    AS_HELP_STRING([--enable-silent-msi],
        [Enable MSI with LIMITUI=1 (silent install).]),
,)

AC_ARG_ENABLE(macosx-code-signing,
    AS_HELP_STRING([--enable-macosx-code-signing=<identity>],
        [Sign executables, dylibs, frameworks and the app bundle. If you
         don't provide an identity the first suitable certificate
         in your keychain is used.]),
,)

AC_ARG_ENABLE(macosx-package-signing,
    AS_HELP_STRING([--enable-macosx-package-signing=<identity>],
        [Create a .pkg suitable for uploading to the Mac App Store and sign
         it. If you don't provide an identity the first suitable certificate
         in your keychain is used.]),
,)

AC_ARG_ENABLE(macosx-sandbox,
    AS_HELP_STRING([--enable-macosx-sandbox],
        [Make the app bundle run in a sandbox. Requires code signing.
         Is required by apps distributed in the Mac App Store, and implies
         adherence to App Store rules.]),
,)

AC_ARG_WITH(macosx-bundle-identifier,
    AS_HELP_STRING([--with-macosx-bundle-identifier=tld.mumble.orifice.TheOffice],
        [Define the OS X bundle identifier. Default is the somewhat weird
         org.libreoffice.script ("script", huh?).]),
,with_macosx_bundle_identifier=org.libreoffice.script)

AC_ARG_WITH(product-name,
    AS_HELP_STRING([--with-product-name='My Own Office Suite'],
        [Define the product name. Default is AC_PACKAGE_NAME.]),
,with_product_name=$PRODUCTNAME)

AC_ARG_WITH(package-version,
    AS_HELP_STRING([--with-package-version='3.1.4.5'],
        [Define the package version. Default is AC_PACKAGE_VERSION. Use only if you distribute an own build for macOS.]),
,)

libo_FUZZ_ARG_ENABLE(readonly-installset,
    AS_HELP_STRING([--enable-readonly-installset],
        [Prevents any attempts by LibreOffice to write into its installation. That means
         at least that no "system-wide" extensions can be added. Experimental work in
         progress.]),
,)

libo_FUZZ_ARG_ENABLE(postgresql-sdbc,
    AS_HELP_STRING([--disable-postgresql-sdbc],
        [Disable the build of the PostgreSQL-SDBC driver.])
)

libo_FUZZ_ARG_ENABLE(lotuswordpro,
    AS_HELP_STRING([--disable-lotuswordpro],
        [Disable the build of the Lotus Word Pro filter.]),
,test "${enable_lotuswordpro+set}" = set || enable_lotuswordpro=yes)

libo_FUZZ_ARG_ENABLE(firebird-sdbc,
    AS_HELP_STRING([--disable-firebird-sdbc],
        [Disable the build of the Firebird-SDBC driver if it doesn't compile for you.]),
,test "${enable_firebird_sdbc+set}" = set || enable_firebird_sdbc=yes)

AC_ARG_ENABLE(bogus-pkg-config,
    AS_HELP_STRING([--enable-bogus-pkg-config],
        [MACOSX only: on MacOSX pkg-config can cause trouble. by default if one is found in the PATH, an error is issued. This flag turn that error into a warning.]),
)

AC_ARG_ENABLE(openssl,
    AS_HELP_STRING([--disable-openssl],
        [Disable using libssl/libcrypto from OpenSSL. If disabled,
         components will either use GNUTLS or NSS. Work in progress,
         use only if you are hacking on it.]),
,enable_openssl=yes)

AC_ARG_ENABLE(library-bin-tar,
    AS_HELP_STRING([--enable-library-bin-tar],
        [Enable the building and reused of tarball of binary build for some 'external' libraries.
        Some libraries can save their build result in a tarball
        stored in TARFILE_LOCATION. That binary tarball is
        uniquely identified by the source tarball,
        the content of the config_host.mk file and the content
        of the top-level directory in core for that library
        If this option is enabled, then if such a tarfile exist, it will be untarred
        instead of the source tarfile, and the build step will be skipped for that
        library.
        If a proper tarfile does not exist, then the normal source-based
        build is done for that library and a proper binary tarfile is created
        for the next time.]),
)

AC_ARG_ENABLE(dconf,
    AS_HELP_STRING([--disable-dconf],
        [Disable the dconf configuration backend (enabled by default where
         available).]))

libo_FUZZ_ARG_ENABLE(formula-logger,
    AS_HELP_STRING(
        [--enable-formula-logger],
        [Enable formula logger for logging formula calculation flow in Calc.]
    )
)

dnl ===================================================================
dnl Optional Packages (--with/without-)
dnl ===================================================================

AC_ARG_WITH(gcc-home,
    AS_HELP_STRING([--with-gcc-home],
        [Specify the location of gcc/g++ manually. This can be used in conjunction
         with --enable-icecream when icecream gcc/g++ wrappers are installed in a
         non-default path.]),
,)

AC_ARG_WITH(gnu-patch,
    AS_HELP_STRING([--with-gnu-patch],
        [Specify location of GNU patch on Solaris or FreeBSD.]),
,)

AC_ARG_WITH(build-platform-configure-options,
    AS_HELP_STRING([--with-build-platform-configure-options],
        [Specify options for the configure script run for the *build* platform in a cross-compilation]),
,)

AC_ARG_WITH(gnu-cp,
    AS_HELP_STRING([--with-gnu-cp],
        [Specify location of GNU cp on Solaris or FreeBSD.]),
,)

AC_ARG_WITH(external-tar,
    AS_HELP_STRING([--with-external-tar=<TARFILE_PATH>],
        [Specify an absolute path of where to find (and store) tarfiles.]),
    TARFILE_LOCATION=$withval ,
)

AC_ARG_WITH(referenced-git,
    AS_HELP_STRING([--with-referenced-git=<OTHER_CHECKOUT_DIR>],
        [Specify another checkout directory to reference. This makes use of
                 git submodule update --reference, and saves a lot of diskspace
                 when having multiple trees side-by-side.]),
    GIT_REFERENCE_SRC=$withval ,
)

AC_ARG_WITH(linked-git,
    AS_HELP_STRING([--with-linked-git=<submodules repo basedir>],
        [Specify a directory where the repositories of submodules are located.
         This uses a method similar to git-new-workdir to get submodules.]),
    GIT_LINK_SRC=$withval ,
)

AC_ARG_WITH(galleries,
    AS_HELP_STRING([--with-galleries],
        [Specify how galleries should be built. It is possible either to
         build these internally from source ("build"),
         or to disable them ("no")]),
)

AC_ARG_WITH(theme,
    AS_HELP_STRING([--with-theme="theme1 theme2..."],
        [Choose which themes to include. By default those themes with an '*' are included.
         Possible choices: *breeze, *breeze_dark, *breeze_svg, crystal, *colibre, *colibre_svg, *elementary, *elementary_svg, *galaxy, *hicontrast, oxygen, *sifr, *sifr_dark, *tango, tango_testing.]),
,)

libo_FUZZ_ARG_WITH(helppack-integration,
    AS_HELP_STRING([--without-helppack-integration],
        [It will not integrate the helppacks to the installer
         of the product. Please use this switch to use the online help
         or separate help packages.]),
,)

libo_FUZZ_ARG_WITH(fonts,
    AS_HELP_STRING([--without-fonts],
        [LibreOffice includes some third-party fonts to provide a reliable basis for
         help content, templates, samples, etc. When these fonts are already
         known to be available on the system then you should use this option.]),
,)

AC_ARG_ENABLE(noto-font,
    AS_HELP_STRING([--enable-noto-font],
        [Add more Google Noto fonts.]),
,)

AC_ARG_WITH(epm,
    AS_HELP_STRING([--with-epm],
        [Decides which epm to use. Default is to use the one from the system if
         one is built. When either this is not there or you say =internal epm
         will be built.]),
,)

AC_ARG_WITH(package-format,
    AS_HELP_STRING([--with-package-format],
        [Specify package format(s) for LibreOffice installation sets. The
         implicit --without-package-format leads to no installation sets being
         generated. Possible values: aix, archive, bsd, deb, dmg,
         installed, msi, pkg, and rpm.
         Example: --with-package-format='deb rpm']),
,)

AC_ARG_WITH(tls,
    AS_HELP_STRING([--with-tls],
        [Decides which TLS/SSL and cryptographic implementations to use for
         LibreOffice's code. Notice that this doesn't apply for depending
         libraries like "neon", for example. Default is to use OpenSSL
         although NSS is also possible. Notice that selecting NSS restricts
         the usage of OpenSSL in LO's code but selecting OpenSSL doesn't
         restrict by now the usage of NSS in LO's code. Possible values:
         openssl, nss. Example: --with-tls="nss"]),
,)

AC_ARG_WITH(system-libs,
    AS_HELP_STRING([--with-system-libs],
        [Use libraries already on system -- enables all --with-system-* flags.]),
,)

AC_ARG_WITH(system-bzip2,
    AS_HELP_STRING([--with-system-bzip2],
        [Use bzip2 already on system. Used only when --enable-online-update=mar]),,
    [with_system_bzip2="$with_system_libs"])

AC_ARG_WITH(system-headers,
    AS_HELP_STRING([--with-system-headers],
        [Use headers already on system -- enables all --with-system-* flags for
         external packages whose headers are the only entities used i.e.
         boost/odbc/sane-header(s).]),,
    [with_system_headers="$with_system_libs"])

AC_ARG_WITH(system-jars,
    AS_HELP_STRING([--without-system-jars],
        [When building with --with-system-libs, also the needed jars are expected
         on the system. Use this to disable that]),,
    [with_system_jars="$with_system_libs"])

AC_ARG_WITH(system-cairo,
    AS_HELP_STRING([--with-system-cairo],
        [Use cairo libraries already on system.  Happens automatically for
         (implicit) --enable-gtk and for --enable-gtk3.]))

AC_ARG_WITH(system-epoxy,
    AS_HELP_STRING([--with-system-epoxy],
        [Use epoxy libraries already on system.  Happens automatically for
         --enable-gtk3.]),,
       [with_system_epoxy="$with_system_libs"])

AC_ARG_WITH(myspell-dicts,
    AS_HELP_STRING([--with-myspell-dicts],
        [Adds myspell dictionaries to the LibreOffice installation set]),
,)

AC_ARG_WITH(system-dicts,
    AS_HELP_STRING([--without-system-dicts],
        [Do not use dictionaries from system paths.]),
,)

AC_ARG_WITH(external-dict-dir,
    AS_HELP_STRING([--with-external-dict-dir],
        [Specify external dictionary dir.]),
,)

AC_ARG_WITH(external-hyph-dir,
    AS_HELP_STRING([--with-external-hyph-dir],
        [Specify external hyphenation pattern dir.]),
,)

AC_ARG_WITH(external-thes-dir,
    AS_HELP_STRING([--with-external-thes-dir],
        [Specify external thesaurus dir.]),
,)

AC_ARG_WITH(system-zlib,
    AS_HELP_STRING([--with-system-zlib],
        [Use zlib already on system.]),,
    [with_system_zlib=auto])

AC_ARG_WITH(system-jpeg,
    AS_HELP_STRING([--with-system-jpeg],
        [Use jpeg already on system.]),,
    [with_system_jpeg="$with_system_libs"])

AC_ARG_WITH(system-clucene,
    AS_HELP_STRING([--with-system-clucene],
        [Use clucene already on system.]),,
    [with_system_clucene="$with_system_libs"])

AC_ARG_WITH(system-expat,
    AS_HELP_STRING([--with-system-expat],
        [Use expat already on system.]),,
    [with_system_expat="$with_system_libs"])

AC_ARG_WITH(system-libxml,
    AS_HELP_STRING([--with-system-libxml],
        [Use libxml/libxslt already on system.]),,
    [with_system_libxml=auto])

AC_ARG_WITH(system-icu,
    AS_HELP_STRING([--with-system-icu],
        [Use icu already on system.]),,
    [with_system_icu="$with_system_libs"])

AC_ARG_WITH(system-ucpp,
    AS_HELP_STRING([--with-system-ucpp],
        [Use ucpp already on system.]),,
    [])

AC_ARG_WITH(system-openldap,
    AS_HELP_STRING([--with-system-openldap],
        [Use the OpenLDAP LDAP SDK already on system.]),,
    [with_system_openldap="$with_system_libs"])

libo_FUZZ_ARG_ENABLE(poppler,
    AS_HELP_STRING([--disable-poppler],
        [Disable building Poppler.])
)

AC_ARG_WITH(system-poppler,
    AS_HELP_STRING([--with-system-poppler],
        [Use system poppler (only needed for PDF import).]),,
    [with_system_poppler="$with_system_libs"])

AC_ARG_WITH(system-gpgmepp,
    AS_HELP_STRING([--with-system-gpgmepp],
        [Use gpgmepp already on system]),,
    [with_system_gpgmepp="$with_system_libs"])

AC_ARG_WITH(system-apache-commons,
    AS_HELP_STRING([--with-system-apache-commons],
        [Use Apache commons libraries already on system.]),,
    [with_system_apache_commons="$with_system_jars"])

AC_ARG_WITH(system-mariadb,
    AS_HELP_STRING([--with-system-mariadb],
        [Use MariaDB/MySQL libraries already on system.]),,
    [with_system_mariadb="$with_system_libs"])

AC_ARG_ENABLE(bundle-mariadb,
    AS_HELP_STRING([--enable-bundle-mariadb],
        [When using MariaDB/MySQL libraries already on system, bundle them with the MariaDB Connector/LibreOffice.])
)

AC_ARG_WITH(system-mysql-cppconn,
    AS_HELP_STRING([--with-system-mysql-cppconn],
        [Use MySQL C++ Connector libraries already on system.]),,
    [with_system_mysql_cppconn="$with_system_libs"])

AC_ARG_WITH(system-postgresql,
    AS_HELP_STRING([--with-system-postgresql],
        [Use PostgreSQL libraries already on system, for building the PostgreSQL-SDBC
         driver. If pg_config is not in PATH, use PGCONFIG to point to it.]),,
    [with_system_postgresql="$with_system_libs"])

AC_ARG_WITH(libpq-path,
    AS_HELP_STRING([--with-libpq-path=<absolute path to your libpq installation>],
        [Use this PostgreSQL C interface (libpq) installation for building
         the PostgreSQL-SDBC extension.]),
,)

AC_ARG_WITH(system-firebird,
    AS_HELP_STRING([--with-system-firebird],
        [Use Firebird libraries already on system, for building the Firebird-SDBC
         driver. If fb_config is not in PATH, use FBCONFIG to point to it.]),,
    [with_system_firebird="$with_system_libs"])

AC_ARG_WITH(system-libtommath,
            AS_HELP_STRING([--with-system-libtommath],
                           [Use libtommath already on system]),,
            [with_system_libtommath="$with_system_libs"])

AC_ARG_WITH(system-hsqldb,
    AS_HELP_STRING([--with-system-hsqldb],
        [Use hsqldb already on system.]))

AC_ARG_WITH(hsqldb-jar,
    AS_HELP_STRING([--with-hsqldb-jar=JARFILE],
        [Specify path to jarfile manually.]),
    HSQLDB_JAR=$withval)

libo_FUZZ_ARG_ENABLE(scripting-beanshell,
    AS_HELP_STRING([--disable-scripting-beanshell],
        [Disable support for scripts in BeanShell.]),
,
)

AC_ARG_WITH(system-beanshell,
    AS_HELP_STRING([--with-system-beanshell],
        [Use beanshell already on system.]),,
    [with_system_beanshell="$with_system_jars"])

AC_ARG_WITH(beanshell-jar,
    AS_HELP_STRING([--with-beanshell-jar=JARFILE],
        [Specify path to jarfile manually.]),
    BSH_JAR=$withval)

libo_FUZZ_ARG_ENABLE(scripting-javascript,
    AS_HELP_STRING([--disable-scripting-javascript],
        [Disable support for scripts in JavaScript.]),
,
)

AC_ARG_WITH(system-rhino,
    AS_HELP_STRING([--with-system-rhino],
        [Use rhino already on system.]),,)
#    [with_system_rhino="$with_system_jars"])
# Above is not used as we have different debug interface
# patched into internal rhino. This code needs to be fixed
# before we can enable it by default.

AC_ARG_WITH(rhino-jar,
    AS_HELP_STRING([--with-rhino-jar=JARFILE],
        [Specify path to jarfile manually.]),
    RHINO_JAR=$withval)

AC_ARG_WITH(commons-logging-jar,
    AS_HELP_STRING([--with-commons-logging-jar=JARFILE],
        [Specify path to jarfile manually.]),
    COMMONS_LOGGING_JAR=$withval)

AC_ARG_WITH(system-jfreereport,
    AS_HELP_STRING([--with-system-jfreereport],
        [Use JFreeReport already on system.]),,
    [with_system_jfreereport="$with_system_jars"])

AC_ARG_WITH(sac-jar,
    AS_HELP_STRING([--with-sac-jar=JARFILE],
        [Specify path to jarfile manually.]),
    SAC_JAR=$withval)

AC_ARG_WITH(libxml-jar,
    AS_HELP_STRING([--with-libxml-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBXML_JAR=$withval)

AC_ARG_WITH(flute-jar,
    AS_HELP_STRING([--with-flute-jar=JARFILE],
        [Specify path to jarfile manually.]),
    FLUTE_JAR=$withval)

AC_ARG_WITH(jfreereport-jar,
    AS_HELP_STRING([--with-jfreereport-jar=JARFILE],
        [Specify path to jarfile manually.]),
    JFREEREPORT_JAR=$withval)

AC_ARG_WITH(liblayout-jar,
    AS_HELP_STRING([--with-liblayout-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBLAYOUT_JAR=$withval)

AC_ARG_WITH(libloader-jar,
    AS_HELP_STRING([--with-libloader-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBLOADER_JAR=$withval)

AC_ARG_WITH(libformula-jar,
    AS_HELP_STRING([--with-libformula-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBFORMULA_JAR=$withval)

AC_ARG_WITH(librepository-jar,
    AS_HELP_STRING([--with-librepository-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBREPOSITORY_JAR=$withval)

AC_ARG_WITH(libfonts-jar,
    AS_HELP_STRING([--with-libfonts-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBFONTS_JAR=$withval)

AC_ARG_WITH(libserializer-jar,
    AS_HELP_STRING([--with-libserializer-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBSERIALIZER_JAR=$withval)

AC_ARG_WITH(libbase-jar,
    AS_HELP_STRING([--with-libbase-jar=JARFILE],
        [Specify path to jarfile manually.]),
    LIBBASE_JAR=$withval)

AC_ARG_WITH(system-odbc,
    AS_HELP_STRING([--with-system-odbc],
        [Use the odbc headers already on system.]),,
    [with_system_odbc="auto"])

AC_ARG_WITH(system-sane,
    AS_HELP_STRING([--with-system-sane],
        [Use sane.h already on system.]),,
    [with_system_sane="$with_system_headers"])

AC_ARG_WITH(system-bluez,
    AS_HELP_STRING([--with-system-bluez],
        [Use bluetooth.h already on system.]),,
    [with_system_bluez="$with_system_headers"])

AC_ARG_WITH(system-curl,
    AS_HELP_STRING([--with-system-curl],
        [Use curl already on system.]),,
    [with_system_curl=auto])

AC_ARG_WITH(system-boost,
    AS_HELP_STRING([--with-system-boost],
        [Use boost already on system.]),,
    [with_system_boost="$with_system_headers"])

AC_ARG_WITH(system-glm,
    AS_HELP_STRING([--with-system-glm],
        [Use glm already on system.]),,
    [with_system_glm="$with_system_headers"])

AC_ARG_WITH(system-hunspell,
    AS_HELP_STRING([--with-system-hunspell],
        [Use libhunspell already on system.]),,
    [with_system_hunspell="$with_system_libs"])

AC_ARG_WITH(system-mythes,
    AS_HELP_STRING([--with-system-mythes],
        [Use mythes already on system.]),,
    [with_system_mythes="$with_system_libs"])

AC_ARG_WITH(system-altlinuxhyph,
    AS_HELP_STRING([--with-system-altlinuxhyph],
        [Use ALTLinuxhyph already on system.]),,
    [with_system_altlinuxhyph="$with_system_libs"])

AC_ARG_WITH(system-lpsolve,
    AS_HELP_STRING([--with-system-lpsolve],
        [Use lpsolve already on system.]),,
    [with_system_lpsolve="$with_system_libs"])

AC_ARG_WITH(system-coinmp,
    AS_HELP_STRING([--with-system-coinmp],
        [Use CoinMP already on system.]),,
    [with_system_coinmp="$with_system_libs"])

AC_ARG_WITH(system-liblangtag,
    AS_HELP_STRING([--with-system-liblangtag],
        [Use liblangtag library already on system.]),,
    [with_system_liblangtag="$with_system_libs"])

AC_ARG_WITH(webdav,
    AS_HELP_STRING([--with-webdav],
        [Specify which library to use for webdav implementation.
         Possible values: "neon", "serf", "no". The default value is "neon".
         Example: --with-webdav="serf"]),
    WITH_WEBDAV=$withval,
    WITH_WEBDAV="neon")

AC_ARG_WITH(linker-hash-style,
    AS_HELP_STRING([--with-linker-hash-style],
        [Use linker with --hash-style=<style> when linking shared objects.
         Possible values: "sysv", "gnu", "both". The default value is "gnu"
         if supported on the build system, and "sysv" otherwise.]))

AC_ARG_WITH(jdk-home,
    AS_HELP_STRING([--with-jdk-home=<absolute path to JDK home>],
        [If you have installed JDK 1.6 or later on your system please supply the
         path here. Note that this is not the location of the java command but the
         location of the entire distribution.]),
,)

AC_ARG_WITH(help,
    AS_HELP_STRING([--with-help],
        [Enable the build of help. There is a special parameter "common" that
         can be used to bundle only the common part, .e.g help-specific icons.
         This is useful when you build the helpcontent separately.])
    [
                          Usage:     --with-help    build the old local help
                                 --without-help     no local help (default)
                                 --with-help=html   build the new HTML local help
                                 --with-help=online build the new HTML online help
                                 --with-help=common bundle common files for the local
                                                    help but do not build the whole help
    ],
,)

libo_FUZZ_ARG_WITH(java,
    AS_HELP_STRING([--with-java=<java command>],
        [Specify the name of the Java interpreter command. Typically "java"
         which is the default.

         To build without support for Java components, applets, accessibility
         or the XML filters written in Java, use --without-java or --with-java=no.]),
    [ test -z "$with_java" -o "$with_java" = "yes" && with_java=java ],
    [ test -z "$with_java" -o "$with_java" = "yes" && with_java=java ]
)

AC_ARG_WITH(jvm-path,
    AS_HELP_STRING([--with-jvm-path=<absolute path to parent of jvm home>],
        [Use a specific JVM search path at runtime.
         e.g. use --with-jvm-path=/usr/lib/ to find JRE/JDK in /usr/lib/jvm/]),
,)

AC_ARG_WITH(ant-home,
    AS_HELP_STRING([--with-ant-home=<absolute path to Ant home>],
        [If you have installed Jakarta Ant on your system, please supply the path here.
         Note that this is not the location of the Ant binary but the location
         of the entire distribution.]),
,)

AC_ARG_WITH(symbol-config,
    AS_HELP_STRING([--with-symbol-config],
        [Configuration for the crashreport symbol upload]),
        [],
        [with_symbol_config=no])

AC_ARG_WITH(export-validation,
    AS_HELP_STRING([--without-export-validation],
        [Disable validating OOXML and ODF files as exported from in-tree tests.
         Use this option e.g. if your system only provides Java 5.]),
,with_export_validation=auto)

AC_ARG_WITH(bffvalidator,
    AS_HELP_STRING([--with-bffvalidator=<absolute path to BFFValidator>],
        [Enables export validation for Microsoft Binary formats (doc, xls, ppt).
         Requires installed Microsoft Office Binary File Format Validator.
         Note: export-validation (--with-export-validation) is required to be turned on.
         See https://www.microsoft.com/en-us/download/details.aspx?id=26794]),
,with_bffvalidator=no)

libo_FUZZ_ARG_WITH(junit,
    AS_HELP_STRING([--with-junit=<absolute path to JUnit 4 jar>],
        [Specifies the JUnit 4 jar file to use for JUnit-based tests.
         --without-junit disables those tests. Not relevant in the --without-java case.]),
,with_junit=yes)

AC_ARG_WITH(hamcrest,
    AS_HELP_STRING([--with-hamcrest=<absolute path to hamcrest jar>],
        [Specifies the hamcrest jar file to use for JUnit-based tests.
         --without-junit disables those tests. Not relevant in the --without-java case.]),
,with_hamcrest=yes)

AC_ARG_WITH(perl-home,
    AS_HELP_STRING([--with-perl-home=<abs. path to Perl 5 home>],
        [If you have installed Perl 5 Distribution, on your system, please
         supply the path here. Note that this is not the location of the Perl
         binary but the location of the entire distribution.]),
,)

libo_FUZZ_ARG_WITH(doxygen,
    AS_HELP_STRING(
        [--with-doxygen=<absolute path to doxygen executable>],
        [Specifies the doxygen executable to use when generating ODK C/C++
         documentation. --without-doxygen disables generation of ODK C/C++
         documentation. Not relevant in the --disable-odk case.]),
,with_doxygen=yes)

AC_ARG_WITH(visual-studio,
    AS_HELP_STRING([--with-visual-studio=<2015/2017>],
        [Specify which Visual Studio version to use in case several are
         installed. If not specified, defaults to 2015.]),
,)

AC_ARG_WITH(windows-sdk,
    AS_HELP_STRING([--with-windows-sdk=<7.1(A)/8.0(A)/8.1(A)/10>],
        [Specify which Windows SDK, or "Windows Kit", version to use
         in case the one that came with the selected Visual Studio
         is not what you want for some reason. Note that not all compiler/SDK
         combinations are supported. The intent is that this option should not
         be needed.]),
,)

AC_ARG_WITH(lang,
    AS_HELP_STRING([--with-lang="es sw tu cs sk"],
        [Use this option to build LibreOffice with additional UI language support.
         English (US) is always included by default.
         Separate multiple languages with space.
         For all languages, use --with-lang=ALL.]),
,)

AC_ARG_WITH(locales,
    AS_HELP_STRING([--with-locales="en es pt fr zh kr ja"],
        [Use this option to limit the locale information built in.
         Separate multiple locales with space.
         Very experimental and might well break stuff.
         Just a desperate measure to shrink code and data size.
         By default all the locales available is included.
         This option is completely unrelated to --with-lang.])
    [
                          Affects also our character encoding conversion
                          tables for encodings mainly targeted for a
                          particular locale, like EUC-CN and EUC-TW for
                          zh, ISO-2022-JP for ja.

                          Affects also our add-on break iterator data for
                          some languages.

                          For the default, all locales, don't use this switch at all.
                          Specifying just the language part of a locale means all matching
                          locales will be included.
    ],
,)

# Kerberos and GSSAPI used only by PostgreSQL as of LibO 3.5
libo_FUZZ_ARG_WITH(krb5,
    AS_HELP_STRING([--with-krb5],
        [Enable MIT Kerberos 5 support in modules that support it.
         By default automatically enabled on platforms
         where a good system Kerberos 5 is available.]),
,)

libo_FUZZ_ARG_WITH(gssapi,
    AS_HELP_STRING([--with-gssapi],
        [Enable GSSAPI support in modules that support it.
         By default automatically enabled on platforms
         where a good system GSSAPI is available.]),
,)

AC_ARG_WITH(iwyu,
    AS_HELP_STRING([--with-iwyu],
        [Use given IWYU binary path to check unneeded includes instead of building.
         Use only if you are hacking on it.]),
,)

dnl ===================================================================
dnl Branding
dnl ===================================================================

AC_ARG_WITH(branding,
    AS_HELP_STRING([--with-branding=/path/to/images],
        [Use given path to retrieve branding images set.])
    [
                          Search for intro.png about.svg and flat_logo.svg.
                          If any is missing, default ones will be used instead.

                          Search also progress.conf for progress
                          settings on intro screen :

                          PROGRESSBARCOLOR="255,255,255" Set color of
                          progress bar. Comma separated RGB decimal values.
                          PROGRESSSIZE="407,6" Set size of progress bar.
                          Comma separated decimal values (width, height).
                          PROGRESSPOSITION="61,317" Set position of progress
                          bar from left,top. Comma separated decimal values.
                          PROGRESSFRAMECOLOR="20,136,3" Set color of progress
                          bar frame. Comma separated RGB decimal values.
                          PROGRESSTEXTCOLOR="255,255,255" Set color of progress
                          bar text. Comma separated RGB decimal values.
                          PROGRESSTEXTBASELINE="287" Set vertical position of
                          progress bar text from top. Decimal value.

                          Default values will be used if not found.
    ],
,)


AC_ARG_WITH(extra-buildid,
    AS_HELP_STRING([--with-extra-buildid="Tinderbox: Win-x86@6, Branch:master, Date:2012-11-26_00.29.34"],
        [Show addition build identification in about dialog.]),
,)


AC_ARG_WITH(vendor,
    AS_HELP_STRING([--with-vendor="John the Builder"],
        [Set vendor of the build.]),
,)

AC_ARG_WITH(android-package-name,
    AS_HELP_STRING([--with-android-package-name="org.libreoffice"],
        [Set Android package name of the build.]),
,)

AC_ARG_WITH(compat-oowrappers,
    AS_HELP_STRING([--with-compat-oowrappers],
        [Install oo* wrappers in parallel with
         lo* ones to keep backward compatibility.
         Has effect only with make distro-pack-install]),
,)

AC_ARG_WITH(os-version,
    AS_HELP_STRING([--with-os-version=<OSVERSION>],
        [For FreeBSD users, use this option to override the detected OSVERSION.]),
,)

AC_ARG_WITH(mingw-cross-compiler,
    AS_HELP_STRING([--with-mingw-cross-compiler=<mingw32-g++ command>],
        [Specify the MinGW cross-compiler to use.
         When building on the ODK on Unix and building unowinreg.dll,
         specify the MinGW C++ cross-compiler.]),
,)

AC_ARG_WITH(idlc-cpp,
    AS_HELP_STRING([--with-idlc-cpp=<cpp/ucpp>],
        [Specify the C Preprocessor to use for idlc. Default is ucpp.]),
,)

AC_ARG_WITH(build-version,
    AS_HELP_STRING([--with-build-version="Built by Jim"],
        [Allows the builder to add a custom version tag that will appear in the
         Help/About box for QA purposes.]),
with_build_version=$withval,
)

AC_ARG_WITH(alloc,
    AS_HELP_STRING([--with-alloc],
        [Define which allocator to build with (choices are oo, system, tcmalloc, jemalloc).
         Note that on FreeBSD/NetBSD system==jemalloc]),
,)

AC_ARG_WITH(parallelism,
    AS_HELP_STRING([--with-parallelism],
        [Number of jobs to run simultaneously during build. Parallel builds can
        save a lot of time on multi-cpu machines. Defaults to the number of
        CPUs on the machine, unless you configure --enable-icecream - then to
        10.]),
,)

AC_ARG_WITH(all-tarballs,
    AS_HELP_STRING([--with-all-tarballs],
        [Download all external tarballs unconditionally]))

AC_ARG_WITH(gdrive-client-id,
    AS_HELP_STRING([--with-gdrive-client-id],
        [Provides the client id of the application for OAuth2 authentication
        on Google Drive. If either this or --with-gdrive-client-secret is
        empty, the feature will be disabled]),
)

AC_ARG_WITH(gdrive-client-secret,
    AS_HELP_STRING([--with-gdrive-client-secret],
        [Provides the client secret of the application for OAuth2
        authentication on Google Drive. If either this or
        --with-gdrive-client-id is empty, the feature will be disabled]),
)

AC_ARG_WITH(alfresco-cloud-client-id,
    AS_HELP_STRING([--with-alfresco-cloud-client-id],
        [Provides the client id of the application for OAuth2 authentication
        on Alfresco Cloud. If either this or --with-alfresco-cloud-client-secret is
        empty, the feature will be disabled]),
)

AC_ARG_WITH(alfresco-cloud-client-secret,
    AS_HELP_STRING([--with-alfresco-cloud-client-secret],
        [Provides the client secret of the application for OAuth2
        authentication on Alfresco Cloud. If either this or
        --with-alfresco-cloud-client-id is empty, the feature will be disabled]),
)

AC_ARG_WITH(onedrive-client-id,
    AS_HELP_STRING([--with-onedrive-client-id],
        [Provides the client id of the application for OAuth2 authentication
        on OneDrive. If either this or --with-onedrive-client-secret is
        empty, the feature will be disabled]),
)

AC_ARG_WITH(onedrive-client-secret,
    AS_HELP_STRING([--with-onedrive-client-secret],
        [Provides the client secret of the application for OAuth2
        authentication on OneDrive. If either this or
        --with-onedrive-client-id is empty, the feature will be disabled]),
)
dnl ===================================================================
dnl Do we want to use pre-build binary tarball for recompile
dnl ===================================================================

if test "$enable_library_bin_tar" = "yes" ; then
    USE_LIBRARY_BIN_TAR=TRUE
else
    USE_LIBRARY_BIN_TAR=
fi
AC_SUBST(USE_LIBRARY_BIN_TAR)

dnl ===================================================================
dnl Test whether build target is Release Build
dnl ===================================================================
AC_MSG_CHECKING([whether build target is Release Build])
if test "$enable_release_build" = "" -o "$enable_release_build" = "no"; then
    AC_MSG_RESULT([no])
    ENABLE_RELEASE_BUILD=
else
    AC_MSG_RESULT([yes])
    ENABLE_RELEASE_BUILD=TRUE
fi
AC_SUBST(ENABLE_RELEASE_BUILD)

dnl ===================================================================
dnl Test whether to sign Windows Build
dnl ===================================================================
AC_MSG_CHECKING([whether to sign windows build])
if test "$enable_windows_build_signing" = "yes" -a "$_os" = "WINNT"; then
    AC_MSG_RESULT([yes])
    WINDOWS_BUILD_SIGNING="TRUE"
else
    AC_MSG_RESULT([no])
    WINDOWS_BUILD_SIGNING="FALSE"
fi
AC_SUBST(WINDOWS_BUILD_SIGNING)

dnl ===================================================================
dnl MacOSX build and runtime environment options
dnl ===================================================================

AC_ARG_WITH(macosx-sdk,
    AS_HELP_STRING([--with-macosx-sdk=<version>],
        [Prefer a specific SDK for building.])
    [
                          If the requested SDK is not available, a search for the oldest one will be done.
                          With current Xcode versions, only the latest SDK is included, so this option is
                          not terribly useful. It works fine to build with a new SDK and run the result
                          on an older OS.

                          e. g.: --with-macosx-sdk=10.9

                          there are 3 options to control the MacOSX build:
                          --with-macosx-sdk (referred as 'sdk' below)
                          --with-macosx-version-min-required (referred as 'min' below)
                          --with-macosx-version-max-allowed (referred as 'max' below)

                          the connection between these value and the default they take is as follow:
                          ( ? means not specified on the command line, s means the SDK version found,
                          constraint: 8 <= x <= y <= z)

                          ==========================================
                           command line      || config result
                          ==========================================
                          min  | max  | sdk  || min  | max  | sdk  |
                          ?    | ?    | ?    || 10.9 | 10.s | 10.s |
                          ?    | ?    | 10.x || 10.9 | 10.x | 10.x |
                          ?    | 10.x | ?    || 10.9 | 10.s | 10.s |
                          ?    | 10.x | 10.y || 10.9 | 10.x | 10.y |
                          10.x | ?    | ?    || 10.x | 10.s | 10.s |
                          10.x | ?    | 10.y || 10.x | 10.y | 10.y |
                          10.x | 10.y | ?    || 10.x | 10.y | 10.y |
                          10.x | 10.y | 10.z || 10.x | 10.y | 10.z |


                          see: http://developer.apple.com/library/mac/#technotes/tn2064/_index.html
                          for a detailed technical explanation of these variables

                          Note: MACOSX_DEPLOYMENT_TARGET will be set to the value of 'min'.
    ],
,)

AC_ARG_WITH(macosx-version-min-required,
    AS_HELP_STRING([--with-macosx-version-min-required=<version>],
        [set the minimum OS version needed to run the built LibreOffice])
    [
                          e. g.: --with-macos-version-min-required=10.9
                          see --with-macosx-sdk for more info
    ],
,)

AC_ARG_WITH(macosx-version-max-allowed,
    AS_HELP_STRING([--with-macosx-version-max-allowed=<version>],
        [set the maximum allowed OS version the LibreOffice compilation can use APIs from])
    [
                          e. g.: --with-macos-version-max-allowed=10.9
                          see --with-macosx-sdk for more info
    ],
,)


dnl ===================================================================
dnl options for stuff used during cross-compilation build
dnl Not quite superseded by --with-build-platform-configure-options.
dnl TODO: check, if the "force" option is still needed anywhere.
dnl ===================================================================

AC_ARG_WITH(system-icu-for-build,
    AS_HELP_STRING([--with-system-icu-for-build=yes/no/force],
        [Use icu already on system for build tools (cross-compilation only).]))


dnl ===================================================================
dnl Check for incompatible options set by fuzzing, and reset those
dnl automatically to working combinations
dnl ===================================================================

if test "$libo_fuzzed_enable_dbus" = yes -a "$libo_fuzzed_enable_avahi" -a \
        "$enable_dbus" != "$enable_avahi"; then
    AC_MSG_NOTICE([Resetting --enable-avahi=$enable_dbus])
    enable_avahi=$enable_dbus
fi

dnl ===================================================================
dnl check for required programs (grep, awk, sed, bash)
dnl ===================================================================

pathmunge ()
{
    if test -n "$1"; then
        if test "$build_os" = "cygwin"; then
            if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
                PathFormat "$1"
                new_path=`cygpath -sm "$formatted_path"`
            else
                PathFormat "$1"
                new_path=`cygpath -u "$formatted_path"`
            fi
        else
            new_path="$1"
        fi
        if ! echo "$LO_PATH" | $EGREP -q "(^|:)$1($|:)"; then
            if test "$2" = "after"; then
                LO_PATH="$LO_PATH${P_SEP}$new_path"
            else
                LO_PATH="$new_path${P_SEP}$LO_PATH"
            fi
        fi
        unset new_path
    fi
}

AC_PROG_AWK
AC_PATH_PROG( AWK, $AWK)
if test -z "$AWK"; then
    AC_MSG_ERROR([install awk to run this script])
fi

AC_PATH_PROG(BASH, bash)
if test -z "$BASH"; then
    AC_MSG_ERROR([bash not found in \$PATH])
fi
AC_SUBST(BASH)

AC_MSG_CHECKING([for GNU or BSD tar])
for a in $GNUTAR gtar gnutar bsdtar tar /usr/sfw/bin/gtar; do
    $a --version 2> /dev/null | egrep "GNU|bsdtar"  2>&1 > /dev/null
    if test $? -eq 0;  then
        GNUTAR=$a
        break
    fi
done
AC_MSG_RESULT($GNUTAR)
if test -z "$GNUTAR"; then
    AC_MSG_ERROR([not found. install GNU or BSD tar.])
fi
AC_SUBST(GNUTAR)

AC_MSG_CHECKING([for tar's option to strip components])
$GNUTAR --help 2> /dev/null | egrep "bsdtar|strip-components" 2>&1 >/dev/null
if test $? -eq 0; then
    STRIP_COMPONENTS="--strip-components"
else
    $GNUTAR --help 2> /dev/null | egrep "strip-path" 2>&1 >/dev/null
    if test $? -eq 0; then
        STRIP_COMPONENTS="--strip-path"
    else
        STRIP_COMPONENTS="unsupported"
    fi
fi
AC_MSG_RESULT($STRIP_COMPONENTS)
if test x$STRIP_COMPONENTS = xunsupported; then
    AC_MSG_ERROR([you need a tar that is able to strip components.])
fi
AC_SUBST(STRIP_COMPONENTS)

dnl It is useful to have a BUILD_TYPE keyword to distinguish "normal"
dnl desktop OSes from "mobile" ones.

dnl We assume that a non-DESKTOP build type is also a non-NATIVE one.
dnl In other words, that when building for an OS that is not a
dnl "desktop" one but a "mobile" one, we are always cross-compiling.

dnl Note the direction of the implication; there is no assumption that
dnl cross-compiling would imply a non-desktop OS.

if test $_os != iOS -a $_os != Android -a "$enable_fuzzers" != "yes"; then
    BUILD_TYPE="$BUILD_TYPE DESKTOP"
    AC_DEFINE(HAVE_FEATURE_DESKTOP)
    AC_DEFINE(HAVE_FEATURE_MULTIUSER_ENVIRONMENT)
fi

# Whether to build "avmedia" functionality or not.

if test -z "$enable_avmedia"; then
    enable_avmedia=yes
fi

BUILD_TYPE="$BUILD_TYPE AVMEDIA"
if test "$enable_avmedia" = yes; then
    AC_DEFINE(HAVE_FEATURE_AVMEDIA)
else
    USE_AVMEDIA_DUMMY='TRUE'
fi
AC_SUBST(USE_AVMEDIA_DUMMY)

# Decide whether to build database connectivity stuff (including
# Base) or not. We probably don't want to on non-desktop OSes.
if test -z "$enable_database_connectivity"; then
    # --disable-database-connectivity is unfinished work in progress
    # and the iOS test app doesn't link if we actually try to use it.
    # if test $_os != iOS -a $_os != Android; then
    if test $_os != iOS; then
        enable_database_connectivity=yes
    fi
fi

if test "$enable_database_connectivity" = yes; then
    BUILD_TYPE="$BUILD_TYPE DBCONNECTIVITY"
    AC_DEFINE(HAVE_FEATURE_DBCONNECTIVITY)
fi

if test -z "$enable_extensions"; then
    # For iOS and Android disable extensions unless specifically overridden with --enable-extensions.
    if test $_os != iOS -a $_os != Android; then
        enable_extensions=yes
    fi
fi

if test "$enable_extensions" = yes; then
    BUILD_TYPE="$BUILD_TYPE EXTENSIONS"
    AC_DEFINE(HAVE_FEATURE_EXTENSIONS)
fi

if test -z "$enable_scripting"; then
    # Disable scripting for iOS unless specifically overridden
    # with --enable-scripting.
    if test $_os != iOS; then
        enable_scripting=yes
    fi
fi

DISABLE_SCRIPTING=''
if test "$enable_scripting" = yes; then
    BUILD_TYPE="$BUILD_TYPE SCRIPTING"
    AC_DEFINE(HAVE_FEATURE_SCRIPTING)
else
    DISABLE_SCRIPTING='TRUE'
    SCPDEFS="$SCPDEFS -DDISABLE_SCRIPTING"
fi

if test $_os = iOS -o $_os = Android; then
    # Disable dynamic_loading always for iOS and Android
    enable_dynamic_loading=no
elif test -z "$enable_dynamic_loading"; then
    # Otherwise enable it unless speficically disabled
    enable_dynamic_loading=yes
fi

DISABLE_DYNLOADING=''
if test "$enable_dynamic_loading" = yes; then
    BUILD_TYPE="$BUILD_TYPE DYNLOADING"
else
    DISABLE_DYNLOADING='TRUE'
fi
AC_SUBST(DISABLE_DYNLOADING)

# remenber SYSBASE value
AC_SUBST(SYSBASE)

dnl ===================================================================
dnl  Sort out various gallery compilation options
dnl ===================================================================
AC_MSG_CHECKING([how to build and package galleries])
if test -n "${with_galleries}"; then
    if test "$with_galleries" = "build"; then
        WITH_GALLERY_BUILD=TRUE
        AC_MSG_RESULT([build from source images internally])
    elif test "$with_galleries" = "no"; then
        WITH_GALLERY_BUILD=
        AC_MSG_RESULT([disable non-internal gallery build])
    else
        AC_MSG_ERROR([unknown value --with-galleries=$with_galleries])
    fi
else
    if test $_os != iOS -a $_os != Android; then
        WITH_GALLERY_BUILD=TRUE
        AC_MSG_RESULT([internal src images for desktop])
    else
        WITH_GALLERY_BUILD=
        AC_MSG_RESULT([disable src image build])
    fi
fi
AC_SUBST(WITH_GALLERY_BUILD)

dnl ===================================================================
dnl  Checks if ccache is available
dnl ===================================================================
if test "$_os" = "WINNT"; then
    # on windows/VC build do not use ccache
    CCACHE=""
elif test "$enable_ccache" = "yes" -o \( "$enable_ccache" = "" -a "$enable_icecream" != "yes" \); then
    case "%$CC%$CXX%" in
    # If $CC and/or $CXX already contain "ccache" (possibly suffixed with some version number etc),
    # assume that's good then
    *%ccache[[-_' ']]*|*/ccache[[-_' ']]*)
        AC_MSG_NOTICE([ccache seems to be included in a pre-defined CC and/or CXX])
        ;;
    *)
        AC_PATH_PROG([CCACHE],[ccache],[not found])
        if test "$CCACHE" = "not found"; then
            CCACHE=""
        else
            # Need to check for ccache version: otherwise prevents
            # caching of the results (like "-x objective-c++" for Mac)
            if test $_os = Darwin -o $_os = iOS; then
                # Check ccache version
                AC_MSG_CHECKING([whether version of ccache is suitable])
                CCACHE_VERSION=`"$CCACHE" -V | "$AWK" '/^ccache version/{print $3}'`
                CCACHE_NUMVER=`echo $CCACHE_VERSION | $AWK -F. '{ print \$1*10000+\$2*100+\$3 }'`
                if test "$CCACHE_VERSION" = "2.4_OOo" -o "$CCACHE_NUMVER" -ge "030100"; then
                    AC_MSG_RESULT([yes, $CCACHE_VERSION])
                else
                    AC_MSG_RESULT([no, $CCACHE_VERSION])
                    CCACHE=""
                fi
            fi
        fi
        ;;
    esac
else
    CCACHE=""
fi

if test "$CCACHE" != ""; then
    ccache_size_msg=$([ccache -s | tail -n 1 | sed 's/^[^0-9]*//' | sed -e 's/\.[0-9]*//'])
    ccache_size=$(echo "$ccache_size_msg" | grep "G" | sed -e 's/G.*$//')
    if test "$ccache_size" = ""; then
        ccache_size=$(echo "$ccache_size_msg" | grep "M" | sed -e 's/\ M.*$//')
        if test "$ccache_size" = ""; then
            ccache_size=0
        fi
        # we could not determine the size or it was less than 1GB -> disable auto-ccache
        if test $ccache_size -lt 1024; then
            CCACHE=""
            AC_MSG_WARN([ccache's cache size is less than 1GB using it is counter-productive: Disabling auto-ccache detection])
            add_warning "ccache's cache size is less than 1GB using it is counter-productive: auto-ccache detection disabled"
        else
            # warn that ccache may be too small for debug build
            AC_MSG_WARN([ccache's cache size is less than 5GB using it may be counter-productive for debug or symbol-enabled build])
            add_warning "ccache's cache size is less than 5GB using it may be counter-productive for debug or symbol-enabled build"
        fi
    else
        if test $ccache_size -lt 5; then
            #warn that ccache may be too small for debug build
            AC_MSG_WARN([ccache's cache size is less than 5GB using it may be counter-productive for debug or symbol-enabled build])
            add_warning "ccache's cache size is less than 5GB using it may be counter-productive for debug or symbol-enabled build"
        fi
    fi
fi

dnl ===================================================================
dnl  Checks for C compiler,
dnl  The check for the C++ compiler is later on.
dnl ===================================================================
if test "$_os" != "WINNT"; then
    GCC_HOME_SET="true"
    AC_MSG_CHECKING([gcc home])
    if test -z "$with_gcc_home"; then
        if test "$enable_icecream" = "yes"; then
            if test -d "/usr/lib/icecc/bin"; then
                GCC_HOME="/usr/lib/icecc/"
            else
                GCC_HOME="/opt/icecream/"
            fi
        else
            GCC_HOME=`which gcc | $SED -e s,/bin/gcc,,`
            GCC_HOME_SET="false"
        fi
    else
        GCC_HOME="$with_gcc_home"
    fi
    AC_MSG_RESULT($GCC_HOME)
    AC_SUBST(GCC_HOME)

    if test "$GCC_HOME_SET" = "true"; then
        if test -z "$CC"; then
            CC="$GCC_HOME/bin/gcc"
        fi
        if test -z "$CXX"; then
            CXX="$GCC_HOME/bin/g++"
        fi
    fi
fi

COMPATH=`dirname "$CC"`
if test "$COMPATH" = "."; then
    AC_PATH_PROGS(COMPATH, $CC)
    dnl double square bracket to get single because of M4 quote...
    COMPATH=`echo $COMPATH | $SED "s@/[[^/:]]*\\\$@@"`
fi
COMPATH=`echo $COMPATH | $SED "s@/[[Bb]][[Ii]][[Nn]]\\\$@@"`

dnl ===================================================================
dnl Java support
dnl ===================================================================
AC_MSG_CHECKING([whether to build with Java support])
if test "$with_java" != "no"; then
    if test "$DISABLE_SCRIPTING" = TRUE; then
        AC_MSG_RESULT([no, overridden by --disable-scripting])
        ENABLE_JAVA=""
        with_java=no
    else
        AC_MSG_RESULT([yes])
        ENABLE_JAVA="TRUE"
        AC_DEFINE(HAVE_FEATURE_JAVA)
    fi
else
    AC_MSG_RESULT([no])
    ENABLE_JAVA=""
fi

AC_SUBST(ENABLE_JAVA)

dnl ENABLE_JAVA="TRUE" if we want there to be *run-time* (and build-time) support for Java

dnl ENABLE_JAVA="" indicate no Java support at all

dnl ===================================================================
dnl Check OS X SDK and compiler
dnl ===================================================================

if test $_os = Darwin -o $_os = iOS; then

    # If no --with-macosx-sdk option is given, look for one

    # The intent is that for "most" Mac-based developers, a suitable
    # SDK will be found automatically without any configure options.

    # For developers with a current Xcode, the lowest-numbered SDK
    # higher than or equal to the minimum required should be found.

    AC_MSG_CHECKING([what Mac OS X SDK to use])
    for _macosx_sdk in ${with_macosx_sdk-10.14 10.13 10.12}; do
        MACOSX_SDK_PATH=`xcrun --sdk macosx${_macosx_sdk} --show-sdk-path 2> /dev/null`
        if test -d "$MACOSX_SDK_PATH"; then
            with_macosx_sdk="${_macosx_sdk}"
            break
        else
            MACOSX_SDK_PATH="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_macosx_sdk}.sdk"
            if test -d "$MACOSX_SDK_PATH"; then
                with_macosx_sdk="${_macosx_sdk}"
                break
            fi
        fi
    done
    if test ! -d "$MACOSX_SDK_PATH"; then
        AC_MSG_ERROR([Could not figure out the location of a Mac OS X SDK and its version])
    fi

    if test $_os = iOS; then
        if test "$enable_ios_simulator" = "yes"; then
            useos=iphonesimulator
        else
            useos=iphoneos
        fi
        MACOSX_SDK_PATH=`xcrun --sdk ${useos} --show-sdk-path 2> /dev/null`
    fi
    AC_MSG_RESULT([SDK $with_macosx_sdk at $MACOSX_SDK_PATH])


    case $with_macosx_sdk in
    10.9)
        MACOSX_SDK_VERSION=1090
        ;;
    10.10)
        MACOSX_SDK_VERSION=101000
        ;;
    10.11)
        MACOSX_SDK_VERSION=101100
        ;;
    10.12)
        MACOSX_SDK_VERSION=101200
        ;;
    10.13)
        MACOSX_SDK_VERSION=101300
        ;;
    10.14)
        MACOSX_SDK_VERSION=101400
        ;;
    *)
        AC_MSG_ERROR([with-macosx-sdk $with_macosx_sdk is not a supported value, supported values are 10.9--13])
        ;;
    esac

    if test "$with_macosx_version_min_required" = "" ; then
        with_macosx_version_min_required="10.9";
    fi

    if test "$with_macosx_version_max_allowed" = "" ; then
        with_macosx_version_max_allowed="$with_macosx_sdk"
    fi

    # export this so that "xcrun" invocations later return matching values
    DEVELOPER_DIR="${MACOSX_SDK_PATH%/SDKs*}"
    DEVELOPER_DIR="${DEVELOPER_DIR%/Platforms*}"
    export DEVELOPER_DIR
    FRAMEWORKSHOME="$MACOSX_SDK_PATH/System/Library/Frameworks"
    MACOSX_DEPLOYMENT_TARGET="$with_macosx_version_min_required"

    case "$with_macosx_version_min_required" in
    10.9)
        MAC_OS_X_VERSION_MIN_REQUIRED="1090"
        ;;
    10.10)
        MAC_OS_X_VERSION_MIN_REQUIRED="101000"
        ;;
    10.11)
        MAC_OS_X_VERSION_MIN_REQUIRED="101100"
        ;;
    10.12)
        MAC_OS_X_VERSION_MIN_REQUIRED="101200"
        ;;
    10.13)
        MAC_OS_X_VERSION_MIN_REQUIRED="101300"
        ;;
    10.14)
        MAC_OS_X_VERSION_MIN_REQUIRED="101400"
        ;;
    *)
        AC_MSG_ERROR([with-macosx-version-min-required $with_macosx_version_min_required is not a supported value, supported values are 10.9--13])
        ;;
    esac
    MAC_OS_X_VERSION_MIN_REQUIRED_DOTS=$with_macosx_version_min_required

    LIBTOOL=/usr/bin/libtool
    INSTALL_NAME_TOOL=install_name_tool
    if test -z "$save_CC"; then
        AC_MSG_CHECKING([what compiler to use])
        stdlib=-stdlib=libc++
        if test "$ENABLE_LTO" = TRUE; then
            lto=-flto
        fi
        CC="`xcrun -find clang` -m64 $lto -mmacosx-version-min=$with_macosx_version_min_required -isysroot $MACOSX_SDK_PATH"
        CXX="`xcrun -find clang++` -m64 $lto $stdlib -mmacosx-version-min=$with_macosx_version_min_required -isysroot $MACOSX_SDK_PATH"
        INSTALL_NAME_TOOL=`xcrun -find install_name_tool`
        AR=`xcrun -find ar`
        NM=`xcrun -find nm`
        STRIP=`xcrun -find strip`
        LIBTOOL=`xcrun -find libtool`
        RANLIB=`xcrun -find ranlib`
        AC_MSG_RESULT([$CC and $CXX])
    fi

    case "$with_macosx_version_max_allowed" in
    10.9)
        MAC_OS_X_VERSION_MAX_ALLOWED="1090"
        ;;
    10.10)
        MAC_OS_X_VERSION_MAX_ALLOWED="101000"
        ;;
    10.11)
        MAC_OS_X_VERSION_MAX_ALLOWED="101100"
        ;;
    10.12)
        MAC_OS_X_VERSION_MAX_ALLOWED="101200"
        ;;
    10.13)
        MAC_OS_X_VERSION_MAX_ALLOWED="101300"
        ;;
    10.14)
        MAC_OS_X_VERSION_MAX_ALLOWED="101400"
        ;;
    *)
        AC_MSG_ERROR([with-macosx-version-max-allowed $with_macosx_version_max_allowed is not a supported value, supported values are 10.9--13])
        ;;
    esac

    AC_MSG_CHECKING([that macosx-version-min-required is coherent with macosx-version-max-allowed])
    if test $MAC_OS_X_VERSION_MIN_REQUIRED -gt $MAC_OS_X_VERSION_MAX_ALLOWED; then
        AC_MSG_RESULT([$MAC_OS_X_VERSION_MIN_REQUIRED])
        AC_MSG_RESULT([$MAC_OS_X_VERSION_MAX_REQUIRED])
        AC_MSG_ERROR([the version minimumn required must be inferior or equal to the version maximum allowed])
    else
        AC_MSG_RESULT([ok])
    fi

    AC_MSG_CHECKING([that macosx-version-max-allowed is coherent with macos-with-sdk])
    if test $MAC_OS_X_VERSION_MAX_ALLOWED -gt $MACOSX_SDK_VERSION; then
        AC_MSG_ERROR([the version maximum allowed cannot be greater than the sdk level])
    else
        AC_MSG_RESULT([ok])
    fi
    AC_MSG_NOTICE([MAC_OS_X_VERSION_MIN_REQUIRED=$MAC_OS_X_VERSION_MIN_REQUIRED])
    AC_MSG_NOTICE([MAC_OS_X_VERSION_MAX_ALLOWED=$MAC_OS_X_VERSION_MAX_ALLOWED])

    AC_MSG_CHECKING([whether to do code signing])

    if test "$enable_macosx_code_signing" = yes; then
        # By default use the first suitable certificate (?).

        # http://stackoverflow.com/questions/13196291/difference-between-mac-developer-and-3rd-party-mac-developer-application
        # says that the "Mac Developer" certificate is useful just for self-testing. For distribution
        # outside the Mac App Store, use the "Developer ID Application" one, and for distribution in
        # the App Store, the "3rd Party Mac Developer" one. I think it works best to the
        # "Developer ID Application" one.

        identity=`security find-identity -p codesigning -v 2>/dev/null | grep 'Developer ID Application:' | $AWK '{print $2}' |head -1`
        if test -n "$identity"; then
            MACOSX_CODESIGNING_IDENTITY=$identity
            pretty_name=`security find-identity -p codesigning -v | grep "$MACOSX_CODESIGNING_IDENTITY" | sed -e 's/^[[^"]]*"//' -e 's/"//'`
            AC_MSG_RESULT([yes, using the identity $MACOSX_CODESIGNING_IDENTITY for $pretty_name])
        else
            AC_MSG_ERROR([cannot determine identity to use])
        fi
    elif test -n "$enable_macosx_code_signing" -a "$enable_macosx_code_signing" != no ; then
        MACOSX_CODESIGNING_IDENTITY=$enable_macosx_code_signing
        pretty_name=`security find-identity -p codesigning -v | grep "$MACOSX_CODESIGNING_IDENTITY" | sed -e 's/^[[^"]]*"//' -e 's/"//'`
        AC_MSG_RESULT([yes, using the identity $MACOSX_CODESIGNING_IDENTITY for $pretty_name])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether to create a Mac App Store package])

    if test -n "$enable_macosx_package_signing" -a -z "$MACOSX_CODESIGNING_IDENTITY"; then
        AC_MSG_ERROR([You forgot --enable-macosx-code-signing])
    elif test "$enable_macosx_package_signing" = yes; then
        # By default use the first suitable certificate.
        # It should be a "3rd Party Mac Developer Installer" one

        identity=`security find-identity -v 2>/dev/null | grep '3rd Party Mac Developer Installer:' | awk '{print $2}' |head -1`
        if test -n "$identity"; then
            MACOSX_PACKAGE_SIGNING_IDENTITY=$identity
            pretty_name=`security find-identity -v | grep "$MACOSX_PACKAGE_SIGNING_IDENTITY" | sed -e 's/^[[^"]]*"//' -e 's/"//'`
            AC_MSG_RESULT([yes, using the identity $MACOSX_PACKAGE_SIGNING_IDENTITY for $pretty_name])
        else
            AC_MSG_ERROR([Could not find any suitable '3rd Party Mac Developer Installer' certificate])
        fi
    elif test -n "$enable_macosx_package_signing"; then
        MACOSX_PACKAGE_SIGNING_IDENTITY=$enable_macosx_package_signing
        pretty_name=`security find-identity -v | grep "$MACOSX_PACKAGE_SIGNING_IDENTITY" | sed -e 's/^[[^"]]*"//' -e 's/"//'`
        AC_MSG_RESULT([yes, using the identity $MACOSX_PACKAGE_SIGNING_IDENTITY for $pretty_name])
    else
        AC_MSG_RESULT([no])
    fi

    if test -n "$MACOSX_CODESIGNING_IDENTITY" -a -n "$MACOSX_PACKAGE_SIGNING_IDENTITY" -a "$MACOSX_CODESIGNING_IDENTITY" = "$MACOSX_PACKAGE_SIGNING_IDENTITY"; then
        AC_MSG_ERROR([You should not use the same identity for code and package signing])
    fi

    AC_MSG_CHECKING([whether to sandbox the application])

    if test -z "$MACOSX_CODESIGNING_IDENTITY" -a "$enable_macosx_sandbox" = yes; then
        AC_MSG_ERROR([OS X sandboxing requires code signing])
    elif test -n "$ENABLE_JAVA" -a "$enable_macosx_sandbox" = yes; then
        AC_MSG_ERROR([OS X sandboxing (actually App Store rules) disallows use of Java])
    elif test -n "$MACOSX_CODESIGNING_IDENTITY" -a "$enable_macosx_sandbox" = yes; then
        ENABLE_MACOSX_SANDBOX=TRUE
        AC_DEFINE(HAVE_FEATURE_MACOSX_SANDBOX)
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([what OS X app bundle identifier to use])
    MACOSX_BUNDLE_IDENTIFIER=$with_macosx_bundle_identifier
    AC_MSG_RESULT([$MACOSX_BUNDLE_IDENTIFIER])
fi
AC_SUBST(MACOSX_SDK_PATH)
AC_SUBST(MACOSX_SDK_VERSION)
AC_SUBST(MACOSX_DEPLOYMENT_TARGET)
AC_SUBST(MAC_OS_X_VERSION_MIN_REQUIRED)
AC_SUBST(MAC_OS_X_VERSION_MIN_REQUIRED_DOTS)
AC_SUBST(MAC_OS_X_VERSION_MAX_ALLOWED)
AC_SUBST(INSTALL_NAME_TOOL)
AC_SUBST(LIBTOOL) # Note that the OS X libtool command is unrelated to GNU libtool
AC_SUBST(MACOSX_CODESIGNING_IDENTITY)
AC_SUBST(MACOSX_PACKAGE_SIGNING_IDENTITY)
AC_SUBST(ENABLE_MACOSX_SANDBOX)
AC_SUBST(MACOSX_BUNDLE_IDENTIFIER)

dnl ===================================================================
dnl Check iOS SDK and compiler
dnl ===================================================================

if test $_os = iOS; then
    AC_MSG_CHECKING([what iOS SDK to use])
    current_sdk_ver=12.2
    older_sdk_vers="12.1 12.0 11.4 11.2"
    if test "$enable_ios_simulator" = "yes"; then
        platform=iPhoneSimulator
        versionmin=-mios-simulator-version-min=11.0
    else
        platform=iPhoneOS
        versionmin=-miphoneos-version-min=11.0
    fi
    xcode_developer=`xcode-select -print-path`

    for sdkver in $current_sdk_ver $older_sdk_vers; do
        t=$xcode_developer/Platforms/$platform.platform/Developer/SDKs/$platform$sdkver.sdk
        if test -d $t; then
            sysroot=$t
            break
        fi
    done

    if test -z "$sysroot"; then
        AC_MSG_ERROR([Could not find iOS SDK, expected something like $xcode_developer/Platforms/$platform.platform/Developer/SDKs/${platform}${current_sdk_ver}.sdk])
    fi

    AC_MSG_RESULT($sysroot)

    # LTO is not really recommended for iOS builds,
    # the link time will be astronomical
    if test "$ENABLE_LTO" = TRUE; then
        lto=-flto
    fi

    stdlib="-stdlib=libc++"

    CC="`xcrun -find clang` -arch $host_cpu -isysroot $sysroot $lto $versionmin"
    CXX="`xcrun -find clang++` -arch $host_cpu $stdlib -isysroot $sysroot $lto $versionmin"

    INSTALL_NAME_TOOL=`xcrun -find install_name_tool`
    AR=`xcrun -find ar`
    NM=`xcrun -find nm`
    STRIP=`xcrun -find strip`
    LIBTOOL=`xcrun -find libtool`
    RANLIB=`xcrun -find ranlib`
fi

AC_MSG_CHECKING([whether to treat the installation as read-only])

if test \( -z "$enable_readonly_installset" -a "$ENABLE_MACOSX_SANDBOX" = TRUE \) -o \
        "$enable_extensions" != yes; then
    enable_readonly_installset=yes
fi
if test "$enable_readonly_installset" = yes; then
    AC_MSG_RESULT([yes])
    AC_DEFINE(HAVE_FEATURE_READONLY_INSTALLSET)
else
    AC_MSG_RESULT([no])
fi

dnl ===================================================================
dnl Structure of install set
dnl ===================================================================

if test $_os = Darwin; then
    LIBO_BIN_FOLDER=MacOS
    LIBO_ETC_FOLDER=Resources
    LIBO_LIBEXEC_FOLDER=MacOS
    LIBO_LIB_FOLDER=Frameworks
    LIBO_LIB_PYUNO_FOLDER=Resources
    LIBO_SHARE_FOLDER=Resources
    LIBO_SHARE_HELP_FOLDER=Resources/help
    LIBO_SHARE_JAVA_FOLDER=Resources/java
    LIBO_SHARE_PRESETS_FOLDER=Resources/presets
    LIBO_SHARE_READMES_FOLDER=Resources/readmes
    LIBO_SHARE_RESOURCE_FOLDER=Resources/resource
    LIBO_SHARE_SHELL_FOLDER=Resources/shell
    LIBO_URE_BIN_FOLDER=MacOS
    LIBO_URE_ETC_FOLDER=Resources/ure/etc
    LIBO_URE_LIB_FOLDER=Frameworks
    LIBO_URE_MISC_FOLDER=Resources/ure/share/misc
    LIBO_URE_SHARE_JAVA_FOLDER=Resources/java
elif test $_os = WINNT; then
    LIBO_BIN_FOLDER=program
    LIBO_ETC_FOLDER=program
    LIBO_LIBEXEC_FOLDER=program
    LIBO_LIB_FOLDER=program
    LIBO_LIB_PYUNO_FOLDER=program
    LIBO_SHARE_FOLDER=share
    LIBO_SHARE_HELP_FOLDER=help
    LIBO_SHARE_JAVA_FOLDER=program/classes
    LIBO_SHARE_PRESETS_FOLDER=presets
    LIBO_SHARE_READMES_FOLDER=readmes
    LIBO_SHARE_RESOURCE_FOLDER=program/resource
    LIBO_SHARE_SHELL_FOLDER=program/shell
    LIBO_URE_BIN_FOLDER=program
    LIBO_URE_ETC_FOLDER=program
    LIBO_URE_LIB_FOLDER=program
    LIBO_URE_MISC_FOLDER=program
    LIBO_URE_SHARE_JAVA_FOLDER=program/classes
else
    LIBO_BIN_FOLDER=program
    LIBO_ETC_FOLDER=program
    LIBO_LIBEXEC_FOLDER=program
    LIBO_LIB_FOLDER=program
    LIBO_LIB_PYUNO_FOLDER=program
    LIBO_SHARE_FOLDER=share
    LIBO_SHARE_HELP_FOLDER=help
    LIBO_SHARE_JAVA_FOLDER=program/classes
    LIBO_SHARE_PRESETS_FOLDER=presets
    LIBO_SHARE_READMES_FOLDER=readmes
    if test "$enable_fuzzers" != yes; then
        LIBO_SHARE_RESOURCE_FOLDER=program/resource
    else
        LIBO_SHARE_RESOURCE_FOLDER=resource
    fi
    LIBO_SHARE_SHELL_FOLDER=program/shell
    LIBO_URE_BIN_FOLDER=program
    LIBO_URE_ETC_FOLDER=program
    LIBO_URE_LIB_FOLDER=program
    LIBO_URE_MISC_FOLDER=program
    LIBO_URE_SHARE_JAVA_FOLDER=program/classes
fi
AC_DEFINE_UNQUOTED(LIBO_BIN_FOLDER,"$LIBO_BIN_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_ETC_FOLDER,"$LIBO_ETC_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_LIBEXEC_FOLDER,"$LIBO_LIBEXEC_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_LIB_FOLDER,"$LIBO_LIB_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_LIB_PYUNO_FOLDER,"$LIBO_LIB_PYUNO_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_FOLDER,"$LIBO_SHARE_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_HELP_FOLDER,"$LIBO_SHARE_HELP_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_JAVA_FOLDER,"$LIBO_SHARE_JAVA_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_PRESETS_FOLDER,"$LIBO_SHARE_PRESETS_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_RESOURCE_FOLDER,"$LIBO_SHARE_RESOURCE_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_SHARE_SHELL_FOLDER,"$LIBO_SHARE_SHELL_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_URE_BIN_FOLDER,"$LIBO_URE_BIN_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_URE_ETC_FOLDER,"$LIBO_URE_ETC_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_URE_LIB_FOLDER,"$LIBO_URE_LIB_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_URE_MISC_FOLDER,"$LIBO_URE_MISC_FOLDER")
AC_DEFINE_UNQUOTED(LIBO_URE_SHARE_JAVA_FOLDER,"$LIBO_URE_SHARE_JAVA_FOLDER")

# Not all of them needed in config_host.mk, add more if need arises
AC_SUBST(LIBO_BIN_FOLDER)
AC_SUBST(LIBO_ETC_FOLDER)
AC_SUBST(LIBO_LIB_FOLDER)
AC_SUBST(LIBO_LIB_PYUNO_FOLDER)
AC_SUBST(LIBO_SHARE_FOLDER)
AC_SUBST(LIBO_SHARE_HELP_FOLDER)
AC_SUBST(LIBO_SHARE_JAVA_FOLDER)
AC_SUBST(LIBO_SHARE_PRESETS_FOLDER)
AC_SUBST(LIBO_SHARE_READMES_FOLDER)
AC_SUBST(LIBO_SHARE_RESOURCE_FOLDER)
AC_SUBST(LIBO_URE_BIN_FOLDER)
AC_SUBST(LIBO_URE_ETC_FOLDER)
AC_SUBST(LIBO_URE_LIB_FOLDER)
AC_SUBST(LIBO_URE_MISC_FOLDER)
AC_SUBST(LIBO_URE_SHARE_JAVA_FOLDER)

dnl ===================================================================
dnl Windows specific tests and stuff
dnl ===================================================================

reg_get_value()
{
    # Return value: $regvalue
    unset regvalue

    local _regentry="/proc/registry${1}/${2}"
    if test -f "$_regentry"; then
        # Stop bash complaining about \0 bytes in input, as it can't handle them.
        # Registry keys read via /proc/registry* are always \0 terminated!
        local _regvalue=$(tr -d '\0' < "$_regentry")
        if test $? -eq 0; then
            regvalue=$_regvalue
        fi
    fi
}

# Get a value from the 32-bit side of the Registry
reg_get_value_32()
{
    reg_get_value "32" "$1"
}

# Get a value from the 64-bit side of the Registry
reg_get_value_64()
{
    reg_get_value "64" "$1"
}

if test "$_os" = "WINNT"; then
    AC_MSG_CHECKING([whether to build a 64-bit LibreOffice])
    if test "$enable_64_bit" = "" -o "$enable_64_bit" = "no"; then
        AC_MSG_RESULT([no])
        WINDOWS_SDK_ARCH="x86"
    else
        AC_MSG_RESULT([yes])
        WINDOWS_SDK_ARCH="x64"
        BITNESS_OVERRIDE=64
    fi
fi
AC_SUBST(WINDOWS_SDK_ARCH)
if test "$_os" = "iOS"; then
    cross_compiling="yes"
fi

if test "$cross_compiling" = "yes"; then
    export CROSS_COMPILING=TRUE
else
    CROSS_COMPILING=
    BUILD_TYPE="$BUILD_TYPE NATIVE"
fi
AC_SUBST(CROSS_COMPILING)

HAVE_LD_BSYMBOLIC_FUNCTIONS=
if test "$GCC" = "yes"; then
    AC_MSG_CHECKING([for -Bsymbolic-functions linker support])
    bsymbolic_functions_ldflags_save=$LDFLAGS
    LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions -Wl,--dynamic-list-cpp-new -Wl,--dynamic-list-cpp-typeinfo"
    AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <stdio.h>
        ],[
printf ("hello world\n");
        ])], HAVE_LD_BSYMBOLIC_FUNCTIONS=TRUE, [])
    if test "$HAVE_LD_BSYMBOLIC_FUNCTIONS" = "TRUE"; then
        AC_MSG_RESULT( found )
    else
        AC_MSG_RESULT( not found )
    fi
    LDFLAGS=$bsymbolic_functions_ldflags_save
fi
AC_SUBST(HAVE_LD_BSYMBOLIC_FUNCTIONS)

# Use -isystem (gcc) if possible, to avoid warnigs in 3rd party headers.
# NOTE: must _not_ be used for bundled external libraries!
ISYSTEM=
if test "$GCC" = "yes"; then
    AC_MSG_CHECKING( for -isystem )
    save_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -Werror"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ ISYSTEM="-isystem " ],[])
    CFLAGS=$save_CFLAGS
    if test -n "$ISYSTEM"; then
        AC_MSG_RESULT(yes)
    else
        AC_MSG_RESULT(no)
    fi
fi
if test -z "$ISYSTEM"; then
    # fall back to using -I
    ISYSTEM=-I
fi
AC_SUBST(ISYSTEM)

dnl ===================================================================
dnl  Check which Visual Studio compiler is used
dnl ===================================================================

map_vs_year_to_version()
{
    # Return value: $vsversion

    unset vsversion

    case $1 in
    2015)
        vsversion=14.0;;
    2017)
        vsversion=15.0;;
    *)
        AC_MSG_ERROR([Assertion failure - invalid argument "$1" to map_vs_year_to_version()]);;
    esac
}

vs_versions_to_check()
{
    # Args: $1 (optional) : versions to check, in the order of preference
    # Return value: $vsversions

    unset vsversions

    if test -n "$1"; then
        map_vs_year_to_version "$1"
        vsversions=$vsversion
    else
        # By default we prefer 2015/2017, in this order
        vsversions="14.0 15.0"
    fi
}

win_get_env_from_vsvars32bat()
{
    WRAPPERBATCHFILEPATH="`mktemp -t wrpXXXXXX.bat`"
    if test $vcnum = "150"; then
      # Also seems to be located in another directory under the same name: vsvars32.bat
      # https://github.com/bazelbuild/bazel/blob/master/src/main/native/build_windows_jni.sh#L56-L57
      printf '@call "%s/../Common7/Tools/VsDevCmd.bat" /no_logo\r\n' "$(cygpath -w $VC_PRODUCT_DIR)" > $WRAPPERBATCHFILEPATH
    else
      printf '@call "%s/../Common7/Tools/vsvars32.bat"\r\n' "$(cygpath -w $VC_PRODUCT_DIR)" > $WRAPPERBATCHFILEPATH
    fi
    printf '@setlocal\r\n@echo %%%s%%\r\n@endlocal\r\n' "$1" >> $WRAPPERBATCHFILEPATH
    chmod +x $WRAPPERBATCHFILEPATH
    _win_get_env_from_vsvars32bat=$("$WRAPPERBATCHFILEPATH" | tr -d '\r')
    rm -f $WRAPPERBATCHFILEPATH
    printf '%s' "$_win_get_env_from_vsvars32bat"
}

find_ucrt()
{
    reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v10.0/InstallationFolder"
    if test -n "$regvalue"; then
        PathFormat "$regvalue"
        UCRTSDKDIR=$formatted_path
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v10.0/ProductVersion"
        UCRTVERSION=$regvalue
        # Rest if not exist
        if ! test -d "${UCRTSDKDIR}Include/$UCRTVERSION/ucrt"; then
          UCRTSDKDIR=
        fi
    fi
    if test -z "$UCRTSDKDIR"; then
        ide_env_dir="$VC_PRODUCT_DIR/../Common7/Tools/"
        if test "$vcnum" = "150"; then
          ide_env_file="${ide_env_dir}VsDevCmd.bat"
        else
          ide_env_file="${ide_env_dir}/vsvars32.bat"
        fi
        if test -f "$ide_env_file"; then
            PathFormat "$(win_get_env_from_vsvars32bat UniversalCRTSdkDir)"
            UCRTSDKDIR=$formatted_path
            UCRTVERSION=$(win_get_env_from_vsvars32bat UCRTVersion)
            dnl Hack needed at least by tml:
            if test "$UCRTVERSION" = 10.0.15063.0 \
                -a ! -f "${UCRTSDKDIR}Include/10.0.15063.0/um/sqlext.h" \
                -a -f "${UCRTSDKDIR}Include/10.0.14393.0/um/sqlext.h"
            then
                UCRTVERSION=10.0.14393.0
            fi
        else
          AC_MSG_ERROR([No UCRT found])
        fi
    fi
}

find_msvc()
{
    # Find Visual C++ 2015/2017
    # Args: $1 (optional) : The VS version year
    # Return values: $vctest, $vcyear, $vcnum, $vcnumwithdot, $vcbuildnumber

    unset vctest vcnum vcnumwithdot vcbuildnumber

    vs_versions_to_check "$1"

    for ver in $vsversions; do
        reg_get_value_32 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/$ver/Setup/VC/ProductDir
        if test -n "$regvalue"; then
            vctest=$regvalue
            break
        fi
        # As always MSVC 15.0 is special here
        reg_get_value_32 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/SxS/VS7/$ver
        if test -n "$regvalue"; then
            AC_MSG_RESULT([found: $regvalue])
            PathFormat "$regvalue"
            vctest=$formatted_path
            break
        fi
    done
    if test -n "$vctest"; then
        vcnumwithdot=$ver
        case "$vcnumwithdot" in
        14.0)
            vcyear=2015
            vcnum=140
            ;;
        15.0)
            vcyear=2017
            vcnum=150
            vcbuildnumber=`ls $vctest/VC/Tools/MSVC -A1r | head -1`
            ;;
        esac
    fi
}

SOLARINC=
MSBUILD_PATH=
DEVENV=
if test "$_os" = "WINNT"; then
    AC_MSG_CHECKING([Visual C++])

    find_msvc "$with_visual_studio"
    if test -z "$vctest"; then
        if test -n "$with_visual_studio"; then
            AC_MSG_ERROR([No Visual Studio $with_visual_studio installation found])
        else
            AC_MSG_ERROR([No Visual Studio 2015/2017 installation found])
        fi
    fi

    if test "$BITNESS_OVERRIDE" = ""; then
        if test -f "$vctest/bin/cl.exe"; then
            VC_PRODUCT_DIR=$vctest
        elif test -f "$vctest/VC/Tools/MSVC/$vcbuildnumber/bin/HostX86/x86/cl.exe"; then
            VC_PRODUCT_DIR=$vctest/VC
        else
            AC_MSG_ERROR([No compiler (cl.exe) in $vctest/bin/cl.exe])
        fi
    else
        if test -f "$vctest/bin/amd64/cl.exe"; then
            VC_PRODUCT_DIR=$vctest
        elif test -f "$vctest/VC/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64/cl.exe"; then
            VC_PRODUCT_DIR=$vctest/VC
        else
            AC_MSG_ERROR([No compiler (cl.exe) in $vctest/VC/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64/cl.exe or $vctest/bin/amd64/cl.exe or $vctest/bin/x86_amd64/cl.exe])
        fi
    fi

    AC_MSG_CHECKING([for short pathname of VC product directory])
    VC_PRODUCT_DIR=`win_short_path_for_make "$VC_PRODUCT_DIR"`
    AC_MSG_RESULT([$VC_PRODUCT_DIR])

    UCRTSDKDIR=
    UCRTVERSION=

    AC_MSG_CHECKING([for UCRT location])
    find_ucrt
    # find_ucrt errors out if it doesn't find it
    AC_MSG_RESULT([found])
    PathFormat "${UCRTSDKDIR}Include/$UCRTVERSION/ucrt"
    ucrtincpath_formatted=$formatted_path
    # SOLARINC is used for external modules and must be set too.
    # And no, it's not sufficient to set SOLARINC only, as configure
    # itself doesn't honour it.
    SOLARINC="$SOLARINC -I$ucrtincpath_formatted"
    CFLAGS="$CFLAGS -I$ucrtincpath_formatted"
    CXXFLAGS="$CXXFLAGS -I$ucrtincpath_formatted"
    CPPFLAGS="$CPPFLAGS -I$ucrtincpath_formatted"

    AC_SUBST(UCRTSDKDIR)
    AC_SUBST(UCRTVERSION)

    AC_MSG_CHECKING([for MSBuild.exe location for: $vcnumwithdot])
    # Find the proper version of MSBuild.exe to use based on the VS version
    reg_get_value_32 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MSBuild/$vcnumwithdot/MSBuildOverrideTasksPath
    if test -n "$regvalue" ; then
        AC_MSG_RESULT([found: $regvalue])
        MSBUILD_PATH=`win_short_path_for_make "$regvalue"`
    else
        if test $vcnum = "150"; then
            if test "$BITNESS_OVERRIDE" = ""; then
                regvalue="$VC_PRODUCT_DIR/../MSBuild/$vcnumwithdot/Bin"
            else
                regvalue="$VC_PRODUCT_DIR/../MSBuild/$vcnumwithdot/Bin/amd64"
            fi
            MSBUILD_PATH=`win_short_path_for_make "$regvalue"`
        else
            AC_MSG_ERROR([No msbuild found, Visual Studio installation broken?])
        fi
	AC_MSG_RESULT([$regvalue])
    fi

    # Find the version of devenv.exe
    # MSVC 2017 devenv does not start properly from a DOS 8.3 path
    DEVENV=$(cygpath -lm "$VC_PRODUCT_DIR/../Common7/IDE/devenv.exe")
    if test ! -e "$DEVENV"; then
        AC_MSG_ERROR([No devenv.exe found, Visual Studio installation broken?])
    fi

    dnl ===========================================================
    dnl  Check for the corresponding mspdb*.dll
    dnl ===========================================================

    MSPDB_PATH=
    CL_DIR=
    CL_LIB=

    if test "$BITNESS_OVERRIDE" = ""; then
        if test "$vcnum" = "150"; then
            MSPDB_PATH="$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/bin/HostX86/x86"
            CL_DIR=Tools/MSVC/$vcbuildnumber/bin/HostX86/x86
        else
            MSPDB_PATH="$VC_PRODUCT_DIR/../Common7/IDE"
            CL_DIR=bin
        fi
    else
        if test "$vcnum" = "150"; then
            MSPDB_PATH="$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64"
            CL_DIR=Tools/MSVC/$vcbuildnumber/bin/HostX64/x64
        else
            MSPDB_PATH="$VC_PRODUCT_DIR/bin/amd64"
            CL_DIR=bin/amd64
        fi
    fi

    # MSVC 15.0 has libraries from 14.0?
    if test  "$vcnum" = "150"; then
        mspdbnum="140"
    else
        mspdbnum=$vcnum
    fi

    if test ! -e "$MSPDB_PATH/mspdb${mspdbnum}.dll"; then
        AC_MSG_ERROR([No mspdb${mspdbnum}.dll in $MSPDB_PATH, Visual Studio installation broken?])
    fi

    MSPDB_PATH=`cygpath -d "$MSPDB_PATH"`
    MSPDB_PATH=`cygpath -u "$MSPDB_PATH"`

    dnl The path needs to be added before cl is called
    PATH="$MSPDB_PATH:$PATH"

    AC_MSG_CHECKING([cl.exe])

    # Is there really ever a need to pass CC explicitly? Surely we can hope to get all the
    # automagical niceness to work OK? If somebody has some unsupported compiler in some weird
    # location, isn't it likely that lots of other things needs changes, too, and just setting CC
    # is not enough?

    dnl Save the true MSVC cl.exe for use when CC/CXX is actually clang-cl,
    dnl needed when building CLR code:
    if test -z "$MSVC_CXX"; then
        if test "$BITNESS_OVERRIDE" = ""; then
            if test -f "$VC_PRODUCT_DIR/$CL_DIR/cl.exe"; then
                MSVC_CXX="$VC_PRODUCT_DIR/$CL_DIR/cl.exe"
            fi
        else
            if test -f "$VC_PRODUCT_DIR/$CL_DIR/cl.exe"; then
                MSVC_CXX="$VC_PRODUCT_DIR/$CL_DIR/cl.exe"
            fi
        fi

        # This gives us a posix path with 8.3 filename restrictions
        MSVC_CXX=`win_short_path_for_make "$MSVC_CXX"`
    fi

    if test -z "$CC"; then
        CC=$MSVC_CXX
    fi
    if test "$BITNESS_OVERRIDE" = ""; then
        dnl since MSVC 2012, default for x86 is -arch:SSE2:
        MSVC_CXX="$MSVC_CXX -arch:SSE"
    fi

    if test -n "$CC"; then
        # Remove /cl.exe from CC case insensitive
        AC_MSG_RESULT([found Visual C++ $vcyear ($CC)])
        if test "$BITNESS_OVERRIDE" = ""; then
           if test "$vcnum" = "150"; then
               COMPATH="$VC_PRODUCT_DIR"
           else
               COMPATH=`echo "$CC" | $SED -e 's@\/[[Bb]][[Ii]][[Nn]]\/[[cC]][[lL]]\.[[eE]][[xX]][[eE]].*@@' -e 's@^.* @@'`
           fi
        else
            if test -n "$VC_PRODUCT_DIR"; then
                COMPATH=$VC_PRODUCT_DIR
            fi
        fi
        if test "$BITNESS_OVERRIDE" = ""; then
            dnl since MSVC 2012, default for x86 is -arch:SSE2:
            CC="$CC -arch:SSE"
        fi

        if test "$vcnum" = "150"; then
            COMPATH="$COMPATH/Tools/MSVC/$vcbuildnumber"
        fi

        export INCLUDE=`cygpath -d "$COMPATH\Include"`

        PathFormat "$COMPATH"
        COMPATH="$formatted_path"

        VCVER=$vcnum
        MSVSVER=$vcyear

        # The WINDOWS_SDK_ACCEPTABLE_VERSIONS is mostly an educated guess...  Assuming newer ones
        # are always "better", we list them in reverse chronological order.

        case $vcnum in
        140)
            COMEX=19
            WINDOWS_SDK_ACCEPTABLE_VERSIONS="10.0 8.1A 8.1 8.0 7.1A"
            ;;
        150)
            COMEX=19
            WINDOWS_SDK_ACCEPTABLE_VERSIONS="10.0 8.1A 8.1 8.0 7.1A"
            ;;
        esac

        # The expectation is that --with-windows-sdk should not need to be used
        if test -n "$with_windows_sdk"; then
            case " $WINDOWS_SDK_ACCEPTABLE_VERSIONS " in
            *" "$with_windows_sdk" "*)
                WINDOWS_SDK_ACCEPTABLE_VERSIONS=$with_windows_sdk
                ;;
            *)
                AC_MSG_ERROR([Windows SDK $with_windows_sdk is not known to work with VS $MSVSVER])
                ;;
            esac
        fi

        # Make AC_COMPILE_IFELSE etc. work (set by AC_PROG_C, which we don't use for MSVC)
        ac_objext=obj
        ac_exeext=exe

    else
        AC_MSG_ERROR([Visual C++ not found after all, huh])
    fi

    # Check for 64-bit (cross-)compiler to use to build the 64-bit
    # version of the Explorer extension (and maybe other small
    # bits, too) needed when installing a 32-bit LibreOffice on a
    # 64-bit OS. The 64-bit Explorer extension is a feature that
    # has been present since long in OOo. Don't confuse it with
    # building LibreOffice itself as 64-bit code.

    BUILD_X64=
    CXX_X64_BINARY=
    LINK_X64_BINARY=

    if test "$BITNESS_OVERRIDE" = ""; then
        AC_MSG_CHECKING([for a x64 compiler and libraries for 64-bit Explorer extensions])
        if test -f "$VC_PRODUCT_DIR/atlmfc/lib/amd64/atls.lib"; then
            # Prefer native x64 compiler to cross-compiler, in case we are running
            # the build on a 64-bit OS.
            if "$VC_PRODUCT_DIR/bin/amd64/cl.exe" -? </dev/null >/dev/null 2>&1; then
                BUILD_X64=TRUE
                CXX_X64_BINARY="$VC_PRODUCT_DIR/bin/amd64/cl.exe"
                LINK_X64_BINARY="$VC_PRODUCT_DIR/bin/amd64/link.exe"
            elif "$VC_PRODUCT_DIR/bin/x86_amd64/cl.exe" -? </dev/null >/dev/null 2>&1; then
                BUILD_X64=TRUE
                CXX_X64_BINARY="$VC_PRODUCT_DIR/bin/x86_amd64/cl.exe"
                LINK_X64_BINARY="$VC_PRODUCT_DIR/bin/x86_amd64/link.exe"
            fi
        elif test -f "$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/atlmfc/lib/x64/atls.lib"; then
            # nobody uses 32-bit OS to build, just pick the 64-bit compiler
            if "$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64/cl.exe" -? </dev/null >/dev/null 2>&1; then
                BUILD_X64=TRUE
                CXX_X64_BINARY="$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64/cl.exe"
                LINK_X64_BINARY="$VC_PRODUCT_DIR/Tools/MSVC/$vcbuildnumber/bin/HostX64/x64/link.exe"
            fi
        fi
        if test "$BUILD_X64" = TRUE; then
            AC_MSG_RESULT([found])
        else
            AC_MSG_RESULT([not found])
            AC_MSG_WARN([Installation set will not contain 64-bit Explorer extensions])
        fi
    fi
    AC_SUBST(BUILD_X64)

    # These are passed to the environment and then used in gbuild/platform/com_MSC_class.mk
    AC_SUBST(CXX_X64_BINARY)
    AC_SUBST(LINK_X64_BINARY)
fi
AC_SUBST(VCVER)
AC_SUBST(DEVENV)
PathFormat "$MSPDB_PATH"
MSPDB_PATH="$formatted_path"
AC_SUBST(MSVC_CXX)

#
# unowinreg.dll
#
UNOWINREG_DLL="185d60944ea767075d27247c3162b3bc-unowinreg.dll"
AC_SUBST(UNOWINREG_DLL)

COM_IS_CLANG=
AC_MSG_CHECKING([whether the compiler is actually Clang])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
    #ifndef __clang__
    you lose
    #endif
    int foo=42;
    ]])],
    [AC_MSG_RESULT([yes])
     COM_IS_CLANG=TRUE],
    [AC_MSG_RESULT([no])])

CC_PLAIN=$CC
if test "$COM_IS_CLANG" = TRUE; then
    AC_MSG_CHECKING([the Clang version])
    if test "$_os" = WINNT; then
        dnl In which case, assume clang-cl:
        my_args="/EP /TC"
        dnl Filter out -FIIntrin.h, which needs to be explicitly stated for
        dnl clang-cl:
        CC_PLAIN=
        for i in $CC; do
            case $i in
            -FIIntrin.h)
                ;;
            *)
                CC_PLAIN="$CC_PLAIN $i"
                ;;
            esac
        done
    else
        my_args="-E -P"
    fi
    clang_version=`echo __clang_major__.__clang_minor__.__clang_patchlevel__ | $CC_PLAIN $my_args -`
    CLANG_FULL_VERSION=`echo __clang_version__ | $CC_PLAIN $my_args -`
    CLANGVER=`echo $clang_version \
        | $AWK -F. '{ print \$1*10000+(\$2<100?\$2:99)*100+(\$3<100?\$3:99) }'`
    AC_MSG_RESULT([Clang $CLANG_FULL_VERSION, $CLANGVER])
    AC_DEFINE_UNQUOTED(CLANG_VERSION,$CLANGVER)
    AC_DEFINE_UNQUOTED(CLANG_FULL_VERSION,$CLANG_FULL_VERSION)
fi
AC_SUBST(COM_IS_CLANG)

SHOWINCLUDES_PREFIX=
if test "$_os" = WINNT; then
    dnl We need to guess the prefix of the -showIncludes output, it can be
    dnl localized
    AC_MSG_CHECKING([the dependency generation prefix (cl.exe -showIncludes)])
    echo "#include <stdlib.h>" > conftest.c
    SHOWINCLUDES_PREFIX=`$CC_PLAIN $CFLAGS -c -showIncludes conftest.c 2>/dev/null | \
        grep 'stdlib\.h' | head -n1 | sed 's/ [[[:alpha:]]]:.*//'`
    rm -f conftest.c conftest.obj
    if test -z "$SHOWINCLUDES_PREFIX"; then
        AC_MSG_ERROR([cannot determine the -showIncludes prefix])
    else
        AC_MSG_RESULT(["$SHOWINCLUDES_PREFIX"])
    fi
fi
AC_SUBST(SHOWINCLUDES_PREFIX)

#
# prefix C with ccache if needed
#
if test "$CCACHE" != ""; then
    AC_MSG_CHECKING([whether $CC is already ccached])

    AC_LANG_PUSH([C])
    save_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS --ccache-skip -O2"
    dnl an empty program will do, we're checking the compiler flags
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                      [use_ccache=yes], [use_ccache=no])
    if test $use_ccache = yes; then
        AC_MSG_RESULT([yes])
    else
        CC="$CCACHE $CC"
        AC_MSG_RESULT([no])
    fi
    CFLAGS=$save_CFLAGS
    AC_LANG_POP([C])
fi

# ===================================================================
# check various GCC options that Clang does not support now but maybe
# will somewhen in the future, check them even for GCC, so that the
# flags are set
# ===================================================================

HAVE_GCC_GGDB2=
HAVE_GCC_FINLINE_LIMIT=
HAVE_GCC_FNO_INLINE=
if test "$GCC" = "yes"; then
    AC_MSG_CHECKING([whether $CC supports -ggdb2])
    if test -n "$CLANGVER" -a 0"$CLANGVER" -le 30100; then
        # Option just ignored and silly warning that isn't a real
        # warning printed
        :
    else
        save_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -Werror -ggdb2"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_GGDB2=TRUE ],[])
        CFLAGS=$save_CFLAGS
    fi
    if test "$HAVE_GCC_GGDB2" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports -finline-limit=0])
    if test -n "$CLANGVER" -a 0"$CLANGVER" -le 30100; then
        # As above
        :
    else
        save_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -Werror -finline-limit=0"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_FINLINE_LIMIT=TRUE ],[])
        CFLAGS=$save_CFLAGS
    fi
    if test "$HAVE_GCC_FINLINE_LIMIT" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports -fno-inline])
    if test -n "$CLANGVER" -a 0"$CLANGVER" -le 30100; then
        # Ditto
        :
    else
        save_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -Werror -fno-inline"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_FNO_INLINE=TRUE ],[])
        CFLAGS=$save_CFLAGS
    fi
    if test "$HAVE_GCC_FNO_INLINE" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    if test "$host_cpu" = "m68k"; then
        AC_MSG_CHECKING([whether $CC supports -mlong-jump-table-offsets])
        save_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -Werror -mlong-jump-table-offsets"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_LONG_JUMP_TABLE_OFFSETS=TRUE ],[])
        CFLAGS=$save_CFLAGS
        if test "$HAVE_GCC_LONG_JUMP_TABLE_OFFSETS" = "TRUE"; then
            AC_MSG_RESULT([yes])
        else
            AC_MSG_ERROR([no])
        fi
    fi
fi
AC_SUBST(HAVE_GCC_GGDB2)
AC_SUBST(HAVE_GCC_FINLINE_LIMIT)
AC_SUBST(HAVE_GCC_FNO_INLINE)

dnl ===================================================================
dnl  Test the gcc version
dnl ===================================================================
if test "$GCC" = "yes" -a -z "$COM_IS_CLANG"; then
    AC_MSG_CHECKING([the GCC version])
    _gcc_version=`$CC -dumpversion`
    gcc_full_version=$(printf '%s' "$_gcc_version" | \
        $AWK -F. '{ print $1*10000+$2*100+(NF<3?1:$3) }')
    GCC_VERSION=`echo $_gcc_version | $AWK -F. '{ print \$1*100+\$2 }'`

    AC_MSG_RESULT([gcc $_gcc_version ($gcc_full_version)])

    if test "$gcc_full_version" -lt 40801; then
        AC_MSG_ERROR([GCC $_gcc_version is too old, must be at least GCC 4.8.1])
    fi
else
    # Explicitly force GCC_VERSION to be empty, even for Clang, to check incorrect uses.
    # GCC version should generally be checked only when handling GCC-specific bugs, for testing
    # things like features configure checks should be used, otherwise they may e.g. fail with Clang
    # (which reports itself as GCC 4.2.1).
    GCC_VERSION=
fi
AC_SUBST(GCC_VERSION)

dnl Set the ENABLE_DBGUTIL variable
dnl ===================================================================
AC_MSG_CHECKING([whether to build with additional debug utilities])
if test -n "$enable_dbgutil" -a "$enable_dbgutil" != "no"; then
    ENABLE_DBGUTIL="TRUE"
    # this is an extra var so it can have different default on different MSVC
    # versions (in case there are version specific problems with it)
    MSVC_USE_DEBUG_RUNTIME="TRUE"

    AC_MSG_RESULT([yes])
    # cppunit and graphite expose STL in public headers
    if test "$with_system_cppunit" = "yes"; then
        AC_MSG_ERROR([--with-system-cppunit conflicts with --enable-dbgutil])
    else
        with_system_cppunit=no
    fi
    if test "$with_system_graphite" = "yes"; then
        AC_MSG_ERROR([--with-system-graphite conflicts with --enable-dbgutil])
    else
        with_system_graphite=no
    fi
    if test "$with_system_mysql_cppconn" = "yes"; then
        AC_MSG_ERROR([--with-system-mysql-cppconn conflicts with --enable-dbgutil])
    else
        with_system_mysql_cppconn=no
    fi
    if test "$with_system_orcus" = "yes"; then
        AC_MSG_ERROR([--with-system-orcus conflicts with --enable-dbgutil])
    else
        with_system_orcus=no
    fi
    if test "$with_system_libcmis" = "yes"; then
        AC_MSG_ERROR([--with-system-libcmis conflicts with --enable-dbgutil])
    else
        with_system_libcmis=no
    fi
    if test "$with_system_hunspell" = "yes"; then
        AC_MSG_ERROR([--with-system-hunspell conflicts with --enable-dbgutil])
    else
        with_system_hunspell=no
    fi
else
    ENABLE_DBGUTIL=""
    MSVC_USE_DEBUG_RUNTIME=""
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_DBGUTIL)
AC_SUBST(MSVC_USE_DEBUG_RUNTIME)

dnl Set the ENABLE_DEBUG variable.
dnl ===================================================================
if test -n "$enable_debug" && test "$enable_debug" != "yes" && test "$enable_debug" != "no"; then
    AC_MSG_ERROR([--enable-debug now accepts only yes or no, use --enable-selective-debuginfo])
fi
if test -n "$ENABLE_DBGUTIL" -a "$enable_debug" = "no"; then
    if test -z "$libo_fuzzed_enable_debug"; then
        AC_MSG_ERROR([--disable-debug cannot be used with --enable-dbgutil])
    else
        AC_MSG_NOTICE([Resetting --enable-debug=yes])
        enable_debug=yes
    fi
fi

AC_MSG_CHECKING([whether to do a debug build])
if test -n "$ENABLE_DBGUTIL" -o \( -n "$enable_debug" -a "$enable_debug" != "no" \) ; then
    ENABLE_DEBUG="TRUE"
    if test -n "$ENABLE_DBGUTIL" ; then
        AC_MSG_RESULT([yes (dbgutil)])
    else
        AC_MSG_RESULT([yes])
    fi
else
    ENABLE_DEBUG=""
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_DEBUG)

if test "$enable_sal_log" = yes; then
    ENABLE_SAL_LOG=TRUE
fi
AC_SUBST(ENABLE_SAL_LOG)

dnl Selective debuginfo
ENABLE_DEBUGINFO_FOR=
if test -n "$ENABLE_DEBUG"; then
    AC_MSG_CHECKING([whether to use selective debuginfo])
    if test -n "$enable_selective_debuginfo" -a "$enable_selective_debuginfo" != "no"; then
        if test "$enable_selective_debuginfo" = "yes"; then
            AC_MSG_ERROR([--enable-selective-debuginfo requires a parameter])
        fi
        ENABLE_DEBUGINFO_FOR="$enable_selective_debuginfo"
        AC_MSG_RESULT([for "$enable_selective_debuginfo"])
    else
        ENABLE_DEBUGINFO_FOR=all
        AC_MSG_RESULT([no, for all])
    fi
else
    if test -n "$enable_selective_debuginfo"; then
        AC_MSG_ERROR([--enable-selective-debuginfo must be used together with either --enable-debug or --enable-dbgutil])
    fi
fi
AC_SUBST(ENABLE_DEBUGINFO_FOR)

dnl Check for enable symbols option
dnl ===================================================================
AC_MSG_CHECKING([whether to generate debug information])
if test -z "$enable_symbols"; then
    if test -n "$ENABLE_DEBUG$ENABLE_DBGUTIL"; then
        enable_symbols=yes
    else
        enable_symbols=no
    fi
fi
if test "$enable_symbols" != no; then
    ENABLE_SYMBOLS=TRUE
    AC_MSG_RESULT([yes])
else
    ENABLE_SYMBOLS=
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_SYMBOLS)

if test -n "$with_android_ndk" -a \( -n "$ENABLE_SYMBOLS" -o -n "$ENABLE_DEBUG" -o -n "$ENABLE_DBGUTIL" \) -a "$ENABLE_DEBUGINFO_FOR" = "all"; then
    # Building on Android with full symbols: without enough memory the linker never finishes currently.
    AC_MSG_CHECKING([whether enough memory is available for linking])
    mem_size=$(grep -o 'MemTotal: *.\+ kB' /proc/meminfo | sed 's/MemTotal: *\(.\+\) kB/\1/')
    # Check for 15GB, as Linux reports a bit less than the physical memory size.
    if test -n "$mem_size" -a $mem_size -lt 15728640; then
        AC_MSG_ERROR([building with full symbols and less than 16GB of memory is not supported])
    else
        AC_MSG_RESULT([yes])
    fi
fi

AC_MSG_CHECKING([whether to compile with optimization flags])
if test -z "$enable_optimized"; then
    if test -n "$ENABLE_DEBUG$ENABLE_DBGUTIL"; then
        enable_optimized=no
    else
        enable_optimized=yes
    fi
fi
if test "$enable_optimized" != no; then
    ENABLE_OPTIMIZED=TRUE
    AC_MSG_RESULT([yes])
else
    ENABLE_OPTIMIZED=
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_OPTIMIZED)

#
# determine CPUNAME, OS, ...
# The USING_X11 flag tells whether the host os uses X by default. Can be overridden with the --without-x option.
#
case "$host_os" in

aix*)
    COM=GCC
    CPUNAME=POWERPC
    USING_X11=TRUE
    OS=AIX
    RTL_OS=AIX
    RTL_ARCH=PowerPC
    PLATFORMID=aix_powerpc
    P_SEP=:
    ;;

cygwin*)
    COM=MSC
    USING_X11=
    OS=WNT
    RTL_OS=Windows
    if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
        P_SEP=";"
    else
        P_SEP=:
    fi
    case "$host_cpu" in
    i*86|x86_64)
        if test "$BITNESS_OVERRIDE" = 64; then
            CPUNAME=X86_64
            RTL_ARCH=X86_64
            PLATFORMID=windows_x86_64
            WINDOWS_X64=1
            SCPDEFS="$SCPDEFS -DWINDOWS_X64"
        else
            CPUNAME=INTEL
            RTL_ARCH=x86
            PLATFORMID=windows_x86
        fi
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    SCPDEFS="$SCPDEFS -D_MSC_VER"
    ;;

darwin*)
    COM=GCC
    USING_X11=
    OS=MACOSX
    RTL_OS=MacOSX
    P_SEP=:

    case "$host_cpu" in
    arm)
        AC_MSG_ERROR([Can't build 32-bit code for iOS])
        ;;
    arm64)
        OS=IOS
        if test "$enable_ios_simulator" = "yes"; then
            AC_MSG_ERROR([iOS simulator is only available in OSX not iOS])
        else
            CPUNAME=ARM64
            RTL_ARCH=ARM_EABI
            PLATFORMID=ios_arm64
        fi
        ;;
    i*86)
        AC_MSG_ERROR([Can't build 64-bit code in 32-bit OS])
        ;;
    x86_64)
        if test "$enable_ios_simulator" = "yes"; then
            OS=IOS
        fi
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=macosx_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

dragonfly*)
    COM=GCC
    USING_X11=TRUE
    OS=DRAGONFLY
    RTL_OS=DragonFly
    P_SEP=:

    case "$host_cpu" in
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=dragonfly_x86
        ;;
    x86_64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=dragonfly_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

freebsd*)
    COM=GCC
    USING_X11=TRUE
    RTL_OS=FreeBSD
    OS=FREEBSD
    P_SEP=:

    case "$host_cpu" in
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=freebsd_x86
        ;;
    x86_64|amd64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=freebsd_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

kfreebsd*)
    COM=GCC
    USING_X11=TRUE
    OS=LINUX
    RTL_OS=kFreeBSD
    P_SEP=:

    case "$host_cpu" in

    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=kfreebsd_x86
        ;;
    x86_64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=kfreebsd_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

linux-gnu*)
    COM=GCC
    USING_X11=TRUE
    OS=LINUX
    RTL_OS=Linux
    P_SEP=:

    case "$host_cpu" in

    aarch64)
        CPUNAME=AARCH64
        PLATFORMID=linux_aarch64
        RTL_ARCH=AARCH64
        ;;
    alpha)
        CPUNAME=AXP
        RTL_ARCH=ALPHA
        PLATFORMID=linux_alpha
        ;;
    arm*)
        CPUNAME=ARM
        EPM_FLAGS="-a arm"
        RTL_ARCH=ARM_EABI
        PLATFORMID=linux_arm_eabi
        case "$host_cpu" in
        arm*-linux)
            RTL_ARCH=ARM_OABI
            PLATFORMID=linux_arm_oabi
            ;;
        esac
        ;;
    hppa)
        CPUNAME=HPPA
        RTL_ARCH=HPPA
        EPM_FLAGS="-a hppa"
        PLATFORMID=linux_hppa
        ;;
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=linux_x86
        ;;
    ia64)
        CPUNAME=IA64
        RTL_ARCH=IA64
        PLATFORMID=linux_ia64
        ;;
    mips)
        CPUNAME=GODSON
        RTL_ARCH=MIPS_EB
        EPM_FLAGS="-a mips"
        PLATFORMID=linux_mips_eb
        ;;
    mips64)
        CPUNAME=GODSON64
        RTL_ARCH=MIPS64_EB
        EPM_FLAGS="-a mips64"
        PLATFORMID=linux_mips64_eb
        ;;
    mips64el)
        CPUNAME=GODSON64
        RTL_ARCH=MIPS64_EL
        EPM_FLAGS="-a mips64el"
        PLATFORMID=linux_mips64_el
        ;;
    mipsel)
        CPUNAME=GODSON
        RTL_ARCH=MIPS_EL
        EPM_FLAGS="-a mipsel"
        PLATFORMID=linux_mips_el
        ;;
    m68k)
        CPUNAME=M68K
        RTL_ARCH=M68K
        PLATFORMID=linux_m68k
        ;;
    powerpc)
        CPUNAME=POWERPC
        RTL_ARCH=PowerPC
        PLATFORMID=linux_powerpc
        ;;
    powerpc64)
        CPUNAME=POWERPC64
        RTL_ARCH=PowerPC_64
        PLATFORMID=linux_powerpc64
        ;;
    powerpc64le)
        CPUNAME=POWERPC64
        RTL_ARCH=PowerPC_64_LE
        PLATFORMID=linux_powerpc64_le
        ;;
    sparc)
        CPUNAME=SPARC
        RTL_ARCH=SPARC
        PLATFORMID=linux_sparc
        ;;
    sparc64)
        CPUNAME=SPARC64
        RTL_ARCH=SPARC64
        PLATFORMID=linux_sparc64
        ;;
    s390)
        CPUNAME=S390
        RTL_ARCH=S390
        PLATFORMID=linux_s390
        ;;
    s390x)
        CPUNAME=S390X
        RTL_ARCH=S390x
        PLATFORMID=linux_s390x
        ;;
    x86_64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=linux_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

linux-android*)
    COM=GCC
    USING_X11=
    OS=ANDROID
    RTL_OS=Android
    P_SEP=:

    case "$host_cpu" in

    arm|armel)
        CPUNAME=ARM
        RTL_ARCH=ARM_EABI
        PLATFORMID=android_arm_eabi
        ;;
    aarch64)
        CPUNAME=AARCH64
        RTL_ARCH=AARCH64
        PLATFORMID=android_aarch64
        ;;
    mips|mipsel)
        CPUNAME=GODSON # Weird, but maybe that's the LO convention?
        RTL_ARCH=MIPS_EL
        PLATFORMID=android_mips_el
        ;;
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=android_x86
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

*netbsd*)
    COM=GCC
    USING_X11=TRUE
    OS=NETBSD
    RTL_OS=NetBSD
    P_SEP=:

    case "$host_cpu" in
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=netbsd_x86
        ;;
    powerpc)
        CPUNAME=POWERPC
        RTL_ARCH=PowerPC
        PLATFORMID=netbsd_powerpc
        ;;
    sparc)
        CPUNAME=SPARC
        RTL_ARCH=SPARC
        PLATFORMID=netbsd_sparc
        ;;
    x86_64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=netbsd_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    ;;

openbsd*)
    COM=GCC
    USING_X11=TRUE
    OS=OPENBSD
    RTL_OS=OpenBSD
    P_SEP=:

    case "$host_cpu" in
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=openbsd_x86
        ;;
    x86_64)
        CPUNAME=X86_64
        RTL_ARCH=X86_64
        PLATFORMID=openbsd_x86_64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    SOLARINC="$SOLARINC -I/usr/local/include"
    ;;

solaris*)
    COM=GCC
    USING_X11=TRUE
    OS=SOLARIS
    RTL_OS=Solaris
    P_SEP=:

    case "$host_cpu" in
    i*86)
        CPUNAME=INTEL
        RTL_ARCH=x86
        PLATFORMID=solaris_x86
        ;;
    sparc)
        CPUNAME=SPARC
        RTL_ARCH=SPARC
        PLATFORMID=solaris_sparc
        ;;
    sparc64)
        CPUNAME=SPARC64
        RTL_ARCH=SPARC64
        PLATFORMID=solaris_sparc64
        ;;
    *)
        AC_MSG_ERROR([Unsupported host_cpu $host_cpu for host_os $host_os])
        ;;
    esac
    SOLARINC="$SOLARINC -I/usr/local/include"
    ;;

*)
    AC_MSG_ERROR([$host_os operating system is not suitable to build LibreOffice for!])
    ;;
esac

if test "$with_x" = "no"; then
    AC_MSG_ERROR([Use --disable-gui instead. How can we get rid of this option? No idea where it comes from.])
fi

ENABLE_HEADLESS=""
if test "$enable_gui" = "no"; then
    if test "$USING_X11" != TRUE; then
        AC_MSG_ERROR([$host_os operating system is not suitable to build LibreOffice with --disable-gui.])
    fi
    USING_X11=
    ENABLE_HEADLESS=TRUE
    AC_DEFINE(HAVE_FEATURE_UI,0)
    test_cairo=yes
fi
AC_SUBST(ENABLE_HEADLESS)

WORKDIR="${BUILDDIR}/workdir"
INSTDIR="${BUILDDIR}/instdir"
INSTROOTBASE=${INSTDIR}${INSTROOTBASESUFFIX}
INSTROOT=${INSTROOTBASE}${INSTROOTCONTENTSUFFIX}
SOLARINC="-I$SRC_ROOT/include $SOLARINC"
AC_SUBST(COM)
AC_SUBST(CPUNAME)
AC_SUBST(RTL_OS)
AC_SUBST(RTL_ARCH)
AC_SUBST(EPM_FLAGS)
AC_SUBST(USING_X11)
AC_SUBST([INSTDIR])
AC_SUBST([INSTROOT])
AC_SUBST([INSTROOTBASE])
AC_SUBST(OS)
AC_SUBST(P_SEP)
AC_SUBST(WORKDIR)
AC_SUBST(PLATFORMID)
AC_SUBST(WINDOWS_X64)
AC_DEFINE_UNQUOTED(WORKDIR,"$WORKDIR")

dnl ===================================================================
dnl Test which package format to use
dnl ===================================================================
AC_MSG_CHECKING([which package format to use])
if test -n "$with_package_format" -a "$with_package_format" != no; then
    for i in $with_package_format; do
        case "$i" in
        aix | bsd | deb | pkg | rpm | archive | dmg | installed | msi)
            ;;
        *)
            AC_MSG_ERROR([unsupported format $i. Supported by EPM are:
aix - AIX software distribution
bsd - FreeBSD, NetBSD, or OpenBSD software distribution
deb - Debian software distribution
pkg - Solaris software distribution
rpm - RedHat software distribution

LibreOffice additionally supports:
archive - .tar.gz or .zip
dmg - Mac OS X .dmg
installed - installation tree
msi - Windows .msi
        ])
            ;;
        esac
    done
    PKGFORMAT="$with_package_format"
    AC_MSG_RESULT([$PKGFORMAT])
else
    PKGFORMAT=
    AC_MSG_RESULT([none])
fi
AC_SUBST(PKGFORMAT)

dnl ===================================================================
dnl Set up a different compiler to produce tools to run on the build
dnl machine when doing cross-compilation
dnl ===================================================================

m4_pattern_allow([PKG_CONFIG_FOR_BUILD])
m4_pattern_allow([PKG_CONFIG_LIBDIR])
if test "$cross_compiling" = "yes"; then
    AC_MSG_CHECKING([for BUILD platform configuration])
    echo
    rm -rf CONF-FOR-BUILD config_build.mk
    mkdir CONF-FOR-BUILD
    # Here must be listed all files needed when running the configure script. In particular, also
    # those expanded by the AC_CONFIG_FILES() call near the end of this configure.ac. For clarity,
    # keep them in the same order as there.
    (cd $SRC_ROOT && tar cf - \
        config.guess \
        bin/get_config_variables \
        solenv/bin/getcompver.awk \
        solenv/inc/langlist.mk \
        download.lst \
        config_host.mk.in \
        config_host_lang.mk.in \
        Makefile.in \
        lo.xcent.in \
        bin/bffvalidator.sh.in \
        bin/odfvalidator.sh.in \
        bin/officeotron.sh.in \
        instsetoo_native/util/openoffice.lst.in \
        setup_native/source/packinfo/finals_instsetoo.txt.in \
        config_host/*.in \
        sysui/desktop/macosx/Info.plist.in) \
    | (cd CONF-FOR-BUILD && tar xf -)
    cp configure CONF-FOR-BUILD
    test -d config_build && cp -p config_build/*.h CONF-FOR-BUILD/config_host 2>/dev/null
    (
    unset COM USING_X11 OS CPUNAME
    unset CC CXX SYSBASE CFLAGS
    unset AR NM OBJDUMP PKG_CONFIG RANLIB READELF STRIP
    unset CPPUNIT_CFLAGS CPPUNIT_LIBS
    unset LIBXML_CFLAGS LIBXML_LIBS LIBXSLT_CFLAGS LIBXSLT_LIBS XSLTPROC PKG_CONFIG_LIBDIR
    test -n "$CC_FOR_BUILD" && export CC="$CC_FOR_BUILD"
    test -n "$CXX_FOR_BUILD" && export CXX="$CXX_FOR_BUILD"
    test -n "$PKG_CONFIG_FOR_BUILD" && export PKG_CONFIG="$PKG_CONFIG_FOR_BUILD"
    cd CONF-FOR-BUILD
    sub_conf_opts=""
    test -n "$enable_ccache" && sub_conf_opts="$sub_conf_opts --enable-ccache=$enable_ccache"
    test -n "$with_ant_home" && sub_conf_opts="$sub_conf_opts --with-ant-home=$with_ant_home"
    test $with_junit = no && sub_conf_opts="$sub_conf_opts --without-junit"
    test -n "$TARFILE_LOCATION" && sub_conf_opts="$sub_conf_opts --with-external-tar=$TARFILE_LOCATION"
    test "$with_system_icu_for_build" = "yes" -o "$with_system_icu_for_build" = "force" && sub_conf_opts="$sub_conf_opts --with-system-icu"
    sub_conf_opts="$sub_conf_opts $with_build_platform_configure_options"
    # Don't bother having configure look for stuff not needed for the build platform anyway
    ./configure \
        --disable-cups \
        --disable-gtk3 \
        --disable-pdfimport \
        --disable-postgresql-sdbc \
        --with-parallelism="$with_parallelism" \
        --without-doxygen \
        --without-java \
        $sub_conf_opts \
        --srcdir=$srcdir \
        2>&1 | sed -e 's/^/    /'
    test -f ./config_host.mk 2>/dev/null || exit
    cp config_host.mk ../config_build.mk
    cp config_host_lang.mk ../config_build_lang.mk
    mv config.log ../config.Build.log
    mkdir -p ../config_build
    mv config_host/*.h ../config_build
    . ./bin/get_config_variables CC CXX INSTDIR INSTROOT LIBO_BIN_FOLDER LIBO_LIB_FOLDER LIBO_URE_LIB_FOLDER LIBO_URE_MISC_FOLDER OS PATH SDKDIRNAME SYSTEM_LIBXML SYSTEM_LIBXSLT WORKDIR

    for V in CC CXX LIBO_BIN_FOLDER LIBO_LIB_FOLDER LIBO_URE_LIB_FOLDER LIBO_URE_MISC_FOLDER OS SDKDIRNAME SYSTEM_LIBXML SYSTEM_LIBXSLT; do
        VV='$'$V
        VV=`eval "echo $VV"`
        if test -n "$VV"; then
            line=${V}_FOR_BUILD='${'${V}_FOR_BUILD:-$VV'}'
            echo "$line" >>build-config
        fi
    done

    for V in INSTDIR INSTROOT WORKDIR; do
        VV='$'$V
        VV=`eval "echo $VV"`
        VV=`echo $VV | sed -e "s,/CONF-FOR-BUILD/\([[a-z]]*\),/\1_for_build,g"`
        if test -n "$VV"; then
            line="${V}_FOR_BUILD='$VV'"
            echo "$line" >>build-config
        fi
    done

    line=`echo "LO_PATH_FOR_BUILD=$PATH" | sed -e 's,/CONF-FOR-BUILD,,g'`
    echo "$line" >>build-config

    )
    test -f CONF-FOR-BUILD/build-config || AC_MSG_ERROR([Running configure script for BUILD system failed, see CONF-FOR-BUILD/config.log])
    test -f config_build.mk || AC_MSG_ERROR([A file called config_build.mk was supposed to have been copied here, but it isn't found])
    perl -pi -e 's,/(workdir|instdir)(/|$),/\1_for_build\2,g;' \
             -e 's,/CONF-FOR-BUILD,,g;' config_build.mk

    eval `cat CONF-FOR-BUILD/build-config`

    AC_MSG_RESULT([checking for BUILD platform configuration... done])

    rm -rf CONF-FOR-BUILD
else
    OS_FOR_BUILD="$OS"
    CC_FOR_BUILD="$CC"
    CXX_FOR_BUILD="$CXX"
    INSTDIR_FOR_BUILD="$INSTDIR"
    INSTROOT_FOR_BUILD="$INSTROOT"
    LIBO_BIN_FOLDER_FOR_BUILD="$LIBO_BIN_FOLDER"
    LIBO_LIB_FOLDER_FOR_BUILD="$LIBO_LIB_FOLDER"
    LIBO_URE_LIB_FOLDER_FOR_BUILD="$LIBO_URE_LIB_FOLDER"
    LIBO_URE_MISC_FOLDER_FOR_BUILD="$LIBO_URE_MISC_FOLDER"
    SDKDIRNAME_FOR_BUILD="$SDKDIRNAME"
    WORKDIR_FOR_BUILD="$WORKDIR"
fi
AC_SUBST(OS_FOR_BUILD)
AC_SUBST(INSTDIR_FOR_BUILD)
AC_SUBST(INSTROOT_FOR_BUILD)
AC_SUBST(LIBO_BIN_FOLDER_FOR_BUILD)
AC_SUBST(LIBO_LIB_FOLDER_FOR_BUILD)
AC_SUBST(LIBO_URE_LIB_FOLDER_FOR_BUILD)
AC_SUBST(LIBO_URE_MISC_FOLDER_FOR_BUILD)
AC_SUBST(SDKDIRNAME_FOR_BUILD)
AC_SUBST(WORKDIR_FOR_BUILD)

dnl ===================================================================
dnl Check for syslog header
dnl ===================================================================
AC_CHECK_HEADER(syslog.h, AC_DEFINE(HAVE_SYSLOG_H))

dnl Set the ENABLE_WERROR variable. (Activate --enable-werror)
dnl ===================================================================
AC_MSG_CHECKING([whether to turn warnings to errors])
if test -n "$enable_werror" -a "$enable_werror" != "no"; then
    ENABLE_WERROR="TRUE"
    AC_MSG_RESULT([yes])
else
    if test -n "$LODE_HOME" -a -z "$enable_werror"; then
        ENABLE_WERROR="TRUE"
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi
fi
AC_SUBST(ENABLE_WERROR)

dnl Check for --enable-assert-always-abort, set ASSERT_ALWAYS_ABORT
dnl ===================================================================
AC_MSG_CHECKING([whether to have assert() failures abort even without --enable-debug])
if test -n "$enable_assert_always_abort" -a "$enable_assert_always_abort" = "yes"; then
    ASSERT_ALWAYS_ABORT="TRUE"
    AC_MSG_RESULT([yes])
else
    ASSERT_ALWAYS_ABORT="FALSE"
    AC_MSG_RESULT([no])
fi
AC_SUBST(ASSERT_ALWAYS_ABORT)

# Determine whether to use ooenv for the instdir installation
# ===================================================================
if test $_os != "WINNT" -a $_os != "Darwin"; then
    AC_MSG_CHECKING([whether to use ooenv for the instdir installation])
    if test "$enable_ooenv" = "no"; then
        AC_MSG_RESULT([no])
    else
        ENABLE_OOENV="TRUE"
        AC_MSG_RESULT([yes])
    fi
fi
AC_SUBST(ENABLE_OOENV)

if test "$USING_X11" != TRUE; then
    # be sure to do not mess with unneeded stuff
    test_randr=no
    test_xrender=no
    test_cups=no
    test_dbus=no
    test_gtk=no
    build_gstreamer_1_0=no
    build_gstreamer_0_10=no
    test_kde4=no
    test_qt5=no
    enable_cairo_canvas=no
fi

dnl ===================================================================
dnl check for cups support
dnl ===================================================================
ENABLE_CUPS=""

if test "$enable_cups" = "no"; then
    test_cups=no
fi

AC_MSG_CHECKING([whether to enable CUPS support])
if test "$test_cups" = "yes"; then
    ENABLE_CUPS="TRUE"
    AC_MSG_RESULT([yes])

    AC_MSG_CHECKING([whether cups support is present])
    AC_CHECK_LIB([cups], [cupsPrintFiles], [:])
    AC_CHECK_HEADER(cups/cups.h, AC_DEFINE(HAVE_CUPS_H))
    if test "$ac_cv_lib_cups_cupsPrintFiles" != "yes" -o "$ac_cv_header_cups_cups_h" != "yes"; then
        AC_MSG_ERROR([Could not find CUPS. Install libcups2-dev or cups-devel.])
    fi

else
    AC_MSG_RESULT([no])
fi

AC_SUBST(ENABLE_CUPS)

# fontconfig checks
if test "$test_fontconfig" = "yes"; then
    PKG_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.4.1])
    SYSTEM_FONTCONFIG=TRUE
    FilterLibs "${FONTCONFIG_LIBS}"
    FONTCONFIG_LIBS="${filteredlibs}"
fi
AC_SUBST(FONTCONFIG_CFLAGS)
AC_SUBST(FONTCONFIG_LIBS)
AC_SUBST([SYSTEM_FONTCONFIG])

dnl whether to find & fetch external tarballs?
dnl ===================================================================
if test -z "$TARFILE_LOCATION" -a -n "$LODE_HOME" ; then
   if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
       TARFILE_LOCATION="`cygpath -m $LODE_HOME/ext_tar`"
   else
       TARFILE_LOCATION="$LODE_HOME/ext_tar"
   fi
fi
if test -z "$TARFILE_LOCATION"; then
    if test -d "$SRC_ROOT/src" ; then
        mv "$SRC_ROOT/src" "$SRC_ROOT/external/tarballs"
        ln -s "$SRC_ROOT/external/tarballs" "$SRC_ROOT/src"
    fi
    TARFILE_LOCATION="$SRC_ROOT/external/tarballs"
else
    AbsolutePath "$TARFILE_LOCATION"
    PathFormat "${absolute_path}"
    TARFILE_LOCATION="${formatted_path}"
fi
AC_SUBST(TARFILE_LOCATION)

AC_MSG_CHECKING([whether we want to fetch tarballs])
if test "$enable_fetch_external" != "no"; then
    if test "$with_all_tarballs" = "yes"; then
        AC_MSG_RESULT([yes, all of them])
        DO_FETCH_TARBALLS="ALL"
    else
        AC_MSG_RESULT([yes, if we use them])
        DO_FETCH_TARBALLS="TRUE"
    fi
else
    AC_MSG_RESULT([no])
    DO_FETCH_TARBALLS=
fi
AC_SUBST(DO_FETCH_TARBALLS)

AC_MSG_CHECKING([whether to build help])
if test -n "$with_help" -a "$with_help" != "no" -a $_os != iOS -a $_os != Android; then
    BUILD_TYPE="$BUILD_TYPE HELP"
    GIT_NEEDED_SUBMODULES="helpcontent2 $GIT_NEEDED_SUBMODULES"
    case "$with_help" in
    "common")
        AC_MSG_RESULT([common only])
        ;;
    "html")
        ENABLE_HTMLHELP=TRUE
        AC_MSG_RESULT([HTML])
        ;;
    "online")
        ENABLE_HTMLHELP=TRUE
        HELP_ONLINE=TRUE
        AC_MSG_RESULT([HTML])
        ;;
    *)
        SCPDEFS="$SCPDEFS -DWITH_HELP"
        AC_MSG_RESULT([yes])
        ;;
    esac
else
    AC_MSG_RESULT([no])
fi
AC_SUBST([ENABLE_HTMLHELP])
AC_SUBST([HELP_ONLINE])

dnl Test whether to include MySpell dictionaries
dnl ===================================================================
AC_MSG_CHECKING([whether to include MySpell dictionaries])
if test "$with_myspell_dicts" = "yes"; then
    AC_MSG_RESULT([yes])
    WITH_MYSPELL_DICTS=TRUE
    BUILD_TYPE="$BUILD_TYPE DICTIONARIES"
    GIT_NEEDED_SUBMODULES="dictionaries $GIT_NEEDED_SUBMODULES"
else
    AC_MSG_RESULT([no])
    WITH_MYSPELL_DICTS=
fi
AC_SUBST(WITH_MYSPELL_DICTS)

# There are no "system" myspell, hyphen or mythes dictionaries on OS X, Windows, Android or iOS.
if test $_os = Darwin -o $_os = WINNT -o $_os = iOS -o $_os = Android; then
    if test "$with_system_dicts" = yes; then
        AC_MSG_ERROR([There are no system dicts on this OS in the formats the 3rd-party libs we use expect]);
    fi
    with_system_dicts=no
fi

AC_MSG_CHECKING([whether to use dicts from external paths])
if test -z "$with_system_dicts" -o "$with_system_dicts" != "no"; then
    AC_MSG_RESULT([yes])
    SYSTEM_DICTS=TRUE
    AC_MSG_CHECKING([for spelling dictionary directory])
    if test -n "$with_external_dict_dir"; then
        DICT_SYSTEM_DIR=file://$with_external_dict_dir
    else
        DICT_SYSTEM_DIR=file:///usr/share/hunspell
        if test ! -d /usr/share/hunspell -a -d /usr/share/myspell; then
            DICT_SYSTEM_DIR=file:///usr/share/myspell
        fi
    fi
    AC_MSG_RESULT([$DICT_SYSTEM_DIR])
    AC_MSG_CHECKING([for hyphenation patterns directory])
    if test -n "$with_external_hyph_dir"; then
        HYPH_SYSTEM_DIR=file://$with_external_hyph_dir
    else
        HYPH_SYSTEM_DIR=file:///usr/share/hyphen
    fi
    AC_MSG_RESULT([$HYPH_SYSTEM_DIR])
    AC_MSG_CHECKING([for thesaurus directory])
    if test -n "$with_external_thes_dir"; then
        THES_SYSTEM_DIR=file://$with_external_thes_dir
    else
        THES_SYSTEM_DIR=file:///usr/share/mythes
    fi
    AC_MSG_RESULT([$THES_SYSTEM_DIR])
else
    AC_MSG_RESULT([no])
    SYSTEM_DICTS=
fi
AC_SUBST(SYSTEM_DICTS)
AC_SUBST(DICT_SYSTEM_DIR)
AC_SUBST(HYPH_SYSTEM_DIR)
AC_SUBST(THES_SYSTEM_DIR)

dnl ===================================================================
dnl enable pch by default on windows
dnl enable it explicitly otherwise
ENABLE_PCH=""
if test "$enable_pch" = yes -a "$enable_compiler_plugins" = yes; then
    if test -z "$libo_fuzzed_enable_pch"; then
        AC_MSG_ERROR([--enable-pch cannot be used with --enable-compiler-plugins])
    else
        AC_MSG_NOTICE([Resetting --enable-pch=no])
        enable_pch=no
    fi
fi

AC_MSG_CHECKING([whether to enable pch feature])
if test "$enable_pch" != "no"; then
    if test "$_os" = "WINNT"; then
        ENABLE_PCH="TRUE"
        AC_MSG_RESULT([yes])
    elif test -n "$enable_pch" && test "$GCC" = "yes"; then
        ENABLE_PCH="TRUE"
        AC_MSG_RESULT([yes])
    elif test -n "$enable_pch"; then
        AC_MSG_ERROR([Precompiled header not yet supported for your platform/compiler])
    else
        AC_MSG_RESULT([no])
    fi
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_PCH)

TAB=`printf '\t'`

AC_MSG_CHECKING([the GNU Make version])
_make_version=`$GNUMAKE --version | grep GNU | $GREP -v GPL | $SED -e 's@^[[^0-9]]*@@' -e 's@ .*@@' -e 's@,.*@@'`
_make_longver=`echo $_make_version | $AWK -F. '{ print \$1*10000+\$2*100+\$3 }'`
if test "$_make_longver" -ge "038200"; then
    AC_MSG_RESULT([$GNUMAKE $_make_version])

elif test "$_make_longver" -ge "038100"; then
    if test "$build_os" = "cygwin"; then
        AC_MSG_ERROR([failed ($GNUMAKE version >= 3.82 needed])
    fi
    AC_MSG_RESULT([$GNUMAKE $_make_version])

    dnl ===================================================================
    dnl Search all the common names for sha1sum
    dnl ===================================================================
    AC_CHECK_PROGS(SHA1SUM, sha1sum sha1 shasum openssl)
    if test -z "$SHA1SUM"; then
        AC_MSG_ERROR([install the appropriate SHA-1 checksumming program for this OS])
    elif test "$SHA1SUM" = "openssl"; then
        SHA1SUM="openssl sha1"
    fi
    AC_MSG_CHECKING([for GNU Make bug 20033])
    TESTGMAKEBUG20033=`mktemp -d tmp.XXXXXX`
    $SED -e "s/<TAB>/$TAB/g" > $TESTGMAKEBUG20033/Makefile << EOF
A := \$(wildcard *.a)

.PHONY: all
all: \$(A:.a=.b)
<TAB>@echo survived bug20033.

.PHONY: setup
setup:
<TAB>@touch 1.a 2.a 3.a 4.a 5.a 6.a

define d1
@echo lala \$(1)
@sleep 1
endef

define d2
@echo tyty \$(1)
@sleep 1
endef

%.b : %.a
<TAB>\$(eval CHECKSUM := \$(word 1,\$(shell cat \$^ | $SHA1SUM))) \$(if \$(wildcard \$(CACHEDIR)/\$(CHECKSUM)),\
<TAB>\$(call d1,\$(CHECKSUM)),\
<TAB>\$(call d2,\$(CHECKSUM)))
EOF
    if test -z "`(cd $TESTGMAKEBUG20033 && $GNUMAKE setup && $GNUMAKE -j)|grep survived`"; then
        no_parallelism_make="YES"
        AC_MSG_RESULT([yes, disable parallelism])
    else
        AC_MSG_RESULT([no, keep parallelism enabled])
    fi
    rm -rf $TESTGMAKEBUG20033
else
    AC_MSG_ERROR([failed ($GNUMAKE version >= 3.81 needed])
fi

# find if gnumake support file function
AC_MSG_CHECKING([whether GNU Make supports the 'file' function])
TESTGMAKEFILEFUNC="`mktemp -d -t tst.XXXXXX`"
if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
    TESTGMAKEFILEFUNC=`cygpath -m $TESTGMAKEFILEFUNC`
fi
$SED -e "s/<TAB>/$TAB/" > $TESTGMAKEFILEFUNC/Makefile << EOF
\$(file >test.txt,Success )

.PHONY: all
all:
<TAB>@cat test.txt

EOF
$GNUMAKE -C $TESTGMAKEFILEFUNC 2>/dev/null 1>&2
if test -f $TESTGMAKEFILEFUNC/test.txt; then
    HAVE_GNUMAKE_FILE_FUNC=TRUE
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
rm -rf $TESTGMAKEFILEFUNC
AC_SUBST(HAVE_GNUMAKE_FILE_FUNC)
AC_SUBST(GNUMAKE_WIN_NATIVE)

_make_ver_check=`$GNUMAKE --version | grep "Built for Windows"`
STALE_MAKE=
if test "$_make_ver_check" = ""; then
   STALE_MAKE=TRUE
fi

HAVE_LD_HASH_STYLE=FALSE
WITH_LINKER_HASH_STYLE=
AC_MSG_CHECKING([for --hash-style gcc linker support])
if test "$GCC" = "yes"; then
    if test -z "$with_linker_hash_style" -o "$with_linker_hash_style" = "yes"; then
        hash_styles="gnu sysv"
    elif test "$with_linker_hash_style" = "no"; then
        hash_styles=
    else
        hash_styles="$with_linker_hash_style"
    fi

    for hash_style in $hash_styles; do
        test "$HAVE_LD_HASH_STYLE" = "TRUE" && continue
        hash_style_ldflags_save=$LDFLAGS
        LDFLAGS="$LDFLAGS -Wl,--hash-style=$hash_style"

        AC_RUN_IFELSE([AC_LANG_PROGRAM(
            [
#include <stdio.h>
            ],[
printf ("");
            ])],
            [
                  HAVE_LD_HASH_STYLE=TRUE
                  WITH_LINKER_HASH_STYLE=$hash_style
            ],
            [HAVE_LD_HASH_STYLE=FALSE],
            [HAVE_LD_HASH_STYLE=FALSE])
        LDFLAGS=$hash_style_ldflags_save
    done

    if test "$HAVE_LD_HASH_STYLE" = "TRUE"; then
        AC_MSG_RESULT( $WITH_LINKER_HASH_STYLE )
    else
        AC_MSG_RESULT( no )
    fi
    LDFLAGS=$hash_style_ldflags_save
else
    AC_MSG_RESULT( no )
fi
AC_SUBST(HAVE_LD_HASH_STYLE)
AC_SUBST(WITH_LINKER_HASH_STYLE)

dnl ===================================================================
dnl Check whether there's a Perl version available.
dnl ===================================================================
if test -z "$with_perl_home"; then
    AC_PATH_PROG(PERL, perl)
else
    test "$build_os" = "cygwin" && with_perl_home=`cygpath -u "$with_perl_home"`
    _perl_path="$with_perl_home/bin/perl"
    if test -x "$_perl_path"; then
        PERL=$_perl_path
    else
        AC_MSG_ERROR([$_perl_path not found])
    fi
fi

dnl ===================================================================
dnl Testing for Perl version 5 or greater.
dnl $] is the Perl version variable, it is returned as an integer
dnl ===================================================================
if test "$PERL"; then
    AC_MSG_CHECKING([the Perl version])
    ${PERL} -e "exit($]);"
    _perl_version=$?
    if test "$_perl_version" -lt 5; then
        AC_MSG_ERROR([found Perl $_perl_version, use Perl 5])
    fi
    AC_MSG_RESULT([Perl $_perl_version])
else
    AC_MSG_ERROR([Perl not found, install Perl 5])
fi

dnl ===================================================================
dnl Testing for required Perl modules
dnl ===================================================================

AC_MSG_CHECKING([for required Perl modules])
if `$PERL -e 'use Cwd; use Digest::MD5'>/dev/null 2>&1`; then
    AC_MSG_RESULT([all modules found])
else
    AC_MSG_RESULT([failed to find some modules])
    # Find out which modules are missing.
    if ! `$PERL -e 'use Cwd;'>/dev/null 2>&1`; then
        missing_perl_modules="$missing_perl_modules Cwd"
    fi
    if ! `$PERL -e 'use Digest::MD5;'>/dev/null 2>&1`; then
        missing_perl_modules="$missing_perl_modules Digest::MD5"
    fi
       AC_MSG_ERROR([
    The missing Perl modules are: $missing_perl_modules
    Install them as superuser/administrator with "cpan -i $missing_perl_modules"])
fi

dnl ===================================================================
dnl Check for pkg-config
dnl ===================================================================
if test "$_os" != "WINNT"; then
    PKG_PROG_PKG_CONFIG
fi

if test "$_os" != "WINNT"; then

    # If you use CC=/path/to/compiler/foo-gcc or even CC="ccache
    # /path/to/compiler/foo-gcc" you need to set the AR etc env vars
    # explicitly. Or put /path/to/compiler in PATH yourself.

    # Use wrappers for LTO
    if test "$ENABLE_LTO" = "TRUE" -a "$COM_IS_CLANG" != "TRUE"; then
        AC_CHECK_TOOL(AR,gcc-ar)
        AC_CHECK_TOOL(NM,gcc-nm)
        AC_CHECK_TOOL(RANLIB,gcc-ranlib)
    else
        AC_CHECK_TOOL(AR,ar)
        AC_CHECK_TOOL(NM,nm)
        AC_CHECK_TOOL(RANLIB,ranlib)
    fi
    AC_CHECK_TOOL(OBJDUMP,objdump)
    AC_CHECK_TOOL(READELF,readelf)
    AC_CHECK_TOOL(STRIP,strip)
    if test "$_os" = "WINNT"; then
        AC_CHECK_TOOL(DLLTOOL,dlltool)
        AC_CHECK_TOOL(WINDRES,windres)
    fi
fi
AC_SUBST(AR)
AC_SUBST(DLLTOOL)
AC_SUBST(NM)
AC_SUBST(OBJDUMP)
AC_SUBST(PKG_CONFIG)
AC_SUBST(RANLIB)
AC_SUBST(READELF)
AC_SUBST(STRIP)
AC_SUBST(WINDRES)

dnl ===================================================================
dnl pkg-config checks on Mac OS X
dnl ===================================================================

if test $_os = Darwin; then
    AC_MSG_CHECKING([for bogus pkg-config])
    if test -n "$PKG_CONFIG"; then
        if test "$PKG_CONFIG" = /usr/bin/pkg-config && ls -l /usr/bin/pkg-config | $GREP -q Mono.framework; then
            AC_MSG_ERROR([yes, from Mono. This *will* break the build. Please remove or hide $PKG_CONFIG])
        else
            if test "$enable_bogus_pkg_config" = "yes"; then
                AC_MSG_RESULT([yes, user-approved from unknown origin.])
            else
                AC_MSG_ERROR([yes, from unknown origin. This *will* break the build. Please modify your PATH variable so that $PKG_CONFIG is no longer found by configure scripts.])
            fi
        fi
    else
        AC_MSG_RESULT([no, good])
    fi
fi

find_csc()
{
    # Return value: $csctest

    unset csctest

    reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP/v4/Client/InstallPath"
    if test -n "$regvalue"; then
        csctest=$regvalue
        return
    fi
}

find_al()
{
    # Return value: $altest

    unset altest

    for x in `ls /proc/registry32/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft\ SDKs/Windows`; do
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/$x/WinSDK-NetFx40Tools/InstallationFolder"
        if test -n "$regvalue" -a \( -f "$regvalue/al.exe" -o -f "$regvalue/bin/al.exe" \); then
            altest=$regvalue
            return
        fi
    done

    # We need this additional check to detect 4.6.1 or above.
    for ver in 4.7.2 4.7.1 4.7 4.6.2 4.6.1; do
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/NETFXSDK/$ver/WinSDK-NetFx40Tools/InstallationFolder"
        if test -n "$regvalue" -a \( -f "$regvalue/al.exe" -o -f "$regvalue/bin/al.exe" \); then
            altest=$regvalue
            return
        fi

        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/Microsoft/Microsoft SDKs/NETFXSDK/$ver/WinSDK-NetFx40Tools"
        if test -n "$regvalue" -a \( -f "$regvalue/al.exe" -o -f "$regvalue/bin/al.exe" \); then
            altest=$regvalue
            return
        fi
    done
}

find_dotnetsdk46()
{
    unset frametest

    for ver in 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6; do
        reg_get_value_64 "HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/Microsoft SDKs/NETFXSDK/$ver/KitsInstallationFolder"
        if test -n "$regvalue"; then
            frametest=$regvalue
            return
        fi
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/NETFXSDK/$ver/KitsInstallationFolder"
        if test -n "$regvalue"; then
            frametest=$regvalue
            return
        fi
    done
}

find_winsdk_version()
{
    # Args: $1 : SDK version as in "6.0A", "7.0" etc
    # Return values: $winsdktest, $winsdkbinsubdir, $winsdklibsubdir

    unset winsdktest winsdkbinsubdir winsdklibsubdir

    case "$1" in
    7.*)
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v${1}/InstallationFolder"
        if test -n "$regvalue"; then
            winsdktest=$regvalue
            winsdklibsubdir=.
            return
        fi
        ;;
    8.0|8.0A)
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows Kits/Installed Roots/KitsRoot"
        if test -n "$regvalue"; then
            winsdktest=$regvalue
            winsdklibsubdir=win8
            return
        fi
        ;;
    8.1|8.1A)
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows Kits/Installed Roots/KitsRoot81"
        if test -n "$regvalue"; then
            winsdktest=$regvalue
            winsdklibsubdir=winv6.3
            return
        fi
        ;;
    10.0)
        reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v${1}/InstallationFolder"
        if test -n "$regvalue"; then
            winsdktest=$regvalue
            reg_get_value_32 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v${1}/ProductVersion"
            if test -n "$regvalue"; then
                winsdkbinsubdir="$regvalue".0
            fi
            winsdklibsubdir=$regvalue
            if test "$regvalue" = "10.0.14393"; then
                winsdklibsubdir="10.0.14393.0"
            elif test "$regvalue" = "10.0.16299"; then
                winsdklibsubdir="10.0.16299.0"
            elif test "$regvalue" = "10.0.15063"; then
                winsdklibsubdir="10.0.15063.0"
            elif test "$regvalue" = "10.0.17134"; then
                winsdklibsubdir="$regvalue.0"
            elif test "$regvalue" = "10.0.17763"; then
                winsdklibsubdir="$regvalue.0"
            fi
            return
        fi
        ;;
    esac
}

find_winsdk()
{
    # Return value: From find_winsdk_version

    unset winsdktest

    for ver in $WINDOWS_SDK_ACCEPTABLE_VERSIONS; do
        find_winsdk_version $ver
        if test -n "$winsdktest"; then
            return
        fi
    done
}

find_msms()
{
    my_msm_files=Microsoft_VC${VCVER}_CRT_x86.msm
    if test $VCVER = 150; then
        my_msm_files="Microsoft_VC141_CRT_x86.msm ${my_msm_files}"
    fi
    AC_MSG_CHECKING([for ${my_msm_files}])
    msmdir=
    for ver in 14.0 15.0; do
        reg_get_value_32 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/VisualStudio/$ver/Setup/VS/MSMDir
        if test -n "$regvalue"; then
            for f in ${my_msm_files}; do
                if test -e "$regvalue/${f}"; then
                    msmdir=$regvalue
                    break
                fi
            done
        fi
    done
    dnl Is the following fallback really necessary, or was it added in response
    dnl to never having started Visual Studio on a given machine, so the
    dnl registry keys checked above had presumably not yet been created?
    dnl Anyway, if it really is necessary, it might be worthwhile to extend it
    dnl to also check %CommonProgramFiles(X86)% (typically expanding to
    dnl "C:\Program Files (X86)\Common Files" compared to %CommonProgramFiles%
    dnl expanding to "C:\Program Files\Common Files"), which would need
    dnl something like $(perl -e 'print $ENV{"CommonProgramFiles(x86)"}') to
    dnl obtain its value from cygwin:
    if test -z "$msmdir"; then
        my_msm_dir="${COMMONPROGRAMFILES}/Merge Modules/"
        for f in ${my_msm_files}; do
            if test -e "$my_msm_dir/${f}"; then
                msmdir=$my_msm_dir
            fi
        done
    fi

    dnl Starting from MSVC 15.0, merge modules are located in different directory
    if test $VCVER = 150; then
        for l in `ls -1 $VC_PRODUCT_DIR/redist/MSVC/`; do
            AC_MSG_CHECKING([for $VC_PRODUCT_DIR/redist/MSVC/$l/MergeModules])
            my_msm_dir="$VC_PRODUCT_DIR/redist/MSVC/$l/MergeModules/"
            for f in ${my_msm_files}; do
                if test -e "$my_msm_dir/${f}"; then
                    msmdir=$my_msm_dir
                    break
                fi
            done
        done
    fi

    if test -n "$msmdir"; then
        msmdir=`cygpath -m "$msmdir"`
        AC_MSG_RESULT([$msmdir])
    else
        if test "$ENABLE_RELEASE_BUILD" = "TRUE" ; then
            AC_MSG_ERROR([not found])
        else
            AC_MSG_WARN([not found])
            add_warning "MSM none of ${my_msm_files} found"
        fi
    fi
}

find_msvc_x64_dlls()
{
    msvcdllpath="$VC_PRODUCT_DIR/redist/x64/Microsoft.VC${VCVER}.CRT"
    if test "$VCVER" = 150; then
        for l in `ls -1 $VC_PRODUCT_DIR/redist/MSVC/`; do
            AC_MSG_CHECKING([for $VC_PRODUCT_DIR/redist/MSVC/$l/x64/Microsoft.VC141.CRT])
            if test -d "$VC_PRODUCT_DIR/redist/MSVC/$l/x64/Microsoft.VC141.CRT"; then
                msvcdllpath="$VC_PRODUCT_DIR/redist/MSVC/$l/x64/Microsoft.VC141.CRT"
                break
            fi
            if test -d "$VC_PRODUCT_DIR/redist/MSVC/$l/onecore/x64/Microsoft.VC150.CRT"; then
                msvcdllpath="$VC_PRODUCT_DIR/redist/MSVC/$l/onecore/x64/Microsoft.VC150.CRT"
                break
            fi
        done
    fi
    msvcdlls="msvcp140.dll vcruntime140.dll"
    for dll in $msvcdlls; do
        if ! test -f "$msvcdllpath/$dll"; then
            AC_MSG_ERROR([can not find $dll in $msvcdllpath])
        fi
    done
}

dnl =========================================
dnl Check for the Windows  SDK.
dnl =========================================
if test "$_os" = "WINNT"; then
    AC_MSG_CHECKING([for Windows SDK])
    if test "$build_os" = "cygwin"; then
        find_winsdk
        WINDOWS_SDK_HOME=$winsdktest

        # normalize if found
        if test -n "$WINDOWS_SDK_HOME"; then
            WINDOWS_SDK_HOME=`cygpath -d "$WINDOWS_SDK_HOME"`
            WINDOWS_SDK_HOME=`cygpath -u "$WINDOWS_SDK_HOME"`
        fi

        WINDOWS_SDK_LIB_SUBDIR=$winsdklibsubdir
    fi

    if test -n "$WINDOWS_SDK_HOME"; then
        # Remove a possible trailing backslash
        WINDOWS_SDK_HOME=`echo $WINDOWS_SDK_HOME | $SED 's/\/$//'`

        if test -f "$WINDOWS_SDK_HOME/Include/adoint.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/SqlUcode.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/usp10.h"; then
            have_windows_sdk_headers=yes
        elif test -f "$WINDOWS_SDK_HOME/Include/um/adoint.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/um/SqlUcode.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/um/usp10.h"; then
            have_windows_sdk_headers=yes
        elif test -f "$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/um/adoint.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/um/SqlUcode.h" \
             -a -f "$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/um/usp10.h"; then
            have_windows_sdk_headers=yes
        else
            have_windows_sdk_headers=no
        fi

        if test -f "$WINDOWS_SDK_HOME/lib/user32.lib"; then
            have_windows_sdk_libs=yes
        elif test -f "$WINDOWS_SDK_HOME/lib/$winsdklibsubdir/um/$WINDOWS_SDK_ARCH/user32.lib"; then
            have_windows_sdk_libs=yes
        else
            have_windows_sdk_libs=no
        fi

        if test $have_windows_sdk_headers = no -o $have_windows_sdk_libs = no; then
            AC_MSG_ERROR([Some (all?) Windows SDK files not found, please check if all needed parts of
the  Windows SDK are installed.])
        fi
    fi

    if test -z "$WINDOWS_SDK_HOME"; then
        AC_MSG_RESULT([no, hoping the necessary headers and libraries will be found anyway!?])
    elif echo $WINDOWS_SDK_HOME | grep "v7.1" >/dev/null 2>/dev/null; then
        WINDOWS_SDK_VERSION=70
        AC_MSG_RESULT([found Windows SDK 7 ($WINDOWS_SDK_HOME)])
    elif echo $WINDOWS_SDK_HOME | grep "8.0" >/dev/null 2>/dev/null; then
        WINDOWS_SDK_VERSION=80
        AC_MSG_RESULT([found Windows SDK 8.0 ($WINDOWS_SDK_HOME)])
    elif echo $WINDOWS_SDK_HOME | grep "8.1" >/dev/null 2>/dev/null; then
        WINDOWS_SDK_VERSION=81
        AC_MSG_RESULT([found Windows SDK 8.1 ($WINDOWS_SDK_HOME)])
    elif echo $WINDOWS_SDK_HOME | grep "/10" >/dev/null 2>/dev/null; then
        WINDOWS_SDK_VERSION=10
        AC_MSG_RESULT([found Windows SDK 10.0 ($WINDOWS_SDK_HOME)])
    else
        AC_MSG_ERROR([Found legacy Windows Platform SDK ($WINDOWS_SDK_HOME)])
    fi
    PathFormat "$WINDOWS_SDK_HOME"
    WINDOWS_SDK_HOME="$formatted_path"
    if test "$build_os" = "cygwin"; then
        SOLARINC="$SOLARINC -I$WINDOWS_SDK_HOME/include -I$COMPATH/Include"
        if test -d "$WINDOWS_SDK_HOME/include/um"; then
            SOLARINC="$SOLARINC -I$WINDOWS_SDK_HOME/include/um -I$WINDOWS_SDK_HOME/include/shared"
        elif test -d "$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/um"; then
            SOLARINC="$SOLARINC -I$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/um -I$WINDOWS_SDK_HOME/Include/$winsdklibsubdir/shared"
        fi
    fi

    dnl TODO: solenv/bin/modules/installer/windows/msiglobal.pm wants to use a
    dnl WiLangId.vbs that is included only in some SDKs (e.g., included in v7.1
    dnl but not in v8.0), so allow this to be overridden with a
    dnl WINDOWS_SDK_WILANGID for now; a full-blown --with-windows-sdk-wilangid
    dnl and configuration error if no WiLangId.vbs is found would arguably be
    dnl better, but I do not know under which conditions exactly it is needed by
    dnl msiglobal.pm:
    if test -z "$WINDOWS_SDK_WILANGID" -a -n "$WINDOWS_SDK_HOME"; then
        WINDOWS_SDK_WILANGID=$WINDOWS_SDK_HOME/Samples/sysmgmt/msi/scripts/WiLangId.vbs
        if ! test -e "$WINDOWS_SDK_WILANGID" ; then
            WINDOWS_SDK_WILANGID=$WINDOWS_SDK_HOME/bin/$WINDOWS_SDK_ARCH/WiLangId.vbs
        fi
        if ! test -e "$WINDOWS_SDK_WILANGID" ; then
            WINDOWS_SDK_WILANGID=$(cygpath -sm "C:/Program Files (x86)/Windows Kits/8.1/bin/$WINDOWS_SDK_ARCH/WiLangId.vbs")
        fi
        if ! test -e "$WINDOWS_SDK_WILANGID" ; then
            AC_MSG_WARN([WiLangId.vbs not found - building translated packages will fail])
            add_warning "WiLangId.vbs not found - building translated packages will fail"
        fi
    fi
fi
AC_SUBST(WINDOWS_SDK_HOME)
AC_SUBST(WINDOWS_SDK_LIB_SUBDIR)
AC_SUBST(WINDOWS_SDK_VERSION)
AC_SUBST(WINDOWS_SDK_WILANGID)

if test "$build_os" = "cygwin"; then
    dnl Check midl.exe; this being the first check for a tool in the SDK bin
    dnl dir, it also determines that dir's path w/o an arch segment if any,
    dnl WINDOWS_SDK_BINDIR_NO_ARCH:
    AC_MSG_CHECKING([for midl.exe])

    find_winsdk
    if test -n "$winsdkbinsubdir" \
        -a -f "$winsdktest/Bin/$winsdkbinsubdir/$WINDOWS_SDK_ARCH/midl.exe"
    then
        MIDL_PATH=$winsdktest/Bin/$winsdkbinsubdir/$WINDOWS_SDK_ARCH
        WINDOWS_SDK_BINDIR_NO_ARCH=$WINDOWS_SDK_HOME/Bin/$winsdkbinsubdir
    elif test -f "$winsdktest/Bin/$WINDOWS_SDK_ARCH/midl.exe"; then
        MIDL_PATH=$winsdktest/Bin/$WINDOWS_SDK_ARCH
        WINDOWS_SDK_BINDIR_NO_ARCH=$WINDOWS_SDK_HOME/Bin
    elif test -f "$winsdktest/Bin/midl.exe"; then
        MIDL_PATH=$winsdktest/Bin
        WINDOWS_SDK_BINDIR_NO_ARCH=$WINDOWS_SDK_HOME/Bin
    fi
    if test ! -f "$MIDL_PATH/midl.exe"; then
        AC_MSG_ERROR([midl.exe not found in $winsdktest/Bin/$WINDOWS_SDK_ARCH, Windows SDK installation broken?])
    else
        AC_MSG_RESULT([$MIDL_PATH/midl.exe])
    fi

    # Convert to posix path with 8.3 filename restrictions ( No spaces )
    MIDL_PATH=`win_short_path_for_make "$MIDL_PATH"`

    if test -f "$WINDOWS_SDK_BINDIR_NO_ARCH/msiinfo.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/msidb.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/uuidgen.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/msitran.exe"; then :
    elif test -f "$WINDOWS_SDK_BINDIR_NO_ARCH/x86/msiinfo.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/x86/msidb.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/x86/uuidgen.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/x86/msitran.exe"; then :
    elif test -f "$WINDOWS_SDK_HOME/bin/x86/msiinfo.exe" \
         -a -f "$WINDOWS_SDK_HOME/bin/x86/msidb.exe" \
         -a -f "$WINDOWS_SDK_BINDIR_NO_ARCH/x86/uuidgen.exe" \
         -a -f "$WINDOWS_SDK_HOME/bin/x86/msitran.exe"; then :
    else
        AC_MSG_ERROR([Some (all?) Windows Installer tools in the Windows SDK are missing, please install.])
    fi

    dnl Check csc.exe
    AC_MSG_CHECKING([for csc.exe])
    find_csc
    if test -f "$csctest/csc.exe"; then
        CSC_PATH="$csctest"
    fi
    if test ! -f "$CSC_PATH/csc.exe"; then
        AC_MSG_ERROR([csc.exe not found as $CSC_PATH/csc.exe])
    else
        AC_MSG_RESULT([$CSC_PATH/csc.exe])
    fi

    CSC_PATH=`win_short_path_for_make "$CSC_PATH"`

    dnl Check al.exe
    AC_MSG_CHECKING([for al.exe])
    find_winsdk
    if test -n "$winsdkbinsubdir" \
        -a -f "$winsdktest/Bin/$winsdkbinsubdir/$WINDOWS_SDK_ARCH/al.exe"
    then
        AL_PATH="$winsdktest/Bin/$winsdkbinsubdir/$WINDOWS_SDK_ARCH"
    elif test -f "$winsdktest/Bin/$WINDOWS_SDK_ARCH/al.exe"; then
        AL_PATH="$winsdktest/Bin/$WINDOWS_SDK_ARCH"
    elif test -f "$winsdktest/Bin/al.exe"; then
        AL_PATH="$winsdktest/Bin"
    fi

    if test -z "$AL_PATH"; then
        find_al
        if test -f "$altest/bin/al.exe"; then
            AL_PATH="$altest/bin"
        elif test -f "$altest/al.exe"; then
            AL_PATH="$altest"
        fi
    fi
    if test ! -f "$AL_PATH/al.exe"; then
        AC_MSG_ERROR([al.exe not found as $AL_PATH/al.exe])
    else
        AC_MSG_RESULT([$AL_PATH/al.exe])
    fi

    AL_PATH=`win_short_path_for_make "$AL_PATH"`

    dnl Check mscoree.lib / .NET Framework dir
    AC_MSG_CHECKING(.NET Framework)
    find_dotnetsdk46
    PathFormat "$frametest"
    frametest="$formatted_path"
    if test -f "$frametest/Lib/um/$WINDOWS_SDK_ARCH/mscoree.lib"; then
        DOTNET_FRAMEWORK_HOME="$frametest"
    else
        find_winsdk
        if test -f "$winsdktest/lib/mscoree.lib" -o -f "$winsdktest/lib/$winsdklibsubdir/um/$WINDOWS_SDK_ARCH/mscoree.lib"; then
            DOTNET_FRAMEWORK_HOME="$winsdktest"
        fi
    fi
    if test ! -f "$DOTNET_FRAMEWORK_HOME/lib/mscoree.lib" -a ! -f "$DOTNET_FRAMEWORK_HOME/lib/$winsdklibsubdir/um/$WINDOWS_SDK_ARCH/mscoree.lib" -a ! -f "$DOTNET_FRAMEWORK_HOME/Lib/um/$WINDOWS_SDK_ARCH/mscoree.lib"; then
        AC_MSG_ERROR([mscoree.lib not found])
    fi
    AC_MSG_RESULT([found: $DOTNET_FRAMEWORK_HOME])

    PathFormat "$MIDL_PATH"
    MIDL_PATH="$formatted_path"

    PathFormat "$AL_PATH"
    AL_PATH="$formatted_path"

    PathFormat "$DOTNET_FRAMEWORK_HOME"
    DOTNET_FRAMEWORK_HOME="$formatted_path"

    PathFormat "$CSC_PATH"
    CSC_PATH="$formatted_path"
fi

dnl ===================================================================
dnl Check if stdc headers are available excluding MSVC.
dnl ===================================================================
if test "$_os" != "WINNT"; then
    AC_HEADER_STDC
fi

dnl ===================================================================
dnl Testing for C++ compiler and version...
dnl ===================================================================

if test "$_os" != "WINNT"; then
    # AC_PROG_CXX sets CXXFLAGS to -g -O2 if not set, avoid that
    save_CXXFLAGS=$CXXFLAGS
    AC_PROG_CXX
    CXXFLAGS=$save_CXXFLAGS
else
    if test -n "$CC" -a -z "$CXX"; then
        CXX="$CC"
    fi
fi

dnl At least MSVC 2015 Update 1 is known to sporadically emit warning C4592
dnl ("implementation limitation" when defining OUStringLiteral variables in
dnl vcl/source/app/IconThemeInfo.cxx), while Update 3 is known good, and it is
dnl probably a good idea to require that anyway.  A reliable way to check for
dnl MSVC 2015 Update 3 appears to be to check for support of C++17 nested
dnl namespace definitions (which requires /std:c++latest to be enabled):
if test "$COM" = MSC -a "$VCVER" = 140; then
    AC_MSG_CHECKING([whether MSVC 2015 compiler $MSVC_CXX is at least Update 3])
    save_CXX=$CXX
    save_CXXFLAGS=$CXXFLAGS
    CXX=$MSVC_CXX
    CXXFLAGS="$CXXFLAGS /std:c++latest"
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
        namespace A::B {}
    ]])], [good=yes], [good=no])
    AC_LANG_POP([C++])
    CXX=$save_CXX
    CXXFLAGS=$save_CXXFLAGS
    AC_MSG_RESULT([$good])
    if test "$good" = no; then
        AC_MSG_ERROR([When using MSVC 2015, at least Update 3 must be installed])
    fi
fi

dnl check for GNU C++ compiler version
if test "$GXX" = "yes"; then
    AC_MSG_CHECKING([the GNU C++ compiler version])

    _gpp_version=`$CXX -dumpversion`
    _gpp_majmin=`echo $_gpp_version | $AWK -F. '{ print \$1*100+\$2 }'`

    if test "$_gpp_majmin" -lt "401"; then
        AC_MSG_ERROR([You need to use GNU C++ compiler version >= 4.1 to build LibreOffice, you have $_gpp_version.])
    else
        AC_MSG_RESULT([checked (g++ $_gpp_version)])
    fi

    dnl see https://code.google.com/p/android/issues/detail?id=41770
    if test "$_gpp_majmin" -ge "401"; then
        glibcxx_threads=no
        AC_LANG_PUSH([C++])
        AC_REQUIRE_CPP
        AC_MSG_CHECKING([whether $CXX is broken with boost.thread])
        AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
            #include <bits/c++config.h>]],[[
            #if !defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \
            && !defined(_GLIBCXX__PTHREADS) \
            && !defined(_GLIBCXX_HAS_GTHREADS)
            choke me
            #endif
        ]])],[AC_MSG_RESULT([yes])
        glibcxx_threads=yes],[AC_MSG_RESULT([no])])
        AC_LANG_POP([C++])
        if test $glibcxx_threads = yes; then
            BOOST_CXXFLAGS="-D_GLIBCXX_HAS_GTHREADS"
        fi
     fi
fi
AC_SUBST(BOOST_CXXFLAGS)

#
# prefx CXX with ccache if needed
#
if test "$CCACHE" != ""; then
    AC_MSG_CHECKING([whether $CXX is already ccached])
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS --ccache-skip -O2"
    dnl an empty program will do, we're checking the compiler flags
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
                      [use_ccache=yes], [use_ccache=no])
    if test $use_ccache = yes; then
        AC_MSG_RESULT([yes])
    else
        CXX="$CCACHE $CXX"
        AC_MSG_RESULT([no])
    fi
    CXXFLAGS=$save_CXXFLAGS
    AC_LANG_POP([C++])
fi

dnl ===================================================================
dnl Find pre-processors.(should do that _after_ messing with CC/CXX)
dnl ===================================================================

if test "$_os" != "WINNT"; then
    AC_PROG_CXXCPP

    dnl Check whether there's a C pre-processor.
    AC_PROG_CPP
fi


dnl ===================================================================
dnl Find integral type sizes and alignments
dnl ===================================================================

if test "$_os" != "WINNT"; then

if test "$_os" == "iOS"; then
    AC_MSG_CHECKING([iOS setting sizes long, short, int, long long, double, voidp])
    ac_cv_sizeof_long=8
    ac_cv_sizeof_short=2
    ac_cv_sizeof_int=4
    ac_cv_sizeof_long_long=8
    ac_cv_sizeof_double=8
    ac_cv_sizeof_voidp=8
else
    AC_CHECK_SIZEOF(long)
    AC_CHECK_SIZEOF(short)
    AC_CHECK_SIZEOF(int)
    AC_CHECK_SIZEOF(long long)
    AC_CHECK_SIZEOF(double)
    AC_CHECK_SIZEOF(void*)
fi

    SAL_TYPES_SIZEOFSHORT=$ac_cv_sizeof_short
    SAL_TYPES_SIZEOFINT=$ac_cv_sizeof_int
    SAL_TYPES_SIZEOFLONG=$ac_cv_sizeof_long
    SAL_TYPES_SIZEOFLONGLONG=$ac_cv_sizeof_long_long
    SAL_TYPES_SIZEOFPOINTER=$ac_cv_sizeof_voidp

    dnl Allow build without AC_CHECK_ALIGNOF, grrr
    m4_pattern_allow([AC_CHECK_ALIGNOF])
    m4_ifdef([AC_CHECK_ALIGNOF],
        [
            AC_CHECK_ALIGNOF(short,[#include <stddef.h>])
            AC_CHECK_ALIGNOF(int,[#include <stddef.h>])
            AC_CHECK_ALIGNOF(long,[#include <stddef.h>])
            AC_CHECK_ALIGNOF(double,[#include <stddef.h>])
        ],
        [
            case "$_os-$host_cpu" in
            Linux-i686)
                test -z "$ac_cv_alignof_short" && ac_cv_alignof_short=2
                test -z "$ac_cv_alignof_int" && ac_cv_alignof_int=4
                test -z "$ac_cv_alignof_long" && ac_cv_alignof_long=4
                test -z "$ac_cv_alignof_double" && ac_cv_alignof_double=4
                ;;
            Linux-x86_64)
                test -z "$ac_cv_alignof_short" && ac_cv_alignof_short=2
                test -z "$ac_cv_alignof_int" && ac_cv_alignof_int=4
                test -z "$ac_cv_alignof_long" && ac_cv_alignof_long=8
                test -z "$ac_cv_alignof_double" && ac_cv_alignof_double=8
                ;;
            *)
                if test -z "$ac_cv_alignof_short" -o \
                        -z "$ac_cv_alignof_int" -o \
                        -z "$ac_cv_alignof_long" -o \
                        -z "$ac_cv_alignof_double"; then
                   AC_MSG_ERROR([Your Autoconf doesn't have [AC_][CHECK_ALIGNOF]. You need to set the environment variables ac_cv_alignof_short, ac_cv_alignof_int, ac_cv_alignof_long and ac_cv_alignof_double.])
                fi
                ;;
            esac
        ])

    SAL_TYPES_ALIGNMENT2=$ac_cv_alignof_short
    SAL_TYPES_ALIGNMENT4=$ac_cv_alignof_int
    if test $ac_cv_sizeof_long -eq 8; then
        SAL_TYPES_ALIGNMENT8=$ac_cv_alignof_long
    elif test $ac_cv_sizeof_double -eq 8; then
        SAL_TYPES_ALIGNMENT8=$ac_cv_alignof_double
    else
        AC_MSG_ERROR([Cannot find alignment of 8 byte types.])
    fi

    dnl Check for large file support
    AC_SYS_LARGEFILE
    if test -n "$ac_cv_sys_file_offset_bits" -a "$ac_cv_sys_file_offset_bits" != "no"; then
        LFS_CFLAGS="-D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits"
    fi
    if test -n "$ac_cv_sys_large_files" -a "$ac_cv_sys_large_files" != "no"; then
        LFS_CFLAGS="$LFS_CFLAGS -D_LARGE_FILES"
    fi
else
    # Hardcode for MSVC
    SAL_TYPES_SIZEOFSHORT=2
    SAL_TYPES_SIZEOFINT=4
    SAL_TYPES_SIZEOFLONG=4
    SAL_TYPES_SIZEOFLONGLONG=8
    if test "$BITNESS_OVERRIDE" = ""; then
        SAL_TYPES_SIZEOFPOINTER=4
    else
        SAL_TYPES_SIZEOFPOINTER=8
    fi
    SAL_TYPES_ALIGNMENT2=2
    SAL_TYPES_ALIGNMENT4=4
    SAL_TYPES_ALIGNMENT8=8
    LFS_CFLAGS=''
fi
AC_SUBST(LFS_CFLAGS)

AC_DEFINE_UNQUOTED(SAL_TYPES_SIZEOFSHORT,$SAL_TYPES_SIZEOFSHORT)
AC_DEFINE_UNQUOTED(SAL_TYPES_SIZEOFINT,$SAL_TYPES_SIZEOFINT)
AC_DEFINE_UNQUOTED(SAL_TYPES_SIZEOFLONG,$SAL_TYPES_SIZEOFLONG)
AC_DEFINE_UNQUOTED(SAL_TYPES_SIZEOFLONGLONG,$SAL_TYPES_SIZEOFLONGLONG)
AC_DEFINE_UNQUOTED(SAL_TYPES_SIZEOFPOINTER,$SAL_TYPES_SIZEOFPOINTER)
AC_DEFINE_UNQUOTED(SAL_TYPES_ALIGNMENT2,$SAL_TYPES_ALIGNMENT2)
AC_DEFINE_UNQUOTED(SAL_TYPES_ALIGNMENT4,$SAL_TYPES_ALIGNMENT4)
AC_DEFINE_UNQUOTED(SAL_TYPES_ALIGNMENT8,$SAL_TYPES_ALIGNMENT8)

dnl ===================================================================
dnl Check whether to enable runtime optimizations
dnl ===================================================================
ENABLE_RUNTIME_OPTIMIZATIONS=
AC_MSG_CHECKING([whether to enable runtime optimizations])
if test -z "$enable_runtime_optimizations"; then
    for i in $CC; do
        case $i in
        -fsanitize=*)
            enable_runtime_optimizations=no
            break
            ;;
        esac
    done
fi
if test "$enable_runtime_optimizations" != no; then
    ENABLE_RUNTIME_OPTIMIZATIONS=TRUE
    AC_DEFINE(ENABLE_RUNTIME_OPTIMIZATIONS)
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST([ENABLE_RUNTIME_OPTIMIZATIONS])

dnl ===================================================================
dnl Check if valgrind headers are available
dnl ===================================================================
ENABLE_VALGRIND=
if test "$cross_compiling" != yes -a "$with_valgrind" != no; then
    prev_cppflags=$CPPFLAGS
    # Is VALGRIND_CFLAGS something one is supposed to have in the environment,
    # or where does it come from?
    CPPFLAGS="$CPPFLAGS $VALGRIND_CFLAGS"
    AC_CHECK_HEADER([valgrind/valgrind.h],
        [ENABLE_VALGRIND=TRUE])
    CPPFLAGS=$prev_cppflags
fi
AC_SUBST([ENABLE_VALGRIND])
if test -z "$ENABLE_VALGRIND"; then
    if test "$with_valgrind" = yes; then
        AC_MSG_ERROR([--with-valgrind specified but no Valgrind headers found])
    fi
    VALGRIND_CFLAGS=
fi
AC_SUBST([VALGRIND_CFLAGS])


dnl ===================================================================
dnl Check if SDT probes (for systemtap, gdb, dtrace) are available
dnl ===================================================================

# We need at least the sys/sdt.h include header.
AC_CHECK_HEADER([sys/sdt.h], [SDT_H_FOUND='TRUE'], [SDT_H_FOUND='FALSE'])
if test "$SDT_H_FOUND" = "TRUE"; then
    # Found sys/sdt.h header, now make sure the c++ compiler works.
    # Old g++ versions had problems with probes in constructors/destructors.
    AC_MSG_CHECKING([working sys/sdt.h and c++ support])
    AC_LANG_PUSH([C++])
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
    #include <sys/sdt.h>
    class ProbeClass
    {
    private:
      int& ref;
      const char *name;

    public:
      ProbeClass(int& v, const char *n) : ref(v), name(n)
      {
        DTRACE_PROBE2(_test_, cons, name, ref);
      }

      void method(int min)
      {
        DTRACE_PROBE3(_test_, meth, name, ref, min);
        ref -= min;
      }

      ~ProbeClass()
      {
        DTRACE_PROBE2(_test_, dest, name, ref);
      }
    };
    ]],[[
    int i = 64;
    DTRACE_PROBE1(_test_, call, i);
    ProbeClass inst = ProbeClass(i, "call");
    inst.method(24);
    ]])], [AC_MSG_RESULT([yes]); AC_DEFINE([USE_SDT_PROBES])],
          [AC_MSG_RESULT([no, sdt.h or c++ compiler too old])])
    AC_LANG_POP([C++])
fi
AC_CONFIG_HEADERS([config_host/config_probes.h])

dnl ===================================================================
dnl GCC features
dnl ===================================================================
if test "$GCC" = "yes" -o "$COM_IS_CLANG" = TRUE; then
    AC_MSG_CHECKING([whether $CC supports -mno-avx])
    save_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -Werror -mno-avx"
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_AVX=TRUE ],[])
    CFLAGS=$save_CFLAGS
    if test "$HAVE_GCC_AVX" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports -fstack-protector-strong])
    save_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -Werror -fstack-protector-strong"
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_STACK_PROTECTOR_STRONG=TRUE ],[])
    CFLAGS=$save_CFLAGS
    if test "$HAVE_GCC_STACK_PROTECTOR_STRONG" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports atomic functions])
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
    int v = 0;
    if (__sync_add_and_fetch(&v, 1) != 1 ||
        __sync_sub_and_fetch(&v, 1) != 0)
        return 1;
    __sync_synchronize();
    if (__sync_val_compare_and_swap(&v, 0, 1) != 0 ||
        v != 1)
        return 1;
    return 0;
]])],[HAVE_GCC_BUILTIN_ATOMIC=TRUE],[])
    if test "$HAVE_GCC_BUILTIN_ATOMIC" = "TRUE"; then
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_GCC_BUILTIN_ATOMIC)
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports __builtin_ffs])
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return __builtin_ffs(1); ]])],[HAVE_GCC_BUILTIN_FFS=TRUE],[])
    if test "$HAVE_GCC_BUILTIN_FFS" = "TRUE"; then
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_GCC_BUILTIN_FFS)
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CC supports __attribute__((deprecated(message)))])
    save_CFLAGS=$CFLAGS
    CFLAGS="$CFLAGS -Werror"
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            __attribute__((deprecated("test"))) void f();
        ])], [
            AC_DEFINE([HAVE_GCC_DEPRECATED_MESSAGE],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    CFLAGS=$save_CFLAGS

    AC_MSG_CHECKING([whether $CXX defines __base_class_type_info in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__base_class_type_info); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_BASE_CLASS_TYPE_INFO],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX defines __class_type_info in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__class_type_info); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CLASS_TYPE_INFO],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX declares __cxa_allocate_exception in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cxxabi.h>
            void * f() { return __cxxabiv1::__cxa_allocate_exception(0); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CXA_ALLOCATE_EXCEPTION],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX defines __cxa_eh_globals in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__cxa_eh_globals); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CXA_EH_GLOBALS],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX defines __cxa_exceptions in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__cxa_exceptions); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CXA_EXCEPTIONS],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX declares __cxa_get_globals in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cxxabi.h>
            void * f() { return __cxxabiv1::__cxa_get_globals(); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CXA_GET_GLOBALS],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX declares __cxa_throw in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cxxabi.h>
            void f() { __cxxabiv1::__cxa_throw(0, 0, 0); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_CXA_THROW],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX defines __si_class_type_info in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__si_class_type_info); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_SI_CLASS_TYPE_INFO],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    AC_MSG_CHECKING([whether $CXX defines __vmi_class_type_info in cxxabi.h])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            #include <cstddef>
            #include <cxxabi.h>
            std::size_t f() { return sizeof(__cxxabiv1::__vmi_class_type_info); }
        ])], [
            AC_DEFINE([HAVE_CXXABI_H_VMI_CLASS_TYPE_INFO],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])

    dnl Available in GCC 4.9 and at least in Clang 3.4 (which is the baseline
    dnl for at least --enable-compiler-plugins according to README.md):
    AC_MSG_CHECKING([whether $CXX supports __attribute__((warn_unused))])
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS -Werror -Wunknown-pragmas"
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            struct __attribute__((warn_unused)) dummy {};
        ])], [
            AC_DEFINE([HAVE_GCC_ATTRIBUTE_WARN_UNUSED],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++])
fi

AC_SUBST(HAVE_GCC_AVX)
AC_SUBST(HAVE_GCC_STACK_PROTECTOR_STRONG)
AC_SUBST(HAVE_GCC_BUILTIN_ATOMIC)
AC_SUBST(HAVE_GCC_BUILTIN_FFS)

dnl ===================================================================
dnl Identify the C++ library
dnl ===================================================================

AC_MSG_CHECKING([What the C++ library is])
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <utility>
#ifndef __GLIBCXX__
foo bar
#endif
]])],
    [CPP_LIBRARY=GLIBCXX
     cpp_library_name="GNU libstdc++"
    ],
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <utility>
#ifndef _LIBCPP_VERSION
foo bar
#endif
]])],
    [CPP_LIBRARY=LIBCPP
     cpp_library_name="LLVM libc++"
    ],
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <utility>
#ifndef _MSC_VER
foo bar
#endif
]])],
    [CPP_LIBRARY=MSVCRT
     cpp_library_name="Microsoft"
    ],
    AC_MSG_ERROR([Could not figure out what C++ library this is]))))
AC_MSG_RESULT([$cpp_library_name])
AC_LANG_POP([C++])

dnl ===================================================================
dnl C++11
dnl ===================================================================

CXXFLAGS_CXX11=
if test "$COM" = MSC; then
    AC_MSG_CHECKING([whether $CXX supports C++11])
    AC_MSG_RESULT(yes)
    # MSVC supports (a subset of) CXX11 without any switch
elif test "$GCC" = "yes"; then
    HAVE_CXX11=
    AC_MSG_CHECKING([whether $CXX supports C++14 or C++11])
    for flag in -std=gnu++14 -std=gnu++1y -std=c++14 -std=c++1y -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x ; do
        save_CXXFLAGS=$CXXFLAGS
        CXXFLAGS="$CXXFLAGS $flag -Werror"
        AC_LANG_PUSH([C++])
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
            #include <algorithm>
            #include <functional>
            #include <vector>
            void f(std::vector<int> & v, std::function<bool(int, int)> fn) {
                std::sort(v.begin(), v.end(), fn);
            }
            ]])],[CXXFLAGS_CXX11=$flag])
        AC_LANG_POP([C++])
        CXXFLAGS=$save_CXXFLAGS
        if test -n "$CXXFLAGS_CXX11"; then
            HAVE_CXX11=TRUE
            break
        fi
    done
    if test "$HAVE_CXX11" = TRUE; then
        AC_MSG_RESULT([yes ($CXXFLAGS_CXX11)])
    else
        AC_MSG_ERROR(no)
    fi
fi

dnl Test for temporarily incompatible libstdc++ 4.7.{0,1}, where
dnl <https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=179528> introduced
dnl an additional member _M_size into C++11 std::list towards 4.7.0 and
dnl <https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=189186> removed it
dnl again towards 4.7.2:
if test $CPP_LIBRARY = GLIBCXX; then
    AC_MSG_CHECKING([whether using C++11 causes libstdc++ 4.7.0/4.7.1 ABI breakage])
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <list>
#if !defined __GLIBCXX__ || (__GLIBCXX__ != 20120322 && __GLIBCXX__ != 20120614)
    // according to <https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html>:
    //   GCC 4.7.0: 20120322
    //   GCC 4.7.1: 20120614
    // and using a range check is not possible as the mapping between
    // __GLIBCXX__ values and GCC versions is not monotonic
/* ok */
#else
abi broken
#endif
        ]])], [AC_MSG_RESULT(no, ok)],
        [AC_MSG_ERROR(yes)])
    AC_LANG_POP([C++])
fi

AC_MSG_CHECKING([whether $CXX supports C++11 without Language Defect 757])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_LANG_PUSH([C++])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stddef.h>

template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S];

namespace
{
        struct b
        {
                int i;
                int j;
        };
}
]], [[
struct a
{
        int i;
        int j;
};
a thinga[]={{0,0}, {1,1}};
b thingb[]={{0,0}, {1,1}};
size_t i = sizeof(sal_n_array_size(thinga));
size_t j = sizeof(sal_n_array_size(thingb));
return !(i != 0 && j != 0);
]])
    ], [ AC_MSG_RESULT(yes) ],
    [ AC_MSG_ERROR(no)])
AC_LANG_POP([C++])
CXXFLAGS=$save_CXXFLAGS

dnl Clang 3.9 supports __float128 since
dnl <http://llvm.org/viewvc/llvm-project?view=revision&revision=268898> "Enable support for
dnl __float128 in Clang and enable it on pertinent platforms":
AC_MSG_CHECKING([whether $CXX supports C++11 without __float128 compile error])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_LANG_PUSH([C++])

AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <vector>
    // some Clang fail when compiling against libstdc++ headers with -std=gnu++0x
    // (__float128)
]])
    ],[ AC_MSG_RESULT(yes) ],
    [
        AC_MSG_RESULT(no)
        # The only reason why libstdc++ headers fail with Clang in C++11 mode is because
        # they use the __float128 type that Clang doesn't know (libstdc++ checks whether
        # __float128 is available during its build, but it's usually built using GCC,
        # and so c++config.h hardcodes __float128 being supported). As the only place
        # where __float128 is actually used is in a template specialization,
        # -D__float128=void will avoid the problem there while still causing a problem
        # if somebody actually uses the type.
        AC_MSG_CHECKING([whether -D__float128=void workaround helps])
        CXXFLAGS="$CXXFLAGS -D__float128=void"
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <vector>
    // some Clang fail when compiling against libstdc++ headers with -std=gnu++0x
    // (__float128)
]])
    ],
    [
     AC_MSG_RESULT(yes)
     CXXFLAGS_CXX11="$CXXFLAGS_CXX11 -D__float128=void"
    ],
    [
     AC_MSG_ERROR(no)
    ])
])

AC_LANG_POP([C++])
CXXFLAGS=$save_CXXFLAGS

AC_SUBST(CXXFLAGS_CXX11)

AC_MSG_CHECKING([whether $CXX supports C++14 constexpr])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    // A somewhat over-complicated way of checking for
    // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66460> "ICE using __func__
    // in constexpr function":
    #include <cassert>
    template<typename T> inline constexpr T f(T x) { return x; }
    template<typename T> inline constexpr T g(T x) {
        assert(f(static_cast<int>(x)));
        return x;
    }
    enum E { e };
    auto v = g(E::e);

    struct S {
        int n_;
        constexpr bool f() {
            int n = n_;
            int i = 0;
            while (n > 0) { --n; ++i; }
            assert(i >= 0);
            return i == 0;
        }
    };
    constexpr auto v2 = S{10}.f();
    ]])], [cxx14_constexpr=yes], [cxx14_constexpr=no])
AC_LANG_POP([C++])
CXXFLAGS=$save_CXXFLAGS
AC_MSG_RESULT([$cxx14_constexpr])
if test "$cxx14_constexpr" = yes; then
    AC_DEFINE([HAVE_CXX14_CONSTEXPR])
fi

AC_MSG_CHECKING([whether $CXX supports C++11 ref-qualifier])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    struct S {
        void f() &;
        void f() &&;
    };
    ]])], [cxx11_ref_qualifier=yes], [cxx11_ref_qualifier=no])
AC_LANG_POP([C++])
CXXFLAGS=$save_CXXFLAGS
AC_MSG_RESULT([$cxx11_ref_qualifier])
if test "$cxx11_ref_qualifier" = no; then
    AC_MSG_ERROR([Your $CXX does not support C++11 ref-qualifiers. This is no longer supported.])
fi

dnl _Pragma support (may require C++11)
if test "$GCC" = "yes" -o "$COM_IS_CLANG" = TRUE; then
    AC_MSG_CHECKING([whether $CXX supports _Pragma operator])
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11 -Werror"
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([
            _Pragma("GCC diagnostic ignored \"-Wformat\"")
        ])], [
            AC_DEFINE([HAVE_GCC_PRAGMA_OPERATOR],[1])
            AC_MSG_RESULT([yes])
        ], [AC_MSG_RESULT([no])])
    AC_LANG_POP([C++])
    CXXFLAGS=$save_CXXFLAGS
fi

HAVE_GCC_FNO_SIZED_DEALLOCATION=
if test "$GCC" = yes; then
    AC_MSG_CHECKING([whether $CXX supports -fno-sized-deallocation])
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS -fno-sized-deallocation"
    AC_LINK_IFELSE([AC_LANG_PROGRAM()],[HAVE_GCC_FNO_SIZED_DEALLOCATION=TRUE])
    CXXFLAGS=$save_CXXFLAGS
    AC_LANG_POP([C++])
    if test "$HAVE_GCC_FNO_SIZED_DEALLOCATION" = TRUE; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi
fi
AC_SUBST([HAVE_GCC_FNO_SIZED_DEALLOCATION])

AC_MSG_CHECKING([whether $CXX has GCC bug 87150])
AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
        struct S1 { S1(S1 &&); };
        struct S2: S1 {};
        S1 f(S2 s) { return s; }
    ])], [
        AC_DEFINE([HAVE_GCC_BUG_87150],[1])
        AC_MSG_RESULT([yes])
    ], [AC_MSG_RESULT([no])])
CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++])

dnl ===================================================================
dnl system stl sanity tests
dnl ===================================================================
if test "$_os" != "WINNT"; then

    AC_LANG_PUSH([C++])

    save_CPPFLAGS="$CPPFLAGS"
    if test -n "$MACOSX_SDK_PATH"; then
        CPPFLAGS="-isysroot $MACOSX_SDK_PATH $CPPFLAGS"
    fi

    # Assume visibility is not broken with libc++. The below test is very much designed for libstdc++
    # only.
    if test "$CPP_LIBRARY" = GLIBCXX; then
        dnl gcc#19664, gcc#22482, rhbz#162935
        AC_MSG_CHECKING([if STL headers are visibility safe (GCC bug 22482)])
        AC_EGREP_HEADER(visibility push, string, stlvisok=yes, stlvisok=no)
        AC_MSG_RESULT([$stlvisok])
        if test "$stlvisok" = "no"; then
            AC_MSG_ERROR([Your libstdc++ headers are not visibility safe. This is no longer supported.])
        fi
    fi

    # As the below test checks things when linking self-compiled dynamic libraries, it presumably is irrelevant
    # when we don't make any dynamic libraries?
    if test "$DISABLE_DYNLOADING" = ""; then
        AC_MSG_CHECKING([if gcc is -fvisibility-inlines-hidden safe (Clang bug 11250)])
        cat > conftestlib1.cc <<_ACEOF
template<typename T> struct S1 { virtual ~S1() {} virtual void f() {} };
struct S2: S1<int> { virtual ~S2(); };
S2::~S2() {}
_ACEOF
        cat > conftestlib2.cc <<_ACEOF
template<typename T> struct S1 { virtual ~S1() {} virtual void f() {} };
struct S2: S1<int> { virtual ~S2(); };
struct S3: S2 { virtual ~S3(); }; S3::~S3() {}
_ACEOF
        gccvisinlineshiddenok=yes
        if ! $CXX $CXXFLAGS $CPPFLAGS $LINKFLAGSSHL -fPIC -fvisibility-inlines-hidden conftestlib1.cc -o libconftest1$DLLPOST >/dev/null 2>&5; then
            gccvisinlineshiddenok=no
        else
            dnl At least Clang -fsanitize=address and -fsanitize=undefined are
            dnl known to not work with -z defs (unsetting which makes the test
            dnl moot, though):
            my_linkflagsnoundefs=$LINKFLAGSNOUNDEFS
            if test "$COM_IS_CLANG" = TRUE; then
                for i in $CXX $CXXFLAGS; do
                    case $i in
                    -fsanitize=*)
                        my_linkflagsnoundefs=
                        break
                        ;;
                    esac
                done
            fi
            if ! $CXX $CXXFLAGS $CPPFLAGS $LINKFLAGSSHL -fPIC -fvisibility-inlines-hidden conftestlib2.cc -L. -lconftest1 $my_linkflagsnoundefs -o libconftest2$DLLPOST >/dev/null 2>&5; then
                gccvisinlineshiddenok=no
            fi
        fi

        rm -fr libconftest*
        AC_MSG_RESULT([$gccvisinlineshiddenok])
        if test "$gccvisinlineshiddenok" = "no"; then
            AC_MSG_ERROR([Your gcc/clang is not -fvisibility-inlines-hidden safe. This is no longer supported.])
        fi
    fi

   AC_MSG_CHECKING([if gcc has a visibility bug with class-level attributes (GCC bug 26905)])
    cat >visibility.cxx <<_ACEOF
#pragma GCC visibility push(hidden)
struct __attribute__ ((visibility ("default"))) TestStruct {
  static void Init();
};
__attribute__ ((visibility ("default"))) void TestFunc() {
  TestStruct::Init();
}
_ACEOF
    if ! $CXX $CXXFLAGS $CPPFLAGS -fpic -S visibility.cxx; then
        gccvisbroken=yes
    else
        case "$host_cpu" in
        i?86|x86_64)
            if test "$_os" = "Darwin" -o "$_os" = "iOS"; then
                gccvisbroken=no
            else
                if $EGREP -q '@PLT|@GOT' visibility.s || test "$ENABLE_LTO" = "TRUE"; then
                    gccvisbroken=no
                else
                    gccvisbroken=yes
                fi
            fi
            ;;
        *)
            gccvisbroken=no
            ;;
        esac
    fi
    rm -f visibility.s visibility.cxx

    AC_MSG_RESULT([$gccvisbroken])
    if test "$gccvisbroken" = "yes"; then
        AC_MSG_ERROR([Your gcc is not -fvisibility=hidden safe. This is no longer supported.])
    fi

    CPPFLAGS="$save_CPPFLAGS"

    AC_LANG_POP([C++])
fi

dnl ===================================================================
dnl  Clang++ tests
dnl ===================================================================

HAVE_GCC_FNO_DEFAULT_INLINE=
HAVE_GCC_FNO_ENFORCE_EH_SPECS=
if test "$GCC" = "yes"; then
    AC_MSG_CHECKING([whether $CXX supports -fno-default-inline])
    if test -n "$CLANGVER" -a 0"$CLANGVER" -le 30100; then
        # Option just ignored and silly warning that isn't a real
        # warning printed
        :
    else
        AC_LANG_PUSH([C++])
        save_CXXFLAGS=$CXXFLAGS
        CXXFLAGS="$CFLAGS -Werror -fno-default-inline"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_FNO_DEFAULT_INLINE=TRUE ],[])
        CXXFLAGS=$save_CXXFLAGS
        AC_LANG_POP([C++])
    fi
    if test "$HAVE_GCC_FNO_DEFAULT_INLINE" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi

    AC_MSG_CHECKING([whether $CXX supports -fno-enforce-eh-specs])
    if test -n "$CLANGVER" -a 0"$CLANGVER" -le 30100; then
        # As above
        :
    else
        AC_LANG_PUSH([C++])
        save_CXXFLAGS=$CXXFLAGS
        CXXFLAGS="$CFLAGS -Werror -fno-enforce-eh-specs"
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ return 0; ]])],[ HAVE_GCC_FNO_ENFORCE_EH_SPECS=TRUE ],[])
        CXXFLAGS=$save_CXXFLAGS
        AC_LANG_POP([C++])
    fi
    if test "$HAVE_GCC_FNO_ENFORCE_EH_SPECS" = "TRUE"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_RESULT([no])
    fi
fi
AC_SUBST(HAVE_GCC_FNO_DEFAULT_INLINE)
AC_SUBST(HAVE_GCC_FNO_ENFORCE_EH_SPECS)

dnl ===================================================================
dnl Compiler plugins
dnl ===================================================================

COMPILER_PLUGINS=
# currently only Clang

if test "$COM_IS_CLANG" != "TRUE"; then
    if test "$libo_fuzzed_enable_compiler_plugins" = yes -a "$enable_compiler_plugins" = yes; then
        AC_MSG_NOTICE([Resetting --enable-compiler-plugins=no])
        enable_compiler_plugins=no
    fi
fi

if test "$COM_IS_CLANG" = "TRUE"; then
    if test -n "$enable_compiler_plugins"; then
        compiler_plugins="$enable_compiler_plugins"
    elif test -n "$ENABLE_DBGUTIL"; then
        compiler_plugins=test
    else
        compiler_plugins=no
    fi
    if test "$compiler_plugins" != "no"; then
        dnl The prefix where Clang resides, override to where Clang resides if
        dnl using a source build:
        if test -z "$CLANGDIR"; then
            CLANGDIR=/usr
        fi
        AC_LANG_PUSH([C++])
        save_CPPFLAGS=$CPPFLAGS
        save_CXX=$CXX
        # compiler plugins must be built with "native" bitness of clang
        # because they link against clang libraries
        CXX=${COMPILER_PLUGINS_CXX-$(echo $CXX | sed -e s/-m64// -e s/-m32//)}
        CPPFLAGS="$CPPFLAGS $CXXFLAGS_CXX11 -I$CLANGDIR/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
        AC_CHECK_HEADER(clang/AST/RecursiveASTVisitor.h,
            [COMPILER_PLUGINS=TRUE],
            [
            if test "$compiler_plugins" = "yes"; then
                AC_MSG_ERROR([Cannot find Clang headers to build compiler plugins.])
            else
                AC_MSG_WARN([Cannot find Clang headers to build compiler plugins, plugins disabled])
                add_warning "Cannot find Clang headers to build compiler plugins, plugins disabled."
            fi
            ])
        CXX=$save_CXX
        CPPFLAGS=$save_CPPFLAGS
        AC_LANG_POP([C++])
    fi
else
    if test "$enable_compiler_plugins" = "yes"; then
        AC_MSG_ERROR([Compiler plugins are currently supported only with the Clang compiler.])
    fi
fi
AC_SUBST(COMPILER_PLUGINS)
AC_SUBST(COMPILER_PLUGINS_CXX)
AC_SUBST(COMPILER_PLUGINS_CXX_LINKFLAGS)
AC_SUBST(CLANGDIR)
AC_SUBST(CLANGLIBDIR)

# Plugin to help linker.
# Add something like LD_PLUGIN=/usr/lib64/LLVMgold.so to your autogen.input.
# This makes --enable-lto build with clang work.
AC_SUBST(LD_PLUGIN)

dnl ===================================================================
dnl allocator
dnl ===================================================================
AC_MSG_CHECKING([which memory allocator to use])
if test "$with_alloc" = "system"; then
    AC_MSG_RESULT([system])
    ALLOC="SYS_ALLOC"
fi
if test "$with_alloc" = "tcmalloc"; then
    AC_MSG_RESULT(tcmalloc)
    if ! echo $host_cpu | $GREP -E 'i[[3456]]86' 2>/dev/null >/dev/null; then
        AC_MSG_ERROR([tcmalloc only available/usable on ix86])
    fi
    AC_CHECK_LIB([tcmalloc], [malloc], [:],
        [AC_MSG_ERROR(tcmalloc not found or functional. Install the Google Profiling Tools)], [])
    ALLOC="TCMALLOC"
fi
if test "$with_alloc" = "jemalloc"; then
    if test "$_os" != "FreeBSD" -o "$_os" != "NetBSD"; then
        AC_MSG_RESULT(jemalloc)
        save_CFLAGS=$CFLAGS
        CFLAGS="$CFLAGS -pthread"
        AC_CHECK_LIB([jemalloc], [malloc], [:],
            [AC_MSG_ERROR(jemalloc not found or functional. Install the jemalloc allocator.)], [])
        ALLOC="JEMALLOC"
        CFLAGS=$save_CFLAGS
    else
        AC_MSG_RESULT([system])
        ALLOC="SYS_ALLOC"
    fi
fi
if test "$with_alloc" = "internal" -o -z "$with_alloc"; then
    AC_MSG_RESULT([internal])
fi
AC_CHECK_FUNCS(posix_fallocate, HAVE_POSIX_FALLOCATE=YES, [HAVE_POSIX_FALLOCATE=NO])
AC_SUBST(HAVE_POSIX_FALLOCATE)
AC_SUBST(ALLOC)

dnl ===================================================================
dnl Custom build version
dnl ===================================================================

AC_MSG_CHECKING([whether to add custom build version])
if test "$with_build_version" != ""; then
    BUILD_VER_STRING=$with_build_version
    AC_MSG_RESULT([yes, $BUILD_VER_STRING])
else
    BUILD_VER_STRING=
    AC_MSG_RESULT([no])
fi
AC_SUBST(BUILD_VER_STRING)

JITC_PROCESSOR_TYPE=""
if test "$_os" = "Linux" -a "$host_cpu" = "powerpc"; then
    # IBMs JDK needs this...
    JITC_PROCESSOR_TYPE=6
    export JITC_PROCESSOR_TYPE
fi
AC_SUBST([JITC_PROCESSOR_TYPE])

# Misc Windows Stuff
AC_ARG_WITH(ucrt-dir,
    AS_HELP_STRING([--with-ucrt-dir],
        [path to the directory with the arch-specific MSU packages of the Windows Universal CRT redistributables
        (MS KB 2999226) for packaging into the installsets (without those the target system needs to install
        the UCRT or Visual C++ Runtimes manually). The directory must contain the following 6 files:
            Windows6.1-KB2999226-x64.msu
            Windows6.1-KB2999226-x86.msu
            Windows8.1-KB2999226-x64.msu
            Windows8.1-KB2999226-x86.msu
            Windows8-RT-KB2999226-x64.msu
            Windows8-RT-KB2999226-x86.msu
        A zip archive including those files is available from Microsoft site:
        https://www.microsoft.com/en-us/download/details.aspx?id=48234]),
,)
UCRT_REDISTDIR="$with_ucrt_dir"
if test $_os = "WINNT"; then
    find_msvc_x64_dlls
    find_msms
    MSVC_DLL_PATH="$msvcdllpath"
    MSVC_DLLS="$msvcdlls"
    MSM_PATH="$msmdir"
    # MSVC 15.3 changed it to VC141
    if echo "$MSVC_DLL_PATH" | grep -q "VC141.CRT$"; then
        SCPDEFS="$SCPDEFS -DWITH_VC141_REDIST"
    else
        SCPDEFS="$SCPDEFS -DWITH_VC${VCVER}_REDIST"
    fi
    if test "$UCRT_REDISTDIR" = "no"; then
        dnl explicitly disabled
        UCRT_REDISTDIR=""
    else
        if ! test -f "$UCRT_REDISTDIR/Windows6.1-KB2999226-x64.msu" -a \
                  -f "$UCRT_REDISTDIR/Windows6.1-KB2999226-x86.msu" -a \
                  -f "$UCRT_REDISTDIR/Windows8.1-KB2999226-x64.msu" -a \
                  -f "$UCRT_REDISTDIR/Windows8.1-KB2999226-x86.msu" -a \
                  -f "$UCRT_REDISTDIR/Windows8-RT-KB2999226-x64.msu" -a \
                  -f "$UCRT_REDISTDIR/Windows8-RT-KB2999226-x86.msu"; then
            UCRT_REDISTDIR=""
            if test -n "$PKGFORMAT"; then
               for i in "$PKGFORMAT"; do
                   case "$i" in
                   msi)
                       AC_MSG_WARN([--without-ucrt-dir not specified or MSUs not found - installer will have runtime dependency])
                       add_warning "--without-ucrt-dir not specified or MSUs not found - installer will have runtime dependency"
                       ;;
                   esac
               done
            fi
        fi
    fi
fi

AC_SUBST(UCRT_REDISTDIR)
AC_SUBST(MSVC_DLL_PATH)
AC_SUBST(MSVC_DLLS)
AC_SUBST(MSM_PATH)

dnl ===================================================================
dnl Checks for Java
dnl ===================================================================
if test "$ENABLE_JAVA" != ""; then

    # Windows-specific tests
    if test "$build_os" = "cygwin"; then
        if test "$BITNESS_OVERRIDE" = 64; then
            bitness=64
        else
            bitness=32
        fi

        if test -z "$with_jdk_home"; then
            for ver in 1.8 1.7 1.6; do
                reg_get_value "$bitness" "HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java Development Kit/$ver/JavaHome"
                if test -n "$regvalue"; then
                    _jdk_home=$regvalue
                    break
                fi
            done
            if test -f "$_jdk_home/lib/jvm.lib" -a -f "$_jdk_home/bin/java.exe"; then
                with_jdk_home="$_jdk_home"
                howfound="found automatically"
            else
                AC_MSG_ERROR([No JDK found, pass the --with-jdk-home option pointing to a $bitness-bit JDK])
            fi
        else
            test "$build_os" = "cygwin" && with_jdk_home=`win_short_path_for_make "$with_jdk_home"`
            howfound="you passed"
        fi
    fi

    # MacOS X: /usr/libexec/java_home helps to set the current JDK_HOME. Actually JDK_HOME should NOT be set where java (/usr/bin/java) is located.
    # /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java, but /usr does not contain the JDK libraries
    if test -z "$with_jdk_home" -a "$_os" = "Darwin" -a -x /usr/libexec/java_home; then
        with_jdk_home=`/usr/libexec/java_home`
    fi

    JAVA_HOME=; export JAVA_HOME
    if test -z "$with_jdk_home"; then
        AC_PATH_PROG(JAVAINTERPRETER, $with_java)
    else
        _java_path="$with_jdk_home/bin/$with_java"
        dnl Check if there is a Java interpreter at all.
        if test -x "$_java_path"; then
            JAVAINTERPRETER=$_java_path
        else
            AC_MSG_ERROR([$_java_path not found, pass --with-jdk-home])
        fi
    fi

    dnl Check that the JDK found is correct architecture (at least 2 reasons to
    dnl check: officebean needs to link -ljawt, and libjpipe.so needs to be
    dnl loaded by java to run JunitTests:
    if test "$build_os" = "cygwin"; then
        shortjdkhome=`cygpath -d "$with_jdk_home"`
        if test "$BITNESS_OVERRIDE" = 64 -a -f "$with_jdk_home/bin/java.exe" -a "`$shortjdkhome/bin/java.exe -version 2>&1 | $GREP -i 64-bit`" = "" >/dev/null; then
            AC_MSG_WARN([You are building 64-bit binaries but the JDK $howfound is 32-bit])
            AC_MSG_ERROR([You should pass the --with-jdk-home option pointing to a 64-bit JDK])
        elif test "$BITNESS_OVERRIDE" = "" -a -f "$_jdk_home/bin/java.exe" -a "`$shortjdkhome/bin/java.exe -version 2>&1 | $GREP -i 64-bit`" != ""  >/dev/null; then
            AC_MSG_WARN([You are building 32-bit binaries but the JDK $howfound is 64-bit])
            AC_MSG_ERROR([You should pass the --with-jdk-home option pointing to a (32-bit) JDK])
        fi

        if test x`echo "$JAVAINTERPRETER" | $GREP -i '\.exe$'` = x; then
            JAVAINTERPRETER="${JAVAINTERPRETER}.exe"
        fi
        JAVAINTERPRETER=`win_short_path_for_make "$JAVAINTERPRETER"`
    elif test "$cross_compiling" != "yes"; then
        case $CPUNAME in
            AARCH64|AXP|X86_64|HPPA|IA64|POWERPC64|S390X|SPARC64|GODSON64)
                if test -f "$JAVAINTERPRETER" -a "`$JAVAINTERPRETER -version 2>&1 | $GREP -i 64-bit`" = "" >/dev/null; then
                    AC_MSG_WARN([You are building 64-bit binaries but the JDK $JAVAINTERPRETER is 32-bit])
                    AC_MSG_ERROR([You should pass the --with-jdk-home option pointing to a 64-bit JDK])
                fi
                ;;
            *) # assumption: everything else 32-bit
                if test -f "$JAVAINTERPRETER" -a "`$JAVAINTERPRETER -version 2>&1 | $GREP -i 64-bit`" != ""  >/dev/null; then
                    AC_MSG_WARN([You are building 32-bit binaries but the JDK $howfound is 64-bit])
                    AC_MSG_ERROR([You should pass the --with-jdk-home option pointing to a (32-bit) JDK])
                fi
                ;;
        esac
    fi
fi

HAVE_JAVA9=
dnl ===================================================================
dnl Checks for JDK.
dnl ===================================================================

# Note that JAVA_HOME as for now always means the *build* platform's
# JAVA_HOME. Whether all the complexity here actually is needed any
# more or not, no idea.

if test "$ENABLE_JAVA" != ""; then
    _gij_longver=0
    AC_MSG_CHECKING([the installed JDK])
    if test -n "$JAVAINTERPRETER"; then
        dnl java -version sends output to stderr!
        if test `$JAVAINTERPRETER -version 2>&1 | $GREP -c "Kaffe"` -gt 0; then
            AC_MSG_ERROR([No valid check available. Please check the block for your desired java in configure.ac])
        elif test `$JAVAINTERPRETER --version 2>&1 | $GREP -c "GNU libgcj"` -gt 0; then
            AC_MSG_ERROR([No valid check available. Please check the block for your desired java in configure.ac])
        elif test `$JAVAINTERPRETER -version 2>&1 | $AWK '{ print }' | $GREP -c "BEA"` -gt 0; then
            AC_MSG_ERROR([No valid check available. Please check the block for your desired java in configure.ac])
        elif test `$JAVAINTERPRETER -version 2>&1 | $AWK '{ print }' | $GREP -c "IBM"` -gt 0; then
            JDK=ibm

            dnl IBM JDK specific tests
            _jdk=`$JAVAINTERPRETER -version 2>&1 | $AWK -F'"' '{ print \$2 }' | $SED s/[[-A-Za-z]]*//`
            _jdk_ver=`echo "$_jdk" | $AWK -F. '{ print (($1 * 100) + $2) * 100 + $3;}'`

            if test "$_jdk_ver" -lt 10600; then
                AC_MSG_ERROR([IBM JDK is too old, you need at least 1.6])
            fi

            AC_MSG_RESULT([checked (IBM JDK $_jdk)])

            if test "$with_jdk_home" = ""; then
                AC_MSG_ERROR([In order to successfully build LibreOffice using the IBM JDK,
you must use the "--with-jdk-home" configure option explicitly])
            fi

            JAVA_HOME=$with_jdk_home
        else
            JDK=sun

            dnl Sun JDK specific tests
            _jdk=`$JAVAINTERPRETER -version 2>&1 | $AWK -F'"' '{ print \$2 }' | $SED s/[[-A-Za-z]]*//`
            _jdk_ver=`echo "$_jdk" | $AWK -F. '{ print (($1 * 100) + $2) * 100 + $3;}'`

            if test "$_jdk_ver" -lt 10600; then
                AC_MSG_ERROR([JDK is too old, you need at least 1.6])
            fi
            if test "$_jdk_ver" -gt 10600; then
                JAVA_CLASSPATH_NOT_SET=TRUE
            fi
            if test "$_jdk_ver" -ge 10900; then
                HAVE_JAVA9=TRUE
            fi

            AC_MSG_RESULT([checked (JDK $_jdk)])
            JAVA_HOME=`echo $JAVAINTERPRETER | $SED -n "s,//*bin//*java,,p"`
            if test "$_os" = "WINNT"; then
                JAVA_HOME=`echo $JAVA_HOME | $SED "s,\.[[eE]][[xX]][[eE]]$,,"`
            fi

            # set to limit VM usage for JunitTests
            JAVAIFLAGS=-Xmx64M
            # set to limit VM usage for javac
            JAVAFLAGS=-J-Xmx128M
        fi
    else
        AC_MSG_ERROR([Java not found. You need at least jdk-1.6])
    fi
else
    dnl Java disabled
    JAVA_HOME=
    export JAVA_HOME
fi

dnl ===================================================================
dnl Set target Java bytecode version
dnl ===================================================================
if test "$ENABLE_JAVA" != ""; then
    if test "$HAVE_JAVA9" = "TRUE"; then
        _java_target_ver="1.6"
    else
        _java_target_ver="1.5"
    fi
    JAVA_SOURCE_VER="$_java_target_ver"
    JAVA_TARGET_VER="$_java_target_ver"
fi

dnl ===================================================================
dnl Checks for javac
dnl ===================================================================
if test "$ENABLE_JAVA" != ""; then
    javacompiler="javac"
    if test -z "$with_jdk_home"; then
        AC_PATH_PROG(JAVACOMPILER, $javacompiler)
    else
        _javac_path="$with_jdk_home/bin/$javacompiler"
        dnl Check if there is a Java compiler at all.
        if test -x "$_javac_path"; then
            JAVACOMPILER=$_javac_path
        fi
    fi
    if test -z "$JAVACOMPILER"; then
        AC_MSG_ERROR([$javacompiler not found set with_jdk_home])
    fi
    if test "$build_os" = "cygwin"; then
        if test x`echo "$JAVACOMPILER" | $GREP -i '\.exe$'` = x; then
            JAVACOMPILER="${JAVACOMPILER}.exe"
        fi
        JAVACOMPILER=`win_short_path_for_make "$JAVACOMPILER"`
    fi
fi

dnl ===================================================================
dnl Checks for javadoc
dnl ===================================================================
if test "$ENABLE_JAVA" != ""; then
    if test -z "$with_jdk_home"; then
        AC_PATH_PROG(JAVADOC, javadoc)
    else
        _javadoc_path="$with_jdk_home/bin/javadoc"
        dnl Check if there is a javadoc at all.
        if test -x "$_javadoc_path"; then
            JAVADOC=$_javadoc_path
        else
            AC_PATH_PROG(JAVADOC, javadoc)
        fi
    fi
    if test -z "$JAVADOC"; then
        AC_MSG_ERROR([$_javadoc_path not found set with_jdk_home])
    fi
    if test "$build_os" = "cygwin"; then
        if test x`echo "$JAVADOC" | $GREP -i '\.exe$'` = x; then
            JAVADOC="${JAVADOC}.exe"
        fi
        JAVADOC=`win_short_path_for_make "$JAVADOC"`
    fi

    if test `$JAVADOC --version 2>&1 | $GREP -c "gjdoc"` -gt 0; then
    JAVADOCISGJDOC="yes"
    fi
fi
AC_SUBST(JAVADOCISGJDOC)

if test "$ENABLE_JAVA" != ""; then
    # check if JAVA_HOME was (maybe incorrectly?) set automatically to /usr
    if test "$JAVA_HOME" = "/usr" -a "x$with_jdk_home" = "x"; then
        if basename $(readlink $(readlink $JAVACOMPILER)) >/dev/null 2>/dev/null; then
           # try to recover first by looking whether we have a alternatives
           # system as in Debian or newer SuSEs where following /usr/bin/javac
           # over /etc/alternatives/javac leads to the right bindir where we
           # just need to strip a bit away to get a valid JAVA_HOME
           JAVA_HOME=$(readlink $(readlink $JAVACOMPILER))
        elif readlink $JAVACOMPILER >/dev/null 2>/dev/null; then
            # maybe only one level of symlink (e.g. on Mac)
            JAVA_HOME=$(readlink $JAVACOMPILER)
            if test "$(dirname $JAVA_HOME)" = "."; then
                # we've got no path to trim back
                JAVA_HOME=""
            fi
        else
            # else warn
            AC_MSG_WARN([JAVA_HOME is set to /usr - this is very likely to be incorrect])
            AC_MSG_WARN([if this is the case, please inform the correct JAVA_HOME with --with-jdk-home])
            add_warning "JAVA_HOME is set to /usr - this is very likely to be incorrect"
            add_warning "if this is the case, please inform the correct JAVA_HOME with --with-jdk-home"
        fi
        dnl now that we probably have the path to the real javac, make a JAVA_HOME out of it..
        if test "$JAVA_HOME" != "/usr"; then
            if test "$_os" = "Darwin" -o "$OS_FOR_BUILD" = MACOSX; then
                dnl Leopard returns a non-suitable path with readlink - points to "Current" only
                JAVA_HOME=$(echo $JAVA_HOME | $SED -e s,/Current/Commands/javac$,/CurrentJDK/Home,)
                dnl Tiger already returns a JDK path..
                JAVA_HOME=$(echo $JAVA_HOME | $SED -e s,/CurrentJDK/Commands/javac$,/CurrentJDK/Home,)
            else
                JAVA_HOME=$(echo $JAVA_HOME | $SED -e s,/bin/javac$,,)
                dnl check that we have a directory as certain distros eg gentoo substitute javac for a script
                dnl that checks which version to run
                if test -f "$JAVA_HOME"; then
                    JAVA_HOME=""; # set JAVA_HOME to null if it's a file
                fi
            fi
        fi
    fi
    # as we drop out of this, JAVA_HOME may have been set to the empty string by readlink

    dnl now if JAVA_HOME has been set to empty, then call findhome to find it
    if test -z "$JAVA_HOME"; then
        if test "x$with_jdk_home" = "x"; then
            cat > findhome.java <<_ACEOF
[import java.io.File;

class findhome
{
    public static void main(String args[])
    {
        String jrelocation = System.getProperty("java.home");
        File jre = new File(jrelocation);
        System.out.println(jre.getParent());
    }
}]
_ACEOF
            AC_MSG_CHECKING([if javac works])
            javac_cmd="$JAVACOMPILER findhome.java 1>&2"
            AC_TRY_EVAL(javac_cmd)
            if test $? = 0 -a -f ./findhome.class; then
                AC_MSG_RESULT([javac works])
            else
                echo "configure: javac test failed" >&5
                cat findhome.java >&5
                AC_MSG_ERROR([javac does not work - java projects will not build!])
            fi
            AC_MSG_CHECKING([if gij knows its java.home])
            JAVA_HOME=`$JAVAINTERPRETER findhome`
            if test $? = 0 -a "$JAVA_HOME" != ""; then
                AC_MSG_RESULT([$JAVA_HOME])
            else
                echo "configure: java test failed" >&5
                cat findhome.java >&5
                AC_MSG_ERROR([gij does not know its java.home - use --with-jdk-home])
            fi
            # clean-up after ourselves
            rm -f ./findhome.java ./findhome.class
        else
            JAVA_HOME=`echo $JAVAINTERPRETER | $SED -n "s,//*bin//*$with_java,,p"`
        fi
    fi

    # now check if $JAVA_HOME is really valid
    if test "$_os" = "Darwin" -o "$OS_FOR_BUILD" = MACOSX; then
        case "${JAVA_HOME}" in
            /Library/Java/JavaVirtualMachines/*)
                ;;
            *)
                AC_MSG_ERROR([JDK in $JAVA_HOME cannot be used in CppUnit tests - install Oracle JDK])
                ;;
        esac
        if test ! -f "$JAVA_HOME/lib/jvm.cfg" -a "x$with_jdk_home" = "x"; then
            JAVA_HOME_OK="NO"
        fi
    elif test ! -d "$JAVA_HOME/jre" -a "x$with_jdk_home" = "x"; then
        JAVA_HOME_OK="NO"
    fi
    if test "$JAVA_HOME_OK" = "NO"; then
        AC_MSG_WARN([JAVA_HOME was not explicitly informed with --with-jdk-home. the configure script])
        AC_MSG_WARN([attempted to find JAVA_HOME automatically, but apparently it failed])
        AC_MSG_WARN([in case JAVA_HOME is incorrectly set, some projects with not be built correctly])
        add_warning "JAVA_HOME was not explicitly informed with --with-jdk-home. the configure script"
        add_warning "attempted to find JAVA_HOME automatically, but apparently it failed"
        add_warning "in case JAVA_HOME is incorrectly set, some projects with not be built correctly"
    fi
    PathFormat "$JAVA_HOME"
    JAVA_HOME="$formatted_path"
fi

if test -z "$JAWTLIB" -a -n "$ENABLE_JAVA" -a "$_os" != Android -a \
    "$_os" != Darwin
then
    AC_MSG_CHECKING([for JAWT lib])
    if test "$_os" = WINNT; then
        # The path to $JAVA_HOME/lib/$JAWTLIB is part of $ILIB:
        JAWTLIB=jawt.lib
    else
        case "$host_cpu" in
        arm*)
            AS_IF([test -e "$JAVA_HOME/jre/lib/aarch32/libjawt.so"], [my_java_arch=aarch32], [my_java_arch=arm])
            JAVA_ARCH=$my_java_arch
            ;;
        i*86)
            my_java_arch=i386
            ;;
        m68k)
            my_java_arch=m68k
            ;;
        powerpc)
            my_java_arch=ppc
            ;;
        powerpc64)
            my_java_arch=ppc64
            ;;
        powerpc64le)
            AS_IF([test -e "$JAVA_HOME/jre/lib/ppc64le/libjawt.so"], [my_java_arch=ppc64le], [my_java_arch=ppc64])
            JAVA_ARCH=$my_java_arch
            ;;
        sparc64)
            my_java_arch=sparcv9
            ;;
        x86_64)
            my_java_arch=amd64
            ;;
        *)
            my_java_arch=$host_cpu
            ;;
        esac
        # This is where JDK9 puts the library
        if test -e "$JAVA_HOME/lib/libjawt.so"; then
            JAWTLIB="-L$JAVA_HOME/lib/ -ljawt"
        else
            JAWTLIB="-L$JAVA_HOME/jre/lib/$my_java_arch -ljawt"
        fi
        AS_IF([test "$JAVA_ARCH" != ""], [AC_DEFINE_UNQUOTED([JAVA_ARCH], ["$JAVA_ARCH"])])
    fi
    AC_MSG_RESULT([$JAWTLIB])
fi
AC_SUBST(JAWTLIB)

if test -n "$ENABLE_JAVA" -a -z "$JAVAINC"; then
    case "$host_os" in

    aix*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/aix"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    cygwin*)
        JAVAINC="-I$JAVA_HOME/include/win32"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include"
        ;;

    darwin*)
        if test -d "$JAVA_HOME/include/darwin"; then
            JAVAINC="-I$JAVA_HOME/include  -I$JAVA_HOME/include/darwin"
        else
            JAVAINC=${ISYSTEM}$FRAMEWORKSHOME/JavaVM.framework/Versions/Current/Headers
        fi
        ;;

    dragonfly*)
        JAVAINC="-I$JAVA_HOME/include"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    freebsd*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/freebsd"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/bsd"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/linux"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    k*bsd*-gnu*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/linux"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    linux-gnu*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/linux"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    *netbsd*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/netbsd"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
       ;;

    openbsd*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/openbsd"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;

    solaris*)
        JAVAINC="-I$JAVA_HOME/include"
        JAVAINC="$JAVAINC -I$JAVA_HOME/include/solaris"
        test -d "$JAVA_HOME/include/native_thread" && JAVAINC="$JAVAINC -I$JAVA_HOME/include/native_thread"
        ;;
    esac
fi
SOLARINC="$SOLARINC $JAVAINC"

AC_SUBST(JAVACOMPILER)
AC_SUBST(JAVADOC)
AC_SUBST(JAVAINTERPRETER)
AC_SUBST(JAVAIFLAGS)
AC_SUBST(JAVAFLAGS)
AC_SUBST(JAVA_CLASSPATH_NOT_SET)
AC_SUBST(JAVA_HOME)
AC_SUBST(JAVA_SOURCE_VER)
AC_SUBST(JAVA_TARGET_VER)
AC_SUBST(JDK)


dnl ===================================================================
dnl Export file validation
dnl ===================================================================
AC_MSG_CHECKING([whether to enable export file validation])
if test "$with_export_validation" != "no"; then
    if test -z "$ENABLE_JAVA"; then
        if test "$with_export_validation" = "yes"; then
            AC_MSG_ERROR([requested, but Java is disabled])
        else
            AC_MSG_RESULT([no, as Java is disabled])
        fi
    elif test "$_jdk_ver" -lt 10800; then
        if test "$with_export_validation" = "yes"; then
            AC_MSG_ERROR([requested, but Java is too old, need Java 8])
        else
            AC_MSG_RESULT([no, as Java is too old, need Java 8])
        fi
    else
        AC_MSG_RESULT([yes])
        AC_DEFINE(HAVE_EXPORT_VALIDATION)

        AC_PATH_PROGS(ODFVALIDATOR, odfvalidator)
        if test -z "$ODFVALIDATOR"; then
            # remember to download the ODF toolkit with validator later
            AC_MSG_NOTICE([no odfvalidator found, will download it])
            BUILD_TYPE="$BUILD_TYPE ODFVALIDATOR"
            ODFVALIDATOR="$BUILDDIR/bin/odfvalidator.sh"

            # and fetch name of odfvalidator jar name from download.lst
            ODFVALIDATOR_JAR=`$SED -n -e "s/export *ODFVALIDATOR_JAR *:= *\(.*\) */\1/p" $SRC_ROOT/download.lst`
            AC_SUBST(ODFVALIDATOR_JAR)

            if test -z "$ODFVALIDATOR_JAR"; then
                AC_MSG_ERROR([cannot determine odfvalidator jar location (--with-export-validation)])
            fi
        fi
        if test "$build_os" = "cygwin"; then
            # In case of Cygwin it will be executed from Windows,
            # so we need to run bash and absolute path to validator
            # so instead of "odfvalidator" it will be
            # something like "bash.exe C:\cygwin\opt\lo\bin\odfvalidator"
            ODFVALIDATOR="bash.exe `cygpath -m "$ODFVALIDATOR"`"
        else
            ODFVALIDATOR="sh $ODFVALIDATOR"
        fi
        AC_SUBST(ODFVALIDATOR)


        AC_PATH_PROGS(OFFICEOTRON, officeotron)
        if test -z "$OFFICEOTRON"; then
            # remember to download the officeotron with validator later
            AC_MSG_NOTICE([no officeotron found, will download it])
            BUILD_TYPE="$BUILD_TYPE OFFICEOTRON"
            OFFICEOTRON="$BUILDDIR/bin/officeotron.sh"

            # and fetch name of officeotron jar name from download.lst
            OFFICEOTRON_JAR=`$SED -n -e "s/export *OFFICEOTRON_JAR *:= *\(.*\) */\1/p" $SRC_ROOT/download.lst`
            AC_SUBST(OFFICEOTRON_JAR)

            if test -z "$OFFICEOTRON_JAR"; then
                AC_MSG_ERROR([cannot determine officeotron jar location (--with-export-validation)])
            fi
        else
            # check version of existing officeotron
            OFFICEOTRON_VER=`$OFFICEOTRON --version | $AWK -F. '{ print \$1*10000+\$2*100+\$3 }'`
            if test 0"$OFFICEOTRON_VER" -lt 704; then
                AC_MSG_ERROR([officeotron too old])
            fi
        fi
        if test "$build_os" = "cygwin"; then
            # In case of Cygwin it will be executed from Windows,
            # so we need to run bash and absolute path to validator
            # so instead of "odfvalidator" it will be
            # something like "bash.exe C:\cygwin\opt\lo\bin\odfvalidator"
            OFFICEOTRON="bash.exe `cygpath -m "$OFFICEOTRON"`"
        else
            OFFICEOTRON="sh $OFFICEOTRON"
        fi
    fi
    AC_SUBST(OFFICEOTRON)
else
    AC_MSG_RESULT([no])
fi

AC_MSG_CHECKING([for Microsoft Binary File Format Validator])
if test "$with_bffvalidator" != "no"; then
    AC_DEFINE(HAVE_BFFVALIDATOR)

    if test "$with_export_validation" = "no"; then
        AC_MSG_ERROR([Please enable export validation (-with-export-validation)!])
    fi

    if test "$with_bffvalidator" = "yes"; then
        BFFVALIDATOR=`win_short_path_for_make "$PROGRAMFILES/Microsoft Office/BFFValidator/BFFValidator.exe"`
    else
        BFFVALIDATOR="$with_bffvalidator"
    fi

    if test "$build_os" = "cygwin"; then
        if test -n "$BFFVALIDATOR" -a -e "`cygpath $BFFVALIDATOR`"; then
            AC_MSG_RESULT($BFFVALIDATOR)
        else
            AC_MSG_ERROR([bffvalidator not found, but required by --with-bffvalidator])
        fi
    elif test -n "$BFFVALIDATOR"; then
        # We are not in Cygwin but need to run Windows binary with wine
        AC_PATH_PROGS(WINE, wine)

        # so swap in a shell wrapper that converts paths transparently
        BFFVALIDATOR_EXE="$BFFVALIDATOR"
        BFFVALIDATOR="sh $BUILDDIR/bin/bffvalidator.sh"
        AC_SUBST(BFFVALIDATOR_EXE)
        AC_MSG_RESULT($BFFVALIDATOR)
    else
        AC_MSG_ERROR([bffvalidator not found, but required by --with-bffvalidator])
    fi
    AC_SUBST(BFFVALIDATOR)
else
    AC_MSG_RESULT([no])
fi

dnl ===================================================================
dnl Check for C preprocessor to use
dnl ===================================================================
AC_MSG_CHECKING([which C preprocessor to use in idlc])
if test -n "$with_idlc_cpp"; then
    AC_MSG_RESULT([$with_idlc_cpp])
    AC_PATH_PROG(SYSTEM_UCPP, $with_idlc_cpp)
else
    AC_MSG_RESULT([ucpp])
    AC_MSG_CHECKING([which ucpp tp use])
    if test -n "$with_system_ucpp" -a "$with_system_ucpp" != "no"; then
        AC_MSG_RESULT([external])
        AC_PATH_PROG(SYSTEM_UCPP, ucpp)
    else
        AC_MSG_RESULT([internal])
        BUILD_TYPE="$BUILD_TYPE UCPP"
    fi
fi
AC_SUBST(SYSTEM_UCPP)

dnl ===================================================================
dnl Check for epm (not needed for Windows)
dnl ===================================================================
AC_MSG_CHECKING([whether to enable EPM for packing])
if test "$enable_epm" = "yes"; then
    AC_MSG_RESULT([yes])
    if test "$_os" != "WINNT"; then
        if test $_os = Darwin; then
            EPM=internal
        elif test -n "$with_epm"; then
            EPM=$with_epm
        else
            AC_PATH_PROG(EPM, epm, no)
        fi
        if test "$EPM" = "no" -o "$EPM" = "internal"; then
            AC_MSG_NOTICE([EPM will be built.])
            BUILD_TYPE="$BUILD_TYPE EPM"
            EPM=${WORKDIR}/UnpackedTarball/epm/epm
        else
            # Gentoo has some epm which is something different...
            AC_MSG_CHECKING([whether the found epm is the right epm])
            if $EPM | grep "ESP Package Manager" >/dev/null 2>/dev/null; then
                AC_MSG_RESULT([yes])
            else
                AC_MSG_ERROR([no. Install ESP Package Manager (http://www.msweet.org/projects.php?Z2) and/or specify the path to the right epm])
            fi
            AC_MSG_CHECKING([epm version])
            EPM_VERSION=`$EPM | grep 'ESP Package Manager' | cut -d' ' -f4 | $SED -e s/v//`
            if test "`echo $EPM_VERSION | cut -d'.' -f1`" -gt "3" || \
               test "`echo $EPM_VERSION | cut -d'.' -f1`" -eq "3" -a "`echo $EPM_VERSION | cut -d'.' -f2`" -ge "7"; then
                AC_MSG_RESULT([OK, >= 3.7])
            else
                AC_MSG_RESULT([too old. epm >= 3.7 is required.])
                AC_MSG_ERROR([Install ESP Package Manager (http://www.msweet.org/projects.php?Z2) and/or specify the path to the right epm])
            fi
        fi
    fi

    if echo "$PKGFORMAT" | $EGREP rpm 2>&1 >/dev/null; then
        AC_MSG_CHECKING([for rpm])
        for a in "$RPM" rpmbuild rpm; do
            $a --usage >/dev/null 2> /dev/null
            if test $? -eq 0; then
                RPM=$a
                break
            else
                $a --version >/dev/null 2> /dev/null
                if test $? -eq 0; then
                    RPM=$a
                    break
                fi
            fi
        done
        if test -z "$RPM"; then
            AC_MSG_ERROR([not found])
        elif "$RPM" --help 2>&1 | $EGREP buildroot >/dev/null; then
            RPM_PATH=`which $RPM`
            AC_MSG_RESULT([$RPM_PATH])
            SCPDEFS="$SCPDEFS -DWITH_RPM"
        else
            AC_MSG_ERROR([cannot build packages. Try installing rpmbuild.])
        fi
    fi
    if echo "$PKGFORMAT" | $EGREP deb 2>&1 >/dev/null; then
        AC_PATH_PROG(DPKG, dpkg, no)
        if test "$DPKG" = "no"; then
            AC_MSG_ERROR([dpkg needed for deb creation. Install dpkg.])
        fi
    fi
    if echo "$PKGFORMAT" | $EGREP rpm 2>&1 >/dev/null || \
       echo "$PKGFORMAT" | $EGREP pkg 2>&1 >/dev/null; then
        if test "$with_epm" = "no" -a "$_os" != "Darwin"; then
            if test "`echo $EPM_VERSION | cut -d'.' -f1`" -lt "4"; then
                AC_MSG_CHECKING([whether epm is patched for LibreOffice's needs])
                if grep "Patched for LibreOffice" $EPM >/dev/null 2>/dev/null; then
                    AC_MSG_RESULT([yes])
                else
                    AC_MSG_RESULT([no])
                    if echo "$PKGFORMAT" | $GREP -q rpm; then
                        _pt="rpm"
                        AC_MSG_WARN([the rpms will need to be installed with --nodeps])
                        add_warning "the rpms will need to be installed with --nodeps"
                    else
                        _pt="pkg"
                    fi
                    AC_MSG_WARN([the ${_pt}s will not be relocateable])
                    add_warning "the ${_pt}s will not be relocateable"
                    AC_MSG_WARN([if you want to make sure installation without --nodeps and
                                 relocation will work, you need to patch your epm with the
                                 patch in epm/epm-3.7.patch or build with
                                 --with-epm=internal which will build a suitable epm])
                fi
            fi
        fi
    fi
    if echo "$PKGFORMAT" | $EGREP pkg 2>&1 >/dev/null; then
        AC_PATH_PROG(PKGMK, pkgmk, no)
        if test "$PKGMK" = "no"; then
            AC_MSG_ERROR([pkgmk needed for Solaris pkg creation. Install it.])
        fi
    fi
    AC_SUBST(RPM)
    AC_SUBST(DPKG)
    AC_SUBST(PKGMK)
else
    for i in $PKGFORMAT; do
        case "$i" in
        aix | bsd | deb | pkg | rpm | native | portable)
            AC_MSG_ERROR(
                [--with-package-format='$PKGFORMAT' requires --enable-epm])
            ;;
        esac
    done
    AC_MSG_RESULT([no])
    EPM=NO
fi
AC_SUBST(EPM)

ENABLE_LWP=
if test "$enable_lotuswordpro" = "yes"; then
    ENABLE_LWP="TRUE"
fi
AC_SUBST(ENABLE_LWP)

dnl ===================================================================
dnl Check for gperf
dnl ===================================================================
AC_PATH_PROG(GPERF, gperf)
if test -z "$GPERF"; then
    AC_MSG_ERROR([gperf not found but needed. Install it.])
fi
if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
    GPERF=`cygpath -m $GPERF`
fi
AC_MSG_CHECKING([gperf version])
if test "`$GPERF --version | $EGREP ^GNU\ gperf | $AWK '{ print $3 }' | cut -d. -f1`" -ge "3"; then
    AC_MSG_RESULT([OK])
else
    AC_MSG_ERROR([too old, you need at least 3.0.0])
fi
AC_SUBST(GPERF)

dnl ===================================================================
dnl Check for building ODK
dnl ===================================================================
if test "$enable_odk" = no; then
    unset DOXYGEN
else
    if test "$with_doxygen" = no; then
        AC_MSG_CHECKING([for doxygen])
        unset DOXYGEN
        AC_MSG_RESULT([no])
    else
        if test "$with_doxygen" = yes; then
            AC_PATH_PROG([DOXYGEN], [doxygen])
            if test -z "$DOXYGEN"; then
                AC_MSG_ERROR([doxygen not found in \$PATH; specify its pathname via --with-doxygen=..., or disable its use via --without-doxygen])
            fi
        else
            AC_MSG_CHECKING([for doxygen])
            DOXYGEN=$with_doxygen
            AC_MSG_RESULT([$DOXYGEN])
        fi
        if test -n "$DOXYGEN"; then
            DOXYGEN_VERSION=`$DOXYGEN --version 2>/dev/null`
            DOXYGEN_NUMVERSION=`echo $DOXYGEN_VERSION | $AWK -F. '{ print \$1*10000 + \$2*100 + \$3 }'`
            if ! test "$DOXYGEN_NUMVERSION" -ge "10804" ; then
                AC_MSG_ERROR([found doxygen is too old; need at least version 1.8.4 or specify --without-doxygen])
            fi
        fi
    fi
fi
AC_SUBST([DOXYGEN])

AC_MSG_CHECKING([whether to build the ODK])
if test "$enable_odk" = "" -o "$enable_odk" != "no"; then
    AC_MSG_RESULT([yes])

    if test "$with_java" != "no"; then
        AC_MSG_CHECKING([whether to build unowinreg.dll])
        if test "$_os" = "WINNT" -a "$enable_build_unowinreg" = ""; then
            # build on Win by default
            enable_build_unowinreg=yes
        fi
        if test "$enable_build_unowinreg" = "" -o "$enable_build_unowinreg" = "no"; then
            AC_MSG_RESULT([no])
            BUILD_UNOWINREG=
        else
            AC_MSG_RESULT([yes])
            BUILD_UNOWINREG=TRUE
        fi
        if test "$_os" != "WINNT" -a "$BUILD_UNOWINREG" = "TRUE"; then
            if test -z "$with_mingw_cross_compiler"; then
                dnl Guess...
                AC_CHECK_PROGS(MINGWCXX,i386-mingw32msvc-g++ i586-pc-mingw32-g++ i686-pc-mingw32-g++ i686-w64-mingw32-g++,false)
            elif test -x "$with_mingw_cross_compiler"; then
                 MINGWCXX="$with_mingw_cross_compiler"
            else
                AC_CHECK_TOOL(MINGWCXX, "$with_mingw_cross_compiler", false)
            fi

            if test "$MINGWCXX" = "false"; then
                AC_MSG_ERROR([MinGW32 C++ cross-compiler not found.])
            fi

            mingwstrip_test="`echo $MINGWCXX | $SED -e s/g++/strip/`"
            if test -x "$mingwstrip_test"; then
                MINGWSTRIP="$mingwstrip_test"
            else
                AC_CHECK_TOOL(MINGWSTRIP, "$mingwstrip_test", false)
            fi

            if test "$MINGWSTRIP" = "false"; then
                AC_MSG_ERROR(MinGW32 binutils not found.)
            fi
        fi
    fi
    BUILD_TYPE="$BUILD_TYPE ODK"
else
    AC_MSG_RESULT([no])
    BUILD_UNOWINREG=
fi
AC_SUBST(BUILD_UNOWINREG)
AC_SUBST(MINGWCXX)
AC_SUBST(MINGWSTRIP)

dnl ===================================================================
dnl Check for system zlib
dnl ===================================================================
if test "$with_system_zlib" = "auto"; then
    case "$_os" in
    WINNT)
        with_system_zlib="$with_system_libs"
        ;;
    *)
        if test "$enable_fuzzers" != "yes"; then
            with_system_zlib=yes
        else
            with_system_zlib=no
        fi
        ;;
    esac
fi

dnl we want to use libo_CHECK_SYSTEM_MODULE here too, but OS X is too stupid
dnl and has no pkg-config for it at least on some tinderboxes,
dnl so leaving that out for now
dnl libo_CHECK_SYSTEM_MODULE([zlib],[ZLIB],[zlib])
AC_MSG_CHECKING([which zlib to use])
if test "$with_system_zlib" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_ZLIB=TRUE
    AC_CHECK_HEADER(zlib.h, [],
        [AC_MSG_ERROR(zlib.h not found. install zlib)], [])
    AC_CHECK_LIB(z, deflate, [ ZLIB_LIBS=-lz ],
        [AC_MSG_ERROR(zlib not found or functional)], [])
else
    AC_MSG_RESULT([internal])
    SYSTEM_ZLIB=
    BUILD_TYPE="$BUILD_TYPE ZLIB"
    ZLIB_CFLAGS="-I${WORKDIR}/UnpackedTarball/zlib"
    ZLIB_LIBS="-L${WORKDIR}/LinkTarget/StaticLibrary -lzlib"
fi
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_LIBS)
AC_SUBST(SYSTEM_ZLIB)

dnl ===================================================================
dnl Check for system jpeg
dnl ===================================================================
AC_MSG_CHECKING([which libjpeg to use])
if test "$with_system_jpeg" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_LIBJPEG=TRUE
    AC_CHECK_HEADER(jpeglib.h, [ LIBJPEG_CFLAGS= ],
        [AC_MSG_ERROR(jpeg.h not found. install libjpeg)], [])
    AC_CHECK_LIB(jpeg, jpeg_resync_to_restart, [ LIBJPEG_LIBS="-ljpeg" ],
        [AC_MSG_ERROR(jpeg library not found or fuctional)], [])
else
    SYSTEM_LIBJPEG=
    AC_MSG_RESULT([internal, libjpeg-turbo])
    BUILD_TYPE="$BUILD_TYPE LIBJPEG_TURBO"
    LIBJPEG_CFLAGS="-I${WORKDIR}/UnpackedTarball/libjpeg-turbo"
    if test "$COM" = "MSC"; then
        LIBJPEG_LIBS="${WORKDIR}/UnpackedTarball/libjpeg-turbo/.libs/libjpeg.lib"
    else
        LIBJPEG_LIBS="-L${WORKDIR}/UnpackedTarball/libjpeg-turbo/.libs -ljpeg"
    fi

    case "$host_cpu" in
    x86_64 | amd64 | i*86 | x86 | ia32)
        AC_CHECK_PROGS(NASM, [nasm nasmw yasm])
        if test -z "$NASM" -a "$build_os" = "cygwin"; then
            if test -n "$LODE_HOME" -a -x "$LODE_HOME/opt/bin/nasm"; then
                NASM="$LODE_HOME/opt/bin/nasm"
            elif test -x "/opt/lo/bin/nasm"; then
                NASM="/opt/lo/bin/nasm"
            fi
        fi

        if test -n "$NASM"; then
            AC_MSG_CHECKING([for object file format of host system])
            case "$host_os" in
              cygwin* | mingw* | pw32* | interix*)
                case "$host_cpu" in
                  x86_64)
                    objfmt='Win64-COFF'
                    ;;
                  *)
                    objfmt='Win32-COFF'
                    ;;
                esac
              ;;
              msdosdjgpp* | go32*)
                objfmt='COFF'
              ;;
              os2-emx*)			# not tested
                objfmt='MSOMF'		# obj
              ;;
              linux*coff* | linux*oldld*)
                objfmt='COFF'		# ???
              ;;
              linux*aout*)
                objfmt='a.out'
              ;;
              linux*)
                case "$host_cpu" in
                  x86_64)
                    objfmt='ELF64'
                    ;;
                  *)
                    objfmt='ELF'
                    ;;
                esac
              ;;
              kfreebsd* | freebsd* | netbsd* | openbsd*)
                if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
                  objfmt='BSD-a.out'
                else
                  case "$host_cpu" in
                    x86_64 | amd64)
                      objfmt='ELF64'
                      ;;
                    *)
                      objfmt='ELF'
                      ;;
                  esac
                fi
              ;;
              solaris* | sunos* | sysv* | sco*)
                case "$host_cpu" in
                  x86_64)
                    objfmt='ELF64'
                    ;;
                  *)
                    objfmt='ELF'
                    ;;
                esac
              ;;
              darwin* | rhapsody* | nextstep* | openstep* | macos*)
                case "$host_cpu" in
                  x86_64)
                    objfmt='Mach-O64'
                    ;;
                  *)
                    objfmt='Mach-O'
                    ;;
                esac
              ;;
              *)
                objfmt='ELF ?'
              ;;
            esac

            AC_MSG_RESULT([$objfmt])
            if test "$objfmt" = 'ELF ?'; then
              objfmt='ELF'
              AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
            fi

            AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
            case "$objfmt" in
              MSOMF)      NAFLAGS='-fobj -DOBJ32';;
              Win32-COFF) NAFLAGS='-fwin32 -DWIN32';;
              Win64-COFF) NAFLAGS='-fwin64 -DWIN64 -D__x86_64__';;
              COFF)       NAFLAGS='-fcoff -DCOFF';;
              a.out)      NAFLAGS='-faout -DAOUT';;
              BSD-a.out)  NAFLAGS='-faoutb -DAOUT';;
              ELF)        NAFLAGS='-felf -DELF';;
              ELF64)      NAFLAGS='-felf64 -DELF -D__x86_64__';;
              RDF)        NAFLAGS='-frdf -DRDF';;
              Mach-O)     NAFLAGS='-fmacho -DMACHO';;
              Mach-O64)   NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';;
            esac
            AC_MSG_RESULT([$NAFLAGS])

            AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works])
            cat > conftest.asm << EOF
            [%line __oline__ "configure"
                    section .text
                    global  _main,main
            _main:
            main:   xor     eax,eax
                    ret
            ]
EOF
            try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm'
            if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then
              AC_MSG_RESULT(yes)
            else
              echo "configure: failed program was:" >&AC_FD_CC
              cat conftest.asm >&AC_FD_CC
              rm -rf conftest*
              AC_MSG_RESULT(no)
              AC_MSG_WARN([installation or configuration problem: assembler cannot create object files.])
              NASM=""
            fi

        fi

        if test -z "$NASM"; then
cat << _EOS
****************************************************************************
You need yasm or nasm (Netwide Assembler) to build the internal jpeg library optimally.
To get one please:

_EOS
            if test "$build_os" = "cygwin"; then
cat << _EOS
install a pre-compiled binary for Win32

mkdir -p /opt/lo/bin
cd /opt/lo/bin
wget https://dev-www.libreoffice.org/bin/cygwin/nasm.exe
chmod +x nasm

or get and install one from http://www.nasm.us/

Then re-run autogen.sh

Note: autogen.sh will try to use /opt/lo/bin/nasm if the environment variable NASM is not already defined.
Alternatively, you can install the 'new' nasm where ever you want and make sure that \`which nasm\` finds it.

_EOS
            else
cat << _EOS
consult https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/BUILDING.md

_EOS
            fi
            AC_MSG_WARN([no suitable nasm (Netwide Assembler) found])
            add_warning "no suitable nasm (Netwide Assembler) found for internal libjpeg-turbo"
        fi
      ;;
    esac
fi

AC_SUBST(NASM)
AC_SUBST(LIBJPEG_CFLAGS)
AC_SUBST(LIBJPEG_LIBS)
AC_SUBST(SYSTEM_LIBJPEG)

dnl ===================================================================
dnl Check for system clucene
dnl ===================================================================
dnl we should rather be using
dnl libo_CHECK_SYSTEM_MODULE([clucence],[CLUCENE],[liblucence-core]) here
dnl but the contribs-lib check seems tricky
AC_MSG_CHECKING([which clucene to use])
if test "$with_system_clucene" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_CLUCENE=TRUE
    PKG_CHECK_MODULES(CLUCENE, libclucene-core)
    CLUCENE_CFLAGS=[$(printf '%s' "$CLUCENE_CFLAGS" | sed -e 's@-I[^ ]*/CLucene/ext@@' -e "s/-I/${ISYSTEM?}/g")]
    FilterLibs "${CLUCENE_LIBS}"
    CLUCENE_LIBS="${filteredlibs}"
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    save_CPPFLAGS=$CPPFLAGS
    CXXFLAGS="$CXXFLAGS $CLUCENE_CFLAGS"
    CPPFLAGS="$CPPFLAGS $CLUCENE_CFLAGS"
    dnl http://sourceforge.net/tracker/index.php?func=detail&aid=3392466&group_id=80013&atid=558446
    dnl https://bugzilla.redhat.com/show_bug.cgi?id=794795
    AC_CHECK_HEADER([CLucene/analysis/cjk/CJKAnalyzer.h], [],
                 [AC_MSG_ERROR([Your version of libclucene has contribs-lib missing.])], [#include <CLucene.h>])
    CXXFLAGS=$save_CXXFLAGS
    CPPFLAGS=$save_CPPFLAGS
    AC_LANG_POP([C++])

    CLUCENE_LIBS="$CLUCENE_LIBS -lclucene-contribs-lib"
else
    AC_MSG_RESULT([internal])
    SYSTEM_CLUCENE=
    BUILD_TYPE="$BUILD_TYPE CLUCENE"
fi
AC_SUBST(SYSTEM_CLUCENE)
AC_SUBST(CLUCENE_CFLAGS)
AC_SUBST(CLUCENE_LIBS)

dnl ===================================================================
dnl Check for system expat
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([expat], [EXPAT], [expat])

dnl ===================================================================
dnl Check for system xmlsec
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([xmlsec], [XMLSEC], [xmlsec1-nss >= 1.2.24])

AC_MSG_CHECKING([whether to enable Embedded OpenType support])
if test "$_os" != "WINNT" -a "$_os" != "Darwin" -a "$enable_eot" = "yes"; then
    ENABLE_EOT="TRUE"
    AC_DEFINE([ENABLE_EOT])
    AC_MSG_RESULT([yes])

    libo_CHECK_SYSTEM_MODULE([libeot],[LIBEOT],[libeot >= 0.01])
else
    ENABLE_EOT=
    AC_MSG_RESULT([no])
fi
AC_SUBST([ENABLE_EOT])

dnl ===================================================================
dnl Check for DLP libs
dnl ===================================================================
AS_IF([test "$COM" = "MSC"],
      [librevenge_libdir="${WORKDIR}/LinkTarget/Library"],
      [librevenge_libdir="${WORKDIR}/UnpackedTarball/librevenge/src/lib/.libs"]
)
libo_CHECK_SYSTEM_MODULE([librevenge],[REVENGE],[librevenge-0.0 >= 0.0.1],["-I${WORKDIR}/UnpackedTarball/librevenge/inc"],["-L${librevenge_libdir} -lrevenge-0.0"])

libo_CHECK_SYSTEM_MODULE([libodfgen],[ODFGEN],[libodfgen-0.1])

libo_CHECK_SYSTEM_MODULE([libepubgen],[EPUBGEN],[libepubgen-0.1])

AS_IF([test "$COM" = "MSC"],
      [libwpd_libdir="${WORKDIR}/LinkTarget/Library"],
      [libwpd_libdir="${WORKDIR}/UnpackedTarball/libwpd/src/lib/.libs"]
)
libo_CHECK_SYSTEM_MODULE([libwpd],[WPD],[libwpd-0.10],["-I${WORKDIR}/UnpackedTarball/libwpd/inc"],["-L${libwpd_libdir} -lwpd-0.10"])

libo_CHECK_SYSTEM_MODULE([libwpg],[WPG],[libwpg-0.3])

libo_CHECK_SYSTEM_MODULE([libwps],[WPS],[libwps-0.4])
libo_PKG_VERSION([WPS], [libwps-0.4], [0.4.8])

libo_CHECK_SYSTEM_MODULE([libvisio],[VISIO],[libvisio-0.1])

libo_CHECK_SYSTEM_MODULE([libcdr],[CDR],[libcdr-0.1])

libo_CHECK_SYSTEM_MODULE([libmspub],[MSPUB],[libmspub-0.1])

libo_CHECK_SYSTEM_MODULE([libmwaw],[MWAW],[libmwaw-0.3 >= 0.3.1])
libo_PKG_VERSION([MWAW], [libmwaw-0.3], [0.3.13])

libo_CHECK_SYSTEM_MODULE([libetonyek],[ETONYEK],[libetonyek-0.1])
libo_PKG_VERSION([ETONYEK], [libetonyek-0.1], [0.1.7])

libo_CHECK_SYSTEM_MODULE([libfreehand],[FREEHAND],[libfreehand-0.1])

libo_CHECK_SYSTEM_MODULE([libebook],[EBOOK],[libe-book-0.1])
libo_PKG_VERSION([EBOOK], [libe-book-0.1], [0.1.2])

libo_CHECK_SYSTEM_MODULE([libabw],[ABW],[libabw-0.1])

libo_CHECK_SYSTEM_MODULE([libpagemaker],[PAGEMAKER],[libpagemaker-0.0])

libo_CHECK_SYSTEM_MODULE([libqxp],[QXP],[libqxp-0.0])

libo_CHECK_SYSTEM_MODULE([libzmf],[ZMF],[libzmf-0.0])

libo_CHECK_SYSTEM_MODULE([libstaroffice],[STAROFFICE],[libstaroffice-0.0])
libo_PKG_VERSION([STAROFFICE], [libstaroffice-0.0], [0.0.4])

dnl ===================================================================
dnl Check for system libcmis
dnl ===================================================================
# libcmis requires curl and we can't build curl for iOS
if test $_os != iOS; then
    libo_CHECK_SYSTEM_MODULE([libcmis],[LIBCMIS],[libcmis-0.5 >= 0.5.0])
    ENABLE_LIBCMIS=TRUE
else
    ENABLE_LIBCMIS=
fi
AC_SUBST(ENABLE_LIBCMIS)

dnl ===================================================================
dnl Check for system lcms2
dnl ===================================================================
if test "$with_system_lcms2" != "yes"; then
    SYSTEM_LCMS2=
fi
libo_CHECK_SYSTEM_MODULE([lcms2],[LCMS2],[lcms2],["-I${WORKDIR}/UnpackedTarball/lcms2/include"],["-L${WORKDIR}/UnpackedTarball/lcms2/src/.libs -llcms2"])
if test "$GCC" = "yes"; then
    LCMS2_CFLAGS="${LCMS2_CFLAGS} -Wno-long-long"
fi
if test "$COM" = "MSC"; then # override the above
    LCMS2_LIBS=${WORKDIR}/UnpackedTarball/lcms2/bin/lcms2.lib
fi

dnl ===================================================================
dnl Check for system cppunit
dnl ===================================================================
if test "$cross_compiling" != "yes"; then
    libo_CHECK_SYSTEM_MODULE([cppunit],[CPPUNIT],[cppunit >= 1.14.0])
fi

dnl ===================================================================
dnl Check whether freetype is available
dnl ===================================================================
if test  "$test_freetype" = "yes"; then
    AC_MSG_CHECKING([whether freetype is available])
    # FreeType has 3 different kinds of versions
    # * release, like 2.4.10
    # * libtool, like 13.0.7 (this what pkg-config returns)
    # * soname
    # FreeType's docs/VERSION.DLL provides a table mapping between the three
    #
    # 9.9.3 is 2.2.0
    PKG_CHECK_MODULES(FREETYPE, freetype2 >= 9.9.3)
    FREETYPE_CFLAGS=$(printf '%s' "$FREETYPE_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${FREETYPE_LIBS}"
    FREETYPE_LIBS="${filteredlibs}"
    SYSTEM_FREETYPE=TRUE
else
    FREETYPE_CFLAGS="${ISYSTEM}${WORKDIR}/UnpackedTarball/freetype/include"
    FREETYPE_LIBS="-L${WORKDIR}/UnpackedTarball/freetype/instdir/lib -lfreetype"
fi
AC_SUBST(FREETYPE_CFLAGS)
AC_SUBST(FREETYPE_LIBS)
AC_SUBST([SYSTEM_FREETYPE])

# ===================================================================
# Check for system libxslt
# to prevent incompatibilities between internal libxml2 and external libxslt,
# or vice versa, use with_system_libxml here
# ===================================================================
if test "$with_system_libxml" = "auto"; then
    case "$_os" in
    WINNT|iOS|Android)
        with_system_libxml="$with_system_libs"
        ;;
    *)
        if test "$enable_fuzzers" != "yes"; then
            with_system_libxml=yes
        else
            with_system_libxml=no
        fi
        ;;
    esac
fi

AC_MSG_CHECKING([which libxslt to use])
if test "$with_system_libxml" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_LIBXSLT=TRUE
    if test "$_os" = "Darwin"; then
        dnl make sure to use SDK path
        LIBXSLT_CFLAGS="-I$MACOSX_SDK_PATH/usr/include/libxml2"
        LIBEXSLT_CFLAGS="$LIBXSLT_CFLAGS"
        dnl omit -L/usr/lib
        LIBXSLT_LIBS="-lxslt -lxml2 -lz -lpthread -liconv -lm"
        LIBEXSLT_LIBS="-lexslt $LIBXSLT_LIBS"
    else
        PKG_CHECK_MODULES(LIBXSLT, libxslt)
        LIBXSLT_CFLAGS=$(printf '%s' "$LIBXSLT_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${LIBXSLT_LIBS}"
        LIBXSLT_LIBS="${filteredlibs}"
        PKG_CHECK_MODULES(LIBEXSLT, libexslt)
        LIBEXSLT_CFLAGS=$(printf '%s' "$LIBEXSLT_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${LIBEXSLT_LIBS}"
        LIBEXSLT_LIBS=$(printf '%s' "${filteredlibs}" | sed -e "s/-lgpg-error//"  -e "s/-lgcrypt//")
    fi

    dnl Check for xsltproc
    AC_PATH_PROG(XSLTPROC, xsltproc, no)
    if test "$XSLTPROC" = "no"; then
        AC_MSG_ERROR([xsltproc is required])
    fi
else
    AC_MSG_RESULT([internal])
    SYSTEM_LIBXSLT=
    BUILD_TYPE="$BUILD_TYPE LIBXSLT"

    if test "$cross_compiling" = "yes"; then
        AC_PATH_PROG(XSLTPROC, xsltproc, no)
        if test "$XSLTPROC" = "no"; then
            AC_MSG_ERROR([xsltproc is required])
        fi
    fi
fi
AC_SUBST(SYSTEM_LIBXSLT)
if test -z "$SYSTEM_LIBXSLT_FOR_BUILD"; then
    SYSTEM_LIBXSLT_FOR_BUILD="$SYSTEM_LIBXSLT"
fi
AC_SUBST(SYSTEM_LIBXSLT_FOR_BUILD)

AC_SUBST(LIBEXSLT_CFLAGS)
AC_SUBST(LIBEXSLT_LIBS)
AC_SUBST(LIBXSLT_CFLAGS)
AC_SUBST(LIBXSLT_LIBS)
AC_SUBST(XSLTPROC)

# ===================================================================
# Check for system libxml
# ===================================================================
AC_MSG_CHECKING([which libxml to use])
if test "$with_system_libxml" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_LIBXML=TRUE
    if test "$_os" = "Darwin"; then
        dnl make sure to use SDK path
        LIBXML_CFLAGS="-I$MACOSX_SDK_PATH/usr/include/libxml2"
        dnl omit -L/usr/lib
        LIBXML_LIBS="-lxml2 -lz -lpthread -liconv -lm"
    elif test $_os = iOS; then
        dnl make sure to use SDK path
        usr=`echo '#include <stdlib.h>' | $CC -E -MD - | grep usr/include/stdlib.h | head -1 | sed -e 's,# 1 ",,' -e 's,/usr/include/.*,/usr,'`
        LIBXML_CFLAGS="-I$usr/include/libxml2"
        LIBXML_LIBS="-L$usr/lib -lxml2 -liconv"
    else
        PKG_CHECK_MODULES(LIBXML, libxml-2.0 >= 2.0)
        LIBXML_CFLAGS=$(printf '%s' "$LIBXML_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${LIBXML_LIBS}"
        LIBXML_LIBS="${filteredlibs}"
    fi

    dnl Check for xmllint
    AC_PATH_PROG(XMLLINT, xmllint, no)
    if test "$XMLLINT" = "no"; then
        AC_MSG_ERROR([xmllint is required])
    fi
else
    AC_MSG_RESULT([internal])
    SYSTEM_LIBXML=
    LIBXML_CFLAGS="-I${WORKDIR}/UnpackedTarball/libxml2/include"
    if test "$COM" = "MSC"; then
        LIBXML_CFLAGS="${LIBXML_CFLAGS} -I${WORKDIR}/UnpackedTarball/icu/source/i18n -I${WORKDIR}/UnpackedTarball/icu/source/common"
    fi
    if test "$COM" = "MSC"; then
        LIBXML_LIBS="${WORKDIR}/UnpackedTarball/libxml2/win32/bin.msvc/libxml2.lib"
    else
        LIBXML_LIBS="-L${WORKDIR}/UnpackedTarball/libxml2/.libs -lxml2"
    fi
    BUILD_TYPE="$BUILD_TYPE LIBXML2"
fi
AC_SUBST(SYSTEM_LIBXML)
if test -z "$SYSTEM_LIBXML_FOR_BUILD"; then
    SYSTEM_LIBXML_FOR_BUILD="$SYSTEM_LIBXML"
fi
AC_SUBST(SYSTEM_LIBXML_FOR_BUILD)
AC_SUBST(LIBXML_CFLAGS)
AC_SUBST(LIBXML_LIBS)
AC_SUBST(XMLLINT)

# =====================================================================
# Checking for a Python interpreter with version >= 2.6.
# Build and runtime requires Python 3 compatible version (>= 2.6).
# Optionally user can pass an option to configure, i. e.
# ./configure PYTHON=/usr/bin/python
# =====================================================================
if test "$build_os" != "cygwin" -a "$enable_python" != fully-internal; then
    # This allows a lack of system python with no error, we use internal one in that case.
    AM_PATH_PYTHON([2.6],, [:])
    # Clean PYTHON_VERSION checked below if cross-compiling
    PYTHON_VERSION=""
    if test "$PYTHON" != ":"; then
        PYTHON_FOR_BUILD=$PYTHON
    fi
fi
AC_SUBST(PYTHON_FOR_BUILD)

# Checks for Python to use for Pyuno
AC_MSG_CHECKING([which Python to use for Pyuno])
case "$enable_python" in
no|disable)
    if test -z $PYTHON_FOR_BUILD; then
        # Python is required to build LibreOffice. In theory we could separate the build-time Python
        # requirement from the choice whether to include Python stuff in the installer, but why
        # bother?
        AC_MSG_ERROR([Python is required at build time.])
    fi
    enable_python=no
    AC_MSG_RESULT([none])
    ;;
""|yes|auto)
    if test "$DISABLE_SCRIPTING" = TRUE -a -n "$PYTHON_FOR_BUILD"; then
        AC_MSG_RESULT([no, overridden by --disable-scripting])
        enable_python=no
    elif test $build_os = cygwin; then
        dnl When building on Windows we don't attempt to use any installed
        dnl "system"  Python.
        AC_MSG_RESULT([fully internal])
        enable_python=internal
    elif test "$cross_compiling" = yes; then
        AC_MSG_RESULT([system])
        enable_python=system
    else
        # Unset variables set by the above AM_PATH_PYTHON so that
        # we actually do check anew.
        unset PYTHON am_cv_pathless_PYTHON ac_cv_path_PYTHON am_cv_python_version am_cv_python_platform am_cv_python_pythondir am_cv_python_pyexecdir
        AM_PATH_PYTHON([3.3],, [:])
        if test "$PYTHON" = ":"; then
            if test -z "$PYTHON_FOR_BUILD"; then
                AC_MSG_RESULT([fully internal])
            else
                AC_MSG_RESULT([internal])
            fi
            enable_python=internal
        else
            AC_MSG_RESULT([system])
            enable_python=system
        fi
    fi
    ;;
internal)
    AC_MSG_RESULT([internal])
    ;;
fully-internal)
    AC_MSG_RESULT([fully internal])
    enable_python=internal
    ;;
system)
    AC_MSG_RESULT([system])
    ;;
*)
    AC_MSG_ERROR([Incorrect --enable-python option])
    ;;
esac

if test $enable_python != no; then
    BUILD_TYPE="$BUILD_TYPE PYUNO"
fi

if test $enable_python = system; then
    if test -z "$PYTHON_CFLAGS" -a $_os = Darwin; then
        python_version=2.7
        PYTHON=python$python_version
        if test -d "$FRAMEWORKSHOME/Python.framework/Versions/${python_version}/include/python${python_version}"; then
            PYTHON_CFLAGS="-I$FRAMEWORKSHOME/Python.framework/Versions/${python_version}/include/python${python_version}"
            PYTHON_LIBS="-framework Python"
        else
            PYTHON_CFLAGS="`$PYTHON-config --includes`"
            PYTHON_LIBS="`$PYTHON-config --libs`"
        fi
    fi
    if test -n "$PYTHON_CFLAGS" -a -n "$PYTHON_LIBS"; then
        # Fallback: Accept these in the environment, or as set above
        # for MacOSX.
        :
    elif test "$cross_compiling" != yes; then
        # Unset variables set by the above AM_PATH_PYTHON so that
        # we actually do check anew.
        unset PYTHON am_cv_pathless_PYTHON ac_cv_path_PYTHON am_cv_python_version am_cv_python_platform am_cv_python_pythondir am_cv_python_pyexecdir
        # This causes an error if no python command is found
        AM_PATH_PYTHON([3.3])
        python_include=`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('INCLUDEPY'));"`
        python_version=`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('VERSION'));"`
        python_libs=`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('LIBS'));"`
        python_libdir=`$PYTHON -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('LIBDIR'));"`
        if test -z "$PKG_CONFIG"; then
            PYTHON_CFLAGS="-I$python_include"
            PYTHON_LIBS="-L$python_libdir -lpython$python_version $python_libs"
        elif $PKG_CONFIG --exists python-$python_version; then
            PYTHON_CFLAGS="`$PKG_CONFIG --cflags python-$python_version`"
            PYTHON_LIBS="`$PKG_CONFIG --libs python-$python_version` $python_libs"
        else
            PYTHON_CFLAGS="-I$python_include"
            PYTHON_LIBS="-L$python_libdir -lpython$python_version $python_libs"
        fi
        FilterLibs "${PYTHON_LIBS}"
        PYTHON_LIBS="${filteredlibs}"
    else
        dnl How to find out the cross-compilation Python installation path?
        AC_MSG_CHECKING([for python version])
        AS_IF([test -n "$PYTHON_VERSION"],
              [AC_MSG_RESULT([$PYTHON_VERSION])],
              [AC_MSG_RESULT([not found])
               AC_MSG_ERROR([no usable python found])])
        test -n "$PYTHON_CFLAGS" && break
    fi
    # let the PYTHON_FOR_BUILD match the same python installation that
    # provides PYTHON_CFLAGS/PYTHON_LDFLAGS for pyuno, which should be
    # better for PythonTests.
    PYTHON_FOR_BUILD=$PYTHON
fi

dnl By now enable_python should be "system", "internal" or "no"
case $enable_python in
system)
    SYSTEM_PYTHON=TRUE

    dnl Check if the headers really work
    save_CPPFLAGS="$CPPFLAGS"
    CPPFLAGS="$CPPFLAGS $PYTHON_CFLAGS"
    AC_CHECK_HEADER(Python.h, [],
       [AC_MSG_ERROR([Python headers not found. You probably want to set both the PYTHON_CFLAGS and PYTHON_LIBS environment variables.])],
       [])
    CPPFLAGS="$save_CPPFLAGS"

    AC_LANG_PUSH(C)
    CFLAGS="$CFLAGS $PYTHON_CFLAGS"
    AC_MSG_CHECKING([for correct python library version])
       AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <Python.h>

int main(int argc, char **argv) {
   if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 6) ||
       (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 3)) return 0;
   else return 1;
}
       ]])],[AC_MSG_RESULT([ok])],[AC_MSG_ERROR([Python >= 3.3 is needed when building with Python 3, or Python >= 2.6 when building with Python 2])],[AC_MSG_RESULT([skipped; cross-compiling])])
    CFLAGS=$save_CFLAGS
    AC_LANG_POP(C)

    dnl FIXME Check if the Python library can be linked with, too?
    ;;

internal)
    SYSTEM_PYTHON=
    PYTHON_VERSION_MAJOR=3
    PYTHON_VERSION_MINOR=5
    PYTHON_VERSION=${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.5
    if ! grep -q -i python.*${PYTHON_VERSION} ${SRC_ROOT}/download.lst; then
        AC_MSG_ERROR([PYTHON_VERSION ${PYTHON_VERSION} but no matching file in download.lst])
    fi
    AC_DEFINE_UNQUOTED([PYTHON_VERSION_STRING], [L"${PYTHON_VERSION}"])
    BUILD_TYPE="$BUILD_TYPE PYTHON"
    # Embedded Python dies without Home set
    if test "$HOME" = ""; then
        export HOME=""
    fi
    # bz2 tarball and bzip2 is not standard
    if test -z "$BZIP2"; then
        AC_PATH_PROG( BZIP2, bzip2)
        if test -z "$BZIP2"; then
            AC_MSG_ERROR([the internal Python module has a .tar.bz2. You need bzip2])
        fi
    fi
    ;;
no)
    DISABLE_PYTHON=TRUE
    SYSTEM_PYTHON=
    ;;
*)
    AC_MSG_ERROR([Internal configure script error, invalid enable_python value "$enable_python"])
    ;;
esac

AC_SUBST(DISABLE_PYTHON)
AC_SUBST(SYSTEM_PYTHON)
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_LIBS)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(PYTHON_VERSION_MAJOR)
AC_SUBST(PYTHON_VERSION_MINOR)

ENABLE_MARIADBC=TRUE
if test "$_os" = "iOS" -o "$enable_mpl_subset" = "yes"; then
    ENABLE_MARIADBC=
fi
MARIADBC_MAJOR=1
MARIADBC_MINOR=0
MARIADBC_MICRO=2
BUILD_TYPE="$BUILD_TYPE MARIADBC"

AC_SUBST(ENABLE_MARIADBC)
AC_SUBST(MARIADBC_MAJOR)
AC_SUBST(MARIADBC_MINOR)
AC_SUBST(MARIADBC_MICRO)

if test "$ENABLE_MARIADBC" = "TRUE"; then
    dnl ===================================================================
    dnl Check for system MariaDB
    dnl ===================================================================
    AC_MSG_CHECKING([which MariaDB to use])
    if test "$with_system_mariadb" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_MARIADB_CONNECTOR_C=TRUE
        #AC_PATH_PROG(MARIADBCONFIG, [mariadb_config])
        if test -z "$MARIADBCONFIG"; then
            AC_PATH_PROG(MARIADBCONFIG, [mysql_config])
            if test -z "$MARIADBCONFIG"; then
                AC_MSG_ERROR([mysql_config is missing. Install MySQL client library development package.])
                #AC_MSG_ERROR([mariadb_config and mysql_config are missing. Install MariaDB or MySQL client library development package.])
            fi
        fi
        AC_MSG_CHECKING([MariaDB version])
        MARIADB_VERSION=`$MARIADBCONFIG --version`
        MARIADB_MAJOR=`$MARIADBCONFIG --version | cut -d"." -f1`
        if test "$MARIADB_MAJOR" -ge "5"; then
            AC_MSG_RESULT([OK])
        else
            AC_MSG_ERROR([too old, use 5.0.x or later])
        fi
        AC_MSG_CHECKING([for MariaDB Client library])
        MARIADB_CFLAGS=`$MARIADBCONFIG --cflags`
        if test "$COM_IS_CLANG" = TRUE; then
            MARIADB_CFLAGS=$(printf '%s' "$MARIADB_CFLAGS" | sed -e s/-fstack-protector-strong//)
        fi
        MARIADB_LIBS=`$MARIADBCONFIG --libs_r`
        dnl At least mariadb-5.5.34-3.fc20.x86_64 plus
        dnl mariadb-5.5.34-3.fc20.i686 reports 64-bit specific output even under
        dnl linux32:
        if test "$OS" = LINUX -a "$CPUNAME" = INTEL; then
            MARIADB_CFLAGS=$(printf '%s' "$MARIADB_CFLAGS" | sed -e s/-m64//)
            MARIADB_LIBS=$(printf '%s' "$MARIADB_LIBS" \
                | sed -e 's|/lib64/|/lib/|')
        fi
        FilterLibs "${MARIADB_LIBS}"
        MARIADB_LIBS="${filteredlibs}"
        AC_MSG_RESULT([includes '$MARIADB_CFLAGS', libraries '$MARIADB_LIBS'])
        AC_MSG_CHECKING([whether to bundle the MySQL/MariaDB client library])
        if test "$enable_bundle_mariadb" = "yes"; then
            AC_MSG_RESULT([yes])
            BUNDLE_MARIADB_CONNECTOR_C=TRUE
            LIBMARIADB=lib$(echo "${MARIADB_LIBS}" | sed -e 's/[[[:space:]]]\{1,\}-l\([[^[:space:]]]\{1,\}\)/\
\1\
/g' -e 's/^-l\([[^[:space:]]]\{1,\}\)[[[:space:]]]*/\
\1\
/g' | grep -E '(mysqlclient|mariadb)')
            if test "$_os" = "Darwin"; then
                LIBMARIADB=${LIBMARIADB}.dylib
            elif test "$_os" = "WINNT"; then
                LIBMARIADB=${LIBMARIADB}.dll
            else
                LIBMARIADB=${LIBMARIADB}.so
            fi
            LIBMARIADB_PATH=$($MARIADBCONFIG --variable=pkglibdir)
            AC_MSG_CHECKING([for $LIBMARIADB in $LIBMARIADB_PATH])
            if test -e "$LIBMARIADB_PATH/$LIBMARIADB"; then
                AC_MSG_RESULT([found.])
                PathFormat "$LIBMARIADB_PATH"
                LIBMARIADB_PATH="$formatted_path"
            else
                AC_MSG_ERROR([not found.])
            fi
        else
            AC_MSG_RESULT([no])
            BUNDLE_MARIADB_CONNECTOR_C=
        fi
    else
        AC_MSG_RESULT([internal])
        SYSTEM_MARIADB_CONNECTOR_C=
        MARIADB_CFLAGS="-I${WORKDIR}/UnpackedTarball/mariadb-connector-c/include"
        MARIADB_LIBS="-L${WORKDIR}/LinkTarget/StaticLibrary -lmariadb-connector-c"
        BUILD_TYPE="$BUILD_TYPE MARIADB_CONNECTOR_C"
    fi

    AC_SUBST(SYSTEM_MARIADB_CONNECTOR_C)
    AC_SUBST(MARIADB_CFLAGS)
    AC_SUBST(MARIADB_LIBS)
    AC_SUBST(LIBMARIADB)
    AC_SUBST(LIBMARIADB_PATH)
    AC_SUBST(BUNDLE_MARIADB_CONNECTOR_C)
fi

dnl ===================================================================
dnl Check for system hsqldb
dnl ===================================================================
if test "$with_java" != "no"; then
    HSQLDB_USE_JDBC_4_1=
    AC_MSG_CHECKING([which hsqldb to use])
    if test "$with_system_hsqldb" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_HSQLDB=TRUE
        if test -z $HSQLDB_JAR; then
            HSQLDB_JAR=/usr/share/java/hsqldb.jar
        fi
        if ! test -f $HSQLDB_JAR; then
               AC_MSG_ERROR(hsqldb.jar not found.)
        fi
        AC_MSG_CHECKING([whether hsqldb is 1.8.0.x])
        export HSQLDB_JAR
        if $PERL -e \
           'use Archive::Zip;
            my $file = "$ENV{'HSQLDB_JAR'}";
            my $zip = Archive::Zip->new( $file );
            my $mf = $zip->contents ( "META-INF/MANIFEST.MF" );
            if ( $mf =~ m/Specification-Version: 1.8.*/ )
            {
                push @l, split(/\n/, $mf);
                foreach my $line (@l)
                {
                    if ($line =~ m/Specification-Version:/)
                    {
                        ($t, $version) = split (/:/,$line);
                        $version =~ s/^\s//;
                        ($a, $b, $c, $d) = split (/\./,$version);
                        if ($c == "0" && $d > "8")
                        {
                            exit 0;
                        }
                        else
                        {
                            exit 1;
                        }
                    }
                }
            }
            else
            {
                exit 1;
            }'; then
            AC_MSG_RESULT([yes])
        else
            AC_MSG_ERROR([no, you need hsqldb >= 1.8.0.9 but < 1.8.1])
        fi
    else
        AC_MSG_RESULT([internal])
        SYSTEM_HSQLDB=
        BUILD_TYPE="$BUILD_TYPE HSQLDB"
        AC_MSG_CHECKING([whether hsqldb should be built with JDBC 4.1])
        javanumver=`$JAVAINTERPRETER -version 2>&1 | $AWK -v num=true -f $SRC_ROOT/solenv/bin/getcompver.awk`
        if expr "$javanumver" '>=' 000100060000 > /dev/null; then
            AC_MSG_RESULT([yes])
            HSQLDB_USE_JDBC_4_1=TRUE
        else
            AC_MSG_RESULT([no])
        fi
    fi
    AC_SUBST(SYSTEM_HSQLDB)
    AC_SUBST(HSQLDB_JAR)
    AC_SUBST([HSQLDB_USE_JDBC_4_1])
fi

dnl ===================================================================
dnl Check for PostgreSQL stuff
dnl ===================================================================
if test "x$enable_postgresql_sdbc" != "xno"; then
    SCPDEFS="$SCPDEFS -DWITH_POSTGRESQL_SDBC"

    if test "$with_krb5" = "yes" -a "$enable_openssl" = "no"; then
        AC_MSG_ERROR([krb5 needs OpenSSL, but --disable-openssl was given.])
    fi
    if test "$with_gssapi" = "yes" -a "$enable_openssl" = "no"; then
        AC_MSG_ERROR([GSSAPI needs OpenSSL, but --disable-openssl was given.])
    fi

    postgres_interface=""
    if test "$with_system_postgresql" = "yes"; then
        postgres_interface="external PostgreSQL"
        SYSTEM_POSTGRESQL=TRUE
        if test "$_os" = Darwin; then
            supp_path=''
            for d in /Library/PostgreSQL/9.*/bin /sw/opt/postgresql/9.*/bin /opt/local/lib/postgresql9*/bin; do
                pg_supp_path="$P_SEP$d$pg_supp_path"
            done
        fi
        AC_PATH_PROG(PGCONFIG, pg_config, ,$PATH$pg_supp_path)
        if test -z "$PGCONFIG"; then
            AC_MSG_ERROR([pg_config needed; set PGCONFIG if not in PATH])
        fi
        POSTGRESQL_INC=-I$(${PGCONFIG} --includedir)
        POSTGRESQL_LIB="-L$(${PGCONFIG} --libdir)"
        FilterLibs "${POSTGRESQL_LIB}"
        POSTGRESQL_LIB="${filteredlibs}"
    else
        # if/when anything else than PostgreSQL uses Kerberos,
        # move this out of `test "x$enable_postgresql_sdbc" != "xno"'
        WITH_KRB5=
        WITH_GSSAPI=
        case "$_os" in
        Darwin)
            # MacOS X has system MIT Kerberos 5 since 10.4
            if test "$with_krb5" != "no"; then
                WITH_KRB5=TRUE
                save_LIBS=$LIBS
                # Not sure whether it makes any sense here to search multiple potential libraries; it is not likely
                # that the libraries where these functions are located on macOS will change, is it?
                AC_SEARCH_LIBS(com_err, [com_err 'com_err -lssl -lcrypto' krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'com_err' required for Kerberos 5])])
                KRB5_LIBS=$LIBS
                LIBS=$save_LIBS
                AC_SEARCH_LIBS(krb5_sendauth, [krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'krb5_sendauth' required for Kerberos 5])])
                KRB5_LIBS="$KRB5_LIBS $LIBS"
                LIBS=$save_LIBS
            fi
            if test "$with_gssapi" != "no"; then
                WITH_GSSAPI=TRUE
                save_LIBS=$LIBS
                AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
                    [AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
                GSSAPI_LIBS=$LIBS
                LIBS=$save_LIBS
            fi
            ;;
        WINNT)
            if test "$with_krb5" = "yes" -o "$with_gssapi" = "yes"; then
                AC_MSG_ERROR([Refusing to enable MIT Kerberos 5 or GSSAPI on Windows.])
            fi
            ;;
        Linux|GNU|*BSD|DragonFly)
            if test "$with_krb5" != "no"; then
                WITH_KRB5=TRUE
                save_LIBS=$LIBS
                AC_SEARCH_LIBS(com_err, [com_err 'com_err -lssl -lcrypto' krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'com_err' required for Kerberos 5])])
                KRB5_LIBS=$LIBS
                LIBS=$save_LIBS
                AC_SEARCH_LIBS(krb5_sendauth, [krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'krb5_sendauth' required for Kerberos 5])])
                KRB5_LIBS="$KRB5_LIBS $LIBS"
                LIBS=$save_LIBS
            fi
            if test "$with_gssapi" != "no"; then
                WITH_GSSAPI=TRUE
                save_LIBS=$LIBS
                AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
                    [AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
                GSSAPI_LIBS=$LIBS
                LIBS=$save_LIBS
            fi
            ;;
        *)
            if test "$with_krb5" = "yes"; then
                WITH_KRB5=TRUE
                save_LIBS=$LIBS
                AC_SEARCH_LIBS(com_err, [com_err 'com_err -lssl -lcrypto' krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'com_err' required for Kerberos 5])])
                KRB5_LIBS=$LIBS
                LIBS=$save_LIBS
                AC_SEARCH_LIBS(krb5_sendauth, [krb5 'krb5 -lcrypto -ldes -lasn1 -lroken'], [],
                    [AC_MSG_ERROR([could not find function 'krb5_sendauth' required for Kerberos 5])])
                KRB5_LIBS="$KRB5_LIBS $LIBS"
                LIBS=$save_LIBS
            fi
            if test "$with_gssapi" = "yes"; then
                WITH_GSSAPI=TRUE
                save_LIBS=$LIBS
                AC_SEARCH_LIBS(gss_init_sec_context, [gssapi_krb5 gss 'gssapi -lkrb5 -lcrypto'], [],
                    [AC_MSG_ERROR([could not find function 'gss_init_sec_context' required for GSSAPI])])
                LIBS=$save_LIBS
                GSSAPI_LIBS=$LIBS
            fi
        esac

        if test -n "$with_libpq_path"; then
            SYSTEM_POSTGRESQL=TRUE
            postgres_interface="external libpq"
            POSTGRESQL_LIB="-L${with_libpq_path}/lib/"
            POSTGRESQL_INC=-I"${with_libpq_path}/include/"
        else
            SYSTEM_POSTGRESQL=
            postgres_interface="internal"
            POSTGRESQL_LIB=""
            POSTGRESQL_INC="%OVERRIDE_ME%"
            BUILD_TYPE="$BUILD_TYPE POSTGRESQL"
        fi
    fi

    AC_MSG_CHECKING([PostgreSQL C interface])
    AC_MSG_RESULT([$postgres_interface])

    if test "${SYSTEM_POSTGRESQL}" = "TRUE"; then
        AC_MSG_NOTICE([checking system PostgreSQL prerequisites])
        save_CFLAGS=$CFLAGS
        save_CPPFLAGS=$CPPFLAGS
        save_LIBS=$LIBS
        CPPFLAGS="${CPPFLAGS} ${POSTGRESQL_INC}"
        LIBS="${LIBS} ${POSTGRESQL_LIB}"
        AC_CHECK_HEADER([libpq-fe.h], [], [AC_MSG_ERROR([libpq-fe.h is needed])], [])
        AC_CHECK_LIB([pq], [PQconnectdbParams], [:],
            [AC_MSG_ERROR(libpq not found or too old. Need >= 9.0)], [])
        CFLAGS=$save_CFLAGS
        CPPFLAGS=$save_CPPFLAGS
        LIBS=$save_LIBS
    fi
    BUILD_POSTGRESQL_SDBC=TRUE
fi
AC_SUBST(WITH_KRB5)
AC_SUBST(WITH_GSSAPI)
AC_SUBST(GSSAPI_LIBS)
AC_SUBST(KRB5_LIBS)
AC_SUBST(BUILD_POSTGRESQL_SDBC)
AC_SUBST(SYSTEM_POSTGRESQL)
AC_SUBST(POSTGRESQL_INC)
AC_SUBST(POSTGRESQL_LIB)

dnl ===================================================================
dnl Check for Firebird stuff
dnl ===================================================================
ENABLE_FIREBIRD_SDBC=""
if test "$enable_firebird_sdbc" = "yes" ; then
    SCPDEFS="$SCPDEFS -DWITH_FIREBIRD_SDBC"

    dnl ===================================================================
    dnl Check for system Firebird
    dnl ===================================================================
    AC_MSG_CHECKING([which Firebird to use])
    if test "$with_system_firebird" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_FIREBIRD=TRUE
        AC_PATH_PROG(FIREBIRDCONFIG, [fb_config])
        if test -z "$FIREBIRDCONFIG"; then
            AC_MSG_NOTICE([No fb_config -- using pkg-config])
            PKG_CHECK_MODULES([FIREBIRD], [fbclient >= 3], [FIREBIRD_PKGNAME=fbclient], [
                PKG_CHECK_MODULES([FIREBIRD], [fbembed], [FIREBIRD_PKGNAME=fbembed])
            ])
            FIREBIRD_VERSION=`pkg-config --modversion "$FIREBIRD_PKGNAME"`
        else
            AC_MSG_NOTICE([fb_config found])
            FIREBIRD_VERSION=`$FIREBIRDCONFIG --version`
            AC_MSG_CHECKING([for Firebird Client library])
            FIREBIRD_CFLAGS=`$FIREBIRDCONFIG --cflags`
            FIREBIRD_LIBS=`$FIREBIRDCONFIG --embedlibs`
            FilterLibs "${FIREBIRD_LIBS}"
            FIREBIRD_LIBS="${filteredlibs}"
        fi
        AC_MSG_RESULT([includes `$FIREBIRD_CFLAGS', libraries `$FIREBIRD_LIBS'])
        AC_MSG_CHECKING([Firebird version])
        if test -n "${FIREBIRD_VERSION}"; then
            FIREBIRD_MAJOR=`echo $FIREBIRD_VERSION | cut -d"." -f1`
            FIREBIRD_MINOR=`echo $FIREBIRD_VERSION | cut -d"." -f2`
            if test "$FIREBIRD_MAJOR" -eq "3" -a "$FIREBIRD_MINOR" -eq "0"; then
                AC_MSG_RESULT([OK])
            else
                AC_MSG_ERROR([Ensure firebird 3.0.x is installed])
            fi
        else
            __save_CFLAGS="${CFLAGS}"
            CFLAGS="${CFLAGS} ${FIREBIRD_CFLAGS}"
            AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <ibase.h>
#if defined(FB_API_VER) && FB_API_VER == 30
int fb_api_is_30(void) { return 0; }
#else
#error "Wrong Firebird API version"
#endif]])],AC_MSG_RESULT([OK]),AC_MSG_ERROR([Ensure firebird 3.0.x is installed]))
            CFLAGS="${__save_CFLAGS}"
        fi
        ENABLE_FIREBIRD_SDBC="TRUE"
    elif test "$enable_database_connectivity" != yes; then
        AC_MSG_RESULT([none])
    elif test "$cross_compiling" = "yes"; then
        AC_MSG_RESULT([none])
    else
        dnl Embedded Firebird has version 3.0
        AC_DEFINE(HAVE_FIREBIRD_30, 1)
        dnl We need libatomic-ops for any non X86/X64 system
        if test "${CPUNAME}" != INTEL -a "${CPUNAME}" != X86_64; then
            dnl ===================================================================
            dnl Check for system libatomic-ops
            dnl ===================================================================
            libo_CHECK_SYSTEM_MODULE([libatomic_ops],[ATOMIC_OPS],[atomic_ops >= 0.7.2])
            if test "$with_system_libatomic_ops" = "yes"; then
                SYSTEM_LIBATOMIC_OPS=TRUE
                AC_CHECK_HEADERS(atomic_ops.h, [],
                [AC_MSG_ERROR(atomic_ops.h not found. install libatomic-ops)], [])
            else
                SYSTEM_LIBATOMIC_OPS=
                LIBATOMIC_OPS_CFLAGS="-I${WORKDIR}/UnpackedTarball/libatomic_ops/include"
                LIBATOMIC_OPS_LIBS="-latomic_ops"
                BUILD_TYPE="$BUILD_TYPE LIBATOMIC_OPS"
            fi
        fi

        AC_MSG_RESULT([internal])
        SYSTEM_FIREBIRD=
        FIREBIRD_CFLAGS="-I${WORKDIR}/UnpackedTarball/firebird/gen/Release/firebird/include"
        FIREBIRD_LIBS="-lfbclient"

        if test "$with_system_libtommath" = "yes"; then
            SYSTEM_LIBTOMMATH=TRUE
            dnl check for tommath presence
            save_LIBS=$LIBS
            AC_CHECK_HEADER(tommath.h,,AC_MSG_ERROR(Include file for tommath not found - please install development tommath package))
            AC_CHECK_LIB(tommath, mp_init, TOMMATH_LIBS=-ltommath, AC_MSG_ERROR(Library tommath not found - please install development tommath package))
            LIBS=$save_LIBS
        else
            SYSTEM_LIBTOMMATH=
            LIBTOMMATH_CFLAGS="-I${WORKDIR}/UnpackedTarball/libtommath"
            LIBTOMMATH_LIBS="-ltommath"
            BUILD_TYPE="$BUILD_TYPE LIBTOMMATH"
        fi

        BUILD_TYPE="$BUILD_TYPE FIREBIRD"
        ENABLE_FIREBIRD_SDBC="TRUE"
    fi
fi
AC_SUBST(ENABLE_FIREBIRD_SDBC)
AC_SUBST(SYSTEM_LIBATOMIC_OPS)
AC_SUBST(LIBATOMIC_OPS_CFLAGS)
AC_SUBST(LIBATOMIC_OPS_LIBS)
AC_SUBST(SYSTEM_FIREBIRD)
AC_SUBST(FIREBIRD_CFLAGS)
AC_SUBST(FIREBIRD_LIBS)
AC_SUBST([TOMMATH_CFLAGS])
AC_SUBST([TOMMATH_LIBS])

dnl ===================================================================
dnl Check for system curl
dnl ===================================================================
AC_MSG_CHECKING([which libcurl to use])
if test "$with_system_curl" = "auto"; then
    with_system_curl="$with_system_libs"
fi

if test "$with_system_curl" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_CURL=TRUE

    # First try PKGCONFIG and then fall back
    PKG_CHECK_MODULES(CURL, libcurl >= 7.19.4,, [:])

    if test -n "$CURL_PKG_ERRORS"; then
        AC_PATH_PROG(CURLCONFIG, curl-config)
        if test -z "$CURLCONFIG"; then
            AC_MSG_ERROR([curl development files not found])
        fi
        CURL_LIBS=`$CURLCONFIG --libs`
        FilterLibs "${CURL_LIBS}"
        CURL_LIBS="${filteredlibs}"
        CURL_CFLAGS=$("$CURLCONFIG" --cflags | sed -e "s/-I/${ISYSTEM?}/g")
        curl_version=`$CURLCONFIG --version | $SED -e 's/^libcurl //'`

        AC_MSG_CHECKING([whether libcurl is >= 7.19.4])
        case $curl_version in
        dnl brackets doubled below because Autoconf uses them as m4 quote characters,
        dnl so they need to be doubled to end up in the configure script
        7.19.4|7.19.[[5-9]]|7.[[2-9]]?.*|7.???.*|[[8-9]].*|[[1-9]][[0-9]].*)
            AC_MSG_RESULT([yes])
            ;;
        *)
            AC_MSG_ERROR([no, you have $curl_version])
            ;;
        esac
    fi

    ENABLE_CURL=TRUE
elif test $_os = iOS; then
    # Let's see if we need curl, I think not?
    AC_MSG_RESULT([none])
    ENABLE_CURL=
else
    AC_MSG_RESULT([internal])
    SYSTEM_CURL=
    BUILD_TYPE="$BUILD_TYPE CURL"
    ENABLE_CURL=TRUE
fi
AC_SUBST(SYSTEM_CURL)
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
AC_SUBST(ENABLE_CURL)

dnl ===================================================================
dnl Check for system boost
dnl ===================================================================
AC_MSG_CHECKING([which boost to use])
if test "$with_system_boost" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_BOOST=TRUE
    AX_BOOST_BASE(1.47)
    AX_BOOST_DATE_TIME
    AX_BOOST_FILESYSTEM
    AX_BOOST_IOSTREAMS
    AX_BOOST_LOCALE
    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS $BOOST_CPPFLAGS $CXXFLAGS_CXX11"
    AC_CHECK_HEADER(boost/shared_ptr.hpp, [],
       [AC_MSG_ERROR(boost/shared_ptr.hpp not found. install boost)], [])
    AC_CHECK_HEADER(boost/spirit/include/classic_core.hpp, [],
       [AC_MSG_ERROR(boost/spirit/include/classic_core.hpp not found. install boost >= 1.36)], [])
    CXXFLAGS=$save_CXXFLAGS
    AC_LANG_POP([C++])
    # this is in m4/ax_boost_base.m4
    FilterLibs "${BOOST_LDFLAGS}"
    BOOST_LDFLAGS="${filteredlibs}"
else
    AC_MSG_RESULT([internal])
    BUILD_TYPE="$BUILD_TYPE BOOST"
    SYSTEM_BOOST=
    if test "${COM}" = "GCC" -o "${COM_IS_CLANG}" = "TRUE"; then
        # use warning-suppressing wrapper headers
        BOOST_CPPFLAGS="-I${SRC_ROOT}/external/boost/include -I${WORKDIR}/UnpackedTarball/boost"
    else
        BOOST_CPPFLAGS="-I${WORKDIR}/UnpackedTarball/boost"
    fi
fi
AC_SUBST(SYSTEM_BOOST)

dnl ===================================================================
dnl Check for system mdds
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([mdds], [MDDS], [mdds-1.2 >= 1.2.3], ["-I${WORKDIR}/UnpackedTarball/mdds/include"])

dnl ===================================================================
dnl Check for system glm
dnl ===================================================================
AC_MSG_CHECKING([which glm to use])
if test "$with_system_glm" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_GLM=TRUE
    AC_LANG_PUSH([C++])
    AC_CHECK_HEADER([glm/glm.hpp], [],
       [AC_MSG_ERROR([glm/glm.hpp not found. install glm])], [])
    AC_LANG_POP([C++])
else
    AC_MSG_RESULT([internal])
    BUILD_TYPE="$BUILD_TYPE GLM"
    SYSTEM_GLM=
    GLM_CFLAGS="${ISYSTEM}${WORKDIR}/UnpackedTarball/glm"
fi
AC_SUBST([GLM_CFLAGS])
AC_SUBST([SYSTEM_GLM])

dnl ===================================================================
dnl Check for system odbc
dnl ===================================================================
AC_MSG_CHECKING([which odbc headers to use])
if test "$with_system_odbc" = "yes" -o '(' "$with_system_headers" = "yes" -a "$with_system_odbc" = "auto" ')' -o '(' "$_os" = "WINNT" -a  "$with_system_odbc" != "no" ')'; then
    AC_MSG_RESULT([external])
    SYSTEM_ODBC_HEADERS=TRUE

    if test "$build_os" = "cygwin"; then
        save_CPPFLAGS=$CPPFLAGS
        find_winsdk
        PathFormat "$winsdktest"
        CPPFLAGS="$CPPFLAGS -I$formatted_path/include/um -I$formatted_path/Include/$winsdklibsubdir/um -I$formatted_path/include -I$formatted_path/include/shared -I$formatted_path/include/$winsdklibsubdir/shared"
        AC_CHECK_HEADER(sqlext.h, [],
            [AC_MSG_ERROR(odbc not found. install odbc)],
            [#include <windows.h>])
        CPPFLAGS=$save_CPPFLAGS
    else
        AC_CHECK_HEADER(sqlext.h, [],
            [AC_MSG_ERROR(odbc not found. install odbc)],[])
    fi
elif test "$enable_database_connectivity" != yes; then
    AC_MSG_RESULT([none])
else
    AC_MSG_RESULT([internal])
    SYSTEM_ODBC_HEADERS=
fi
AC_SUBST(SYSTEM_ODBC_HEADERS)


dnl ===================================================================
dnl Check for system openldap
dnl ===================================================================

if test "$_os" != "WINNT" -a "$_os" != "iOS" -a "$_os" != "Android"; then
AC_MSG_CHECKING([which openldap library to use])
if test "$with_system_openldap" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_OPENLDAP=TRUE
    AC_CHECK_HEADERS(ldap.h, [], [AC_MSG_ERROR(ldap.h not found. install openldap libs)], [])
    AC_CHECK_LIB([ldap], [ldap_simple_bind_s], [:], [AC_MSG_ERROR(openldap lib not found or functional)], [])
    AC_CHECK_LIB([ldap], [ldap_set_option], [:], [AC_MSG_ERROR(openldap lib not found or functional)], [])
else
    AC_MSG_RESULT([internal])
    SYSTEM_OPENLDAP=
    BUILD_TYPE="$BUILD_TYPE OPENLDAP"
fi
fi
AC_SUBST(SYSTEM_OPENLDAP)

dnl ===================================================================
dnl Check for system NSS
dnl ===================================================================
if test $_os != iOS -a "$enable_fuzzers" != "yes"; then
    libo_CHECK_SYSTEM_MODULE([nss],[NSS],[nss >= 3.9.3 nspr >= 4.8])
    AC_DEFINE(HAVE_FEATURE_NSS)
    ENABLE_NSS="TRUE"
    AC_DEFINE(ENABLE_NSS)
elif test $_os != iOS ; then
    with_tls=openssl
fi
AC_SUBST(ENABLE_NSS)

dnl ===================================================================
dnl Check for TLS/SSL and cryptographic implementation to use
dnl ===================================================================
AC_MSG_CHECKING([which TLS/SSL and cryptographic implementation to use])
if test -n "$with_tls"; then
    case $with_tls in
    openssl)
        AC_DEFINE(USE_TLS_OPENSSL)
        TLS=OPENSSL

        if test "$enable_openssl" != "yes"; then
            AC_MSG_ERROR(["Disabling OpenSSL was requested, but the requested TLS to use is actually OpenSSL."])
        fi

        # warn that OpenSSL has been selected but not all TLS code has this option
        AC_MSG_WARN([TLS/SSL implementation to use is OpenSSL but some code may still depend on NSS or GNUTLS])
        add_warning "TLS/SSL implementation to use is OpenSSL but some code may still depend on NSS or GNUTLS"
        ;;
    nss)
        AC_DEFINE(USE_TLS_NSS)
        TLS=NSS
        ;;
    no)
        AC_MSG_WARN([Skipping TLS/SSL])
        ;;
    *)
        AC_MSG_ERROR([unsupported implementation $with_tls. Supported are:
openssl - OpenSSL
nss - Mozilla's Network Security Services (NSS)
    ])
        ;;
    esac
else
    # default to using NSS, it results in smaller oox lib
    AC_DEFINE(USE_TLS_NSS)
    TLS=NSS
fi
AC_MSG_RESULT([$TLS])
AC_SUBST(TLS)

dnl ===================================================================
dnl Check for system sane
dnl ===================================================================
AC_MSG_CHECKING([which sane header to use])
if test "$with_system_sane" = "yes"; then
    AC_MSG_RESULT([external])
    AC_CHECK_HEADER(sane/sane.h, [],
      [AC_MSG_ERROR(sane not found. install sane)], [])
else
    AC_MSG_RESULT([internal])
    BUILD_TYPE="$BUILD_TYPE SANE"
fi

dnl ===================================================================
dnl Check for system icu
dnl ===================================================================
SYSTEM_GENBRK=
SYSTEM_GENCCODE=
SYSTEM_GENCMN=

ICU_MAJOR=60
ICU_MINOR=2
ICU_RECLASSIFIED_PREPEND_SET_EMPTY="TRUE"
ICU_RECLASSIFIED_CONDITIONAL_JAPANESE_STARTER="TRUE"
ICU_RECLASSIFIED_HEBREW_LETTER="TRUE"
AC_MSG_CHECKING([which icu to use])
if test "$with_system_icu" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_ICU=TRUE
    AC_LANG_PUSH([C++])
    AC_MSG_CHECKING([for unicode/rbbi.h])
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[unicode/rbbi.h]])],[AC_MSG_RESULT(checked.)],[AC_MSG_ERROR(icu headers not found.)])
    AC_LANG_POP([C++])

    if test "$cross_compiling" != "yes"; then
        PKG_CHECK_MODULES(ICU, icu-i18n >= 4.6)
        ICU_VERSION=`$PKG_CONFIG --modversion icu-i18n 2>/dev/null`
        ICU_MAJOR=`echo $ICU_VERSION | cut -d"." -f1`
        ICU_MINOR=`echo $ICU_VERSION | cut -d"." -f2`
    fi

    if test "$cross_compiling" = "yes" -a \( "$with_system_icu_for_build" = "yes" -o "$with_system_icu_for_build" = "force" \); then
        ICU_VERSION_FOR_BUILD=`$PKG_CONFIG --modversion icu-i18n 2>/dev/null`
        ICU_MAJOR_FOR_BUILD=`echo $ICU_VERSION_FOR_BUILD | cut -d"." -f1`
        ICU_MINOR_FOR_BUILD=`echo $ICU_VERSION_FOR_BUILD | cut -d"." -f2`
        AC_MSG_CHECKING([if MinGW and system versions of ICU are compatible])
        if test "$ICU_MAJOR" -eq "$ICU_MAJOR_FOR_BUILD" -a "$ICU_MINOR" -eq "$ICU_MINOR_FOR_BUILD"; then
            AC_MSG_RESULT([yes])
        else
            AC_MSG_RESULT([no])
            if test "$with_system_icu_for_build" != "force"; then
                AC_MSG_ERROR([System ICU is not version-compatible with MinGW ICU.
You can use --with-system-icu-for-build=force to use it anyway.])
            fi
        fi
    fi

    if test "$cross_compiling" != "yes" -o "$with_system_icu_for_build" = "yes" -o "$with_system_icu_for_build" = "force"; then
        # using the system icu tools can lead to version confusion, use the
        # ones from the build environment when cross-compiling
        AC_PATH_PROG(SYSTEM_GENBRK, genbrk, [], [$PATH:/usr/sbin:/sbin])
        if test -z "$SYSTEM_GENBRK"; then
            AC_MSG_ERROR([\'genbrk\' not found in \$PATH, install the icu development tool \'genbrk\'])
        fi
        AC_PATH_PROG(SYSTEM_GENCCODE, genccode, [], [$PATH:/usr/sbin:/sbin:/usr/local/sbin])
        if test -z "$SYSTEM_GENCCODE"; then
            AC_MSG_ERROR([\'genccode\' not found in \$PATH, install the icu development tool \'genccode\'])
        fi
        AC_PATH_PROG(SYSTEM_GENCMN, gencmn, [], [$PATH:/usr/sbin:/sbin:/usr/local/sbin])
        if test -z "$SYSTEM_GENCMN"; then
            AC_MSG_ERROR([\'gencmn\' not found in \$PATH, install the icu development tool \'gencmn\'])
        fi
        if test "$ICU_MAJOR" -ge "49"; then
            ICU_RECLASSIFIED_PREPEND_SET_EMPTY="TRUE"
            ICU_RECLASSIFIED_CONDITIONAL_JAPANESE_STARTER="TRUE"
            ICU_RECLASSIFIED_HEBREW_LETTER="TRUE"
        else
            ICU_RECLASSIFIED_PREPEND_SET_EMPTY=
            ICU_RECLASSIFIED_CONDITIONAL_JAPANESE_STARTER=
            ICU_RECLASSIFIED_HEBREW_LETTER=
        fi
    fi

    if test "$cross_compiling" = "yes"; then
        if test "$ICU_MAJOR" -ge "50"; then
            AC_MSG_RESULT([Ignore ICU_MINOR as obviously the libraries don't include the minor version in their names any more])
            ICU_MINOR=""
        fi
    fi
else
    AC_MSG_RESULT([internal])
    SYSTEM_ICU=
    BUILD_TYPE="$BUILD_TYPE ICU"
    # surprisingly set these only for "internal" (to be used by various other
    # external libs): the system icu-config is quite unhelpful and spits out
    # dozens of weird flags and also default path -I/usr/include
    ICU_CFLAGS="-I${WORKDIR}/UnpackedTarball/icu/source/i18n -I${WORKDIR}/UnpackedTarball/icu/source/common"
    ICU_LIBS="-L${WORKDIR}/UnpackedTarball/icu/source/lib"
fi
if test "$ICU_MAJOR" -ge "59"; then
    # As of ICU 59 it defaults to typedef char16_t UChar; which is available
    # with -std=c++11 but not all external libraries can be built with that,
    # for those use a bit-compatible typedef uint16_t UChar; see
    # icu/source/common/unicode/umachine.h
    ICU_UCHAR_TYPE="-DUCHAR_TYPE=uint16_t"
else
    ICU_UCHAR_TYPE=""
fi
AC_SUBST(SYSTEM_ICU)
AC_SUBST(SYSTEM_GENBRK)
AC_SUBST(SYSTEM_GENCCODE)
AC_SUBST(SYSTEM_GENCMN)
AC_SUBST(ICU_MAJOR)
AC_SUBST(ICU_MINOR)
AC_SUBST(ICU_RECLASSIFIED_PREPEND_SET_EMPTY)
AC_SUBST(ICU_RECLASSIFIED_CONDITIONAL_JAPANESE_STARTER)
AC_SUBST(ICU_RECLASSIFIED_HEBREW_LETTER)
AC_SUBST(ICU_CFLAGS)
AC_SUBST(ICU_LIBS)
AC_SUBST(ICU_UCHAR_TYPE)

dnl ==================================================================
dnl Breakpad
dnl ==================================================================
AC_MSG_CHECKING([whether to enable breakpad])
if test "$enable_breakpad" != yes; then
    AC_MSG_RESULT([no])
else
    AC_MSG_RESULT([yes])
    ENABLE_BREAKPAD="TRUE"
    AC_DEFINE(ENABLE_BREAKPAD)
    AC_DEFINE(HAVE_FEATURE_BREAKPAD, 1)
    BUILD_TYPE="$BUILD_TYPE BREAKPAD"

    AC_MSG_CHECKING([for crashreport config])
    if test "$with_symbol_config" = "no"; then
        BREAKPAD_SYMBOL_CONFIG="invalid"
        AC_MSG_RESULT([no])
    else
        BREAKPAD_SYMBOL_CONFIG="$with_symbol_config"
        AC_DEFINE(BREAKPAD_SYMBOL_CONFIG)
        AC_MSG_RESULT([yes])
    fi
    AC_SUBST(BREAKPAD_SYMBOL_CONFIG)
fi
AC_SUBST(ENABLE_BREAKPAD)

dnl ==================================================================
dnl libfuzzer
dnl ==================================================================
AC_MSG_CHECKING([whether to enable fuzzers])
if test "$enable_fuzzers" != yes; then
    AC_MSG_RESULT([no])
else
    AC_MSG_RESULT([yes])
    ENABLE_FUZZERS="TRUE"
    AC_DEFINE(ENABLE_FUZZERS)
    BUILD_TYPE="$BUILD_TYPE FUZZERS"
fi
AC_SUBST(ENABLE_FUZZERS)

dnl ===================================================================
dnl Orcus
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([orcus],[ORCUS],[liborcus-0.13 >= 0.13.3])
if test "$with_system_orcus" != "yes"; then
    if test "$SYSTEM_BOOST" = "TRUE"; then
        # ===========================================================
        # Determine if we are going to need to link with Boost.System
        # ===========================================================
        dnl This seems to be necessary since boost 1.50 (1.48 does not need it,
        dnl 1.49 is untested). The macro BOOST_THREAD_DONT_USE_SYSTEM mentioned
        dnl in documentation has no effect.
        AC_MSG_CHECKING([if we need to link with Boost.System])
        AC_LANG_PUSH([C++])
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
                @%:@include <boost/version.hpp>
            ]],[[
                #if BOOST_VERSION >= 105000
                #   error yes, we need to link with Boost.System
                #endif
            ]])],[
                AC_MSG_RESULT([no])
            ],[
                AC_MSG_RESULT([yes])
                AX_BOOST_SYSTEM
        ])
        AC_LANG_POP([C++])
    fi
fi
dnl FIXME by renaming SYSTEM_LIBORCUS to SYSTEM_ORCUS in the build system world
SYSTEM_LIBORCUS=$SYSTEM_ORCUS
AC_SUBST([BOOST_SYSTEM_LIB])
AC_SUBST(SYSTEM_LIBORCUS)

dnl ===================================================================
dnl HarfBuzz
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([graphite],[GRAPHITE],[graphite2 >= 0.9.3],
                         ["-I${WORKDIR}/UnpackedTarball/graphite/include -DGRAPHITE2_STATIC"],
                         ["-L${WORKDIR}/LinkTarget/StaticLibrary -lgraphite"])

libo_CHECK_SYSTEM_MODULE([harfbuzz],[HARFBUZZ],[harfbuzz-icu >= 0.9.42],
                         ["-I${WORKDIR}/UnpackedTarball/harfbuzz/src"],
                         ["-L${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs -lharfbuzz"])

if test "$COM" = "MSC"; then # override the above
    GRAPHITE_LIBS="${WORKDIR}/LinkTarget/StaticLibrary/graphite.lib"
    HARFBUZZ_LIBS="${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs/libharfbuzz.lib"
fi

if test "$with_system_harfbuzz" = "yes"; then
    if test "$with_system_graphite" = "no"; then
        AC_MSG_ERROR([--with-system-graphite must be used when --with-system-harfbuzz is used])
    fi
    AC_MSG_CHECKING([whether system Harfbuzz is built with Graphite support])
    _save_libs="$LIBS"
    _save_cflags="$CFLAGS"
    LIBS="$LIBS $HARFBUZZ_LIBS"
    CFLAGS="$CFLAGS $HARFBUZZ_CFLAGS"
    AC_CHECK_FUNC(hb_graphite2_face_get_gr_face,,[AC_MSG_ERROR([Harfbuzz needs to be built with Graphite support.])])
    LIBS="$_save_libs"
    CFLAGS="$_save_cflags"
else
    if test "$with_system_graphite" = "yes"; then
        AC_MSG_ERROR([--without-system-graphite must be used when --without-system-harfbuzz is used])
    fi
fi

AC_MSG_CHECKING([whether to use X11])
dnl ***************************************
dnl testing for X libraries and includes...
dnl ***************************************
if test "$USING_X11" = TRUE; then
    AC_DEFINE(HAVE_FEATURE_X11)
fi
AC_MSG_RESULT([$USING_X11])

if test "$USING_X11" = TRUE; then
    AC_PATH_X
    AC_PATH_XTRA
    CPPFLAGS="$CPPFLAGS $X_CFLAGS"

    if test -z "$x_includes"; then
        x_includes="default_x_includes"
    fi
    if test -z "$x_libraries"; then
        x_libraries="default_x_libraries"
    fi
    CFLAGS="$CFLAGS $X_CFLAGS"
    LDFLAGS="$LDFLAGS $X_LDFLAGS $X_LIBS"
    AC_CHECK_LIB(X11, XOpenDisplay, x_libs="-lX11 $X_EXTRA_LIBS", [AC_MSG_ERROR([X Development libraries not found])])
else
    x_includes="no_x_includes"
    x_libraries="no_x_libraries"
fi

if test "$USING_X11" = TRUE; then
    dnl ===================================================================
    dnl Check for extension headers
    dnl ===================================================================
    AC_CHECK_HEADERS(X11/extensions/shape.h,[],[AC_MSG_ERROR([libXext headers not found])],
     [#include <X11/extensions/shape.h>])

    # vcl needs ICE and SM
    AC_CHECK_HEADERS(X11/ICE/ICElib.h,[],[AC_MSG_ERROR([libICE headers not found])])
    AC_CHECK_LIB([ICE], [IceConnectionNumber], [:],
        [AC_MSG_ERROR(ICE library not found)])
    AC_CHECK_HEADERS(X11/SM/SMlib.h,[],[AC_MSG_ERROR([libSM headers not found])])
    AC_CHECK_LIB([SM], [SmcOpenConnection], [:],
        [AC_MSG_ERROR(SM library not found)])
fi

dnl ===================================================================
dnl Check for system Xrender
dnl ===================================================================
AC_MSG_CHECKING([whether to use Xrender])
if test "$USING_X11" = TRUE -a  "$test_xrender" = "yes"; then
    AC_MSG_RESULT([yes])
    PKG_CHECK_MODULES(XRENDER, xrender)
    XRENDER_CFLAGS=$(printf '%s' "$XRENDER_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${XRENDER_LIBS}"
    XRENDER_LIBS="${filteredlibs}"
    AC_CHECK_LIB([Xrender], [XRenderQueryVersion], [:],
      [AC_MSG_ERROR(libXrender not found or functional)], [])
    AC_CHECK_HEADER(X11/extensions/Xrender.h, [],
      [AC_MSG_ERROR(Xrender not found. install X)], [])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(XRENDER_CFLAGS)
AC_SUBST(XRENDER_LIBS)

dnl ===================================================================
dnl Check for XRandr
dnl ===================================================================
AC_MSG_CHECKING([whether to enable RandR support])
if test "$USING_X11" = TRUE -a "$test_randr" = "yes" -a \( "$enable_randr" = "yes" -o "$enable_randr" = "TRUE" \); then
    AC_MSG_RESULT([yes])
    PKG_CHECK_MODULES(XRANDR, xrandr >= 1.2, ENABLE_RANDR="TRUE", ENABLE_RANDR="")
    if test "$ENABLE_RANDR" != "TRUE"; then
        AC_CHECK_HEADER(X11/extensions/Xrandr.h, [],
                    [AC_MSG_ERROR([X11/extensions/Xrandr.h could not be found. X11 dev missing?])], [])
        XRANDR_CFLAGS=" "
        AC_CHECK_LIB([Xrandr], [XRRQueryExtension], [:],
          [ AC_MSG_ERROR(libXrandr not found or functional) ], [])
        XRANDR_LIBS="-lXrandr "
        ENABLE_RANDR="TRUE"
    fi
    XRANDR_CFLAGS=$(printf '%s' "$XRANDR_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${XRANDR_LIBS}"
    XRANDR_LIBS="${filteredlibs}"
else
    ENABLE_RANDR=""
    AC_MSG_RESULT([no])
fi
AC_SUBST(XRANDR_CFLAGS)
AC_SUBST(XRANDR_LIBS)
AC_SUBST(ENABLE_RANDR)

if test "$enable_neon" = "no" -o "$enable_mpl_subset" = "yes"; then
    WITH_WEBDAV="serf"
fi
if test $_os = iOS -o $_os = Android; then
    WITH_WEBDAV="no"
fi
AC_MSG_CHECKING([for webdav library])
case "$WITH_WEBDAV" in
serf)
    AC_MSG_RESULT([serf])
    # Check for system apr-util
    libo_CHECK_SYSTEM_MODULE([apr],[APR],[apr-util-1],
                             ["-I${WORKDIR}/UnpackedTarball/apr/include -I${WORKDIR}/UnpackedTarball/apr_util/include"],
                             ["-L${WORKDIR}/UnpackedTarball/apr/.libs -lapr-1 -L${WORKDIR}/UnpackedTarball/apr_util/.libs -laprutil-1"])
    if test "$COM" = "MSC"; then
        APR_LIB_DIR="LibR"
        test -n "${MSVC_USE_DEBUG_RUNTIME}" && APR_LIB_DIR="LibD"
        APR_LIBS="${WORKDIR}/UnpackedTarball/apr/${APR_LIB_DIR}/apr-1.lib ${WORKDIR}/UnpackedTarball/apr_util/${APR_LIB_DIR}/aprutil-1.lib"
    fi

    # Check for system serf
    libo_CHECK_SYSTEM_MODULE([serf],[SERF],[serf-1 >= 1.1.0],["-I${WORKDIR}/UnpackedTarball/serf"],
                             ["-L${WORKDIR}/UnpackedTarball/serf/.libs -lserf-1"])
    if test "$COM" = "MSC"; then
        SERF_LIB_DIR="Release"
        test -n "${MSVC_USE_DEBUG_RUNTIME}" && SERF_LIB_DIR="Debug"
        SERF_LIBS="${WORKDIR}/UnpackedTarball/serf/${SERF_LIB_DIR}/serf-1.lib"
    fi
    ;;
neon)
    AC_MSG_RESULT([neon])
    # Check for system neon
    libo_CHECK_SYSTEM_MODULE([neon],[NEON],[neon >= 0.26.0])
    if test "$with_system_neon" = "yes"; then
        NEON_VERSION="`$PKG_CONFIG --modversion neon | $SED 's/\.//g'`"
    else
        NEON_VERSION=0295
    fi
    AC_SUBST(NEON_VERSION)
    ;;
*)
    AC_MSG_RESULT([none, disabled])
    WITH_WEBDAV=""
    ;;
esac
AC_SUBST(WITH_WEBDAV)

dnl ===================================================================
dnl Check for disabling cve_tests
dnl ===================================================================
AC_MSG_CHECKING([whether to execute CVE tests])
# If not explicitly enabled or disabled, default
if test -z "$enable_cve_tests"; then
    case "$OS" in
    WNT)
        # Default cves off for windows with its wild and wonderful
        # varienty of AV software kicking in and panicing
        enable_cve_tests=no
        ;;
    *)
        # otherwise yes
        enable_cve_tests=yes
        ;;
    esac
fi
if test "$enable_cve_tests" = "no"; then
    AC_MSG_RESULT([no])
    DISABLE_CVE_TESTS=TRUE
    AC_SUBST(DISABLE_CVE_TESTS)
else
    AC_MSG_RESULT([yes])
fi

dnl ===================================================================
dnl Check for enabling chart XShape tests
dnl ===================================================================
AC_MSG_CHECKING([whether to execute chart XShape tests])
if test "$enable_chart_tests" = "yes" -o '(' "$_os" = "WINNT" -a "$enable_chart_tests" != "no" ')'; then
    AC_MSG_RESULT([yes])
    ENABLE_CHART_TESTS=TRUE
    AC_SUBST(ENABLE_CHART_TESTS)
else
    AC_MSG_RESULT([no])
fi

dnl ===================================================================
dnl Check for system openssl
dnl ===================================================================
DISABLE_OPENSSL=
AC_MSG_CHECKING([whether to disable OpenSSL usage])
if test "$enable_openssl" = "yes"; then
    AC_MSG_RESULT([no])
    if test "$_os" = Darwin ; then
        # OpenSSL is deprecated when building for 10.7 or later.
        #
        # http://stackoverflow.com/questions/7406946/why-is-apple-deprecating-openssl-in-macos-10-7-lion
        # http://stackoverflow.com/questions/7475914/libcrypto-deprecated-on-mac-os-x-10-7-lion

        with_system_openssl=no
        libo_CHECK_SYSTEM_MODULE([openssl],[OPENSSL],[openssl])
    elif test "$_os" = "NetBSD" -o "$_os" = "OpenBSD" -o "$_os" = "DragonFly" \
            && test "$with_system_openssl" != "no"; then
        with_system_openssl=yes
        SYSTEM_OPENSSL=TRUE
        OPENSSL_CFLAGS=
        OPENSSL_LIBS="-lssl -lcrypto"
    else
        libo_CHECK_SYSTEM_MODULE([openssl],[OPENSSL],[openssl])
    fi
    if test "$with_system_openssl" = "yes"; then
        AC_MSG_CHECKING([whether openssl supports SHA512])
        AC_LANG_PUSH([C])
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <openssl/sha.h>]],[[
            SHA512_CTX context;
]])],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, openssl too old. Need >= 0.9.8.])])
        AC_LANG_POP(C)
    fi
else
    AC_MSG_RESULT([yes])
    DISABLE_OPENSSL=TRUE

    # warn that although OpenSSL is disabled, system libraries may depend on it
    AC_MSG_WARN([OpenSSL has been disabled. No code compiled by LibO will make use of it but system librares may create indirect dependencies])
    add_warning "OpenSSL has been disabled. No code compiled by LibO will make use of it but system librares may create indirect dependencies"
fi

AC_SUBST([DISABLE_OPENSSL])

dnl ===================================================================
dnl Check for building gnutls
dnl ===================================================================
AC_MSG_CHECKING([whether to use gnutls])
if test "$WITH_WEBDAV" = "neon" -a "$with_system_neon" = no -a "$enable_openssl" = "no"; then
    AC_MSG_RESULT([yes])
    AM_PATH_LIBGCRYPT()
    PKG_CHECK_MODULES(GNUTLS, [gnutls],,
        AC_MSG_ERROR([[Disabling OpenSSL was requested, but GNUTLS is not
                      available in the system to use as replacement.]]))
    FilterLibs "${LIBGCRYPT_LIBS}"
    LIBGCRYPT_LIBS="${filteredlibs}"
else
    AC_MSG_RESULT([no])
fi

AC_SUBST([LIBGCRYPT_CFLAGS])
AC_SUBST([LIBGCRYPT_LIBS])

dnl ===================================================================
dnl Check for system redland
dnl ===================================================================
dnl redland: versions before 1.0.8 write RDF/XML that is useless for ODF (@xml:base)
dnl raptor2: need at least 2.0.7 for CVE-2012-0037
libo_CHECK_SYSTEM_MODULE([redland],[REDLAND],[redland >= 1.0.8 raptor2 >= 2.0.7])
if test "$with_system_redland" = "yes"; then
    AC_CHECK_LIB([rdf], [librdf_world_set_raptor_init_handler], [:],
            [AC_MSG_ERROR(librdf too old. Need >= 1.0.16)], [])
else
    RAPTOR_MAJOR="0"
    RASQAL_MAJOR="3"
    REDLAND_MAJOR="0"
fi
AC_SUBST(RAPTOR_MAJOR)
AC_SUBST(RASQAL_MAJOR)
AC_SUBST(REDLAND_MAJOR)

dnl ===================================================================
dnl Check for system hunspell
dnl ===================================================================
AC_MSG_CHECKING([which libhunspell to use])
if test "$with_system_hunspell" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_HUNSPELL=TRUE
    AC_LANG_PUSH([C++])
    PKG_CHECK_MODULES(HUNSPELL, hunspell, HUNSPELL_PC="TRUE", HUNSPELL_PC="" )
    if test "$HUNSPELL_PC" != "TRUE"; then
        AC_CHECK_HEADER(hunspell.hxx, [],
            [
            AC_CHECK_HEADER(hunspell/hunspell.hxx, [ HUNSPELL_CFLAGS=-I/usr/include/hunspell ],
            [AC_MSG_ERROR(hunspell headers not found.)], [])
            ], [])
        AC_CHECK_LIB([hunspell], [main], [:],
           [ AC_MSG_ERROR(hunspell library not found.) ], [])
        HUNSPELL_LIBS=-lhunspell
    fi
    AC_LANG_POP([C++])
    HUNSPELL_CFLAGS=$(printf '%s' "$HUNSPELL_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${HUNSPELL_LIBS}"
    HUNSPELL_LIBS="${filteredlibs}"
else
    AC_MSG_RESULT([internal])
    SYSTEM_HUNSPELL=
    HUNSPELL_CFLAGS="-I${WORKDIR}/UnpackedTarball/hunspell/src/hunspell"
    if test "$COM" = "MSC"; then
        HUNSPELL_LIBS="${WORKDIR}/LinkTarget/StaticLibrary/hunspell.lib"
    else
        HUNSPELL_LIBS="-L${WORKDIR}/UnpackedTarball/hunspell/src/hunspell/.libs -lhunspell-1.6"
    fi
    BUILD_TYPE="$BUILD_TYPE HUNSPELL"
fi
AC_SUBST(SYSTEM_HUNSPELL)
AC_SUBST(HUNSPELL_CFLAGS)
AC_SUBST(HUNSPELL_LIBS)

dnl ===================================================================
dnl Checking for altlinuxhyph
dnl ===================================================================
AC_MSG_CHECKING([which altlinuxhyph to use])
if test "$with_system_altlinuxhyph" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_HYPH=TRUE
    AC_CHECK_HEADER(hyphen.h, [],
       [ AC_MSG_ERROR(altlinuxhyph headers not found.)], [])
    AC_CHECK_MEMBER(struct _HyphenDict.cset, [],
       [ AC_MSG_ERROR(no. You are sure you have altlinuyhyph headers?)],
       [#include <hyphen.h>])
    AC_CHECK_LIB(hyphen, hnj_hyphen_hyphenate2, [HYPHEN_LIB=-lhyphen],
        [ AC_MSG_ERROR(altlinuxhyph library not found or too old.)], [])
    if test -z "$HYPHEN_LIB"; then
        AC_CHECK_LIB(hyph, hnj_hyphen_hyphenate2, [HYPHEN_LIB=-lhyph],
           [ AC_MSG_ERROR(altlinuxhyph library not found or too old.)], [])
    fi
    if test -z "$HYPHEN_LIB"; then
        AC_CHECK_LIB(hnj, hnj_hyphen_hyphenate2, [HYPHEN_LIB=-lhnj],
           [ AC_MSG_ERROR(altlinuxhyph library not found or too old.)], [])
    fi
else
    AC_MSG_RESULT([internal])
    SYSTEM_HYPH=
    BUILD_TYPE="$BUILD_TYPE HYPHEN"
    if test "$COM" = "MSC"; then
        HYPHEN_LIB="${WORKDIR}/LinkTarget/StaticLibrary/hyphen.lib"
    else
        HYPHEN_LIB="-L${WORKDIR}/UnpackedTarball/hyphen/.libs -lhyphen"
    fi
fi
AC_SUBST(SYSTEM_HYPH)
AC_SUBST(HYPHEN_LIB)

dnl ===================================================================
dnl Checking for mythes
dnl ===================================================================
AC_MSG_CHECKING([which mythes to use])
if test "$with_system_mythes" = "yes"; then
    AC_MSG_RESULT([external])
    SYSTEM_MYTHES=TRUE
    AC_LANG_PUSH([C++])
    PKG_CHECK_MODULES(MYTHES, mythes, MYTHES_PKGCONFIG=yes, MYTHES_PKGCONFIG=no)
    if test "$MYTHES_PKGCONFIG" = "no"; then
        AC_CHECK_HEADER(mythes.hxx, [],
            [ AC_MSG_ERROR(mythes.hxx headers not found.)], [])
        AC_CHECK_LIB([mythes-1.2], [main], [:],
            [ MYTHES_FOUND=no], [])
    if test "$MYTHES_FOUND" = "no"; then
        AC_CHECK_LIB(mythes, main, [MYTHES_FOUND=yes],
                [ MYTHES_FOUND=no], [])
    fi
    if test "$MYTHES_FOUND" = "no"; then
        AC_MSG_ERROR([mythes library not found!.])
    fi
    fi
    AC_LANG_POP([C++])
    MYTHES_CFLAGS=$(printf '%s' "$MYTHES_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${MYTHES_LIBS}"
    MYTHES_LIBS="${filteredlibs}"
else
    AC_MSG_RESULT([internal])
    SYSTEM_MYTHES=
    BUILD_TYPE="$BUILD_TYPE MYTHES"
    if test "$COM" = "MSC"; then
        MYTHES_LIBS="${WORKDIR}/LinkTarget/StaticLibrary/mythes.lib"
    else
        MYTHES_LIBS="-L${WORKDIR}/UnpackedTarball/mythes/.libs -lmythes-1.2"
    fi
fi
AC_SUBST(SYSTEM_MYTHES)
AC_SUBST(MYTHES_CFLAGS)
AC_SUBST(MYTHES_LIBS)

dnl ===================================================================
dnl How should we build the linear programming solver ?
dnl ===================================================================

ENABLE_COINMP=
AC_MSG_CHECKING([whether to build with CoinMP])
if test "$enable_coinmp" != "no"; then
    ENABLE_COINMP=TRUE
    AC_MSG_RESULT([yes])
    if test "$with_system_coinmp" = "yes"; then
        SYSTEM_COINMP=TRUE
        PKG_CHECK_MODULES(COINMP, coinmp coinutils)
        FilterLibs "${COINMP_LIBS}"
        COINMP_LIBS="${filteredlibs}"
    else
        BUILD_TYPE="$BUILD_TYPE COINMP"
    fi
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_COINMP)
AC_SUBST(SYSTEM_COINMP)
AC_SUBST(COINMP_CFLAGS)
AC_SUBST(COINMP_LIBS)

ENABLE_LPSOLVE=
AC_MSG_CHECKING([whether to build with lpsolve])
if test "$enable_lpsolve" != "no"; then
    ENABLE_LPSOLVE=TRUE
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_LPSOLVE)

if test "$ENABLE_LPSOLVE" = TRUE; then
    AC_MSG_CHECKING([which lpsolve to use])
    if test "$with_system_lpsolve" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_LPSOLVE=TRUE
        AC_CHECK_HEADER(lpsolve/lp_lib.h, [],
           [ AC_MSG_ERROR(lpsolve headers not found.)], [])
        save_LIBS=$LIBS
        # some systems need this. Like Ubuntu....
        AC_CHECK_LIB(m, floor)
        AC_CHECK_LIB(dl, dlopen)
        AC_CHECK_LIB([lpsolve55], [make_lp], [:],
            [ AC_MSG_ERROR(lpsolve library not found or too old.)], [])
        LIBS=$save_LIBS
    else
        AC_MSG_RESULT([internal])
        SYSTEM_LPSOLVE=
        BUILD_TYPE="$BUILD_TYPE LPSOLVE"
    fi
fi
AC_SUBST(SYSTEM_LPSOLVE)

dnl ===================================================================
dnl Checking for libexttextcat
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([libexttextcat],[LIBEXTTEXTCAT],[libexttextcat >= 3.4.1])
if test "$with_system_libexttextcat" = "yes"; then
    SYSTEM_LIBEXTTEXTCAT_DATA=file://`$PKG_CONFIG --variable=pkgdatadir libexttextcat`
fi
AC_SUBST(SYSTEM_LIBEXTTEXTCAT_DATA)

dnl ***************************************
dnl testing libc version for Linux...
dnl ***************************************
if test "$_os" = "Linux"; then
    AC_MSG_CHECKING([whether libc is >= 2.1.1])
    exec 6>/dev/null # no output
    AC_CHECK_LIB(c, gnu_get_libc_version, HAVE_LIBC=yes; export HAVE_LIBC)
    exec 6>&1 # output on again
    if test "$HAVE_LIBC"; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_ERROR([no, upgrade libc])
    fi
fi

dnl =========================================
dnl Check for uuidgen
dnl =========================================
if test "$_os" = "WINNT" -a "$cross_compiling" != "yes"; then
    # presence is already tested above in the WINDOWS_SDK_HOME check
    UUIDGEN=uuidgen.exe
    AC_SUBST(UUIDGEN)
else
    AC_PATH_PROG([UUIDGEN], [uuidgen])
    if test -z "$UUIDGEN"; then
        AC_MSG_WARN([uuid is needed for building installation sets])
    fi
fi

dnl ***************************************
dnl Checking for bison and flex
dnl ***************************************
AC_PATH_PROG(BISON, bison)
if test -z "$BISON"; then
    AC_MSG_ERROR([no bison found in \$PATH, install it])
else
    AC_MSG_CHECKING([the bison version])
    _bison_version=`$BISON --version | grep GNU | $SED -e 's@^[[^0-9]]*@@' -e 's@ .*@@' -e 's@,.*@@'`
    _bison_longver=`echo $_bison_version | $AWK -F. '{ print \$1*1000+\$2}'`
    # Accept newer than 2.0
    if test "$_bison_longver" -lt 2000; then
        AC_MSG_ERROR([failed ($BISON $_bison_version need 2.0+)])
    fi
fi

AC_PATH_PROG(FLEX, flex)
if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
    FLEX=`cygpath -m $FLEX`
fi
if test -z "$FLEX"; then
    AC_MSG_ERROR([no flex found in \$PATH, install it])
else
    AC_MSG_CHECKING([the flex version])
    _flex_version=$($FLEX --version | $SED -e 's/^.*\([[[:digit:]]]\{1,\}\.[[[:digit:]]]\{1,\}\.[[[:digit:]]]\{1,\}\).*$/\1/')
    if test $(echo $_flex_version | $AWK -F. '{printf("%d%03d%03d", $1, $2, $3)}') -lt 2005035; then
        AC_MSG_ERROR([failed ($FLEX $_flex_version found, but need at least 2.5.35)])
    fi
fi
AC_SUBST([FLEX])
dnl ***************************************
dnl Checking for patch
dnl ***************************************
AC_PATH_PROG(PATCH, patch)
if test -z "$PATCH"; then
    AC_MSG_ERROR(["patch" not found in \$PATH, install it])
fi

dnl On Solaris, FreeBSD or MacOS X, check if --with-gnu-patch was used
if test "$_os" = "SunOS" -o "$_os" = "FreeBSD" -o "$_os" = "Darwin"; then
    if test -z "$with_gnu_patch"; then
        GNUPATCH=$PATCH
    else
        if test -x "$with_gnu_patch"; then
            GNUPATCH=$with_gnu_patch
        else
            AC_MSG_ERROR([--with-gnu-patch did not point to an executable])
        fi
    fi

    AC_MSG_CHECKING([whether $GNUPATCH is GNU patch])
    if $GNUPATCH --version | grep "Free Software Foundation" >/dev/null 2>/dev/null; then
        AC_MSG_RESULT([yes])
    else
        AC_MSG_ERROR([no, GNU patch needed. install or specify with --with-gnu-patch=/path/to/it])
    fi
else
    GNUPATCH=$PATCH
fi

if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
    GNUPATCH=`cygpath -m $GNUPATCH`
fi

dnl We also need to check for --with-gnu-cp

if test -z "$with_gnu_cp"; then
    # check the place where the good stuff is hidden on Solaris...
    if test -x /usr/gnu/bin/cp; then
        GNUCP=/usr/gnu/bin/cp
    else
        AC_PATH_PROGS(GNUCP, gnucp cp)
    fi
    if test -z $GNUCP; then
        AC_MSG_ERROR([Neither gnucp nor cp found. Install GNU cp and/or specify --with-gnu-cp=/path/to/it])
    fi
else
    if test -x "$with_gnu_cp"; then
        GNUCP=$with_gnu_cp
    else
        AC_MSG_ERROR([--with-gnu-cp did not point to an executable])
    fi
fi

if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
    GNUCP=`cygpath -m $GNUCP`
fi

AC_MSG_CHECKING([whether $GNUCP is GNU cp from coreutils with preserve= support])
if $GNUCP --version 2>/dev/null | grep "coreutils" >/dev/null 2>/dev/null; then
    AC_MSG_RESULT([yes])
elif $GNUCP --version 2>/dev/null | grep "GNU fileutils" >/dev/null 2>/dev/null; then
    AC_MSG_RESULT([yes])
else
    case "$build_os" in
    darwin*|netbsd*|openbsd*|freebsd*|dragonfly*|aix*)
        x_GNUCP=[\#]
        GNUCP=''
        AC_MSG_RESULT([no gnucp found - using the system's cp command])
        ;;
    *)
        AC_MSG_ERROR([no, GNU cp needed. install or specify with --with-gnu-cp=/path/to/it])
        ;;
    esac
fi

AC_SUBST(GNUPATCH)
AC_SUBST(GNUCP)
AC_SUBST(x_GNUCP)

dnl ***************************************
dnl testing assembler path
dnl ***************************************
ML_EXE=""
if test "$_os" = "WINNT"; then
    if test "$BITNESS_OVERRIDE" = ""; then
        assembler=ml.exe
        assembler_bin=$CL_DIR
    else
        assembler=ml64.exe
        assembler_bin=$CL_DIR
    fi

    AC_MSG_CHECKING([$VC_PRODUCT_DIR/$assembler_bin/$assembler])
    if test -f "$VC_PRODUCT_DIR/$assembler_bin/$assembler"; then
        ASM_HOME=$VC_PRODUCT_DIR/$assembler_bin
        AC_MSG_RESULT([found])
        ML_EXE="$VC_PRODUCT_DIR/$assembler_bin/$assembler"
    else
        AC_MSG_ERROR([Configure did not find $assembler assembler.])
    fi

    PathFormat "$ASM_HOME"
    ASM_HOME="$formatted_path"
else
    ASM_HOME=""
fi

AC_SUBST(ML_EXE)

dnl ===================================================================
dnl We need zip and unzip
dnl ===================================================================
AC_PATH_PROG(ZIP, zip)
test -z "$ZIP" && AC_MSG_ERROR([zip is required])
if ! "$ZIP" --filesync < /dev/null 2>/dev/null > /dev/null; then
    AC_MSG_ERROR([Zip version 3.0 or newer is required to build, please install it and make sure it is the one found first in PATH],,)
fi

AC_PATH_PROG(UNZIP, unzip)
test -z "$UNZIP" && AC_MSG_ERROR([unzip is required])

dnl ===================================================================
dnl Zip must be a specific type for different build types.
dnl ===================================================================
if test $build_os = cygwin; then
    if test -n "`$ZIP -h | $GREP -i WinNT`"; then
        AC_MSG_ERROR([$ZIP is not the required Cygwin version of Info-ZIP's zip.exe.])
    fi
fi

dnl ===================================================================
dnl We need touch with -h option support.
dnl ===================================================================
AC_PATH_PROG(TOUCH, touch)
test -z "$TOUCH" && AC_MSG_ERROR([touch is required])
touch warn
if ! "$TOUCH" -h warn 2>/dev/null > /dev/null; then
    AC_MSG_ERROR([touch version with -h option support is required to build, please install it and make sure it is the one found first in PATH],,)
fi

dnl ===================================================================
dnl Check for system epoxy
dnl ===================================================================
libo_CHECK_SYSTEM_MODULE([epoxy], [EPOXY], [epoxy >= 1.2], ["-I${WORKDIR}/UnpackedTarball/epoxy/include"])

dnl ===================================================================
dnl Set vcl option: coordinate device in double or sal_Int32
dnl ===================================================================

dnl disabled for now, we don't want subtle differences between OSs
dnl AC_MSG_CHECKING([Type to use for Device Pixel coordinates])
dnl if test "$_os" = "Darwin" -o  $_os = iOS ; then
dnl     AC_DEFINE(VCL_FLOAT_DEVICE_PIXEL)
dnl     AC_MSG_RESULT([double])
dnl else
dnl     AC_MSG_RESULT([sal_Int32])
dnl fi

dnl ===================================================================
dnl Test which vclplugs have to be built.
dnl ===================================================================
R=""
if test "$USING_X11" != TRUE; then
    enable_gtk=no
    enable_gtk3=no
fi
GTK3_CFLAGS=""
GTK3_LIBS=""
ENABLE_GTK3=""
if test "x$enable_gtk3" = "xyes"; then
    if test "$with_system_cairo" = no; then
        AC_MSG_ERROR([System cairo required for gtk3 support, do not combine --enable-gtk3 with --without-system-cairo])
    fi
    : ${with_system_cairo:=yes}
    PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.8 gtk+-unix-print-3.0 gmodule-no-export-2.0 glib-2.0 >= 2.38 cairo, ENABLE_GTK3="TRUE", ENABLE_GTK3="")
    if test "x$ENABLE_GTK3" = "xTRUE"; then
        R="gtk3"
        dnl Avoid installed by unpackaged files for now.
        if test -z "$PKGFORMAT"; then
            GOBJECT_INTROSPECTION_CHECK(INTROSPECTION_REQUIRED_VERSION)
        fi
    else
        AC_MSG_ERROR([gtk3 or dependent libraries of the correct versions, not found])
    fi
    GTK3_CFLAGS=$(printf '%s' "$GTK3_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${GTK3_LIBS}"
    GTK3_LIBS="${filteredlibs}"

    dnl We require egl only for the gtk3 plugin. Otherwise we use glx.
    if test "$with_system_epoxy" != "yes"; then
        AC_CHECK_LIB(EGL, eglMakeCurrent, [:], AC_MSG_ERROR([libEGL required.]))
        AC_CHECK_HEADER(EGL/eglplatform.h, [],
                        [AC_MSG_ERROR(EGL headers not found. install mesa-libEGL-devel)], [])
    fi
fi
AC_SUBST(GTK3_LIBS)
AC_SUBST(GTK3_CFLAGS)
AC_SUBST(ENABLE_GTK3)

ENABLE_GTK=""
if test "x$enable_gtk" = "xyes"; then
    if test "$with_system_cairo" = no; then
        AC_MSG_ERROR([System cairo required for gtk support, do not use --without-system-cairo or use --disable-gtk])
    fi
    : ${with_system_cairo:=yes}
    ENABLE_GTK="TRUE"
    AC_DEFINE(ENABLE_GTK)
    R="gtk $R"
fi
AC_SUBST(ENABLE_GTK)

ENABLE_KDE4=""
if test "x$enable_kde4" = "xyes"; then
    ENABLE_KDE4="TRUE"
    AC_DEFINE(ENABLE_KDE4)
    R="$R kde4"
fi
AC_SUBST(ENABLE_KDE4)

ENABLE_QT5=""
if test "x$enable_qt5" = "xyes"; then
    ENABLE_QT5="TRUE"
    AC_DEFINE(ENABLE_QT5)
    R="$R qt5"
fi
AC_SUBST(ENABLE_QT5)

build_vcl_plugins="$R"
if test -z "$build_vcl_plugins"; then
    build_vcl_plugins="none"
fi
AC_MSG_NOTICE([VCLplugs to be built: $build_vcl_plugins])

dnl ===================================================================
dnl check for dbus support
dnl ===================================================================
ENABLE_DBUS=""
DBUS_CFLAGS=""
DBUS_LIBS=""

if test "$enable_dbus" = "no"; then
    test_dbus=no
fi

AC_MSG_CHECKING([whether to enable DBUS support])
if test "$test_dbus" = "yes"; then
    ENABLE_DBUS="TRUE"
    AC_MSG_RESULT([yes])
    PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.70)
    AC_DEFINE(ENABLE_DBUS)
    DBUS_CFLAGS=$(printf '%s' "$DBUS_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${DBUS_LIBS}"
    DBUS_LIBS="${filteredlibs}"
else
    AC_MSG_RESULT([no])
fi

AC_SUBST(ENABLE_DBUS)
AC_SUBST(DBUS_CFLAGS)
AC_SUBST(DBUS_LIBS)

AC_MSG_CHECKING([whether to enable Impress remote control])
if test -n "$enable_sdremote" -a "$enable_sdremote" != "no"; then
    AC_MSG_RESULT([yes])
    ENABLE_SDREMOTE=TRUE
    AC_MSG_CHECKING([whether to enable Bluetooth support in Impress remote control])

    # If not explicitly enabled or disabled, default
    if test -z "$enable_sdremote_bluetooth"; then
        case "$OS" in
        LINUX|MACOSX|WNT)
            # Default to yes for these
            enable_sdremote_bluetooth=yes
            ;;
        *)
            # otherwise no
            enable_sdremote_bluetooth=no
            ;;
        esac
    fi
    # $enable_sdremote_bluetooth is guaranteed non-empty now

    if test "$enable_sdremote_bluetooth" != "no"; then
        if test "$OS" = "LINUX"; then
            if test "$ENABLE_DBUS" = "TRUE"; then
                AC_MSG_RESULT([yes])
                ENABLE_SDREMOTE_BLUETOOTH=TRUE
                dnl ===================================================================
                dnl Check for system bluez
                dnl ===================================================================
                AC_MSG_CHECKING([which Bluetooth header to use])
                if test "$with_system_bluez" = "yes"; then
                    AC_MSG_RESULT([external])
                    AC_CHECK_HEADER(bluetooth/bluetooth.h, [],
                        [AC_MSG_ERROR(bluetooth.h not found. install bluez)], [])
                    SYSTEM_BLUEZ=TRUE
                else
                    AC_MSG_RESULT([internal])
                    SYSTEM_BLUEZ=
                fi
            else
                AC_MSG_RESULT([no, dbus disabled])
                ENABLE_SDREMOTE_BLUETOOTH=
                SYSTEM_BLUEZ=
            fi
        else
            AC_MSG_RESULT([yes])
            ENABLE_SDREMOTE_BLUETOOTH=TRUE
            SYSTEM_BLUEZ=
        fi
    else
        AC_MSG_RESULT([no])
        ENABLE_SDREMOTE_BLUETOOTH=
        SYSTEM_BLUEZ=
    fi
else
    ENABLE_SDREMOTE=
    SYSTEM_BLUEZ=
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_SDREMOTE)
AC_SUBST(ENABLE_SDREMOTE_BLUETOOTH)
AC_SUBST(SYSTEM_BLUEZ)

dnl ===================================================================
dnl Check whether the gtk 2.0 libraries are available.
dnl ===================================================================

GTK_CFLAGS=""
GTK_LIBS=""
ENABLE_SYSTRAY_GTK=""
if test  "$test_gtk" = "yes"; then

    if test "$ENABLE_GTK" = "TRUE"; then
        PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.18.0 gdk-pixbuf-2.0 >= 2.2 ,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages]))
        GTK_CFLAGS=$(printf '%s' "$GTK_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${GTK_LIBS}"
        GTK_LIBS="${filteredlibs}"
        PKG_CHECK_MODULES(GTHREAD, gthread-2.0,,AC_MSG_ERROR([requirements to build the gtk-plugin not met. Use --disable-gtk or install the missing packages]))
        BUILD_TYPE="$BUILD_TYPE GTK"
        GTHREAD_CFLAGS=$(printf '%s' "$GTK_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${GTHREAD_LIBS}"
        GTHREAD_LIBS="${filteredlibs}"

        if test "x$enable_systray" = "xyes"; then
            ENABLE_SYSTRAY_GTK="TRUE"
        fi

        AC_MSG_CHECKING([whether to enable Gtk print dialog support])
        PKG_CHECK_MODULES([GTK_PRINT], [gtk+-unix-print-2.0 >= 2.10.0],
                          [ENABLE_GTK_PRINT="TRUE"],
                          [ENABLE_GTK_PRINT=""])
        GTK_PRINT_CFLAGS=$(printf '%s' "$GTK_PRINT_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${GTK_PRINT_LIBS}"
        GTK_PRINT_LIBS="${filteredlibs}"
    fi

    if test "$ENABLE_GTK" = "TRUE" || test "$ENABLE_GTK3" = "TRUE"; then
        AC_MSG_CHECKING([whether to enable GIO support])
        if test "$_os" != "WINNT" -a "$_os" != "Darwin" -a "$enable_gio" = "yes"; then
            dnl Need at least 2.26 for the dbus support.
            PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.26],
                              [ENABLE_GIO="TRUE"], [ENABLE_GIO=""])
            if test "$ENABLE_GIO" = "TRUE"; then
                AC_DEFINE(ENABLE_GIO)
                GIO_CFLAGS=$(printf '%s' "$GIO_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
                FilterLibs "${GIO_LIBS}"
                GIO_LIBS="${filteredlibs}"
            fi
        else
            AC_MSG_RESULT([no])
        fi
    fi
fi
AC_SUBST(ENABLE_GIO)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)
AC_SUBST(ENABLE_SYSTRAY_GTK)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
AC_SUBST(GTHREAD_CFLAGS)
AC_SUBST(GTHREAD_LIBS)
AC_SUBST([ENABLE_GTK_PRINT])
AC_SUBST([GTK_PRINT_CFLAGS])
AC_SUBST([GTK_PRINT_LIBS])


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

SPLIT_APP_MODULES=""
if test "$enable_split_app_modules" = "yes"; then
    SPLIT_APP_MODULES="TRUE"
fi
AC_SUBST(SPLIT_APP_MODULES)

SPLIT_OPT_FEATURES=""
if test "$enable_split_opt_features" = "yes"; then
    SPLIT_OPT_FEATURES="TRUE"
fi
AC_SUBST(SPLIT_OPT_FEATURES)

if test $_os = Darwin -o $_os = WINNT -o $_os = iOS; then
    if test "$enable_cairo_canvas" = yes; then
        AC_MSG_ERROR([The cairo canvas should not be used for this platform])
    fi
    enable_cairo_canvas=no
elif test -z "$enable_cairo_canvas"; then
    enable_cairo_canvas=yes
fi

ENABLE_CAIRO_CANVAS=""
if test "$enable_cairo_canvas" = "yes"; then
    test_cairo=yes
    ENABLE_CAIRO_CANVAS="TRUE"
    AC_DEFINE(ENABLE_CAIRO_CANVAS)
fi
AC_SUBST(ENABLE_CAIRO_CANVAS)

dnl ===================================================================
dnl Check whether the GStreamer libraries are available.
dnl It's possible to build avmedia with both GStreamer backends!
dnl ===================================================================

ENABLE_GSTREAMER_1_0=""

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

    AC_MSG_CHECKING([whether to enable the new GStreamer 1.0 avmedia backend])
    if test "$enable_avmedia" = yes -a "$enable_gstreamer_1_0" != no; then
        ENABLE_GSTREAMER_1_0="TRUE"
        AC_MSG_RESULT([yes])
        PKG_CHECK_MODULES( [GSTREAMER_1_0], [gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0] )
        GSTREAMER_1_0_CFLAGS=$(printf '%s' "$GSTREAMER_1_0_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${GSTREAMER_1_0_LIBS}"
        GSTREAMER_1_0_LIBS="${filteredlibs}"
    else
        AC_MSG_RESULT([no])
    fi
fi
AC_SUBST(GSTREAMER_1_0_CFLAGS)
AC_SUBST(GSTREAMER_1_0_LIBS)
AC_SUBST(ENABLE_GSTREAMER_1_0)


ENABLE_GSTREAMER_0_10=""
if test "$build_gstreamer_0_10" = "yes"; then

    AC_MSG_CHECKING([whether to enable the GStreamer 0.10 avmedia backend])
    if test "$enable_avmedia" = yes -a "$enable_gstreamer_0_10" != no; then
        ENABLE_GSTREAMER_0_10="TRUE"
        AC_MSG_RESULT([yes])
        PKG_CHECK_MODULES( [GSTREAMER_0_10], [gstreamer-0.10 gstreamer-plugins-base-0.10 gstreamer-pbutils-0.10 gstreamer-interfaces-0.10],, [
            PKG_CHECK_MODULES( [GSTREAMER_0_10], [gstreamer-0.10 gstreamer-plugins-base-0.10 gstreamer-pbutils-0.10] )
        ])
        GSTREAMER_0_10_CFLAGS=$(printf '%s' "$GSTREAMER_0_10_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${GSTREAMER_0_10_LIBS}"
        GSTREAMER_0_10_LIBS="${filteredlibs}"
    else
        AC_MSG_RESULT([no])
    fi
fi

AC_SUBST(GSTREAMER_0_10_CFLAGS)
AC_SUBST(GSTREAMER_0_10_LIBS)
AC_SUBST(ENABLE_GSTREAMER_0_10)

dnl ===================================================================
dnl Check whether to build the VLC avmedia backend
dnl ===================================================================

ENABLE_VLC=""

AC_MSG_CHECKING([whether to enable the VLC avmedia backend])
if test "$enable_avmedia" = yes -a $_os != iOS -a $_os != Android -a "$enable_vlc" = yes; then
    ENABLE_VLC="TRUE"
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_VLC)

ENABLE_OPENGL_TRANSITIONS=
ENABLE_OPENGL_CANVAS=
if test $_os = iOS -o $_os = Android; then
   : # disable
elif test "$_os" = "Darwin"; then
    # We use frameworks on Mac OS X, no need for detail checks
    ENABLE_OPENGL_TRANSITIONS=TRUE
    AC_DEFINE(HAVE_FEATURE_OPENGL,1)
    ENABLE_OPENGL_CANVAS=TRUE
elif test $_os = WINNT; then
    ENABLE_OPENGL_TRANSITIONS=TRUE
    AC_DEFINE(HAVE_FEATURE_OPENGL,1)
    ENABLE_OPENGL_CANVAS=TRUE
else
    if test "$USING_X11" = TRUE; then
        AC_CHECK_LIB(GL, glBegin, [:], AC_MSG_ERROR([libGL required.]))
        ENABLE_OPENGL_TRANSITIONS=TRUE
        AC_DEFINE(HAVE_FEATURE_OPENGL,1)
        ENABLE_OPENGL_CANVAS=TRUE
    fi
fi

AC_SUBST(ENABLE_OPENGL_TRANSITIONS)
AC_SUBST(ENABLE_OPENGL_CANVAS)

dnl =================================================
dnl Check whether to build with OpenCL support.
dnl =================================================

if test $_os != iOS -a $_os != Android; then
    # OPENCL in BUILD_TYPE and HAVE_FEATURE_OPENCL tell that OpenCL is potentially available on the
    # platform (optional at run-time, used through clew).
    BUILD_TYPE="$BUILD_TYPE OPENCL"
    AC_DEFINE(HAVE_FEATURE_OPENCL)
fi

dnl =================================================
dnl Check whether to build with dconf support.
dnl =================================================

if test $_os != Android -a $_os != iOS -a "$enable_dconf" != no; then
    PKG_CHECK_MODULES([DCONF], [dconf >= 0.15.2], [], [
        if test "$enable_dconf" = yes; then
            AC_MSG_ERROR([dconf not found])
        else
            enable_dconf=no
        fi])
fi
AC_MSG_CHECKING([whether to enable dconf])
if test $_os = Android -o $_os = iOS -o "$enable_dconf" = no; then
    DCONF_CFLAGS=
    DCONF_LIBS=
    ENABLE_DCONF=
    AC_MSG_RESULT([no])
else
    ENABLE_DCONF=TRUE
    AC_DEFINE(ENABLE_DCONF)
    AC_MSG_RESULT([yes])
fi
AC_SUBST([DCONF_CFLAGS])
AC_SUBST([DCONF_LIBS])
AC_SUBST([ENABLE_DCONF])

# pdf import?
AC_MSG_CHECKING([whether to build the PDF import feature])
ENABLE_PDFIMPORT=
if test $_os != Android -a $_os != iOS -a \( -z "$enable_pdfimport" -o "$enable_pdfimport" = yes \); then
    AC_MSG_RESULT([yes])
    ENABLE_PDFIMPORT=TRUE
    AC_DEFINE(HAVE_FEATURE_PDFIMPORT)
else
    AC_MSG_RESULT([no])
fi

# Pdfium?
AC_MSG_CHECKING([whether to build PDFium])
ENABLE_PDFIUM=
if test \( -z "$enable_pdfium" -a "$ENABLE_PDFIMPORT" == "TRUE" \) -o "$enable_pdfium" = yes; then
    AC_MSG_RESULT([yes])
    ENABLE_PDFIUM=TRUE
    AC_DEFINE(HAVE_FEATURE_PDFIUM)
    BUILD_TYPE="$BUILD_TYPE PDFIUM"
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_PDFIUM)

dnl ===================================================================
dnl Check for poppler
dnl ===================================================================
ENABLE_POPPLER=
AC_MSG_CHECKING([whether to build Poppler])
if test \( -z "$enable_poppler" -a "$ENABLE_PDFIMPORT" == "TRUE" \) -o "$enable_poppler" = yes; then
    AC_MSG_RESULT([yes])
    ENABLE_POPPLER=TRUE
    AC_DEFINE(HAVE_FEATURE_POPPLER)
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_POPPLER)

if test "$ENABLE_PDFIMPORT" == "TRUE" -a "$ENABLE_POPPLER" != "TRUE" -a "$ENABLE_PDFIUM" != "TRUE"; then
    AC_MSG_ERROR([Cannot import PDF without either Pdfium or Poppler; please enable either of them.])
fi

if test "$ENABLE_PDFIMPORT" != "TRUE" -a \( "$ENABLE_POPPLER" == "TRUE" -o "$ENABLE_PDFIUM" == "TRUE" \); then
    AC_MSG_ERROR([Cannot enable Pdfium or Poppler when PDF importing is disabled; please enable PDF import first.])
fi

if test "$ENABLE_PDFIMPORT" == "TRUE" -a "$ENABLE_POPPLER" == "TRUE"; then
    dnl ===================================================================
    dnl Check for system poppler
    dnl ===================================================================
    AC_MSG_CHECKING([which PDF import poppler to use])
    if test "$with_system_poppler" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_POPPLER=TRUE
        PKG_CHECK_MODULES( POPPLER, poppler >= 0.12.0 )
        AC_LANG_PUSH([C++])
        save_CXXFLAGS=$CXXFLAGS
        save_CPPFLAGS=$CPPFLAGS
        CXXFLAGS="$CXXFLAGS $POPPLER_CFLAGS"
        CPPFLAGS="$CPPFLAGS $POPPLER_CFLAGS"
        AC_CHECK_HEADER([cpp/poppler-version.h],
            [AC_DEFINE([HAVE_POPPLER_VERSION_H], 1)],
            [])
        CXXFLAGS=$save_CXXFLAGS
        CPPFLAGS=$save_CPPFLAGS
        AC_LANG_POP([C++])
        POPPLER_CFLAGS=$(printf '%s' "$POPPLER_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")

        FilterLibs "${POPPLER_LIBS}"
        POPPLER_LIBS="${filteredlibs}"
    else
        AC_MSG_RESULT([internal])
        SYSTEM_POPPLER=
        BUILD_TYPE="$BUILD_TYPE POPPLER"
        AC_DEFINE([HAVE_POPPLER_VERSION_H], 1)
    fi
    AC_DEFINE([ENABLE_PDFIMPORT],1)
fi
AC_SUBST(ENABLE_PDFIMPORT)
AC_SUBST(SYSTEM_POPPLER)
AC_SUBST(POPPLER_CFLAGS)
AC_SUBST(POPPLER_LIBS)

SYSTEM_GPGMEPP=

if test "$build_for_ios" = "YES"; then
    AC_MSG_CHECKING([whether gpgmepp should be disabled due to iOS])
    AC_MSG_RESULT([yes])
elif test "$enable_mpl_subset" = "yes"; then
    AC_MSG_CHECKING([whether gpgmepp should be disabled due to building just MPL])
    AC_MSG_RESULT([yes])
elif test "$_os" = "Linux" -o "$_os" = "Darwin" -o "$_os" = "WINNT" ; then
    dnl ===================================================================
    dnl Check for system gpgme
    dnl ===================================================================
    AC_MSG_CHECKING([which gpgmepp to use])
    if test "$with_system_gpgmepp" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_GPGMEPP=TRUE

        # C++ library doesn't come with fancy gpgmepp-config, check for headers the old-fashioned way
        AC_CHECK_HEADER(gpgme++/gpgmepp_version.h, [ GPGMEPP_CFLAGS=-I/usr/include/gpgme++ ],
            [AC_MSG_ERROR([gpgmepp headers not found, install gpgmepp development package])], [])
        # progress_callback is the only func with plain C linkage
        # checking for it also filters out older, KDE-dependent libgpgmepp versions
        AC_CHECK_LIB(gpgmepp, progress_callback, [ GPGMEPP_LIBS=-lgpgmepp ],
            [AC_MSG_ERROR(gpgmepp not found or not functional)], [])
        AC_CHECK_HEADER(gpgme.h, [],
            [AC_MSG_ERROR([gpgme headers not found, install gpgme development package])], [])
    else
        AC_MSG_RESULT([internal])
        BUILD_TYPE="$BUILD_TYPE LIBGPGERROR LIBASSUAN GPGMEPP"
        AC_DEFINE([GPGME_CAN_EXPORT_MINIMAL_KEY])

        GPG_ERROR_CFLAGS="-I${WORKDIR}/UnpackedTarball/libgpg-error/src"
        LIBASSUAN_CFLAGS="-I${WORKDIR}/UnpackedTarball/libassuan/src"
        if test "$_os" != "WINNT"; then
            GPG_ERROR_LIBS="-L${WORKDIR}/UnpackedTarball/libgpg-error/src/.libs -lgpg-error"
            LIBASSUAN_LIBS="-L${WORKDIR}/UnpackedTarball/libassuan/src/.libs -lassuan"
        elif test "$host_cpu" = "i686" -a "$WINDOWS_SDK_ARCH" = "x64"; then
            AC_MSG_ERROR(gpgme cannot be built on cygwin32 for Win64.)
        fi
    fi
    ENABLE_GPGMEPP=TRUE
    AC_DEFINE([HAVE_FEATURE_GPGME])
    AC_PATH_PROG(GPG, gpg)
    # TODO: Windows's cygwin gpg does not seem to work with our gpgme,
    # so let's exclude that manually for the moment
    if test -n "$GPG" -a "$_os" != "WINNT"; then
        # make sure we not only have a working gpgme, but a full working
        # gpg installation to run OpenPGP signature verification
        AC_DEFINE([HAVE_FEATURE_GPGVERIFY])
    fi
    if test "$_os" = "Linux"; then
      uid=`id -u`
      AC_MSG_CHECKING([for /run/user/$uid])
      if test -d /run/user/$uid; then
        AC_MSG_RESULT([yes])
        AC_PATH_PROG(GPGCONF, gpgconf)
        AC_MSG_CHECKING([for gpgconf --create-socketdir... ])
        if $GPGCONF --dump-options > /dev/null ; then
          if $GPGCONF --dump-options | grep -q create-socketdir ; then
	    AC_MSG_RESULT([yes])
            AC_DEFINE([HAVE_GPGCONF_SOCKETDIR])
          else
            AC_MSG_RESULT([no])
          fi
        else
	  AC_MSG_RESULT([no. missing or broken gpgconf?])
        fi
      else
        AC_MSG_RESULT([no])
     fi
   fi
fi
AC_SUBST(ENABLE_GPGMEPP)
AC_SUBST(SYSTEM_GPGMEPP)
AC_SUBST(GPG_ERROR_CFLAGS)
AC_SUBST(GPG_ERROR_LIBS)
AC_SUBST(LIBASSUAN_CFLAGS)
AC_SUBST(LIBASSUAN_LIBS)
AC_SUBST(GPGMEPP_CFLAGS)
AC_SUBST(GPGMEPP_LIBS)
AC_SUBST(GPGCONF)
AC_SUBST(HAVE_GPGCONF_SOCKETDIR)

AC_MSG_CHECKING([whether to build the Wiki Publisher extension])
if test "x$enable_ext_wiki_publisher" = "xyes" -a "x$enable_extension_integration" != "xno" -a "$with_java" != "no"; then
    AC_MSG_RESULT([yes])
    ENABLE_MEDIAWIKI=TRUE
    BUILD_TYPE="$BUILD_TYPE XSLTML"
    if test  "x$with_java" = "xno"; then
        AC_MSG_ERROR([Wiki Publisher requires Java! Enable Java if you want to build it.])
    fi
else
    AC_MSG_RESULT([no])
    ENABLE_MEDIAWIKI=
    SCPDEFS="$SCPDEFS -DWITHOUT_EXTENSION_MEDIAWIKI"
fi
AC_SUBST(ENABLE_MEDIAWIKI)

AC_MSG_CHECKING([whether to build the Report Builder])
if test "$enable_report_builder" != "no" -a "$with_java" != "no"; then
    AC_MSG_RESULT([yes])
    ENABLE_REPORTBUILDER=TRUE
    AC_MSG_CHECKING([which jfreereport libs to use])
    if test "$with_system_jfreereport" = "yes"; then
        SYSTEM_JFREEREPORT=TRUE
        AC_MSG_RESULT([external])
        if test -z $SAC_JAR; then
            SAC_JAR=/usr/share/java/sac.jar
        fi
        if ! test -f $SAC_JAR; then
             AC_MSG_ERROR(sac.jar not found.)
        fi

        if test -z $LIBXML_JAR; then
            if test -f /usr/share/java/libxml-1.0.0.jar; then
                LIBXML_JAR=/usr/share/java/libxml-1.0.0.jar
            elif test -f /usr/share/java/libxml.jar; then
                LIBXML_JAR=/usr/share/java/libxml.jar
            else
                AC_MSG_ERROR(libxml.jar replacement not found.)
            fi
        elif ! test -f $LIBXML_JAR; then
            AC_MSG_ERROR(libxml.jar not found.)
        fi

        if test -z $FLUTE_JAR; then
            if test -f/usr/share/java/flute-1.3.0.jar; then
                FLUTE_JAR=/usr/share/java/flute-1.3.0.jar
            elif test -f /usr/share/java/flute.jar; then
                FLUTE_JAR=/usr/share/java/flute.jar
            else
                AC_MSG_ERROR(flute-1.3.0.jar replacement not found.)
            fi
        elif ! test -f $FLUTE_JAR; then
            AC_MSG_ERROR(flute-1.3.0.jar not found.)
        fi

        if test -z $JFREEREPORT_JAR; then
            if test -f /usr/share/java/flow-engine-0.9.2.jar; then
                JFREEREPORT_JAR=/usr/share/java/flow-engine-0.9.2.jar
            elif test -f /usr/share/java/flow-engine.jar; then
                JFREEREPORT_JAR=/usr/share/java/flow-engine.jar
            else
                AC_MSG_ERROR(jfreereport.jar replacement not found.)
            fi
        elif ! test -f  $JFREEREPORT_JAR; then
                AC_MSG_ERROR(jfreereport.jar not found.)
        fi

        if test -z $LIBLAYOUT_JAR; then
            if test -f /usr/share/java/liblayout-0.2.9.jar; then
                LIBLAYOUT_JAR=/usr/share/java/liblayout-0.2.9.jar
            elif test -f /usr/share/java/liblayout.jar; then
                LIBLAYOUT_JAR=/usr/share/java/liblayout.jar
            else
                AC_MSG_ERROR(liblayout.jar replacement not found.)
            fi
        elif ! test -f $LIBLAYOUT_JAR; then
                AC_MSG_ERROR(liblayout.jar not found.)
        fi

        if test -z $LIBLOADER_JAR; then
            if test -f /usr/share/java/libloader-1.0.0.jar; then
                LIBLOADER_JAR=/usr/share/java/libloader-1.0.0.jar
            elif test -f /usr/share/java/libloader.jar; then
                LIBLOADER_JAR=/usr/share/java/libloader.jar
            else
                AC_MSG_ERROR(libloader.jar replacement not found.)
            fi
        elif ! test -f  $LIBLOADER_JAR; then
            AC_MSG_ERROR(libloader.jar not found.)
        fi

        if test -z $LIBFORMULA_JAR; then
            if test -f /usr/share/java/libformula-0.2.0.jar; then
                LIBFORMULA_JAR=/usr/share/java/libformula-0.2.0.jar
            elif test -f /usr/share/java/libformula.jar; then
                LIBFORMULA_JAR=/usr/share/java/libformula.jar
            else
                AC_MSG_ERROR(libformula.jar replacement not found.)
            fi
        elif ! test -f $LIBFORMULA_JAR; then
                AC_MSG_ERROR(libformula.jar not found.)
        fi

        if test -z $LIBREPOSITORY_JAR; then
            if test -f /usr/share/java/librepository-1.0.0.jar; then
                LIBREPOSITORY_JAR=/usr/share/java/librepository-1.0.0.jar
            elif test -f /usr/share/java/librepository.jar; then
                LIBREPOSITORY_JAR=/usr/share/java/librepository.jar
            else
                AC_MSG_ERROR(librepository.jar replacement not found.)
            fi
        elif ! test -f $LIBREPOSITORY_JAR; then
            AC_MSG_ERROR(librepository.jar not found.)
        fi

        if test -z $LIBFONTS_JAR; then
            if test -f /usr/share/java/libfonts-1.0.0.jar; then
                LIBFONTS_JAR=/usr/share/java/libfonts-1.0.0.jar
            elif test -f /usr/share/java/libfonts.jar; then
                LIBFONTS_JAR=/usr/share/java/libfonts.jar
            else
                AC_MSG_ERROR(libfonts.jar replacement not found.)
            fi
        elif ! test -f $LIBFONTS_JAR; then
                AC_MSG_ERROR(libfonts.jar not found.)
        fi

        if test -z $LIBSERIALIZER_JAR; then
            if test -f /usr/share/java/libserializer-1.0.0.jar; then
                LIBSERIALIZER_JAR=/usr/share/java/libserializer-1.0.0.jar
            elif test -f /usr/share/java/libserializer.jar; then
                LIBSERIALIZER_JAR=/usr/share/java/libserializer.jar
            else
                AC_MSG_ERROR(libserializer.jar replacement not found.)
            fi
        elif ! test -f $LIBSERIALIZER_JAR; then
                AC_MSG_ERROR(libserializer.jar not found.)
        fi

        if test -z $LIBBASE_JAR; then
            if test -f /usr/share/java/libbase-1.0.0.jar; then
                LIBBASE_JAR=/usr/share/java/libbase-1.0.0.jar
            elif test -f /usr/share/java/libbase.jar; then
                LIBBASE_JAR=/usr/share/java/libbase.jar
            else
                AC_MSG_ERROR(libbase.jar replacement not found.)
            fi
        elif ! test -f $LIBBASE_JAR; then
            AC_MSG_ERROR(libbase.jar not found.)
        fi

    else
        AC_MSG_RESULT([internal])
        SYSTEM_JFREEREPORT=
        BUILD_TYPE="$BUILD_TYPE JFREEREPORT"
    fi
else
    AC_MSG_RESULT([no])
    ENABLE_REPORTBUILDER=
    SYSTEM_JFREEREPORT=
fi
AC_SUBST(ENABLE_REPORTBUILDER)
AC_SUBST(SYSTEM_JFREEREPORT)
AC_SUBST(SAC_JAR)
AC_SUBST(LIBXML_JAR)
AC_SUBST(FLUTE_JAR)
AC_SUBST(JFREEREPORT_JAR)
AC_SUBST(LIBBASE_JAR)
AC_SUBST(LIBLAYOUT_JAR)
AC_SUBST(LIBLOADER_JAR)
AC_SUBST(LIBFORMULA_JAR)
AC_SUBST(LIBREPOSITORY_JAR)
AC_SUBST(LIBFONTS_JAR)
AC_SUBST(LIBSERIALIZER_JAR)

# this has to be here because both the Wiki Publisher and the SRB use
# commons-logging
COMMONS_LOGGING_VERSION=1.2
if test "$ENABLE_REPORTBUILDER" = "TRUE"; then
    AC_MSG_CHECKING([which Apache commons-* libs to use])
    if test "$with_system_apache_commons" = "yes"; then
        SYSTEM_APACHE_COMMONS=TRUE
        AC_MSG_RESULT([external])
        if test -z $COMMONS_LOGGING_JAR; then
            if test -f /usr/share/java/commons-logging-${COMMONS_LOGGING_VERSION}.jar; then
               COMMONS_LOGGING_JAR=/usr/share/java/commons-logging-${COMMONS_LOGGING_VERSION}.jar
           elif test -f /usr/share/java/commons-logging.jar; then
                COMMONS_LOGGING_JAR=/usr/share/java/commons-logging.jar
            else
                AC_MSG_ERROR(commons-logging.jar replacement not found.)
            fi
        elif ! test -f $COMMONS_LOGGING_JAR; then
            AC_MSG_ERROR(commons-logging.jar not found.)
        fi
    else
        AC_MSG_RESULT([internal])
        SYSTEM_APACHE_COMMONS=
        BUILD_TYPE="$BUILD_TYPE APACHE_COMMONS"
    fi
fi
AC_SUBST(SYSTEM_APACHE_COMMONS)
AC_SUBST(COMMONS_LOGGING_JAR)
AC_SUBST(COMMONS_LOGGING_VERSION)

# scripting provider for BeanShell?
AC_MSG_CHECKING([whether to build support for scripts in BeanShell])
if test "${enable_scripting_beanshell}" != "no" -a "x$with_java" != "xno"; then
    AC_MSG_RESULT([yes])
    ENABLE_SCRIPTING_BEANSHELL=TRUE

    dnl ===================================================================
    dnl Check for system beanshell
    dnl ===================================================================
    AC_MSG_CHECKING([which beanshell to use])
    if test "$with_system_beanshell" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_BSH=TRUE
        if test -z $BSH_JAR; then
            BSH_JAR=/usr/share/java/bsh.jar
        fi
        if ! test -f $BSH_JAR; then
            AC_MSG_ERROR(bsh.jar not found.)
        fi
    else
        AC_MSG_RESULT([internal])
        SYSTEM_BSH=
        BUILD_TYPE="$BUILD_TYPE BSH"
    fi
else
    AC_MSG_RESULT([no])
    ENABLE_SCRIPTING_BEANSHELL=
    SCPDEFS="$SCPDEFS -DWITHOUT_SCRIPTING_BEANSHELL"
fi
AC_SUBST(ENABLE_SCRIPTING_BEANSHELL)
AC_SUBST(SYSTEM_BSH)
AC_SUBST(BSH_JAR)

# scripting provider for JavaScript?
AC_MSG_CHECKING([whether to build support for scripts in JavaScript])
if test "${enable_scripting_javascript}" != "no" -a "x$with_java" != "xno"; then
    AC_MSG_RESULT([yes])
    ENABLE_SCRIPTING_JAVASCRIPT=TRUE

    dnl ===================================================================
    dnl Check for system rhino
    dnl ===================================================================
    AC_MSG_CHECKING([which rhino to use])
    if test "$with_system_rhino" = "yes"; then
        AC_MSG_RESULT([external])
        SYSTEM_RHINO=TRUE
        if test -z $RHINO_JAR; then
            RHINO_JAR=/usr/share/java/js.jar
        fi
        if ! test -f $RHINO_JAR; then
            AC_MSG_ERROR(js.jar not found.)
        fi
    else
        AC_MSG_RESULT([internal])
        SYSTEM_RHINO=
        BUILD_TYPE="$BUILD_TYPE RHINO"
    fi
else
    AC_MSG_RESULT([no])
    ENABLE_SCRIPTING_JAVASCRIPT=
    SCPDEFS="$SCPDEFS -DWITHOUT_SCRIPTING_JAVASCRIPT"
fi
AC_SUBST(ENABLE_SCRIPTING_JAVASCRIPT)
AC_SUBST(SYSTEM_RHINO)
AC_SUBST(RHINO_JAR)

# This is only used in KDE3/KDE4 checks to determine if /usr/lib64
# paths should be added to library search path. So lets put all 64-bit
# platforms there.
supports_multilib=
case "$host_cpu" in
x86_64 | powerpc64 | powerpc64le | s390x | aarch64 | mips64 | mips64el)
    if test "$SAL_TYPES_SIZEOFLONG" = "8"; then
        supports_multilib="yes"
    fi
    ;;
*)
    ;;
esac

dnl ===================================================================
dnl KDE4 Integration
dnl ===================================================================

KDE4_CFLAGS=""
KDE4_LIBS=""
QMAKE4="qmake"
MOC4="moc"
KDE4_GLIB_CFLAGS=""
KDE4_GLIB_LIBS=""
KDE4_HAVE_GLIB=""
if test "$test_kde4" = "yes" -a "$ENABLE_KDE4" = "TRUE"; then
    qt4_incdirs="$QT4INC /usr/include/qt4 /usr/include $x_includes"
    qt4_libdirs="$QT4LIB /usr/lib/qt4 /usr/lib $x_libraries"

    kde4_incdirs="/usr/include /usr/include/kde4 $x_includes"
    kde4_libdirs="/usr/lib /usr/lib/kde4 /usr/lib/kde4/devel $x_libraries"

    if test -n "$supports_multilib"; then
        qt4_libdirs="$qt4_libdirs /usr/lib64/qt4 /usr/lib64/qt /usr/lib64"
        kde4_libdirs="$kde4_libdirs /usr/lib64 /usr/lib64/kde4 /usr/lib64/kde4/devel"
    fi

    if test -n "$QTDIR"; then
        qt4_incdirs="$QTDIR/include $qt4_incdirs"
        if test -z "$supports_multilib"; then
            qt4_libdirs="$QTDIR/lib $qt4_libdirs"
        else
            qt4_libdirs="$QTDIR/lib64 $QTDIR/lib $qt4_libdirs"
        fi
    fi
    if test -n "$QT4DIR"; then
        qt4_incdirs="$QT4DIR/include $qt4_incdirs"
        if test -z "$supports_multilib"; then
            qt4_libdirs="$QT4DIR/lib $qt4_libdirs"
        else
            qt4_libdirs="$QT4DIR/lib64 $QT4DIR/lib $qt4_libdirs"
        fi
    fi

    if test -n "$KDEDIR"; then
        kde4_incdirs="$KDEDIR/include $kde4_incdirs"
        if test -z "$supports_multilib"; then
            kde4_libdirs="$KDEDIR/lib $kde4_libdirs"
        else
            kde4_libdirs="$KDEDIR/lib64 $KDEDIR/lib $kde4_libdirs"
        fi
    fi
    if test -n "$KDE4DIR"; then
        kde4_incdirs="$KDE4DIR/include $KDE4DIR/include/kde4 $kde4_incdirs"
        if test -z "$supports_multilib"; then
            kde4_libdirs="$KDE4DIR/lib $kde4_libdirs"
        else
            kde4_libdirs="$KDE4DIR/lib64 $KDE4DIR/lib $kde4_libdirs"
        fi
    fi

    qt4_test_include="Qt/qobject.h"
    qt4_test_library="libQtNetwork.so"
    kde4_test_include="kwindowsystem.h"
    kde4_test_library="libsolid.so"

    AC_MSG_CHECKING([for Qt4 headers])
    qt4_header_dir="no"
    for inc_dir in $qt4_incdirs; do
        if test -r "$inc_dir/$qt4_test_include"; then
            qt4_header_dir="$inc_dir"
            break
        fi
    done

    AC_MSG_RESULT([$qt4_header_dir])
    if test "x$qt4_header_dir" = "xno"; then
        AC_MSG_ERROR([Qt4 headers not found.  Please specify the root of your Qt4 installation by exporting QT4DIR before running "configure".])
    fi

    dnl Check for qmake
    AC_PATH_PROGS( QMAKE4, [qmake-qt4 qmake], no, [`dirname $qt4_header_dir`/bin:$QT4DIR/bin:$PATH] )
    if test "$QMAKE4" = "no"; then
        AC_MSG_ERROR([Qmake not found.  Please specify the root of your Qt4 installation by exporting QT4DIR before running "configure".])
    else
        qmake4_test_ver="`$QMAKE4 -v 2>&1 | sed -n -e '/^Using Qt version 4\./p'`"
        if test -z "$qmake4_test_ver"; then
            AC_MSG_ERROR([Wrong qmake for Qt4 found. Please specify the root of your Qt installation by exporting QT4DIR before running "configure".])
        fi
    fi

    qt4_libdirs="`$QMAKE4 -query QT_INSTALL_LIBS` $qt4_libdirs"
    AC_MSG_CHECKING([for Qt4 libraries])
    qt4_lib_dir="no"
    for lib_dir in $qt4_libdirs; do
        if test -r "$lib_dir/$qt4_test_library"; then
            qt4_lib_dir="$lib_dir"
            PKG_CONFIG_PATH="$qt4_lib_dir"/pkgconfig:$PKG_CONFIG_PATH
            break
        fi
    done

    AC_MSG_RESULT([$qt4_lib_dir])

    if test "x$qt4_lib_dir" = "xno"; then
        AC_MSG_ERROR([Qt4 libraries not found.  Please specify the root of your Qt4 installation by exporting QT4DIR before running "configure".])
    fi

    dnl Check for Meta Object Compiler

    AC_PATH_PROG( MOCQT4, moc-qt4, no, [`dirname $qt4_lib_dir`/bin:$QT4DIR/bin:$PATH] )
    MOC4="$MOCQT4"
    if test "$MOC4" = "no"; then
        AC_PATH_PROG( MOC4, moc, no, [`dirname $qt4_lib_dir`/bin:$QT4DIR/bin:$PATH] )
        if test "$MOC4" = "no"; then
            AC_MSG_ERROR([Qt Meta Object Compiler not found.  Please specify
the root of your Qt installation by exporting QT4DIR before running "configure".])
        fi
    fi

    dnl Check for KDE4 headers
    AC_MSG_CHECKING([for KDE4 headers])
    kde4_incdir="no"
    for kde4_check in $kde4_incdirs; do
        if test -r "$kde4_check/$kde4_test_include"; then
            kde4_incdir="$kde4_check"
            break
        fi
    done
    AC_MSG_RESULT([$kde4_incdir])
    if test "x$kde4_incdir" = "xno"; then
        AC_MSG_ERROR([KDE4 headers not found.  Please specify the root of your KDE4 installation by exporting KDE4DIR before running "configure".])
    fi
    if test "$kde4_incdir" = "/usr/include"; then kde4_incdir=; fi

    dnl Check for KDE4 libraries
    AC_MSG_CHECKING([for KDE4 libraries])
    kde4_libdir="no"
    for kde4_check in $kde4_libdirs; do
        if test -r "$kde4_check/$kde4_test_library"; then
            kde4_libdir="$kde4_check"
            break
        fi
    done

    AC_MSG_RESULT([$kde4_libdir])
    if test "x$kde4_libdir" = "xno"; then
        AC_MSG_ERROR([KDE4 libraries not found.  Please specify the root of your KDE4 installation by exporting KDE4DIR before running "configure".])
    fi

    PKG_CHECK_MODULES([QT4],[QtNetwork QtGui])
    if ! test -z "$kde4_incdir"; then
    	KDE4_CFLAGS="-I$kde4_incdir $QT4_CFLAGS -DQT_CLEAN_NAMESPACE -DQT_THREAD_SUPPORT"
    else
    	KDE4_CFLAGS="$QT4_CFLAGS -DQT_CLEAN_NAMESPACE -DQT_THREAD_SUPPORT"
    fi

    KDE4_LIBS="-L$kde4_libdir -lkio -lkfile -lkdeui -lkdecore -L$qt4_lib_dir $QT4_LIBS"
    KDE4_CFLAGS=$(printf '%s' "$KDE4_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "$KDE4_LIBS"
    KDE4_LIBS="$filteredlibs"

    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS $KDE4_CFLAGS"
    AC_MSG_CHECKING([whether KDE is >= 4.2])
       AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <kdeversion.h>

int main(int argc, char **argv) {
       if (KDE_VERSION_MAJOR == 4 && KDE_VERSION_MINOR >= 2) return 0;
       else return 1;
}
]])],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([KDE version too old])],[AC_MSG_ERROR([KDE support not tested with cross-compilation])])
    CXXFLAGS=$save_CXXFLAGS
    AC_LANG_POP([C++])

    # Glib is needed for properly handling Qt event loop with Qt's Glib integration enabled.
    # Sets also KDE4_GLIB_CFLAGS/KDE4_GLIB_LIBS if successful.
    PKG_CHECK_MODULES(KDE4_GLIB,[glib-2.0 >= 2.4],
        [
            KDE4_HAVE_GLIB=TRUE
            AC_DEFINE(KDE4_HAVE_GLIB,1)
            KDE4_GLIB_CFLAGS=$(printf '%s' "$KDE4_GLIB_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
            FilterLibs "${KDE4_GLIB_LIBS}"
            KDE4_GLIB_LIBS="${filteredlibs}"

            qt4_fix_warning=

            AC_LANG_PUSH([C++])
            # tst_exclude_socket_notifiers.moc:70:28: runtime error: member access within address 0x60d00000bb20 which does not point to an object of type 'QObjectData'
            # 0x60d00000bb20: note: object is of type 'QObjectPrivate'
            #  02 00 80 3a  90 8a 4e d2 3a 00 00 00  f0 b4 b9 a7 ff 7f 00 00  00 00 00 00 00 00 00 00  20 d8 4e d2
            #               ^~~~~~~~~~~~~~~~~~~~~~~
            #               vptr for 'QObjectPrivate'
            save_CXX=$CXX
            CXX=$(printf %s "$CXX" \
                | sed -e 's/-fno-sanitize-recover\(=[[0-9A-Za-z,_-]]*\)*//')
            save_CXXFLAGS=$CXXFLAGS
            CXXFLAGS="$CXXFLAGS $KDE4_CFLAGS"
            save_LIBS=$LIBS
            LIBS="$LIBS $KDE4_LIBS"
            AC_MSG_CHECKING([whether Qt has fixed ExcludeSocketNotifiers])

            # Prepare meta object data
            TSTBASE="tst_exclude_socket_notifiers"
            TSTMOC="${SRC_ROOT}/vcl/unx/kde4/${TSTBASE}"
            ln -fs "${TSTMOC}.hxx"
            $MOC4 "${TSTBASE}.hxx" -o "${TSTBASE}.moc"

            AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <cstdlib>
#include "tst_exclude_socket_notifiers.moc"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    exit(tst_processEventsExcludeSocket());
    return 0;
}
            ]])],[
                AC_MSG_RESULT([yes])
            ],[
                AC_MSG_RESULT([no])
                AC_MSG_WARN([native KDE4 file pickers will be disabled at runtime])
                if test -z "$qt4_fix_warning"; then
                    add_warning "native KDE4 file pickers will be disabled at runtime, Qt4 fixes needed"
                fi
                qt4_fix_warning=1
                add_warning "  https://bugreports.qt.io/browse/QTBUG-37380 (needed)"
                ],[AC_MSG_ERROR([KDE4 file pickers not tested with cross-compilation])])

            # Remove meta object data
            rm -f "${TSTBASE}."*

            AC_MSG_CHECKING([whether Qt avoids QClipboard recursion caused by posted events])

            # Prepare meta object data
            TSTBASE="tst_exclude_posted_events"
            TSTMOC="${SRC_ROOT}/vcl/unx/kde4/${TSTBASE}"
            ln -fs "${TSTMOC}.hxx"
            $MOC4 "${TSTBASE}.hxx" -o "${TSTBASE}.moc"

            AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <cstdlib>
#include "tst_exclude_posted_events.moc"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    exit(tst_excludePostedEvents());
    return 0;
}
            ]])],[
                AC_MSG_RESULT([yes])
            ],[
                AC_MSG_RESULT([no])
                AC_MSG_WARN([native KDE4 file pickers will be disabled at runtime])
                if test -z "$qt4_fix_warning"; then
                    add_warning "native KDE4 file pickers will be disabled at runtime, Qt4 fixes needed"
                fi
                qt4_fix_warning=1
                add_warning "  https://bugreports.qt.io/browse/QTBUG-34614 (needed)"
            ],[AC_MSG_ERROR([KDE4 file pickers not tested with cross-compilation])])

            # Remove meta object data
            rm -f "${TSTBASE}."*

            if test -n "$qt4_fix_warning"; then
                add_warning "  https://bugreports.qt.io/browse/QTBUG-38585 (recommended)"
            fi

            LIBS=$save_LIBS
            CXXFLAGS=$save_CXXFLAGS
            CXX=$save_CXX
            AC_LANG_POP([C++])
        ],
        AC_MSG_WARN([[No Glib found, KDE4 support will not use native file pickers!]]))
fi
AC_SUBST(KDE4_CFLAGS)
AC_SUBST(KDE4_LIBS)
AC_SUBST(MOC4)
AC_SUBST(KDE4_GLIB_CFLAGS)
AC_SUBST(KDE4_GLIB_LIBS)
AC_SUBST(KDE4_HAVE_GLIB)

dnl ===================================================================
dnl QT5 Integration
dnl ===================================================================

QT5_CFLAGS=""
QT5_LIBS=""
QMAKE5="qmake"
MOC5="moc"
QT5_GLIB_CFLAGS=""
QT5_GLIB_LIBS=""
QT5_HAVE_GLIB=""
if test \( "$test_kde5" = "yes" -a "$ENABLE_KDE5" = "TRUE" \) -o \
        \( "$test_qt5" = "yes" -a "$ENABLE_QT5" = "TRUE" \)
then
    qt5_incdirs="$QT5INC /usr/include/qt5 /usr/include $x_includes"
    qt5_libdirs="$QT5LIB /usr/lib/qt5 /usr/lib $x_libraries"

    if test -n "$supports_multilib"; then
        qt5_libdirs="$qt5_libdirs /usr/lib64/qt5 /usr/lib64/qt /usr/lib64"
    fi

    qt5_test_include="QtWidgets/qapplication.h"
    qt5_test_library="libQt5Widgets.so"

    dnl Check for qmake5
    AC_PATH_PROGS( QMAKE5, [qmake-qt5 qmake], no, [$QT5DIR/bin:$PATH] )
    if test "$QMAKE5" = "no"; then
        AC_MSG_ERROR([Qmake not found.  Please specify the root of your Qt5 installation by exporting QT5DIR before running "configure".])
    else
        qmake5_test_ver="`$QMAKE5 -v 2>&1 | sed -n -e '/^Using Qt version 5\./p'`"
        if test -z "$qmake5_test_ver"; then
            AC_MSG_ERROR([Wrong qmake for Qt5 found. Please specify the root of your Qt5 installation by exporting QT5DIR before running "configure".])
        fi
    fi

    qt5_incdirs="`$QMAKE5 -query QT_INSTALL_HEADERS` $qt5_incdirs"
    qt5_libdirs="`$QMAKE5 -query QT_INSTALL_LIBS` $qt5_libdirs"

    AC_MSG_CHECKING([for Qt5 headers])
    qt5_incdir="no"
    for inc_dir in $qt5_incdirs; do
        if test -r "$inc_dir/$qt5_test_include"; then
            qt5_incdir="$inc_dir"
            break
        fi
    done
    AC_MSG_RESULT([$qt5_incdir])
    if test "x$qt5_incdir" = "xno"; then
        AC_MSG_ERROR([Qt5 headers not found.  Please specify the root of your Qt5 installation by exporting QT5DIR before running "configure".])
    fi

    AC_MSG_CHECKING([for Qt5 libraries])
    qt5_libdir="no"
    for lib_dir in $qt5_libdirs; do
        if test -r "$lib_dir/$qt5_test_library"; then
            qt5_libdir="$lib_dir"
            break
        fi
    done
    AC_MSG_RESULT([$qt5_libdir])
    if test "x$qt5_libdir" = "xno"; then
        AC_MSG_ERROR([Qt5 libraries not found.  Please specify the root of your Qt5 installation by exporting QT5DIR before running "configure".])
    fi

    QT5_CFLAGS="-I$qt5_incdir -DQT_CLEAN_NAMESPACE -DQT_THREAD_SUPPORT"
    QT5_LIBS="-L$qt5_libdir -lQt5Core -lQt5Gui -lQt5Widgets -lQt5Network"

    dnl Check for Meta Object Compiler

    AC_PATH_PROGS( MOC5, [moc-qt5 moc], no, [`dirname $qt5_libdir`/bin:$QT5DIR/bin:$PATH] )
    if test "$MOC5" = "no"; then
        AC_MSG_ERROR([Qt Meta Object Compiler not found.  Please specify
the root of your Qt installation by exporting QT5DIR before running "configure".])
    fi

    # Glib is needed for properly handling Qt event loop with Qt's Glib integration enabled.
    # Sets also QT5_GLIB_CFLAGS/QT5_GLIB_LIBS if successful.
    PKG_CHECK_MODULES(QT5_GLIB,[glib-2.0 >= 2.4],
        [
            QT5_HAVE_GLIB=1
            AC_DEFINE(QT5_HAVE_GLIB,1)
            QT5_GLIB_CFLAGS=$(printf '%s' "$QT5_GLIB_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
            FilterLibs "${QT5_GLIB_LIBS}"
            QT5_GLIB_LIBS="${filteredlibs}"

            qt5_fix_warning=

            AC_LANG_PUSH([C++])
            # tst_exclude_socket_notifiers.moc:70:28: runtime error: member access within address 0x60d00000bb20 which does not point to an object of type 'QO
            # 0x60d00000bb20: note: object is of type 'QObjectPrivate'
            #  02 00 80 3a  90 8a 4e d2 3a 00 00 00  f0 b4 b9 a7 ff 7f 00 00  00 00 00 00 00 00 00 00  20 d8 4e d2
            #               ^~~~~~~~~~~~~~~~~~~~~~~
            #               vptr for 'QObjectPrivate'
            save_CXX=$CXX
            CXX=$(printf %s "$CXX" \
                | sed -e 's/-fno-sanitize-recover\(=[[0-9A-Za-z,_-]]*\)*//')
            save_CXXFLAGS=$CXXFLAGS
            CXXFLAGS="$CXXFLAGS $QT5_CFLAGS"
            save_LIBS=$LIBS
            LIBS="$LIBS $QT5_LIBS"
            AC_MSG_CHECKING([whether Qt has fixed ExcludeSocketNotifiers])
            # Prepare meta object data
            TSTBASE="tst_exclude_socket_notifiers"
            TSTMOC="${SRC_ROOT}/vcl/unx/qt5/${TSTBASE}"
            ln -fs "${TSTMOC}.hxx"
            $MOC5 "${TSTBASE}.hxx" -o "${TSTBASE}.moc"

            AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <cstdlib>
#include "tst_exclude_socket_notifiers.moc"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    exit(tst_processEventsExcludeSocket());
    return 0;
}
            ]])],[
                AC_MSG_RESULT([yes])
            ],[
                AC_MSG_RESULT([no])
                AC_MSG_WARN([native Qt5 file pickers will be disabled at runtime])
                if test -z "$qt5_fix_warning"; then
                    add_warning "native QT5 file pickers will be disabled at runtime, Qt5 fixes needed"
                fi
                qt5_fix_warning=1
                add_warning "  https://bugreports.qt-project.org/browse/QTBUG-37380 (needed)"
            ])

            # Remove meta object data
            rm -f "${TSTBASE}."*

            AC_MSG_CHECKING([whether Qt avoids QClipboard recursion caused by posted events])
            # Prepare meta object data
            TSTBASE="tst_exclude_posted_events"
            TSTMOC="${SRC_ROOT}/vcl/unx/qt5/${TSTBASE}"
            ln -fs "${TSTMOC}.hxx"
            $MOC5 "${TSTBASE}.hxx" -o "${TSTBASE}.moc"

            AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <cstdlib>
#include "tst_exclude_posted_events.moc"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    exit(tst_excludePostedEvents());
    return 0;
}
            ]])],[
                AC_MSG_RESULT([yes])
            ],[
                AC_MSG_RESULT([no])
                AC_MSG_WARN([native QT5 file pickers will be disabled at runtime])
                if test -z "$qt5_fix_warning"; then
                    add_warning "native QT5 file pickers will be disabled at runtime, Qt5 fixes needed"
                fi
                qt5_fix_warning=1
                add_warning "  https://bugreports.qt-project.org/browse/QTBUG-34614 (needed)"
            ])

            # Remove meta object data
            rm -f "${TSTBASE}."*

            if test -n "$qt5_fix_warning"; then
                add_warning "  https://bugreports.qt-project.org/browse/QTBUG-38585 (recommended)"
            fi

            LIBS=$save_LIBS
            CXXFLAGS=$save_CXXFLAGS
            CXX=$save_CXX
            AC_LANG_POP([C++])
        ],
        AC_MSG_WARN([[No Glib found, Qt5 support will not use native file pickers!]])
    )
fi
AC_SUBST(QT5_CFLAGS)
AC_SUBST(QT5_LIBS)
AC_SUBST(MOC5)
AC_SUBST(QT5_GLIB_CFLAGS)
AC_SUBST(QT5_GLIB_LIBS)
AC_SUBST(QT5_HAVE_GLIB)

dnl ===================================================================
dnl KDE5 Integration
dnl ===================================================================

KF5_CFLAGS=""
KF5_LIBS=""
KF5_CONFIG="kf5-config"
if test \( "$test_kde5" = "yes" -a "$ENABLE_KDE5" = "TRUE" \) -o \
        \( "$test_kf5" = "yes" -a "$ENABLE_KF5" = "TRUE" \)
then
    kf5_incdirs="$KF5INC /usr/include /usr/include/KF5 $x_includes"
    kf5_libdirs="$KF5LIB /usr/lib /usr/lib/kf5 /usr/lib/kf5/devel $x_libraries"
    if test -n "$supports_multilib"; then
        kf5_libdirs="$kf5_libdirs /usr/lib64 /usr/lib64/kf5 /usr/lib64/kf5/devel"
    fi

    kf5_test_include="kcoreaddons_version.h"
    kf5_test_library="libKF5CoreAddons.so"
    kf5_libdirs="$qt5_libdir $kf5_libdirs"

    dnl kf5 KDE4 support compatibility installed
    AC_PATH_PROG( KF5_CONFIG, $KF5_CONFIG, no, )
    if test "$KF5_CONFIG" != "no"; then
        kf5_incdirs="`$KF5_CONFIG --path include` $kf5_incdirs"
        kf5_libdirs="`$KF5_CONFIG --path lib` $kf5_libdirs"
    fi

    dnl Check for KF5 headers
    AC_MSG_CHECKING([for KF5 headers])
    kf5_incdir="no"
    for kf5_check in $kf5_incdirs; do
        if test -r "$kf5_check/$kf5_test_include"; then
            kf5_incdir="$kf5_check"
            break
        fi
    done
    AC_MSG_RESULT([$kf5_incdir])
    if test "x$kf5_incdir" = "xno"; then
        AC_MSG_ERROR([KF5 headers not found.  Please specify the root of your KF5 installation by exporting KF5DIR before running "configure".])
    fi

    dnl Check for KF5 libraries
    AC_MSG_CHECKING([for KF5 libraries])
    kf5_libdir="no"
    for kf5_check in $kf5_libdirs; do
        if test -r "$kf5_check/$kf5_test_library"; then
            kf5_libdir="$kf5_check"
            break
        fi
    done

    AC_MSG_RESULT([$kf5_libdir])
    if test "x$kf5_libdir" = "xno"; then
        AC_MSG_ERROR([KF5 libraries not found.  Please specify the root of your KF5 installation by exporting KF5DIR before running "configure".])
    fi

    PKG_CHECK_MODULES(KF5_XCB,[xcb],,[AC_MSG_ERROR([XCB not installed])])

    KF5_CFLAGS="-I$kf5_incdir -I$kf5_incdir/KCoreAddons -I$kf5_incdir/KI18n -I$kf5_incdir/KConfigCore -I$kf5_incdir/KWindowSystem -I$kf5_incdir/KIOCore -I$qt5_incdir -I$qt5_incdir/QtCore -I$qt5_incdir/QtGui -I$qt5_incdir/QtWidgets -I$qt5_incdir/QtNetwork -DQT_CLEAN_NAMESPACE -DQT_THREAD_SUPPORT $KF5_XCB_CFLAGS"
    KF5_LIBS="-L$kf5_libdir -lKF5CoreAddons -lKF5I18n -lKF5ConfigCore -lKF5WindowSystem -lKF5KIOCore -L$qt5_libdir -lQt5Core -lQt5Gui -lQt5Widgets -lQt5Network -lQt5X11Extras $KF5_XCB_LIBS"
    KF5_CFLAGS=$(printf '%s' "$KF5_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")

    AC_LANG_PUSH([C++])
    save_CXXFLAGS=$CXXFLAGS
    CXXFLAGS="$CXXFLAGS $KF5_CFLAGS"
    AC_MSG_CHECKING([whether KDE is >= 5.0])
       AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <kcoreaddons_version.h>

int main(int argc, char **argv) {
       if (KCOREADDONS_VERSION_MAJOR == 5 && KCOREADDONS_VERSION_MINOR >= 0) return 0;
       else return 1;
}
       ]])],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([KDE version too old])],[])
    CXXFLAGS=$save_CXXFLAGS
    AC_LANG_POP([C++])
fi
AC_SUBST(KF5_CFLAGS)
AC_SUBST(KF5_LIBS)

dnl ===================================================================
dnl Test whether to include Evolution 2 support
dnl ===================================================================
AC_MSG_CHECKING([whether to enable evolution 2 support])
if test "$enable_evolution2" = "yes" -o "$enable_evolution2" = "TRUE"; then
    AC_MSG_RESULT([yes])
    PKG_CHECK_MODULES(GOBJECT, gobject-2.0)
    GOBJECT_CFLAGS=$(printf '%s' "$GOBJECT_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${GOBJECT_LIBS}"
    GOBJECT_LIBS="${filteredlibs}"
    ENABLE_EVOAB2="TRUE"
else
    ENABLE_EVOAB2=""
    AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_EVOAB2)
AC_SUBST(GOBJECT_CFLAGS)
AC_SUBST(GOBJECT_LIBS)

dnl ===================================================================
dnl Test which themes to include
dnl ===================================================================
AC_MSG_CHECKING([which themes to include])
# if none given use default subset of available themes
if test "x$with_theme" = "x" -o "x$with_theme" = "xyes"; then
    with_theme="breeze breeze_dark breeze_svg colibre colibre_svg elementary elementary_svg galaxy hicontrast sifr sifr_dark tango"
    # test -z "$ENABLE_RELEASE_BUILD" && with_theme="$with_theme tango_testing"
fi

WITH_THEMES=""
if test "x$with_theme" != "xno"; then
    for theme in $with_theme; do
        case $theme in
        breeze|breeze_dark|breeze_svg|crystal|colibre|colibre_svg|elementary|elementary_svg|galaxy|hicontrast|oxygen|sifr|sifr_dark|tango|tango_testing) real_theme="$theme" ;;
        default) real_theme=galaxy ;;
        *) AC_MSG_ERROR([Unknown value for --with-theme: $theme]) ;;
        esac
        WITH_THEMES=`echo "$WITH_THEMES $real_theme"|tr '\ ' '\n'|sort|uniq|tr '\n' '\ '`
    done
fi
AC_MSG_RESULT([$WITH_THEMES])
AC_SUBST([WITH_THEMES])
# FIXME: remove this, and the convenience default->galaxy remapping after a crace period
for theme in $with_theme; do
    case $theme in
    default) AC_MSG_WARN([--with-theme=default is deprecated and will be removed, use --with-theme=galaxy]) ;;
    *) ;;
    esac
done

dnl ===================================================================
dnl Test whether to integrate helppacks into the product's installer
dnl ===================================================================
AC_MSG_CHECKING([for helppack integration])
if test "$with_helppack_integration" = "no"; then
    WITH_HELPPACK_INTEGRATION=
    AC_MSG_RESULT([no integration])
else
    WITH_HELPPACK_INTEGRATION=TRUE
    SCPDEFS="$SCPDEFS -DWITH_HELPPACK_INTEGRATION"
    AC_MSG_RESULT([integration])
fi
AC_SUBST(WITH_HELPPACK_INTEGRATION)

###############################################################################
# Extensions checking
###############################################################################
AC_MSG_CHECKING([for extensions integration])
if test "x$enable_extension_integration" != "xno"; then
    WITH_EXTENSION_INTEGRATION=TRUE
    SCPDEFS="$SCPDEFS -DWITH_EXTENSION_INTEGRATION"
    AC_MSG_RESULT([yes, use integration])
else
    WITH_EXTENSION_INTEGRATION=
    AC_MSG_RESULT([no, do not integrate])
fi
AC_SUBST(WITH_EXTENSION_INTEGRATION)

dnl Should any extra extensions be included?
dnl There are standalone tests for each of these below.
WITH_EXTRA_EXTENSIONS=
AC_SUBST([WITH_EXTRA_EXTENSIONS])

libo_CHECK_EXTENSION([ConvertTextToNumber],[CT2N],[ct2n],[ct2n],[])
libo_CHECK_EXTENSION([Numbertext],[NUMBERTEXT],[numbertext],[numbertext],[b7cae45ad2c23551fd6ccb8ae2c1f59e-numbertext_0.9.5.oxt])
if test "x$with_java" != "xno"; then
    libo_CHECK_EXTENSION([NLPSolver],[NLPSOLVER],[nlpsolver],[nlpsolver],[])
    libo_CHECK_EXTENSION([LanguageTool],[LANGUAGETOOL],[languagetool],[languagetool],[])
fi

TEST_FONTS_MISSING=0

# $1  = font family
# $2+ = accepted font mappings
test_font_map()
{
    FONT="$1" ; shift
    AC_MSG_CHECKING([font mapping for '$FONT'])
    FONTFILE="$(basename `$FCMATCH -f '%{file}' "$FONT"`)"
    FONTFILE_LOWER="$(echo $FONTFILE | $AWK '{print tolower($0)}')"

    TESTEXPR="'${FONTFILE_LOWER}' = '$(echo $FONT | $AWK '{print tolower($0)}').ttf'"
    while test "$#" -ge 1 ; do
        MAPPING="$(echo $1 | $AWK '{print tolower($0)}')"; shift
        TESTEXPR="${TESTEXPR} -o '${FONTFILE_LOWER}' = '$MAPPING-regular.ttf'"
    done
    if test $TESTEXPR
    then
        AC_MSG_RESULT([ok])
    else
        AC_MSG_WARN([unknown ($FONTFILE)])
        add_warning "unknown ($FONTFILE)"
        TEST_FONTS_MISSING=1
    fi
}

dnl ===================================================================
dnl Test whether to include fonts
dnl ===================================================================
AC_MSG_CHECKING([whether to include third-party fonts])
if test "$with_fonts" != "no"; then
    AC_MSG_RESULT([yes])
    WITH_FONTS=TRUE
    BUILD_TYPE="$BUILD_TYPE MORE_FONTS"
    AC_DEFINE(HAVE_MORE_FONTS)
else
    AC_MSG_RESULT([no])
    WITH_FONTS=
    SCPDEFS="$SCPDEFS -DWITHOUT_FONTS"
    if test "$test_fontconfig" = "yes"; then
        AC_PATH_PROG([FCMATCH], [fc-match])
        if test -z "$FCMATCH"; then
            AC_MSG_WARN([Unable to query installed fonts - unit tests disabled.])
            TEST_FONTS_MISSING=1
        else
            test_font_map 'Calibri' 'Carlito'
            test_font_map 'DejaVuSans' 'DejaVuSans'
            if test ${TEST_FONTS_MISSING} -eq 1
            then
                AC_MSG_WARN([Unknown font mappings - unit tests disabled.])
                add_warning "Unknown font mappings - unit tests disabled."
            fi
        fi
    else
        TEST_FONTS_MISSING=1
    fi
fi
AC_SUBST(WITH_FONTS)
AC_DEFINE_UNQUOTED([TEST_FONTS_MISSING], $TEST_FONTS_MISSING)

dnl Test whether to include more Google Noto fonts
dnl ===================================================================
AC_MSG_CHECKING([whether to include more Google Noto fonts])
if test "$enable_noto_font" = "" -o "$enable_noto_font" = "no" -o "$with_fonts" = "no"; then
    AC_MSG_RESULT([no])
    WITH_NOTO_FONT=
else
    AC_MSG_RESULT([yes])
    WITH_NOTO_FONT=TRUE
    BUILD_TYPE="$BUILD_TYPE NOTO_FONT"
    SCPDEFS="$SCPDEFS -DWITH_NOTO_FONT"
fi
AC_SUBST(WITH_NOTO_FONT)

dnl ===================================================================
dnl Test whether to enable online update service
dnl ===================================================================
AC_MSG_CHECKING([whether to enable online update])
ENABLE_ONLINE_UPDATE=
ENABLE_ONLINE_UPDATE_MAR=
UPDATE_CONFIG=
if test "$enable_online_update" = ""; then
    if test "$_os" = "WINNT" -o "$_os" = "Darwin"; then
        AC_MSG_RESULT([yes])
        ENABLE_ONLINE_UPDATE="TRUE"
    else
        AC_MSG_RESULT([no])
    fi
else
    if test "$enable_online_update" = "mar"; then
        AC_MSG_RESULT([yes - MAR-based online update])
        ENABLE_ONLINE_UPDATE_MAR="TRUE"
        if test "$with_update_config" = ""; then
            AC_MSG_ERROR([mar based online updater needs an update config specified with "with-update-config])
        fi
        UPDATE_CONFIG="$with_update_config"
        AC_DEFINE(HAVE_FEATURE_UPDATE_MAR)
    elif test "$enable_online_update" = "yes"; then
        AC_MSG_RESULT([yes])
        ENABLE_ONLINE_UPDATE="TRUE"
    else
        AC_MSG_RESULT([no])
    fi
fi
AC_SUBST(ENABLE_ONLINE_UPDATE)
AC_SUBST(ENABLE_ONLINE_UPDATE_MAR)
AC_SUBST(UPDATE_CONFIG)

dnl ===================================================================
dnl Test whether we need bzip2
dnl ===================================================================
SYSTEM_BZIP2=
if test "$ENABLE_ONLINE_UPDATE_MAR" = "TRUE"; then
    AC_MSG_CHECKING([whether to use system bzip2])
    if test "$with_system_bzip2" = yes; then
        SYSTEM_BZIP2=TRUE
        AC_MSG_RESULT([yes])
        PKG_CHECK_MODULES(BZIP2, bzip2)
        FilterLibs "${BZIP2_LIBS}"
        BZIP2_LIBS="${filteredlibs}"
    else
        AC_MSG_RESULT([no])
        BUILD_TYPE="$BUILD_TYPE BZIP2"
    fi
fi
AC_SUBST(SYSTEM_BZIP2)
AC_SUBST(BZIP2_CFLAGS)
AC_SUBST(BZIP2_LIBS)

dnl ===================================================================
dnl Test whether to enable extension update
dnl ===================================================================
AC_MSG_CHECKING([whether to enable extension update])
ENABLE_EXTENSION_UPDATE=
if test "x$enable_extension_update" = "xno"; then
    AC_MSG_RESULT([no])
else
    AC_MSG_RESULT([yes])
    ENABLE_EXTENSION_UPDATE="TRUE"
    AC_DEFINE(ENABLE_EXTENSION_UPDATE)
    SCPDEFS="$SCPDEFS -DENABLE_EXTENSION_UPDATE"
fi
AC_SUBST(ENABLE_EXTENSION_UPDATE)


dnl ===================================================================
dnl Test whether to create MSI with LIMITUI=1 (silent install)
dnl ===================================================================
AC_MSG_CHECKING([whether to create MSI with LIMITUI=1 (silent install)])
if test "$enable_silent_msi" = "" -o "$enable_silent_msi" = "no"; then
    AC_MSG_RESULT([no])
    ENABLE_SILENT_MSI=
else
    AC_MSG_RESULT([yes])
    ENABLE_SILENT_MSI=TRUE
    SCPDEFS="$SCPDEFS -DENABLE_SILENT_MSI"
fi
AC_SUBST(ENABLE_SILENT_MSI)

AC_MSG_CHECKING([whether and how to use Xinerama])
if test "$_os" = "Linux" -o "$_os" = "FreeBSD"; then
    if test "$x_libraries" = "default_x_libraries"; then
        XINERAMALIB=`$PKG_CONFIG --variable=libdir xinerama`
        if test "x$XINERAMALIB" = x; then
           XINERAMALIB="/usr/lib"
        fi
    else
        XINERAMALIB="$x_libraries"
    fi
    if test -e "$XINERAMALIB/libXinerama.so" -a -e "$XINERAMALIB/libXinerama.a"; then
        # we have both versions, let the user decide but use the dynamic one
        # per default
        USE_XINERAMA=TRUE
        if test -z "$with_static_xinerama" -o -n "$with_system_libs"; then
            XINERAMA_LINK=dynamic
        else
            XINERAMA_LINK=static
        fi
    elif test -e "$XINERAMALIB/libXinerama.so" -a ! -e "$XINERAMALIB/libXinerama.a"; then
        # we have only the dynamic version
        USE_XINERAMA=TRUE
        XINERAMA_LINK=dynamic
    elif test -e "$XINERAMALIB/libXinerama.a"; then
        # static version
        if echo $host_cpu | $GREP -E 'i[[3456]]86' 2>/dev/null >/dev/null; then
            USE_XINERAMA=TRUE
            XINERAMA_LINK=static
        else
            USE_XINERAMA=
            XINERAMA_LINK=none
        fi
    else
        # no Xinerama
        USE_XINERAMA=
        XINERAMA_LINK=none
    fi
    if test "$USE_XINERAMA" = "TRUE"; then
        AC_MSG_RESULT([yes, with $XINERAMA_LINK linking])
        AC_CHECK_HEADER(X11/extensions/Xinerama.h, [],
            [AC_MSG_ERROR(Xinerama header not found.)], [])
        XEXTLIBS=`$PKG_CONFIG --variable=libs xext`
        if test "x$XEXTLIB" = x; then
           XEXTLIBS="-L$XLIB -L$XINERAMALIB -lXext"
        fi
        XINERAMA_EXTRA_LIBS="$XEXTLIBS"
        if test "$_os" = "FreeBSD"; then
            XINERAMA_EXTRA_LIBS="$XINERAMA_EXTRA_LIBS -lXt"
        fi
        if test "$_os" = "Linux"; then
            XINERAMA_EXTRA_LIBS="$XINERAMA_EXTRA_LIBS -ldl"
        fi
        AC_CHECK_LIB([Xinerama], [XineramaIsActive], [:],
            [AC_MSG_ERROR(Xinerama not functional?)], [$XINERAMA_EXTRA_LIBS])
    else
        AC_MSG_RESULT([no, libXinerama not found or wrong architecture.])
    fi
else
    USE_XINERAMA=
    XINERAMA_LINK=none
    AC_MSG_RESULT([no])
fi
AC_SUBST(USE_XINERAMA)
AC_SUBST(XINERAMA_LINK)

dnl ===================================================================
dnl Test whether to build cairo or rely on the system version
dnl ===================================================================

if test "$USING_X11" = TRUE; then
    # Used in vcl/Library_vclplug_gen.mk
    test_cairo=yes
fi

if test "$test_cairo" = "yes"; then
    AC_MSG_CHECKING([whether to use the system cairo])

    : ${with_system_cairo:=$with_system_libs}
    if test "$with_system_cairo" = "yes"; then
        SYSTEM_CAIRO=TRUE
        AC_MSG_RESULT([yes])

        PKG_CHECK_MODULES( CAIRO, cairo >= 1.2.0 )
        CAIRO_CFLAGS=$(printf '%s' "$CAIRO_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${CAIRO_LIBS}"
        CAIRO_LIBS="${filteredlibs}"

        if test "$test_xrender" = "yes"; then
            AC_MSG_CHECKING([whether Xrender.h defines PictStandardA8])
            AC_LANG_PUSH([C])
            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <X11/extensions/Xrender.h>]],[[
#ifdef PictStandardA8
#else
      return fail;
#endif
]])],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, X headers too old.])])

            AC_LANG_POP([C])
        fi
    else
        SYSTEM_CAIRO=
        AC_MSG_RESULT([no])

        BUILD_TYPE="$BUILD_TYPE CAIRO"
    fi
fi

AC_SUBST(SYSTEM_CAIRO)
AC_SUBST(CAIRO_CFLAGS)
AC_SUBST(CAIRO_LIBS)

dnl ===================================================================
dnl Test whether to use avahi
dnl ===================================================================
if test "$_os" = "WINNT"; then
    # Windows uses bundled mDNSResponder
    BUILD_TYPE="$BUILD_TYPE MDNSRESPONDER"
elif test "$_os" != "Darwin" -a "$enable_avahi" = "yes"; then
    PKG_CHECK_MODULES([AVAHI], [avahi-client >= 0.6.10],
                      [ENABLE_AVAHI="TRUE"])
    AC_DEFINE(HAVE_FEATURE_AVAHI)
    AVAHI_CFLAGS=$(printf '%s' "$AVAHI_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${AVAHI_LIBS}"
    AVAHI_LIBS="${filteredlibs}"
fi

AC_SUBST(ENABLE_AVAHI)
AC_SUBST(AVAHI_CFLAGS)
AC_SUBST(AVAHI_LIBS)

dnl ===================================================================
dnl Test whether to use liblangtag
dnl ===================================================================
SYSTEM_LIBLANGTAG=
AC_MSG_CHECKING([whether to use system liblangtag])
if test "$with_system_liblangtag" = yes; then
    SYSTEM_LIBLANGTAG=TRUE
    AC_MSG_RESULT([yes])
    PKG_CHECK_MODULES( LIBLANGTAG, liblangtag >= 0.4.0)
    dnl cf. <https://bitbucket.org/tagoh/liblangtag/commits/9324836a0d1c> "Fix a build issue with inline keyword"
    PKG_CHECK_EXISTS([liblangtag >= 0.5.5], [], [AC_DEFINE([LIBLANGTAG_INLINE_FIX])])
    LIBLANGTAG_CFLAGS=$(printf '%s' "$LIBLANGTAG_CFLAGS" | sed -e "s/-I/${ISYSTEM?}/g")
    FilterLibs "${LIBLANGTAG_LIBS}"
    LIBLANGTAG_LIBS="${filteredlibs}"
else
    SYSTEM_LIBLANGTAG=
    AC_MSG_RESULT([no])
    BUILD_TYPE="$BUILD_TYPE LIBLANGTAG"
    LIBLANGTAG_CFLAGS="-I${WORKDIR}/UnpackedTarball/liblangtag"
    if test "$COM" = "MSC"; then
        LIBLANGTAG_LIBS="${WORKDIR}/UnpackedTarball/liblangtag/liblangtag/.libs/liblangtag.lib"
    else
        LIBLANGTAG_LIBS="-L${WORKDIR}/UnpackedTarball/liblangtag/liblangtag/.libs -llangtag"
    fi
fi
AC_SUBST(SYSTEM_LIBLANGTAG)
AC_SUBST(LIBLANGTAG_CFLAGS)
AC_SUBST(LIBLANGTAG_LIBS)

dnl ===================================================================
dnl Test whether to build libpng or rely on the system version
dnl ===================================================================

libo_CHECK_SYSTEM_MODULE([libpng],[LIBPNG],[libpng],["-I${WORKDIR}/UnpackedTarball/libpng"],["-L${WORKDIR}/LinkTarget/StaticLibrary -llibpng"])

dnl ===================================================================
dnl Check for runtime JVM search path
dnl ===================================================================
if test "$ENABLE_JAVA" != ""; then
    AC_MSG_CHECKING([whether to use specific JVM search path at runtime])
    if test -n "$with_jvm_path" -a "$with_jvm_path" != "no"; then
        AC_MSG_RESULT([yes])
        if ! test -d "$with_jvm_path"; then
            AC_MSG_ERROR(["$with_jvm_path" not a directory])
        fi
        if ! test -d "$with_jvm_path"jvm; then
            AC_MSG_ERROR(["$with_jvm_path"jvm not found, point with_jvm_path to \[/path/to/\]jvm])
        fi
        JVM_ONE_PATH_CHECK="$with_jvm_path"
        AC_SUBST(JVM_ONE_PATH_CHECK)
    else
        AC_MSG_RESULT([no])
    fi
fi

dnl ===================================================================
dnl Test for the presence of Ant and that it works
dnl ===================================================================

if test "$ENABLE_JAVA" != ""; then
    ANT_HOME=; export ANT_HOME
    WITH_ANT_HOME=; export WITH_ANT_HOME
    if test -z "$with_ant_home" -a -n "$LODE_HOME" ; then
        if test -x "$LODE_HOME/opt/ant/bin/ant" ; then
            if test "$_os" = "WINNT"; then
                with_ant_home="`cygpath -m $LODE_HOME/opt/ant`"
            else
                with_ant_home="$LODE_HOME/opt/ant"
            fi
        elif test -x  "$LODE_HOME/opt/bin/ant" ; then
            with_ant_home="$LODE_HOME/opt/ant"
        fi
    fi
    if test -z "$with_ant_home"; then
        AC_PATH_PROGS(ANT, [jakarta-ant ant ant.sh ant.bat ant.cmd])
    else
        if test "$_os" = "WINNT"; then
            # AC_PATH_PROGS needs unix path
            with_ant_home=`cygpath -u "$with_ant_home"`
        fi
        AbsolutePath "$with_ant_home"
        with_ant_home=$absolute_path
        AC_PATH_PROGS(ANT, [jakarta-ant ant ant.sh ant.bat ant.cmd],,$with_ant_home/bin:$PATH)
        WITH_ANT_HOME=$with_ant_home
        ANT_HOME=$with_ant_home
    fi

    if test -z "$ANT"; then
        AC_MSG_ERROR([Ant not found - Make sure it's in the path or use --with-ant-home])
    else
        # resolve relative or absolute symlink
        while test -h "$ANT"; do
            a_cwd=`pwd`
            a_basename=`basename "$ANT"`
            a_script=`ls -l "$ANT" | $SED "s/.*${a_basename} -> //g"`
            cd "`dirname "$ANT"`"
            cd "`dirname "$a_script"`"
            ANT="`pwd`"/"`basename "$a_script"`"
            cd "$a_cwd"
        done

        AC_MSG_CHECKING([if $ANT works])
        cat > conftest.java << EOF
        public class conftest {
            int testmethod(int a, int b) {
                    return a + b;
            }
        }
EOF

        cat > conftest.xml << EOF
        <project name="conftest" default="conftest">
        <target name="conftest">
            <javac srcdir="." includes="conftest.java">
            </javac>
        </target>
        </project>
EOF

        AC_TRY_COMMAND("$ANT" -buildfile conftest.xml 1>&2)
        if test $? = 0 -a -f ./conftest.class; then
            AC_MSG_RESULT([Ant works])
            if test -z "$WITH_ANT_HOME"; then
                ANT_HOME=`"$ANT" -diagnostics | $EGREP "ant.home :" | $SED -e "s#ant.home : ##g"`
                if test -z "$ANT_HOME"; then
                    ANT_HOME=`echo "$ANT" | $SED -n "s/\/bin\/ant.*\$//p"`
                fi
            else
                ANT_HOME="$WITH_ANT_HOME"
            fi
        else
            echo "configure: Ant test failed" >&5
            cat conftest.java >&5
            cat conftest.xml >&5
            AC_MSG_ERROR([Ant does not work - Some Java projects will not build!])
        fi
        rm -f conftest* core core.* *.core
    fi
    if test -z "$ANT_HOME"; then
        ANT_HOME="NO_ANT_HOME"
    else
        PathFormat "$ANT_HOME"
        ANT_HOME="$formatted_path"
        PathFormat "$ANT"
        ANT="$formatted_path"
    fi
    AC_SUBST(ANT_HOME)
    AC_SUBST(ANT)

    dnl Checking for ant.jar
    if test "$ANT_HOME" != "NO_ANT_HOME"; then
        AC_MSG_CHECKING([Ant lib directory])
        if test -f $ANT_HOME/lib/ant.jar; then
            ANT_LIB="$ANT_HOME/lib"
        else
            if test -f $ANT_HOME/ant.jar; then
                ANT_LIB="$ANT_HOME"
            else
                if test -f /usr/share/java/ant.jar; then
                    ANT_LIB=/usr/share/java
                else
                    if test -f /usr/share/ant-core/lib/ant.jar; then
                        ANT_LIB=/usr/share/ant-core/lib
                    else
                        if test -f $ANT_HOME/lib/ant/ant.jar; then
                            ANT_LIB="$ANT_HOME/lib/ant"
                        else
                            if test -f /usr/share/lib/ant/ant.jar; then
                                ANT_LIB=/usr/share/lib/ant
                            else
                                AC_MSG_ERROR([Ant libraries not found!])
                            fi
                        fi
                    fi
                fi
            fi
        fi
        PathFormat "$ANT_LIB"
        ANT_LIB="$formatted_path"
        AC_MSG_RESULT([Ant lib directory found.])
    fi
    AC_SUBST(ANT_LIB)

    ant_minver=1.6.0
    ant_minminor1=`echo $ant_minver | cut -d"." -f2`

    AC_MSG_CHECKING([whether Ant is >= $ant_minver])
    ant_version=`"$ANT" -version | $AWK '{ print $4; }'`
    ant_version_major=`echo $ant_version | cut -d. -f1`
    ant_version_minor=`echo $ant_version | cut -d. -f2`
    echo "configure: ant_version $ant_version " >&5
    echo "configure: ant_version_major $ant_version_major " >&5
    echo "configure: ant_version_minor $ant_version_minor " >&5
    if test "$ant_version_major" -ge "2"; then
        AC_MSG_RESULT([yes, $ant_version])
    elif test "$ant_version_major" = "1" -a "$ant_version_minor" -ge "$ant_minminor1"; then
        AC_MSG_RESULT([yes, $ant_version])
    else
        AC_MSG_ERROR([no, you need at least Ant >= $ant_minver])
    fi

    rm -f conftest* core core.* *.core
fi

OOO_JUNIT_JAR=
if test "$ENABLE_JAVA" != "" -a "$with_junit" != "no"; then
    AC_MSG_CHECKING([for JUnit 4])
    if test "$with_junit" = "yes"; then
        if test -n "$LODE_HOME" -a -e "$LODE_HOME/opt/share/java/junit.jar" ; then
            OOO_JUNIT_JAR="$LODE_HOME/opt/share/java/junit.jar"
        elif test -e /usr/share/java/junit4.jar; then
            OOO_JUNIT_JAR=/usr/share/java/junit4.jar
        else
           if test -e /usr/share/lib/java/junit.jar; then
              OOO_JUNIT_JAR=/usr/share/lib/java/junit.jar
           else
              OOO_JUNIT_JAR=/usr/share/java/junit.jar
           fi
        fi
    else
        OOO_JUNIT_JAR=$with_junit
    fi
    if test "$_os" = "WINNT"; then
        OOO_JUNIT_JAR=`cygpath -m "$OOO_JUNIT_JAR"`
    fi
    printf 'import org.junit.Before;' > conftest.java
    if "$JAVACOMPILER" -classpath "$OOO_JUNIT_JAR" conftest.java >&5 2>&5; then
        AC_MSG_RESULT([$OOO_JUNIT_JAR])
    else
        AC_MSG_ERROR(
[cannot find JUnit 4 jar; please install one in the default location (/usr/share/java),
 specify its pathname via --with-junit=..., or disable it via --without-junit])
    fi
    rm -f conftest.class conftest.java
    if test $OOO_JUNIT_JAR != ""; then
    BUILD_TYPE="$BUILD_TYPE QADEVOOO"
    fi
fi
AC_SUBST(OOO_JUNIT_JAR)

HAMCREST_JAR=
if test "$ENABLE_JAVA" != "" -a "$with_junit" != "no"; then
    AC_MSG_CHECKING([for included Hamcrest])
    printf 'import org.hamcrest.BaseDescription;' > conftest.java
    if "$JAVACOMPILER" -classpath "$OOO_JUNIT_JAR" conftest.java >&5 2>&5; then
        AC_MSG_RESULT([Included in $OOO_JUNIT_JAR])
    else
        AC_MSG_RESULT([Not included])
        AC_MSG_CHECKING([for standalone hamcrest jar.])
        if test "$with_hamcrest" = "yes"; then
            if test -e /usr/share/lib/java/hamcrest.jar; then
                HAMCREST_JAR=/usr/share/lib/java/hamcrest.jar
            elif test -e /usr/share/java/hamcrest/core.jar; then
                HAMCREST_JAR=/usr/share/java/hamcrest/core.jar
            else
                HAMCREST_JAR=/usr/share/java/hamcrest.jar
            fi
        else
            HAMCREST_JAR=$with_hamcrest
        fi
        if test "$_os" = "WINNT"; then
            HAMCREST_JAR=`cygpath -m "$HAMCREST_JAR"`
        fi
        if "$JAVACOMPILER" -classpath "$HAMCREST_JAR" conftest.java >&5 2>&5; then
            AC_MSG_RESULT([$HAMCREST_JAR])
        else
            AC_MSG_ERROR([junit does not contain hamcrest; please use a junit jar that includes hamcrest, install a hamcrest jar in the default location (/usr/share/java),
                          specify its path with --with-hamcrest=..., or disable junit with --without-junit])
        fi
    fi
    rm -f conftest.class conftest.java
fi
AC_SUBST(HAMCREST_JAR)


AC_SUBST(SCPDEFS)

#
# check for wget and curl
#
WGET=
CURL=

if test "$enable_fetch_external" != "no"; then

CURL=`which curl 2>/dev/null`

for i in wget /usr/bin/wget /usr/local/bin/wget /usr/sfw/bin/wget /opt/sfw/bin/wget /opt/local/bin/wget; do
    # wget new enough?
    $i --help 2> /dev/null | $GREP no-use-server-timestamps 2>&1 > /dev/null
    if test $? -eq 0; then
        WGET=$i
        break
    fi
done

if test -z "$WGET" -a -z "$CURL"; then
    AC_MSG_ERROR([neither wget nor curl found!])
fi

fi

AC_SUBST(WGET)
AC_SUBST(CURL)

#
# check for sha256sum
#
SHA256SUM=

for i in shasum /usr/local/bin/shasum /usr/sfw/bin/shasum /opt/sfw/bin/shasum /opt/local/bin/shasum; do
    eval "$i -a 256 --version" > /dev/null 2>&1
    ret=$?
    if test $ret -eq 0; then
        SHA256SUM="$i -a 256"
        break
    fi
done

if test -z "$SHA256SUM"; then
    for i in sha256sum /usr/local/bin/sha256sum /usr/sfw/bin/sha256sum /opt/sfw/bin/sha256sum /opt/local/bin/sha256sum; do
        eval "$i --version" > /dev/null 2>&1
        ret=$?
        if test $ret -eq 0; then
            SHA256SUM=$i
            break
        fi
    done
fi

if test -z "$SHA256SUM"; then
    AC_MSG_ERROR([no sha256sum found!])
fi

AC_SUBST(SHA256SUM)

dnl ===================================================================
dnl Dealing with l10n options
dnl ===================================================================
AC_MSG_CHECKING([which languages to be built])
# get list of all languages
# generate shell variable from completelangiso= from solenv/inc/langlist.mk
# the sed command does the following:
#   + if a line ends with a backslash, append the next line to it
#   + adds " on the beginning of the value (after =)
#   + adds " at the end of the value
#   + removes en-US; we want to put it on the beginning
#   + prints just the section starting with 'completelangiso=' and ending with the " at the end of line
[eval $(sed -e :a -e '/\\$/N; s/\\\n//; ta' -n -e 's/=/="/;s/\([^\\]\)$/\1"/;s/en-US//;/^completelangiso/p' $SRC_ROOT/solenv/inc/langlist.mk)]
ALL_LANGS="en-US $completelangiso"
# check the configured localizations
WITH_LANG="$with_lang"
if test -z "$WITH_LANG" -o "$WITH_LANG" = "en-US"; then
    AC_MSG_RESULT([en-US])
else
    AC_MSG_RESULT([$WITH_LANG])
    GIT_NEEDED_SUBMODULES="translations $GIT_NEEDED_SUBMODULES"
    if test -z "$MSGFMT"; then
        if test -n "$LODE_HOME" -a -x "$LODE_HOME/opt/bin/msgfmt" ; then
            MSGFMT="$LODE_HOME/opt/bin/msgfmt"
        elif test -x "/opt/lo/bin/msgfmt"; then
            MSGFMT="/opt/lo/bin/msgfmt"
        else
            AC_CHECK_PROGS(MSGFMT, [msgfmt])
            if test -z "$MSGFMT"; then
                AC_MSG_ERROR([msgfmt not found. Install GNU gettext, or re-run without languages.])
            fi
        fi
    fi
    if test -z "$MSGUNIQ"; then
        if test -n "$LODE_HOME" -a -x "$LODE_HOME/opt/bin/msguniq" ; then
            MSGUNIQ="$LODE_HOME/opt/bin/msguniq"
        elif test -x "/opt/lo/bin/msguniq"; then
            MSGUNIQ="/opt/lo/bin/msguniq"
        else
            AC_CHECK_PROGS(MSGUNIQ, [msguniq])
            if test -z "$MSGUNIQ"; then
                AC_MSG_ERROR([msguniq not found. Install GNU gettext, or re-run without languages.])
            fi
        fi
    fi
fi
AC_SUBST(MSGFMT)
AC_SUBST(MSGUNIQ)
# check that the list is valid
for lang in $WITH_LANG; do
    test "$lang" = "ALL" && continue
    # need to check for the exact string, so add space before and after the list of all languages
    for vl in $ALL_LANGS; do
        if test "$vl" = "$lang"; then
           break
        fi
    done
    if test "$vl" != "$lang"; then
        # if you're reading this - you prolly quoted your languages remove the quotes ...
        AC_MSG_ERROR([invalid language: '$lang' (vs '$v1'); supported languages are: $ALL_LANGS])
    fi
done
if test -n "$WITH_LANG" -a "$WITH_LANG" != "ALL"; then
    echo $WITH_LANG | grep -q en-US
    test $? -ne 1 || WITH_LANG=`echo $WITH_LANG en-US`
fi
# list with substituted ALL
WITH_LANG_LIST=`echo $WITH_LANG | sed "s/ALL/$ALL_LANGS/"`
test -z "$WITH_LANG_LIST" && WITH_LANG_LIST="en-US"
test "$WITH_LANG" = "en-US" && WITH_LANG=
if test "$enable_release_build" = "" -o "$enable_release_build" = "no"; then
    test "$WITH_LANG_LIST" = "en-US" || WITH_LANG_LIST=`echo $WITH_LANG_LIST qtz`
    ALL_LANGS=`echo $ALL_LANGS qtz`
fi
AC_SUBST(ALL_LANGS)
AC_SUBST(WITH_LANG)
AC_SUBST(WITH_LANG_LIST)
AC_SUBST(GIT_NEEDED_SUBMODULES)

WITH_POOR_HELP_LOCALIZATIONS=
if test -d "$SRC_ROOT/translations/source"; then
    for l in `ls -1 $SRC_ROOT/translations/source`; do
        if test ! -d "$SRC_ROOT/translations/source/$l/helpcontent2"; then
            WITH_POOR_HELP_LOCALIZATIONS="$WITH_POOR_HELP_LOCALIZATIONS $l"
        fi
    done
fi
AC_SUBST(WITH_POOR_HELP_LOCALIZATIONS)

if test -n "$with_locales"; then
    WITH_LOCALES="$with_locales"

    just_langs="`echo $WITH_LOCALES | sed -e 's/_[A-Z]*//g'`"
    # Only languages and scripts for which we actually have ifdefs need to be handled. Also see
    # config_host/config_locales.h.in
    for locale in $WITH_LOCALES; do
        lang=${locale%_*}

        AC_DEFINE_UNQUOTED(WITH_LOCALE_$lang, 1)

        case $lang in
        hi|mr*ne)
            AC_DEFINE(WITH_LOCALE_FOR_SCRIPT_Deva)
            ;;
        bg|ru)
            AC_DEFINE(WITH_LOCALE_FOR_SCRIPT_Cyrl)
            ;;
        esac
    done
else
    AC_DEFINE(WITH_LOCALE_ALL)
fi
AC_SUBST(WITH_LOCALES)

dnl git submodule update --reference
dnl ===================================================================
if test -n "${GIT_REFERENCE_SRC}"; then
    for repo in ${GIT_NEEDED_SUBMODULES}; do
        if ! test -d "${GIT_REFERENCE_SRC}"/${repo}; then
            AC_MSG_ERROR([referenced git: required repository does not exist: ${GIT_REFERENCE_SRC}/${repo}])
        fi
    done
fi
AC_SUBST(GIT_REFERENCE_SRC)

dnl git submodules linked dirs
dnl ===================================================================
if test -n "${GIT_LINK_SRC}"; then
    for repo in ${GIT_NEEDED_SUBMODULES}; do
        if ! test -d "${GIT_LINK_SRC}"/${repo}; then
            AC_MSG_ERROR([linked git: required repository does not exist: ${GIT_LINK_SRC}/${repo}])
        fi
    done
fi
AC_SUBST(GIT_LINK_SRC)

dnl branding
dnl ===================================================================
AC_MSG_CHECKING([for alternative branding images directory])
# initialize mapped arrays
BRAND_INTRO_IMAGES="flat_logo.svg intro.png intro-highres.png"
brand_files="$BRAND_INTRO_IMAGES about.svg"

if test -z "$with_branding" -o "$with_branding" = "no"; then
    AC_MSG_RESULT([none])
    DEFAULT_BRAND_IMAGES="$brand_files"
else
    if ! test -d $with_branding ; then
        AC_MSG_ERROR([No directory $with_branding, falling back to default branding])
    else
        AC_MSG_RESULT([$with_branding])
        CUSTOM_BRAND_DIR="$with_branding"
        for lfile in $brand_files
        do
            if ! test -f $with_branding/$lfile ; then
                AC_MSG_WARN([Branded file $lfile does not exist, using the default one])
                DEFAULT_BRAND_IMAGES="$DEFAULT_BRAND_IMAGES $lfile"
            else
                CUSTOM_BRAND_IMAGES="$CUSTOM_BRAND_IMAGES $lfile"
            fi
        done
        check_for_progress="yes"
    fi
fi
AC_SUBST([BRAND_INTRO_IMAGES])
AC_SUBST([CUSTOM_BRAND_DIR])
AC_SUBST([CUSTOM_BRAND_IMAGES])
AC_SUBST([DEFAULT_BRAND_IMAGES])


AC_MSG_CHECKING([for 'intro' progress settings])
PROGRESSBARCOLOR=
PROGRESSSIZE=
PROGRESSPOSITION=
PROGRESSFRAMECOLOR=
PROGRESSTEXTCOLOR=
PROGRESSTEXTBASELINE=

if test "$check_for_progress" = "yes" -a -f "$with_branding/progress.conf" ; then
    source "$with_branding/progress.conf"
    AC_MSG_RESULT([settings found in $with_branding/progress.conf])
else
    AC_MSG_RESULT([none])
fi

AC_SUBST(PROGRESSBARCOLOR)
AC_SUBST(PROGRESSSIZE)
AC_SUBST(PROGRESSPOSITION)
AC_SUBST(PROGRESSFRAMECOLOR)
AC_SUBST(PROGRESSTEXTCOLOR)
AC_SUBST(PROGRESSTEXTBASELINE)


AC_MSG_CHECKING([for extra build ID])
if test -n "$with_extra_buildid" -a "$with_extra_buildid" != "yes" ; then
    EXTRA_BUILDID="$with_extra_buildid"
fi
# in tinderboxes, it is easier to set EXTRA_BUILDID via the environment variable instead of configure switch
if test -n "$EXTRA_BUILDID" ; then
    AC_MSG_RESULT([$EXTRA_BUILDID])
else
    AC_MSG_RESULT([not set])
fi
AC_DEFINE_UNQUOTED([EXTRA_BUILDID], ["$EXTRA_BUILDID"])

OOO_VENDOR=
AC_MSG_CHECKING([for vendor])
if test -z "$with_vendor" -o "$with_vendor" = "no"; then
    OOO_VENDOR="$USERNAME"

    if test -z "$OOO_VENDOR"; then
        OOO_VENDOR="$USER"
    fi

    if test -z "$OOO_VENDOR"; then
        OOO_VENDOR="`id -u -n`"
    fi

    AC_MSG_RESULT([not set, using $OOO_VENDOR])
else
    OOO_VENDOR="$with_vendor"
    AC_MSG_RESULT([$OOO_VENDOR])
fi
AC_SUBST(OOO_VENDOR)

if test "$_os" = "Android" ; then
    ANDROID_PACKAGE_NAME=
    AC_MSG_CHECKING([for Android package name])
    if test -z "$with_android_package_name" -o "$with_android_package_name" = "no"; then
        if test -n "$ENABLE_DEBUG"; then
            # Default to the package name that makes ndk-gdb happy.
            ANDROID_PACKAGE_NAME="org.libreoffice"
        else
            ANDROID_PACKAGE_NAME="org.example.libreoffice"
        fi

        AC_MSG_RESULT([not set, using $ANDROID_PACKAGE_NAME])
    else
        ANDROID_PACKAGE_NAME="$with_android_package_name"
        AC_MSG_RESULT([$ANDROID_PACKAGE_NAME])
    fi
    AC_SUBST(ANDROID_PACKAGE_NAME)
fi

AC_MSG_CHECKING([whether to install the compat oo* wrappers])
if test "$with_compat_oowrappers" = "yes"; then
    WITH_COMPAT_OOWRAPPERS=TRUE
    AC_MSG_RESULT(yes)
else
    WITH_COMPAT_OOWRAPPERS=
    AC_MSG_RESULT(no)
fi
AC_SUBST(WITH_COMPAT_OOWRAPPERS)

INSTALLDIRNAME=`echo AC_PACKAGE_NAME | $AWK '{gsub(" ", "", $0);print tolower($0)}'`
AC_MSG_CHECKING([for install dirname])
if test -n "$with_install_dirname" -a "$with_install_dirname" != "no" -a "$with_install_dirname" != "yes"; then
    INSTALLDIRNAME="$with_install_dirname"
fi
AC_MSG_RESULT([$INSTALLDIRNAME])
AC_SUBST(INSTALLDIRNAME)

AC_MSG_CHECKING([for prefix])
test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix=$prefix
PREFIXDIR="$prefix"
AC_MSG_RESULT([$PREFIXDIR])
AC_SUBST(PREFIXDIR)

LIBDIR=[$(eval echo $(eval echo $libdir))]
AC_SUBST(LIBDIR)

DATADIR=[$(eval echo $(eval echo $datadir))]
AC_SUBST(DATADIR)

MANDIR=[$(eval echo $(eval echo $mandir))]
AC_SUBST(MANDIR)

DOCDIR=[$(eval echo $(eval echo $docdir))]
AC_SUBST(DOCDIR)

INSTALLDIR="$LIBDIR/$INSTALLDIRNAME"
AC_SUBST(INSTALLDIR)

TESTINSTALLDIR="${BUILDDIR}/test-install"
AC_SUBST(TESTINSTALLDIR)


# ===================================================================
# OAuth2 id and secrets
# ===================================================================

AC_MSG_CHECKING([for Google Drive client id and secret])
GDRIVE_CLIENT_ID="\"$with_gdrive_client_id\""
GDRIVE_CLIENT_SECRET="\"$with_gdrive_client_secret\""
if test "$with_gdrive_client_id" = "no" -o -z "$with_gdrive_client_id"; then
    GDRIVE_CLIENT_ID="\"\""
fi

if test "$with_gdrive_client_secret" = "no" -o -z "$with_gdrive_client_secret"; then
    GDRIVE_CLIENT_SECRET="\"\""
fi

if test -z "$GDRIVE_CLIENT_ID" -o -z "$GDRIVE_CLIENT_SECRET"; then
    AC_MSG_RESULT([not set])
else
    AC_MSG_RESULT([set])
fi

AC_DEFINE_UNQUOTED(GDRIVE_CLIENT_ID, $GDRIVE_CLIENT_ID)
AC_DEFINE_UNQUOTED(GDRIVE_CLIENT_SECRET, $GDRIVE_CLIENT_SECRET)

AC_MSG_CHECKING([for Alfresco Cloud client id and secret])
ALFRESCO_CLOUD_CLIENT_ID="\"$with_alfresco_cloud_client_id\""
ALFRESCO_CLOUD_CLIENT_SECRET="\"$with_alfresco_cloud_client_secret\""
if test "$with_alfresco_cloud_client_id" = "no" -o -z "$with_alfresco_cloud_client_id"; then
    ALFRESCO_CLOUD_CLIENT_ID="\"\""
fi

if test "$with_alfresco_cloud_client_secret" = "no" -o -z "$with_alfresco_cloud_client_secret"; then
    ALFRESCO_CLOUD_CLIENT_SECRET="\"\""
fi

if test -z "$ALFRESCO_CLOUD_CLIENT_ID" -o -z "$ALFRESCO_CLOUD_CLIENT_SECRET"; then
    AC_MSG_RESULT([not set])
else
    AC_MSG_RESULT([set])
fi
AC_DEFINE_UNQUOTED(ALFRESCO_CLOUD_CLIENT_ID, $ALFRESCO_CLOUD_CLIENT_ID)
AC_DEFINE_UNQUOTED(ALFRESCO_CLOUD_CLIENT_SECRET, $ALFRESCO_CLOUD_CLIENT_SECRET)

AC_MSG_CHECKING([for OneDrive client id and secret])
ONEDRIVE_CLIENT_ID="\"$with_onedrive_client_id\""
ONEDRIVE_CLIENT_SECRET="\"$with_onedrive_client_secret\""
if test "$with_onedrive_client_id" = "no" -o -z "$with_onedrive_client_id"; then
    ONEDRIVE_CLIENT_ID="\"\""
fi

if test "$with_onedrive_client_secret" = "no" -o -z "$with_onedrive_client_secret"; then
    ONEDRIVE_CLIENT_SECRET="\"\""
fi

if test -z "$ONEDRIVE_CLIENT_ID" -o -z "$ONEDRIVE_CLIENT_SECRET"; then
    AC_MSG_RESULT([not set])
else
    AC_MSG_RESULT([set])
fi
AC_DEFINE_UNQUOTED(ONEDRIVE_CLIENT_ID, $ONEDRIVE_CLIENT_ID)
AC_DEFINE_UNQUOTED(ONEDRIVE_CLIENT_SECRET, $ONEDRIVE_CLIENT_SECRET)


dnl ===================================================================
dnl Hook up LibreOffice's nodep environmental variable to automake's equivalent
dnl --enable-dependency-tracking configure option
dnl ===================================================================
AC_MSG_CHECKING([whether to enable dependency tracking])
if test "$enable_dependency_tracking" = "no"; then
    nodep=TRUE
    AC_MSG_RESULT([no])
else
    AC_MSG_RESULT([yes])
fi
AC_SUBST(nodep)

dnl ===================================================================
dnl Number of CPUs to use during the build
dnl ===================================================================
AC_MSG_CHECKING([for number of processors to use])
# plain --with-parallelism is just the default
if test -n "$with_parallelism" -a "$with_parallelism" != "yes"; then
    if test "$with_parallelism" = "no"; then
        PARALLELISM=0
    else
        PARALLELISM=$with_parallelism
    fi
else
    if test "$enable_icecream" = "yes"; then
        PARALLELISM="10"
    else
        case `uname -s` in

        Darwin|FreeBSD|NetBSD|OpenBSD)
            PARALLELISM=`sysctl -n hw.ncpu`
            ;;

        Linux)
            PARALLELISM=`getconf _NPROCESSORS_ONLN`
        ;;
        # what else than above does profit here *and* has /proc?
        *)
            PARALLELISM=`grep $'^processor\t*:' /proc/cpuinfo | wc -l`
            ;;
        esac

        # If we hit the catch-all case, but /proc/cpuinfo doesn't exist or has an
        # unexpected format, 'wc -l' will have returned 0 (and we won't use -j at all).
    fi
fi

if test "$no_parallelism_make" = "YES" && test $PARALLELISM -gt 1; then
    if test -z "$with_parallelism"; then
            AC_MSG_WARN([gmake 3.81 crashes with parallelism > 1, reducing it to 1. upgrade to 3.82 to avoid this.])
            add_warning "gmake 3.81 crashes with parallelism > 1, reducing it to 1. upgrade to 3.82 to avoid this."
            PARALLELISM="1"
    else
        add_warning "make 3.81 is prone to crashes with parallelism > 1. Since --with-parallelism was explicitly given, it is honored, but do not complain when make segfaults on you."
    fi
fi

if test $PARALLELISM -eq 0; then
    AC_MSG_RESULT([explicit make -j option needed])
else
    AC_MSG_RESULT([$PARALLELISM])
fi
AC_SUBST(PARALLELISM)

IWYU_PATH="$with_iwyu"
AC_SUBST(IWYU_PATH)
if test ! -z "$IWYU_PATH"; then
    if test ! -f "$IWYU_PATH"; then
        AC_MSG_ERROR([cannot find include-what-you-use binary specified by --with-iwyu])
    fi
fi

#
# Set up ILIB for MSVC build
#
ILIB1=
if test "$build_os" = "cygwin"; then
    ILIB="."
    if test -n "$JAVA_HOME"; then
        ILIB="$ILIB;$JAVA_HOME/lib"
    fi
    ILIB1=-link
    if test "$BITNESS_OVERRIDE" = 64; then
        if test $vcnum = "150"; then
            ILIB="$ILIB;$COMPATH/lib/x64"
            ILIB1="$ILIB1 -LIBPATH:$COMPATH/lib/x64"
        else
            ILIB="$ILIB;$COMPATH/lib/amd64"
            ILIB1="$ILIB1 -LIBPATH:$COMPATH/lib/amd64"
        fi
        ILIB="$ILIB;$WINDOWS_SDK_HOME/lib/x64"
        ILIB1="$ILIB1 -LIBPATH:$WINDOWS_SDK_HOME/lib/x64"
        if test $WINDOWS_SDK_VERSION = 80 -o $WINDOWS_SDK_VERSION = 81 -o $WINDOWS_SDK_VERSION = 10; then
            ILIB="$ILIB;$WINDOWS_SDK_HOME/lib/$winsdklibsubdir/um/x64"
            ILIB1="$ILIB1 -LIBPATH:$WINDOWS_SDK_HOME/lib/$winsdklibsubdir/um/x64"
        fi
        PathFormat "${UCRTSDKDIR}lib/$UCRTVERSION/ucrt/x64"
        ucrtlibpath_formatted=$formatted_path
        ILIB="$ILIB;$ucrtlibpath_formatted"
        ILIB1="$ILIB1 -LIBPATH:$ucrtlibpath_formatted"
    else
        if test $vcnum = "150"; then
            ILIB="$ILIB;$COMPATH/lib/x86"
            ILIB1="$ILIB1 -LIBPATH:$COMPATH/lib/x86"
        else
            ILIB="$ILIB;$COMPATH/lib"
            ILIB1="$ILIB1 -LIBPATH:$COMPATH/lib"
        fi
        ILIB="$ILIB;$WINDOWS_SDK_HOME/lib"
        ILIB1="$ILIB1 -LIBPATH:$WINDOWS_SDK_HOME/lib"
        if test $WINDOWS_SDK_VERSION = 80 -o $WINDOWS_SDK_VERSION = 81 -o $WINDOWS_SDK_VERSION = 10; then
            ILIB="$ILIB;$WINDOWS_SDK_HOME/lib/$winsdklibsubdir/um/x86"
            ILIB1="$ILIB1 -LIBPATH:$WINDOWS_SDK_HOME/lib/$winsdklibsubdir/um/x86"
        fi
        PathFormat "${UCRTSDKDIR}lib/$UCRTVERSION/ucrt/x86"
        ucrtlibpath_formatted=$formatted_path
        ILIB="$ILIB;$ucrtlibpath_formatted"
        ILIB1="$ILIB1 -LIBPATH:$ucrtlibpath_formatted"
    fi
    if test -f "$DOTNET_FRAMEWORK_HOME/lib/mscoree.lib"; then
        ILIB="$ILIB;$DOTNET_FRAMEWORK_HOME/lib"
    else
        ILIB="$ILIB;$DOTNET_FRAMEWORK_HOME/Lib/um/$WINDOWS_SDK_ARCH"
    fi

    AC_SUBST(ILIB)
fi

dnl We should be able to drop the below check when bumping the GCC baseline to
dnl 4.9, as <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54577>
dnl "deque<T>::erase() still takes iterator instead of const_iterator" should be
dnl fixed there with <https://gcc.gnu.org/git/?p=gcc.git;a=commit;
dnl h=6b0e18ca48bb4b4c01e7b5be2b98849943fdcf91>:
AC_MSG_CHECKING(
    [whether C++11 use of const_iterator in standard containers is broken])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
    #include <list>
    ]],[[
        std::list<int> l;
        l.erase(l.cbegin());
    ]])],
    [broken=no], [broken=yes])
AC_LANG_POP([C++])
CXXFLAGS=$save_CXXFLAGS
AC_MSG_RESULT([$broken])
if test "$broken" = yes; then
    AC_DEFINE([HAVE_BROKEN_CONST_ITERATORS])
fi


AC_MSG_CHECKING([whether $CXX has broken static initializer_list support])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
save_LIBS=$LIBS
if test -n "$ILIB1"; then
    LIBS="$LIBS $ILIB1"
fi
AC_LANG_PUSH([C++])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
    // Exit with failure if the static initializer_list is stored on the
    // stack (as done by Clang < 3.4):
    #include <initializer_list>
    struct S {};
    bool g(void const * p1, void const * p2) {
        int n;
        return !((p1 > p2 && p2 > &n) || (p1 < p2 && p2 < &n));
    }
    bool f(void const * p1) {
        static std::initializer_list<S> s { S() };
        return g(p1, s.begin());
    }
    ]],[[
        int n;
        return f(&n) ? 0 : 1;
    ]])], [broken=no], [broken=yes],[broken='assuming not (cross-compiling)'])
AC_LANG_POP([C++])
LIBS=$save_LIBS
CXXFLAGS=$save_CXXFLAGS
AC_MSG_RESULT([$broken])
if test "$broken" = yes -a "$_os" != "iOS"; then
    AC_MSG_ERROR([working support for static initializer_list needed])
fi


# ===================================================================
# Creating bigger shared library to link against
# ===================================================================
AC_MSG_CHECKING([whether to create huge library])
MERGELIBS=

if test $_os = iOS -o $_os = Android; then
    # Never any point in mergelibs for these as we build just static
    # libraries anyway...
    enable_mergelibs=no
fi

if test -n "$enable_mergelibs" -a "$enable_mergelibs" != "no"; then
    if test $_os != Linux -a $_os != WINNT; then
        add_warning "--enable-mergelibs is not tested for this platform"
    fi
    MERGELIBS="TRUE"
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST([MERGELIBS])

dnl ===================================================================
dnl icerun is a wrapper that stops us spawning tens of processes
dnl locally - for tools that can't be executed on the compile cluster
dnl this avoids a dozen javac's ganging up on your laptop to kill it.
dnl ===================================================================
AC_MSG_CHECKING([whether to use icerun wrapper])
ICECREAM_RUN=
if test "$enable_icecream" = "yes" && which icerun >/dev/null 2>&1 ; then
    ICECREAM_RUN=icerun
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi
AC_SUBST(ICECREAM_RUN)

dnl ===================================================================
dnl Setup the ICECC_VERSION for the build the same way it was set for
dnl configure, so that CC/CXX and ICECC_VERSION are in sync
dnl ===================================================================
x_ICECC_VERSION=[\#]
if test -n "$ICECC_VERSION" ; then
    x_ICECC_VERSION=
fi
AC_SUBST(x_ICECC_VERSION)
AC_SUBST(ICECC_VERSION)

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

AC_MSG_CHECKING([MPL subset])
MPL_SUBSET=

if test "$enable_mpl_subset" = "yes"; then
    warn_report=false
    if test "$enable_report_builder" != "no" -a "$with_java" != "no"; then
        warn_report=true
    elif test "$ENABLE_REPORTBUILDER" = "TRUE"; then
        warn_report=true
    fi
    if test "$warn_report" = "true"; then
        AC_MSG_ERROR([need to --disable-report-builder - extended database report builder.])
    fi
    if test "x$enable_postgresql_sdbc" != "xno"; then
        AC_MSG_ERROR([need to --disable-postgresql-sdbc - the PostgreSQL database backend.])
    fi
    if test "$enable_lotuswordpro" = "yes"; then
        AC_MSG_ERROR([need to --disable-lotuswordpro - a Lotus Word Pro file format import filter.])
    fi
    if test "$WITH_WEBDAV" = "neon"; then
        AC_MSG_ERROR([need --with-webdav=serf or --without-webdav - webdav support.])
    fi
    if test -n "$ENABLE_POPPLER"; then
        if test "x$SYSTEM_POPPLER" = "x"; then
            AC_MSG_ERROR([need to disable PDF import via poppler or use system library])
        fi
    fi
    # cf. m4/libo_check_extension.m4
    if test "x$WITH_EXTRA_EXTENSIONS" != "x"; then
        AC_MSG_ERROR([need to disable extra extensions '$WITH_EXTRA_EXTENSIONS'])
    fi
    for theme in $WITH_THEMES; do
        case $theme in
        crystal|default|hicontrast|oxygen)
            AC_MSG_ERROR([need to disable icon themes from '$WITH_THEMES': $theme present, use --with-theme=tango]) ;;
        *) : ;;
        esac
    done

    ENABLE_OPENGL_TRANSITIONS=

    if test "$enable_lpsolve" != "no" -o "x$ENABLE_LPSOLVE" = "xTRUE"; then
        AC_MSG_ERROR([need to --disable-lpsolve - calc linear programming solver.])
    fi

    MPL_SUBSET="TRUE"
    AC_DEFINE(MPL_HAVE_SUBSET)
    AC_MSG_RESULT([only])
else
    AC_MSG_RESULT([no restrictions])
fi
AC_SUBST(MPL_SUBSET)

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

AC_MSG_CHECKING([formula logger])
ENABLE_FORMULA_LOGGER=

if test "x$enable_formula_logger" = "xyes"; then
    AC_MSG_RESULT([yes])
    AC_DEFINE(ENABLE_FORMULA_LOGGER)
    ENABLE_FORMULA_LOGGER=TRUE
elif test -n "$ENABLE_DBGUTIL" ; then
    AC_MSG_RESULT([yes])
    AC_DEFINE(ENABLE_FORMULA_LOGGER)
    ENABLE_FORMULA_LOGGER=TRUE
else
    AC_MSG_RESULT([no])
fi

AC_SUBST(ENABLE_FORMULA_LOGGER)

dnl ===================================================================
dnl Setting up the environment.
dnl ===================================================================
AC_MSG_NOTICE([setting up the build environment variables...])

AC_SUBST(COMPATH)

if test "$build_os" = "cygwin"; then
    if test -d "$COMPATH/atlmfc/lib"; then
        ATL_LIB="$COMPATH/atlmfc/lib"
        ATL_INCLUDE="$COMPATH/atlmfc/include"
    else
        ATL_LIB="$WINDOWS_SDK_HOME/lib" # Doesn't exist for VSE
        ATL_INCLUDE="$WINDOWS_SDK_HOME/include/atl"
    fi
    if test "$BITNESS_OVERRIDE" = 64; then
        if test $VCVER = "150"; then
            ATL_LIB="$ATL_LIB/x64"
        else
            ATL_LIB="$ATL_LIB/amd64"
        fi
    else
        if test $VCVER = "150"; then
            ATL_LIB="$ATL_LIB/x86"
        fi
    fi
    # sort.exe and find.exe also exist in C:/Windows/system32 so need /usr/bin/
    PathFormat "/usr/bin/find.exe"
    FIND="$formatted_path"
    PathFormat "/usr/bin/sort.exe"
    SORT="$formatted_path"
    PathFormat "/usr/bin/grep.exe"
    WIN_GREP="$formatted_path"
    PathFormat "/usr/bin/ls.exe"
    WIN_LS="$formatted_path"
    PathFormat "/usr/bin/touch.exe"
    WIN_TOUCH="$formatted_path"
else
    FIND=find
    SORT=sort
fi

AC_SUBST(ATL_INCLUDE)
AC_SUBST(ATL_LIB)
AC_SUBST(FIND)
AC_SUBST(SORT)
AC_SUBST(WIN_GREP)
AC_SUBST(WIN_LS)
AC_SUBST(WIN_TOUCH)

AC_SUBST(BUILD_TYPE)

AC_SUBST(SOLARINC)

PathFormat "$PERL"
PERL="$formatted_path"
AC_SUBST(PERL)

if test -n "$TMPDIR"; then
    TEMP_DIRECTORY="$TMPDIR"
else
    TEMP_DIRECTORY="/tmp"
fi
if test "$build_os" = "cygwin"; then
    TEMP_DIRECTORY=`cygpath -m "$TEMP_DIRECTORY"`
fi
AC_SUBST(TEMP_DIRECTORY)

# setup the PATH for the environment
if test -n "$LO_PATH_FOR_BUILD"; then
    LO_PATH="$LO_PATH_FOR_BUILD"
else
    LO_PATH="$PATH"

    case "$host_os" in

    aix*|dragonfly*|freebsd*|linux-gnu*|*netbsd*|openbsd*)
        if test "$ENABLE_JAVA" != ""; then
            pathmunge "$JAVA_HOME/bin" "after"
        fi
        ;;

    cygwin*)
        # Win32 make needs native paths
        if test "$GNUMAKE_WIN_NATIVE" = "TRUE" ; then
            LO_PATH=`cygpath -p -m "$PATH"`
        fi
        if test "$BITNESS_OVERRIDE" = 64; then
            # needed for msi packaging
            pathmunge "$WINDOWS_SDK_BINDIR_NO_ARCH/x86" "before"
        fi
        # .NET 4.6 and higher don't have bin directory
        if test -f "$DOTNET_FRAMEWORK_HOME/bin"; then
            pathmunge "$DOTNET_FRAMEWORK_HOME/bin" "before"
        fi
        pathmunge "$ASM_HOME" "before"
        pathmunge "$WINDOWS_SDK_HOME/bin" "before"
        pathmunge "$CSC_PATH" "before"
        pathmunge "$MIDL_PATH" "before"
        pathmunge "$AL_PATH" "before"
        pathmunge "$MSPDB_PATH" "before"
        if test -n "$MSBUILD_PATH" ; then
            pathmunge "$MSBUILD_PATH" "before"
        fi
        if test "$BITNESS_OVERRIDE" = 64; then
            pathmunge "$COMPATH/bin/amd64" "before"
            pathmunge "$WINDOWS_SDK_BINDIR_NO_ARCH/x64" "before"
        else
            pathmunge "$COMPATH/bin" "before"
            pathmunge "$WINDOWS_SDK_BINDIR_NO_ARCH/x86" "before"
        fi
        if test "$ENABLE_JAVA" != ""; then
            if test -d "$JAVA_HOME/jre/bin/client"; then
                pathmunge "$JAVA_HOME/jre/bin/client" "before"
            fi
            if test -d "$JAVA_HOME/jre/bin/hotspot"; then
                pathmunge "$JAVA_HOME/jre/bin/hotspot" "before"
            fi
            pathmunge "$JAVA_HOME/bin" "before"
        fi
        ;;

    solaris*)
        pathmunge "/usr/css/bin" "before"
        if test "$ENABLE_JAVA" != ""; then
            pathmunge "$JAVA_HOME/bin" "after"
        fi
        ;;
    esac
fi

AC_SUBST(LO_PATH)

libo_FUZZ_SUMMARY

# Generate a configuration sha256 we can use for deps
if test -f config_host.mk; then
    config_sha256=`$SHA256SUM config_host.mk | sed "s/ .*//"`
fi
if test -f config_host_lang.mk; then
    config_lang_sha256=`$SHA256SUM config_host_lang.mk | sed "s/ .*//"`
fi

CFLAGS=$my_original_CFLAGS
CXXFLAGS=$my_original_CXXFLAGS
CPPFLAGS=$my_original_CPPFLAGS

AC_CONFIG_FILES([config_host.mk
                 config_host_lang.mk
                 Makefile
                 lo.xcent
                 bin/bffvalidator.sh
                 bin/odfvalidator.sh
                 bin/officeotron.sh
                 instsetoo_native/util/openoffice.lst
                 setup_native/source/packinfo/finals_instsetoo.txt
                 sysui/desktop/macosx/Info.plist])
AC_CONFIG_HEADERS([config_host/config_buildid.h])
AC_CONFIG_HEADERS([config_host/config_clang.h])
AC_CONFIG_HEADERS([config_host/config_dconf.h])
AC_CONFIG_HEADERS([config_host/config_eot.h])
AC_CONFIG_HEADERS([config_host/config_extension_update.h])
AC_CONFIG_HEADERS([config_host/config_cairo_canvas.h])
AC_CONFIG_HEADERS([config_host/config_cxxabi.h])
AC_CONFIG_HEADERS([config_host/config_dbus.h])
AC_CONFIG_HEADERS([config_host/config_features.h])
AC_CONFIG_HEADERS([config_host/config_firebird.h])
AC_CONFIG_HEADERS([config_host/config_folders.h])
AC_CONFIG_HEADERS([config_host/config_gio.h])
AC_CONFIG_HEADERS([config_host/config_global.h])
AC_CONFIG_HEADERS([config_host/config_gpgme.h])
AC_CONFIG_HEADERS([config_host/config_java.h])
AC_CONFIG_HEADERS([config_host/config_lgpl.h])
AC_CONFIG_HEADERS([config_host/config_liblangtag.h])
AC_CONFIG_HEADERS([config_host/config_locales.h])
AC_CONFIG_HEADERS([config_host/config_mpl.h])
AC_CONFIG_HEADERS([config_host/config_kde4.h])
AC_CONFIG_HEADERS([config_host/config_qt5.h])
AC_CONFIG_HEADERS([config_host/config_oox.h])
AC_CONFIG_HEADERS([config_host/config_options.h])
AC_CONFIG_HEADERS([config_host/config_options_calc.h])
AC_CONFIG_HEADERS([config_host/config_test.h])
AC_CONFIG_HEADERS([config_host/config_typesizes.h])
AC_CONFIG_HEADERS([config_host/config_vcl.h])
AC_CONFIG_HEADERS([config_host/config_vclplug.h])
AC_CONFIG_HEADERS([config_host/config_version.h])
AC_CONFIG_HEADERS([config_host/config_oauth2.h])
AC_CONFIG_HEADERS([config_host/config_poppler.h])
AC_CONFIG_HEADERS([config_host/config_python.h])
AC_CONFIG_HEADERS([config_host/config_writerperfect.h])
AC_OUTPUT

if test "$CROSS_COMPILING" = TRUE; then
    (echo; echo export BUILD_TYPE_FOR_HOST=$BUILD_TYPE) >>config_build.mk
fi

# touch the config timestamp file
if test ! -f config_host.mk.stamp; then
    echo > config_host.mk.stamp
elif test "$config_sha256" = `$SHA256SUM config_host.mk | sed "s/ .*//"`; then
    echo "Host Configuration unchanged - avoiding scp2 stamp update"
else
    echo > config_host.mk.stamp
fi

# touch the config lang timestamp file
if test ! -f config_host_lang.mk.stamp; then
    echo > config_host_lang.mk.stamp
elif test "$config_lang_sha256" = `$SHA256SUM config_host_lang.mk | sed "s/ .*//"`; then
    echo "Language Configuration unchanged - avoiding scp2 stamp update"
else
    echo > config_host_lang.mk.stamp
fi


if test "$STALE_MAKE" = "TRUE" -a "$build_os" = "cygwin"; then

cat << _EOS
****************************************************************************
WARNING:
Your make version is known to be horribly slow, and hard to debug
problems with. To get a reasonably functional make please do:

to install a pre-compiled binary make for Win32

 mkdir -p /opt/lo/bin
 cd /opt/lo/bin
 wget https://dev-www.libreoffice.org/bin/cygwin/make-85047eb-msvc.exe
 cp make-85047eb-msvc.exe make
 chmod +x make

to install from source:
place yourself in a working directory of you choice.

 git clone git://git.savannah.gnu.org/make.git

 [go to Start menu, click "All Programs", click "Visual Studio 2015", click "Visual Studio Tools", double-click "VS2015 x86 Native Tools Command Prompt" or "VS2015 x64 Native Tools Command Prompt"]
 set PATH=%PATH%;C:\Cygwin\bin
 [or Cygwin64, if that is what you have]
 cd path-to-make-repo-you-cloned-above
 build_w32.bat --without-guile

should result in a WinRel/gnumake.exe.
Copy it to the Cygwin /opt/lo/bin directory as make.exe

Then re-run autogen.sh

Note: autogen.sh will try to use /opt/lo/bin/make if the environment variable GNUMAKE is not already defined.
Alternatively, you can install the 'new' make where ever you want and make sure that `which make` finds it.

_EOS
fi

cat << _EOF
****************************************************************************

To build, run:
$GNUMAKE

To view some help, run:
$GNUMAKE help

_EOF

if test $_os != WINNT -a "$CROSS_COMPILING" != TRUE; then
    cat << _EOF
After the build of LibreOffice has finished successfully, you can immediately run LibreOffice using the command:
_EOF

    if test $_os = Darwin; then
        echo open instdir/$PRODUCTNAME.app
    else
        echo instdir/program/soffice
    fi
    cat << _EOF

If you want to run the smoketest, run:
$GNUMAKE check

_EOF
fi

if test -f warn; then
    cat warn
    rm warn
fi

dnl vim:set shiftwidth=4 softtabstop=4 expandtab: