From 0698eb93f6e618d2882ae2c8758c5fa87524bea6 Mon Sep 17 00:00:00 2001
From: Petr Mensik <pemensik@redhat.com>
Date: Tue, 23 Jul 2019 12:10:39 +0200
Subject: [PATCH] Allow explicitly using json-c but not libjson

Separate detection of json support. Allows explicit use of json-c when
jsoncpp package is found. Have to use --without-libjson --with-json-c.
---
 configure.ac | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index f7978e4..40b4f9f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1331,7 +1331,6 @@ AC_ARG_WITH(libjson,
 	    use_libjson="$withval", use_libjson="auto")
 
 have_libjson=""
-have_libjson_c=""
 case "$use_libjson" in
 	no)
 		libjson_libs=""
@@ -1347,7 +1346,43 @@ case "$use_libjson" in
 					LIBS="$LIBS -L${d}/lib"
 				fi
 				have_libjson="yes"
-			elif test -f "${d}/include/json-c/json.h"
+			fi
+		done
+		;;
+	*)
+		if test -f "${use_libjson}/include/json/json.h"
+		then
+			libjson_cflags="-I${use_libjson}/include"
+			LIBS="$LIBS -L${use_libjson}/lib"
+			have_libjson="yes"
+		else
+			AC_MSG_ERROR([$use_libjson/include/json/json.h not found.])
+		fi
+		;;
+esac
+
+#
+# was --with-json-c specified?
+#
+AC_ARG_WITH(json-c,
+	    AS_HELP_STRING([--with-json-c[=PATH]],
+			   [build with json-c library [yes|no|path]]),
+	    use_json_c="$withval", use_json_c="$use_libjson")
+
+if test "X${have_libjson}" != "X"
+then
+	# Do not use if libjson were found
+	use_json_c=no
+fi
+
+have_libjson_c=""
+case "$use_json_c" in
+	no)
+		;;
+	auto|yes)
+		for d in /usr /usr/local /opt/local
+		do
+			if test -f "${d}/include/json-c/json.h"
 			then
 				if test ${d} != /usr
 				then
@@ -1360,19 +1395,14 @@ case "$use_libjson" in
 		done
 		;;
 	*)
-		if test -f "${use_libjson}/include/json/json.h"
-		then
-			libjson_cflags="-I${use_libjson}/include"
-			LIBS="$LIBS -L${use_libjson}/lib"
-			have_libjson="yes"
-		elif test -f "${use_libjson}/include/json-c/json.h"
+		if test -f "${use_json_c}/include/json-c/json.h"
 		then
-			libjson_cflags="-I${use_libjson}/include"
-			LIBS="$LIBS -L${use_libjson}/lib"
+			libjson_cflags="-I${use_json_c}/include"
+			LIBS="$LIBS -L${use_json_c}/lib"
 			have_libjson="yes"
 			have_libjson_c="yes"
 		else
-			AC_MSG_ERROR([$use_libjson/include/json{,-c}/json.h not found.])
+			AC_MSG_ERROR([$use_json_c/include/json-c/json.h not found.])
 		fi
 		;;
 esac
-- 
2.20.1

