summaryrefslogtreecommitdiff
path: root/configure.ac
blob: 292829cebb25442bd587fc56deb9f005acb56fb0 (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
dnl -*- sh -*-
dnl the "configure" script is made from this by running GNU "autoconf"
dnl
dnl Configuration script for the Fast Light Tool Kit (FLTK).
dnl
dnl Copyright 1998-2023 by Bill Spitzak and others.
dnl
dnl This library is free software. Distribution and use rights are outlined in
dnl the file "COPYING" which should have been included with this file.  If this
dnl file is missing or damaged, see the license at:
dnl
dnl     https://www.fltk.org/COPYING.php
dnl
dnl Please see the following page on how to report bugs and issues:
dnl
dnl      https://www.fltk.org/bugs.php
dnl

dnl We need at least autoconf 2.50...
AC_PREREQ([2.50])


dnl Package name and version
AC_INIT([fltk], [1.4.0], [https://github.com/fltk/fltk/issues], [fltk], [https://www.fltk.org/])

FLTK_VERSION="AC_PACKAGE_VERSION"
FLTK_VERSION_MAJOR=$(echo AC_PACKAGE_VERSION | awk -F. '{print $1}')
FLTK_VERSION_MINOR=$(echo AC_PACKAGE_VERSION | awk -F. '{print $2}')
FLTK_VERSION_PATCH=$(echo AC_PACKAGE_VERSION | awk -F. '{print $3}')

FL_DSO_VERSION="${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}"
FL_ABI_VERSION="${FLTK_VERSION_MAJOR}.${FLTK_VERSION_MINOR}.0"

AC_SUBST(FLTK_VERSION)
AC_SUBST(FLTK_VERSION_MAJOR)
AC_SUBST(FLTK_VERSION_MINOR)
AC_SUBST(FLTK_VERSION_PATCH)
AC_SUBST(FL_DSO_VERSION)
AC_SUBST(FL_ABI_VERSION)


dnl Required file in package...
AC_CONFIG_SRCDIR([src/Fl.cxx])


AC_CANONICAL_HOST


dnl determine whether we're cross-compiling
AS_IF([test "$host" != "$build"], [
    fltk_cross_compiling="yes"
], [
    fltk_cross_compiling="no"
])


dnl Do not automatically add "-g" to compiler options...
dnl This must be _before_ "Find compiler commands..."
CFLAGS="${CFLAGS:=}"
CPPFLAGS="${CPPFLAGS:=}"
CXXFLAGS="${CXXFLAGS:=}"
DSOFLAGS="${DSOFLAGS:=}"
LDFLAGS="${LDFLAGS:=}"
LIBS="${LDFLAGS:=}"


dnl Find common commands...
AC_PROG_CC
AC_PROG_CXX
AC_PATH_TOOL(PKGCONFIG, pkg-config)


dnl Architecture and optimization options...
ARCHFLAGS="${ARCHFLAGS:=}"
AC_ARG_WITH([archflags], AS_HELP_STRING([--with-archflags="flags"], [use custom architecture flags (default=none, macOS values include "-arch arm64", "-arch i386", "-arch ppc", and "-arch x86_64")]), [
    ARCHFLAGS="$withval"
])
AC_SUBST(ARCHFLAGS)

OPTIM="${OPTIM:=}"
AC_ARG_WITH(optim, AS_HELP_STRING([--with-optim="flags"], [use custom optimization flags]), [
    OPTIM="$withval"
])
AC_SUBST(OPTIM)


dnl Other options
AC_ARG_ENABLE([cairo], AS_HELP_STRING([--enable-cairo], [add support for Fl_Cairo_Window]))
AC_ARG_ENABLE([cairoext], AS_HELP_STRING([--enable-cairoext], [use FLTK code instrumentation for cairo extended use]))

AC_ARG_ENABLE([cp936], AS_HELP_STRING([--enable-cp936], [turn on CP936]))
AS_IF([test x$enable_cp936 = xyes], [
    CFLAGS="$CFLAGS -DCP936"
])

AC_ARG_ENABLE([cygwin], AS_HELP_STRING([--enable-cygwin], [use the Cygwin libraries (default=no)]))

AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [turn on debugging]))
AS_IF([test x$enable_debug = xyes], [
    DEBUGFLAG="-g "
], [
    DEBUGFLAG=""
])

AC_ARG_ENABLE([gl], AS_HELP_STRING([--disable-gl], [turn off OpenGL support]))

AC_ARG_ENABLE([localjpeg], AS_HELP_STRING([--enable-localjpeg], [use local JPEG library (default=auto)]))
AC_ARG_ENABLE([localpng], AS_HELP_STRING([--enable-localpng], [use local PNG library (default=auto)]))
AC_ARG_ENABLE([localzlib], AS_HELP_STRING([--enable-localzlib], [use local ZLIB library (default=auto)]))

AC_ARG_ENABLE([pango], AS_HELP_STRING([--enable-pango], [turn on Pango support]))

AC_ARG_ENABLE([wayland], AS_HELP_STRING([--disable-wayland], [turn off hybrid Wayland/X11 support]))

AC_ARG_ENABLE([usecairo], AS_HELP_STRING([--enable-usecairo], [all drawing to X11 windows uses Cairo]))

AC_ARG_ENABLE([print], AS_HELP_STRING([--disable-print], [turn off print support (X11)]))
AS_IF([test x$enable_print = xno], [
    AC_DEFINE([FL_NO_PRINT_SUPPORT], [Disable X11 print support?])
])

AC_ARG_ENABLE([shared], AS_HELP_STRING([--enable-shared], [turn on shared libraries]))

AC_ARG_ENABLE([svg], AS_HELP_STRING([--disable-svg], [disable SVG support]))
AS_IF([test x$enable_svg != xno], [
    AC_DEFINE([FLTK_USE_SVG], 1, [SVG image support])
])

AC_ARG_ENABLE([threads], AS_HELP_STRING([--disable-threads], [turn off multi-threading support]))

AC_ARG_ENABLE([x11], AS_HELP_STRING([--enable-x11], [use X11 with Cygwin or macOS (default=no)]))

AC_ARG_ENABLE([xcursor], AS_HELP_STRING([--disable-xcursor], [turn off Xcursor support]))

AC_ARG_ENABLE([xfixes], AS_HELP_STRING([--disable-xfixes], [turn off Xfixes support]))

AC_ARG_ENABLE([xft], AS_HELP_STRING([--disable-xft], [turn off Xft support]))

AC_ARG_ENABLE([xinerama], AS_HELP_STRING([--disable-xinerama], [turn off Xinerama support]))

AC_ARG_ENABLE([xrender], AS_HELP_STRING([--disable-xrender], [turn off Xrender support]))

AS_CASE([$host_os], [cygwin* | mingw*], [
  AC_ARG_ENABLE([gdiplus], AS_HELP_STRING([--disable-gdiplus], [don't use GDI+ for antialiased graphics]))

 gdiplus_found=no
    AS_IF([test x$enable_gdiplus != xno], [
        AC_CHECK_HEADERS([wtypes.h gdiplus.h], [
            AC_DEFINE([USE_GDIPLUS])
            LIBS="-lgdiplus $LIBS"
            gdiplus_found=yes
        ], [],
    [[#include <wtypes.h>]])
    ])

])

AS_IF([test x$enable_pango = xyes -a x$enable_xft = xno], [
    AC_MSG_ERROR([--disable-xft and --enable-pango are incompatible because Xft is necessary for Pango.])
])


dnl So --with-archflags option is used during "checking size of long"
# TODO: Fix long long test
AS_IF([test "x$with_archflags" != x], [
    CFLAGS="$CFLAGS $with_archflags"
])


dnl FLTK build options to be used in Makefiles (defined in makeinclude)
BUILD=""


dnl OS-specific pre-tests...
dnl host_os_gui equals $host_os unless we target Cygwin or Darwin in combination with X11.
host_os_gui=$host_os
AS_CASE([$host_os], [cygwin*], [
    # Handle Cygwin option *first*, before all other tests.
    AS_IF([test x$enable_cygwin = xyes], [
        # we target Cygwin in combination with X11
        AS_IF([test x$enable_x11 = xyes], [
            host_os_gui="X11$host_os"
        ])
    ])
], [darwin*], [
    AS_IF([test x$enable_x11 = xyes], [
        host_os_gui="X11"
        macosversion=$(sw_vers -productVersion | cut -d. -f2)
        macosversion_maj=$(sw_vers -productVersion | cut -d. -f1)
        AS_IF([test $macosversion_maj -ge 11 -o $macosversion -ge 13], [
            CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.9 -D_LIBCPP_HAS_THREAD_API_PTHREAD"
        ])
    ])
])


dnl Define the libraries and link options we will need.
LINKFLTK="../lib/libfltk.a"
LINKFLTKFORMS="../lib/libfltk_forms.a"
LINKFLTKGL="../lib/libfltk_gl.a"
LINKFLTKIMG="../lib/libfltk_images.a"
GLDEMOS="gldemos"

LIBEXT=".a"
LIBNAME="../lib/libfltk.a"
FLLIBNAME="../lib/libfltk_forms.a"
GLLIBNAME="../lib/libfltk_gl.a"
IMGLIBNAME="../lib/libfltk_images.a"
CAIROLIBNAME="../lib/libfltk_cairo.a"

LIBBASENAME="libfltk.a"
FLLIBBASENAME="libfltk_forms.a"
GLLIBBASENAME="libfltk_gl.a"
IMGLIBBASENAME="libfltk_images.a"
CAIROLIBBASENAME="libfltk_cairo.a"


dnl Check for Cairo library unless disabled...
CAIRODIR=""
CAIROFLAGS=""
LINKFLTKCAIRO=""
FLTKCAIROOPTION=""
CAIROLIBS=""

AS_IF([test x$enable_cairoext = xyes], [
    AS_IF([$PKGCONFIG --exists cairo], [
        AC_DEFINE([FLTK_HAVE_CAIROEXT])
        AC_DEFINE([FLTK_HAVE_CAIRO])
        CAIRODIR="cairo"
        CAIROFLAGS="$($PKGCONFIG --cflags cairo)"
        CAIROLIBS="$($PKGCONFIG --libs cairo)"
        CXXFLAGS="$CAIROFLAGS $CXXFLAGS"
        LINKFLTKCAIRO="../lib/libfltk_cairo.a"
        FLTKCAIROOPTION="-L ../cairo -lfltk_cairo$SHAREDSUFFIX"
        LIBS="$CAIROLIBS $LIBS"
        LINKFLTK="$LINKFLTK $LINKFLTKCAIRO"
    ], [
        AC_MSG_ERROR([Cairo requested but not available.])
    ])
], [test x$enable_cairo = xyes], [
    AS_IF([$PKGCONFIG --exists cairo], [
        AC_DEFINE(FLTK_HAVE_CAIRO)
        CAIRODIR="cairo"
        CAIROFLAGS="$($PKGCONFIG --cflags cairo)"
        CAIROLIBS="$($PKGCONFIG --libs cairo)"
        CXXFLAGS="$CAIROFLAGS $CXXFLAGS"
        LINKFLTKCAIRO="../lib/libfltk_cairo.a"
        FLTKCAIROOPTION="-L ../cairo -lfltk_cairo$SHAREDSUFFIX"
    ], [
        AC_MSG_ERROR([Cairo requested but not available.])
    ])
])

AC_SUBST(CAIRODIR)
AC_SUBST(CAIROFLAGS)
AC_SUBST(CAIROLIBS)
AC_SUBST(LINKFLTKCAIRO)
AC_SUBST(FLTKCAIROOPTION)

AC_SUBST(FLLIBNAME)
AC_SUBST(GLDEMOS)
AC_SUBST(GLLIBNAME)
AC_SUBST(IMGLIBNAME)
AC_SUBST(CAIROLIBNAME)
AC_SUBST(LIBEXT)
AC_SUBST(LIBNAME)
AC_SUBST(LINKFLTK)
AC_SUBST(LINKFLTKFORMS)
AC_SUBST(LINKFLTKGL)
AC_SUBST(LINKFLTKIMG)

AC_SUBST(LIBBASENAME)
AC_SUBST(FLLIBBASENAME)
AC_SUBST(GLLIBBASENAME)
AC_SUBST(IMGLIBBASENAME)
AC_SUBST(CAIROLIBBASENAME)

AC_ARG_WITH([abiversion], AS_HELP_STRING([--with-abiversion], [Build with FL_ABI_VERSION, e.g. 10304 for FLTK 1.3.4]))
has_abiversion="$with_abiversion"
AS_IF([test "x$has_abiversion" = xyes -o "x$has_abiversion" = xno], [
    has_abiversion=""
])
AS_IF([test "x$has_abiversion" != x], [
    AC_DEFINE_UNQUOTED([FL_ABI_VERSION], [$has_abiversion], [ABI version number])
])


dnl Handle compile-time options...
AS_IF([test "x$enable_shared" = xyes], [
    PICFLAG=1
    SHAREDSUFFIX=""
    FLUID="fluid-shared"
    FLTK_OPTIONS="fltk-options-shared"

    AS_CASE([$host_os], [darwin*], [
        DSONAME="libfltk.$FL_DSO_VERSION.dylib"
        FLDSONAME="libfltk_forms.$FL_DSO_VERSION.dylib"
        GLDSONAME="libfltk_gl.$FL_DSO_VERSION.dylib"
        IMGDSONAME="libfltk_images.$FL_DSO_VERSION.dylib"
        CAIRODSONAME="libfltk_cairo.$FL_DSO_VERSION.dylib"
        DSOCOMMAND="\$(CXX) \$(ARCHFLAGS) \$(DSOFLAGS) -dynamiclib -lc -o"
    ], [solaris*], [
        DSONAME="libfltk.so.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared -fPIC $DEBUGFLAG -o"
        AS_IF([test "x$libdir" != "x/usr/lib"], [
            DSOLINK="-R$libdir"
        ])
    ], [hpux*], [
        DSONAME="libfltk.sl.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.sl.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.sl.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.sl.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.sl.$FL_DSO_VERSION"
        DSOCOMMAND="ld \$(DSOFLAGS) -b -z +h \$@ $DEBUGFLAG -o"
        AS_IF([test "x$libdir" != "x/usr/lib"], [
            DSOLINK="-Wl,-rpath,$libdir"
        ])
    ], [irix*], [
        DSONAME="libfltk.so.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@,-set_version,sgi1.1 \$(LDLIBS) -shared $DEBUGFLAG -o"
        AS_IF([test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib32" -a "x$libdir" != "x/usr/lib64"], [
            DSOLINK="-Wl,-rpath,$libdir"
        ])
    ], [osf*], [
        DSONAME="libfltk.so.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared $DEBUGFLAG -o"
        AS_IF([test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib32"], [
            DSOLINK="-Wl,-rpath,$libdir"
        ])
    ], [linux*|*bsd*], [
        DSONAME="libfltk.so.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared -fPIC $DEBUGFLAG -o"

        # See if the compiler supports -fvisibility...
        AC_CACHE_CHECK([if the compiler supports -fvisibility], ac_cv_cxx_fvisibility, [
            OLDCXXFLAGS="$CXXFLAGS"
            CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
            AC_LANG_PUSH([C++])
            AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM([[]], [[]])],
                [ac_cv_cxx_fvisibility=yes],
                [ac_cv_cxx_fvisibility=no])
            CXXFLAGS="$OLDCXXFLAGS"
            AC_LANG_POP([])
        ])
        AS_IF([test x"$ac_cv_cxx_fvisibility" = xyes], [
            OPTIM="$OPTIM -fvisibility=hidden"
        ])

        # See if the compiler supports -fvisibility-inlines-hidden...
        AC_CACHE_CHECK([if the compiler supports -fvisibility-inlines-hidden], [ac_cv_cxx_fvisibility_inlines], [
            OLDCXXFLAGS="$CXXFLAGS"
            CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden"
            AC_LANG_PUSH([C++])
            AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM([[]], [[]])],
                [ac_cv_cxx_fvisibility_inlines=yes],
                [ac_cv_cxx_fvisibility_inlines=no])
            CXXFLAGS="$OLDCXXFLAGS"
            AC_LANG_POP([])
        ])
        AS_IF([test x"$ac_cv_cxx_fvisibility_inlines" = xyes], [
            CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden"
        ])

        AS_IF([test "x$libdir" != "x/usr/lib" -a "x$libdir" != "x/usr/lib64"], [
            DSOLINK="-Wl,-rpath,$libdir"
        ])
    ], [aix*], [
        DSONAME="libfltk_s.a"
        FLDSONAME="libfltk_forms_s.a"
        GLDSONAME="libfltk_gl_s.a"
        IMGDSONAME="libfltk_images_s.a"
        CAIRODSONAME="libfltk_cairo_s.a"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-bexpall,-bM:SRE,-bnoentry -o"
        SHAREDSUFFIX="_s"
    ], [cygwin* | mingw*], [
        PICFLAG=0
        AS_IF([test x$enable_cygwin != xyes], [
            DSONAME="mgwfltknox-$FL_DSO_VERSION.dll"
            FLDSONAME="mgwfltknox_forms-$FL_DSO_VERSION.dll"
            GLDSONAME="mgwfltknox_gl-$FL_DSO_VERSION.dll"
            IMGDSONAME="mgwfltknox_images-$FL_DSO_VERSION.dll"
            CAIRODSONAME="mgwfltknox_cairo-$FL_DSO_VERSION.dll"
        ], [test x$enable_x11 = xyes], [
            DSONAME="cygfltk-$FL_DSO_VERSION.dll"
            FLDSONAME="cygfltk_forms-$FL_DSO_VERSION.dll"
            GLDSONAME="cygfltk_gl-$FL_DSO_VERSION.dll"
            IMGDSONAME="cygfltk_images-$FL_DSO_VERSION.dll"
            CAIRODSONAME="cygfltk_cairo-$FL_DSO_VERSION.dll"
        ], [
            DSONAME="cygfltknox-$FL_DSO_VERSION.dll"
            FLDSONAME="cygfltknox_forms-$FL_DSO_VERSION.dll"
            GLDSONAME="cygfltknox_gl-$FL_DSO_VERSION.dll"
            IMGDSONAME="cygfltknox_images-$FL_DSO_VERSION.dll"
            CAIRODSONAME="cygfltknox_cairo-$FL_DSO_VERSION.dll"
        ])

        #-----------------------------------------------------------
        # -Wl,--enable-runtime-pseudo-reloc: See str 1585
        # appears to be necessary for older binutils versions < 2.16
        #-----------------------------------------------------------
        LDFLAGS="$LDFLAGS -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -shared -Wl,--whole-archive -Wl,--export-all-symbols  -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-import -Wl,--enable-auto-image-base -o \$@"
    ], [*], [
        AC_MSG_WARN([Shared libraries may not be supported. Trying -shared option with compiler.])
        DSONAME="libfltk.so.$FL_DSO_VERSION"
        FLDSONAME="libfltk_forms.so.$FL_DSO_VERSION"
        GLDSONAME="libfltk_gl.so.$FL_DSO_VERSION"
        IMGDSONAME="libfltk_images.so.$FL_DSO_VERSION"
        CAIRODSONAME="libfltk_cairo.so.$FL_DSO_VERSION"
        DSOCOMMAND="\$(CXX) \$(DSOFLAGS) -Wl,-soname,\$@ \$(LDLIBS) -shared $DEBUGFLAG -o"
    ])

    LINKSHARED="-L../src $FLTKCAIROOPTION -lfltk_images$SHAREDSUFFIX -lfltk_forms$SHAREDSUFFIX -lfltk$SHAREDSUFFIX"
], [
    DSOCOMMAND="echo"
    DSOLINK=""
    DSONAME=""
    FLDSONAME=""
    GLDSONAME=""
    IMGDSONAME=""
    CAIRODSONAME=""
    PICFLAG=0
    SHAREDSUFFIX=""
    FLUID="fluid"
    FLTK_OPTIONS="fltk-options"
    LINKSHARED="$LINKFLTKCAIRO ../lib/libfltk_images.a ../lib/libfltk_forms.a ../lib/libfltk.a"
])


dnl Define the fluid executable used when building the test programs.
dnl In a native build we use the fluid executable created during the build,
dnl in a cross-compilation we use "fluid" which must exist on the build system
dnl and must be in the PATH, i.e. executable as 'fluid' (w/o $EXEEXT).
AS_IF([test "x$fltk_cross_compiling" = xyes], [
    FLUID_BUILD="fluid"
], [
    FLUID_BUILD="../fluid/fluid$EXEEXT"
])

AC_SUBST([DSOCOMMAND])
AC_SUBST([DSOFLAGS])
AC_SUBST([DSOLINK])
AC_SUBST([DSONAME])
AC_SUBST([FLDSONAME])
AC_SUBST([GLDSONAME])
AC_SUBST([IMGDSONAME])
AC_SUBST([CAIRODSONAME])
AC_SUBST([SHAREDSUFFIX])
AC_SUBST([LINKSHARED])
AC_SUBST([FLUID])
AC_SUBST([FLUID_BUILD])
AC_SUBST([FLTK_OPTIONS])


dnl Find commands...
AC_PROG_INSTALL
AS_CASE([$host_os],
[osf*], [
    INSTALL="$(pwd)/install-sh -c"
])

AS_IF([test "x$INSTALL" = "x$ac_install_sh"], [
    # Use full path to install-sh script...
    INSTALL="$(pwd)/install-sh -c"
])

AC_PATH_PROGS([NROFF], [nroff groff], [echo])
AC_PATH_PROG([DOXYDOC], [doxygen])

dnl How do we make libraries?
AC_PROG_RANLIB
AC_PATH_TOOL([AR], [ar])

AS_IF([test "x$AR" = "x:"], [
    AC_MSG_ERROR([Configure could not find the library archiver, aborting.])
])

AS_IF([test "x$RANLIB" != "x:"], [
    LIBCOMMAND="$AR cr"
], [
    LIBCOMMAND="$AR crs"
])

AC_SUBST(LIBCOMMAND)

dnl how to compile (Windows) resource files
dnl this will only be used to compile resources for Windows .exe files
AC_PATH_TOOL(RC,windres)

dnl Architecture checks...
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)
AS_IF([test $ac_cv_sizeof_short -eq 2], [
    AC_DEFINE([U16], [unsigned short])
])
AS_IF([test $ac_cv_sizeof_int -eq 4], [
    AC_DEFINE([U32], [unsigned])
], [test $ac_cv_sizeof_long -eq 4], [
    AC_DEFINE([U32],[unsigned long])
])

AS_CASE([$host_os], [darwin*], [
], [*], [
    AC_C_BIGENDIAN

    AS_IF([test $ac_cv_sizeof_int -eq 8], [
        AC_DEFINE([U64], [unsigned])
    ], [test $ac_cv_sizeof_long -eq 8], [
        AC_DEFINE([U64], [unsigned long])
    ])
])


dnl Standard headers and functions...
AC_HEADER_DIRENT
AC_CHECK_HEADERS([sys/select.h sys/stdtypes.h])

dnl Do we have the POSIX compatible scandir() prototype?
AC_CACHE_CHECK([whether we have the POSIX compatible scandir() prototype], ac_cv_cxx_scandir_posix,[
    AC_LANG_PUSH([C++])
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM(
            [[#include <dirent.h>
              int func (const char *d, dirent ***list, void *sort) {
                int n = scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort);
                return n;
              }
            ]], [[
            ]])],
        [ac_cv_cxx_scandir_posix=yes],
        [ac_cv_cxx_scandir_posix=no])
    AC_LANG_POP([])
])

dnl Define both HAVE_SCANDIR... macros, if the POSIX compatible function is
dnl available. Otherwise: check, whether any scandir prototype is available,
dnl but dont use it on SunOS and QNX because of an incompatibility in pre-Y2K
dnl SunOS scandir versions. We assume, though, that the POSIX compatible
dnl version on newer SunOS/Solaris versions works as expected.
AS_IF([test "x$ac_cv_cxx_scandir_posix" = xyes], [
    AC_DEFINE([HAVE_SCANDIR])
    AC_DEFINE([HAVE_SCANDIR_POSIX])
], [
    AC_CHECK_FUNC([scandir], [
        AS_CASE([$host_os], [solaris* | *qnx*], [
            AC_MSG_WARN([Not using $host_os scandir emulation function.])
        ], [*], [
            AC_DEFINE([HAVE_SCANDIR])
        ])
    ])
])

AC_CHECK_FUNC([vsnprintf], [
    AS_CASE([$host_os], [hpux1020], [
        AC_MSG_WARN([Not using built-in vsnprintf function because you are running HP-UX 10.20.])
    ], [osf4], [
        AC_MSG_WARN([Not using built-in vsnprintf function because you are running Tru64 4.0.])
    ], [*], [
        AC_DEFINE([HAVE_VSNPRINTF])
    ])
])

AC_CHECK_FUNC([snprintf], [
    AS_CASE([$host_os], [hpux1020], [
        AC_MSG_WARN([Not using built-in snprintf function because you are running HP-UX 10.20.])
    ], [osf4], [
        AC_MSG_WARN([Not using built-in snprintf function because you are running Tru64 4.0.])
    ], [*], [
        AC_DEFINE([HAVE_SNPRINTF])
    ])
])

AC_CHECK_HEADERS([strings.h])
AC_CHECK_FUNCS([strcasecmp strlcat strlcpy])

AC_CHECK_HEADERS([locale.h])
AC_CHECK_FUNCS([localeconv])


dnl FLTK library uses math library functions...
AC_SEARCH_LIBS([pow], [m])


dnl Check for largefile support...
AC_SYS_LARGEFILE

LARGEFILE=""
AS_IF([test x$enable_largefile != xno], [
    LARGEFILE="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"

    AS_IF([test x$ac_cv_sys_large_files = x1], [
        LARGEFILE="$LARGEFILE -D_LARGE_FILES"
    ])

    AS_IF([test x$ac_cv_sys_file_offset_bits = x64], [
        LARGEFILE="$LARGEFILE -D_FILE_OFFSET_BITS=64"
    ])
])
AC_SUBST(LARGEFILE)


dnl Check for "long long" support...
AC_CACHE_CHECK([for long long int], [ac_cv_c_long_long], [
    AS_IF([test "$GCC" = yes], [
        ac_cv_c_long_long=yes
    ], [
        AC_COMPILE_IFELSE(
            [AC_LANG_PROGRAM([[]],
                [[long long int i;]])],
            [ac_cv_c_long_long=yes],
            [ac_cv_c_long_long=no])
    ])
])

AS_IF([test $ac_cv_c_long_long = yes], [
    AC_DEFINE([HAVE_LONG_LONG])
])


dnl Check for dlopen/dlsym...
AC_SEARCH_LIBS([dlsym], [dl], AC_DEFINE([HAVE_DLSYM]))
AC_CHECK_HEADER([dlfcn.h], AC_DEFINE([HAVE_DLFCN_H]))


dnl Check for audio libraries...
AUDIOLIBS=""

AS_CASE([$host_os], [cygwin* | mingw*], [
    dnl Cygwin environment...
    AUDIOLIBS="-lwinmm"
], [darwin*], [
    AUDIOLIBS="-framework CoreAudio"
], [*], [
    AC_CHECK_HEADER([alsa/asoundlib.h], [
        AC_DEFINE([HAVE_ALSA_ASOUNDLIB_H])
        AUDIOLIBS="-lasound"
    ])
])

AC_SUBST(AUDIOLIBS)


dnl Check for image libraries...
SAVELIBS="$LIBS"
IMAGELIBS=""
STATICIMAGELIBS=""

AC_SUBST([IMAGELIBS])
AC_SUBST([STATICIMAGELIBS])

# Handle the ZLIB lib linking mode (use fltk local or system lib)
# If --enable-(resp. --disable-)localzlib parameter is not set by user
# Then we check the ZLIB lib usability, with result in syszlib_ok variable
# Check for System lib use if automatic mode or --disable-localzlib is requested
syszlib_ok=no
syszinc_ok=no
AS_IF([test x$enable_localzlib != xyes], [
    AC_CHECK_LIB([z], [gzgets], [
        AC_CHECK_HEADER([zlib.h], [syszinc_ok=yes])
        AS_IF([test x$syszinc_ok = xyes], [
            syszlib_ok=yes
        ])
    ])
])

# Handle the PNG lib linking mode (use fltk local or system lib)
# If --enable-(resp. --disable-)localpng parameter is not set by user
# Then we check the png lib usability with result in syspng_lib variable

# Now check if system lib is usable, we check Lib AND include availability with inc variant,
# but only, if the builtin lib is not requested
syspnglib_ok=no
syspnginc_ok=no
AS_IF([test x$enable_localpng != xyes], [
    AC_CHECK_LIB([png], [png_read_info], [
        AC_CHECK_HEADER([png.h], [
            AC_DEFINE([HAVE_PNG_H])
            syspnginc_ok=yes
        ])
        AC_CHECK_HEADER([libpng/png.h], [
            syspnginc_ok=yes
        ])
        AS_IF([test x$syspnginc_ok = xyes], [
            syspnglib_ok=yes
        ])
    ])
])

# If we use the system zlib, we must also use the system png zlib and vice versa
# If either of them is not available, we fall back to using both local libraries
AS_IF([test x$syspnglib_ok = xyes -a x$syszlib_ok != xyes], [
    syspnglib_ok=no
    enable_localpng=yes
    AC_MSG_WARN([Local z lib selected: overriding png lib to local for compatibility.])
])
AS_IF([test x$syszlib_ok = xyes -a x$syspnglib_ok != xyes], [
    syszlib_ok=no
    enable_localzlib=yes
    AC_MSG_WARN([Local png lib selected: overriding z lib to local for compatibility.])
])


# Now set the Z lib and include flags according to the requested mode and availability
AS_IF([test x$enable_localzlib = xyes -o x$syszlib_ok = xno], [
    ZLIBINC="-I../zlib"
    ZLIB="zlib"
    LIBS="-lfltk_z $LIBS"
    IMAGELIBS="-lfltk_z $IMAGELIBS"
    STATICIMAGELIBS="\$libdir/libfltk_z.a $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBZ])
    ac_cv_lib_z_gzgets=no # fc: is still necessary ?
    # Finally, warn user if system lib was requested but not found
    AS_IF([test x$enable_localzlib = xno], [
        AC_MSG_WARN([Cannot find system z lib or header: choosing the local lib mode.])
    ])
], [
    ZLIBINC=""
    ZLIB=""
    LIBS="-lz $LIBS"
    IMAGELIBS="-lz $IMAGELIBS"
    STATICIMAGELIBS="-lz $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBZ])
])


# The following is executed if the png lib was not found usable or if local lib is required explicitly
AS_IF([test x$enable_localpng = xyes -o x$syspnglib_ok = xno], [
    PNGINC="-I../png"
    PNG="png"
    IMAGELIBS="-lfltk_png $IMAGELIBS"
    STATICIMAGELIBS="\$libdir/libfltk_png.a $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBPNG])
    AC_DEFINE([HAVE_PNG_H])
    AC_DEFINE([HAVE_PNG_GET_VALID])
    AC_DEFINE([HAVE_PNG_SET_TRNS_TO_ALPHA])
    # Finally, warn user if system lib was requested but not found
    AS_IF([test x$enable_localpng = xno], [
        AC_MSG_WARN([Cannot find system png lib or header: choosing the local lib mode.])
    ])
], [
    PNGINC=""
    PNG=""
    IMAGELIBS="-lpng $IMAGELIBS"
    STATICIMAGELIBS="-lpng $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBPNG])
    AC_CHECK_LIB([png], [png_get_valid], [
        AC_DEFINE([HAVE_PNG_GET_VALID])
    ])
    AC_CHECK_LIB([png], [png_set_tRNS_to_alpha], [
        AC_DEFINE([HAVE_PNG_SET_TRNS_TO_ALPHA])
    ])
])


# Handle the JPEG lib linking mode (use fltk local or system lib)
# If --enable-(resp. --disable-)localjpeg parameter is not set by user
# Then we check the JPEG lib usability, with result in sysjpeglib_ok variable
# Check for System lib use if automatic mode or --disable-localjpeg is requested
sysjpeglib_ok=no
sysjpeginc_ok=no
AS_IF([test x$enable_localjpeg != xyes], [
    AC_CHECK_LIB([jpeg], [jpeg_CreateCompress], [
        AC_CHECK_HEADER([jpeglib.h], [sysjpeginc_ok=yes])
        AS_IF([test x$sysjpeginc_ok = xyes], [
            sysjpeglib_ok=yes
        ])
    ])
])

# Now set the jpeg lib and include flags according to the requested mode and availability
AS_IF([test x$enable_localjpeg = xyes -o x$sysjpeglib_ok = xno], [
    JPEGINC="-I../jpeg"
    JPEG="jpeg"
    IMAGELIBS="-lfltk_jpeg $IMAGELIBS"
    STATICIMAGELIBS="\$libdir/libfltk_jpeg.a $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBJPEG])
    # Finally, warn user if system lib was requested but not found
    AS_IF([test x$enable_localjpeg = xno], [
        AC_MSG_WARN([Cannot find system jpeg lib or header: choosing the local lib mode.])
    ])
], [
    JPEGINC=""
    JPEG=""
    IMAGELIBS="-ljpeg $IMAGELIBS"
    STATICIMAGELIBS="-ljpeg $STATICIMAGELIBS"
    AC_DEFINE([HAVE_LIBJPEG])
])

AC_SUBST([JPEG])
AC_SUBST([JPEGINC])
AC_SUBST([PNG])
AC_SUBST([PNGINC])
AC_SUBST([HAVE_PNG_H])
AC_SUBST([ZLIB])
AC_SUBST([ZLIBINC])


# Control the usage of the nanosvg lib and SVG output

dnl Restore original LIBS settings...
LIBS="$SAVELIBS"

dnl See if we need a .exe extension on executables...
AC_EXEEXT

dnl Check for pthreads for multi-threaded apps...
have_pthread=no
PTHREAD_FLAGS=""

dnl Test whether we want to check for pthreads. We must not do it on Windows
dnl unless we run under Cygwin with --enable-cygwin, since we always use
dnl native threads on Windows (even if libpthread is available)
check_pthread=yes
AS_CASE([$host_os], [mingw*], [
    check_pthread=no
], [cygwin*], [
    AS_IF([test "x$enable_cygwin" != xyes], [
        check_pthread=no
    ])
])

AS_IF([test "x$enable_threads" != xno -a x$check_pthread = xyes], [
    AC_CHECK_HEADERS([pthread.h])

    AS_IF([test x$ac_cv_header_pthread_h = xyes], [
        dnl Check various threading options for the platforms we support
        for flag in -lpthreads -lpthread -pthread; do
            AC_MSG_CHECKING([for pthread_create using $flag])
            SAVELIBS="$LIBS"
            LIBS="$flag $LIBS"
            AC_LINK_IFELSE(
                [AC_LANG_PROGRAM(
                    [[#include <pthread.h>]],
                    [[pthread_create(0, 0, 0, 0);]])],
                [have_pthread=yes],
                [LIBS="$SAVELIBS"])
            AC_MSG_RESULT([$have_pthread])

            AS_IF([test $have_pthread = yes], [
                AC_DEFINE([HAVE_PTHREAD])
                PTHREAD_FLAGS="-D_THREAD_SAFE -D_REENTRANT"

                # Solaris requires -D_POSIX_PTHREAD_SEMANTICS to
                # be POSIX-compliant... :(
                AS_CASE([$host_os], [solaris*], [
                    PTHREAD_FLAGS="$PTHREAD_FLAGS -D_POSIX_PTHREAD_SEMANTICS"
                ])
            ])
        done

        dnl Check if we have PTHREAD_MUTEX_RECURSIVE
        AC_CACHE_CHECK([whether we have PTHREAD_MUTEX_RECURSIVE], ac_cv_pthread_mutex_recursive,[
            AC_LANG_PUSH([C])
            AC_COMPILE_IFELSE(
                [AC_LANG_PROGRAM(
                    [[#include <pthread.h>
                    ]], [[
                        return PTHREAD_MUTEX_RECURSIVE;
                    ]])],
                [ac_cv_pthread_mutex_recursive=yes],
                [ac_cv_pthread_mutex_recursive=no])
            AC_LANG_POP([])
        ])
        AS_IF([test x$ac_cv_pthread_mutex_recursive = xyes], [
            AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE])
        ])
    ])
])

AC_SUBST([PTHREAD_FLAGS])
AC_SUBST([HAVE_PTHREAD_MUTEX_RECURSIVE])


dnl Define OS-specific stuff...
HLINKS=
OSX_ONLY=:
THREADS=
LIBDECORDIR=""

AC_ARG_WITH([links], AS_HELP_STRING([--with-links], [make header links for common misspellings (default=no)]))

INSTALL_DESKTOP=""
UNINSTALL_DESKTOP=""

AS_CASE([$host_os_gui], [cygwin* | mingw*], [
    dnl Cygwin environment, using windows GDI ...
    # Recent versions of Cygwin are seriously broken and the size
    # checks don't work because the shell puts out \r\n instead of
    # \n.  Here we just force U32 to be defined to "unsigned"...
    AC_DEFINE([U32], [unsigned])
    # We do no longer define WIN32 or _WIN32 (since FLTK 1.4.0)
    # and we don't need to define USE_OPENGL32 (added in svn r6657
    # but never used, see STR #2147)
    # CFLAGS="-mwindows -D_WIN32 -DUSE_OPENGL32 $CFLAGS"
    # CXXFLAGS="-mwindows -D_WIN32 -DUSE_OPENGL32 $CXXFLAGS"
    CFLAGS="-mwindows $CFLAGS"
    CXXFLAGS="-mwindows $CXXFLAGS"
    LDFLAGS="-mwindows $LDFLAGS"
    DSOFLAGS="-mwindows $DSOFLAGS"
    LIBS="$LIBS -lole32 -luuid -lcomctl32 -lws2_32"

    BUILD="WIN"
    AS_IF([test "x$with_optim" = x], [
        dnl Avoid -Os optimization on Cygwin/MinGW
        with_optim="-O3"
    ])

    AS_IF([test x$enable_gl != xno], [
        AC_CHECK_HEADER([GL/gl.h], [
            AC_DEFINE([HAVE_GL])
            GLLIBS="-lopengl32"
        ])
        AC_CHECK_HEADER([GL/glu.h], [
            AC_DEFINE([HAVE_GL_GLU_H])
            GLLIBS="-lglu32 $GLLIBS"
        ])
    ], [
        LINKFLTKGL=""
        GLLIBNAME=""
        GLDSONAME=""
        GLDEMOS=""
    ])

    AS_IF([test "x$enable_threads" != xno -a x$have_pthread = xyes], [
        AC_DEFINE([HAVE_PTHREAD])
    ])

    THREADS="threads$EXEEXT"

    # Don't make symlinks since Windows is not case sensitive.
    AS_IF([test "x$with_links" != xyes], [
        HLINKS="#"
    ])
], [darwin*], [
    BUILD="OSX"

    # MacOS X uses Cocoa for graphics.
    LIBS="$LIBS -framework Cocoa"

    AS_IF([test x$have_pthread = xyes], [
        AC_DEFINE([HAVE_PTHREAD])
        THREADS="threads$EXEEXT"
    ])

    AS_IF([test x$enable_gl != xno], [
        AC_DEFINE([HAVE_GL])
        AC_DEFINE([HAVE_GL_GLU_H])
        GLLIBS="-framework OpenGL"
    ], [
        LINKFLTKGL=""
        GLLIBNAME=""
        GLDSONAME=""
        GLDEMOS=""
    ])

    # Don't make symlinks because HFS+ is not case sensitive...
    AS_IF([test "x$with_links" != xyes], [
        HLINKS="#"
    ])

    # Some steps are only done for OS X package management
    OSX_ONLY=

    # Install/Uninstall FLUID application
    INSTALL_DESKTOP="install-osx"
    UNINSTALL_DESKTOP="uninstall-osx"
], [*], [
    # All others are UNIX/X11...
    # This includes Cygwin target combined with X11
    AS_IF([test x$have_pthread = xyes], [
        AC_DEFINE([HAVE_PTHREAD])
        THREADS="threads$EXEEXT"
    ])

    AS_IF([test x$enable_wayland != xno], [
      AS_IF([test x$PKGCONFIG = x], [
        dnl pkg-config is not available, issue warning and possibly abort...
        AS_IF([test x$enable_wayland = xyes], [
          AC_MSG_WARN([--enable-wayland: please install pkg-config.])
          AC_MSG_ERROR([Aborting.])
        ],[
          AC_MSG_WARN([pkg-config is not found. Continuing with --disable-wayland])
          enable_wayland="no"
        ])
      ],[
        missing="no"
        AS_IF([$PKGCONFIG --exists wayland-client],[],[missing="yes"])
        AS_IF([$PKGCONFIG --exists wayland-protocols],[],[missing="yes"])
        AS_IF([$PKGCONFIG --exists wayland-cursor],[],[missing="yes"])
        AS_IF([$PKGCONFIG --exists xkbcommon],[],[missing="yes"])
        AS_IF([$PKGCONFIG --exists dbus-1],[],[missing="yes"])
        AS_IF([$PKGCONFIG --exists pangocairo],[],[missing="yes"])
        AS_IF([test x$missing = xyes], [
            AC_MSG_WARN([These packages 'wayland-client wayland-protocols wayland-cursor xkbcommon dbus-1 pangocairo' are required to build FLTK for wayland.])
            AC_MSG_WARN([At least one of them is missing.])
          AS_IF([test x$enable_wayland = xyes], [
            AC_MSG_ERROR([Building for Wayland is not possible. Aborting.])
          ],[
            AC_MSG_WARN([Continuing with --disable-wayland])
            enable_wayland="no"
          ])
        ])
      ])
    ])

    AS_IF([test x$enable_wayland != xno], [
      dnl Prepare for Wayland...
      dnl Turn option usecairo ON
      AC_DEFINE([FLTK_USE_CAIRO])
      AC_MSG_NOTICE([Turning on the usecairo option])

      BUILD="WAYLAND"
      AC_DEFINE([FLTK_USE_WAYLAND])
      graphics="Wayland"
      AS_IF([test x$enable_x11 != xno], [
       AC_DEFINE([FLTK_USE_X11]) # to build a hybrid Wayland/X11 library
       BUILD="WAYLANDX11"
       graphics="Wayland or X11 with cairo"
       ])
#     CFLAGS="$CFLAGS -DUSE_SYSTEM_LIBDECOR=0"
#     CXXFLAGS="$CXXFLAGS -DUSE_SYSTEM_LIBDECOR=0"
      LIBS="$LIBS $($PKGCONFIG --libs wayland-cursor) $($PKGCONFIG --libs wayland-client) $($PKGCONFIG --libs xkbcommon) $($PKGCONFIG --libs pangocairo) "
      AS_IF([test x$enable_x11 != xno], [LIBS="$LIBS $($PKGCONFIG --libs x11)"] )
      LIBS="$LIBS $($PKGCONFIG --libs dbus-1) -ldl"
#     CXXFLAGS="$CXXFLAGS -I../libdecor/src"
      DSOFLAGS="$LIBS $DSOFLAGS"
      enable_pango=yes
      LIBDECORDIR="libdecor/build"
      LDFLAGS="$LDFLAGS -rdynamic"
      AC_SUBST([UNAME])
      UNAME="$(uname -s)"
      AS_CASE([$UNAME],
         [Linux], [LDFLAGS="$LDFLAGS -no-pie"]
      )

      AC_SEARCH_LIBS([dlopen], [dl])

      AS_IF([test x$enable_gl != xno], [
          AS_IF([$PKGCONFIG --exists gl], [
            AS_IF([$PKGCONFIG --exists egl], [
              AS_IF([$PKGCONFIG --exists wayland-egl], [
                AC_DEFINE([HAVE_GL])
                GLLIBS="$($PKGCONFIG --libs wayland-egl) $($PKGCONFIG --libs egl) $($PKGCONFIG --libs gl) $GLLIBS"
          ])])])
          AS_IF([$PKGCONFIG --exists glu], [
             AC_DEFINE([HAVE_GL_GLU_H])
             GLLIBS="$($PKGCONFIG --libs glu) $GLLIBS"
          ])
          AC_CHECK_LIB([GL], [glXGetProcAddressARB], [AC_DEFINE([HAVE_GLXGETPROCADDRESSARB])
             ],, [-lm])
      ], [
          LINKFLTKGL=""
          GLLIBNAME=""
          GLDSONAME=""
          GLDEMOS=""
      ])

      dnl Check for GTK-3 ...
      gtk_found=no
      CFLAGS="$($PKGCONFIG --cflags gtk+-3.0) $CFLAGS"
      AC_CHECK_HEADERS([gtk/gtk.h], [
          CFLAGS="$CFLAGS -DHAVE_GTK"
          LIBS="$LIBS $($PKGCONFIG --libs gtk+-3.0)"
          gtk_found=yes
      ])

      dnl Check for the Pango library ...
      pango_found=no
      CFLAGS="$($PKGCONFIG --cflags pangocairo) $CFLAGS"
      CXXFLAGS="$($PKGCONFIG --cflags pangocairo) $CXXFLAGS"
      LIBS="$LIBS $($PKGCONFIG --libs pangocairo)"

      AC_CHECK_HEADERS([pango/pangocairo.h], [
          AC_DEFINE([USE_PANGO])
          AC_DEFINE([USE_XFT])
          pango_found=yes
      ])

      dnl Early abort if Pango could not be found
      AS_IF([test x$pango_found != xyes], [
          AC_MSG_NOTICE([--enable-wayland: Pango libs and/or headers could not be found.])
          AC_MSG_ERROR([Aborting.])
      ])

      dnl check for Xinerama, Xcursor, Xfixes, Xrender, Xregion.h
      AS_IF([test x$enable_x11 != xno], [
        xinerama_found=no
        AS_IF([$PKGCONFIG --exists xinerama], [
          AC_DEFINE(HAVE_XINERAMA)
          LIBS="$LIBS $($PKGCONFIG --libs xinerama)"
          xinerama_found=yes
        ])

        xcursor_found=no
        AS_IF([$PKGCONFIG --exists xcursor], [
          AC_DEFINE(HAVE_XCURSOR)
          LIBS="$LIBS $($PKGCONFIG --libs xcursor)"
          xcursor_found=yes
        ])

        xfixes_found=no
        AS_IF([$PKGCONFIG --exists xfixes], [
          AC_DEFINE(HAVE_XFIXES)
          LIBS="$LIBS $($PKGCONFIG --libs xfixes)"
          xfixes_found=yes
        ])

        xrender_found=no
        AS_IF([$PKGCONFIG --exists xrender], [
          AC_DEFINE(HAVE_XRENDER)
          LIBS="$LIBS $($PKGCONFIG --libs xrender)"
          xrender_found=yes
        ])

        AC_CHECK_HEADER([X11/Xregion.h], [
          AC_DEFINE([HAVE_X11_XREGION_H])
        ], [], [#include <X11/Xlib.h>])
      ])

    ], [

    dnl Check for X11...
    AC_PATH_XTRA

    AS_IF([test x$no_x = xyes], [
        AC_MSG_ERROR([Configure could not find required X11 libraries, aborting.])
    ])

    AS_IF([test "x$X_PRE_LIBS" != x], [
        AC_MSG_WARN([Ignoring libraries "$X_PRE_LIBS" requested by configure.])
    ])

    LIBS="$LIBS -lX11 $X_EXTRA_LIBS"
    CFLAGS="$CFLAGS $X_CFLAGS"
    CXXFLAGS="$CXXFLAGS $X_CFLAGS"
    AS_CASE([$host_os], [darwin*], [
      DARWIN_LDFLAGS="$LDFLAGS"
    ])
    LDFLAGS="$X_LIBS $LDFLAGS"
    DSOFLAGS="$X_LIBS $DSOFLAGS"
    AC_DEFINE([FLTK_USE_X11])
    BUILD="X11"
    AS_IF([test "x$x_includes" != x], [
        ac_cpp="$ac_cpp -I$x_includes"
    ])

    dnl Check for OpenGL unless disabled...
    GLLIBS=

    AS_IF([test x$enable_gl != xno], [
        AC_SEARCH_LIBS([dlopen], [dl])
        AC_CHECK_HEADER([GL/gl.h], [
            AC_CHECK_LIB([GL], [glXMakeCurrent], [
                AC_DEFINE([HAVE_GL])
                GLLIBS="-lGL"
            ], [
                AC_CHECK_LIB([MesaGL], [glXMakeCurrent], [
                    AC_DEFINE([HAVE_GL])
                    GLLIBS="-lMesaGL"
                ],, [-lm]),
            ], [-lm])
            AC_CHECK_LIB([GL], [glXGetProcAddressARB], [
                AC_DEFINE([HAVE_GLXGETPROCADDRESSARB])
            ],, [-lm])
        ])
        AC_CHECK_HEADER([GL/glu.h], [
            AC_DEFINE([HAVE_GL_GLU_H])
            AS_IF([test x$ac_cv_lib_GL_glXMakeCurrent = xyes], [
                GLLIBS="-lGLU $GLLIBS"
            ])
            AS_IF([test x$ac_cv_lib_MesaGL_glXMakeCurrent = xyes], [
                GLLIBS="-lMesaGLU $GLLIBS"
            ])
        ])

        AS_IF([test x$ac_cv_lib_GL_glXMakeCurrent != xyes -a x$ac_cv_lib_MesaGL_glXMakeCurrent != xyes], [
            LINKFLTKGL=""
            GLLIBNAME=""
            GLDSONAME=""
            GLDEMOS=""
        ])
    ], [
        LINKFLTKGL=""
        GLLIBNAME=""
        GLDSONAME=""
        GLDEMOS=""
    ])

    xinerama_found=no
    AS_IF([test x$enable_xinerama != xno], [
        AC_CHECK_LIB([Xinerama], [XineramaIsActive], [
            AC_DEFINE([HAVE_XINERAMA])
            LIBS="-lXinerama $LIBS"
            xinerama_found=yes
        ])
    ])

    dnl Check for the Xft library unless disabled...
    xft_found=no
    AS_IF([test x$enable_xft != xno -a x$enable_wayland = xno], [
        # Try pkg-config first (freetype2 deprecated freetype-config from some version on)
        FT_FLAGS=""
        AS_IF([test "x$PKGCONFIG" != x], [
            FT_FLAGS="$($PKGCONFIG --cflags xft)"
            AS_IF([test "x$FT_FLAGS" = x], [
                FT_FLAGS="$($PKGCONFIG --cflags freetype2)"
            ])
        ])

        # if that failed, try freetype-config
        AS_IF([test "x$FT_FLAGS" = x], [
            AC_PATH_PROG([FTCONFIG], [freetype-config])
            AS_IF([test "x$FTCONFIG" != x], [
                FT_FLAGS="$($FTCONFIG --cflags)"
            ], [
                # abort if both methods failed
                AC_MSG_NOTICE([please install pkg-config or use 'configure --disable-xft'.])
                AC_MSG_ERROR([Aborting.])
            ])
        ])
        CPPFLAGS="$FT_FLAGS $CPPFLAGS"
        CXXFLAGS="$FT_FLAGS $CXXFLAGS"
        CFLAGS="$FT_FLAGS $CFLAGS"

        AC_CHECK_LIB([fontconfig], [FcPatternCreate])
        AC_CHECK_HEADER([X11/Xft/Xft.h], [
            AC_CHECK_LIB([Xft], [XftDrawCreate], [
                AC_DEFINE([USE_XFT])
                LIBS="-lXft $LIBS"
                BUILD="XFT"
                xft_found=yes
            ])
        ])
    ])

    dnl Issue a warning message if Xft was not found, abort configure
    dnl if Xft was requested explicitly (but not found)
    AS_IF([test x$enable_xft != xno -a x$xft_found != xyes], [
        AC_MSG_WARN([could not find the required Xft headers and/or libraries.])
        AC_MSG_NOTICE([please install Xft headers and libraries or use 'configure --disable-xft'.])
        AS_IF([test x$enable_xft = xyes], [
            AC_MSG_ERROR([Aborting.])
        ])
    ])

    dnl Option usecairo
    AS_IF([test x$enable_usecairo = xyes], [
      enable_pango=yes
      BUILD="CAIRO"
      AC_DEFINE([FLTK_USE_CAIRO])
      AC_MSG_NOTICE([Processing usecairo option])
      ]
    )

    dnl test if Pango is asked but xft was not found
    AS_IF([test x$enable_pango = xyes -a x$xft_found = xno], [
        AC_MSG_WARN([could not find the Xft headers and/or libraries required for Pango.])
        AC_MSG_NOTICE([please install Xft headers and libraries or don't use configure with '--enable-pango'.])
        AC_MSG_ERROR([Aborting.])
    ])

    dnl Check for the Pango library unless disabled...
    pango_found=no
    AS_IF([test x$enable_pango = xyes], [
        AS_IF([test x$PKGCONFIG != x], [
            dnl pkg-config is available, use it...
            dnl AC_MSG_NOTICE([--enable-pango: using pkg-config ...])
            CXXFLAGS="$($PKGCONFIG --cflags pangocairo) $CXXFLAGS"
            AS_CASE([$host_os], [darwin*], [], [*], [
              CXXFLAGS="$($PKGCONFIG --cflags pangoxft) $CXXFLAGS"
            ])
            AS_CASE([$host_os], [darwin*], [
              DARWIN_SAVE_LIBS=$LIBS
              DARWIN_PANGO_LIBS="$($PKGCONFIG --libs pangocairo)"
              LIBS="$($PKGCONFIG --libs pangocairo) $LIBS"
            ], [*], [
              LIBS="$($PKGCONFIG --libs pangocairo --libs pangoxft) $LIBS"
            ])
        ], [
            dnl pkg-config is not available, issue warning and continue...
            AC_MSG_WARN([--enable-pango: please install pkg-config. Continuing anyway.])
        ])

        CPPFLAGS="$CXXFLAGS"
        AS_CASE([$host_os], [darwin*],
          [AC_CHECK_HEADERS([pango/pango.h], [
            AC_CHECK_LIB([pango-1.0], [pango_layout_new], [
              AC_DEFINE([USE_PANGO])
              pango_found=yes
              LIBS=$DARWIN_SAVE_LIBS
              ])
          ])
        ],[*], [
          AC_CHECK_HEADERS([pango/pango.h pango/pangoxft.h], [
            AC_CHECK_LIB([pango-1.0], [pango_layout_new], [
                AC_CHECK_LIB([pangoxft-1.0], [pango_xft_render_layout], [
                    AC_DEFINE([USE_PANGO])
                    pango_found=yes
                ])
            ])
          ])
        ])

        dnl Early abort if --enable-pango was requested but Pango could not be found
        AS_IF([test x$pango_found != xyes], [
            AC_MSG_NOTICE([--enable-pango: Pango libs and/or headers could not be found.])
            AC_MSG_ERROR([Aborting.])
        ])
    ])

    dnl Check for the Xfixes extension unless disabled...
    xfixes_found=no
    AS_IF([test x$enable_xfixes != xno], [
        AC_CHECK_HEADER([X11/extensions/Xfixes.h], [
            AC_CHECK_LIB([Xfixes], [XFixesQueryExtension], [
                AC_DEFINE([HAVE_XFIXES])
                LIBS="-lXfixes $LIBS"
                xfixes_found=yes
            ])
        ], [], [#include <X11/Xlib.h>])
    ])

    dnl Check for the Xcursor library unless disabled...
    xcursor_found=no
    AS_IF([test x$enable_xcursor != xno], [
        AC_CHECK_HEADER([X11/Xcursor/Xcursor.h], [
            AC_CHECK_LIB([Xcursor], [XcursorImageCreate], [
                AC_DEFINE([HAVE_XCURSOR])
                LIBS="-lXcursor $LIBS"
                xcursor_found=yes
            ])
        ], [], [#include <X11/Xlib.h>])
    ])

    dnl Check for the Xrender library unless disabled...
    xrender_found=no
    AS_IF([test x$enable_xrender != xno], [
        AC_CHECK_HEADER([X11/extensions/Xrender.h], [
            AC_CHECK_LIB([Xrender], [XRenderQueryVersion], [
                AC_DEFINE([HAVE_XRENDER])
                LIBS="-lXrender $LIBS"
                xrender_found=yes
            ])
        ], [], [#include <X11/Xlib.h>])
    ])

    AS_CASE([$host_os], [darwin*], [
      AS_IF([test x$pango_found = xyes], [
        #place X_LIBS after homebrew's pango libs
        LIBS="$DARWIN_PANGO_LIBS $X_LIBS $LIBS"
        #remove X_LIBS from LDFLAGS while keeping its initial content
        LDFLAGS="$DARWIN_LDFLAGS"
      ])
    ])

    dnl Check for the X11/Xregion.h header file...
    AC_CHECK_HEADER([X11/Xregion.h], [
        AC_DEFINE([HAVE_X11_XREGION_H])
    ], [], [#include <X11/Xlib.h>])

    ])

    # Make symlinks since UNIX/Linux is case sensitive,
    # but Cygwin in general not.
    AS_CASE([$host_os], [cygwin*], [
        HLINKS="#"
    ])

    # Make symlinks since UNIX/Linux is case sensitive,
    # but only if explicitly configured (default=no)
    AS_IF([test "x$with_links" != xyes], [
        HLINKS="#"
    ])

    # Install/Uninstall FLUID application support files
    INSTALL_DESKTOP="install-linux"
    UNINSTALL_DESKTOP="uninstall-linux"
])

AC_SUBST([GLDEMOS])
AC_SUBST([GLLIBS])
AC_SUBST([HLINKS])
AC_SUBST([OSX_ONLY])
AC_SUBST([THREADS])

AC_SUBST([LIBDECORDIR])

AC_SUBST([INSTALL_DESKTOP])
AC_SUBST([UNINSTALL_DESKTOP])

AC_SUBST([BUILD])

dnl Figure out the appropriate formatted man page extension...
AS_CASE(["$host_os"], [*bsd* | darwin*], [
    # *BSD
    CAT1EXT=0
    CAT3EXT=0
    CAT6EXT=0
], [irix*], [
    # SGI IRIX
    CAT1EXT=z
    CAT3EXT=z
    CAT6EXT=z
], [*], [
    # All others
    CAT1EXT=1
    CAT3EXT=3
    CAT6EXT=6
])

AC_SUBST([CAT1EXT])
AC_SUBST([CAT3EXT])
AC_SUBST([CAT6EXT])

dnl Fix "mandir" variable...
AS_IF([test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"], [
    AS_CASE(["$host_os"], [*bsd* | darwin* | linux*], [
        # *BSD, Darwin, and Linux
        mandir="\${prefix}/share/man"
    ], [irix*], [
        # SGI IRIX
        mandir="\${prefix}/share/catman"
    ])
])

dnl Fix "libdir" variable...
AS_IF([test "$prefix" = NONE], [
    prefix=/usr/local
])

AS_IF([test "$exec_prefix" = NONE], [
    exec_prefix="\${prefix}"
])

AS_CASE([$host_os], [irix[1-5]*], [
], [irix*], [
    AS_IF([test "$libdir" = "\${exec_prefix}/lib" -a "$exec_prefix" = "\${prefix}" -a "$prefix" = "/usr"], [
        libdir="/usr/lib32"
    ])
])

dnl Define the command used to update the dependencies (this option
dnl mainly for FLTK core developers - not necessary for users)
MAKEDEPEND="\$(CXX) -M"
AC_SUBST([MAKEDEPEND])

dnl Add warnings to compiler switches:
dnl do this last so messing with switches does not break tests

AS_IF([test -n "$GCC"], [
    # Show all standard warnings + unused variables, conversion errors,
    # and inlining problems when compiling...
    OPTIM="-Wall -Wunused -Wno-format-y2k $OPTIM"

    # The following additional warnings are useful for tracking down problems...
    #OPTIM="-Wshadow -Wconversion $OPTIM"

    # We know that Carbon is deprecated on OS X 10.4. To avoid hundreds of warnings
    # we will temporarily disable 'deprecated' warnings on OS X.
    AS_CASE([$host_os], [darwin[1-7]], [
    ], [darwin*], [
        OPTIM="-Wno-deprecated-declarations $OPTIM"
    ])

    # Set the default compiler optimizations...
    AS_IF([test -z "$DEBUGFLAG"], [
        #
        # Note: Can't use -fomit-frame-pointer - prevents tools like
        #       libsafe from working!
        #
        #       Don't use -fforce-mem, -fforce-addr, or -fcaller-saves.
        #       They all seem to make either no difference or enlarge
        #       the code by a few hundred bytes.
        #
        #       "-Os" seems to be the best compromise between speed and
        #       code size.  "-O3" and higher seem to make no effective
        #       difference in the speed of the code, but does bloat the
        #       library 10+%.
        #

        AS_IF([test "x$with_optim" != x], [
            OPTIM="$with_optim $OPTIM"
        ], [
            OPTIM="-Os $OPTIM"
        ])
    ])

    # Generate position-independent code when needed...
    AS_IF([test $PICFLAG = 1], [
        OPTIM="$OPTIM -fPIC"
    ])

    # See if GCC supports -fno-exceptions...
    AC_MSG_CHECKING([if GCC supports -fno-exceptions])
    OLDCFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -fno-exceptions"
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([[]], [[]])],
        [OPTIM="$OPTIM -fno-exceptions"
         AC_MSG_RESULT(yes)],
        [AC_MSG_RESULT(no)])
    CFLAGS="$OLDCFLAGS"

    # See if GCC supports -fno-strict-aliasing...
    AC_MSG_CHECKING([if GCC supports -fno-strict-aliasing])
    OLDCFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS -fno-strict-aliasing"
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([[]], [[]])],
        [OPTIM="$OPTIM -fno-strict-aliasing"
         AC_MSG_RESULT(yes)],
        [AC_MSG_RESULT(no)])
    CFLAGS="$OLDCFLAGS"

    dnl Make sure that shared libraries don't have undefined references
    # See if ld supports -no-undefined...
    AC_MSG_CHECKING([if ld supports -no-undefined])
    OLDLDFLAGS="$LDFLAGS"
    LDFLAGS="$LDFLAGS -Wl,-no-undefined"
    AC_LINK_IFELSE(
      [AC_LANG_PROGRAM([[]], [[]])],
      [DSOFLAGS="$DSOFLAGS -Wl,-no-undefined"
      AC_MSG_RESULT(yes)],
      [AC_MSG_RESULT(no)])
    LDFLAGS="$OLDLDFLAGS"

    # See if ld supports -Bsymbolic-functions...
    AC_MSG_CHECKING([if ld supports -Bsymbolic-functions])
    OLDLDFLAGS="$LDFLAGS"
    LDFLAGS="$LDFLAGS -Wl,-Bsymbolic-functions"
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([[]], [[]])],
        [DSOFLAGS="$DSOFLAGS -Wl,-Bsymbolic-functions"
         AC_MSG_RESULT(yes)],
        [AC_MSG_RESULT(no)])
    LDFLAGS="$OLDLDFLAGS"

    # See if toolchain supports a sectioned build...
    AC_MSG_CHECKING([if toolchain supports sections])
    OLDLDFLAGS="$LDFLAGS"
    OLDCFLAGS="$CFLAGS"
    LDFLAGS="$LDFLAGS -Wl,-gc-sections"
    CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
    AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([[]], [[]])],
        [DSOFLAGS="$DSOFLAGS -Wl,-gc-sections"
         OPTIM="$OPTIM -ffunction-sections -fdata-sections"
         AC_MSG_RESULT(yes)],
        [AC_MSG_RESULT(no)])
    LDFLAGS="$OLDLDFLAGS"
    CFLAGS="$OLDCFLAGS"

    # See if we are running Solaris; if so, try the -fpermissive option...
    # This option is required on some versions of Solaris to work around
    # bugs in the X headers up through Solaris 7.
    #
    # Unlike the other compiler/optimization settings, this one is placed
    # in CFLAGS and CXXFLAGS so that fltk-config will provide the option
    # to clients - otherwise client apps will not compile properly...
    AS_CASE([$host_os], [solaris*], [
        AC_MSG_CHECKING([if GCC supports -fpermissive])

        OLDCFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS -fpermissive"
        AC_COMPILE_IFELSE(
            [AC_LANG_PROGRAM([[]], [[]])],
            [CXXFLAGS="$CXXFLAGS -fpermissive"
             AC_MSG_RESULT(yes)],
            [CFLAGS="$OLDCFLAGS"
             AC_MSG_RESULT(no)])
    ])
], [
    AS_CASE(["$host_os"], [irix*], [
        # Running some flavor of IRIX; see which version and
        # set things up according...
        AS_IF([test "$uversion" -ge 62], [
            # We are running IRIX 6.2 or higher; uncomment the following
            # lines if you don't have IDO 7.2 or higher:
            #
            #     CXX="CC -n32 -mips3"
            #     CC="cc -n32 -mips3"
            #     LD="ld -n32 -mips3"
            #     MAKEDEPEND="CC -M"

            AS_IF([test "x`grep abi=n32 /etc/compiler.defaults`" = x], [
                AC_MSG_WARN([FOR BEST RESULTS BEFORE COMPILING: setenv SGI_ABI "-n32 -mips3"])
            ])

            OPTIM="-fullwarn $OPTIM"
        ])

        AS_IF([test -z "$DEBUGFLAG"], [
            AS_IF([test "x$with_optim" != x], [
                OPTIM="$with_optim $OPTIM"
            ], [
                OPTIM="-O2 $OPTIM"
                AS_IF([test $uversion -gt 62], [
                    OPTIM="-OPT:Olimit=4000 $OPTIM"
                ])
            ])
        ])
    ], [hpux*], [
        # Running HP-UX; these options should work for the HP compilers.
        AS_IF([test -z "$DEBUGFLAG"], [
            AS_IF([test "x$with_optim" != x], [
                OPTIM="$with_optim $OPTIM"
            ], [
                OPTIM="+O2 $OPTIM"
            ])
        ])

        AS_IF([test $PICFLAG = 1], [
            OPTIM="+z $OPTIM"
        ])

        CXXFLAGS="$CXXFLAGS +W336,501,736,740,749,829"
    ], [OSF1*], [
        # Running Digital/Tru64 UNIX; these options should work for the
        # Digital/Compaq/NewHP compilers.
        AS_IF([test -z "$DEBUGFLAG"], [
            AS_IF([test "x$with_optim" != x], [
                OPTIM="$with_optim $OPTIM"
            ], [
                OPTIM="-O2 $OPTIM"
            ])
        ])
    ], [solaris*], [
        # Solaris
        AS_IF([test -z "$DEBUGFLAG"], [
            AS_IF([test "x$with_optim" != x], [
                OPTIM="$with_optim $OPTIM"
            ], [
                OPTIM="-xO3 $OPTIM"
            ])
        ])

        AS_IF([test $PICFLAG = 1], [
            OPTIM="-KPIC $OPTIM"
        ])
    ], [aix*], [
        AS_IF([test -z "$DEBUGFLAG"], [
            AS_IF([test "x$with_optim" != x], [
                OPTIM="$with_optim $OPTIM"
            ], [
                OPTIM="-O2 $OPTIM"
            ])
        ])

        AC_MSG_WARN([The AIX C and C++ compilers are known not to correctly compile the FLTK library.])
    ], [*], [
        # Running some other operating system; inform the user they
        # should contribute the necessary options via the STR form..
        AC_MSG_WARN([Building FLTK with default compiler optimizations])
        AC_MSG_WARN([Send the FLTK developers your uname and compiler options via https://www.fltk.org/bugs.php])
    ])
])

OPTIM="$DEBUGFLAG $OPTIM"

dnl Take archflags away from CFLAGS (makefiles use ARCHFLAGS explicitly)
AS_CASE([$host_os], [darwin*], [
    AS_IF([test "x$with_archflags" != x], [
        CFLAGS="$(echo $CFLAGS | sed -e 's/$with_archflags//g')"
    ])
])

dnl Define the FLTK documentation directory...
AS_CASE([$host_os], [mingw*], [
    # Determine the path where MSys has /usr installed
    msyspath="$(mount | grep '/usr ' | cut -d ' ' -f -1 | sed -e's,\\,/, g')"

    # Then substitute that in the Windows path instead of /usr
    AC_DEFINE_UNQUOTED([FLTK_DOCDIR], "$msyspath/local/share/doc/fltk")
], [*], [
    AS_IF([test x$prefix = xNONE], [
        AC_DEFINE_UNQUOTED([FLTK_DOCDIR], "/usr/local/share/doc/fltk")
    ], [
        AC_DEFINE_UNQUOTED([FLTK_DOCDIR], "$prefix/share/doc/fltk")
    ])
])

dnl Define the FLTK data directory...
AS_IF([test x$prefix = xNONE], [
    AC_DEFINE_UNQUOTED([FLTK_DATADIR], "/usr/local/share/fltk")
], [
    AC_DEFINE_UNQUOTED([FLTK_DATADIR], "$prefix/share/fltk")
])


dnl Summarize results of configure tests...
echo ""
echo "Configuration Summary"
echo "-------------------------------------------------------------------------"

AS_CASE([$host_os_gui], [cygwin* | mingw*], [
    AS_IF([test x$gdiplus_found = xyes], [graphics="GDI+"], [graphics="GDI"])
], [darwin*], [
    graphics="Quartz"
], [*], [
    AS_IF([test x$enable_wayland = xno], [
        graphics="X11"
    ])
    AS_IF([test x$xft_found = xyes], [
        graphics="$graphics + Xft"
    ])
    AS_IF([test x$xfixes_found = xyes], [
        graphics="$graphics + Xfixes"
    ])
    AS_IF([test x$xinerama_found = xyes], [
        graphics="$graphics + Xinerama"
    ])
    AS_IF([test x$xcursor_found = xyes], [
        graphics="$graphics + Xcursor"
    ])
    AS_IF([test x$xrender_found = xyes], [
        graphics="$graphics + Xrender"
    ])
    AS_IF([test x$enable_usecairo = xyes], [
        graphics="$graphics + Cairo"
    ])
    AS_IF([test x$pango_found = xyes], [
        graphics="$graphics + Pango"
    ])
])

echo "    Directories: prefix=$prefix"
echo "                 bindir=$bindir"
echo "                 datadir=$datadir"
echo "                 datarootdir=$datarootdir"
echo "                 exec_prefix=$exec_prefix"
echo "                 includedir=$includedir"
echo "                 libdir=$libdir"
echo "                 mandir=$mandir"
AS_CASE([$host_os], [mingw*], [
    echo "                 MSys docpath=$msyspath/local/share/doc/fltk"
])

dnl
echo "Cross-compiling: $fltk_cross_compiling"
AS_IF([test "$fltk_cross_compiling" = "yes"], [
    echo "          Build: $build -> Host: $host"
])
dnl
echo "       Graphics: $graphics"
dnl
AS_IF([test x$JPEG = x], [
    echo "Image Libraries: JPEG=System"
], [
    echo "Image Libraries: JPEG=Builtin"
])
AS_IF([test x$PNG = x], [
    echo "                 PNG=System"
], [
    echo "                 PNG=Builtin"
])
AS_IF([test x$ZLIB = x], [
    echo "                 ZLIB=System"
], [
    echo "                 ZLIB=Builtin"
])
AS_IF([test x$enable_cairo = xyes], [
    echo "                 CAIRO=lib"
])
AS_IF([test x$enable_cairoext = xyes], [
    echo "                 CAIRO=internal_use"
])

AS_IF([test x$enable_largefile != xno], [
    echo "    Large Files: YES"
], [
    echo "    Large Files: NO"
])

AS_IF([test x$GLDEMOS = x], [
    echo "         OpenGL: NO"
], [
    echo "         OpenGL: YES"
])

AS_IF([test x$THREADS = x], [
    echo "        Threads: NO"
], [
    echo "        Threads: YES"
])

dnl Set empty BINARY_DIR variable for fltk-config.in (CMake compatibility)
BINARY_DIR=
AC_SUBST([BINARY_DIR])

dnl Write all of the files...
AC_CONFIG_HEADERS([config.h:configh.in])
AC_CONFIG_HEADERS([FL/fl_config.h:fl_config.in])
AC_CONFIG_FILES([makeinclude fltk.list fltk-config fltk.spec FL/Makefile])
AC_OUTPUT

dnl Make sure the fltk-config script is executable...
chmod +x fltk-config