configure.ac 43.3 KB
Newer Older
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
dnl **********************************************************************
dnl * $Id: configure.ac 2797 2008-05-31 09:56:44Z mcayland $
dnl *
dnl * PostGIS - Spatial Types for PostgreSQL
dnl * http://postgis.refractions.net
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 **********************************************************************

AC_INIT()
AC_CONFIG_HEADERS([postgis_config.h])
AC_CONFIG_MACRO_DIR([macros])


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

dnl
dnl Compilers
dnl
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
28
AC_PROG_GREP
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
AC_PATH_PROG([ANT], [ant], [])
AC_SUBST([ANT])

dnl
dnl SQL Preprocessor
dnl
AC_PATH_PROG([CPPBIN], [cpp], [])
if test "x$CPPBIN" != "x"; then
  SQLPP="${CPPBIN} -traditional-cpp -P"
else
  AC_PATH_PROG([GPP], [gpp_], [])
  if test "x$GPP" != "x"; then
    SQLPP="${GPP} -C -s \'" dnl Use better string support
  else
    SQLPP="${CPP} -traditional-cpp"
  fi
fi
AC_SUBST([SQLPP])
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

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=""
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"], []) 
AC_SUBST([WARNFLAGS])

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

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 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'`

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 Search for flex/bison to build the parser
dnl

AC_PROG_LEX
AC_PROG_YACC
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])
104 105 106 107 108 109 110 111 112 113 114 115
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, [HAVE_VASPRINTF=1], [HAVE_VASPRINTF=0])
AC_DEFINE([HAVE_VASPRINTF])
AC_CHECK_FUNC(asprintf, [HAVE_ASPRINTF=1], [HAVE_ASPRINTF=0])
AC_DEFINE([HAVE_ASPRINTF])
AC_FUNC_FSEEKO()
116 117 118 119 120 121 122

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*)
123
                 MINGWBUILD=1
124 125
                 ;;
         *)
126
                 MINGWBUILD=0
127 128
                 ;;
esac
129
AC_SUBST([MINGWBUILD])
130

131 132 133 134 135
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])
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

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

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

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

154 155 156 157 158
AC_PATH_PROG([XMLLINT], [xmllint], [])
if test "x$XMLLINT" = "x"; then
	AC_MSG_WARN([xmllint is not installed so documentation cannot be checked])
fi

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
AC_PATH_PROG([DBLATEX], [dblatex], [])
if test "x$DBLATEX" = "x"; then
	AC_MSG_WARN([dblatex is not installed so PDF documentation cannot be built])
fi

dnl
dnl Allow the user to specify the location of the html/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 directory
	dnl that matches from the following list
	SEARCHPATH="
		/usr/share/sgml/docbook/xsl-stylesheets 
		/usr/share/xml/docbook/stylesheet/nwalsh
		/usr/share/sgml/docbook/stylesheet/xsl/nwalsh
		/opt/local/share/xsl/docbook-xsl
		/usr/local/share/xsl/docbook-xsl
		/usr/share/xsl/docbook-xsl
		"
	for p in ${SEARCHPATH}; do
		if test -r "${p}"/html/docbook.xsl; then
			XSLBASE_AUTO="${p}"
			break
		fi
	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 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/html/docbook.xsl"; then
		AC_MSG_ERROR([the docbook stylesheet directory specified using --with-xsldir does not contain the html/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])

225 226 227
dnl
dnl Let's see if we can find mathml2.dtd
dnl
228 229 230
AC_ARG_WITH([mathmldtd], 
	[AS_HELP_STRING([--with-mathmldtd=PATH], [specify the dtd path for mathml2.dtd])], 
	[MATHML2_DTD="$withval"], [MATHML2_DTD=""])
231
dnl TODO: get more paths to add here...
232 233 234 235 236 237 238 239 240 241 242 243
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
244
AC_SUBST([MATHML2_DTD])
245 246 247 248 249 250 251 252 253 254 255 256 257

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_LDFLAGS=""
AC_CHECK_HEADER([CUnit/CUnit.h], [
	CUNIT_CPPFLAGS="$CPPFLAGS"
258
	AC_CHECK_LIB([cunit], [CU_initialize_registry], [CUNIT_LDFLAGS="$LDFLAGS -lcunit"], [AC_MSG_WARN([could not locate CUnit required for unit tests])])
259 260
	],
	[
261
	AC_MSG_WARN([could not locate CUnit required for unit tests])
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
	])
	
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 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])
AC_SUBST([ICONV_CFLAGS])


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

333
AC_ARG_VAR(PG_CONFIG, [PostgreSQL configure command to determine Postgres version to bulid against.])
334 335
AC_ARG_WITH([pgconfig], 
	[AS_HELP_STRING([--with-pgconfig=FILE], [specify an alternative pg_config file])], 
336 337 338 339 340
	[PG_CONFIG="$withval"], [])

if test "x$PG_CONFIG" = "xno"; then
	dnl disabling pg_config doesn't make sense
	AC_MSG_ERROR([Cannot disable pg_config.])
341

342 343 344
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])
345 346

	dnl If we couldn't find pg_config, display an error
347 348
	if test "x$PG_CONFIG" = "x"; then
		AC_MSG_ERROR([could not find pg_config within the current path. You may need to try re-running configure with a --with-pg_config parameter.])
349 350
	fi
else
351 352
	dnl PG_CONFIG was specified; display a message to the user
	if test "x$PG_CONFIG" = "xyes"; then
353 354
		AC_MSG_ERROR([you must specify a parameter to --with-pgconfig, e.g. --with-pgconfig=/path/to/pg_config])
	else
355 356
		if test -f $PG_CONFIG; then
			AC_MSG_RESULT([Using user-specified pg_config file: $PG_CONFIG])
357
		else
358
			AC_MSG_ERROR([the user-specified pg_config file $PG_CONFIG does not exist])
359 360 361 362 363 364 365 366 367 368 369 370
		fi
	fi
fi


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 ===========================================================================

371
PGXS=`$PG_CONFIG --pgxs`
372 373 374 375 376 377 378 379 380 381
if test ! -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... 
382 383 384
PGSQL_MAJOR_VERSION=`$PG_CONFIG --version | sed 's/[[A-Za-z ]]*//' | cut -d. -f1 | sed 's/[[^0-9]]//g'`	
PGSQL_MINOR_VERSION=`$PG_CONFIG --version | sed 's/[[A-Za-z ]]*//' | cut -d. -f2 | sed 's/[[^0-9]]//g'`	
PGSQL_FULL_VERSION=`$PG_CONFIG --version`
385 386
POSTGIS_PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION"

387 388 389
PGSQL_PKGLIBDIR=`$PG_CONFIG --pkglibdir`
PGSQL_LIBDIR=`$PG_CONFIG --libdir`
PGSQL_SHAREDIR=`$PG_CONFIG --sharedir`
390

391
AC_MSG_RESULT([checking PostgreSQL version... $PGSQL_FULL_VERSION])
392 393 394
dnl Ensure that we are using PostgreSQL >= 9.0
if test ! "$PGSQL_MAJOR_VERSION" -ge 9; then
	AC_MSG_ERROR([PostGIS requires PostgreSQL >= 9.0])
395 396 397 398 399 400 401 402 403 404 405 406 407 408
fi	

dnl Temporary hack until minimum PostgreSQL version is 9.0:
dnl If PostgreSQL < 9.0 is detected, trigger the inclusion of the new versioned PGXS targets
PGXSOVERRIDE=0
if test ! "$PGSQL_MAJOR_VERSION" -ge 9; then
	PGXSOVERRIDE=1
fi

AC_SUBST([PGXSOVERRIDE])

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)
409 410
PGSQL_FE_LDFLAGS=-L`$PG_CONFIG --libdir`" -lpq"
PGSQL_FE_CPPFLAGS=-I`$PG_CONFIG --includedir`
411 412 413 414

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

415
dnl Extract the include flags for the backend (libpgcommon)
416
PGSRV_INC=`$PG_CONFIG --includedir-server`
417 418 419 420 421 422 423 424 425 426
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])

427
dnl Extract the documentation and man page directories
428 429
PGSQL_DOCDIR=`$PG_CONFIG --docdir`
PGSQL_MANDIR=`$PG_CONFIG --mandir`
430 431 432 433

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

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

438
dnl Extract the executable directory
439
PGSQL_BINDIR=`$PG_CONFIG --bindir`
440 441 442 443

AC_SUBST([PGSQL_BINDIR])

dnl Extract the share directory
444
PGSQL_SHAREDIR=`$PG_CONFIG --sharedir`
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466

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"
AC_CHECK_LIB([pq], [PQserverVersion],
	[],
	[AC_MSG_ERROR([could not find libpq])],
	[])
LIBS="$LIBS_SAVE"

AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_VERSION], [$POSTGIS_PGSQL_VERSION], [PostgreSQL server version])	
AC_SUBST([POSTGIS_PGSQL_VERSION])


467 468 469 470 471 472 473 474
dnl ===========================================================================
dnl Explain our prefix policy if necessary.
dnl ===========================================================================

if test "$prefix" != "NONE"; 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 ])
475
  AC_MSG_RESULT([  $PG_CONFIG we will be installing:   ])
476 477 478 479 480 481
  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 ])
  AC_MSG_RESULT([------------------------------------------------------------------------])
fi

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
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=""])

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


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

dnl Extract the version
POSTGIS_LIBXML2_VERSION=`$XML2CONFIG --version`

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])])
525
CPPFLAGS="$CPPFLAGS_SAVE"
526 527 528 529 530

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])], [])
531
LIBS="$LIBS_SAVE"
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

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 ===========================================================================

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

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

	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.])
	fi
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])
		fi	
	fi
fi

dnl Extract the version information from geos_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... 
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'`
GEOS_PATCH_VERSION=`$GEOSCONFIG --version | cut -d. -f3 | sed 's/[[^0-9]]//g'`
574 575 576
if test "x$GEOS_PATCH_VERSION" = "x"; then 
	GEOS_PATCH_VERSION="0"; 
fi
577 578
GEOS_FULL_VERSION=`$GEOSCONFIG --version`
POSTGIS_GEOS_VERSION="$GEOS_MAJOR_VERSION$GEOS_MINOR_VERSION"
579 580 581
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"
582

583
dnl Ensure that we are using GEOS >= 3.3.0
584
AC_MSG_RESULT([checking GEOS version... $GEOS_FULL_VERSION])
585 586
if test ! "$GEOS_NUMERIC_VERSION" -ge 30300; then
	AC_MSG_ERROR([PostGIS requires GEOS >= 3.3.0])
587 588 589 590 591
fi

dnl Extract the linker and include flags 
GEOS_LDFLAGS=`$GEOSCONFIG --ldflags`
GEOS_CPPFLAGS=-I`$GEOSCONFIG --includes`
592 593
AC_SUBST([GEOS_LDFLAGS])
AC_SUBST([GEOS_CPPFLAGS])
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611

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])
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
AC_SUBST([GEOS_NUMERIC_VERSION])

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"], 
	[AC_PATH_PROG([SFCGAL_CONFIG], [sfcgal-config], [])])

HAVE_SFCGAL="no"

if test "x$with_sfcgal" != "xno"; then
	if test -x "$SFCGAL_CONFIG"; then
		SFCGAL_VERSION=`$SFCGAL_CONFIG --version`
		SFCGAL_LDFLAGS=`$SFCGAL_CONFIG --libs`
		SFCGAL_CPPFLAGS=`$SFCGAL_CONFIG --cflags`" -DHAVE_SFCGAL"

		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

	else
		if test "x$with_sfcgal" != "x"; then
			AC_MSG_ERROR([sfcgal-config cannot be found. Please install sfcgal])
		fi
	fi
fi 
645

646 647 648 649 650 651
AC_SUBST([SFCGAL_VERSION])
AC_SUBST([SFCGAL_CPPFLAGS])
AC_SUBST([SFCGAL_LDFLAGS])
AC_SUBST([SFCGAL_OBJS])
AC_SUBST([SFCGAL])
AC_SUBST([HAVE_SFCGAL])
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
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"

690 691 692 693 694 695 696 697 698 699 700
dnl ===========================================================================
dnl Detect the version of PROJ.4 installed
dnl ===========================================================================

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

if test ! "x$PROJDIR" = "x"; then
	dnl Make sure that the directory exists 
	if test "x$PROJDIR" = "xyes"; then
701
		AC_MSG_ERROR([you must specify a parameter to --with-projdir, e.g. --with-projdir=/path/to])
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
	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"
		else
			AC_MSG_ERROR([the --with-projdir directory "$PROJDIR" cannot be found]) 
		fi
	fi
fi


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_MSG_ERROR([could not find proj_api.h - you may need to specify the directory of a PROJ.4 installation using --with-projdir])])	

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"

727 728 729
AC_SUBST([PROJ_CPPFLAGS])
AC_SUBST([PROJ_LDFLAGS])

730 731 732
dnl Ensure that we are using PROJ >= 4.6.0 (requires pj_set_searchpath) 
if test ! "$POSTGIS_PROJ_VERSION" -ge 46; then
	AC_MSG_ERROR([PostGIS requires PROJ >= 4.6.0])
733 734 735 736 737 738 739 740 741 742 743
fi

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"

744 745 746 747
dnl ===========================================================================
dnl Detect if json-c installed
dnl ===========================================================================

748
CHECK_JSON=yes
749 750 751
HAVE_JSON=no
AC_SUBST([HAVE_JSON])

752 753 754 755 756 757
AC_ARG_WITH([json],
	[AS_HELP_STRING([--without-json], [build without json-c support])],
	[CHECK_JSON="$withval"], [])

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

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
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
		dnl We need (libjson.so OR libjson.a OR libjson.dll) AND json/json.h
		if test ! -e "${JSONDIR}/include/json/json.h" -o \
		        ! \( -e "${JSONDIR}/lib/libjson.so" -o \
		            -e "${JSONDIR}/lib/libjson.dll" -o \
		            -e "${JSONDIR}/lib/libjson.dylib" -o \
		            -e "${JSONDIR}/bin/libjson.dll" -o \
		            -e "${JSONDIR}/lib/libjson.a" \) 
		then
			AC_MSG_ERROR([Cannot find json dev files in "$JSONDIR"])
		fi
		AC_MSG_RESULT([Using user-specified json-c directory: $JSONDIR])

		dnl Add the include directory to JSON_CPPFLAGS
		JSON_CPPFLAGS="-I$JSONDIR/include"
781
		JSON_LDFLAGS="-L$JSONDIR/lib"
782 783 784 785 786 787 788 789 790 791 792 793
	fi
fi

dnl Check that we can find the json/json.h header file
CPPFLAGS_SAVE="$CPPFLAGS"
CPPFLAGS="$JSON_CPPFLAGS"
AC_CHECK_HEADER([json/json.h], [HAVE_JSON=yes], [])	
CPPFLAGS="$CPPFLAGS_SAVE"

dnl Ensure we can link against libjson
LIBS_SAVE="$LIBS"
LIBS="$JSON_LDFLAGS"
794 795 796
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"], [], [])
], [])
797 798 799 800 801 802 803 804 805
LIBS="$LIBS_SAVE"

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

806 807
fi dnl }

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
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="yes"], [GUI="no"])

if test "x$GUI" = "xyes"; then
	AC_MSG_RESULT([GUI: Build requested, checking for dependencies (GKT+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 user to enable debugging with --enable-debug
dnl
dnl Currently we default to debug level 4. See DEBUG for more information. 
dnl

AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable verbose debugging messages]), 
	[POSTGIS_DEBUG_LEVEL=4], [POSTGIS_DEBUG_LEVEL=0]) 

AC_DEFINE_UNQUOTED([POSTGIS_DEBUG_LEVEL], [$POSTGIS_DEBUG_LEVEL], [PostGIS library debug level (0=disabled)])

dnl ===========================================================================
dnl Allow the user to enable GEOS profiling with --enable-profile
dnl

AC_ARG_ENABLE([profile], AC_HELP_STRING([--enable-profile], [Enable GEOS profiling messages]), 
	[POSTGIS_PROFILE=1], [POSTGIS_PROFILE=0]) 

AC_DEFINE_UNQUOTED([POSTGIS_PROFILE], [$POSTGIS_PROFILE], [Enable GEOS profiling (0=disabled)])

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 -u "+%Y-%m-%d %H:%M:%S"`
873
POSTGIS_SCRIPTS_VERSION="$POSTGIS_LIB_VERSION"
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895

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 Other parameters 
dnl

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

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

896 897
CPPFLAGS="$PGSQL_CPPFLAGS $GEOS_CPPFLAGS $PROJ_CPPFLAGS $XML2_CPPFLAGS $SFCGAL_CPPFLAGS $CPPFLAGS"
AC_MSG_RESULT([CPPFLAGS: $CPPFLAGS])
898

899
SHLIB_LINK="$PGSQL_LDFLAGS $GEOS_LDFLAGS $PROJ_LDFLAGS -lgeos_c -lproj $JSON_LDFLAGS $XML2_LDFLAGS $SFCGAL_LDFLAGS"
900 901 902
AC_SUBST([SHLIB_LINK])
dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK])

903 904 905 906 907 908 909 910 911 912 913 914
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])
915
	if test "$GEOS_NUMERIC_VERSION" -lt 30302; then
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
		AC_MSG_ERROR([Topology requires GEOS version >= 3.3.2. Use --without-topology or install a newer GEOS.])
	fi
else
    AC_MSG_RESULT([TOPOLOGY: Topology support disabled])
fi

AC_SUBST([TOPOLOGY])

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],
	AC_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 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_MICRO_VERSION"
	POSTGIS_RASTER_BUILD_DATE=`date -u "+%Y-%m-%d %H:%M:%S"`
	POSTGIS_RASTER_SCRIPTS_VERSION="$POSTGIS_RASTER_LIB_VERSION"

	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_VERSION], ["$POSTGIS_RASTER_VERSION"], [PostGIS Raster version])
	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_LIB_VERSION], ["$POSTGIS_RASTER_LIB_VERSION"], [PostGIS Raster library version])
	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_BUILD_DATE], ["$POSTGIS_RASTER_BUILD_DATE"], [PostGIS Raster build date])
	AC_DEFINE_UNQUOTED([POSTGIS_RASTER_SCRIPTS_VERSION], ["$POSTGIS_RASTER_SCRIPTS_VERSION"], [PostGIS Raster scripts version])

	AC_SUBST([POSTGIS_RASTER_VERSION])
	AC_SUBST([POSTGIS_RASTER_LIB_VERSION])
	AC_SUBST([POSTGIS_RASTER_BUILD_DATE])
	AC_SUBST([POSTGIS_RASTER_SCRIPTS_VERSION])

	dnl ===========================================================================
	dnl Allow output of double truncation warnings with --with-raster-dblwarning
	dnl ===========================================================================
	AC_ARG_WITH(
		[raster-dblwarning],
		AC_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=""
1010
	LIBGDAL_DEPLIBS_LDFLAGS=""
1011 1012

	dnl GDAL version constants, update here
1013 1014
	GDAL_MIN_VERSION=1.8.0
	GDAL_MIN_VERSION_NUMBER=180 dnl TODO: Use GDAL version calculation MAJOR*1000+MINOR*100+REV*10+BUILD
1015 1016 1017 1018 1019 1020 1021 1022

	AC_ARG_WITH(
		[gdalconfig],
		AC_HELP_STRING([--with-gdalconfig=@<:@ARG@:>@],[specify location of gdal-config (ARG=path).  Only used with --with-raster]),
		[GDAL_CONFIG="$withval"],
		[AC_PATH_PROG([GDAL_CONFIG], [gdal-config], [])]
  )

1023
	AC_MSG_CHECKING([GDAL version])
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

	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"

1037 1038
		AC_MSG_RESULT([$GDAL_FULL_VERSION])

1039 1040 1041 1042 1043 1044 1045 1046
		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])

1047 1048 1049 1050 1051 1052 1053 1054 1055
		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])

1056 1057
		dnl Extract the linker and include flags 
		LIBGDAL_LDFLAGS=`$GDAL_CONFIG --libs`
1058
		dnl LIBGDAL_DEPLIBS_LDFLAGS=`$GDAL_CONFIG --dep-libs`
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
		LIBGDAL_CFLAGS=`$GDAL_CONFIG --cflags`

		CPPFLAGS_SAVE="$CPPFLAGS"
		CPPFLAGS="$LIBGDAL_CFLAGS"
		CFLAGS_SAVE="$CFLAGS"
		CFLAGS=""
		LIBS_SAVE="$LIBS"
		LIBS="$LIBGDAL_LDFLAGS"

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

		dnl Ensure we can link against gdal
1075 1076 1077 1078 1079 1080
		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])], [])
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096

		LIBS="$LIBGDAL_LDFLAGS"

		dnl Check if the new polygonize function is present
		AC_SEARCH_LIBS(
			[GDALFPolygonize],
			[gdal],
			[AC_DEFINE_UNQUOTED([GDALFPOLYGONIZE], [1], [Define to 1 if GDALFPolygonize function is available])],
			[])

		CPPFLAGS="$CPPFLAGS_SAVE"
		CFLAGS="$CFLAGS_SAVE"
		LIBS="$LIBS_SAVE"

		AC_SUBST([LIBGDAL_CFLAGS])
		AC_SUBST([LIBGDAL_LDFLAGS])
1097
		AC_SUBST([LIBGDAL_DEPLIBS_LDFLAGS])
1098 1099

		AC_SUBST([GDALFPOLYGONIZE])
1100

1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
	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_PG_LIB=pglib
	RT_LOADER=rtloader
	RT_POSTGIS_SQL=rtpostgis.sql

	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="
		raster/Makefile \
		raster/rt_core/Makefile \
		raster/rt_pg/Makefile \
		raster/loader/Makefile \
		raster/test/Makefile \
1124
		raster/test/cunit/Makefile \
1125 1126 1127 1128 1129 1130 1131 1132 1133
		raster/test/regress/Makefile \
		raster/scripts/Makefile \
		raster/scripts/python/Makefile"

else
	AC_MSG_RESULT([RASTER: Raster support disabled])
	RT_MAKEFILE_LIST="raster/Makefile"
fi

1134

1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
dnl ===========================================================================
dnl See if we have the requirements for building the extensions, namely
dnl PostgreSQL 9.1 or better and the xlstproc tool for generating the commends
dnl SQL file.
dnl ===========================================================================

EXTENSIONS=""
if test $POSTGIS_PGSQL_VERSION -ge 91; then
	if test \
          "x$XSLTPROC" != "x" -o \
          -e doc/postgis_comments.sql -a \
          -e doc/raster_comments.sql;
  then
		if test "x$RASTER" = "xraster"; then
				AC_MSG_RESULT([enabling PostgreSQL extension support...])
				EXTENSIONS=extensions
				AC_SUBST([EXTENSIONS])
		fi
	fi
fi


dnl ===========================================================================
1158
dnl Output the relevant files
1159
dnl ===========================================================================
1160

1161 1162 1163 1164 1165 1166
AC_OUTPUT([GNUmakefile 
   extensions/Makefile
   extensions/postgis/Makefile 
   extensions/postgis/postgis.control 
   extensions/postgis_topology/Makefile 
   extensions/postgis_topology/postgis_topology.control 
1167 1168
   extensions/postgis_tiger_geocoder/Makefile 
   extensions/postgis_tiger_geocoder/postgis_tiger_geocoder.control 
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
   liblwgeom/Makefile 
   liblwgeom/cunit/Makefile 
   liblwgeom/liblwgeom.h 
   libpgcommon/Makefile 
   libpgcommon/cunit/Makefile 
   postgis/Makefile 
   postgis/sqldefines.h 
   loader/Makefile 
   loader/cunit/Makefile 
   topology/Makefile 
1179
   topology/test/Makefile 
1180 1181 1182 1183 1184 1185 1186 1187
   regress/Makefile 
   doc/Makefile 
   doc/Makefile.comments 
   doc/html/image_src/Makefile 
   utils/Makefile 
   java/jdbc/Makefile
   $RT_MAKEFILE_LIST])
    
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
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}])
AC_MSG_RESULT([  C++ compiler:         ${CXX} ${CXXFLAGS}])
1198
AC_MSG_RESULT([  SQL preprocessor:     ${SQLPP}])
1199 1200 1201 1202
AC_MSG_RESULT()
AC_MSG_RESULT([ -------------- Dependencies -------------- ])
AC_MSG_RESULT([  GEOS config:          ${GEOSCONFIG}])
AC_MSG_RESULT([  GEOS version:         ${GEOS_FULL_VERSION}])
1203 1204 1205 1206
if test "x$RASTER" = "xraster"; then
    AC_MSG_RESULT([  GDAL config:          ${GDAL_CONFIG}])
    AC_MSG_RESULT([  GDAL version:         ${GDAL_FULL_VERSION}])
fi
1207 1208 1209 1210 1211
if test "x$SFCGAL" = "xsfcgal"; then
    AC_MSG_RESULT([  SFCGAL config:        ${SFCGAL_CONFIG}])
    AC_MSG_RESULT([  SFCGAL version:       ${SFCGAL_VERSION}])
fi
AC_MSG_RESULT([  PostgreSQL config:    ${PG_CONFIG}])
1212 1213 1214 1215
AC_MSG_RESULT([  PostgreSQL version:   ${PGSQL_FULL_VERSION}])
AC_MSG_RESULT([  PROJ4 version:        ${POSTGIS_PROJ_VERSION}])
AC_MSG_RESULT([  Libxml2 config:       ${XML2CONFIG}])
AC_MSG_RESULT([  Libxml2 version:      ${POSTGIS_LIBXML2_VERSION}])
1216
AC_MSG_RESULT([  JSON-C support:       ${HAVE_JSON}])
1217
AC_MSG_RESULT([  PostGIS debug level:  ${POSTGIS_DEBUG_LEVEL}])
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
AC_MSG_RESULT([  Perl:                 ${PERL}])
AC_MSG_RESULT()
AC_MSG_RESULT([ --------------- Extensions --------------- ])
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
1232 1233 1234 1235 1236
if test "x$SFCGAL" = "xsfcgal"; then
    AC_MSG_RESULT([  SFCGAL support:       enabled])
else
    AC_MSG_RESULT([  SFCGAL support:       disabled])
fi
1237 1238 1239 1240 1241 1242
AC_MSG_RESULT()
AC_MSG_RESULT([ -------- Documentation Generation -------- ])
AC_MSG_RESULT([  xsltproc:             ${XSLTPROC}])
AC_MSG_RESULT([  xsl style sheets:     ${XSLBASE}])
AC_MSG_RESULT([  dblatex:              ${DBLATEX}])
AC_MSG_RESULT([  convert:              ${IMAGEMAGICK}])
1243
AC_MSG_RESULT([  mathml2.dtd:          ${MATHML2_DTD}])
1244 1245
AC_MSG_RESULT()

1246
if test "$GEOS_NUMERIC_VERSION" -lt 30302; then
1247 1248 1249 1250 1251 1252 1253 1254 1255
AC_MSG_RESULT([ --------- GEOS VERSION NOTICE ------------ ])
AC_MSG_RESULT([  You are building against GEOS ${GEOS_FULL_VERSION} ])
AC_MSG_RESULT([  To take advantage of all the features of ])
AC_MSG_RESULT([  PostGIS we recommend you build using ])
AC_MSG_RESULT([  GEOS 3.3.2 or higher. You can download ])
AC_MSG_RESULT([  the latest versions from ])
AC_MSG_RESULT([  http://trac.osgeo.org/geos ])
AC_MSG_RESULT()
fi
1256