From c8c98e13ab6033de86f5505d67d6927d5fffd6fe Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Tue, 27 May 2008 14:47:06 +0000 Subject: [PATCH] Update new build system to include iconv detection for shp2pgsql git-svn-id: http://svn.osgeo.org/postgis/trunk@2784 b70326c6-7e19-0410-871a-916f4a2858ee --- configure.in | 46 ++++++++++++++++++- ...kefile.shp2pgsql => Makefile.shp2pgsql.in} | 3 ++ loader/shp2pgsql.c | 30 ++++++------ postgis_config.h.in | 3 ++ 4 files changed, 66 insertions(+), 16 deletions(-) rename loader/{Makefile.shp2pgsql => Makefile.shp2pgsql.in} (77%) diff --git a/configure.in b/configure.in index e280e6635..be263e986 100644 --- a/configure.in +++ b/configure.in @@ -54,6 +54,7 @@ if test "x$XSLBASE" = "x"; then done fi + dnl For XSLBASE, make sure the directory exists and that it contains html/docbook.xsl if test ! -d "$XSLBASE"; then AC_MSG_ERROR([the docbook stylesheet directory specified using --with-xsldir does not exist]) @@ -66,6 +67,49 @@ fi AC_SUBST([XSLBASE]) +dnl +dnl Detect iconv if it is installed (used for shp2pgsql encoding conversion if available) +dnl + +LIBS_SAVE="$LIBS" +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" != "x0"; then + dnl Check for iconv includes as part of libc + AC_CHECK_LIB([c], [iconv_open], [HAVE_ICONV=1], []) + if test "x$HAVE_ICONV" = "x"; then + dnl If not found, check for iconv included as part of libiconv + AC_CHECK_LIB([iconv], [iconv_open], [HAVE_ICONV=1], []) + if test "x$HAVE_ICONV" = "x"; then + dnl If not found, check for Win32 iconv (some of them use a lib prefix for functions within the iconv DLLs) + AC_CHECK_LIB([iconv], [libiconv_open], [HAVE_ICONV=1], []) + if test "x$HAVE_ICONV" = "x"; then + dnl No iconv library was found; issue a warning to the console + AC_MSG_WARN([could not find iconv library: no support for encoding conversion will be included]) + else + ICONV_LDFLAGS="$LIBS" + fi + else + ICONV_LDFLAGS="$LIBS" + fi + fi +else + dnl No iconv header was found; issue a warning to the console + AC_MSG_WARN([could not find iconv.h header: no support for encoding conversion will be included]) +fi + +LIBS="$LIBS_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]) + + dnl dnl Detect the version of PostgreSQL installed on the system dnl @@ -295,5 +339,5 @@ AC_SUBST([SHLIB_LINK]) dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK]) dnl Output the relevant files -AC_OUTPUT([lwgeom/Makefile lwgeom/sqldefines.h loader/Makefile.pgsql2shp regress/Makefile doc/Makefile]) +AC_OUTPUT([lwgeom/Makefile lwgeom/sqldefines.h loader/Makefile.pgsql2shp loader/Makefile.shp2pgsql regress/Makefile doc/Makefile]) diff --git a/loader/Makefile.shp2pgsql b/loader/Makefile.shp2pgsql.in similarity index 77% rename from loader/Makefile.shp2pgsql rename to loader/Makefile.shp2pgsql.in index ee5f89960..0e4f36189 100644 --- a/loader/Makefile.shp2pgsql +++ b/loader/Makefile.shp2pgsql.in @@ -9,6 +9,9 @@ OBJS= shpopen.o \ getopt.o \ shp2pgsql.o +# Link against libiconv where available +PG_LIBS=@ICONV_LDFLAGS@ + # PGXS information PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/loader/shp2pgsql.c b/loader/shp2pgsql.c index 847aeb72a..cb747a9d1 100644 --- a/loader/shp2pgsql.c +++ b/loader/shp2pgsql.c @@ -33,7 +33,7 @@ #include #include #include "getopt.h" -#ifdef HAVE_ICONV_H +#ifdef HAVE_ICONV #include #endif @@ -82,7 +82,7 @@ int pgdims; unsigned int wkbtype; char *shp_file = NULL; int hwgeom = 0; /* old (hwgeom) mode */ -#ifdef USE_ICONV +#ifdef HAVE_ICONV char *encoding=NULL; #endif int null_policy = insert_null; @@ -118,7 +118,7 @@ void InsertLineStringWKT(int id); int ParseCmdline(int ARGC, char **ARGV); void SetPgType(void); char *dump_ring(Ring *ring); -#ifdef USE_ICONV +#ifdef HAVE_ICONV char *utf8(const char *fromcode, char *inputbuf); #endif int FindPolygons(SHPObject *obj, Ring ***Out); @@ -170,7 +170,7 @@ make_good_string(char *str) char *ptr, *optr; int toescape = 0; size_t size; -#ifdef USE_ICONV +#ifdef HAVE_ICONV char *utf8str=NULL; if ( encoding ) @@ -202,7 +202,7 @@ make_good_string(char *str) } *optr='\0'; -#ifdef USE_ICONV +#ifdef HAVE_ICONV if ( encoding ) free(str); #endif @@ -225,7 +225,7 @@ protect_quotes_string(char *str) char *ptr, *optr; int toescape = 0; size_t size; -#ifdef USE_ICONV +#ifdef HAVE_ICONV char *utf8str=NULL; if ( encoding ) @@ -258,7 +258,7 @@ protect_quotes_string(char *str) } *optr='\0'; -#ifdef USE_ICONV +#ifdef HAVE_ICONV if ( encoding ) free(str); #endif @@ -412,12 +412,12 @@ main (int ARGC, char **ARGV) fprintf(stderr, "Postgis type: %s[%d]\n", pgtype, pgdims); } -#ifdef USE_ICONV +#ifdef HAVE_ICONV if ( encoding ) { printf("SET CLIENT_ENCODING TO UTF8;\n"); } -#endif /* defined USE_ICONV */ +#endif /* defined HAVE_ICONV */ /* * Drop table if requested @@ -802,7 +802,7 @@ usage(char *me, int exitcode, FILE* out) fprintf(out, " -I Create a GiST index on the geometry column.\n"); fprintf(out, " -S Generate simple geometries instead of MULTI geometries.\n"); fprintf(out, " -w Use wkt format (for postgis-0.x support - drops M - drifts coordinates).\n"); -#ifdef USE_ICONV +#ifdef HAVE_ICONV fprintf(out, " -W Specify the character encoding of Shape's\n"); fprintf(out, " attribute column. (default : \"ASCII\")\n"); #endif @@ -1376,7 +1376,7 @@ ParseCmdline(int ARGC, char **ARGV) readshape = 0; break; case 'W': -#ifdef USE_ICONV +#ifdef HAVE_ICONV encoding = optarg; #else fprintf(stderr, "WARNING: the -W switch will have no effect. UTF8 disabled at compile time\n"); @@ -1681,7 +1681,7 @@ GetFieldsSpec(void) char name[MAXFIELDNAMELEN]; char name2[MAXFIELDNAMELEN]; DBFFieldType type = -1; -#ifdef USE_ICONV +#ifdef HAVE_ICONV char *utf8str; #endif @@ -1710,7 +1710,7 @@ GetFieldsSpec(void) widths[j] = field_width; precisions[j] = field_precision; -#ifdef USE_ICONV +#ifdef HAVE_ICONV if ( encoding ) { utf8str = utf8(encoding, name); @@ -1778,7 +1778,7 @@ GetFieldsSpec(void) strcat(col_names, ")"); } -#ifdef USE_ICONV +#ifdef HAVE_ICONV char * utf8 (const char *fromcode, char *inputbuf) @@ -1820,7 +1820,7 @@ utf8 (const char *fromcode, char *inputbuf) return outputbuf; } -#endif /* defined USE_ICONV */ +#endif /* defined HAVE_ICONV */ /********************************************************************** * $Log$ diff --git a/postgis_config.h.in b/postgis_config.h.in index 2e9547a17..8b7979574 100644 --- a/postgis_config.h.in +++ b/postgis_config.h.in @@ -1,5 +1,8 @@ /* postgis_config.h.in. Generated from configure.in by autoheader. */ +/* Defined if libiconv headers and library are present */ +#undef HAVE_ICONV + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -- 2.50.1