From: Arran Cudbard-Bell Date: Fri, 31 Jul 2015 20:00:07 +0000 (-0400) Subject: Search for json headers in multiple locations Closes #794 X-Git-Tag: release_3_0_10~269 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7832d9f273ad4fa24714fd7eaac1d81f3b200eac;p=thirdparty%2Ffreeradius-server.git Search for json headers in multiple locations Closes #794 --- diff --git a/src/modules/rlm_rest/config.h.in b/src/modules/rlm_rest/config.h.in index 6952dd1846a..0a3a6de5e43 100644 --- a/src/modules/rlm_rest/config.h.in +++ b/src/modules/rlm_rest/config.h.in @@ -3,9 +3,15 @@ /* Build with JSON support from json-c */ #undef HAVE_JSON +/* json.h is at json-c/json.h relative to include dir */ +#undef HAVE_JSONMC_JSON_H + /* Define to 1 if you have the `json_c_version' function. */ #undef HAVE_JSON_C_VERSION +/* json.h is at json/json.h relative to include dir */ +#undef HAVE_JSON_JSON_H + /* Define to 1 if you have the `json_type_to_name' function. */ #undef HAVE_JSON_TYPE_TO_NAME diff --git a/src/modules/rlm_rest/configure b/src/modules/rlm_rest/configure index 189b7ffe804..04891c695ea 100755 --- a/src/modules/rlm_rest/configure +++ b/src/modules/rlm_rest/configure @@ -3562,9 +3562,246 @@ fi smart_prefix= if test "x$ac_cv_header_json_json_h" != "xyes"; then - have_json="no" - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&5 + + +ac_safe=`echo "json-c/json.h" | sed 'y%./+-%__pm%'` +old_CPPFLAGS="$CPPFLAGS" +smart_include= +smart_include_dir="/usr/local/include /opt/include" + +_smart_try_dir= +_smart_include_dir= + +for _prefix in $smart_prefix ""; do + for _dir in $smart_try_dir; do + _smart_try_dir="${_smart_try_dir} ${_dir}/${_prefix}" + done + + for _dir in $smart_include_dir; do + _smart_include_dir="${_smart_include_dir} ${_dir}/${_prefix}" + done +done + +if test "x$_smart_try_dir" != "x"; then + for try in $_smart_try_dir; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h in $try" >&5 +$as_echo_n "checking for json-c/json.h in $try... " >&6; } + CPPFLAGS="-isystem $try $old_CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem $try" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done + CPPFLAGS="$old_CPPFLAGS" +fi + +if test "x$smart_include" = "x"; then + for _prefix in $smart_prefix; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/json-c/json.h" >&5 +$as_echo_n "checking for ${_prefix}/json-c/json.h... " >&6; } + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem ${_prefix}/" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +fi + +if test "x$smart_include" = "x"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h" >&5 +$as_echo_n "checking for json-c/json.h... " >&6; } + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include=" " + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +if test "x$smart_include" = "x"; then + + for prefix in $smart_prefix; do + + +if test "x$LOCATE" != "x"; then + DIRS= + file="${_prefix}/${1}" + + for x in `${LOCATE} $file 2>/dev/null`; do + base=`echo $x | sed "s%/${file}%%"` + if test "x$x" = "x$base"; then + continue; + fi + + dir=`${DIRNAME} $x 2>/dev/null` + exclude=`echo ${dir} | ${GREP} /home` + if test "x$exclude" != "x"; then + continue + fi + + already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}` + if test "x$already" = "x"; then + DIRS="$DIRS $dir" + fi + done +fi + +eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" + + done + + +if test "x$LOCATE" != "x"; then + DIRS= + file=json-c/json.h + + for x in `${LOCATE} $file 2>/dev/null`; do + base=`echo $x | sed "s%/${file}%%"` + if test "x$x" = "x$base"; then + continue; + fi + + dir=`${DIRNAME} $x 2>/dev/null` + exclude=`echo ${dir} | ${GREP} /home` + if test "x$exclude" != "x"; then + continue + fi + + already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}` + if test "x$already" = "x"; then + DIRS="$DIRS $dir" + fi + done +fi + +eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\"" + + + for try in $_smart_include_dir; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for json-c/json.h in $try" >&5 +$as_echo_n "checking for json-c/json.h in $try... " >&6; } + CPPFLAGS="-isystem $try $old_CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include +int +main () +{ +int a = 1; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + smart_include="-isystem $try" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + +else + + smart_include= + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done + CPPFLAGS="$old_CPPFLAGS" +fi + +if test "x$smart_include" != "x"; then + eval "ac_cv_header_$ac_safe=yes" + CPPFLAGS="$smart_include $old_CPPFLAGS" + SMART_CPPFLAGS="$smart_include $SMART_CPPFLAGS" +fi + +smart_prefix= + + if test "x$ac_cv_header_jsonmc_json_h" != "xyes"; then + have_json="no" + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&5 $as_echo "$as_me: WARNING: json-c headers not found. Use --with-jsonc-include-dir=." >&2;} + fail="$fail json.h" + else + +$as_echo "#define HAVE_JSONMC_JSON_H 1" >>confdefs.h + + fi + else + +$as_echo "#define HAVE_JSON_JSON_H 1" >>confdefs.h + fi diff --git a/src/modules/rlm_rest/configure.ac b/src/modules/rlm_rest/configure.ac index e38f4e48c76..958da818dce 100644 --- a/src/modules/rlm_rest/configure.ac +++ b/src/modules/rlm_rest/configure.ac @@ -99,8 +99,16 @@ if test x$with_[]modname != xno; then smart_try_dir="$jsonc_include_dir" FR_SMART_CHECK_INCLUDE([json/json.h]) if test "x$ac_cv_header_json_json_h" != "xyes"; then - have_json="no" - AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=.]) + FR_SMART_CHECK_INCLUDE([json-c/json.h]) + if test "x$ac_cv_header_jsonmc_json_h" != "xyes"; then + have_json="no" + AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=.]) + fail="$fail json.h" + else + AC_DEFINE([HAVE_JSONMC_JSON_H],[1],[json.h is at json-c/json.h relative to include dir]) + fi + else + AC_DEFINE([HAVE_JSON_JSON_H],[1],[json.h is at json/json.h relative to include dir]) fi dnl ############################################################ diff --git a/src/modules/rlm_rest/rest.h b/src/modules/rlm_rest/rest.h index e09f0193b27..eee846e8ec0 100644 --- a/src/modules/rlm_rest/rest.h +++ b/src/modules/rlm_rest/rest.h @@ -35,8 +35,10 @@ RCSIDH(other_h, "$Id$") #define CURL_NO_OLDIES 1 #include -#ifdef HAVE_JSON -#include +#if defined(HAVE_JSONMC_JSON_H) +# include +#elif defined(HAVE_JSON_JSON_H) +# include #endif #define REST_URI_MAX_LEN 2048