ae557e9eca18e9ce8979a49a8afec3942fb0c40e
[freeradius.git] / src / modules / rlm_couchbase / configure.ac
1 AC_PREREQ([2.53])
2 AC_INIT(rlm_couchbase.c)
3 AC_REVISION($Revision$)
4 AC_DEFUN(modname,[rlm_couchbase])
5 AC_CONFIG_HEADER(config.h)
6
7 if test x$with_[]modname != xno; then
8
9         AC_PROG_CC
10         AC_PROG_CPP
11
12         dnl put configuration checks here.
13         dnl set $fail to what's missing, on fatal errors.
14         dnl use AC_MSG_WARN() on important messages.
15
16         dnl ############################################################
17         dnl # Check for json-c
18         dnl ############################################################
19
20         dnl extra argument: --with-jsonc-include-dir=DIR
21         jsonc_include_dir=
22         AC_ARG_WITH(jsonc-include-dir,
23                 [AS_HELP_STRING([--with-jsonc-include-dir=DIR],
24                 [Directory where the json-c includes may be found])],
25                 [case "$withval" in
26                         no)
27                                 AC_MSG_ERROR(Need jsonc-include-dir)
28                         ;;
29                         yes)
30                         ;;
31                         *)
32                                 jsonc_include_dir="$withval"
33                         ;;
34                 esac])
35
36         dnl extra argument: --with-jsonc-lib-dir=DIR
37         jsonc_lib_dir=
38         AC_ARG_WITH(jsonc-lib-dir,
39         [AS_HELP_STRING([--with-jsonc-lib-dir=DIR],
40                 [Directory where the json-c libraries may be found])],
41                 [case "$withval" in
42                         no)
43                                 AC_MSG_ERROR(Need jsonc-lib-dir)
44                         ;;
45                         yes)
46                         ;;
47                         *)
48                                 jsonc_lib_dir="$withval"
49                         ;;
50                 esac])
51
52         dnl extra argument: --with-jsonc-dir=DIR
53         AC_ARG_WITH(jsonc-dir,
54         [AS_HELP_STRING([--with-jsonc-dir=DIR],
55                 [Base directory where json-c is installed])],
56                 [case "$withval" in
57                         no)
58                                 AC_MSG_ERROR(Need json-c-dir)
59                         ;;
60                         yes)
61                         ;;
62                         *)
63                                 jsonc_lib_dir="$withval/lib"
64                                 jsonc_include_dir="$withval/include"
65                         ;;
66                 esac])
67
68         dnl ############################################################
69         dnl # Check for json-c header files
70         dnl ############################################################
71
72         have_json="yes"
73         smart_try_dir="$jsonc_include_dir \
74         /usr/include/json-c /usr/local/include/json-c /opt/include/json-c \
75         /usr/include/json /usr/local/include/json /opt/include/json"
76         FR_SMART_CHECK_INCLUDE([json.h])
77         if test "x$ac_cv_header_json_h" != "xyes"; then
78                 have_json="no"
79                 AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=<path>.])
80         fi
81
82         dnl ############################################################
83         dnl # Check for json-c libraries
84         dnl ############################################################
85
86         smart_try_dir="$jsonc_lib_dir"
87         dnl # Use a json-c specific function which is only
88         dnl # available in newer versions.
89         FR_SMART_CHECK_LIB([json-c], [json_c_version])
90         if test "x$ac_cv_lib_json_c_json_c_version" != "xyes"; then
91                 dnl # Use a function which is included in legacy versions
92                 dnl # but which may be available in other json libraries
93                 FR_SMART_CHECK_LIB([json], [json_tokener_new])
94                 if test "x$ac_cv_lib_json_json_tokener_new" != "xyes"; then
95                         have_json="no"
96                 fi
97         fi
98
99         if test "x$have_json" = "xyes"; then
100                 dnl # Ensure we use the library we just found the rest of the checks
101                 LDFLAGS="$SMART_LIBS"
102
103                 dnl # Add any optional functions here
104                 AC_CHECK_FUNCS(\
105                         json_c_version \
106                         json_object_get_string_len \
107                         json_object_object_get_ex \
108                         json_object_new_int64 \
109                         json_tokener_parse_verbose \
110                         json_tokener_error_desc \
111                         json_tokener_get_error
112                 )
113         else
114                 fail="$fail json-c"
115         fi
116
117         dnl ############################################################
118         dnl # Check for libcouchbase
119         dnl ############################################################
120
121         dnl extra argument: --with-libcouchbase-include-dir=DIR
122         libcouchbase_include_dir=
123         AC_ARG_WITH(libcouchbase-include-dir,
124                 [AS_HELP_STRING([--with-libcouchbase-include-dir=DIR],
125                 [Directory where the libcouchbase includes may be found])],
126                 [case "$withval" in
127                         no)
128                                 AC_MSG_ERROR(Need libcouchbase-include-dir)
129                         ;;
130                         yes)
131                         ;;
132                         *)
133                                 libcouchbase_include_dir="$withval"
134                         ;;
135                 esac])
136
137         dnl extra argument: --with-libcouchbase-lib-dir=DIR
138         libcouchbase_lib_dir=
139         AC_ARG_WITH(libcouchbase-lib-dir,
140         [AS_HELP_STRING([--with-libcouchbase-lib-dir=DIR],
141                 [Directory where the libcouchbase libraries may be found])],
142                 [case "$withval" in
143                         no)
144                                 AC_MSG_ERROR(Need libcouchbase-lib-dir)
145                         ;;
146                         yes)
147                         ;;
148                         *)
149                                 libcouchbase_lib_dir="$withval"
150                         ;;
151                 esac])
152
153         dnl extra argument: --with-libcouchbase-dir=DIR
154         AC_ARG_WITH(libcouchbase-dir,
155         [AS_HELP_STRING([--with-libcouchbase-dir=DIR],
156                 [Base directory where libcouchbase is installed])],
157                 [case "$withval" in
158                         no)
159                                 AC_MSG_ERROR(Need libcouchbase-dir)
160                         ;;
161                         yes)
162                         ;;
163                         *)
164                                 libcouchbase_lib_dir="$withval/lib"
165                                 libcouchbase_include_dir="$withval/include"
166                         ;;
167                 esac])
168
169         dnl ############################################################
170         dnl # Check for libcouchbase header files
171         dnl ############################################################
172
173         have_couchbase="yes"
174         smart_try_dir="$libcouchbase_include_dir"
175         FR_SMART_CHECK_INCLUDE([libcouchbase/couchbase.h])
176         if test "x$ac_cv_header_libcouchbase_couchbase_h" != "xyes"; then
177                 have_couchbase="no"
178                 AC_MSG_WARN([libcouchbase headers not found. Use --with-libcouchbase-include-dir=<path>.])
179         fi
180
181         dnl ############################################################
182         dnl # Check for libcouchbase libraries
183         dnl ############################################################
184
185         smart_try_dir="$libcouchbase_lib_dir"
186         FR_SMART_CHECK_LIB([couchbase], [lcb_get_version])
187         if test "x$ac_cv_lib_couchbase_lcb_get_version" != "xyes"; then
188                 have_couchbase="no"
189                 AC_MSG_WARN([libcouchbase libraries not found. Use --with-libcouchbase-lib-dir=<path>.])
190         fi
191
192         if test "x$have_couchbase" != "xyes"; then
193                 fail="$fail json-c"
194         fi
195
196         if test "x$have_couchbase" = "xno"; then
197                 fail="$fail libcouchbase"
198         fi
199
200         dnl ############################################################
201         dnl # Checks done - set targetname
202         dnl ############################################################
203
204         targetname=modname
205 else
206         targetname=
207         echo \*\*\* module modname is disabled.
208 fi
209
210 dnl  Don't change this section.
211 if test x"$fail" != x""; then
212         if test x"${enable_strict_dependencies}" = x"yes"; then
213                 AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
214         else
215                 AC_MSG_WARN([silently not building ]modname[.])
216                 AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
217                 targetname=""
218         fi
219 fi
220
221 mod_ldflags="${SMART_LIBS}"
222 mod_cflags="${SMART_CPPFLAGS}"
223
224 AC_SUBST(mod_cflags)
225 AC_SUBST(mod_ldflags)
226
227 AC_SUBST(targetname)
228 AC_OUTPUT(all.mk)