File: configure.ac

package info (click to toggle)
postgis 3.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,528 kB
  • sloc: ansic: 162,229; sql: 93,970; xml: 53,139; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,435; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (2075 lines) | stat: -rw-r--r-- 70,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
dnl **********************************************************************
dnl *
dnl * PostGIS - Spatial Types for PostgreSQL
dnl * http://postgis.net
dnl *
dnl * Copyright (C) 2010-2023 Sandro Santilli <strk@kbt.io>
dnl * Copyright (C) 2008 Mark Cave-Ayland
dnl *
dnl * This is free software; you can redistribute and/or modify it under
dnl * the terms of the GNU General Public Licence. See the COPYING file.
dnl *
dnl **********************************************************************

AC_INIT( [postgis], m4_esyscmd_s([utils/extract_majmin_version.sh]) )

# test to see if srcdir already configured, when
# building out of tree
if test "`cd $srcdir && pwd`" != "`pwd`"; then
  if test -f $srcdir/config.status; then
    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
  fi
fi

AC_CONFIG_HEADERS([postgis_config.h])
AH_TEMPLATE([HAVE_VASPRINTF])
AH_TEMPLATE([HAVE_ASPRINTF])
AC_CONFIG_MACRO_DIR([macros])
AC_CONFIG_AUX_DIR([build-aux])
AC_PROG_INSTALL

dnl Overwrite _LT_PROG_AR
m4_pushdef([_LT_PROG_AR],
  [: ${AR_FLAGS=rs}
  PG_PROG_AR
  PG_PROG_RANLIB
  dnl Call original _LT_PROG_AR
  m4_popdef([_LT_PROG_AR])
  _LT_PROG_AR
]) # _LT_PROG_AR

dnl Invoke libtool: we do this as it is the easiest way to find the PIC
dnl flags required to build liblwgeom
LT_INIT

dnl
dnl Compilers
dnl
AC_PROG_CC
AC_PROG_CPP
AC_PROG_GREP
AC_C_BIGENDIAN

dnl
dnl SQL Preprocessor
dnl
AC_PATH_PROG([CPPBIN], [cpp], [])
if test "x$CPPBIN" != "x"; then
  SQLPP="${CPPBIN} -traditional-cpp -w -P -Upixel -Ubool"
else
  AC_PATH_PROG([GPP], [gpp_], [])
  if test "x$GPP" != "x"; then
    SQLPP="${GPP} -C -s \'" dnl Use better string support
  else
    if test "x${CPP}" != "x"; then
      SQLPP="${CPP} -traditional-cpp"
    else
		  AC_MSG_ERROR([Required "cpp" command not found])
    fi
  fi
fi
AC_SUBST([SQLPP])

dnl
dnl Silence warning: ar: 'u' modifier ignored since 'D' is the default
dnl
AC_ARG_VAR(AR_FLAGS, [Archiver flags])

dnl
dnl Define PIC flags in PICFLAGS (note: this variable is set as part of libtool initialisation above)
dnl
PICFLAGS="$lt_prog_compiler_pic"
AC_SUBST([PICFLAGS])

_LT_COMPILER_OPTION([if $compiler supports -fno-math-errno], [_cv_nomatherrno], [-fno-math-errno], [], [CFLAGS="$CFLAGS -fno-math-errno"], [])
_LT_COMPILER_OPTION([if $compiler supports -fno-signed-zeros], [_cv_nosignedzeros], [-fno-signed-zeros], [], [CFLAGS="$CFLAGS -fno-signed-zeros"], [])
_LT_COMPILER_OPTION([if $compiler supports -std=gnu11], [_cv_std], -std=gnu11, [], [CFLAGS="-std=gnu11 $CFLAGS"], [])


dnl
dnl Add libm to LDFLAGS so we don't need to add it everywhere manually
dnl
LDFLAGS="$LDFLAGS -lm"

dnl
dnl Exporting used library symbols in the module is a source of issues,
dnl see https://trac.osgeo.org/postgis/ticket/3281
dnl
EXCLUDELIBS_LDFLAGS=""
_LT_LINKER_OPTION([if $compiler supports --exclude-libs], [_cv_exclude_libs], [[-Wl,--exclude-libs,ALL]], [EXCLUDELIBS_LDFLAGS="-Wl,--exclude-libs,ALL"])
AC_SUBST([EXCLUDELIBS_LDFLAGS])

dnl
dnl Define executable suffix for use with the loader Makefiles
dnl
EXESUFFIX="$ac_cv_exeext"
AC_SUBST([EXESUFFIX])

dnl
dnl Version Information imported from Version.config
dnl
POSTGIS_MAJOR_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MAJOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
POSTGIS_MINOR_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MINOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
POSTGIS_MICRO_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MICRO_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`

AC_DEFINE_UNQUOTED([POSTGIS_MAJOR_VERSION], ["$POSTGIS_MAJOR_VERSION"], [PostGIS major version])
AC_DEFINE_UNQUOTED([POSTGIS_MINOR_VERSION], ["$POSTGIS_MINOR_VERSION"], [PostGIS minor version])
AC_DEFINE_UNQUOTED([POSTGIS_MICRO_VERSION], ["$POSTGIS_MICRO_VERSION"], [PostGIS micro version])

AC_SUBST([POSTGIS_MAJOR_VERSION])
AC_SUBST([POSTGIS_MINOR_VERSION])
AC_SUBST([POSTGIS_MICRO_VERSION])

dnl =====================================================
dnl Include minor version in postgis extension libraries
dnl =====================================================
LIBINCLUDEMINORVERSION="no"
AC_ARG_WITH([library-minor-version],
    [AS_HELP_STRING([--with-library-minor-version],
                    [Include minor version in the PostgreSQL PostGIS library files])],
    [LIBINCLUDEMINORVERSION="yes"], [])

if test "x$with-library-minor-version" = "xno"; then
    LIBINCLUDEMINORVERSION="no"
fi

AC_SUBST([LIBINCLUDEMINORVERSION])


dnl
dnl Liblwgeom version information imported from Version.config
dnl
LIBLWGEOM_CURRENT=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_CUR | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
LIBLWGEOM_AGE=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_AGE | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
LIBLWGEOM_REV=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_REV | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
AC_SUBST([LIBLWGEOM_CURRENT])
AC_SUBST([LIBLWGEOM_AGE])
AC_SUBST([LIBLWGEOM_REV])


dnl
dnl Search for flex/bison to build the parser
dnl

AC_PROG_LEX(noyywrap)
AC_PATH_PROG(YACC, bison)
AC_SUBST([LEX])
AC_SUBST([YACC])

dnl
dnl Search for OS-specific headers
dnl
AC_CHECK_HEADER([ieeefp.h], [HAVE_IEEEFP_H=1], [HAVE_IEEEFP_H=0])
AC_DEFINE_UNQUOTED([HAVE_IEEEFP_H], [$HAVE_IEEEFP_H], [ieeefp.h header])
AC_CHECK_HEADER([termios.h], [HAVE_TERMIOS_H=1], [HAVE_TERMIOS_H=0])
AC_DEFINE_UNQUOTED([HAVE_TERMIOS_H], [$HAVE_TERMIOS_H], [termios.h header])


dnl
dnl Check for platform-specific functions
dnl
AC_CHECK_FUNC(vasprintf, AC_DEFINE([HAVE_VASPRINTF]))
AC_CHECK_FUNC(asprintf, AC_DEFINE([HAVE_ASPRINTF]))
AC_FUNC_FSEEKO()

dnl
dnl MingW requires use of pwd -W to give proper Windows (not MingW) paths
dnl for in-place regression tests
dnl
case $host_os in
         *mingw*)
                 MINGWBUILD=1
                 ;;
         *)
                 MINGWBUILD=0
                 ;;
esac
AC_SUBST([MINGWBUILD])

AC_PATH_PROG([PERL], [perl], [])
if test "x$PERL" = "x"; then
        AC_MSG_ERROR([Perl was not found. Building PostGIS requires Perl.])
fi
AC_SUBST([PERL])

dnl ===========================================================================
dnl Find components needed to build documentation
dnl ===========================================================================
dnl
dnl Search for xsltproc which is required for building documentation
dnl

CAN_BUILD_COMMENTS=yes

AC_PATH_PROG([XSLTPROC], [xsltproc], [])
if test "x$XSLTPROC" = "x"; then
	AC_MSG_WARN([xsltproc is not installed so documentation cannot be built])
  CAN_BUILD_COMMENTS=no
fi

AC_PATH_PROG([XMLCATALOG], [xmlcatalog], [])
if test "x$XMLCATALOG" = "x"; then
	AC_MSG_WARN([xmlcatalog is not installed so documentation cannot be checked])
fi

AC_PATH_PROG([XMLLINT], [xmllint], [])
if test "x$XMLLINT" = "x"; then
	dnl AC_MSG_WARN([xmllint is not installed so documentation cannot be checked])
	AC_MSG_WARN([xmlcatalog is not installed so documentation cannot be built])
	CAN_BUILD_COMMENTS=no
fi



AC_PATH_PROG([XML2POT], [xml2pot], [])
if test "x$XML2POT" = "x"; then
	AC_MSG_WARN([xml2pot is not installed so translation template cannot be updated])
fi

AC_PATH_PROG([MSGMERGE], [msgmerge], [])
if test "x$MSGMERGE" = "x"; then
	AC_MSG_WARN([msgmerge is not installed so translations cannot be updated])
fi

AC_PATH_PROG([MSGCAT], [msgcat], [])
if test "x$MSGCAT" = "x"; then
	AC_MSG_WARN([msgcat is not installed so translation templates cannot be updated])
fi

AC_PATH_PROG([MSGCOMM], [msgcomm], [])
if test "x$MSGCOMM" = "x"; then
	AC_MSG_WARN([msgcomm is not installed so translations cannot be updated])
fi

AC_PATH_PROG([MSGATTRIB], [msgattrib], [])
if test "x$MSGATTRIB" = "x"; then
	AC_MSG_WARN([msgattrib is not installed so translations cannot be updated])
fi

AC_PATH_PROG([MSGINIT], [msginit], [])
if test "x$MSGINIT" = "x"; then
	AC_MSG_WARN([msginit is not installed so new translations cannot be initialized])
fi

CAN_BUILD_PDF=${CAN_BUILD_COMMENTS}

AC_PATH_PROG([CONVERT], [convert], [])
if test "x$CONVERT" = "x"; then
	AC_MSG_WARN([ImageMagick does not seem to be installed. Documentation cannot be built])
  CAN_BUILD_PDF=no
fi

AC_PATH_PROG([DBLATEX], [dblatex], [])
if test "x$DBLATEX" = "x"; then
	AC_MSG_WARN([dblatex is not installed so PDF documentation cannot be built])
  CAN_BUILD_PDF=no
fi

AC_SUBST(CAN_BUILD_COMMENTS)
AC_SUBST(CAN_BUILD_PDF)

CAN_BUILD_EPUB=${CAN_BUILD_COMMENTS}
AC_PATH_PROG([DBTOEPUB], [dbtoepub], [])
if test "x$DBTOEPUB" = "x"; then
  AC_MSG_WARN([dbtoepub is not installed so EPUB documentation cannot be built])
  CAN_BUILD_EPUB=no
fi
AC_SUBST(CAN_BUILD_EPUB)

dnl
dnl Allow the user to specify the location of the xhtml5/docbook.xsl stylesheet
dnl

AC_ARG_WITH([xsldir],
	[AS_HELP_STRING([--with-xsldir=PATH], [specify the directory containing the docbook.xsl stylesheet])],
	[XSLBASE="$withval"], [XSLBASE=""])

XSLBASE_AUTO=""
if test "x$XSLBASE" = "x"; then
	dnl If the user did not specify a directory for the docbook
	dnl stylesheet, choose the first uri that can resolve
  dnl xhtml5/docbook.xsl or the first directory
	dnl that matches from the following list
	SEARCHPATH="
		http://cdn.docbook.org/release/xsl/current
		https://cdn.docbook.org/release/xsl/current
		http://docbook.sourceforge.net/release/xsl-ns/current
		/usr/share/sgml/docbook/xsl-stylesheets
		/usr/share/xml/docbook/stylesheet/docbook-xsl-ns
		/usr/share/xml/docbook/stylesheet/docbook-xsl
		/usr/share/xml/docbook/stylesheet/nwalsh
		/usr/share/sgml/docbook/stylesheet/xsl/nwalsh
		/opt/local/share/xsl/docbook-xsl
		/usr/local/opt/docbook-xsl/docbook-xsl
		/usr/local/share/xsl/docbook-xsl
		/usr/share/xsl/docbook-xsl
		"
	for p in ${SEARCHPATH}; do
    case "${p}" in
      /*)
        AC_MSG_CHECKING([for xhtml5/docbook.xsl in directory $p...])
        if test -r "${p}"/xhtml5/docbook.xsl; then
          XSLBASE_AUTO="${p}"
          AC_MSG_RESULT([found])
          break
        fi
        AC_MSG_RESULT([not found])
        ;;
      *)
        if test "x$XMLCATALOG" != "x"; then
          AC_MSG_CHECKING([for xhtml5/docbook.xsl in URI $p...])
          if $XMLCATALOG '' "${p}/xhtml5/docbook.xsl" >/dev/null; then
            XSLBASE_AUTO="${p}"
            AC_MSG_RESULT([found])
            break
          fi
          AC_MSG_RESULT([not found])
        fi
        ;;
    esac
	done

	dnl Check to see if the automatically searched paths above located a
	dnl valid Docbook stylesheet
	if test "x$XSLBASE_AUTO" = "x"; then
		AC_MSG_WARN([could not locate Docbook stylesheets required to build the html documentation])
	fi
else
	dnl The user specified an alternate directory so make sure everything
	dnl looks sensible
	if test ! -d "$XSLBASE"; then
		AC_MSG_ERROR([the docbook stylesheet directory specified using --with-xsldir does not exist])
	fi

	if test ! -f "$XSLBASE/xhtml5/docbook.xsl"; then
		AC_MSG_ERROR([the docbook stylesheet directory specified using --with-xsldir does not contain the xhtml5/docbook.xsl file])
	fi
fi

dnl
dnl If XSLBASE has been set then at this point we know it must be
dnl valid and so we can just use it. If XSLBASE_AUTO has been set, and XSLBASE
dnl is empty then a valid stylesheet was found in XSLBASE_AUTO so we
dnl should use that. Otherwise just continue silently with a blank XSLBASE
dnl variable which will trigger the error message in the documentation Makefile
dnl

if test "x$XSLBASE" = "x"; then
	if test ! "x$XSLBASE_AUTO" = "x"; then
		XSLBASE="$XSLBASE_AUTO"
	fi
fi

AC_SUBST([XSLBASE])

dnl
dnl Ensure DocBook RelaxNG can be found
dnl
DOCBOOK5_RNG=http://docbook.org/xml/5.0/rng/docbook.rng
if test "x$XMLCATALOG" = "x"; then
  DOCBOOK5_RNG=
else
  if $XMLCATALOG '' "${DOCBOOK5_RNG}" > /dev/null; then :
  else DOCBOOK5_RNG=
  fi
fi
AC_SUBST([DOCBOOK5_RNG])

dnl
dnl Ensure DocBook DTD can be found
dnl
DOCBOOK5_DTD=http://docbook.org/xml/5.0/rng/docbook.dtd
if test "x$XMLCATALOG" = "x"; then
  DOCBOOK5_DTD=
else
  if $XMLCATALOG '' "${DOCBOOK5_DTD}" > /dev/null; then :
  else DOCBOOK5_DTD=
  fi
fi
AC_SUBST([DOCBOOK5_DTD])

dnl ===========================================================================
dnl Detect if pkg-config installed
dnl ===========================================================================
# check for pkg-config
PKG_PROG_PKG_CONFIG
if test -z "$PKG_CONFIG"; then
   AC_MSG_WARN([Cannot find pkg-config, make sure it is installed in your PATH])
fi


dnl ===========================================================================
dnl Detect CUnit if it is installed (used for unit testing)
dnl
dnl Note that we pass any specified CPPFLAGS and LDFLAGS into the Makefile
dnl as CUnit is the only compile-time dependency that cannot obtain any
dnl specialised flags using a --with-X parameter, and so we allow this
dnl information to be passed in if required.
dnl ===========================================================================

CUNIT_CPPFLAGS=""
CUNIT_LDFLAGS=""
if test ! -z "$PKG_CONFIG"; then
	PKG_CHECK_MODULES([CUNIT], [cunit],
		[
			CUNIT_CPPFLAGS="$CPPFLAGS $CUNIT_CFLAGS"
			CUNIT_LDFLAGS="$LDFLAGS $CUNIT_LIBS"
		],
		[AC_MSG_WARN([could not locate CUnit required for unit tests])])
else
	AC_CHECK_HEADER([CUnit/CUnit.h],
		[
			CUNIT_CPPFLAGS="$CPPFLAGS"
			AC_CHECK_LIB([cunit], [CU_initialize_registry], [CUNIT_LDFLAGS="$LDFLAGS -lcunit"], [AC_MSG_WARN([could not locate CUnit required for unit tests])])
		],
		[AC_MSG_WARN([could not locate CUnit required for unit tests])])
fi

AC_SUBST([CUNIT_CPPFLAGS])
AC_SUBST([CUNIT_LDFLAGS])


dnl ===========================================================================
dnl Detect iconv if it is installed (used for shp2pgsql encoding conversion
dnl if available)
dnl ===========================================================================

ICONV_CFLAGS=""
ICONV_LDFLAGS=""

AC_ARG_WITH([libiconv],
	[AS_HELP_STRING([--with-libiconv=PATH], [specify a path to non-default libiconv installation])],
	[LIBICONV_PATH="$withval"], [LIBICONV_PATH=""])

LDFLAGS_SAVE="$LDFLAGS"
CFLAGS_SAVE="$CFLAGS"

if test "x$LIBICONV_PATH" != "x"; then
	AC_MSG_RESULT([checking user-specified libiconv location: $LIBICONV_PATH])
	ICONV_CFLAGS="-I$LIBICONV_PATH/include"
	ICONV_LDFLAGS="-L$LIBICONV_PATH/lib"
	LDFLAGS="$ICONV_LDFLAGS $LDFLAGS"
	CFLAGS="$ICONV_CFLAGS $CFLAGS"
fi

HAVE_ICONV_H=0
AC_CHECK_HEADER([iconv.h], [HAVE_ICONV_H=1], [])

dnl If we find the header file, try and link against the library
if test "x$HAVE_ICONV_H" = "x1"; then
	dnl libconv defines iconv_open to libiconv_open, so we'll check that directly
	AC_CHECK_LIB([iconv], [libiconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -liconv" HAVE_ICONV=1], [])
	if test "x$HAVE_ICONV" = "x"; then
	        dnl Check for iconv included as part of libc, using iconv_open
	        AC_CHECK_LIB([c], [iconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -lc" HAVE_ICONV=1], [])
		if test "x$HAVE_ICONV" = "x"; then
			dnl But it's possible this implementation of libiconv doesn't have a libiconv_* define
			AC_CHECK_LIB([iconv], [iconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -liconv" HAVE_ICONV=1], [])
			if test "x$HAVE_ICONV" = "x"; then
				dnl No iconv library was found; issue a warning to the console
				AC_MSG_ERROR([Could not find libiconv. Please install libiconv and libiconv-devel.])
			fi
		fi
	fi
else
	dnl No iconv header was found; issue a warning to the console
	AC_MSG_ERROR([Could not find iconv.h header. Please install libiconv and libiconv-devel.])
fi

AC_CHECK_FUNCS([iconvctl libiconvctl],[],[])

LDFLAGS="$LDFLAGS_SAVE"
CFLAGS="$CFLAGS_SAVE"

dnl Only define HAVE_ICONV in postgis_config.h if we detect iconv successfully
if test "x$HAVE_ICONV" != "x"; then
	AC_DEFINE_UNQUOTED([HAVE_ICONV], [$HAVE_ICONV], [Defined if libiconv headers and library are present])
fi

AC_SUBST([ICONV_LDFLAGS])
AC_SUBST([ICONV_CFLAGS])

dnl ===========================================================================
dnl Detect the version of PostgreSQL installed on the system, if needed
dnl ===========================================================================

SUPPORT_POSTGRESQL=yes
AC_SUBST([SUPPORT_POSTGRESQL])

AC_ARG_VAR(PG_CONFIG, [PostgreSQL configure command to determine Postgres version to build against.])
AC_ARG_WITH([pgconfig],
	[AS_HELP_STRING([--with-pgconfig=FILE], [specify an alternative pg_config file or disable postgresql (--without-pgconfig)])],
	[PG_CONFIG="$withval"], [])

if test "x$PG_CONFIG" = "xno"; then
	SUPPORT_POSTGRESQL="no"
	AC_MSG_RESULT([PostgreSQL support disabled])

elif test "x$PG_CONFIG" = "x"; then
	dnl PG_CONFIG was not specified, so search within the current path
	AC_PATH_PROG([PG_CONFIG], [pg_config])

	dnl If we couldn't find pg_config, display an error
	if test "x$PG_CONFIG" = "x"; then
		AC_MSG_ERROR([could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.])
	fi
else
	dnl PG_CONFIG was specified; display a message to the user
	if test "x$PG_CONFIG" = "xyes"; then
		AC_MSG_ERROR([you must specify a parameter to --with-pgconfig, e.g. --with-pgconfig=/path/to/pg_config])
	else
		if test -f "$PG_CONFIG"; then
			AC_MSG_RESULT([Using user-specified pg_config file: $PG_CONFIG])
		else
			AC_MSG_ERROR([the user-specified pg_config file $PG_CONFIG does not exist])
		fi
	fi
fi

if test "x$SUPPORT_POSTGRESQL" = "xyes"; then dnl {

  dnl ===========================================================================
  dnl Ensure that $PG_CONFIG --pgxs points to a valid file. This is because some
  dnl distributions such as Debian also include pg_config as part of libpq-dev
  dnl packages, but don't install the Makefile it points to unless
  dnl the postgresql-server-dev packages are installed :)
  dnl ===========================================================================

  PGXS=`"$PG_CONFIG" --pgxs`
  if test "x$PGXS" = "x" -o ! -f "$PGXS"; then
    AC_MSG_ERROR([the PGXS Makefile $PGXS cannot be found. Please install the PostgreSQL server development packages and re-run configure.])
  fi

  AC_SUBST([PGXS])

  dnl Extract the version information from pg_config
  dnl Note: we extract the major & minor separately, ensure they are numeric, and then combine to give
  dnl the final version. This is to guard against user error...
  PGSQL_FULL_VERSION=`"$PG_CONFIG" --version`

  PGSQL_MAJOR_VERSION=`echo $PGSQL_FULL_VERSION | sed 's/[[^0-9]]*\([[0-9]]*\).*/\1/'`
  PGSQL_MINOR_VERSION=`$PG_CONFIG --version | sed 's/[[^0-9]]*\([[0-9]]\)\.\([[0-9]]\).*/\2/'`

  if test $PGSQL_MAJOR_VERSION -gt 9; then
  	dnl ==================================================================
  	dnl Starting with PostgreSQL 10, major is the new minor
  	dnl This is to prevent things like 10.31 ranking higher than 11.0
  	dnl===================================================================
  	PGSQL_MINOR_VERSION=0
  fi

  POSTGIS_PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION"
  POSTGIS_PGSQL_HR_VERSION="$PGSQL_MAJOR_VERSION.$PGSQL_MINOR_VERSION"

  PGSQL_PKGLIBDIR=`"$PG_CONFIG" --pkglibdir`
  PGSQL_LIBDIR=`"$PG_CONFIG" --libdir`
  PGSQL_SHAREDIR=`"$PG_CONFIG" --sharedir`

  AC_MSG_RESULT([checking PostgreSQL version... $PGSQL_FULL_VERSION])
  dnl Ensure that we are using PostgreSQL >= 12
  if test $POSTGIS_PGSQL_VERSION -lt 120; then
    AC_MSG_ERROR([PostGIS requires PostgreSQL >= 12])
  fi

  HAVE_SPGIST=yes

  dnl Note: We don't need the server-side LDFLAGS or CPPFLAGS because we get these from PGXS

  dnl Extract the linker and include flags for the frontend (for programs that use libpq)
  PGSQL_FE_LDFLAGS=-L`"$PG_CONFIG" --libdir`" -lpq"
  PGSQL_FE_CPPFLAGS=-I`"$PG_CONFIG" --includedir`

  AC_SUBST([PGSQL_FE_LDFLAGS])
  AC_SUBST([PGSQL_FE_CPPFLAGS])

  dnl Extract the include flags for the backend (libpgcommon)
  PGSRV_INC=`"$PG_CONFIG" --includedir-server`
  PGSQL_BE_CPPFLAGS="-I${PGSRV_INC}"
  dnl Add $PGSRV_INC/port/win32 to MinGW build to pick up netdb.h
  case $host in
    *mingw32*)
      PGSQL_BE_CPPFLAGS="${PGSQL_BE_CPPFLAGS} -I${PGSRV_INC}/port/win32"
      ;;
  esac

  AC_SUBST([PGSQL_BE_CPPFLAGS])

  dnl Extract the documentation and man page directories
  PGSQL_DOCDIR=`"$PG_CONFIG" --docdir`
  PGSQL_MANDIR=`"$PG_CONFIG" --mandir`

  AC_SUBST([PGSQL_DOCDIR])
  AC_SUBST([PGSQL_MANDIR])

  dnl Extract the locale directory
  PGSQL_LOCALEDIR=`"$PG_CONFIG" --localedir`
  AC_DEFINE_UNQUOTED([PGSQL_LOCALEDIR], ["$PGSQL_LOCALEDIR"], [Location of PostgreSQL locale directory])

  dnl Extract the executable directory
  PGSQL_BINDIR=`"$PG_CONFIG" --bindir`

  AC_SUBST([PGSQL_BINDIR])

  dnl Extract the share directory
  PGSQL_SHAREDIR=`"$PG_CONFIG" --sharedir`

  AC_SUBST([PGSQL_SHAREDIR])

  dnl Ensure that we can parse libpq-fe.h
  CPPFLAGS_SAVE="$CPPFLAGS"
  CPPFLAGS="$PGSQL_FE_CPPFLAGS"
  AC_CHECK_HEADER([libpq-fe.h], [], [AC_MSG_ERROR([could not find libpq-fe.h])])
  CPPFLAGS="$CPPFLAGS_SAVE"

  dnl Ensure we can link against libpq
  LIBS_SAVE="$LIBS"
  LIBS="$PGSQL_FE_LDFLAGS"

  CC_SAVE="$CC"
  CC=`"$PG_CONFIG" --cc`

  CFLAGS_SAVE="$CFLAGS"
  CFLAGS=`"$PG_CONFIG" --cflags`

  AC_CHECK_LIB([pq], [PQserverVersion],
    [],
    [AC_MSG_ERROR([could not find libpq])],
    [])
  LIBS="$LIBS_SAVE"
  CC="$CC_SAVE"
  CFLAGS="$CFLAGS_SAVE"

  AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_VERSION], [$POSTGIS_PGSQL_VERSION], [PostgreSQL server version])
  AC_SUBST([POSTGIS_PGSQL_VERSION])
  AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_HR_VERSION], [$POSTGIS_PGSQL_HR_VERSION], [PostgreSQL human readable server version])
  AC_SUBST([POSTGIS_PGSQL_HR_VERSION])
  AC_SUBST([HAVE_SPGIST])

fi dnl } SUPPORT_POSTGRESQL = yes


dnl ===========================================================================
dnl Explain our prefix policy if necessary.
dnl ===========================================================================

if test "$prefix" != "NONE" -a "x$PG_CONFIG" != "xno"; then
  AC_MSG_RESULT([------------------------------------------------------------------------])
  AC_MSG_RESULT([  WARNING: You have set the --prefix to '$prefix'. But we mostly    ])
  AC_MSG_RESULT([  ignore the --prefix. For your info, using the values determined from ])
  AC_MSG_RESULT([  $PG_CONFIG we will be installing:   ])
  AC_MSG_RESULT([    * postgis shared library in $PGSQL_LIBDIR ])
  AC_MSG_RESULT([    * postgis SQL files in $PGSQL_SHAREDIR/contrib/postgis-$POSTGIS_MAJOR_VERSION.$POSTGIS_MINOR_VERSION ])
  AC_MSG_RESULT([------------------------------------------------------------------------])
fi

dnl ===========================================================================
dnl Detect libxml2 if it is installed
dnl (needed to GeomFromGML and GeomFromKML functions)
dnl ===========================================================================

AC_ARG_WITH([xml2config],
	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])],
	[XML2CONFIG="$withval"], [XML2CONFIG=""])

XML2_LDFLAGS=""
XML2_CPPFLAGS=""

if test "x$XML2CONFIG" = "x"; then
	dnl XML2CONFIG was not specified, so search within the current path
	AC_PATH_PROG([XML2CONFIG], [xml2-config])

	dnl If we couldn't find xml2-config, display a warning if pkg-config fails too
	if test "x$XML2CONFIG" = "x"; then
		if test ! -z "$PKG_CONFIG"; then
			PKG_CHECK_MODULES([LIBXML2], [libxml-2.0], [
				XML2_CPPFLAGS="$LIBXML2_CFLAGS"
				XML2_LDFLAGS="$LIBXML2_LIBS"
				POSTGIS_LIBXML2_VERSION=`$PKG_CONFIG libxml-2.0 --modversion`
			], [])
		else
			AC_MSG_ERROR([could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.])
		fi
	else
		dnl Extract the linker and include flags
		XML2_LDFLAGS=`$XML2CONFIG --libs`
		XML2_CPPFLAGS=`$XML2CONFIG --cflags`

		dnl Extract the version
		POSTGIS_LIBXML2_VERSION=`$XML2CONFIG --version`
	fi
else
	dnl XML2CONFIG was specified; display a message to the user
	if test "x$XML2CONFIG" = "xyes"; then
		AC_MSG_ERROR([you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])
	else
		if test -f $XML2CONFIG; then
			AC_MSG_RESULT([Using user-specified xml2-config file: $XML2CONFIG])

			dnl Extract the linker and include flags
			XML2_LDFLAGS=`$XML2CONFIG --libs`
			XML2_CPPFLAGS=`$XML2CONFIG --cflags`

			dnl Extract the version
			POSTGIS_LIBXML2_VERSION=`$XML2CONFIG --version`
		else
			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
		fi
	fi
fi


dnl
dnl XCode in 10.12 supplies bad flags in xml2config resulting
dnl in compile errors. For that one version, we force the prefix
dnl to match where we know the libraries reside
dnl
case $host_os in
    darwin*)
        AC_PATH_PROG([XCRUN], [xcrun])
        if test "x$XCRUN" = "x"; then
        	AC_MSG_RESULT([using OSX XCode... no])
        else
            XCODE_VER=`$XCRUN --show-sdk-version`
            if test $XCODE_VER = "10.12"; then
                AC_MSG_RESULT([applying OSX XCode 10.12 libxml special case... yes])
                XML2_LDFLAGS=`$XML2CONFIG --exec-prefix=/usr --libs`
            else
                AC_MSG_RESULT([using OSX XCode $XCODE_VER... yes])
            fi
        fi
        ;;
esac

dnl Check headers file
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$XML2_CPPFLAGS"
AC_CHECK_HEADERS([libxml/tree.h libxml/parser.h libxml/xpath.h libxml/xpathInternals.h],
		 [], [AC_MSG_ERROR([could not find headers include related to libxml2])])
CPPFLAGS="$CPPFLAGS_SAVE"

dnl Ensure we can link against libxml2
LIBS_SAVE="$LIBS"
LIBS="$XML2_LDFLAGS"
AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], [])
LIBS="$LIBS_SAVE"

AC_DEFINE_UNQUOTED([POSTGIS_LIBXML2_VERSION], ["$POSTGIS_LIBXML2_VERSION"], [PostGIS libxml2 version])
AC_SUBST([POSTGIS_LIBXML2_VERSION])



dnl ===========================================================================
dnl Detect the version of GEOS installed on the system
dnl ===========================================================================

dnl
dnl Set the min version number here
dnl
GEOS_MIN_VERSION=3.8.0
GEOS_MIN_VERSION_NUMERIC=`echo $GEOS_MIN_VERSION | $PERL -nle 'printf "%d%02d%02d\n",$1,$2,$3 if /(\d+)\.(\d+)\.(\d+)/'`

AC_ARG_WITH([geosconfig],
	[AS_HELP_STRING([--with-geosconfig=FILE], [specify an alternative geos-config file])],
	[GEOSCONFIG="$withval"], [GEOSCONFIG=""])

if test ! -z "$GEOSCONFIG"; then

	dnl the --with-geosconfig argument was set
	AC_MSG_CHECKING([that $GEOSCONFIG exists])
	if test -f "$GEOSCONFIG"; then
		AC_MSG_RESULT([yes])
		AC_MSG_CHECKING([that $GEOSCONFIG is executable])
		if test -x "$GEOSCONFIG"; then
			AC_MSG_RESULT([yes])
		else
			AC_MSG_RESULT([no])
			AC_MSG_ERROR([use --with-geosconfig=/path/to/executable/geos-config])
		fi
	else
		AC_MSG_RESULT([no])
		AC_MSG_ERROR([use --with-geosconfig=/path/to/geos-config])
	fi

	dnl a usable geos-config was specified
	GEOS_VERSION=`$GEOSCONFIG --version`
	GEOS_LDFLAGS=`$GEOSCONFIG --clibs`
	GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
	GEOS_CONFIG_SRC=$GEOSCONFIG

else

	dnl the --with-geosconfig argument was NOT set
	if test ! -z "$PKG_CONFIG"; then
		dnl look in pkg-config first
		dnl GEOS_LDFLAGS and GEOS_CPPFLAGS get set automatically

			PKG_CHECK_MODULES([GEOS], [geos], [
				GEOS_VERSION=`$PKG_CONFIG geos --modversion`
				GEOS_LDFLAGS=`$PKG_CONFIG geos --libs`
				GEOS_CPPFLAGS=`$PKG_CONFIG geos --cflags`
				GEOS_PKGCONFIG=yes
				GEOS_CONFIG_SRC="$PKG_CONFIG geos"
			], [
				AC_MSG_RESULT([checking for geos-config on the path...])

			])
	fi

	if test -z "$GEOS_PKGCONFIG"; then
		dnl pkg-config failed, so try to use geos-config from path
		AC_PATH_PROG([GEOSCONFIG], [geos-config])
		if test -z "$GEOSCONFIG"; then
			AC_MSG_ERROR([could not find geos-config on the current path, try using the --with-geosconfig parameter.])
		else
			GEOS_VERSION=`$GEOSCONFIG --version`
			GEOS_LDFLAGS=`$GEOSCONFIG --clibs`
			GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
			GEOS_CONFIG_SRC="$GEOSCONFIG"
		fi
	fi
fi

dnl
dnl Convert human form (3.1.12) of version
dnl    to numeric form (30112) for version checking
dnl
POSTGIS_GEOS_VERSION=`echo $GEOS_VERSION | $PERL -nle 'printf "%d%02d%02d\n",$1,$2,$3 if /(\d+)\.(\d+)\.(\d+)/'`

AC_MSG_CHECKING([GEOS version])
AC_MSG_RESULT([$GEOS_VERSION])

AC_MSG_CHECKING([GEOS numeric version])
AC_MSG_RESULT([$POSTGIS_GEOS_VERSION])

AC_MSG_CHECKING([GEOS link flags])
AC_MSG_RESULT([$GEOS_LDFLAGS])

AC_MSG_CHECKING([GEOS compile flags])
AC_MSG_RESULT([$GEOS_CPPFLAGS])

dnl Ensure that we are using GEOS >= GEOS_MIN_VERSION
AC_MSG_CHECKING([GEOS version is supported])
if test "$POSTGIS_GEOS_VERSION" -ge "$GEOS_MIN_VERSION_NUMERIC"; then
	AC_MSG_RESULT([yes])
else
	AC_MSG_ERROR([PostGIS requires GEOS >= $GEOS_MIN_VERSION])
fi

#
# MacOS with XCode > 15 now requires rpath entries for
# libraries like GEOS/Proj that might be flexibly installed
# with movability expected
#
case $host_os in
    darwin*)
				GEOS_RPATH=`echo $GEOS_LDFLAGS | $PERL -nle 'print "$1" if /\-L ?(\S+) /'`
				AC_MSG_RESULT([checking for GEOS_RPATH under MacOS... $GEOS_RPATH])
				if test "x$GEOS_RPATH" != "x"; then
				  # Add the rpath setting to the LDFLAGS
					GEOS_LDFLAGS="$GEOS_LDFLAGS -Wl,-rpath,$GEOS_RPATH"
				fi
				;;
esac

dnl Ensure that we can parse geos_c.h
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$GEOS_CPPFLAGS"
AC_CHECK_HEADER([geos_c.h], [], [AC_MSG_ERROR([could not find geos_c.h - you may need to specify the directory of a geos-config file using --with-geosconfig])])
CPPFLAGS="$CPPFLAGS_SAVE"

dnl Ensure we can link against libgeos_c
LIBS_SAVE="$LIBS"
LIBS="$GEOS_LDFLAGS"
AC_CHECK_LIB([geos_c], [initGEOS],
	[],
	[AC_MSG_ERROR([could not find libgeos_c - you may need to specify the directory of a geos-config file using --with-geosconfig])],
	[])
LIBS="$LIBS_SAVE"

AC_DEFINE_UNQUOTED([POSTGIS_GEOS_VERSION], [$POSTGIS_GEOS_VERSION], [GEOS library version])
AC_SUBST([POSTGIS_GEOS_VERSION])
AC_SUBST([GEOS_LDFLAGS])
AC_SUBST([GEOS_CPPFLAGS])


dnl ===========================================================================
dnl SFCGAL library support
dnl ===========================================================================

AC_ARG_WITH([sfcgal],
	[AS_HELP_STRING([--with-sfcgal=PATH], [Add SFCGAL support. ARG allows to specify an alternate PATH to sfcgal-config])],
	[SFCGAL_CONFIG="$withval"],
	[with_sfcgal=auto])


POSTGIS_SFCGAL_VERSION="0"
if test "x$with_sfcgal" != "xno"; then
  if test "x$with_sfcgal" = "xyes" -o "x$with_sfcgal" = "xauto"; then
	  AC_PATH_PROG([SFCGAL_CONFIG], [sfcgal-config], [])
  fi
	if test -x "$SFCGAL_CONFIG"; then
		SFCGAL_VERSION=`$SFCGAL_CONFIG --version` || AC_MSG_ERROR([cannot determine sfcgal version (tried with $SFCGAL_CONFIG --version)])
		SFCGAL_LDFLAGS=`$SFCGAL_CONFIG --libs`
		SFCGAL_CPPFLAGS=`$SFCGAL_CONFIG --cflags`

		SFCGAL_MAJOR_VERSION=`echo $SFCGAL_VERSION | cut -d. -f1 | sed 's/[[^0-9]]//g'`
		SFCGAL_MINOR_VERSION=`echo $SFCGAL_VERSION | cut -d. -f2 | sed 's/[[^0-9]]//g'`
		SFCGAL_PATCH_VERSION=`echo $SFCGAL_VERSION | cut -d. -f3 | sed 's/[[^0-9]]//g'`
		SFCGAL_NUMERIC_PATCH_VERSION=`printf "%02d" $SFCGAL_PATCH_VERSION`
		SFCGAL_NUMERIC_MINOR_VERSION=`printf "%02d" $SFCGAL_MINOR_VERSION`
		POSTGIS_SFCGAL_VERSION="$SFCGAL_MAJOR_VERSION$SFCGAL_NUMERIC_MINOR_VERSION$SFCGAL_NUMERIC_PATCH_VERSION"
		AC_DEFINE_UNQUOTED([POSTGIS_SFCGAL_VERSION], [$POSTGIS_SFCGAL_VERSION], [SFCGAL library version at build time])

		SFCGAL_STATIC=`$SFCGAL_CONFIG --static`
		if test "x$SFCGAL_STATIC" = "xON"; then
			AC_MSG_WARN([The SFCGAL version found is not installed as a dynamic library.])
		else
      SFCGAL="sfcgal"
			HAVE_SFCGAL="yes"
      AC_DEFINE([HAVE_SFCGAL], [1], [Define to 1 if sfcgal is being built])
	    SFCGAL_MAKEFILE_LIST="sfcgal/regress/Makefile sfcgal/regress/tests.mk extensions/postgis_sfcgal/Makefile"
		fi
		if test ! "$POSTGIS_SFCGAL_VERSION" -ge 10301; then
			AC_MSG_ERROR([PostGIS requires SFCGAL >= 1.3.1 (found $SFCGAL_VERSION)])
		fi
	else
		if test "x$with_sfcgal" != "xauto"; then
			AC_MSG_ERROR([sfcgal-config cannot be found. Please install sfcgal])
		fi
	fi
fi

AC_SUBST([POSTGIS_SFCGAL_VERSION])
AC_SUBST([SFCGAL_VERSION])
AC_SUBST([SFCGAL_CPPFLAGS])
AC_SUBST([SFCGAL_LDFLAGS])
AC_SUBST([SFCGAL_OBJS])
AC_SUBST([SFCGAL])
AC_SUBST([HAVE_SFCGAL])


dnl ===========================================================================
dnl Detect gettext
dnl ===========================================================================

GETTEXT_CFLAGS=""
GETTEXT_LDFLAGS=""

AC_ARG_WITH([gettext],
	[AS_HELP_STRING([--with-gettext=PATH], [specify a path to non-default gettext installation])],
	[GETTEXT_PATH="$withval"], [GETTEXT_PATH="yes"])

LDFLAGS_SAVE="$LDFLAGS"
CFLAGS_SAVE="$CFLAGS"

if test "x$GETTEXT_PATH" != "xno"; then
	dnl If user has specified a custom gettext installation path, use it.
	if test "x$GETTEXT_PATH" != "xyes"; then
		AC_MSG_RESULT([checking user-specified gettext location: $GETTEXT_PATH])
		GETTEXT_CFLAGS="-I$GETTEXT_PATH/include"
		GETTEXT_LDFLAGS="-L$GETTEXT_PATH/lib"
		LDFLAGS="$GETTEXT_LDFLAGS $LDFLAGS"
		CFLAGS="$GETTEXT_CFLAGS $CFLAGS"
	fi

	AM_GNU_GETTEXT([external], [], [])

	if test "x$LIBINTL" = "x"; then
		USE_NLS=no
	fi
fi

AC_SUBST([GETTEXT_CFLAGS])
AC_SUBST([GETTEXT_LDFLAGS])

LDFLAGS="$LDFLAGS_SAVE"
CFLAGS="$CFLAGS_SAVE"


dnl ===========================================================================
dnl Detect the version of PROJ installed
dnl ===========================================================================

AC_ARG_WITH([projdir],
	[AS_HELP_STRING([--with-projdir=PATH], [specify the PROJ installation directory])],
	[PROJDIR="$withval"], [PROJDIR=""])

if test ! "x$PROJDIR" = "x"; then
	dnl Make sure that the directory exists
	if test "x$PROJDIR" = "xyes"; then
		AC_MSG_ERROR([you must specify a parameter to --with-projdir, e.g. --with-projdir=/path/to])
	else
		if test -d "$PROJDIR"; then
			AC_MSG_RESULT([Using user-specified proj directory: $PROJDIR])

			dnl Add the include directory to PROJ_CPPFLAGS
			PROJ_CPPFLAGS="-I$PROJDIR/include"
			PROJ_LDFLAGS="-L$PROJDIR/lib -lproj"
		else
			AC_MSG_ERROR([the --with-projdir directory "$PROJDIR" cannot be found])
		fi
	fi
elif test ! -z "$PKG_CONFIG"; then
	dnl To keep compatibility with PROJ pre 4.8, default to lproj if not found
	PKG_CHECK_MODULES([PROJ], [proj],
		[
			PROJ_CPPFLAGS="$PROJ_CFLAGS"
			PROJ_LDFLAGS="$PROJ_LIBS"
			PROJ_VERSION=`$PKG_CONFIG proj --modversion`
		],
		[
			PROJ_LDFLAGS="-lproj"
		])
else
	dnl To keep compatibility with PROJ pre 4.8, default to lproj
	PROJ_LDFLAGS="-lproj"
fi


#
# MacOS with XCode > 15 now requires rpath entries for
# libraries like GEOS/Proj that might be flexibly installed
# with movability expected
#
case $host_os in
    darwin*)
				PROJ_RPATH=`echo $PROJ_LDFLAGS | $PERL -nle 'print "$1" if /\-L ?(\S+) /'`
				AC_MSG_RESULT([checking for PROJ_RPATH under MacOS... $PROJ_RPATH])
					if test "x$PROJ_RPATH" != "x"; then
				  # Add the rpath setting to the LDFLAGS
					PROJ_LDFLAGS="$PROJ_LDFLAGS -Wl,-rpath,$PROJ_RPATH"
				fi
				;;
esac


dnl Check that we can find the proj_api.h header file
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$PROJ_CPPFLAGS"
AC_CHECK_HEADER([proj_api.h],
	[],
	[AC_CHECK_HEADER([proj.h],
		[],
		[AC_MSG_ERROR([could not find proj.h or proj_api.h - you may need to specify the directory of a PROJ installation using --with-projdir])]
		)]
	)

dnl Find the PROJ version number if not detected via pkg-config
if test "x$PROJ_VERSION" = "x"; then
	AC_PROJ_VERSION()
fi
CPPFLAGS="$CPPFLAGS_SAVE"

POSTGIS_PROJ_VERSION=`echo "${PROJ_VERSION}" | $PERL -nle 'printf "%d%02d%02d\n",$1,$2,$3 if /(\d+)\.(\d+)\.(\d+)/'`

dnl Ensure that we are using PROJ >= 6.1.0 (requires pj_set_searchpath)
if test ! "$POSTGIS_PROJ_VERSION" -ge 61; then
	AC_MSG_ERROR([PostGIS requires PROJ >= 6.1.0])
fi

AC_DEFINE_UNQUOTED([POSTGIS_PROJ_VERSION], [$POSTGIS_PROJ_VERSION], [PROJ library version])
AC_SUBST([POSTGIS_PROJ_VERSION])
AC_SUBST([PROJ_CPPFLAGS])
AC_SUBST([PROJ_LDFLAGS])

dnl Ensure we can link against libproj
LIBS_SAVE="$LIBS"
LIBS="$PROJ_LDFLAGS"
AC_CHECK_LIB([proj], [pj_get_release], [],
	[AC_CHECK_LIB([proj], [proj_info], [],
		[AC_MSG_ERROR([could not find libproj - you may need to specify the directory of a PROJ installation using --with-projdir])],
		[]
		)],
	[])
LIBS="$LIBS_SAVE"


dnl ===========================================================================
dnl Detect if json-c installed
dnl ===========================================================================

CHECK_JSON=yes
HAVE_JSON=no

AC_ARG_WITH([json],
	[AS_HELP_STRING([--without-json], [build without json-c support])],
	[CHECK_JSON="$withval"], [])

if test "$CHECK_JSON" != "no"; then

    AC_ARG_WITH([jsondir],
            [AS_HELP_STRING([--with-jsondir=PATH], [specify the json-c installation directory])],
            [JSONDIR="$withval"], [JSONDIR=])

    if test ! "x$JSONDIR" = "x"; then
            dnl Make sure that the directory exists
            if test "x$JSONDIR" = "xyes"; then
                    AC_MSG_ERROR([you must specify a parameter to --with-jsondir, e.g. --with-jsondir=/path/to])
            else
                    AC_MSG_RESULT([Using user-specified json-c directory: $JSONDIR])

                    JSON_LDFLAGS="-L$JSONDIR/lib"
                    LIBS_SAVE="$LIBS"
                    LIBS="$JSON_LDFLAGS"
                    AC_CHECK_FILE("$JSONDIR/include/json-c/json.h",
                                [
                                    JSON_CPPFLAGS="-I$JSONDIR/include/json-c"
                                    AC_CHECK_LIB([json-c], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson-c"])
                                ],
                                [
                                    AC_CHECK_FILE("$JSONDIR/include/json/json.h",
                                    [
                                        JSON_CPPFLAGS="-I$JSONDIR/include/json"
                                        AC_CHECK_LIB([json], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson"])
                                    ],
                                    [AC_MSG_ERROR([Could not find header: json.h])])
                                ])
                    LIBS="$LIBS_SAVE"
            fi
    elif test ! -z "$PKG_CONFIG"; then
	PKG_CHECK_MODULES([JSONC], [json-c], [
                HAVE_JSON=yes
                JSON_CPPFLAGS="$JSONC_CFLAGS"
                JSON_LDFLAGS="$JSONC_LIBS"
            ], [AC_MSG_WARN("Could not find json-c")])
    fi

    if test "$HAVE_JSON" = "yes"; then
            AC_DEFINE([HAVE_LIBJSON], 1, [Define to 1 if libjson is present])
    fi

    AC_SUBST([JSON_CPPFLAGS])
    AC_SUBST([JSON_LDFLAGS])
    AC_SUBST([HAVE_JSON])

fi


dnl ===========================================================================
dnl Detect if protobuf-c installed
dnl ===========================================================================

CHECK_PROTOBUF=yes
HAVE_PROTOBUF=no

AC_ARG_WITH([protobuf],
	[AS_HELP_STRING([--without-protobuf], [build without protobuf-c support])],
	[CHECK_PROTOBUF="$withval"], [])

dnl User didn't turn OFF protobuf support so...
if test "$CHECK_PROTOBUF" != "no"; then

	HAVE_PROTOBUF=yes
	dnl Need to find libdir, incdir and protoc-c compiler

	CPPFLAGS_SAVE="$CPPFLAGS"
	LDFLAGS_SAVE="$LDFLAGS"
	LIBS_SAVE="$LIBS"

	dnl Try pkgconfig first
	if test -n "$PKG_CONFIG"; then
		dnl Ensure libprotobuf-c is of minimum required version
		PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.1.0], [
				PROTOBUF_CPPFLAGS="$PROTOBUFC_CFLAGS";
				PROTOBUF_LDFLAGS="$PROTOBUFC_LIBS";
				PROTOC_VERSION=`$PKG_CONFIG libprotobuf-c --modversion | sed 's/\([[0-9]]\).*\([[0-9]]\).*\([[0-9]]\)/\100\200\3/'`
			], [
				AC_MSG_RESULT([libprotobuf-c not found in pkg-config])
			])
	fi

	AC_ARG_WITH([protobufdir],
		[AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],[
			if test "x$withval" = "xyes"; then
				AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/usr/local])
			else
				PROTOBUF_LDFLAGS="-L$withval/lib -lprotobuf-c";
				PROTOBUF_CPPFLAGS="-I$withval/include"
			fi
		], [])

	AC_ARG_WITH([protobuf-inc],
		[AS_HELP_STRING([--with-protobuf-inc=PATH], [google/protobuf-c/protobuf-c.h header installation directory])], [
			PROTOBUF_CPPFLAGS="-I$withval"
		],[])

	AC_ARG_WITH([protobuf-lib],
		[AS_HELP_STRING([--with-protobuf-lib=PATH], [libprotobuf-c.so/dll/dylib library installation directory])], [
			PROTOBUF_LDFLAGS="-L$withval -lprotobuf-c"
		],[])

	if test -n "$PROTOBUF_CPPFLAGS"; then
		CPPFLAGS="$CPPFLAGS $PROTOBUF_CPPFLAGS"
	fi

	if test -n "$PROTOBUF_LDFLAGS"; then
		LDFLAGS="$LDFLAGS $PROTOBUF_LDFLAGS"
	fi

	dnl confirm that discovered/configured include path works
	AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [],
		AC_MSG_ERROR([unable to find protobuf-c/protobuf-c.h using CPPFLAGS. You can disable MVT and Geobuf support using --without-protobuf])
		HAVE_PROTOBUF=no
	)

	dnl confirm that discovered/configured library path works
	AC_CHECK_LIB([protobuf-c], [protobuf_c_message_init],[
			if test "x$PROTOBUF_LDFLAGS" = "x"; then
				PROTOBUF_LDFLAGS="-lprotobuf-c"
			fi
		],
		AC_MSG_ERROR([unable to link protobuf-c using $LDFLAGS. You can disable MVT and Geobuf support using --without-protobuf])
		HAVE_PROTOBUF=no
	)

	AC_CHECK_LIB([protobuf-c], [protobuf_c_version],
		AC_DEFINE([HAVE_PROTOBUF_C_VERSION], [1], [Define to 1 if protobuf_c_version() is present]),
		[])

	AC_MSG_CHECKING([protobuf-c version])
	dnl Return the protobuf-c version number if not detected by pkg-config
	if test "x$PROTOC_VERSION" = "x"; then
		AC_PROTOBUFC_VERSION([PROTOC_VERSION])
	fi
        if test ! "$PROTOC_VERSION" -ge 1001000; then
                AC_MSG_ERROR("Old protobuf-c release found but 1.1.0 is required. You can disable MVT and Geobuf support using --without-protobuf")
        fi
	AC_MSG_RESULT([$PROTOC_VERSION])

	CPPFLAGS="$CPPFLAGS_SAVE"
	LDFLAGS="$LDFLAGS_SAVE"
        LIBS="$LIBS_SAVE"

	dnl confirm that protobuf compiler is available
	AC_PATH_PROG(PROTOCC, protoc-c)
	if test -z "$PROTOCC"; then
		AC_MSG_ERROR([Cannot find protoc-c protobuf compiler on the PATH: $PATH. You can disable MVT and Geobuf support using --without-protobuf])
		HAVE_PROTOBUF=no
	fi

	dnl all tests passed! turn on compile-time defines
        if test "$HAVE_PROTOBUF" = "yes"; then
		AC_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
		AC_DEFINE_UNQUOTED([LIBPROTOBUF_VERSION], [$PROTOC_VERSION], [Numeric version number for libprotobuf-c])
	else
                AC_MSG_ERROR("Missing protobuf-c support. You can disable MVT and Geobuf support using --without-protobuf")
        fi

        AC_SUBST([HAVE_PROTOBUF])
        AC_SUBST([PROTOC_VERSION])
        AC_SUBST([PROTOBUF_CPPFLAGS])
        AC_SUBST([PROTOBUF_LDFLAGS])

fi


dnl ===========================================================================
dnl Detect GTK+2.0 for GUI
dnl ===========================================================================

AC_ARG_WITH([gui],
	[AS_HELP_STRING([--with-gui], [compile the data import GUI (requires GTK+2.0)])],
	[GUI="$withval"], [GUI="no"])

if test "x$GUI" = "xyes"; then
	AC_MSG_RESULT([GUI: Build requested, checking for dependencies (GTK+2.0)])
	dnl Try to find the GTK libs with pkgconfig
	AM_PATH_GTK_2_0([2.8.0], [GTK_BUILD="gui"], [GTK_BUILD=""])

	dnl Add -mwindows to MinGW GUI build
	case $host in
		*mingw32*)
			GTK_WIN32_FLAGS=-mwindows
			GTK_WIN32_RES=shp2pgsql-gui.res
                        GTK_WIN32_BUILD=gui-win32
			;;
	esac
fi



AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
AC_SUBST([GTK_WIN32_FLAGS])
AC_SUBST([GTK_WIN32_RES])
AC_SUBST([GTK_BUILD])
AC_SUBST([IGE_MAC_CFLAGS])
AC_SUBST([IGE_MAC_LIBS])


dnl ===========================================================================
dnl Allow the developer to turn on expensive checks and debugging flags
dnl with --enable-debug
dnl

AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debugging flags]),
	[ENABLE_DEBUG=1], [ENABLE_DEBUG=0])

AC_ARG_ENABLE([assert], AS_HELP_STRING([--enable-assert], [Enable assertions and expensive correctness checks]),
	[ENABLE_ASSERT=1], [ENABLE_ASSERT=0])

dnl Allow the developer to turn on link time optimization is supported by compiler
dnl with --enable-lto (for non-debug build)
AC_ARG_ENABLE(
    [lto],
    AS_HELP_STRING([--enable-lto], [enable link time optimization if supported by compiler (for non-debug build)]),
    [case "${enableval}" in
        yes) ENABLE_LTO=1 ;;
        no)  ENABLE_LTO=0 ;;
        *) AC_MSG_ERROR([bad value "${enableval}" for --enable-lto]) ;;
    esac],
    [ENABLE_LTO=0])

dnl Add -Wall to CFLAGS
_LT_COMPILER_OPTION([if $compiler supports -Wall], [_cv_wall], [-Wall], [], [CFLAGS="$CFLAGS -Wall"], [])

dnl We only turn on link-time optimizations for full production builds
dnl because they make debugger use problematic
if test $ENABLE_DEBUG -eq 1; then
  CFLAGS="$CFLAGS -g"
else
  CFLAGS="$CFLAGS -O2"
  if test $ENABLE_LTO -eq 1; then
    _LT_COMPILER_OPTION([if $compiler supports -flto],[_cv_flto],[-flto],[],[CFLAGS="$CFLAGS -flto"],[])
    _LT_LINKER_OPTION([if $compiler supports -flto],[_cv_flto],[[-flto]],[LDFLAGS="$LDFLAGS -flto"])
  fi
fi

dnl If asserts are not requested, we need to disable them
dnl and other safety checks with NDEBUG
if test $ENABLE_ASSERT -eq 0; then
  CPPFLAGS="-DNDEBUG $CPPFLAGS"
fi

AC_DEFINE([POSTGIS_DEBUG_LEVEL], [0], [Define debug level. Default 0])

dnl ===========================================================================
dnl Allow the developer to disable the automatic updates of postgis_revision.h
dnl with --without-phony-revision
dnl
AC_ARG_WITH([phony-revision], AS_HELP_STRING([--without-phony-revision], [Disable automatic updates of postgis_revision.h]), [], [])
if test "x$with_phony_revision" != "xno"; then
    PHONY_REVISION="yes"
else
    PHONY_REVISION="no"
fi
AC_MSG_RESULT([phony-revision: $with_phony_revision])
AC_SUBST([PHONY_REVISION])

dnl ===========================================================================
dnl Define version macros
dnl

POSTGIS_VERSION="$POSTGIS_MAJOR_VERSION.$POSTGIS_MINOR_VERSION USE_GEOS=1 USE_PROJ=1 USE_STATS=1"
if test "$HAVE_LIBXML2" = "1"; then
	POSTGIS_VERSION="$POSTGIS_VERSION USE_LIBXML2=1"
fi

POSTGIS_LIB_VERSION="$POSTGIS_MAJOR_VERSION.$POSTGIS_MINOR_VERSION.$POSTGIS_MICRO_VERSION"
POSTGIS_BUILD_DATE=`date ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH} -u "+%Y-%m-%d %H:%M:%S"`
POSTGIS_SCRIPTS_VERSION="$POSTGIS_LIB_VERSION"

AC_DEFINE_UNQUOTED([POSTGIS_VERSION], ["$POSTGIS_VERSION"], [PostGIS version])
AC_DEFINE_UNQUOTED([POSTGIS_LIB_VERSION], ["$POSTGIS_LIB_VERSION"], [PostGIS library version])
AC_DEFINE_UNQUOTED([POSTGIS_BUILD_DATE], ["$POSTGIS_BUILD_DATE"], [PostGIS build date])
AC_DEFINE_UNQUOTED([POSTGIS_SCRIPTS_VERSION], ["$POSTGIS_SCRIPTS_VERSION"], [PostGIS scripts version])

AC_SUBST([POSTGIS_VERSION])
AC_SUBST([POSTGIS_LIB_VERSION])
AC_SUBST([POSTGIS_BUILD_DATE])
AC_SUBST([POSTGIS_SCRIPTS_VERSION])


dnl ====================================
dnl address standardizer stuff
dnl ====================================
AC_ARG_WITH([address-standardizer],
    [AS_HELP_STRING([--without-address-standardizer],
                    [Disable the address_standardizer extension])],
    [], [])

HAVE_PCRE1=no
HAVE_PCRE2=no
PCRE_SUPPORT="not found"
ADDRESS_STANDARDIZER=""

if test "x$with_address_standardizer" != "xno"; then
    dnl ===========================================================================
    dnl Detect the version of PCRE installed
    dnl ===========================================================================


    AC_ARG_WITH([pcredir],
        [AS_HELP_STRING([--with-pcredir=PATH], [specify the PCRE installation directory])],
        [PCREDIR="$withval"], [PCREDIR=""])

    if test ! "x$PCREDIR" = "x"; then
        dnl Make sure that the directory exists
        if test "x$PCREDIR" = "xyes"; then
            AC_MSG_ERROR([you must specify a parameter to --with-pcredir, e.g. --with-pcredir=/path/to])
        else
            if test -d "$PCREDIR"; then
                AC_MSG_CHECKING([for PCRE in $PCREDIR...])

                AC_CHECK_FILE("$PCREDIR/include/pcre2.h",
                    [
                        PCRE_CPPFLAGS="-I$PCREDIR/include"
                        PCRE_LDFLAGS="-L$PCREDIR/lib -lpcre2-8"
                        HAVE_PCRE2=yes
                        ADDRESS_STANDARDIZER="address_standardizer"
                        AC_MSG_RESULT([found pcre2.h])
                    ],
                    [
                        AC_CHECK_FILE("$PCREDIR/include/pcre.h",
                        [
	                          PCRE_CPPFLAGS="-I$PCREDIR/include"
	                          PCRE_LDFLAGS="-L$PCREDIR/lib -lpcre"
	                          HAVE_PCRE1=yes
	                          ADDRESS_STANDARDIZER="address_standardizer"
                            AC_MSG_RESULT([found pcre.h])
                        ],
                        [
                            AC_MSG_RESULT([no])
                            AC_MSG_ERROR(["Could not find PCRE header in $PCREDIR/include"])
                        ])
                    ])
            else
                AC_MSG_ERROR([the --with-pcredir directory "$PCREDIR" cannot be found])
            fi
        fi
    elif test ! -z "$PKG_CONFIG"; then
        PKG_CHECK_MODULES([PCRE2], [libpcre2-8], [
            PCRE_CPPFLAGS="$PCRE2_CFLAGS"
            PCRE_LDFLAGS="$PCRE2_LIBS"
            ADDRESS_STANDARDIZER="address_standardizer"
            HAVE_PCRE2=yes
        ],[
            PKG_CHECK_MODULES([PCRE], [libpcre], [
                PCRE_CPPFLAGS="$PCRE_CFLAGS"
                PCRE_LDFLAGS="$PCRE_LIBS"
                ADDRESS_STANDARDIZER="address_standardizer"
                HAVE_PCRE1=yes
            ],[
                ADDRESS_STANDARDIZER=""
            ])
        ])
    fi

    if test "x$HAVE_PCRE2" = "xyes"; then
        PCRE_SUPPORT="Version 2"
        PCRE_VERSION=2
    elif test "x$HAVE_PCRE1" = "xyes"; then
        PCRE_SUPPORT="Version 1"
        PCRE_VERSION=1
    else
        ADDRESS_STANDARDIZER=""
        PCRE_SUPPORT="not found"
        PCRE_VERSION=0
        AC_MSG_RESULT([ADDRESS_STANDARDIZER support: disabled])
    fi

    AC_SUBST([PCRE_CPPFLAGS])
    AC_SUBST([PCRE_LDFLAGS])
    AC_SUBST([PCRE_LDFLAGS])
    AC_SUBST([PCRE_VERSION])
    ADDRESS_STANDARDIZER_MAKEFILE_LIST=extensions/address_standardizer/Makefile


else
    ADDRESS_STANDARDIZER=""
    AC_MSG_RESULT([ADDRESS_STANDARDIZER support: disabled])
    ADDRESS_STANDARDIZER_MAKEFILE_LIST=""
fi

AC_SUBST([ADDRESS_STANDARDIZER])

CPPFLAGS="$PGSQL_CPPFLAGS $GEOS_CPPFLAGS $PROJ_CPPFLAGS $PROTOBUF_CPPFLAGS $XML2_CPPFLAGS $SFCGAL_CPPFLAGS $JSON_CPPFLAGS $PCRE_CPPFLAGS $CPPFLAGS"
dnl AC_MSG_RESULT([CPPFLAGS: $CPPFLAGS])

SHLIB_LINK="$PGSQL_LDFLAGS $GEOS_LDFLAGS $PROJ_LDFLAGS $JSON_LDFLAGS $PROTOBUF_LDFLAGS $XML2_LDFLAGS $SFCGAL_LDFLAGS $EXCLUDELIBS_LDFLAGS $LDFLAGS"
AC_SUBST([SHLIB_LINK])
dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK])

dnl ====================================
dnl topology stuff
dnl ====================================
AC_ARG_WITH([topology],
    [AS_HELP_STRING([--without-topology],
                    [Disable the topology extension])],
    [], [])

if test "x$with_topology" != "xno"; then

    TOPOLOGY="topology"
    AC_MSG_RESULT([TOPOLOGY: Topology support requested])
else
    AC_MSG_RESULT([TOPOLOGY: Topology support disabled])
fi

AC_SUBST([TOPOLOGY])

dnl ====================================
dnl interrupt tests
dnl ====================================
INTERRUPTTESTS="yes"
AC_ARG_WITH([interrupt-tests],
    [AS_HELP_STRING([--without-interrupt-tests],
                    [Disable the interrupt tests])],
    [INTERRUPTTESTS="yes"], [INTERRUPTTEST="no"])

if test "x$with_interrupt_tests" = "xno"; then
    INTERRUPTTESTS="no"
fi

AC_SUBST([INTERRUPTTESTS])



dnl ===========================================================================
dnl SRID stuff
dnl ===========================================================================

SRID_MAX=999999
SRID_USR_MAX=998999
AC_SUBST([SRID_MAX])
AC_SUBST([SRID_USR_MAX])


dnl ====================================
dnl raster stuff
dnl ====================================
AC_ARG_WITH(
	[raster],
	AS_HELP_STRING([--without-raster], [Disable the raster extension]),
	[], [])

if test "x$with_raster" != "xno"; then
	RASTER="raster"
	AC_MSG_RESULT([RASTER: Raster support requested])

	AC_CONFIG_HEADERS([raster/raster_config.h])

	dnl ===========================================================================
	dnl Allow output of double truncation warnings with --with-raster-dblwarning
	dnl ===========================================================================
	AC_ARG_WITH(
		[raster-dblwarning],
		AS_HELP_STRING([--with-raster-dblwarning], [output double truncation warnings.  Only used with --with-raster]),
		[POSTGIS_RASTER_WARN_ON_TRUNCATION=1],
		[POSTGIS_RASTER_WARN_ON_TRUNCATION=0])

	AC_DEFINE_UNQUOTED(
		[POSTGIS_RASTER_WARN_ON_TRUNCATION],
		[$POSTGIS_RASTER_WARN_ON_TRUNCATION],
		[Define to 1 if a warning is outputted every time a double is truncated])

	dnl ========================================================================
	dnl Determine GDAL Support
	dnl
	dnl TODO: Now, --with-gdalconfig can have only 1 value: path to gdal-config. It
	dnl could be useful to allow path to GDAL tree, because the cflags and the
	dnl libs can be obtained from GDAL tree too, apart from gdal-config
	dnl How to get cflags and libs from GDAL tree?
	dnl
	dnl LIBGDAL_CFLAGS="-I$with_gdal/port -I$with_gdal/ogr -I$with_gdal/alg -I$with_gdal/gcore -I$with_gdal/frmts "
	dnl LIBGDAL_LDFLAGS="-L${with_gdal}/.libs -lgdal -L${with_gdal}/ -lgdal"
	dnl ========================================================================
	dnl not used right now
	USE_GDAL_SOURCE_TREE="no"
	LIBGDAL_CFLAGS=""
	LIBGDAL_LDFLAGS=""
	LIBGDAL_DEPLIBS_LDFLAGS=""

	dnl GDAL version constants, update here
	GDAL_MIN_VERSION=2.0.0
	GDAL_MIN_VERSION_NUMBER=180 dnl TODO: Use GDAL version calculation MAJOR*1000+MINOR*100+REV*10+BUILD

	AC_ARG_WITH(
		[gdalconfig],
		AS_HELP_STRING([--with-gdalconfig=@<:@ARG@:>@],[specify location of gdal-config (ARG=path).  Only used with --with-raster]),
		[
			if test -f "$withval"; then
				GDAL_CONFIG="$withval"
			else
				AC_MSG_ERROR([the user-specified gdal-config file $withval does not exist])
			fi
		],
		[AC_PATH_PROG([GDAL_CONFIG], [gdal-config], [])]
	)

	AC_MSG_CHECKING([GDAL version])

	if test -x "$GDAL_CONFIG"; then
		dnl Extract the version information from gdal-config
		dnl Note: we extract the major & minor separately, ensure they are numeric,
		dnl and then combine to give the final version.
		dnl This is to guard against user error...
		GDAL_MAJOR_VERSION=`$GDAL_CONFIG --version | cut -d. -f1 | sed 's/[[^0-9]]//g'`
		GDAL_MINOR_VERSION=`$GDAL_CONFIG --version | cut -d. -f2 | sed 's/[[^0-9]]//g'`
		GDAL_PATCH_VERSION=`$GDAL_CONFIG --version | cut -d. -f3 | sed 's/[[^0-9]]//g'`
		GDAL_FULL_VERSION=`$GDAL_CONFIG --version`
		POSTGIS_GDAL_VERSION="$GDAL_MAJOR_VERSION$GDAL_MINOR_VERSION"
		GDAL_VERSION_NUMBER="$GDAL_MAJOR_VERSION$GDAL_MINOR_VERSION$GDAL_PATCH_VERSION"

		AC_MSG_RESULT([$GDAL_FULL_VERSION])

		dnl Ensure we are using minimum required version of GDAL
		if test ! "$GDAL_VERSION_NUMBER" -ge "$GDAL_MIN_VERSION_NUMBER" ; then
			AC_MSG_ERROR([PostGIS raster requires GDAL >= $GDAL_MIN_VERSION. Use --without-raster to build without raster support.])
		fi

		AC_DEFINE_UNQUOTED([POSTGIS_GDAL_VERSION], [$POSTGIS_GDAL_VERSION], [GDAL library version])
		AC_SUBST([POSTGIS_GDAL_VERSION])

		dnl Check that OGR is enabled
		AC_MSG_CHECKING([for OGR enabled])
		OGR_ENABLED=`$GDAL_CONFIG --ogr-enabled`
		if test "x$OGR_ENABLED" != "xyes"; then
			AC_MSG_RESULT([$OGR_ENABLED])
			AC_MSG_ERROR([PostGIS raster requires OGR to be enabled in GDAL. Use --without-raster to build without raster support.])
		fi
		AC_MSG_RESULT([$OGR_ENABLED])

		dnl Extract the linker and include flags
		LIBGDAL_LDFLAGS=`$GDAL_CONFIG --libs`
		dnl LIBGDAL_DEPLIBS_LDFLAGS=`$GDAL_CONFIG --dep-libs`
		LIBGDAL_CFLAGS=`$GDAL_CONFIG --cflags`

		CPPFLAGS_SAVE="$CPPFLAGS"
		CPPFLAGS="$LIBGDAL_CFLAGS"
		CFLAGS_SAVE="$CFLAGS"
		CC_SAVE="$CC"

		if test "x$PG_CONFIG" != "xno"; then
			CFLAGS=`"$PG_CONFIG" --cflags`
			CC=`"$PG_CONFIG" --cc`
		fi

		LIBS_SAVE="$LIBS"
		LIBS="$LIBGDAL_LDFLAGS"

		dnl Check headers file
		AC_CHECK_HEADERS(
			[gdal.h ogr_api.h cpl_conv.h],
			[],
			[AC_MSG_ERROR([could not find GDAL headers])])

		dnl Ensure we can link against gdal
		AC_SEARCH_LIBS([GDALAllRegister], [gdal], [], [AC_MSG_ERROR([could not find GDAL])], [])

		LIBS="$LIBGDAL_LDFLAGS"

		dnl Ensure we can link against ogr
		AC_SEARCH_LIBS([OGRRegisterAll], [gdal], [], [AC_MSG_ERROR([could not find OGR])], [])

		LIBS="$LIBGDAL_LDFLAGS"
		CPPFLAGS="$CPPFLAGS_SAVE"
		CFLAGS="$CFLAGS_SAVE"
		CC="$CC_SAVE"
		LIBS="$LIBS_SAVE"

		AC_SUBST([LIBGDAL_CFLAGS])
		AC_SUBST([LIBGDAL_LDFLAGS])
		AC_SUBST([LIBGDAL_DEPLIBS_LDFLAGS])

	else
		AC_MSG_RESULT([not found])
		AC_MSG_ERROR([gdal-config not found. Use --without-raster or try --with-gdalconfig=<path to gdal-config>])
	fi

	dnl Define raster objects, for makefiles
	RT_CORE_LIB=corelib
	RT_LOADER=rtloader
	if test "x$PG_CONFIG" != "xno"; then
		RT_PG_LIB=pglib
		RT_POSTGIS_SQL=rtpostgis.sql
	fi

	AC_SUBST([RASTER])
	AC_SUBST([RT_CORE_LIB])
	AC_SUBST([RT_PG_LIB])
	AC_SUBST([RT_LOADER])
	AC_SUBST([RT_POSTGIS_SQL])

	RT_MAKEFILE_LIST="
		extensions/postgis_raster/Makefile \
		raster/Makefile \
		raster/rt_core/Makefile \
		raster/rt_pg/Makefile \
		raster/loader/Makefile \
		raster/test/Makefile \
		raster/test/cunit/Makefile \
		raster/test/regress/Makefile \
		raster/scripts/Makefile \
		raster/scripts/python/Makefile"

else
	AC_MSG_RESULT([RASTER: Raster support disabled])

	dnl We still generate raster/rt_pg makefile to
	dnl use for upgrading from pre-split-raster versions
	RT_MAKEFILE_LIST="raster/Makefile raster/rt_pg/Makefile"
fi


dnl ===========================================================================
dnl Deps folder
dnl ===========================================================================

DEPS_MAKEFILE_LIST="
    deps/Makefile"


dnl ===========================================================================
dnl Wagyu
dnl ===========================================================================

dnl Wagyu will only be necessary if protobuf is present to build MVTs

if test "x$HAVE_PROTOBUF" = "xyes"; then
    DEPS_SUBDIR="deps"
    AC_SUBST([DEPS_SUBDIR])

    WAGYU_LIB=libwagyu.la
    AC_SUBST([WAGYU_LIB])

    dnl ============================================================
    dnl We force  to use the same compiler as Postgresql
    dnl ============================================================
    CXX_SAVE="$CXX"
    CC_SAVE="$CC"
    CFLAGS_SAVE="$CFLAGS"
    CXXFLAGS_SAVE="$CXXFLAGS"
    CPPFLAGS_SAVE="$CPPFLAGS"
    LDFLAGS_SAVE="$LDFLAGS"
    LIBS_SAVE="$LIBS"

    WAGYU_CXX=`"$PG_CONFIG" --cc`
    CPPFLAGS="-x c++"
    CFLAGS=""
    LDFLAGS=""
    LIBS=""
    CXX="$WAGYU_CXX"
    AC_PROG_CXX
    AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
    WAGYU_CXX="$CXX -x c++"

    dnl ============================================================
    dnl Check if we can declare the c++ stdlib
    dnl ============================================================
    CC="$WAGYU_CXX"

    AC_CHECK_LIB(c++, main, [HAVE_CPP=yes], [HAVE_CPP=no])
    AC_CHECK_LIB(stdc++, main, [HAVE_STDCPP=yes], [HAVE_STDCPP=no])

    if test "x$HAVE_CPP" = "xyes"; then
        WAGYU_LDFLAGS="-lc++"
    elif test "x$HAVE_STDCPP" = "xyes"; then
        WAGYU_LDFLAGS="-lstdc++"
    else
        AC_MSG_WARN("Could not find a C++ standard library")
        WAGYU_LDFLAGS=""
    fi

    CXX="$CXX_SAVE"
    CC="$CC_SAVE"
    CFLAGS="$CFLAGS_SAVE"
    CXXFLAGS="$CXXFLAGS_SAVE"
    CPPFLAGS="$CPPFLAGS_SAVE"
    LDFLAGS="$LDFLAGS_SAVE"
    LIBS="$LIBS_SAVE"

    HAVE_WAGYU=yes
    AC_DEFINE([HAVE_WAGYU], [1], [Define to 1 if wagyu is being built])
    AC_SUBST([HAVE_WAGYU])
    AC_SUBST([WAGYU_CXX])
    AC_SUBST([WAGYU_LDFLAGS])

    DEPS_MAKEFILE_LIST="$DEPS_MAKEFILE_LIST
            deps/wagyu/Makefile"
fi

dnl ===========================================================================
dnl Ryu
dnl ===========================================================================
RYU_LIB=libryu.la
AC_SUBST([RYU_LIB])

DEPS_MAKEFILE_LIST="$DEPS_MAKEFILE_LIST
        deps/ryu/Makefile"


dnl ===========================================================================
dnl FlatGeobuf
dnl ===========================================================================

FLATGEOBUF_LIB=libflatgeobuf.la
AC_SUBST([FLATGEOBUF_LIB])

dnl ============================================================
dnl We force  to use the same compiler as Postgresql
dnl ============================================================
CXX_SAVE="$CXX"
CC_SAVE="$CC"
CFLAGS_SAVE="$CFLAGS"
CXXFLAGS_SAVE="$CXXFLAGS"
CPPFLAGS_SAVE="$CPPFLAGS"
LDFLAGS_SAVE="$LDFLAGS"
LIBS_SAVE="$LIBS"

FLATGEOBUF_CXX=`"$PG_CONFIG" --cc`
CPPFLAGS="-x c++"
CFLAGS=""
LDFLAGS=""
LIBS=""
CXX="$FLATGEOBUF_CXX"
AC_PROG_CXX
AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
FLATGEOBUF_CXX="$CXX -x c++"

dnl ============================================================
dnl Check if we can declare the c++ stdlib
dnl ============================================================
CC="$FLATGEOBUF_CXX"

AC_CHECK_LIB(c++, main, [HAVE_CPP=yes], [HAVE_CPP=no])
AC_CHECK_LIB(stdc++, main, [HAVE_STDCPP=yes], [HAVE_STDCPP=no])

if test "x$HAVE_CPP" = "xyes"; then
	FLATGEOBUF_LDFLAGS="-lc++"
elif test "x$HAVE_STDCPP" = "xyes"; then
	FLATGEOBUF_LDFLAGS="-lstdc++"
else
	AC_MSG_WARN("Could not find a C++ standard library")
	FLATGEOBUF_LDFLAGS=""
fi

CXX="$CXX_SAVE"
CC="$CC_SAVE"
CFLAGS="$CFLAGS_SAVE"
CXXFLAGS="$CXXFLAGS_SAVE"
CPPFLAGS="$CPPFLAGS_SAVE"
LDFLAGS="$LDFLAGS_SAVE"
LIBS="$LIBS_SAVE"

HAVE_FLATGEOBUF=yes
AC_DEFINE([HAVE_FLATGEOBUF], [1], [Define to 1 if FlatGeobuf is being built])
AC_SUBST([HAVE_FLATGEOBUF])
AC_SUBST([FLATGEOBUF_CXX])
AC_SUBST([FLATGEOBUF_LDFLAGS])

DEPS_MAKEFILE_LIST="$DEPS_MAKEFILE_LIST
		deps/flatgeobuf/Makefile"



dnl ===========================================================================
dnl See if we have the requirements for building the extensions, namely
dnl the pg_config support
dnl ===========================================================================

EXTENSIONS=""
if test "x$PG_CONFIG" != "xno"; then
    AC_MSG_RESULT([enabling PostgreSQL extension support...])
    EXTENSIONS=extensions
    AC_SUBST([EXTENSIONS])
fi

INSTALL_EXTENSION_UPGRADES=yes
AC_ARG_ENABLE([extension-upgrades-install], AS_HELP_STRING([--disable-extension-upgrades-install], [Disable automatic install of extension upgrade scripts]),
	[INSTALL_EXTENSION_UPGRADES=$enableval])
AC_SUBST([INSTALL_EXTENSION_UPGRADES])

dnl ===========================================================================
dnl Output the relevant files
dnl ===========================================================================

TRANSLATIONS_MAKEFILE_LIST=`grep 'translations = ' ${srcdir}/doc/Makefile.in \
  | cut -d= -f2 \
  | tr ' ' '\n' \
  | grep -v '^ *$' \
  | sed 's|^|doc/po/|;s|$|/Makefile|'
`

dnl echo "TRANSLATIONS_MAKEFILE_LIST: ${TRANSLATIONS_MAKEFILE_LIST}"

AC_CONFIG_FILES([GNUmakefile
   extensions/Makefile
   extensions/postgis/Makefile
   extensions/postgis_topology/Makefile
   extensions/postgis_tiger_geocoder/Makefile
   $ADDRESS_STANDARDIZER_MAKEFILE_LIST
   liblwgeom/Makefile
   liblwgeom/cunit/Makefile
   liblwgeom/liblwgeom.h
   libpgcommon/Makefile
   libpgcommon/cunit/Makefile
   postgis/Makefile
   postgis/sqldefines.h
   sfcgal/Makefile
   $SFCGAL_MAKEFILE_LIST
   loader/Makefile
   loader/cunit/Makefile
   topology/Makefile
   topology/test/Makefile
   regress/Makefile
   regress/core/Makefile
   regress/core/tests.mk
   regress/dumper/Makefile
   regress/loader/Makefile
   doc/Makefile
   doc/Makefile.comments
   $TRANSLATIONS_MAKEFILE_LIST
   doc/html/images/Makefile
   utils/Makefile
   $RT_MAKEFILE_LIST
   $DEPS_MAKEFILE_LIST])

AC_OUTPUT

dnl ===========================================================================
dnl Display the configuration status information
dnl ===========================================================================

AC_MSG_RESULT()
AC_MSG_RESULT([  PostGIS is now configured for ${host}])
AC_MSG_RESULT()
AC_MSG_RESULT([ -------------- Compiler Info ------------- ])
AC_MSG_RESULT([  C compiler:           ${CC} ${CFLAGS}])
if test "x$HAVE_WAGYU" = "xyes"; then
    AC_MSG_RESULT([  C++ compiler (Wagyu): ${WAGYU_CXX} ${CXXFLAGS}])
fi
if test "x$HAVE_FLATGEOBUF" = "xyes"; then
    AC_MSG_RESULT([  C++ compiler (FlatGeobuf): ${FLATGEOBUF_CXX} ${CXXFLAGS}])
fi
AC_MSG_RESULT([  CPPFLAGS:             $CPPFLAGS])
AC_MSG_RESULT([  LDFLAGS:              $LDFLAGS])
AC_MSG_RESULT([  SQL preprocessor:     ${SQLPP}])
AC_MSG_RESULT([  Archiver:             $AR $AR_FLAGS])
AC_MSG_RESULT()
AC_MSG_RESULT([ -------------- Additional Info ------------- ])
if test "x$LIBINCLUDEMINORVERSION" = "xyes"; then
  AC_MSG_RESULT([  POSTGIS lib file includes minor:   ENABLED])
fi
if test "x$INTERRUPTTESTS" = "xyes"; then
  AC_MSG_RESULT([  Interrupt Tests:   ENABLED])
else
  AC_MSG_RESULT([  Interrupt Tests:   DISABLED use: --with-interrupt-tests to enable])
fi

AC_MSG_RESULT()
AC_MSG_RESULT([ -------------- Dependencies -------------- ])
AC_MSG_RESULT([  GEOS config:          ${GEOS_CONFIG_SRC}])
AC_MSG_RESULT([  GEOS version:         ${GEOS_VERSION} (${POSTGIS_GEOS_VERSION})])
if test "x$RASTER" = "xraster"; then
    AC_MSG_RESULT([  GDAL config:          ${GDAL_CONFIG}])
    AC_MSG_RESULT([  GDAL version:         ${GDAL_FULL_VERSION}])
fi
if test "x$SFCGAL" = "xsfcgal"; then
    AC_MSG_RESULT([  SFCGAL config:        ${SFCGAL_CONFIG}])
    AC_MSG_RESULT([  SFCGAL version:       ${SFCGAL_VERSION}])
fi
if test "x$SUPPORT_POSTGRESQL" = "xyes"; then
  AC_MSG_RESULT([  PostgreSQL config:    ${PG_CONFIG}])
  AC_MSG_RESULT([  PostgreSQL version:   ${PGSQL_FULL_VERSION}])
else
  AC_MSG_RESULT([  PostgreSQL support:   DISABLED])
fi
AC_MSG_RESULT([  PROJ version:         ${PROJ_VERSION} (${POSTGIS_PROJ_VERSION})])
AC_MSG_RESULT([  Libxml2 config:       ${XML2CONFIG}])
AC_MSG_RESULT([  Libxml2 version:      ${POSTGIS_LIBXML2_VERSION}])
AC_MSG_RESULT([  JSON-C support:       ${HAVE_JSON}])

AC_MSG_RESULT([  protobuf support:     ${HAVE_PROTOBUF}])
if test "x$HAVE_PROTOBUF" = "xyes"; then
  AC_MSG_RESULT([  protobuf-c version:   ${PROTOC_VERSION}])
fi

AC_MSG_RESULT([  PCRE support:         ${PCRE_SUPPORT}])
AC_MSG_RESULT([  Perl:                 ${PERL}])

AC_MSG_RESULT()
AC_MSG_RESULT([ --------------- Extensions --------------- ])
if test "x$EXTENSIONS" = "xextensions"; then
    if test "x$INSTALL_EXTENSION_UPGRADES" = "xyes"; then
        AC_MSG_RESULT([  PostgreSQL EXTENSION support:       enabled])
    else
        AC_MSG_RESULT([  PostgreSQL EXTENSION support:       enabled (manual install of upgrade paths)])
    fi
else
    AC_MSG_RESULT([  PostgreSQL EXTENSION support:       disabled])
fi
if test "x$RASTER" = "xraster"; then
    AC_MSG_RESULT([  PostGIS Raster:                     enabled])
else
    AC_MSG_RESULT([  PostGIS Raster:                     disabled])

fi
if test "x$TOPOLOGY" = "xtopology"; then
    AC_MSG_RESULT([  PostGIS Topology:                   enabled])
else
    AC_MSG_RESULT([  PostGIS Topology:                   disabled])
fi
if test "x$SFCGAL" = "xsfcgal"; then
    AC_MSG_RESULT([  SFCGAL support:                     enabled])
else
    AC_MSG_RESULT([  SFCGAL support:                     disabled])
fi

if test "x$ADDRESS_STANDARDIZER" = "xaddress_standardizer"; then
    AC_MSG_RESULT([  Address Standardizer support:       enabled])
else
    AC_MSG_RESULT([  Address Standardizer support:       disabled])
fi

AC_MSG_RESULT()
AC_MSG_RESULT([ -------- Documentation Generation -------- ])
AC_MSG_RESULT([  xsltproc:             ${XSLTPROC}])
AC_MSG_RESULT([  docbook xsl base:     ${XSLBASE}])
AC_MSG_RESULT([  dblatex:              ${DBLATEX}])
AC_MSG_RESULT([  convert:              ${CONVERT}])
AC_MSG_RESULT()

if test "$POSTGIS_GEOS_VERSION" -lt 31200; then
AC_MSG_WARN([ --------- GEOS VERSION WARNING ------------ ])
AC_MSG_WARN([  You are building against GEOS ${GEOS_VERSION}.])
AC_MSG_WARN([])
AC_MSG_WARN([  To take advantage of _all_ the features of ])
AC_MSG_WARN([  PostGIS, GEOS 3.12.0 or higher is required.])
AC_MSG_WARN([])
AC_MSG_WARN([  You can download the latest versions from ])
AC_MSG_WARN([  http://geos.osgeo.org/ ])
AC_MSG_WARN()
fi

if test ! -z "$PKG_CONFIG"; then
    if test ! "x$PROJDIR" = "x"; then
        AC_MSG_WARN()
        AC_MSG_WARN([ | You are building using --with-projdir. This option isn't standard and    |])
        AC_MSG_WARN([ | might be incompatible with future releases of PROJ.                      |])
        AC_MSG_WARN([ | You can instead adjust the PKG_CONFIG_PATH environment variable if you   |])
        AC_MSG_WARN([ | installed software in a non-standard prefix.                             |])
        AC_MSG_WARN([ | Alternatively, you may set the environment variables PROJ_CFLAGS and     |])
        AC_MSG_WARN([ | PROJ_LIBS to avoid the need to call pkg-config.                          |])
    fi

    if test ! "x$JSONDIR" = "x"; then
        AC_MSG_WARN()
        AC_MSG_WARN([ | You are building using --with-jsondir. This option isn't standard and    |])
        AC_MSG_WARN([ | might be incompatible with future releases of json-c.                    |])
        AC_MSG_WARN([ | You can instead adjust the PKG_CONFIG_PATH environment variable if you   |])
        AC_MSG_WARN([ | installed software in a non-standard prefix.                             |])
        AC_MSG_WARN([ | Alternatively, you may set the environment variables JSONC_CFLAGS and    |])
        AC_MSG_WARN([ | JSONC_LIBS to avoid the need to call pkg-config.                         |])
    fi

    if test ! "x$PCREDIR" = "x"; then
        AC_MSG_WARN()
        AC_MSG_WARN([ | You are building using --with-pcredir. This option isn't standard and    |])
        AC_MSG_WARN([ | might be incompatible with future releases of libpcre.                   |])
        AC_MSG_WARN([ | You can instead adjust the PKG_CONFIG_PATH environment variable if you   |])
        AC_MSG_WARN([ | installed software in a non-standard prefix.                             |])
        AC_MSG_WARN([ | Alternatively, you may set the environment variables PCRE_CFLAGS and     |])
        AC_MSG_WARN([ | PCRE_LIBS to avoid the need to call pkg-config.                          |])
    fi
fi