From 4626d99aa1fd15e1fcd67141b396b35c5cf7fe29 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Mon, 14 Jan 2013 16:46:13 -0800 Subject: [PATCH] Add first cut at autoconf Rename 'core' directory --- .gitignore | 4 + Makefile | 4 +- configure.ac | 280 +++++++++++++++++++++ {core => libpc}/Makefile | 0 {core => libpc}/cunit/.gitignore | 0 {core => libpc}/cunit/Makefile | 0 {core => libpc}/cunit/cu_pc_schema.c | 0 {core => libpc}/cunit/cu_tester.c | 0 {core => libpc}/cunit/cu_tester.h | 0 {core => libpc}/cunit/data/pdal-schema.xml | 0 {core => libpc}/hashtable.c | 0 {core => libpc}/hashtable.h | 0 {core => libpc}/pc_api.h | 0 {core => libpc}/pc_api_internal.h | 0 {core => libpc}/pc_core.c | 0 {core => libpc}/pc_mem.c | 0 {core => libpc}/pc_point.c | 0 {core => libpc}/pc_schema.c | 0 {core => libpc}/pc_util.c | 0 {core => libpc}/pc_val.c | 0 {core => libpc}/stringbuffer.c | 0 {core => libpc}/stringbuffer.h | 0 macros/ac_proj4_version.m4 | 42 ++++ postgis/Makefile | 2 +- 24 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 configure.ac rename {core => libpc}/Makefile (100%) rename {core => libpc}/cunit/.gitignore (100%) rename {core => libpc}/cunit/Makefile (100%) rename {core => libpc}/cunit/cu_pc_schema.c (100%) rename {core => libpc}/cunit/cu_tester.c (100%) rename {core => libpc}/cunit/cu_tester.h (100%) rename {core => libpc}/cunit/data/pdal-schema.xml (100%) rename {core => libpc}/hashtable.c (100%) rename {core => libpc}/hashtable.h (100%) rename {core => libpc}/pc_api.h (100%) rename {core => libpc}/pc_api_internal.h (100%) rename {core => libpc}/pc_core.c (100%) rename {core => libpc}/pc_mem.c (100%) rename {core => libpc}/pc_point.c (100%) rename {core => libpc}/pc_schema.c (100%) rename {core => libpc}/pc_util.c (100%) rename {core => libpc}/pc_val.c (100%) rename {core => libpc}/stringbuffer.c (100%) rename {core => libpc}/stringbuffer.h (100%) create mode 100644 macros/ac_proj4_version.m4 diff --git a/.gitignore b/.gitignore index d3399f6..bcf91f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.o *.a *.so +autom4te.cache +configure +config.log +confdefs.h diff --git a/Makefile b/Makefile index 397416c..0d87526 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ all install uninstall noop clean distclean: - $(MAKE) -C core $@ + $(MAKE) -C libpc $@ $(MAKE) -C postgis $@ check: - $(MAKE) -C core $@ + $(MAKE) -C libpc $@ astyle: find . \ diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..1064ae6 --- /dev/null +++ b/configure.ac @@ -0,0 +1,280 @@ +dnl ********************************************************************** +dnl * configure.ac +dnl * +dnl * Pointclound buildb configuration. +dnl * +dnl * Copyright (c) 2012, OpenGeo +dnl * +dnl ***********************************************************************/ + + +AC_INIT() +dnl AC_CONFIG_HEADERS([postgis_config.h]) +AC_CONFIG_MACRO_DIR([macros]) + +dnl +dnl Compilers +dnl +AC_PROG_CC + +dnl +dnl Define executable suffix for use with the loader Makefiles +dnl +EXESUFFIX="$ac_cv_exeext" +AC_SUBST([EXESUFFIX]) + +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 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" + AC_CHECK_LIB([cunit], [CU_initialize_registry], [CUNIT_LDFLAGS="$LDFLAGS -lcunit"], [AC_MSG_WARN([could not locate CUnit required for unit tests])]) + ], + [ + AC_MSG_WARN([could not locate CUnit required for unit tests]) + ]) + +AC_SUBST([CUNIT_CPPFLAGS]) +AC_SUBST([CUNIT_LDFLAGS]) + + +dnl =========================================================================== +dnl Detect the version of PostgreSQL installed on the system +dnl =========================================================================== + +AC_ARG_WITH([pgconfig], + [AS_HELP_STRING([--with-pgconfig=FILE], [specify an alternative pg_config file])], + [PGCONFIG="$withval"], [PGCONFIG=""]) + +if test "x$PGCONFIG" = "x"; then + dnl PGCONFIG was not specified, so search within the current path + AC_PATH_PROG([PGCONFIG], [pg_config]) + + dnl If we couldn't find pg_config, display an error + if test "x$PGCONFIG" = "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-pgconfig parameter.]) + fi +else + dnl PGCONFIG was specified; display a message to the user + if test "x$PGCONFIG" = "xyes"; then + AC_MSG_ERROR([you must specify a parameter to --with-pgconfig, e.g. --with-pgconfig=/path/to/pg_config]) + else + if test -f $PGCONFIG; then + AC_MSG_RESULT([Using user-specified pg_config file: $PGCONFIG]) + else + AC_MSG_ERROR([the user-specified pg_config file $PGCONFIG does not exist]) + 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 =========================================================================== + +PGXS=`$PGCONFIG --pgxs` +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... +PGSQL_MAJOR_VERSION=`$PGCONFIG --version | sed 's/[[A-Za-z ]]*//' | cut -d. -f1 | sed 's/[[^0-9]]//g'` +PGSQL_MINOR_VERSION=`$PGCONFIG --version | sed 's/[[A-Za-z ]]*//' | cut -d. -f2 | sed 's/[[^0-9]]//g'` +PGSQL_FULL_VERSION=`$PGCONFIG --version` +PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION" + +PGSQL_PKGLIBDIR=`$PGCONFIG --pkglibdir` +PGSQL_LIBDIR=`$PGCONFIG --libdir` +PGSQL_SHAREDIR=`$PGCONFIG --sharedir` + +AC_MSG_RESULT([checking PostgreSQL version... $PGSQL_FULL_VERSION]) +dnl Ensure that we are using PostgreSQL >= 9.0 +if test ! "$PGSQL_MAJOR_VERSION" -ge 9; then + AC_MSG_ERROR([PointCloud requires PostgreSQL >= 9.0]) +fi + +dnl Extract the linker and include flags for the frontend (for programs that use libpq) +PGSQL_FE_LDFLAGS=-L`$PGCONFIG --libdir`" -lpq" +PGSQL_FE_CPPFLAGS=-I`$PGCONFIG --includedir` + +AC_SUBST([PGSQL_FE_LDFLAGS]) +AC_SUBST([PGSQL_FE_CPPFLAGS]) + +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([PGSQL_VERSION], [$PGSQL_VERSION], [PostgreSQL server version]) +AC_SUBST([PGSQL_VERSION]) + + +dnl =========================================================================== +dnl Detect LibXML2 +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 +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])]) +CPPFLAGS="$CPPFLAGS_SAVE" + +dnl Ensure we can link against libxml2 +LIBS_SAVE="$LIBS" +LIBS="$XML2_LDFLAGS" +AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], []) +LIBS="$LIBS_SAVE" + +AC_DEFINE_UNQUOTED([LIBXML2_VERSION], ["$LIBXML2_VERSION"], [PointCloud libxml2 version]) +AC_SUBST([LIBXML2_VERSION]) + + +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 + AC_MSG_ERROR([you must specify a parameter to --with-projdir, e.g. --with-projdir=/path/to]) + else + if test -d "$PROJDIR"; then + AC_MSG_RESULT([Using user-specified proj directory: $PROJDIR]) + + dnl Add the include directory to PROJ_CPPFLAGS + PROJ_CPPFLAGS="-I$PROJDIR/include" + PROJ_LDFLAGS="-L$PROJDIR/lib" + 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([PROJ_VERSION]) +AC_DEFINE_UNQUOTED([PROJ_VERSION], [$PROJ_VERSION], [PROJ library version]) +AC_SUBST([PROJ_VERSION]) +CPPFLAGS="$CPPFLAGS_SAVE" + +AC_SUBST([PROJ_CPPFLAGS]) +AC_SUBST([PROJ_LDFLAGS]) + +dnl Ensure that we are using PROJ >= 4.6.0 (requires pj_set_searchpath) +if test ! "$PROJ_VERSION" -ge 46; then + AC_MSG_ERROR([PointCloud requires PROJ >= 4.6.0]) +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" + + +dnl =========================================================================== +dnl Output the relevant files +dnl =========================================================================== + +AC_OUTPUT([ + core/Makefile + core/cunit/Makefile +]) + +dnl =========================================================================== +dnl Display the configuration status information +dnl =========================================================================== + +AC_MSG_RESULT() +AC_MSG_RESULT([ PointCloud is now configured for ${host}]) +AC_MSG_RESULT() +AC_MSG_RESULT([ -------------- Compiler Info ------------- ]) +AC_MSG_RESULT([ C compiler: ${CC} ${CFLAGS}]) +AC_MSG_RESULT() +AC_MSG_RESULT([ -------------- Dependencies -------------- ]) +AC_MSG_RESULT([ PostgreSQL config: ${PGCONFIG}]) +AC_MSG_RESULT([ PostgreSQL version: ${PGSQL_FULL_VERSION}]) +AC_MSG_RESULT([ PROJ4 version: ${PROJ_VERSION}]) +AC_MSG_RESULT([ Libxml2 config: ${XML2CONFIG}]) +AC_MSG_RESULT([ Libxml2 version: ${LIBXML2_VERSION}]) +AC_MSG_RESULT() diff --git a/core/Makefile b/libpc/Makefile similarity index 100% rename from core/Makefile rename to libpc/Makefile diff --git a/core/cunit/.gitignore b/libpc/cunit/.gitignore similarity index 100% rename from core/cunit/.gitignore rename to libpc/cunit/.gitignore diff --git a/core/cunit/Makefile b/libpc/cunit/Makefile similarity index 100% rename from core/cunit/Makefile rename to libpc/cunit/Makefile diff --git a/core/cunit/cu_pc_schema.c b/libpc/cunit/cu_pc_schema.c similarity index 100% rename from core/cunit/cu_pc_schema.c rename to libpc/cunit/cu_pc_schema.c diff --git a/core/cunit/cu_tester.c b/libpc/cunit/cu_tester.c similarity index 100% rename from core/cunit/cu_tester.c rename to libpc/cunit/cu_tester.c diff --git a/core/cunit/cu_tester.h b/libpc/cunit/cu_tester.h similarity index 100% rename from core/cunit/cu_tester.h rename to libpc/cunit/cu_tester.h diff --git a/core/cunit/data/pdal-schema.xml b/libpc/cunit/data/pdal-schema.xml similarity index 100% rename from core/cunit/data/pdal-schema.xml rename to libpc/cunit/data/pdal-schema.xml diff --git a/core/hashtable.c b/libpc/hashtable.c similarity index 100% rename from core/hashtable.c rename to libpc/hashtable.c diff --git a/core/hashtable.h b/libpc/hashtable.h similarity index 100% rename from core/hashtable.h rename to libpc/hashtable.h diff --git a/core/pc_api.h b/libpc/pc_api.h similarity index 100% rename from core/pc_api.h rename to libpc/pc_api.h diff --git a/core/pc_api_internal.h b/libpc/pc_api_internal.h similarity index 100% rename from core/pc_api_internal.h rename to libpc/pc_api_internal.h diff --git a/core/pc_core.c b/libpc/pc_core.c similarity index 100% rename from core/pc_core.c rename to libpc/pc_core.c diff --git a/core/pc_mem.c b/libpc/pc_mem.c similarity index 100% rename from core/pc_mem.c rename to libpc/pc_mem.c diff --git a/core/pc_point.c b/libpc/pc_point.c similarity index 100% rename from core/pc_point.c rename to libpc/pc_point.c diff --git a/core/pc_schema.c b/libpc/pc_schema.c similarity index 100% rename from core/pc_schema.c rename to libpc/pc_schema.c diff --git a/core/pc_util.c b/libpc/pc_util.c similarity index 100% rename from core/pc_util.c rename to libpc/pc_util.c diff --git a/core/pc_val.c b/libpc/pc_val.c similarity index 100% rename from core/pc_val.c rename to libpc/pc_val.c diff --git a/core/stringbuffer.c b/libpc/stringbuffer.c similarity index 100% rename from core/stringbuffer.c rename to libpc/stringbuffer.c diff --git a/core/stringbuffer.h b/libpc/stringbuffer.h similarity index 100% rename from core/stringbuffer.h rename to libpc/stringbuffer.h diff --git a/macros/ac_proj4_version.m4 b/macros/ac_proj4_version.m4 new file mode 100644 index 0000000..796ee5c --- /dev/null +++ b/macros/ac_proj4_version.m4 @@ -0,0 +1,42 @@ +dnl ********************************************************************** +dnl * $Id: ac_proj4_version.m4 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 ********************************************************************** + +dnl +dnl Return the PROJ.4 version number +dnl + +AC_DEFUN([AC_PROJ_VERSION], [ + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([ + #ifdef HAVE_STDINT_H + #include + #endif + #include "proj_api.h" + ], + [ + FILE *fp; + + fp = fopen("conftest.out", "w"); + fprintf(fp, "%d\n", PJ_VERSION); + fclose(fp)]) + ], + [ + dnl The program ran successfully, so return the version number in the form MAJORMINOR + $1=`cat conftest.out | sed 's/\([[0-9]]\)\([[0-9]]\)\([[0-9]]\)/\1\2/'` + ], + [ + dnl The program failed so return an empty variable + $1="" + ] + ) +]) + diff --git a/postgis/Makefile b/postgis/Makefile index 1f0e9b9..8f3a893 100644 --- a/postgis/Makefile +++ b/postgis/Makefile @@ -9,7 +9,7 @@ DATA = pointcloud--1.0.sql REGRESS = pointcloud -SHLIB_LINK += $(filter -lm, $(LIBS)) ../core/libpc.a +SHLIB_LINK += $(filter -lm, $(LIBS)) ../libpc/libpc.a # We are going to use PGXS for sure PG_CONFIG = pg_config