configure.ac 52.6 KB
Newer Older
1 2 3
dnl **********************************************************************
dnl *
dnl * PostGIS - Spatial Types for PostgreSQL
4
dnl * http://postgis.net
5 6 7 8 9 10
dnl * Copyright 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 **********************************************************************
11 12 13

AC_INIT()
AC_CONFIG_HEADERS([postgis_config.h])
14
AC_CONFIG_MACRO_DIR([macros])
Sandro Santilli's avatar
Sandro Santilli committed
15
AC_CONFIG_AUX_DIR([build-aux])
16
AC_PROG_INSTALL
17

18

19 20 21
dnl Invoke libtool: we do this as it is the easiest way to find the PIC
dnl flags required to build liblwgeom
AC_PROG_LIBTOOL
Regina Obe's avatar
Regina Obe committed
22

23 24 25 26
dnl
dnl Compilers
dnl
AC_PROG_CC
27
AC_PROG_CPP
28
AC_PROG_GREP
29

30 31 32 33 34
dnl
dnl SQL Preprocessor
dnl
AC_PATH_PROG([CPPBIN], [cpp], [])
if test "x$CPPBIN" != "x"; then
35
  SQLPP="${CPPBIN} -traditional-cpp -w -P"
36 37 38 39 40
else
  AC_PATH_PROG([GPP], [gpp_], [])
  if test "x$GPP" != "x"; then
    SQLPP="${GPP} -C -s \'" dnl Use better string support
  else
41 42 43 44 45
    if test "x${CPP}" != "x"; then
      SQLPP="${CPP} -traditional-cpp"
    else
		  AC_MSG_ERROR([Required "cpp" command not found])
    fi
46 47 48 49
  fi
fi
AC_SUBST([SQLPP])

50 51 52 53 54
dnl
dnl Silence warning: ar: 'u' modifier ignored since 'D' is the default
dnl
AC_SUBST(AR_FLAGS, [cr])

55 56 57 58 59 60 61 62 63 64
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])

dnl
dnl For GCC enable additional warning flags -Wall and -Wmissing-prototypes (using macro included with libtool)
dnl
WARNFLAGS=""
65 66
AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -Wall], [_cv_wall], [-Wall], [], [WARNFLAGS="$WARNFLAGS -Wall"], [])
AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -Wmissing-prototypes], [_cv_misprot], [-Wmissing-prototypes], [], [WARNFLAGS="$WARNFLAGS -Wmissing-prototypes"], [])
67
AC_SUBST([WARNFLAGS])
Sandro Santilli's avatar
Sandro Santilli committed
68

69 70
dnl
dnl For some GCC versions and platforms, floating point issues need to be
71
dnl ironed out.
72 73 74 75
NUMERICFLAGS=""
AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -ffloat-store], [dummy_cv_ffloat_store], [-ffloat-store], [], [NUMERICFLAGS="$NUMERICFLAGS -ffloat-store"], [])
AC_SUBST([NUMERICFLAGS])

76 77 78 79 80
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=""
81
AC_LIBTOOL_LINKER_OPTION([if $compiler supports --exclude-libs], [_cv_exclude_libs], [[-Wl,--exclude-libs,ALL]], [EXCLUDELIBS_LDFLAGS="-Wl,--exclude-libs,ALL"])
82 83
AC_SUBST([EXCLUDELIBS_LDFLAGS])

84 85 86 87 88 89
dnl
dnl Define executable suffix for use with the loader Makefiles
dnl
EXESUFFIX="$ac_cv_exeext"
AC_SUBST([EXESUFFIX])

Sandro Santilli's avatar
Sandro Santilli committed
90
dnl
91
dnl Version Information imported from Version.config
Sandro Santilli's avatar
Sandro Santilli committed
92
dnl
93 94 95
POSTGIS_MAJOR_VERSION=`cat Version.config | grep ^POSTGIS_MAJOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
POSTGIS_MINOR_VERSION=`cat Version.config | grep ^POSTGIS_MINOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
POSTGIS_MICRO_VERSION=`cat Version.config | grep ^POSTGIS_MICRO_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
96

97 98 99 100 101 102 103
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])
Sandro Santilli's avatar
Sandro Santilli committed
104

105
dnl
106
dnl Liblwgeom version information imported from Version.config
107
dnl
108 109 110
LIBLWGEOM_CURRENT=`cat Version.config | grep ^LIBLWGEOM_IFACE_CUR | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
LIBLWGEOM_AGE=`cat Version.config | grep ^LIBLWGEOM_IFACE_AGE | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
LIBLWGEOM_REV=`cat Version.config | grep ^LIBLWGEOM_IFACE_REV | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
111 112 113 114 115
AC_SUBST([LIBLWGEOM_CURRENT])
AC_SUBST([LIBLWGEOM_AGE])
AC_SUBST([LIBLWGEOM_REV])


116 117 118
dnl
dnl Search for flex/bison to build the parser
dnl
119

120 121 122 123 124
AC_PROG_LEX
AC_PROG_YACC
AC_SUBST([LEX])
AC_SUBST([YACC])

125 126 127 128 129
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])
130 131 132
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])

133 134 135 136

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

141
dnl
142 143 144
dnl First see if we have isfinite in basic header
dnl then check to see if it's a GNU extension
dnl
145 146
AC_CHECK_DECL(isfinite,
  [AC_DEFINE([HAVE_ISFINITE])],
147 148 149
  [],
  [#include <math.h>])

150 151 152
dnl Clear the cache
unset ac_cv_have_decl_isfinite

153 154 155
AC_CHECK_DECL(isfinite,
  AC_DEFINE([HAVE_GNU_ISFINITE]),
  [],
156
  [[
157
    #define _GNU_SOURCE
158 159
    #include <math.h>
  ]])
160

161 162 163 164
dnl
dnl MingW requires use of pwd -W to give proper Windows (not MingW) paths
dnl for in-place regression tests
dnl
165 166
case $host_os in
         *mingw*)
167
                 MINGWBUILD=1
168 169
                 ;;
         *)
170
                 MINGWBUILD=0
171 172
                 ;;
esac
173
AC_SUBST([MINGWBUILD])
174

Sandro Santilli's avatar
Sandro Santilli committed
175
AC_PATH_PROG([PERL], [perl], [])
176 177 178
if test "x$PERL" = "x"; then
        AC_MSG_ERROR([Perl was not found. Building PostGIS requires Perl.])
fi
Sandro Santilli's avatar
Sandro Santilli committed
179
AC_SUBST([PERL])
Nicklas Avén's avatar
Nicklas Avén committed
180

181 182 183
dnl ===========================================================================
dnl Find components needed to build documentation
dnl ===========================================================================
184 185 186 187
dnl
dnl Search for xsltproc which is required for building documentation
dnl

188 189
CAN_BUILD_COMMENTS=yes

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

196 197
CAN_BUILD_PDF=${CAN_BUILD_COMMENTS}

198 199 200 201 202 203
AC_PATH_PROG([IMAGEMAGICK], [convert], [])
if test "x$IMAGEMAGICK" = "x"; then
	AC_MSG_WARN([ImageMagick does not seem to be installed. Documentation cannot be built])
  CAN_BUILD_PDF=no
fi

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

210 211 212
AC_SUBST(CAN_BUILD_COMMENTS)
AC_SUBST(CAN_BUILD_PDF)

213 214 215 216 217 218
AC_PATH_PROG([XMLLINT], [xmllint], [])
if test "x$XMLLINT" = "x"; then
	AC_MSG_WARN([xmllint is not installed so documentation cannot be checked])
fi


219 220 221 222
dnl
dnl Allow the user to specify the location of the html/docbook.xsl stylesheet
dnl

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

227
XSLBASE_AUTO=""
228
if test "x$XSLBASE" = "x"; then
229
	dnl If the user did not specify a directory for the docbook
230
	dnl stylesheet, choose the first directory
231 232
	dnl that matches from the following list
	SEARCHPATH="
233
		/usr/share/sgml/docbook/xsl-stylesheets
234
		/usr/share/xml/docbook/stylesheet/docbook-xsl
235 236
		/usr/share/xml/docbook/stylesheet/nwalsh
		/usr/share/sgml/docbook/stylesheet/xsl/nwalsh
237 238 239
		/opt/local/share/xsl/docbook-xsl
		/usr/local/share/xsl/docbook-xsl
		/usr/share/xsl/docbook-xsl
240 241 242
		"
	for p in ${SEARCHPATH}; do
		if test -r "${p}"/html/docbook.xsl; then
243
			XSLBASE_AUTO="${p}"
244 245 246 247
			break
		fi
	done

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

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

265
dnl
266
dnl If XSLBASE has been set then at this point we know it must be
267
dnl valid and so we can just use it. If XSLBASE_AUTO has been set, and XSLBASE
268
dnl is empty then a valid stylesheet was found in XSLBASE_AUTO so we
269
dnl should use that. Otherwise just continue silently with a blank XSLBASE
270 271 272 273 274 275 276 277 278
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

279 280
AC_SUBST([XSLBASE])

281 282 283
dnl
dnl Let's see if we can find mathml2.dtd
dnl
284 285
AC_ARG_WITH([mathmldtd],
	[AS_HELP_STRING([--with-mathmldtd=PATH], [specify the dtd path for mathml2.dtd])],
286
	[MATHML2_DTD="$withval"], [MATHML2_DTD=""])
287
dnl TODO: get more paths to add here...
288 289 290 291 292 293 294 295 296 297 298 299
if test "x$MATHML2_DTD" = "x"; then
	MATHML2_DTD="http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"
	SEARCHPATH="
			/usr/share/xml/schema/w3c/mathml/dtd
			"
	for p in ${SEARCHPATH}; do
		if test -r "${p}"/mathml2.dtd; then
			MATHML2_DTD="${p}/mathml2.dtd"
			break
		fi
	done
fi
300 301
AC_SUBST([MATHML2_DTD])

302
dnl ===========================================================================
303 304
dnl Detect CUnit if it is installed (used for unit testing)
dnl
305 306 307
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
308 309
dnl information to be passed in if required.
dnl ===========================================================================
310

311 312
CUNIT_LDFLAGS=""
AC_CHECK_HEADER([CUnit/CUnit.h], [
313
	CUNIT_CPPFLAGS="$CPPFLAGS"
314
	AC_CHECK_LIB([cunit], [CU_initialize_registry], [CUNIT_LDFLAGS="$LDFLAGS -lcunit"], [AC_MSG_WARN([could not locate CUnit required for unit tests])])
315 316
	],
	[
317
	AC_MSG_WARN([could not locate CUnit required for unit tests])
318
	])
319

320
AC_SUBST([CUNIT_CPPFLAGS])
321
AC_SUBST([CUNIT_LDFLAGS])
322

323

324
dnl ===========================================================================
325
dnl Detect iconv if it is installed (used for shp2pgsql encoding conversion
326 327
dnl if available)
dnl ===========================================================================
328

329 330 331
ICONV_CFLAGS=""
ICONV_LDFLAGS=""

332 333
AC_ARG_WITH([libiconv],
	[AS_HELP_STRING([--with-libiconv=PATH], [specify a path to non-default libiconv installation])],
334 335 336 337 338 339 340 341 342 343 344 345 346
	[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

347 348 349 350
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
351
if test "x$HAVE_ICONV_H" = "x1"; then
352
	dnl libconv defines iconv_open to libiconv_open, so we'll check that directly
353
	AC_CHECK_LIB([iconv], [libiconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -liconv" HAVE_ICONV=1], [])
354
	if test "x$HAVE_ICONV" = "x"; then
355
	        dnl Check for iconv included as part of libc, using iconv_open
356
	        AC_CHECK_LIB([c], [iconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -lc" HAVE_ICONV=1], [])
357
		if test "x$HAVE_ICONV" = "x"; then
358
			dnl But it's possible this implementation of libiconv doesn't have a libiconv_* define
359
			AC_CHECK_LIB([iconv], [iconv_open], [ICONV_LDFLAGS="$ICONV_LDFLAGS -liconv" HAVE_ICONV=1], [])
360 361
			if test "x$HAVE_ICONV" = "x"; then
				dnl No iconv library was found; issue a warning to the console
362
				AC_MSG_ERROR([Could not find libiconv. Please install libiconv and libiconv-devel.])
363
			fi
364
		fi
365 366 367
	fi
else
	dnl No iconv header was found; issue a warning to the console
368
	AC_MSG_ERROR([Could not find iconv.h header. Please install libiconv and libiconv-devel.])
369 370
fi

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

373 374
LDFLAGS="$LDFLAGS_SAVE"
CFLAGS="$CFLAGS_SAVE"
375 376 377 378 379 380 381

dnl Only define HAVE_ICONV in postgis_config.h if we detect iconv sucessfully
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])
382
AC_SUBST([ICONV_CFLAGS])
383

384 385
LIBLWGEOM_ONLY="no"
AC_SUBST([LIBLWGEOM_ONLY])
386

387
dnl ===========================================================================
388
dnl Detect the version of PostgreSQL installed on the system, if needed
389
dnl ===========================================================================
390

391 392 393
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)])],
394
	[PG_CONFIG="$withval"], [])
395

396
if test "x$PG_CONFIG" = "xno"; then
397 398
	LIBLWGEOM_ONLY="yes"
	AC_MSG_RESULT([PostgreSQL support disabled])
399 400 401 402

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])
403

404
	dnl If we couldn't find pg_config, display an error
405
	if test "x$PG_CONFIG" = "x"; then
406
		AC_MSG_ERROR([could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.])
407 408
	fi
else
409 410
	dnl PG_CONFIG was specified; display a message to the user
	if test "x$PG_CONFIG" = "xyes"; then
411
		AC_MSG_ERROR([you must specify a parameter to --with-pgconfig, e.g. --with-pgconfig=/path/to/pg_config])
412
	else
413
		if test -f "$PG_CONFIG"; then
414
			AC_MSG_RESULT([Using user-specified pg_config file: $PG_CONFIG])
415
		else
416
			AC_MSG_ERROR([the user-specified pg_config file $PG_CONFIG does not exist])
417 418
		fi
	fi
419
fi
420

421
if test "x$LIBLWGEOM_ONLY" = "xno"; then
422

423
  dnl ===========================================================================
424 425
  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
426 427 428
  dnl packages, but don't install the Makefile it points to unless
  dnl the postgresql-server-dev packages are installed :)
  dnl ===========================================================================
429

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

435
  AC_SUBST([PGXS])
436

437 438
  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
439
  dnl the final version. This is to guard against user error...
440
  PGSQL_FULL_VERSION=`"$PG_CONFIG" --version`
441

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

445
  if test $PGSQL_MAJOR_VERSION -gt 9; then
446 447 448 449 450
  	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
451 452
  fi

453
  POSTGIS_PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION"
454

455 456 457
  PGSQL_PKGLIBDIR=`"$PG_CONFIG" --pkglibdir`
  PGSQL_LIBDIR=`"$PG_CONFIG" --libdir`
  PGSQL_SHAREDIR=`"$PG_CONFIG" --sharedir`
458

459
  AC_MSG_RESULT([checking PostgreSQL version... $PGSQL_FULL_VERSION])
460 461 462
  dnl Ensure that we are using PostgreSQL >= 9.4
  if test $POSTGIS_PGSQL_VERSION -lt 94; then
    AC_MSG_ERROR([PostGIS requires PostgreSQL >= 9.4])
463
  fi
464

465 466 467 468
  HAVE_BRIN=no
  if test $POSTGIS_PGSQL_VERSION -gt 94; then
    HAVE_BRIN=yes
  fi
469

470 471 472 473 474
  HAVE_SPGIST=no
  if test $POSTGIS_PGSQL_VERSION -gt 100; then
    HAVE_SPGIST=yes
  fi

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

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

481 482
  AC_SUBST([PGSQL_FE_LDFLAGS])
  AC_SUBST([PGSQL_FE_CPPFLAGS])
483

484
  dnl Extract the include flags for the backend (libpgcommon)
485
  PGSRV_INC=`"$PG_CONFIG" --includedir-server`
486 487 488 489 490 491 492
  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
493

494
  AC_SUBST([PGSQL_BE_CPPFLAGS])
495

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

500 501
  AC_SUBST([PGSQL_DOCDIR])
  AC_SUBST([PGSQL_MANDIR])
502

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

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

510
  AC_SUBST([PGSQL_BINDIR])
511

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

515
  AC_SUBST([PGSQL_SHAREDIR])
516

517 518 519 520 521
  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"
522

523 524 525
  dnl Ensure we can link against libpq
  LIBS_SAVE="$LIBS"
  LIBS="$PGSQL_FE_LDFLAGS"
526 527 528 529 530 531 532

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

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

533 534 535 536 537
  AC_CHECK_LIB([pq], [PQserverVersion],
    [],
    [AC_MSG_ERROR([could not find libpq])],
    [])
  LIBS="$LIBS_SAVE"
538 539
  CC="$CC_SAVE"
  CFLAGS="$CFLAGS_SAVE"
540

541
  AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_VERSION], [$POSTGIS_PGSQL_VERSION], [PostgreSQL server version])
542
  AC_SUBST([POSTGIS_PGSQL_VERSION])
543
  AC_SUBST([HAVE_BRIN])
544
  AC_SUBST([HAVE_SPGIST])
545

546
fi dnl LIBLWGEOM_ONLY != no
547

548

549 550 551 552 553
dnl ===========================================================================
dnl Explain our prefix policy if necessary.
dnl ===========================================================================

if test "$prefix" != "NONE"; then
554 555 556
  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 ])
557
  AC_MSG_RESULT([  $PG_CONFIG we will be installing:   ])
558 559 560
  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([    * postgis executables in $PGSQL_BINDIR ])
561
  AC_MSG_RESULT([------------------------------------------------------------------------])
562 563
fi

564 565
dnl ===========================================================================
dnl Detect libxml2 if it is installed
566
dnl (needed to GeomFromGML and GeomFromKML functions)
567 568
dnl ===========================================================================

569 570
AC_ARG_WITH([xml2config],
	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])],
571 572 573 574 575 576 577 578
	[XML2CONFIG="$withval"], [XML2CONFIG=""])

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 test "x$XML2CONFIG" = "x"; then
579
		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.])
580 581 582 583 584 585 586 587 588 589
	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])
		else
			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
590
		fi
591 592 593 594
	fi
fi


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

599 600 601 602 603 604 605 606 607 608

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
Paul Ramsey's avatar
Paul Ramsey committed
609
        	AC_MSG_RESULT([using OSX XCode... no])
610
        else
Paul Ramsey's avatar
Paul Ramsey committed
611 612 613 614 615 616 617
            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
618 619 620
        fi
        ;;
esac
621 622


623 624
dnl Extract the version
POSTGIS_LIBXML2_VERSION=`$XML2CONFIG --version`
625

626 627 628 629 630
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])])
631
CPPFLAGS="$CPPFLAGS_SAVE"
632

633 634 635 636
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])], [])
637
LIBS="$LIBS_SAVE"
638

639 640
AC_DEFINE_UNQUOTED([POSTGIS_LIBXML2_VERSION], ["$POSTGIS_LIBXML2_VERSION"], [PostGIS libxml2 version])
AC_SUBST([POSTGIS_LIBXML2_VERSION])
641 642


643 644

dnl ===========================================================================
645
dnl Detect the version of GEOS installed on the system
646
dnl ===========================================================================
647

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

652 653 654
if test "x$GEOSCONFIG" = "x"; then
	dnl GEOSCONFIG was not specified, so search within the current path
	AC_PATH_PROG([GEOSCONFIG], [geos-config])
655

656 657 658
	dnl If we couldn't find geos-config, display an error
	if test "x$GEOSCONFIG" = "x"; then
		AC_MSG_ERROR([could not find geos-config within the current path. You may need to try re-running configure with a --with-geosconfig parameter.])
659
	fi
660 661 662 663 664 665 666 667 668
else
	dnl GEOSCONFIG was specified; display a message to the user
	if test "x$GEOSCONFIG" = "xyes"; then
		AC_MSG_ERROR([you must specify a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])
	else
		if test -f $GEOSCONFIG; then
			AC_MSG_RESULT([Using user-specified geos-config file: $GEOSCONFIG])
		else
			AC_MSG_ERROR([the user-specified geos-config file $GEOSCONFIG does not exist])
669
		fi
670
	fi
671
fi
672

673
dnl Extract the version information from geos_config
674 675 676
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...
677 678
GEOS_MAJOR_VERSION=`$GEOSCONFIG --version | cut -d. -f1 | sed 's/[[^0-9]]//g'`
GEOS_MINOR_VERSION=`$GEOSCONFIG --version | cut -d. -f2 | sed 's/[[^0-9]]//g'`
679
GEOS_PATCH_VERSION=`$GEOSCONFIG --version | cut -d. -f3 | sed 's/[[^0-9]]//g'`
680 681
if test "x$GEOS_PATCH_VERSION" = "x"; then
	GEOS_PATCH_VERSION="0";
682
fi
683
GEOS_FULL_VERSION=`$GEOSCONFIG --version`
684
POSTGIS_GEOS_VERSION="$GEOS_MAJOR_VERSION$GEOS_MINOR_VERSION"
685 686 687
GEOS_NUMERIC_PATCH_VERSION=`printf "%02d" $GEOS_PATCH_VERSION`
GEOS_NUMERIC_MINOR_VERSION=`printf "%02d" $GEOS_MINOR_VERSION`
GEOS_NUMERIC_VERSION="$GEOS_MAJOR_VERSION$GEOS_NUMERIC_MINOR_VERSION$GEOS_NUMERIC_PATCH_VERSION"
688

689
dnl Ensure that we are using GEOS >= 3.5.0
690
AC_MSG_RESULT([checking GEOS version... $GEOS_FULL_VERSION])
691 692
if test ! "$GEOS_NUMERIC_VERSION" -ge 30500; then
	AC_MSG_ERROR([PostGIS requires GEOS >= 3.5.0])
693
fi
694

695
dnl Extract the linker and include flags
696 697
GEOS_LDFLAGS=`$GEOSCONFIG --ldflags`
GEOS_CPPFLAGS=-I`$GEOSCONFIG --includes`
698 699
AC_SUBST([GEOS_LDFLAGS])
AC_SUBST([GEOS_CPPFLAGS])
700

701 702 703 704 705
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"
706

707 708 709 710 711 712 713 714
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"
715

716
AC_DEFINE_UNQUOTED([POSTGIS_GEOS_VERSION], [$POSTGIS_GEOS_VERSION], [GEOS library version])
717
AC_SUBST([POSTGIS_GEOS_VERSION])
718
AC_SUBST([GEOS_NUMERIC_VERSION])
719 720


721 722 723 724
dnl ===========================================================================
dnl SFCGAL library support
dnl ===========================================================================

725 726 727
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"],
728
	[with_sfcgal=auto])
729 730 731 732

HAVE_SFCGAL="no"

if test "x$with_sfcgal" != "xno"; then
733
  if test "x$with_sfcgal" = "xyes" -o "x$with_sfcgal" = "xauto"; then
734 735
	  AC_PATH_PROG([SFCGAL_CONFIG], [sfcgal-config], [])
  fi
736
	if test -x "$SFCGAL_CONFIG"; then
737
		SFCGAL_VERSION=`$SFCGAL_CONFIG --version` || AC_MSG_ERROR([cannot determine sfcgal version (tried with $SFCGAL_CONFIG --version)])
738 739 740
		SFCGAL_LDFLAGS=`$SFCGAL_CONFIG --libs`
		SFCGAL_CPPFLAGS=`$SFCGAL_CONFIG --cflags`" -DHAVE_SFCGAL"

741 742 743 744 745 746
		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'`
		POSTGIS_SFCGAL_VERSION="$SFCGAL_MAJOR_VERSION$SFCGAL_MINOR_VERSION"
		AC_DEFINE_UNQUOTED([POSTGIS_SFCGAL_VERSION], [$POSTGIS_SFCGAL_VERSION], [SFCGAL library version at build time])
		AC_SUBST([POSTGIS_SFCGAL_VERSION])

747 748 749 750 751 752 753
		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"
		fi
754 755 756
		if test ! "$POSTGIS_SFCGAL_VERSION" -ge 11; then
			AC_MSG_ERROR([PostGIS requires SFCGAL >= 1.1.0 (found $SFCGAL_VERSION)])
		fi
757 758

	else
759
		if test "x$with_sfcgal" != "xauto"; then
760 761 762
			AC_MSG_ERROR([sfcgal-config cannot be found. Please install sfcgal])
		fi
	fi
763
fi
764 765 766 767 768 769 770 771

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

772 773


774 775 776 777 778 779 780
dnl ===========================================================================
dnl Detect gettext
dnl ===========================================================================

GETTEXT_CFLAGS=""
GETTEXT_LDFLAGS=""

781 782
AC_ARG_WITH([gettext],
	[AS_HELP_STRING([--with-gettext=PATH], [specify a path to non-default gettext installation])],
783
	[GETTEXT_PATH="$withval"], [GETTEXT_PATH="yes"])
784 785 786 787

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

788 789 790 791 792 793 794 795 796
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
797

798
	AM_GNU_GETTEXT([external], [], [])
799

800 801 802
	if test "x$LIBINTL" = "x"; then
		USE_NLS=no
	fi
803 804 805 806 807 808 809 810
fi

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

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

811
dnl ===========================================================================
812
dnl Detect the version of PROJ.4 installed
813
dnl ===========================================================================
814

815 816
AC_ARG_WITH([projdir],
	[AS_HELP_STRING([--with-projdir=PATH], [specify the PROJ.4 installation directory])],
817 818
	[PROJDIR="$withval"], [PROJDIR=""])

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

827
			dnl Add the include directory to PROJ_CPPFLAGS
828
			PROJ_CPPFLAGS="-I$PROJDIR/include -DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"
829 830
			PROJ_LDFLAGS="-L$PROJDIR/lib"
		else
831
			AC_MSG_ERROR([the --with-projdir directory "$PROJDIR" cannot be found])
832
		fi
833
	fi
834
fi
835

836
dnl Check that we can find the proj_api.h header file
837 838
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$PROJ_CPPFLAGS"
839 840 841 842
AC_CHECK_HEADER([proj_api.h], [], [AC_MSG_ERROR([could not find proj_api.h - you may need to specify the directory of a PROJ.4 installation using --with-projdir])],
[
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1
])
843

844 845 846 847 848
dnl Return the PROJ.4 version number
AC_PROJ_VERSION([POSTGIS_PROJ_VERSION])
AC_DEFINE_UNQUOTED([POSTGIS_PROJ_VERSION], [$POSTGIS_PROJ_VERSION], [PROJ library version])
AC_SUBST([POSTGIS_PROJ_VERSION])
CPPFLAGS="$CPPFLAGS_SAVE"
849

850 851 852
AC_SUBST([PROJ_CPPFLAGS])
AC_SUBST([PROJ_LDFLAGS])

853
dnl Ensure that we are using PROJ >= 4.6.0 (requires pj_set_searchpath)
854 855
if test ! "$POSTGIS_PROJ_VERSION" -ge 46; then
	AC_MSG_ERROR([PostGIS requires PROJ >= 4.6.0])
856 857
fi

858 859 860 861 862 863 864 865
dnl Ensure we can link against libproj
LIBS_SAVE="$LIBS"
LIBS="$PROJ_LDFLAGS"
AC_CHECK_LIB([proj], [pj_get_release],
	[],
	[AC_MSG_ERROR([could not find libproj - you may need to specify the directory of a PROJ.4 installation using --with-projdir])],
	[])
LIBS="$LIBS_SAVE"
866

867 868 869 870
dnl ===========================================================================
dnl Detect if json-c installed
dnl ===========================================================================

871
CHECK_JSON=yes
872
HAVE_JSON=no
873
HAVE_JSON_C=no
874

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

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

881 882 883 884 885 886 887 888 889
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
890 891 892 893
		AC_MSG_RESULT([Using user-specified json-c directory: $JSONDIR])

		dnl Add the include directory to JSON_CPPFLAGS
		JSON_CPPFLAGS="-I$JSONDIR/include"
894
		JSON_LDFLAGS="-L$JSONDIR/lib"
895 896 897
	fi
fi

898 899 900
dnl Check that we can find the json/json.h header file
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$JSON_CPPFLAGS"
901 902
AC_CHECK_HEADER([json/json.h], [HAVE_JSON=yes], [
  AC_CHECK_HEADER([json-c/json.h], [HAVE_JSON=yes; HAVE_JSON_C=yes], [])
903
])
904 905 906 907 908
CPPFLAGS="$CPPFLAGS_SAVE"

dnl Ensure we can link against libjson
LIBS_SAVE="$LIBS"
LIBS="$JSON_LDFLAGS"
909 910
AC_CHECK_LIB([json-c], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson-c"], [
  AC_CHECK_LIB([json], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson"], [], [])
911
], [])
912 913
LIBS="$LIBS_SAVE"

914
if test "$HAVE_JSON" = "yes"; then
915
	AC_DEFINE([HAVE_LIBJSON], 1, [Define to 1 if libjson is present])
916
fi
917 918 919
if test "$HAVE_JSON_C" = "yes"; then
	AC_DEFINE([HAVE_LIBJSON_C], 1, [Define to 1 if libjson resides in a json-c subdir])
fi
920

921 922
AC_SUBST([JSON_CPPFLAGS])
AC_SUBST([JSON_LDFLAGS])
923
AC_SUBST([HAVE_JSON])
924

925
fi
926

927 928 929 930
dnl ===========================================================================
dnl Detect if pkg-config installed
dnl ===========================================================================
# check for pkg-config
931 932
PKG_PROG_PKG_CONFIG
if test -z "$PKG_CONFIG"; then
933 934 935
   AC_MSG_WARN([Cannot find pkg-config, make sure it is installed in your PATH])
fi

936

937 938 939 940 941 942 943 944 945 946 947
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"], [])

948
dnl User didn't turn off protobuf support so...
949
if test "$CHECK_PROTOBUF" != "no"; then
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967

    AC_ARG_WITH([protobufdir],
    	[AS_HELP_STRING([--with-protobufdir=PATH], [specify the protobuf-c installation directory])],
    	[PROTOBUFDIR="$withval"], [PROTOBUFDIR=])

    dnl User specified the directory to find protobuf in, check that and
    dnl fail if it doesn't work
    if test ! "x$PROTOBUFDIR" = "x"; then
    	dnl Make sure that the directory exists
    	if test "x$PROTOBUFDIR" = "xyes"; then
    		AC_MSG_ERROR([you must specify a parameter to --with-protobufdir, e.g. --with-protobufdir=/path/to])
    	else
    		AC_MSG_RESULT([Using user-specified protobuf-c directory: $PROTOBUFDIR])

    		dnl Add the include directory to PROTOBUF_CPPFLAGS
    		PROTOBUF_CPPFLAGS="-I$PROTOBUFDIR/include"
    		PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib"
    	fi
968

969 970 971
        dnl Check that we can find the protobuf/protobuf.h header file
        CPPFLAGS_SAVE="$CPPFLAGS"
        CPPFLAGS="$PROTOBUF_CPPFLAGS"
972
        AC_CHECK_HEADER([protobuf-c/protobuf-c.h], [],
973 974 975 976 977 978 979
		    AC_MSG_ERROR([unable to find $PROTOBUFDIR/include/protobuf-c/protobuf-c.h])
        )
        CPPFLAGS="$CPPFLAGS_SAVE"

        dnl Ensure we can link against libprotobuf-c
        LIBS_SAVE="$LIBS"
        LIBS="$PROTOBUF_LDFLAGS"
980
        AC_CHECK_LIB([protobuf-c], [protobuf_c_message_check], [],
981 982 983 984 985 986
            AC_MSG_ERROR([unable to link protobuf-c from $PROTOBUFDIR/lib])
        )
        HAVE_PROTOBUF=yes
        PROTOBUF_LDFLAGS="-L$PROTOBUFDIR/lib -lprotobuf-c"
        LIBS="$LIBS_SAVE"

987
    dnl No user-specified protobuf dir, try to find one using pkg-config
988
    else
989
        if test -z "$PKG_CONFIG"; then
990 991 992 993 994
        	AC_MSG_WARN([Cannot find pkg-config, disabling protobuf support.])
        	HAVE_PROTOBUF=no
        else
        	dnl Ensure libprotobuf-c is of minimum required version
        	PKG_CHECK_MODULES([PROTOBUFC], [libprotobuf-c >= 1.1.0], [
995
                    HAVE_PROTOBUF=yes;
996 997
                    PROTOBUF_CPPFLAGS=$PROTOBUFC_CFLAGS;
                    PROTOBUF_LDFLAGS=$PROTOBUFC_LIBS
998
                ],
999 1000 1001
                [HAVE_PROTOBUF=no])
        fi
    fi
1002

1003 1004 1005 1006 1007 1008 1009 1010 1011
    if test "$HAVE_PROTOBUF" = "yes"; then
    	AC_PATH_PROG(PROTOCC, protoc-c)
    	if test "x$PROTOCC" = "x"; then
    	  AC_MSG_WARN([Protobuf compiler missing, disabling protobuf support.])
    	  HAVE_PROTOBUF=no
    	else
    	  AC_DEFINE([HAVE_LIBPROTOBUF], [1], [Define to 1 if libprotobuf-c is present])
    	fi
    fi
1012

1013 1014 1015
    AC_SUBST([PROTOBUF_CPPFLAGS])
    AC_SUBST([PROTOBUF_LDFLAGS])
    AC_SUBST([HAVE_PROTOBUF])
1016 1017 1018
fi


1019
dnl ===========================================================================
1020
dnl Detect GTK+2.0 for GUI
1021 1022
dnl ===========================================================================

1023 1024
AC_ARG_WITH([gui],
	[AS_HELP_STRING([--with-gui], [compile the data import GUI (requires GTK+2.0)])],
1025 1026 1027 1028
	[GUI="yes"], [GUI="no"])

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

	dnl Add -mwindows to MinGW GUI build
	case $host in
		*mingw32*)
1035 1036 1037
			GTK_WIN32_FLAGS=-mwindows
			GTK_WIN32_RES=shp2pgsql-gui.res
                        GTK_WIN32_BUILD=gui-win32
1038 1039
			;;
	esac
1040
fi
1041 1042 1043



1044
AC_SUBST([GTK_CFLAGS])
1045
AC_SUBST([GTK_LIBS])
1046 1047
AC_SUBST([GTK_WIN32_FLAGS])
AC_SUBST([GTK_WIN32_RES])
1048
AC_SUBST([GTK_BUILD])
1049 1050
AC_SUBST([IGE_MAC_CFLAGS])
AC_SUBST([IGE_MAC_LIBS])
1051

1052

1053
dnl ===========================================================================
1054 1055
dnl Allow the developer to turn on expensive checks and debugging flags
dnl with --enable-debug
1056 1057
dnl

1058 1059
AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable debugging code and flags]),
	[ENABLE_DEBUG=1], [ENABLE_DEBUG=0])
1060

1061
if test $ENABLE_DEBUG -eq 1; then
1062
    AC_DEFINE([PARANOIA_LEVEL], [10], [Enable use of memory checks])
1063 1064
    CFLAGS="$CFLAGS -g"
else
1065 1066
    AC_DEFINE([PARANOIA_LEVEL], [0], [Disable use of memory checks])
    AC_DEFINE([NDEBUG], [0], [Disable C asserts])
1067
fi
1068

1069

1070
dnl ===========================================================================
1071 1072
dnl Define version macros
dnl
1073

1074
POSTGIS_VERSION="$POSTGIS_MAJOR_VERSION.$POSTGIS_MINOR_VERSION USE_GEOS=1 USE_PROJ=1 USE_STATS=1"
1075 1076 1077 1078
if test "$HAVE_LIBXML2" = "1"; then
	POSTGIS_VERSION="$POSTGIS_VERSION USE_LIBXML2=1"
fi

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

1083 1084 1085 1086
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])
1087

1088 1089 1090 1091
AC_SUBST([POSTGIS_VERSION])
AC_SUBST([POSTGIS_LIB_VERSION])
AC_SUBST([POSTGIS_BUILD_DATE])
AC_SUBST([POSTGIS_SCRIPTS_VERSION])
1092

1093

1094
dnl ===========================================================================
1095
dnl Other parameters
1096
dnl
1097

1098 1099
dnl Always enable BBOX caching by default
AC_DEFINE_UNQUOTED([POSTGIS_AUTOCACHE_BBOX], [1], [Enable caching of bounding box within geometries])
1100

1101 1102
dnl Always enable use of ANALYZE statistics by default
AC_DEFINE_UNQUOTED([POSTGIS_USE_STATS], [1], [Enable use of ANALYZE statistics])
1103

1104 1105 1106
dnl ====================================
dnl address standardizer stuff
dnl ====================================
1107 1108
AC_ARG_WITH([address-standardizer],
    [AS_HELP_STRING([--without-address-standardizer],
1109 1110 1111
                    [Disable the address_standardizer extension])],
    [], [])

1112
if test "x$with_address_standardizer" != "xno"; then
1113 1114 1115 1116 1117
    dnl ===========================================================================
    dnl Detect the version of PCRE installed
    dnl ===========================================================================
    LDFLAGS="$LDFLAGS_SAVE"
    CFLAGS="$CFLAGS_SAVE"
1118

1119 1120 1121
    CHECK_PCRE=yes
    HAVE_PCRE=no
    ADDRESS_STANDARDIZER="address_standardizer"
1122 1123
    AC_ARG_WITH([pcredir],
        [AS_HELP_STRING([--with-pcredir=PATH], [specify the PCRE installation directory])],
1124
        [PCREDIR="$withval"], [PCREDIR=""])
1125

1126
    if test ! "x$PCREDIR" = "x"; then
1127
        dnl Make sure that the directory exists
1128 1129 1130 1131 1132
        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_RESULT([Using user-specified PCRE directory: $PCREDIR])
1133 1134 1135

                dnl Add the include directory to PCRE_CPPFLAGS
                PCRE_CPPFLAGS="-I$PCREDIR/include"
1136 1137
                PCRE_LDFLAGS="-L$PCREDIR/lib"
            else
1138
                AC_MSG_ERROR([the --with-pcredir directory "$PCREDIR" cannot be found])
1139 1140 1141
            fi
        fi
    fi
1142 1143


1144 1145 1146
    dnl Check that we can find the pcre.h header file
    CPPFLAGS_SAVE="$CPPFLAGS"
    CPPFLAGS="$PCRE_CPPFLAGS"
1147 1148

    AC_CHECK_HEADER([pcre.h], [HAVE_PCRE=yes], [ADDRESS_STANDARDIZER=""])
1149 1150 1151
    AC_SUBST([PCRE])
    AC_SUBST([HAVE_PCRE])
    AC_SUBST([ADDRESS_STANDARDIZER])
1152

1153 1154 1155 1156
    dnl Return the PCRE version number
    AC_DEFINE_UNQUOTED([PCRE_VERSION], [$PCRE_VERSION], [PCRE library version])
    AC_SUBST([PCRE_VERSION])
    CPPFLAGS="$CPPFLAGS_SAVE"
1157

1158 1159
    AC_SUBST([PCRE_CPPFLAGS])
    AC_SUBST([PCRE_LDFLAGS])
1160

1161 1162 1163 1164 1165
else
    ADDRESS_STANDARDIZER=""
    AC_SUBST([ADDRESS_STANDARDIZER])
    AC_MSG_RESULT([ADDRESS_STANDARDIZER support: disabled])
fi
1166

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

1170
SHLIB_LINK="$PGSQL_LDFLAGS $GEOS_LDFLAGS $PROJ_LDFLAGS -lgeos_c -lproj $JSON_LDFLAGS $PROTOBUF_LDFLAGS $XML2_LDFLAGS $SFCGAL_LDFLAGS $PCRE_LDFLAGS $EXCLUDELIBS_LDFLAGS $LDFLAGS"
1171 1172 1173
AC_SUBST([SHLIB_LINK])
dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK])

1174 1175 1176 1177
dnl ====================================
dnl topology stuff
dnl ====================================
AC_ARG_WITH([topology],
1178 1179 1180
    [AS_HELP_STRING([--without-topology],
                    [Disable the topology extension])],
    [], [])
1181

1182 1183 1184
if test "x$with_topology" != "xno"; then

    TOPOLOGY="topology"
1185
    AC_MSG_RESULT([TOPOLOGY: Topology support requested])
1186 1187
else
    AC_MSG_RESULT([TOPOLOGY: Topology support disabled])
1188 1189 1190 1191
fi

AC_SUBST([TOPOLOGY])

1192 1193 1194 1195 1196 1197 1198 1199 1200
dnl ====================================
dnl interrupt tests
dnl ====================================
INTERRUPTTESTS="no"
AC_ARG_WITH([interrupt-tests],
    [AS_HELP_STRING([--without-interrupt-tests],
                    [Disable the interrupt tests (for CI servers)])],
    [], [])

1201 1202 1203 1204 1205
AC_ARG_WITH([interrupt-tests],
    [AS_HELP_STRING([--with-interrupt-tests],
                    [Enable interrupt tests])],
    [INTERRUPTTESTS="yes"], [])

1206
if test "x$with_interrupt_tests" = "xno"; then
1207
    INTERRUPTTESTS="no"
1208 1209 1210 1211 1212 1213
fi

AC_SUBST([INTERRUPTTESTS])



1214 1215 1216 1217 1218 1219 1220 1221 1222
dnl ===========================================================================
dnl SRID stuff
dnl ===========================================================================

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

1223

1224 1225 1226
dnl ====================================
dnl raster stuff
dnl ====================================
1227
AC_ARG_WITH(
1228 1229
	[raster],
	AC_HELP_STRING([--without-raster], [Disable the raster extension]),
1230
	[], [])
1231

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

1236
	AC_CONFIG_HEADERS([raster/raster_config.h])
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257

	dnl
	dnl Raster Version Information imported from raster/Version.config
	dnl
	POSTGIS_RASTER_MAJOR_VERSION=`cat raster/Version.config | grep POSTGIS_RASTER_MAJOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
	POSTGIS_RASTER_MINOR_VERSION=`cat raster/Version.config | grep POSTGIS_RASTER_MINOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
	POSTGIS_RASTER_MICRO_VERSION=`cat raster/Version.config | grep POSTGIS_RASTER_MICRO_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`

	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_MAJOR_VERSION], ["$POSTGIS_RASTER_MAJOR_VERSION"], [PostGIS Raster major version])
	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_MINOR_VERSION], ["$POSTGIS_RASTER_MINOR_VERSION"], [PostGIS Raster minor version])
	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_MICRO_VERSION], ["$POSTGIS_RASTER_MICRO_VERSION"], [PostGIS Raster micro version])

	AC_SUBST([POSTGIS_RASTER_MAJOR_VERSION])
	AC_SUBST([POSTGIS_RASTER_MINOR_VERSION])
	AC_SUBST([POSTGIS_RASTER_MICRO_VERSION])

	dnl ==============================
	dnl Define raster version macros
	dnl ==============================
	POSTGIS_RASTER_VERSION="$POSTGIS_RASTER_MAJOR_VERSION.$POSTGIS_RASTER_MINOR_VERSION"
	POSTGIS_RASTER_LIB_VERSION="$POSTGIS_RASTER_MAJOR_VERSION.$POSTGIS_RASTER_MINOR_VERSION.$POSTGIS_RASTER_M