File: x_ac_json.m4

package info (click to toggle)
slurm-wlm 24.11.5-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 51,508 kB
  • sloc: ansic: 529,598; exp: 64,795; python: 17,051; sh: 10,365; javascript: 6,528; makefile: 4,116; perl: 3,762; pascal: 131
file content (75 lines) | stat: -rw-r--r-- 2,454 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
##*****************************************************************************
#  AUTHOR:
#    Derived from x_ac_munge.
#
#  SYNOPSIS:
#    X_AC_JSON()
#
#  DESCRIPTION:
#    Check for JSON parser libraries.
#    Right now, just check for json-c header and library.
#
#  WARNINGS:
#    This macro must be placed after AC_PROG_CC and before AC_PROG_LIBTOOL.
##*****************************************************************************

AC_DEFUN([X_AC_JSON], [

  _x_ac_json_dirs="/usr /usr/local"
  _x_ac_json_libs="lib64 lib"

  AC_ARG_WITH(
    [json],
    AS_HELP_STRING(--with-json=PATH,Specify path to json-c installation),
    [AS_IF([test "x$with_json" != xno && test "x$with_json" != xyes],
	   [_x_ac_json_dirs="$with_json"])])

  if [test "x$with_json" = xno]; then
    AC_MSG_NOTICE([support for json disabled])
  else
    AC_CACHE_CHECK(
      [for json installation],
      [x_ac_cv_json_dir],
      [
        for d in $_x_ac_json_dirs; do
          test -d "$d" || continue
          test -d "$d/include" || continue
          test -f "$d/include/json-c/json_object.h" || test -f "$d/include/json/json_object.h" || continue
          for bit in $_x_ac_json_libs; do
            test -d "$d/$bit" || continue
            _x_ac_json_libs_save="$LIBS"
            LIBS="-L$d/$bit -ljson-c $LIBS"
            AC_LINK_IFELSE(
              [AC_LANG_CALL([], json_tokener_parse)],
              AS_VAR_SET(x_ac_cv_json_dir, $d))
            LIBS="$_x_ac_json_libs_save"
            test -n "$x_ac_cv_json_dir" && break
          done
          test -n "$x_ac_cv_json_dir" && break
        done
      ])

    if test -z "$x_ac_cv_json_dir"; then
      if [test -z "$with_json"] ; then
        AC_MSG_WARN([unable to locate json parser library])
      else
        AC_MSG_ERROR([unable to locate json parser library])
      fi
    else
      if test -f "$d/include/json-c/json_object.h" ; then
        AC_DEFINE([HAVE_JSON_C_INC], [1], [Define if headers in include/json-c.])
      fi
      if test -f "$d/include/json/json_object.h" ; then
        AC_DEFINE([HAVE_JSON_INC], [1], [Define if headers in include/json.])
      fi
      AC_DEFINE([HAVE_JSON], [1], [Define if you are compiling with json.])
      JSON_CPPFLAGS="-I$x_ac_cv_json_dir/include"
      JSON_LDFLAGS="-L$x_ac_cv_json_dir/$bit -ljson-c"
    fi

    AC_SUBST(JSON_CPPFLAGS)
    AC_SUBST(JSON_LDFLAGS)
  fi

  AM_CONDITIONAL(WITH_JSON_PARSER, test -n "$x_ac_cv_json_dir")
])