summaryrefslogtreecommitdiffstats
path: root/configure.in
blob: 4bc1026784f57b43c05ad60ec51cf9fda8b440ce (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
#############################################################################
#
# MODULE:   	Grass Compilation
# AUTHOR(S):	Original author unknown - probably CERL
#   	    	Eric G. Miller - egm2 jps.net
#   	    	Justin Hickey - Thailand - jhickey hpcc.nectec.or.th
#		Markus Neteler - Germany/Italy - neteler itc.it
# PURPOSE:  	This configure runs all the tests to determine what components
#   	    	are installed on the current system. It also defines certain
#   	    	configuration variables for compilation and installation.
# COPYRIGHT:    (C) 2000-2009, 2011-2012 by the GRASS Development Team
#
#               This program is free software under the GNU General
#   	    	Public License (>=v2). Read the file COPYING that
#   	    	comes with GRASS for details.
#
# MANUAL:       http://www.gnu.org/software/autoconf/manual/autoconf.html
#               http://savannah.gnu.org/projects/autoconf/
# Website for   config.guess, config.sub:
#               wget http://git.savannah.gnu.org/cgit/config.git/plain/config.guess
#               wget http://git.savannah.gnu.org/cgit/config.git/plain/config.sub
#               Note: use autoconf-2.13
#############################################################################

define([AC_CACHE_LOAD], )
define([AC_CACHE_SAVE], )
define([AC_CACHE_VAL], [
$2
])

AC_INIT(configure.in)
AC_PREREQ(2.13)
AC_PREFIX_DEFAULT(/usr/local)
AC_CONFIG_HEADER(include/config.h)
AC_CANONICAL_HOST
AC_PROG_CC
LOC_EXEEXT
AC_SUBST(MINGW32)

# Check for full floating-point support, including Infinity and NaN
IEEEFLAG=
LOC_CHECK_FP_INF_NAN([],
[],
[ ac_save_cflags=${CFLAGS}
  CFLAGS=-mieee
  LOC_CHECK_FP_INF_NAN([ with -mieee],
    [IEEEFLAG="-mieee"],
    [AC_MSG_WARN([*** Incomplete floating-point support.])],
    [AC_MSG_ERROR([*** INTERNAL CONFIGURE ERROR])])
  CFLAGS=${ac_save_cflags}],
[ LOC_CHECK_CC_MIEEE ])
CFLAGS="$CFLAGS $IEEEFLAG"

# Set BINDIR

if test -n "${bindir}"; then
BINDIR="${bindir}"
else
BINDIR=/usr/local/bin
fi
AC_SUBST(BINDIR)

# Set SRCDIR and DSTDIR

AC_PATH_PROG(pwd, pwd, pwd)

if test "$MINGW32" = yes ; then
  winpwd="pwd -W"
else
  winpwd="$pwd"
fi

AC_MSG_CHECKING(for source directory)

if test -z "$srcdir" ; then
  SRCDIR=`$pwd`
else
  SRCDIR=`(cd "$srcdir" ; $pwd)`
fi

AC_MSG_RESULT("$SRCDIR")

AC_MSG_CHECKING(for build directory)

DSTDIR=`$pwd`
WINDSTDIR=`$winpwd`

AC_MSG_RESULT("$DSTDIR")

AC_SUBST(SRCDIR)
AC_SUBST(DSTDIR)

# Set ARCH

ARCH=
if test -z "${host}"; then
ARCH="unknown"
else
ARCH="${host}"
fi

AC_SUBST(ARCH)

# Use absolute path for aux directory so that install-sh works

AC_CONFIG_AUX_DIR("$SRCDIR")

# Set GISBASE and GRASS_BIN

GISBASE="${WINDSTDIR}/dist.${ARCH}"
GRASS_BIN="${DSTDIR}/bin.${ARCH}"

AC_SUBST(GISBASE)
AC_SUBST(GRASS_BIN)

# Set GRASS_VERSION_*

GRASS_VERSION_FILE=include/VERSION
GRASS_VERSION_MAJOR=`sed -n 1p "${GRASS_VERSION_FILE}"`
GRASS_VERSION_MINOR=`sed -n 2p "${GRASS_VERSION_FILE}"`
GRASS_VERSION_RELEASE=`sed -n 3p "${GRASS_VERSION_FILE}"`
GRASS_VERSION_DATE=`sed -n 4p "${GRASS_VERSION_FILE}"`
GRASS_VERSION_NUMBER=`echo ${GRASS_VERSION_MAJOR}.${GRASS_VERSION_MINOR}.${GRASS_VERSION_RELEASE}`
NAME_VER=`echo ${GRASS_VERSION_NUMBER} | sed 's/\..*//'`
changequote(,)
LIB_VER=`echo ${GRASS_VERSION_NUMBER} | sed 's/^\([0-9.]*\).*$/\1/'`
changequote([,])

GRASS_VERSION_GIT="exported"
AC_PATH_PROG(GIT, git, no)
if test "$GIT" != "no" ; then
   GRASS_VERSION_GIT=`$GIT rev-parse --short HEAD 2>/dev/null`
   if test -z "$GRASS_VERSION_GIT"; then
      GRASS_VERSION_GIT="exported"
   fi
fi

AC_SUBST(GRASS_VERSION_FILE)
AC_SUBST(GRASS_VERSION_MAJOR)
AC_SUBST(GRASS_VERSION_MINOR)
AC_SUBST(GRASS_VERSION_RELEASE)
AC_SUBST(GRASS_VERSION_NUMBER)
AC_SUBST(GRASS_VERSION_DATE)
AC_SUBST(GRASS_VERSION_GIT)
AC_SUBST(NAME_VER)
AC_SUBST(LIB_VER)

# Check for MacOSX App

AC_ARG_ENABLE(macosx-app,
[  --enable-macosx-app     create a MacOSX application],,
[enable_macosx_app=no])

AC_MSG_CHECKING(for MacOSX App)
case "$enable_macosx_app" in
	yes)	MACOSX_APP=1	;;
	no)	MACOSX_APP=	;;
	*)	AC_MSG_ERROR([*** You must answer yes or no.])	;;
esac
AC_MSG_RESULT("$enable_macosx_app")
AC_SUBST(MACOSX_APP)

# Check for MacOSX archs

AC_MSG_CHECKING(for MacOSX architectures)

MACOSX_ARCHS=

if test -z "$with_macosx_archs" ; then
  AC_MSG_RESULT(no)
else
  for a in $with_macosx_archs
  do
    # check if valid arch?
    case "$a" in
      i386|ppc|x86_64|ppc64)
        MACOSX_ARCHS="$MACOSX_ARCHS -arch $a"
        ;;
    esac
  done
  AC_MSG_RESULT([$MACOSX_ARCHS])
  LDFLAGS="$LDFLAGS $MACOSX_ARCHS"
  CFLAGS="$CFLAGS $MACOSX_ARCHS"
  CXXFLAGS="$CXXFLAGS $MACOSX_ARCHS"
fi

AC_SUBST(MACOSX_ARCHS)

# Done checking MacOSX archs

# Check for MacOSX SDK

AC_MSG_CHECKING(for MacOSX SDK)

MACOSX_SDK=

if test -z "$with_macosx_sdk" ; then
  AC_MSG_RESULT(no)
else
  AC_CHECK_FILE($with_macosx_sdk/SDKSettings.plist, [
    MACOSX_SDK="-isysroot $with_macosx_sdk"],[
    AC_MSG_ERROR([*** specified SDK does not exist or is not a SDK])])
  LDFLAGS="$LDFLAGS $MACOSX_SDK"
  CFLAGS="$CFLAGS $MACOSX_SDK"
  CXXFLAGS="$CXXFLAGS $MACOSX_SDK"
fi

AC_SUBST(MACOSX_SDK)

# Done checking MacOSX SDK

# Set INST_DIR

if test -n "$MACOSX_APP" ; then
    INSTDIR='${prefix}'"/GRASS-${GRASS_VERSION_MAJOR}.${GRASS_VERSION_MINOR}.app/Contents/MacOS"
else
    INSTDIR='${prefix}'"/grass${GRASS_VERSION_MAJOR}${GRASS_VERSION_MINOR}"
fi

AC_SUBST(INSTDIR)

# Get flags for building shared libraries

SC_ENABLE_SHARED

ac_save_ldflags="$LDFLAGS"
SC_CONFIG_CFLAGS
LDFLAGS="${ac_save_ldflags} $LDFLAGS"

# Enable options

AC_ARG_ENABLE(w11,
[  --enable-w11            use W11 library for Windows X11 emulation],,
[enable_w11=no])

# With options

LOC_ARG_WITH(cxx, C++)
#LOC_ARG_WITH(g77, GNU Fortran 77, no)

AC_ARG_WITH(macosx-archs,
[  --with-macosx-archs[=arch list]
                          compile multiple architectures on MacOSX, ie.
                          universal.  Valid architectures are i386, ppc,
                          x86_64 and ppc64. (default: no [native])],, with_macosx_archs="no")
AC_ARG_WITH(macosx-sdk,
[  --with-macosx-sdk[=path/sdk]
                          compile with a system SDK on MacOSX. (default: no)],, with_macosx_sdk="no")
LOC_ARG_WITH(tiff, TIFF)
LOC_ARG_WITH(png, PNG)
LOC_ARG_WITH(postgres, PostgreSQL, no)
LOC_ARG_WITH(mysql, MySQL, no)
LOC_ARG_WITH(sqlite, SQLite)
LOC_ARG_WITH(opengl, OpenGL)
LOC_ARG_WITH(odbc, ODBC, no)
LOC_ARG_WITH(fftw, FFTW)
LOC_ARG_WITH(blas, BLAS, no)
LOC_ARG_WITH(lapack, LAPACK, no)
LOC_ARG_WITH(cairo, Cairo)
LOC_ARG_WITH(freetype, FreeType)
LOC_ARG_WITH(nls, NLS, no)
LOC_ARG_WITH(readline, Readline, no)
LOC_ARG_WITH(opendwg, openDWG, no)
LOC_ARG_WITH(regex, regex)
LOC_ARG_WITH(pthread, POSIX threads, no)
LOC_ARG_WITH(openmp, OpenMP, no)
LOC_ARG_WITH(opencl, OpenCL, no)
LOC_ARG_WITH(bzlib, BZIP2, no)
LOC_ARG_WITH(zstd, Zstandard)

AC_ARG_WITH(gdal,
[  --with-gdal[=path/gdal-config]
                          enable GDAL/OGR support (gdal-config with path,
                          e.g. '--with-gdal=/usr/local/bin/gdal-config')])

AC_ARG_WITH(liblas,
[  --with-liblas[=path/liblas-config]
                          enable libLAS support (liblas-config with path,
                          e.g. '--with-liblas=/usr/local/bin/liblas-config',
                          default: no)],, with_liblas="no")

AC_ARG_WITH(pdal,
[  --with-pdal[=path/pdal-config]
                          enable PDAL support (pdal-config with path,
                          e.g. '--with-pdal=/usr/local/bin/pdal-config',
                          default: no)],, with_pdal="no")

AC_ARG_WITH(wxwidgets,
[  --with-wxwidgets[=path/wx-config]
                          enable wxWidgets support (wx-config with path,
                          e.g. '--with-wxwidgets=/usr/local/bin/wx-config',
                          default: no)],, with_wxwidgets="no")

AC_ARG_WITH(netcdf,
[  --with-netcdf[=path/nc-config]
                          enable NetCDF support (nc-config with path,
                          e.g. '--with-nc=/usr/local/bin/nc-config',
                          default: no)],, with_netcdf="no")

# With includes and libs options

AC_ARG_WITH(geos,
[  --with-geos[=path/geos-config]
                          enable GEOS support (geos-config with path,
                          e.g. '--with-geos=/usr/local/bin/geos-config',
                          default: no)],, with_geos="no")

AC_ARG_WITH(includes,
[  --with-includes=DIRS    site include files are in DIRS])

AC_ARG_WITH(libs,
[  --with-libs=DIRS        site library files are in DIRS])

LOC_ARG_WITH_INC(zlib, zlib)
LOC_ARG_WITH_LIB(zlib, zlib)

LOC_ARG_WITH_INC(bzlib, BZIP2)
LOC_ARG_WITH_LIB(bzlib, BZIP2)

LOC_ARG_WITH_INC(zstd, ZSTD)
LOC_ARG_WITH_LIB(zstd, ZSTD)

LOC_ARG_WITH_INC(readline, Readline)
LOC_ARG_WITH_LIB(readline, Readline)

LOC_ARG_WITH_INC(tiff, TIFF)
LOC_ARG_WITH_LIB(tiff, TIFF)

LOC_ARG_WITH_INC(png, PNG)
LOC_ARG_WITH_LIB(png, PNG)

LOC_ARG_WITH_INC(postgres, PostgreSQL)
LOC_ARG_WITH_LIB(postgres, PostgreSQL)

LOC_ARG_WITH_INC(mysql, MySQL)
LOC_ARG_WITH_LIB(mysql, MySQL)

LOC_ARG_WITH_INC(sqlite, SQLite)
LOC_ARG_WITH_LIB(sqlite, SQLite)

LOC_ARG_WITH_INC(opengl, OpenGL)
LOC_ARG_WITH_LIB(opengl, OpenGL)
LOC_ARG_WITH_FRAMEWORK(opengl, OpenGL)

LOC_ARG_WITH_INC(odbc, ODBC)
LOC_ARG_WITH_LIB(odbc, ODBC)

LOC_ARG_WITH_INC(fftw, FFTW)
LOC_ARG_WITH_LIB(fftw, FFTW)

LOC_ARG_WITH_INC(blas, BLAS)
LOC_ARG_WITH_LIB(blas, BLAS)

LOC_ARG_WITH_INC(lapack, LAPACK)
LOC_ARG_WITH_LIB(lapack, LAPACK)

LOC_ARG_WITH_INC(cairo, cairo)
LOC_ARG_WITH_LIB(cairo, cairo)
LOC_ARG_WITH_LDFLAGS(cairo, cairo)

LOC_ARG_WITH_INC(freetype, FreeType)
LOC_ARG_WITH_LIB(freetype, FreeType)

LOC_ARG_WITH_INC(proj, External PROJ.4)
LOC_ARG_WITH_LIB(proj, External PROJ.4)
LOC_ARG_WITH_SHARE(proj, External PROJ.4)

LOC_ARG_WITH_INC(opendwg, openDWG)
LOC_ARG_WITH_LIB(opendwg, openDWG)

LOC_ARG_WITH_INC(regex, regex)
LOC_ARG_WITH_LIB(regex, regex)

LOC_ARG_WITH_INC(pthread, POSIX threads)
LOC_ARG_WITH_LIB(pthread, POSIX threads)

LOC_ARG_WITH_INC(openmp, OpenMP)
LOC_ARG_WITH_LIB(openmp, OpenMP)

LOC_ARG_WITH_INC(opencl, OpenCL)
LOC_ARG_WITH_LIB(opencl, OpenCL)
#LOC_ARG_WITH_FRAMEWORK(opencl, OpenCL)

# Put this early on so CPPFLAGS and LDFLAGS have any additional dirs

# With includes option

# Handle Fortran compiler choice
#LOC_CHECK_USE(g77, GNU Fortran 77, USE_G77)
# Done checking fortran

AC_MSG_CHECKING(for additional include dirs)
case "$with_includes" in
y | ye | yes | n | no)
	AC_MSG_ERROR([*** You must supply a directory to list --with-includes.])
	;;
esac
AC_MSG_RESULT($with_includes)

if test -n "$with_includes"; then
    for dir in $with_includes; do
        if test -d "$dir"; then
            INCLUDE_DIRS="$INCLUDE_DIRS -I$dir"
        else
            AC_MSG_ERROR([*** Include directory $dir does not exist.])
        fi
    done
    CPPFLAGS="$CPPFLAGS $INCLUDE_DIRS"
fi
AC_SUBST(INCLUDE_DIRS)

# With libs option

AC_MSG_CHECKING(for additional library dirs)
case "$with_libs" in
y | ye | yes | n | no)
	AC_MSG_ERROR([*** You must supply a directory list to --with-libs.])
	;;
esac
AC_MSG_RESULT($with_libs)

if test -n "$with_libs"; then
    for dir in $with_libs; do
        if test -d "$dir"; then
            LIBRARY_DIRS="$LIBRARY_DIRS -L$dir"
        else
            AC_MSG_ERROR([*** Library directory $dir does not exist.])
        fi
    done
    LDFLAGS="$LDFLAGS $LIBRARY_DIRS"
fi
AC_SUBST(LIBRARY_DIRS)

# Programs and standard headers, libraries, functions

AC_PROG_INSTALL

AC_PROG_LEX
if test "$LEX" = "lex"; then
    AC_PATH_PROG(LEXPATH, lex, no)
    if test "$LEXPATH" = "no"; then
	AC_MSG_ERROR([*** Unable to locate lex.])
    fi
fi

AC_PROG_YACC
if test "$YACC" = "yacc"; then
    AC_PATH_PROG(YACCPATH, yacc, no)
    if test "$YACCPATH" = "no"; then
	AC_MSG_ERROR([*** Unable to locate yacc.])
    fi
fi

AC_PROG_RANLIB
AC_CHECK_PROGS(AR, ar)
AC_CHECK_PROGS(ENV, env)
AC_PATH_PROG(PERL, perl, no)  
AC_HEADER_STDC
#AC_CHECK_HEADERS(curses.h limits.h termio.h termios.h unistd.h values.h)
AC_CHECK_HEADERS(limits.h termio.h termios.h unistd.h values.h f2c.h g2c.h)
AC_CHECK_HEADERS(sys/ioctl.h sys/mtio.h sys/resource.h sys/time.h)
AC_CHECK_HEADERS(sys/timeb.h sys/types.h sys/utsname.h)
AC_CHECK_HEADERS(libintl.h iconv.h)
AC_CHECK_HEADERS(langinfo.h)
AC_HEADER_TIME
AC_TYPE_OFF_T
AC_TYPE_UID_T
AC_TYPE_SIGNAL
AC_CYGWIN
AC_CHECK_FUNCS(ftime gethostname gettimeofday lseek nice time uname)
AC_CHECK_FUNCS(seteuid setpriority setreuid setruid)
AC_CHECK_FUNCS(drand48)
AC_CHECK_FUNCS(putenv setenv)
AC_CHECK_FUNCS(nanosleep)
if test "$cross_compiling" != "yes" ; then
AC_FUNC_SETPGRP
else
CROSS_COMPILING=1
AC_SUBST(CROSS_COMPILING)
fi

AC_MSG_CHECKING(for long long int)
AC_TRY_COMPILE(,[long long int x;],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_LONG_LONG_INT)
],[
AC_MSG_RESULT(no)
])

AC_MSG_CHECKING(for int64_t)
AC_TRY_COMPILE([#include <sys/types.h>],[int64_t x;],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_INT64_T)
],[
AC_MSG_RESULT(no)
])

AC_MSG_CHECKING(for W11)
case "$enable_w11" in
	yes|no)	AC_MSG_RESULT("$enable_w11")	;;
	*)	AC_MSG_ERROR([*** You must answer yes or no.])	;;
esac

USE_X11=
USE_W11=
XLIB=
XTLIB=

if test "$enable_w11" = "yes" ; then
    X_CFLAGS=-I${SRCDIR}/display/drivers/windows/libW11
    X_LIBS='-L$(LIBDIR)'
    AC_SUBST(X_CFLAGS)
    AC_SUBST(X_LIBS)

    USE_W11="1"
    USE_X11="1"
    XLIB=-lX11

    CFLAGS="$CFLAGS -D__W98__"
else
    AC_PATH_XTRA
    if test "$no_x" != "yes"; then
        USE_X11="1"
        XLIB=-lX11
        XTLIB=-lXt
    fi
fi

AC_SUBST(XLIB)
AC_SUBST(XTLIB)
AC_SUBST(USE_X11)

# Note that some systems (FreeBSD for example) need an extra library for
# cuserid
ac_save_libs="$LIBS"
LIBS=""
AC_SEARCH_LIBS(cuserid,[compat])
DBMIEXTRALIB="$LIBS"
LIBS="$ac_save_libs"
AC_SUBST(DBMIEXTRALIB)

AC_CHECK_FUNCS(asprintf)
AC_SUBST(HAVE_ASPRINTF)

# Test if mathlib needs -lm flag or is included with libc
AC_CHECK_FUNC(atan, MATHLIB=, [
AC_CHECK_LIB(m, atan, MATHLIB=-lm, [
    AC_MSG_ERROR([*** Failed check for math library.])
])])
AC_SUBST(MATHLIB)

AC_CHECK_FUNC(dlsym, DLLIB=, [
AC_CHECK_LIB(dl, dlsym, DLLIB=-ldl, [
    DLLIB=
])])
AC_SUBST(DLLIB)

AC_CHECK_FUNC(iconv, ICONVLIB=, [
AC_CHECK_LIB(iconv, iconv, ICONVLIB=-liconv, [
AC_CHECK_LIB(giconv, iconv, ICONVLIB=-lgiconv, [
AC_CHECK_FUNC(libiconv, ICONVLIB=, [
AC_CHECK_LIB(iconv, libiconv, ICONVLIB=-liconv, [
AC_CHECK_LIB(giconv, libiconv, ICONVLIB=-lgiconv, [
    AC_MSG_WARN([*** Unable to locate iconv() function.])
    ICONVLIB=
])])])])])])
AC_SUBST(ICONVLIB)

have_socket=1
AC_CHECK_FUNC(socket, SOCKLIB=, [
AC_CHECK_LIB(socket, socket, SOCKLIB=-lsocket, [
    have_socket=0
    AC_MSG_WARN([*** Unable to locate socket() function.])
])])
AC_SUBST(SOCKLIB)
if test "$have_socket" = 1 ; then
  HAVE_SOCKET=1
  AC_DEFINE(HAVE_SOCKET)
else
  HAVE_SOCKET=
fi
AC_SUBST(HAVE_SOCKET)


# Mandatory zlib dependency

ZLIBLIBPATH=
ZLIBINCPATH=
ZLIB=

# With zlib includes directory

LOC_CHECK_INC_PATH(zlib,zlib,ZLIBINCPATH)

LOC_CHECK_INCLUDES(zlib.h,zlib,$ZLIBINCPATH)

# With zlib library directory

LOC_CHECK_LIB_PATH(zlib,zlib,ZLIBLIBPATH)

LOC_CHECK_LIBS(z,deflate,zlib,$ZLIBLIBPATH,ZLIB,,,)

#

AC_SUBST(ZLIBINCPATH)
AC_SUBST(ZLIBLIBPATH)
AC_SUBST(ZLIB)

# Done checking zlib

# bzip2 support

BZIP2LIBPATH=
BZIP2INCPATH=
BZIP2LIB=

LOC_CHECK_USE(bzlib,bzlib,USE_BZIP2)

if test -n "$USE_BZIP2"; then

# With bzip2 includes directory

LOC_CHECK_INC_PATH(bzlib,bzlib,BZIP2INCPATH)

LOC_CHECK_INCLUDES(bzlib.h,bzlib,$BZIP2INCPATH)

# With bzip2 library directory

LOC_CHECK_LIB_PATH(bzlib,bzlib,BZIP2LIBPATH)

LOC_CHECK_LIBS(bz2,BZ2_bzBuffToBuffCompress,bzlib,$BZIP2LIBPATH,BZIP2LIB,,,)

#

fi # $USE_BZIP2

AC_SUBST(BZIP2INCPATH)
AC_SUBST(BZIP2LIBPATH)
AC_SUBST(BZIP2LIB)

# Done checking bzip2

# zstd support

ZSTDLIBPATH=
ZSTDINCPATH=
ZSTDLIB=

LOC_CHECK_USE(zstd,zstd,USE_ZSTD)

if test -n "$USE_ZSTD"; then

# With zstd includes directory

LOC_CHECK_INC_PATH(zstd,zstd,ZSTDINCPATH)
LOC_CHECK_INCLUDES(zstd.h,zstd,$ZSTDINCPATH)

# With zstd library directory

LOC_CHECK_LIB_PATH(zstd,zstd,ZSTDLIBPATH)

LOC_CHECK_LIBS(zstd,ZSTD_compress,zstd,$ZSTDLIBPATH,ZSTDLIB,,,)

#

fi # $USE_ZSTD

AC_SUBST(ZSTDINCPATH)
AC_SUBST(ZSTDLIBPATH)
AC_SUBST(ZSTDLIB)

# Done checking zstd

# Mandatory PROJ dependency

PROJINC=
PROJLIB=
PROJSHARE=
PROJ4API=0

# With PROJ includes directory

LOC_CHECK_INC_PATH(proj,External PROJ,PROJINC)

# PROJ version check: if proj.h exists, it must be proj 5+
LOC_CHECK_INCLUDES(proj.h,External PROJ,$PROJINC,PROJ4API=1)

if test $PROJ4API = 0 ; then
    LOC_CHECK_VERSION_INT(proj.h,PROJ_VERSION_MAJOR,External PROJ major,proj_ver_major,$PROJINC,0)
    LOC_CHECK_VERSION_INT(proj.h,PROJ_VERSION_MINOR,External PROJ minor,proj_ver_minor,$PROJINC,0)
    LOC_CHECK_VERSION_INT(proj.h,PROJ_VERSION_PATCH,External PROJ patch,proj_ver_patch,$PROJINC,0)
    AC_MSG_RESULT([found PROJ version "${proj_ver_major}.${proj_ver_minor}.${proj_ver_patch}"])
    # minimum required PROJ 5+ version to use the new PROJ API: 5.1.0
    if test ${proj_ver_major} = 5 && test `expr ${proj_ver_minor} \< 1` = 1 ; then
	AC_MSG_WARN([At least PROJ version "5.1.0" is required for the new API ])
	PROJ4API=1
    fi
fi

if test $PROJ4API = 0 ; then
    AC_MSG_RESULT([using new PROJ version 5+ API])

    # With PROJ library directory

    LOC_CHECK_LIB_PATH(proj,External PROJ,PROJLIB)
    LOC_CHECK_LIBS(proj,proj_pj_info,External PROJ,$PROJLIB,PROJLIB,,,)
else
    AC_MSG_RESULT([using old PROJ version 4 API])
    AC_DEFINE(USE_PROJ4API)

    LOC_CHECK_INCLUDES(proj_api.h,External PROJ,$PROJINC)
    # PROJ version check for v4.x

    if test "$cross_compiling" = yes; then
	AC_MSG_WARN([*** Cannot check PROJ.4 version (cross-compiling).])
    else
	LOC_CHECK_VERSION_INT(proj_api.h,PJ_VERSION,External PROJ.4,proj_ver,$PROJINC,0)

	if test `expr ${proj_ver} \< 446` = 1 ; then
	    AC_MSG_ERROR([*** PROJ.4.4.6 or later is required.])
	fi
    fi

    # With PROJ library directory

    LOC_CHECK_LIB_PATH(proj,External PROJ.4,PROJLIB)
    LOC_CHECK_LIBS(proj,pj_get_def,External PROJ.4,$PROJLIB,PROJLIB,,,)
fi

# With PROJ share directory

LOC_CHECK_SHARE_PATH(proj,External PROJ,PROJSHARE)
if test -z "$PROJSHARE" ; then
    AC_MSG_WARN([*** External PROJ directory not specified; default will be used])
    PROJSHARE=/usr/share/proj
fi

# LOC_CHECK_SHARE does not work when cross compiling
if test "$cross_compiling" = "yes" ; then
    AC_MSG_CHECKING([for epsg])
    AC_MSG_RESULT([unknown (cross-compiling)])
else
    LOC_CHECK_SHARE(epsg,External PROJ,$PROJSHARE,[
    AC_MSG_WARN([*** Unable to locate PROJ data files.])
    ])
fi

AC_SUBST(PROJINC)
AC_SUBST(PROJLIB)
AC_SUBST(PROJSHARE)

# Done checking PROJ

# Enable regex option

LOC_CHECK_USE(regex,regex,USE_REGEX)

REGEXINCPATH=
REGEXLIBPATH=
REGEXLIB=

if test -n "$USE_REGEX"; then

# With regex includes directory

LOC_CHECK_INC_PATH(regex,regex,REGEXINCPATH)

LOC_CHECK_INCLUDES(regex.h,regex,$REGEXINCPATH)

# With regex library directory

LOC_CHECK_LIB_PATH(regex,regex,REGEXLIBPATH)

LOC_CHECK_FUNC(regcomp,regex functions,REGEXLIB,,,,,[
LOC_CHECK_LIBS(regex,regcomp,regex,$REGEXLIBPATH,REGEXLIB,,,)
])

fi # $USE_REGEX

AC_SUBST(REGEXINCPATH)
AC_SUBST(REGEXLIBPATH)
AC_SUBST(REGEXLIB)
AC_SUBST(USE_REGEX)

# Done checking regex

# Enable Readline option

LOC_CHECK_USE(readline,Readline,USE_READLINE)

READLINEINCPATH=
READLINELIBPATH=
READLINELIB=
HISTORYLIB=

if test -n "$USE_READLINE"; then

# With Readline includes directory

LOC_CHECK_INC_PATH(readline,Readline,READLINEINCPATH)

LOC_CHECK_INCLUDES(readline/readline.h,Readline,$READLINEINCPATH)
LOC_CHECK_INCLUDES(readline/history.h,Readline,$READLINEINCPATH)

# With Readline library directory

LOC_CHECK_LIB_PATH(readline,Readline,READLINELIBPATH)

LOC_CHECK_LIBS(readline,readline,Readline,$READLINELIBPATH,READLINELIB,,,)
LOC_CHECK_LIBS(history,add_history,History,$READLINELIBPATH,HISTORYLIB,,,)

fi # $USE_READLINE

AC_SUBST(READLINEINCPATH)
AC_SUBST(READLINELIBPATH)
AC_SUBST(READLINELIB)
AC_SUBST(HISTORYLIB)

# Done checking Readline

# GDAL option

AC_MSG_CHECKING(whether to use GDAL)

GDAL_LIBS=
GDAL_CFLAGS=
USE_GDAL=
USE_OGR=

if test "`basename xx/$with_gdal`" = "gdal-config" ; then
  GDAL_CONFIG="$with_gdal"
fi

if test "$with_gdal" = "no" ; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_PATH_PROG(GDAL_CONFIG, gdal-config, no)

  if test "$GDAL_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** couldn't find gdal-config])
  fi

  if test "$GDAL_CONFIG" != "" ; then
    GDAL_LIBS=`"$GDAL_CONFIG" --libs`
    GDAL_DEP_LIBS=`"$GDAL_CONFIG" --dep-libs`
    GDAL_CFLAGS=`"$GDAL_CONFIG" --cflags`
    USE_GDAL=1
    if test `"$GDAL_CONFIG" --ogr-enabled` = "yes" ; then
      AC_DEFINE(HAVE_OGR)
      USE_OGR=1
    fi
  fi

  GDAL=
  ac_save_libs="$LIBS"
  ac_save_cflags="$CFLAGS"
  LIBS="$LIBS $GDAL_LIBS"
  CFLAGS="$CFLAGS $GDAL_CFLAGS"
  AC_TRY_LINK([#include <gdal.h>],[GDALOpen("foo", GA_ReadOnly);],,[
  LIBS="$LIBS $GDAL_DEP_LIBS"
  AC_TRY_LINK([#include <gdal.h>],[GDALOpen("foo", GA_ReadOnly);],GDAL_LIBS="$GDAL_LIBS $GDAL_DEP_LIBS",[
  AC_MSG_ERROR([*** Unable to locate GDAL library.])
  ])
  ])
  LIBS=${ac_save_libs}
  CFLAGS=${ac_save_cflags}

  AC_DEFINE(HAVE_GDAL)
fi

AC_SUBST(GDAL_LIBS)
AC_SUBST(GDAL_CFLAGS)
AC_SUBST(USE_GDAL)
AC_SUBST(USE_OGR)

# libLAS option

AC_MSG_CHECKING(whether to use libLAS)

LIBLAS_LIBS=
LIBLAS_CFLAGS=
USE_LIBLAS=

if test "`basename xx/$with_liblas`" = "liblas-config" ; then
  LIBLAS_CONFIG="$with_liblas"
fi

if test "$with_liblas" = "no" ; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_PATH_PROG(LIBLAS_CONFIG, liblas-config, no)

  if test "$LIBLAS_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** couldn't find liblas-config])
  fi

  if test "$LIBLAS_CONFIG" != "" ; then
    LIBLAS_LIBS=`"$LIBLAS_CONFIG" --libs`
    LIBLAS_CFLAGS=`"$LIBLAS_CONFIG" --cflags`
    LIBLAS_INC=`"$LIBLAS_CONFIG" --includes`
    USE_LIBLAS=1
  fi

  LIBLAS=
  ac_save_libs="$LIBS"
  ac_save_cflags="$CFLAGS"
  ac_save_cppflags="$CPPFLAGS"
  LIBS="$LIBS $LIBLAS_LIBS"
  CFLAGS="$CFLAGS $LIBLAS_CFLAGS"
  CPPFLAGS="$CPPFLAGS $LIBLAS_INC"
  AC_CHECK_HEADERS(liblas/capi/liblas.h)
  AC_TRY_LINK([#include <liblas/capi/liblas.h>],[LASReader_Create("foo");],,[
  AC_TRY_LINK([#include <liblas/capi/liblas.h>],[LASReader_Create("foo");],LAS_LIBS="$LAS_LIBS",[
  AC_MSG_ERROR([*** Unable to locate libLAS library.])
  ])
  ])
  LIBS=${ac_save_libs}
  CFLAGS=${ac_save_cflags}
  CPPFLAGS=${ac_save_cppflags}

  AC_DEFINE(HAVE_LIBLAS)
fi

AC_SUBST(LIBLAS_LIBS)
AC_SUBST(LIBLAS_CFLAGS)
AC_SUBST(LIBLAS_INC)
AC_SUBST(USE_LIBLAS)

# PDAL option

AC_MSG_CHECKING(whether to use PDAL)

# new and currently used way to switch language to C++
# AC_LANG_PUSH(C++)
AC_LANG_SAVE
AC_LANG_CPLUSPLUS

PDAL_LIBS=
PDAL_CPPFLAGS=
USE_PDAL=

if test "`basename xx/$with_pdal`" = "pdal-config" ; then
  PDAL_CONFIG="$with_pdal"
fi

if test "$with_pdal" = "no" ; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_PATH_PROG(PDAL_CONFIG, pdal-config, no)

  if test "$PDAL_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** could not find pdal-config])
  fi

  if test "$PDAL_CONFIG" != "" ; then
    PDAL_LIBS=`"$PDAL_CONFIG" --libs`
    PDAL_CPPFLAGS=`"$PDAL_CONFIG" --cxxflags`
    PDAL_INC=`"$PDAL_CONFIG" --includes`
    USE_PDAL=1
  fi

  PDAL=
  ac_save_libs="$LIBS"
  ac_save_cflags="$CFLAGS"
  ac_save_cppflags="$CPPFLAGS"
  LIBS="$LIBS $PDAL_LIBS"
  CFLAGS="$CFLAGS $PDAL_CFLAGS"
  CPPFLAGS="$CPPFLAGS $PDAL_CPPFLAGS $PDAL_INC"
  AC_TRY_LINK([#include <pdal/PointTable.hpp>],[pdal::PointTable table;],,[
  AC_TRY_LINK([#include <pdal/PointTable.hpp>],[pdal::PointTable table;],PDAL_LIBS="$PDAL_LIBS",[
  AC_MSG_ERROR([*** Unable to locate PDAL library.])
  ])
  ])
  LIBS=${ac_save_libs}
  CFLAGS=${ac_save_cflags}
  CPPFLAGS=${ac_save_cppflags}

  AC_DEFINE(HAVE_PDAL)
fi

AC_SUBST(PDAL_LIBS)
AC_SUBST(PDAL_CPPFLAGS)
AC_SUBST(PDAL_INC)
AC_SUBST(USE_PDAL)

# new and currently used way to switch language back to C
# AC_LANG_POP(C++)
AC_LANG_C
AC_LANG_RESTORE

# NetCDF option

AC_MSG_CHECKING(whether to use NetCDF)

NETCDF_LIBS=
NETCDF_CFLAGS=
USE_NETCDF=

if test "`basename xx/$with_netcdf`" = "nc-config" ; then
  NETCDF_CONFIG="$with_netcdf"
fi

if test "$with_netcdf" = "no" ; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_PATH_PROG(NETCDF_CONFIG, nc-config, no)

  if test "$NETCDF_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** couldn't find nc-config])
  fi

  if test "$NETCDF_CONFIG" != "" ; then
    NETCDF_LIBS=`"$NETCDF_CONFIG" --libs`
    NETCDF_CFLAGS=`"$NETCDF_CONFIG" --cflags`
    USE_NETCDF=1
  fi

  NETCDF=
  ac_save_libs="$LIBS"
  ac_save_cflags="$CFLAGS"
  LIBS="$LIBS $NETCDF_LIBS"
  CFLAGS="$CFLAGS $NETCDF_CFLAGS"
  AC_TRY_LINK([#include <netcdf.h>],[nc_create("foo", NC_CLOBBER, NULL);],,[
  AC_TRY_LINK([#include <netcdf.h>],[nc_create("foo", NC_CLOBBER, NULL);],NETCDF_LIBS="$NETCDF_LIBS",[
  AC_MSG_ERROR([*** Unable to locate NetCDF library.])
  ])
  ])
  LIBS=${ac_save_libs}
  CFLAGS=${ac_save_cflags}

  AC_DEFINE(HAVE_NETCDF)
fi

AC_SUBST(NETCDF_LIBS)
AC_SUBST(NETCDF_CFLAGS)
AC_SUBST(USE_NETCDF)

# GEOS option

AC_MSG_CHECKING(whether to use GEOS)

GEOS_LIBS=
GEOS_CFLAGS=
USE_GEOS=

# FIXME: "quote" $with_geos ?
if test "`basename xx/$with_geos`" = "geos-config" ; then
  GEOS_CONFIG="$with_geos"
fi

if test "$with_geos" = "no" ; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
  AC_PATH_PROG(GEOS_CONFIG, geos-config, no)

  if test "$GEOS_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** couldn't find geos-config])
  fi
  
  if test "$GEOS_CONFIG" != "" ; then
    GEOS_LIBS=`"$GEOS_CONFIG" --clibs`
    GEOS_CFLAGS=`"$GEOS_CONFIG" --cflags`
    USE_GEOS=1
  fi
  
  LOC_CHECK_INCLUDES(geos_c.h,GEOS,$GEOS_CFLAGS)
### geos 3.3.6 installs geos_c.lib, see http://osgeo-org.1560.n6.nabble.com/osgeo4w-329-update-geos-to-3-3-6-td5024605.html
#  if test "$MINGW32" = yes ; then
#    LOC_CHECK_LIBS(geos_c_i,initGEOS,GEOS,$GEOS_LIBS,GEOS_LIBS)
#  else
  LOC_CHECK_LIBS(geos_c,initGEOS,GEOS,$GEOS_LIBS,GEOS_LIBS)
#  fi
  AC_DEFINE(HAVE_GEOS)
fi

AC_SUBST(GEOS_LIBS)
AC_SUBST(GEOS_CFLAGS)
AC_SUBST(USE_GEOS)

# Enable TIFF option

LOC_CHECK_USE(tiff,TIFF,USE_TIFF)

TIFF_INCLUDE_DIRS=
TIFF_LIBRARY_DIRS=
TIFFLIB=

if test -n "$USE_TIFF"; then

# With TIFF includes directory

LOC_CHECK_INC_PATH(tiff,TIFF,TIFF_INCLUDE_DIRS)

LOC_CHECK_INCLUDES(tiffio.h,TIFF,$TIFF_INCLUDE_DIRS)

# With TIFF library directory

LOC_CHECK_LIB_PATH(tiff,TIFF,TIFF_LIBRARY_DIRS)

LOC_CHECK_LIBS(tiff,TIFFOpen,TIFF,$TIFF_LIBRARY_DIRS,TIFFLIB,,,,-ljpeg,$ZLIB,$MATHLIB)

fi # $USE_TIFF

AC_SUBST(TIFF_INCLUDE_DIRS)
AC_SUBST(TIFF_LIBRARY_DIRS)
AC_SUBST(TIFFLIB)

# Done checking TIFF

# Enable PNG option

LOC_CHECK_USE(png,PNG,USE_PNG)

PNGINC=
PNGLIB=

if test -n "$USE_PNG"; then

# With PNG includes directory

LOC_CHECK_INC_PATH(png,PNG,PNGINC)

LOC_CHECK_INCLUDES(png.h,PNG,$PNGINC)

# With PNG library directory

LOC_CHECK_LIB_PATH(png,PNG,PNGLIB)

LOC_CHECK_LIBS(png,png_read_image,PNG,$PNGLIB,PNGLIB,,$ZLIB $MATHLIB,)

fi # $USE_PNG

AC_SUBST(PNGINC)
AC_SUBST(PNGLIB)
AC_SUBST(USE_PNG)

# Done checking PNG

# Enable PostgreSQL option

LOC_CHECK_USE(postgres,PostgreSQL,USE_POSTGRES)

if test -n "$USE_POSTGRES"; then
AC_DEFINE(HAVE_POSTGRES)
fi # $USE_POSTGRES

PQINCPATH=
PQLIBPATH=
PQLIB=

if test -n "$USE_POSTGRES"; then

# With PostgreSQL includes directory

LOC_CHECK_INC_PATH(postgres,PostgreSQL,PQINCPATH)

LOC_CHECK_INCLUDES(libpq-fe.h,PostgreSQL,$PQINCPATH)

fi # $USE_POSTGRES

if test -n "$USE_POSTGRES"; then

# With PostgreSQL library directory

LOC_CHECK_LIB_PATH(postgres,PostgreSQL,PQLIBPATH)

LOC_CHECK_LIBS(pq,PQsetdbLogin,PostgreSQL,$PQLIBPATH,PQLIB,,,,-lcrypt,-lssl -lcrypto)

ac_save_ldflags="$LDFLAGS"
LDFLAGS="$LDFLAGS $PQLIBPATH"
AC_CHECK_LIB(pq,PQcmdTuples, [AC_DEFINE(HAVE_PQCMDTUPLES)], [
AC_CHECK_LIB(pq,PQcmdTuples, [AC_DEFINE(HAVE_PQCMDTUPLES)], [
], -lcrypt)
])
LDFLAGS="${ac_save_ldflags}"

fi # $USE_POSTGRES

AC_SUBST(USE_POSTGRES)

AC_SUBST(PQINCPATH)
AC_SUBST(PQLIBPATH)
AC_SUBST(PQLIB)

# Done checking PostgreSQL

# Enable MySQL option

LOC_CHECK_USE(mysql,MySQL,USE_MYSQL)

MYSQLINCPATH=
MYSQLLIBPATH=
MYSQLLIB=

if test -n "$USE_MYSQL"; then

# With MySQL includes directory

LOC_CHECK_INC_PATH(mysql,MySQL,MYSQLINCPATH)

LOC_CHECK_INCLUDES(mysql.h,MySQL,$MYSQLINCPATH)

fi # $USE_MYSQL

if test -n "$USE_MYSQL"; then
  # With MySQL library directory

  LOC_CHECK_LIB_PATH(mysql,MySQL,MYSQLLIBPATH)

  LOC_CHECK_LIBS(mysqlclient,mysql_query,MySQL,$MYSQLLIBPATH,MYSQLLIB,,,,$ZLIB,$SOCKLIB,$MATHLIB)

  # Check for libmysqld (for embedded version of the driver)
  AC_PATH_PROG(MYSQLD_CONFIG, mysql_config, no)

  if test "$MYSQLD_CONFIG" = "no" ; then
    AC_MSG_ERROR([*** couldn't find mysql_config])
  fi

  if test "$MYSQLD_CONFIG" != "" ; then
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    ac_save_libs="$LIBS"
    MYSQLDLIB=`"$MYSQLD_CONFIG" --libmysqld-libs`

    LIBS="$MYSQLDLIB $LIBS"
    AC_CHECK_FUNC(mysql_server_init,,[MYSQLDLIB="";
                  AC_MSG_WARN([libmysqld not found])] )
    LIBS=$ac_save_libs
    AC_LANG_C
    AC_LANG_RESTORE
  fi

fi # $USE_MYSQL

AC_SUBST(USE_MYSQL)

AC_SUBST(MYSQLINCPATH)
AC_SUBST(MYSQLLIBPATH)
AC_SUBST(MYSQLLIB)
AC_SUBST(MYSQLDLIB)

# Done checking MySQL

# Enable SQLite option

LOC_CHECK_USE(sqlite,SQLite,USE_SQLITE)

SQLITEINCPATH=
SQLITELIBPATH=
SQLITELIB=

if test -n "$USE_SQLITE"; then

# With SQLite includes directory

LOC_CHECK_INC_PATH(sqlite,SQLite,SQLITEINCPATH)

LOC_CHECK_INCLUDES(sqlite3.h,SQLite,$SQLITEINCPATH)

AC_DEFINE(HAVE_SQLITE)

fi # $USE_SQLITE

if test -n "$USE_SQLITE"; then

# With SQLite library directory

LOC_CHECK_LIB_PATH(sqlite,SQLite,SQLITELIBPATH)

LOC_CHECK_LIBS(sqlite3,sqlite3_open,SQLite,$SQLITELIBPATH,SQLITELIB,,,,$MATHLIB,$DLLIB)

fi # $USE_SQLITE

AC_SUBST(USE_SQLITE)

AC_SUBST(SQLITEINCPATH)
AC_SUBST(SQLITELIBPATH)
AC_SUBST(SQLITELIB)

# Done checking SQLite

# Enable OpenGL option

OPENGLINC=
OPENGLLIB=
OPENGLULIB=
USE_OPENGL=
OPENGL_X11=
OPENGL_AQUA=
OPENGL_WINDOWS=

AC_MSG_CHECKING(whether to use OpenGL)
AC_MSG_RESULT("$with_opengl")
case "$with_opengl" in
	n|no)
		OPENGL_TYPE=none
		;;
	y|yes|x|x11|glx)
		OPENGL_TYPE=X11
		USE_OPENGL=1
		OPENGL_X11=1
		;;
	aqua|mac|osx|macosx|agl)
		OPENGL_TYPE=Aqua
		USE_OPENGL=1
		OPENGL_AQUA=1
		;;
	win|windows|mswin|wgl)
		OPENGL_TYPE=Windows
		USE_OPENGL=1
		OPENGL_WINDOWS=1
		;;
	*)
		AC_MSG_ERROR([*** Valid arguments for --with-opengl= are yes,no,x11,aqua,windows.])
		;;
esac

if test -n "$USE_OPENGL" ; then

if test "$OPENGL_X11" = 1 ; then

# With OpenGL includes directory

LOC_CHECK_INC_PATH(opengl,OpenGL,OPENGLINC)

LOC_CHECK_INCLUDES(GL/gl.h GL/glu.h,OpenGL,$OPENGLINC $X_CFLAGS)

# With OpenGL library directory

LOC_CHECK_LIB_PATH(opengl,OpenGL,OPENGL_LIB_PATH)

LOC_CHECK_LIBS(GL,glBegin,OpenGL,$OPENGL_LIB_PATH,OPENGLLIB,$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $MATHLIB,,,-lpthread,-lXext)

LOC_CHECK_LIBS(GLU,gluBeginCurve,GLU,$OPENGL_LIB_PATH,OPENGLULIB,$OPENGLLIB $X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $MATHLIB,,,-lstdc++)

OPENGLLIB="$OPENGL_LIB_PATH $OPENGLLIB"
OPENGLULIB="$OPENGL_LIB_PATH $OPENGLULIB"

LOC_CHECK_FUNC(glXCreatePbuffer,,,,,$OPENGLLIB,[AC_DEFINE(HAVE_PBUFFERS)])
LOC_CHECK_FUNC(glXCreateGLXPixmap,,,,,$OPENGLLIB,[AC_DEFINE(HAVE_PIXMAPS)])

AC_DEFINE(OPENGL_X11)

fi # $OPENGL_X11

if test "$OPENGL_AQUA" = 1 ; then

LOC_CHECK_FRAMEWORK_PATH(opengl,OpenGL,OPENGLPATH)

LOC_CHECK_INCLUDES(OpenGL/gl.h OpenGL/glu.h,OpenGL,$OPENGLPATH)

LOC_CHECK_FUNC(glBegin,OpenGL library,OPENGLLIB,-framework OpenGL -framework AGL -framework ApplicationServices,$OPENGLPATH)
LOC_CHECK_FUNC(gluBeginCurve,GLU library,OPENGLLIB,,$OPENGLPATH,$OPENGLLIB)

OPENGLINC="$OPENGLPATH"
OPENGLLIBPATH="$OPENGLPATH"

AC_DEFINE(OPENGL_AQUA)

fi # $OPENGL_AQUA

if test "$OPENGL_WINDOWS" = 1 ; then

# With OpenGL includes directory

LOC_CHECK_INC_PATH(opengl,OpenGL,OPENGLINC)

LOC_CHECK_INCLUDES(GL/gl.h GL/glu.h,OpenGL,$OPENGLINC)

# With OpenGL library directory

LOC_CHECK_LIB_PATH(opengl,OpenGL,OPENGL_LIB_PATH)

ac_save_cflags="$CFLAGS"
CFLAGS="$CFLAGS $OPENGLINC"
LOC_CHECK_LINK(opengl32,[#include <GL/gl.h>],[glEnd();],OpenGL,$OPENGL_LIB_PATH,OPENGLLIB)
LOC_CHECK_LINK(glu32,[#include <GL/glu.h>],[gluNewQuadric();],GLU,$OPENGL_LIB_PATH,OPENGLULIB,$OPENGLLIB)
CFLAGS="${ac_save_cflags}"

OPENGLLIB="$OPENGL_LIB_PATH $OPENGLLIB"
OPENGLULIB="$OPENGL_LIB_PATH $OPENGLULIB"

AC_DEFINE(OPENGL_WINDOWS)

fi # $OPENGL_WINDOWS

fi # $USE_OPENGL

AC_SUBST(USE_OPENGL)
AC_SUBST(OPENGL_X11)
AC_SUBST(OPENGL_AQUA)
AC_SUBST(OPENGL_WINDOWS)

AC_SUBST(OPENGLINC)
AC_SUBST(OPENGLLIB)
AC_SUBST(OPENGLULIB)

# Done checking OpenGL

# Enable ODBC option

LOC_CHECK_USE(odbc,ODBC,USE_ODBC)

ODBCINC=
ODBCLIB=

if test -n "$USE_ODBC"; then

# With ODBC includes directory

LOC_CHECK_INC_PATH(odbc,ODBC,ODBCINC)

LOC_CHECK_INCLUDES(sql.h,ODBC,$ODBCINC)

# With ODBC library directory

LOC_CHECK_LIB_PATH(odbc,ODBC,ODBCLIB)

LOC_CHECK_LIBS(odbc,SQLConnect,ODBC,$ODBCLIB,ODBCLIB,$ICONVLIB,,[
LOC_CHECK_LIBS(iodbc,SQLConnect,ODBC,$ODBCLIB,ODBCLIB,,,[
ac_save_cflags="$CFLAGS"
CFLAGS="$CFLAGS $ODBCINC"
LOC_CHECK_LINK(odbc32,[#include <windows.h>
#include <sql.h>],[SQLAllocEnv((SQLHENV *)0);],ODBC,$ODBCLIB,ODBCLIB)
CFLAGS="${ac_save_cflags}"
])
])

fi # $USE_ODBC

AC_SUBST(ODBCINC)
AC_SUBST(ODBCLIB)

# Done checking ODBC

# Enable FFTW option

LOC_CHECK_USE(fftw,FFTW,USE_FFTW)

FFTWINC=
FFTWLIB=

if test -n "$USE_FFTW"; then

# With FFTW includes directory

LOC_CHECK_INC_PATH(fftw,FFTW,FFTWINC)

LOC_CHECK_INCLUDES(fftw3.h,FFTW,$FFTWINC,[
LOC_CHECK_INCLUDES(fftw.h,FFTW,,[
LOC_CHECK_INCLUDES(dfftw.h,FFTW,,)
])
])

# With FFTW library directory

LOC_CHECK_LIB_PATH(fftw,FFTW,FFTWLIB)

LOC_CHECK_LIBS(fftw3, fftw_execute,FFTW,$FFTWLIB,FFTWLIB,,$MATHLIB,[
LOC_CHECK_LIBS(fftw, fftwnd_one,FFTW,$FFTWLIB,FFTWLIB,,$MATHLIB,[
LOC_CHECK_LIBS(dfftw,fftwnd_one,FFTW,$FFTWLIB,FFTWLIB,,$MATHLIB,)
])
])

fi # $USE_FFTW

AC_SUBST(FFTWINC)
AC_SUBST(FFTWLIB)

# Done checking FFTW

# Enable BLAS option

LOC_CHECK_USE(blas,BLAS,USE_BLAS)

BLASLIB=
BLASINC=

if test -n "$USE_BLAS"; then

# With BLAS includes directory
# BLAS doesn't have includes (FORTRAN library)
# With BLAS library directory

LOC_CHECK_INC_PATH(blas, BLAS, BLASINC)
LOC_CHECK_LIB_PATH(blas, BLAS, BLASLIB)

# See if cblas.h exists (CBLAS,ATLAS,others)
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$BLASINC $CPPFLAGS"
AC_CHECK_HEADERS(cblas.h)
CPPFLAGS="$save_CPPFLAGS"

LOC_CHECK_LIBS(blas,dnrm2_,BLAS,$BLASLIB,BLASLIB,$MATHLIB,,,-lg2c)

blas_ok=no

# Check for ATLAS
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$BLASLIB $LDFLAGS"
AC_CHECK_LIB(atlas, ATL_xerbla,
		[AC_CHECK_LIB(f77blas, sgemm_,
		[AC_CHECK_LIB(cblas, cblas_dgemm, 
			[blas_ok=yes; BLASLIB="-lcblas -lf77blas -latlas"],
			[],[-lf77blas -latlas])],
		[],[-latlas])]
)
LDFLAGS="$save_LDFLAGS"

# Do we have ATLAS?
if test $blas_ok = yes; then
	AC_DEFINE(HAVE_LIBATLAS)
fi

# BLAS in Apple vecLib framework? (Mac OS-X)
#  not dependent on APP build
#if test -n "$MACOSX_APP"; then
if test $blas_ok = no; then
	vlib_flags="-framework vecLib"
	save_LIBS="$LIBS"
	LIBS="$vlib_flags $LIBS"
	AC_MSG_CHECKING([for sgemm in $vlib_flags])
	AC_TRY_LINK([], [sgemm], [blas_ok=yes; BLASLIB="$vlib_flags"], [BLASLIB=""])
	AC_MSG_RESULT($blas_ok)
	LIBS="$save_LIBS"
fi
#fi # $MACOSX_APP

# BLAS in PhiPACK libraries? (requires generic BLAS, too)
if test $blas_ok = no; then
	AC_CHECK_LIB(blas, sgemm_,
		[AC_CHECK_LIB(dgemm, dgemm_,
		[AC_CHECK_LIB(sgemm, sgemm_,
			[blas_ok=yes; BLASLIB="-lsgemm -ldgemm -lblas"],
			[], [-lblas])],
			[], [-lblas])]
	)
fi

# BLAS in Sun Performance library?
if test $blas_ok = no; then
	if test "x$GCC" != xyes; then # only works with Sun CC
		AC_CHECK_LIB(sunmath, acosp,
			[AC_CHECK_LIB(sunperf, sgemm_,
				[blas_ok=yes; BLASLIB="-xlic_lib=sunperf -lsunmath"],
			[], [-lsunmath])]
		)
	fi
fi

# Generic BLAS library
if test $blas_ok = no; then
	AC_CHECK_LIB(blas, sgemm_, [blas_ok=yes; BLASLIB="-lblas"])
fi

if test $blas_ok = yes; then
AC_DEFINE(HAVE_LIBBLAS)
fi

fi # $USE_BLAS

AC_SUBST(BLASLIB)
AC_SUBST(BLASINC)

# Done checking BLAS

# Enable LAPACK option

LOC_CHECK_USE(lapack,LAPACK,USE_LAPACK)

LAPACKLIB=
LAPACKINC=

# LAPACK is useless without BLAS
if test -n "$USE_BLAS"; then
if test -n "$USE_LAPACK"; then

# With LAPACK includes directory
# LAPACK doesn't have includes (FORTRAN library)
# With LAPACK library directory

lapack_ok=no

LOC_CHECK_INC_PATH(lapack, LAPACK, LAPACKINC)
LOC_CHECK_LIB_PATH(lapack, LAPACK, LAPACKLIB)

# See if clapack.h exists (ATLAS)
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$LAPACKINC $CPPFLAGS"
AC_CHECK_HEADERS(clapack.h)
CPPFLAGS="$save_CPPFLAGS"

# LAPACK linked to by default?
if test lapack_ok=no; then
	save_LIBS="$LIBS"; LIBS="$LIBS $BLASLIB $MATHLIB $FLIBS"
	save_LDFLAGS="$LDFLAGS"; LDFLAGS="$LAPACKLIB $LDFLAGS"
	AC_CHECK_FUNC(dsegv_, [lapack_ok=yes])
	LIBS="$save_LIBS"
	LDFLAGS="$save_LDFLAGS"
fi

# Generic LAPACK library?
if test $lapack_ok = no; then
	save_libs="$LIBS"; LIBS="$BLASLIB $MATHLIB $LIBS"
	save_LDFLAGS="$LDFLAGS"; LDFLAGS="$LAPACKLIB $LDFLAGS"
	AC_CHECK_LIB(lapack, desgv_,
		[lapack_ok=yes; LAPACKLIB="-llapack"], [], [$FLIBS])
	LIBS="$save_LIBS"
	LDFLAGS="$save_LDFLAGS"
fi

if test $lapack_ok = no; then
	LOC_CHECK_LIBS(lapack,dgesv_,LAPACK,$LAPACKLIB,LAPACKLIB,$BLASLIB $MATHLIB,,,-lg2c)
fi

AC_DEFINE(HAVE_LIBLAPACK)

fi # $USE_LAPACK
fi # $USE_BLAS

AC_SUBST(LAPACKLIB)
AC_SUBST(LAPACKINC)

# Done checking LAPACK

# Enable Cairo display driver option

LOC_CHECK_USE(cairo,Cairo,USE_CAIRO)

CAIROINC=
CAIROLIB=

if test -n "$USE_CAIRO"; then

cairo="cairo"
pkgs="cairo-ft cairo-fc cairo-pdf cairo-ps cairo-svg fontconfig"
if test -n "$USE_X11"; then
	pkgs="$pkgs cairo-xlib cairo-xlib-xrender"
fi
for pkg in $pkgs ; do
    if pkg-config --exists $pkg ; then
        cairo="$cairo $pkg"
    fi
done

# With Cairo includes directory
#FIXME: somehow quote dirs with spaces in $cairo ?
CAIROINC=`pkg-config --cflags $cairo`

LOC_CHECK_INC_PATH(cairo,cairo,CAIROINC)

LOC_CHECK_INCLUDES(cairo.h,Cairo,$CAIROINC)

# With Cairo library directory

CAIROLIB=`pkg-config --libs $cairo`

LOC_CHECK_LIB_PATH(cairo,cairo,CAIROLIB)
LOC_CHECK_LDFLAGS(cairo,cairo,CAIROLIB)

LOC_CHECK_FUNC(cairo_create,,,,,$CAIROLIB,[:])
LOC_CHECK_FUNC(cairo_xlib_surface_create_with_xrender_format,,,,,$CAIROLIB,
[CAIRO_HAS_XRENDER=1],[CAIRO_HAS_XRENDER=])
AC_SUBST(CAIRO_HAS_XRENDER)
LOC_CHECK_FUNC(cairo_xlib_surface_get_xrender_format,,,,,$CAIROLIB,
[CAIRO_HAS_XRENDER_SURFACE=1],[CAIRO_HAS_XRENDER_SURFACE=])
AC_SUBST(CAIRO_HAS_XRENDER_SURFACE)

CAIROLIB="$CAIROLIB $CAIROLDFLAGS"

fi # $USE_CAIRO

AC_SUBST(CAIROINC)
AC_SUBST(CAIROLIB)
AC_SUBST(USE_CAIRO)

# Done checking Cairo

# Enable FreeType option

LOC_CHECK_USE(freetype,FreeType,USE_FREETYPE)

FTINC=
FTLIB=

if test -n "$USE_FREETYPE"; then

# With FreeType includes directory

LOC_CHECK_INC_PATH(freetype,FreeType,FTINC)

LOC_CHECK_INCLUDES(ft2build.h,FreeType,$FTINC)

# With FreeType library directory

LOC_CHECK_LIB_PATH(freetype,FreeType,FTLIB)

LOC_CHECK_LIBS(freetype,FT_Init_FreeType,FreeType,$FTLIB,FTLIB,,,)

fi # $USE_FREETYPE

AC_SUBST(FTINC)
AC_SUBST(FTLIB)

# Done checking FreeType

# Enable NLS option

LOC_CHECK_USE(nls,NLS,USE_NLS)

INTLLIB=
HAVE_NLS=

if test -n "${USE_NLS}" ; then
    AC_DEFINE(USE_NLS)

AC_CHECK_FUNC(gettext, INTLLIB=, [
AC_CHECK_LIB(intl, gettext, INTLLIB=-lintl, [
    AC_MSG_ERROR([*** Unable to locate gettext() function.])
])])

    HAVE_NLS=1
fi

AC_SUBST(INTLLIB)
AC_SUBST(HAVE_NLS)

# Enable C++ option
 
LOC_CHECK_USE(cxx,C++,USE_CXX)

if test -n "$USE_CXX"; then
	AC_PROG_CXX
else
	CXX=
	CXXFLAGS=
	AC_SUBST(CXX)
	AC_SUBST(CXXFLAGS)
fi

# Done checking C++

# Enable openDWG option

LOC_CHECK_USE(opendwg,openDWG,USE_OPENDWG)

OPENDWGINCPATH=
OPENDWGLIBPATH=
OPENDWGLIB=

if test -n "${USE_OPENDWG}"; then

# With OPENDWG includes directory

LOC_CHECK_INC_PATH(opendwg,openDGW,OPENDWGINCPATH)

LOC_CHECK_INCLUDES(ad2.h,openDWG,$OPENDWGINCPATH)

# With OPENDWG library directory

LOC_CHECK_LIB_PATH(opendwg,openDWG,OPENDWGLIBPATH)

#search for ad2.a, ad3.a ... in openDWG toolkit directory:
#FIX ME  how to program this test??
#LOC_CHECK_LIBS(ad?.a,adSeekLayer,openDWG,$OPENDWGLIBPATH,OPENDWGLIB,,)
#
#for now hack (but working):
TRUEOPENDWGLIBPATH=`echo "$OPENDWGLIBPATH" | cut -b3-`
adlib=`ls -1 "$TRUEOPENDWGLIBPATH"/ad?.a | tail -1`
OPENDWGLIB="$adlib"

fi # $USE_OPENDWG

AC_SUBST(OPENDWGINCPATH)
AC_SUBST(OPENDWGLIBPATH)
AC_SUBST(OPENDWGLIB)
AC_SUBST(USE_OPENDWG)

# Done checking OPENDWG

# Enable pthread option

LOC_CHECK_USE(pthread,POSIX threads,USE_PTHREAD)

PTHREADINCPATH=
PTHREADLIBPATH=
PTHREADLIB=

if test -n "$USE_PTHREAD"; then

# With pthread includes directory

LOC_CHECK_INC_PATH(pthread,POSIX threads,PTHREADINCPATH)

LOC_CHECK_INCLUDES(pthread.h,POSIX threads,$PTHREADINCPATH)

# With pthread library directory

LOC_CHECK_LIB_PATH(pthread,POSIX threads,PTHREADLIBPATH)

LOC_CHECK_FUNC(pthread_create,POSIX threads functions,PTHREADLIB,,,,,[
LOC_CHECK_LIBS(pthread,pthread_create,POSIX threads,$PTHREADLIBPATH,PTHREADLIB,,,)
])

fi # $USE_PTHREAD

AC_SUBST(PTHREADINCPATH)
AC_SUBST(PTHREADLIBPATH)
AC_SUBST(PTHREADLIB)
AC_SUBST(USE_PTHREAD)

# Done checking pthread

# Enable OpenMP option

LOC_CHECK_USE(openmp,OpenMP,USE_OPENMP)

OMPINCPATH=
OMPLIBPATH=
OMPLIB=
OMPCFLAGS=

if test -n "$USE_OPENMP"; then

# With OpenMP includes directory

LOC_CHECK_INC_PATH(openmp,OpenMP,OMPINCPATH)

LOC_CHECK_INCLUDES(omp.h,OpenMP,$OMPINCPATH)

# With OpenMP library directory
# GCC et al.: -lgomp
# Solaris cc: -lmtsk
# AIX xlc: -lxlsmp
# SGI IRIX 6.5 MIPSpro C/C++: -lmp

LOC_CHECK_LIB_PATH(openmp,OpenMP,OMPLIBPATH)

LOC_CHECK_FUNC(GOMP_parallel_start,OpenMP functions,OMPLIB,,,,,[
LOC_CHECK_LIBS(gomp,GOMP_parallel_start,OpenMP,$OMPLIBPATH,OMPLIB,,,)
])

# compiler dependent
#if test ${CC} = "gcc" ; then
if test x$GCC = xyes ; then
	# GNU C compiler (>= 4.2.1)
	OMPCFLAGS=-fopenmp
elif test ${CC} = "icc" ; then
	# Intel compiler
	OMPCFLAGS=-openmp
elif test ${CC} = "opencc" ; then
	# AMD's x86 Open64 compiler
	OMPCFLAGS=-mp
elif test ${CC} = "pgcc" ; then
	# Portland Group's compiler
	OMPCFLAGS=-mp
# ... anybody else?
fi

# try to build a test program with "$CC $OMPCLFAGS" to confirm it works
#...how?
#echo "int main() {return 0;}" > test.c 
#$CC $OMPCLFAGS test.c -o test

fi # $USE_OPENMP

AC_SUBST(OMPINCPATH)
AC_SUBST(OMPLIBPATH)
AC_SUBST(OMPLIB)
AC_SUBST(OMPCFLAGS)
AC_SUBST(USE_OPENMP)

# Done checking OpenMP

# Enable OpenCL option

LOC_CHECK_USE(opencl,OpenCL,USE_OPENCL)

OCLINCPATH=
OCLLIBPATH=
OCLLIB=

if test -n "$USE_OPENCL"; then

# With OpenCL includes directory

LOC_CHECK_INC_PATH(opencl,OpenCL,OCLINCPATH)

if test -n "$MACOSX_APP" ; then
    LOC_CHECK_INCLUDES(OpenCL/opencl.h,OpenCL,$OCLINCPATH)

    # With OpenCL library directory
    ### FIXME: ###
    #LOC_CHECK_FRAMEWORK_PATH(opencl,OpenCL,OPENCLPATH)
    # last term in following would become ',$OPENCLPATH)' if above is uncommented
    LOC_CHECK_FUNC(clGetPlatformInfo,OpenCL library,OCLLIB,-framework OpenCL,)
else
    LOC_CHECK_INCLUDES(CL/cl.h,OpenCL,$OCLINCPATH)

    # With OpenCL library directory
    LOC_CHECK_LIB_PATH(opencl,OpenCL,OCLLIBPATH)
    LOC_CHECK_LIBS(OpenCL,clGetPlatformInfo,OpenCL,$OCLLIBPATH,OCLLIB,,,)
    # expanded symbol check: yes? no?
    #LOC_CHECK_FUNC(clGetPlatformInfo,OpenCL functions,OCLLIB,,,,,[
    #LOC_CHECK_LIBS(OpenCL,clGetPlatformInfo,OpenCL,$OCLLIBPATH,OCLLIB,,,)
    #])
fi

fi # $USE_OPENCL

AC_SUBST(OCLINCPATH)
AC_SUBST(OCLLIBPATH)
AC_SUBST(OCLLIB)
AC_SUBST(USE_OPENCL)

# Done checking OpenCL

# Enable LFS (from cdr-tools, tar, and autoconf 2.68)
dnl Check for large file support
dnl Do this last to make sure that no large file definition
dnl in confdefs.h will modify our results
AC_SYS_LARGEFILE
ac_save_cflags=${CFLAGS}
CFLAGS="$LFS_CFLAGS ${ac_save_cflags}"
dnl Warning do not run this test. it interferes with the test
dnl AC_CHECK_FUNCS(fseeko ftello) from above.
dnl The test AC_HAVE_LARGEFILES will check whether ftello/fseeko
dnl are available in Large File mode
AC_FUNC_FSEEKO
AC_HAVE_LARGEFILES
CFLAGS=${ac_save_cflags}
# Done large file support

USE_TERMIO=
AC_SUBST(USE_TERMIO)

STRIPFLAG=
AC_SUBST(STRIPFLAG)

GRASS_HOME="${DSTDIR}"
AC_SUBST(GRASS_HOME)

AC_OUTPUT(include/Make/Platform.make include/Make/Doxyfile_arch_html include/Make/Doxyfile_arch_latex include/version.h grass.pc)

LOC_MSG([Copying config.status to config.status.${ARCH}])
cp -f config.status config.status.${ARCH}

# Display configuration status

LOC_MSG()
LOC_MSG([GRASS is now configured for:  ${host}])
LOC_MSG()
LOC_MSG([  Source directory:           ${SRCDIR}])
LOC_MSG([  Build directory:            ${DSTDIR}])
LOC_MSG([  Installation directory:     ${INSTDIR}])
LOC_MSG([  Startup script in directory:${bindir}])
LOC_MSG([  C compiler:                 ${CC} ${CFLAGS}])
LOC_MSG([  C++ compiler:               ${CXX} ${CXXFLAGS}])
LOC_MSG([  Building shared libraries:  ${shared_ok}])
LOC_MSG([  OpenGL platform:            ${OPENGL_TYPE}])
LOC_MSG()
LOC_MSG_USE(MacOSX application,MACOSX_APP)
LOC_MSG([  MacOSX architectures:       ${MACOSX_ARCHS}])
LOC_MSG([  MacOSX SDK:                 ${MACOSX_SDK}])
LOC_MSG()
LOC_MSG_USE(BLAS support,USE_BLAS)
LOC_MSG_USE(BZIP2 support,USE_BZIP2)
LOC_MSG_USE(C++ support,USE_CXX)
LOC_MSG_USE(Cairo support,USE_CAIRO)
LOC_MSG_USE(DWG support,USE_OPENDWG)
LOC_MSG_USE(FFTW support,USE_FFTW)
LOC_MSG_USE(FreeType support,USE_FREETYPE)
LOC_MSG_USE(GDAL support,USE_GDAL)
LOC_MSG_USE(GEOS support,USE_GEOS)
LOC_MSG_USE(LAPACK support,USE_LAPACK)
LOC_MSG_USE(Large File support (LFS), USE_LARGEFILES)
LOC_MSG_USE(libLAS support,USE_LIBLAS)
LOC_MSG_USE(MySQL support,USE_MYSQL)
LOC_MSG_USE(NetCDF support,USE_NETCDF)
LOC_MSG_USE(NLS support,USE_NLS)
LOC_MSG_USE(ODBC support,USE_ODBC)
LOC_MSG_USE(OGR support,USE_OGR)
LOC_MSG_USE(OpenCL support,USE_OPENCL)
LOC_MSG_USE(OpenGL support,USE_OPENGL)
LOC_MSG_USE(OpenMP support,USE_OPENMP)
LOC_MSG_USE(PDAL support,USE_PDAL)
LOC_MSG_USE(PNG support,USE_PNG)
LOC_MSG_USE(POSIX thread support,USE_PTHREAD)
LOC_MSG_USE(PostgreSQL support,USE_POSTGRES)
LOC_MSG_USE(Readline support,USE_READLINE)
LOC_MSG_USE(Regex support,USE_REGEX)
LOC_MSG_USE(SQLite support,USE_SQLITE)
LOC_MSG_USE(TIFF support,USE_TIFF)
LOC_MSG_USE(X11 support,USE_X11)
LOC_MSG_USE(Zstandard support,USE_ZSTD)
LOC_MSG()
# remove when the new PROJ API is stable
if test $PROJ4API = 0 ; then
AC_MSG_RESULT([  using new PROJ 5+ API])
else
AC_MSG_RESULT([  using old PROJ 4 API])
fi
LOC_MSG()