]> granicus.if.org Git - postgis/commitdiff
Update new build system to include iconv detection for shp2pgsql
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Tue, 27 May 2008 14:47:06 +0000 (14:47 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Tue, 27 May 2008 14:47:06 +0000 (14:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@2784 b70326c6-7e19-0410-871a-916f4a2858ee

configure.in
loader/Makefile.shp2pgsql.in [moved from loader/Makefile.shp2pgsql with 77% similarity]
loader/shp2pgsql.c
postgis_config.h.in

index e280e66357ba0f9b1eadacdcf3f436fa7f33b576..be263e98650cf7646dfeca9476b9cbc2c573082a 100644 (file)
@@ -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])
 
similarity index 77%
rename from loader/Makefile.shp2pgsql
rename to loader/Makefile.shp2pgsql.in
index ee5f899608e6012f2077ed2117cd725945d17025..0e4f36189162a7ad955799a6072a17d2d80d6a3e 100644 (file)
@@ -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)
index 847aeb72ad9e96bc3e3b830ecb2251cbaa5afc92..cb747a9d14bdc5462d16845388cbccdb12b3f0d3 100644 (file)
@@ -33,7 +33,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include "getopt.h"
-#ifdef HAVE_ICONV_H
+#ifdef HAVE_ICONV
 #include <iconv.h>
 #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 <encoding> 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$
index 2e9547a17c19ec5f2512b5e2f75a7d5f83287359..8b79795743f3d314bb5435b40e2759fb6802f44f 100644 (file)
@@ -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 <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H