1dnl Check for libjson
2
3have_json_header="no"
4AC_MSG_CHECKING([for libjson installation])
5
6AC_ARG_WITH([libjson], [AS_HELP_STRING([--with-libjson@<:@=DIR@:>@], [path to directory containing libjson
7                        @<:@default=/usr/local or /usr if not found in /usr/local@:>@])],
8    [
9        find_json="no"
10        if test "X$withval" = "Xyes"; then
11            find_json="yes"
12        else
13            if test "X$withval" != "Xno"; then
14                if test -f "${withval}/include/json/json.h" -o -f "${withval}/include/json-c/json.h"; then
15                    LIBJSON_HOME="$withval"
16                    have_json_header="yes"
17                fi
18            fi
19        fi
20    ],
21    [find_json="yes"]
22)
23
24if test "X$find_json" = "Xyes"; then
25    for p in /usr/local /usr ; do
26        if test -f "${p}/include/json/json.h" -o -f "${p}/include/json-c/json.h"; then
27            LIBJSON_HOME=$p
28            have_json_header="yes"
29        fi
30    done
31fi
32
33if test "X$have_json_header" = "Xyes"; then
34    AC_MSG_RESULT([$LIBJSON_HOME])
35    if test -f "$LIBJSON_HOME/include/json/json.h"
36    then
37        JSON_INCLUDE="include/json"
38    fi
39    if test -f "$LIBJSON_HOME/include/json-c/json.h"
40    then
41        JSON_INCLUDE="include/json-c"
42    fi
43    if test -z $JSON_INCLUDE
44    then
45        AC_MSG_WARN([json header lost.])
46    fi
47
48    JSON_CPPFLAGS="-I$LIBJSON_HOME/$JSON_INCLUDE"
49    save_LDFLAGS="$LDFLAGS"
50    save_CFLAGS="$CFLAGS"
51    save_LIBS="$LIBS"
52    LIBS=""
53    JSON_LIBS=""
54    if test "$LIBJSON_HOME" != "/usr"
55    then
56        JSON_LDFLAGS="-L$LIBJSON_HOME/lib"
57        LDFLAGS="$LDFLAGS $JSON_LDFLAGS"
58        CFLAGS="$CFLAGS $JSON_CPPFLAGS"
59    fi
60
61    AC_CHECK_LIB([json-c], [json_object_object_get_ex],
62        [
63            dnl Found
64            have_json="yes"
65            have_deprecated_json="no"
66            json_libname="json-c"
67        ],
68        [
69            dnl Not-Found
70            AC_CHECK_LIB([json], [json_object_object_get_ex],
71                [
72                    dnl Found
73                    have_json="yes"
74                    have_deprecated_json="no"
75                    json_libname="json"
76                ],
77                [
78                    dnl Not-Found
79                    AC_CHECK_LIB([json-c], [json_object_object_get],
80                        [
81                            dnl Found
82                            have_json="yes"
83                            have_deprecated_json="yes"
84                            json_libname="json-c"
85                        ],
86                        [
87                            dnl Not-Found
88                            AC_CHECK_LIB([json], [json_object_object_get],
89                                [
90                                    dnl Found
91                                    have_json="yes"
92                                    have_deprecated_json="yes"
93                                    json_libname="json"
94                                ],
95                                [
96                                    dnl Not-Found
97                                    have_json="no"
98                                    AC_MSG_ERROR([Unable to find libjson library.])
99                                ]
100                            )
101                        ]
102                    )
103                ]
104            )
105        ]
106    )
107
108    CFLAGS="$save_CFLAGS"
109    LDFLAGS="$save_LDFLAGS"
110fi
111
112if test "X$have_json" = "Xyes"; then
113    AC_DEFINE([HAVE_JSON],1,[Define to 1 if you have the 'libjson' library (-ljson).])
114    if test "X$have_deprecated_json" = "Xyes"; then
115        AC_DEFINE([HAVE_DEPRECATED_JSON],1,[Define to 1 if you have a deprecated version of the 'libjson' library (-ljson).])
116    fi
117
118    dnl Determine linking method to json
119    AC_ARG_WITH([libjson-static],
120        [AC_HELP_STRING([--with-libjson-static=FILE],[full file path for libjson-c.a static library])],
121        [
122            json_linking="static"
123            JSON_LIBS="$withval $LIBS"
124        ],
125        [
126            json_linking="dynamic"
127            JSON_LIBS="-l${json_libname} $LIBS"
128        ]
129    )
130fi
131
132LIBS="$save_LIBS"
133