x_ac_json.m4 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ##*****************************************************************************
  2. # AUTHOR:
  3. # Derived from x_ac_munge.
  4. #
  5. # SYNOPSIS:
  6. # X_AC_JSON()
  7. #
  8. # DESCRIPTION:
  9. # Check for JSON parser libraries.
  10. # Right now, just check for json-c header and library.
  11. #
  12. # WARNINGS:
  13. # This macro must be placed after AC_PROG_CC and before AC_PROG_LIBTOOL.
  14. ##*****************************************************************************
  15. AC_DEFUN([X_AC_JSON], [
  16. _x_ac_json_dirs="/usr /usr/local"
  17. _x_ac_json_libs="lib64 lib"
  18. AC_ARG_WITH(
  19. [json],
  20. AS_HELP_STRING(--with-json=PATH,Specify path to json-c installation),
  21. [AS_IF([test "x$with_json" != xno],[_x_ac_json_dirs="$with_json $_x_ac_json_dirs"])])
  22. if [test "x$with_json" = xno]; then
  23. AC_MSG_WARN([support for json disabled])
  24. else
  25. AC_CACHE_CHECK(
  26. [for json installation],
  27. [x_ac_cv_json_dir],
  28. [
  29. for d in $_x_ac_json_dirs; do
  30. test -d "$d" || continue
  31. test -d "$d/include" || continue
  32. test -f "$d/include/json-c/json_object.h" || test -f "$d/include/json/json_object.h" || continue
  33. for bit in $_x_ac_json_libs; do
  34. test -d "$d/$bit" || continue
  35. _x_ac_json_libs_save="$LIBS"
  36. LIBS="-L$d/$bit -ljson-c $LIBS"
  37. AC_LINK_IFELSE(
  38. [AC_LANG_CALL([], json_tokener_parse)],
  39. AS_VAR_SET(x_ac_cv_json_dir, $d))
  40. LIBS="$_x_ac_json_libs_save"
  41. test -n "$x_ac_cv_json_dir" && break
  42. done
  43. test -n "$x_ac_cv_json_dir" && break
  44. done
  45. ])
  46. if test -z "$x_ac_cv_json_dir"; then
  47. AC_MSG_WARN([unable to locate json parser library])
  48. else
  49. if test -f "$d/include/json-c/json_object.h" ; then
  50. AC_DEFINE([HAVE_JSON_C_INC], [1], [Define if headers in include/json-c.])
  51. fi
  52. if test -f "$d/include/json/json_object.h" ; then
  53. AC_DEFINE([HAVE_JSON_INC], [1], [Define if headers in include/json.])
  54. fi
  55. AC_DEFINE([HAVE_JSON], [1], [Define if you are compiling with json.])
  56. JSON_CPPFLAGS="-I$x_ac_cv_json_dir/include"
  57. JSON_LDFLAGS="-L$x_ac_cv_json_dir/$bit -ljson-c"
  58. fi
  59. AC_SUBST(JSON_CPPFLAGS)
  60. AC_SUBST(JSON_LDFLAGS)
  61. fi
  62. AM_CONDITIONAL(WITH_JSON_PARSER, test -n "$x_ac_cv_json_dir")
  63. ])