Description: Adjust to the rename of json to json-c
 Tweak configure to not only detect json-c, but set different
 variables in case the new variant is found. Adjust other files to
 conditionally use the new variant.
Forwarded: yes
Bug-Upstream: http://trac.osgeo.org/postgis/ticket/2723
Author: Markus Wanner <markus@bluegap.ch>
Last-Update: 2013-05-12

--- a/configure.ac
+++ b/configure.ac
@@ -113,9 +113,9 @@ dnl
 dnl Check for platform-specific functions
 dnl
 AC_CHECK_FUNC(vasprintf, [HAVE_VASPRINTF=1], [HAVE_VASPRINTF=0])
-AC_DEFINE([HAVE_VASPRINTF])
+AC_DEFINE_UNQUOTED([HAVE_VASPRINTF], [$HAVE_VASPRINTF], [vasprintf function])
 AC_CHECK_FUNC(asprintf, [HAVE_ASPRINTF=1], [HAVE_ASPRINTF=0])
-AC_DEFINE([HAVE_ASPRINTF])
+AC_DEFINE_UNQUOTED([HAVE_ASPRINTF], [$HAVE_ASPRINTF], [asprintf function])
 AC_FUNC_FSEEKO()
 
 dnl 
@@ -751,6 +751,7 @@ dnl ====================================
 
 CHECK_JSON=yes
 HAVE_JSON=no
+HAVE_JSON_C=no
 
 AC_ARG_WITH([json],
 	[AS_HELP_STRING([--without-json], [build without json-c support])],
@@ -788,14 +789,14 @@ fi
 dnl Check that we can find the json/json.h header file
 CPPFLAGS_SAVE="$CPPFLAGS"
 CPPFLAGS="$JSON_CPPFLAGS"
-AC_CHECK_HEADER([json-c/json.h], [HAVE_JSON=yes], [
+AC_CHECK_HEADER([json-c/json.h], [HAVE_JSON_C=yes], [
   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"
-AC_CHECK_LIB([json-c], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson-c"], [
+AC_CHECK_LIB([json-c], [json_object_get], [HAVE_JSON_C=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson-c"], [
   AC_CHECK_LIB([json], [json_object_get], [HAVE_JSON=yes; JSON_LDFLAGS="${JSON_LDFLAGS} -ljson"], [], [])
 ], [])
 LIBS="$LIBS_SAVE"
@@ -804,9 +805,14 @@ if test "$HAVE_JSON" = "yes"; then
 	AC_DEFINE([HAVE_LIBJSON], 1, [Define to 1 if libjson is present])
 fi
 
+if test "$HAVE_JSON_C" = "yes"; then
+	AC_DEFINE([HAVE_LIBJSON_C], 1, [Define to 1 if libjson-c is present])
+fi
+
 AC_SUBST([JSON_CPPFLAGS])
 AC_SUBST([JSON_LDFLAGS])
 AC_SUBST([HAVE_JSON])
+AC_SUBST([HAVE_JSON_C])
 
 fi dnl }
 
--- a/liblwgeom/lwin_geojson.c
+++ b/liblwgeom/lwin_geojson.c
@@ -15,10 +15,15 @@
 #include "lwgeom_log.h"
 #include "../postgis_config.h"
 
-#ifdef HAVE_LIBJSON
+#if defined(HAVE_LIBJSON_C) || defined(HAVE_LIBJSON)
 
+#if defined(HAVE_LIBJSON_C)
+#include <json-c/json.h>
+#include <json-c/json_object_private.h>
+#else
 #include <json/json.h>
 #include <json/json_object_private.h>
+#endif
 #include <string.h>
 
 static void geojson_lwerror(char *msg, int error_code)
@@ -489,11 +494,11 @@ parse_geojson(json_object *geojson, int
 LWGEOM*
 lwgeom_from_geojson(const char *geojson, char **srs)
 {
-#ifndef HAVE_LIBJSON
+#if !defined(HAVE_LIBJSON_C) && !defined(HAVE_LIBJSON)
   *srs = NULL;
 	lwerror("You need JSON-C for lwgeom_from_geojson");
 	return NULL;
-#else /* HAVE_LIBJSON  */
+#else /* HAVE_LIBJSON_C || HAVE_LIBJSON  */
 
 	/* size_t geojson_size = strlen(geojson); */
 
@@ -547,7 +552,7 @@ lwgeom_from_geojson(const char *geojson,
 	}
 
   return lwgeom;
-#endif /* HAVE_LIBJSON  */
+#endif /* HAVE_LIBJSON_C || HAVE_LIBJSON  */
 }
 
 
--- a/liblwgeom/cunit/cu_tester.c
+++ b/liblwgeom/cunit/cu_tester.c
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
 		surface_suite,
 		homogenize_suite,
 		force_sfs_suite,
-#if HAVE_JSON
+#if defined(HAVE_JSON_C) || defined(HAVE_JSON)
 		in_geojson_suite,
 #endif
 		out_gml_suite,
--- a/regress/Makefile.in
+++ b/regress/Makefile.in
@@ -21,6 +21,7 @@ POSTGIS_PROJ_VERSION=@POSTGIS_PROJ_VERSI
 POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@
 POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 HAVE_JSON=@HAVE_JSON@
+HAVE_JSON_C=@HAVE_JSON_C@
 HAVE_SFCGAL=@HAVE_SFCGAL@
 MINGWBUILD=@MINGWBUILD@
 
--- a/postgis_config.h.in
+++ b/postgis_config.h.in
@@ -54,6 +54,9 @@
 /* Define to 1 if libjson is present */
 #undef HAVE_LIBJSON
 
+/* Define to 1 if libjson-c is present */
+#undef HAVE_LIBJSON_C
+
 /* Define to 1 if you have the `pq' library (-lpq). */
 #undef HAVE_LIBPQ
 
--- a/postgis/lwgeom_in_geojson.c
+++ b/postgis/lwgeom_in_geojson.c
@@ -23,7 +23,7 @@ Datum postgis_libjson_version(PG_FUNCTIO
 PG_FUNCTION_INFO_V1(postgis_libjson_version);
 Datum postgis_libjson_version(PG_FUNCTION_ARGS)
 {
-#ifndef HAVE_LIBJSON
+#if !defined(HAVE_LIBJSON) && !defined(HAVE_LIBJSON_C)
 	PG_RETURN_NULL();
 #else /* HAVE_LIBJSON  */
 	const char *ver = "UNKNOWN";
@@ -35,7 +35,7 @@ Datum postgis_libjson_version(PG_FUNCTIO
 PG_FUNCTION_INFO_V1(geom_from_geojson);
 Datum geom_from_geojson(PG_FUNCTION_ARGS)
 {
-#ifndef HAVE_LIBJSON
+#if !defined(HAVE_LIBJSON) && !defined(HAVE_LIBJSON_C)
 	elog(ERROR, "You need JSON-C for ST_GeomFromGeoJSON");
 	PG_RETURN_NULL();
 #else /* HAVE_LIBJSON  */
