Merge pull request #700 from mcnewton/rlm_files
[freeradius.git] / src / modules / rlm_rest / configure.ac
1 AC_PREREQ([2.53])
2 AC_INIT(rlm_rest.c)
3 AC_REVISION($Revision$)
4 AC_DEFUN(modname,[rlm_rest])
5 AC_CONFIG_HEADER(config.h)
6 m4_include([m4/libcurl_check_config.m4])
7
8 if test x$with_[]modname != xno; then
9
10         AC_PROG_CC
11         AC_PROG_CPP
12
13         dnl put configuration checks here.
14         dnl set $fail to what's missing, on fatal errors.
15         dnl use AC_MSG_WARN() on important messages.
16
17         dnl ############################################################
18         dnl # Check for curl
19         dnl ############################################################
20
21         LIBCURL_CHECK_CONFIG([], [7.19.1])
22
23         if test "x$libcurl_cv_lib_version_ok" != "xyes"; then
24                 fail="$fail libcurl >= 7.19.2"
25         elif test "x$libcurl_cv_lib_curl_usable" != "xyes"; then
26                 fail="$fail libcurl"
27         else
28                 if test x$libcurl_protocol_HTTP != xyes; then
29                         fail="$fail libcurl_protocol_http"
30                 fi
31
32                 if test x$libcurl_protocol_HTTPS != xyes || test x$libcurl_feature_SSL != xyes; then
33                         AC_MSG_WARN([silently building without HTTPS support. requires: libcurl_protocol_https.])
34                 fi
35         fi
36
37         dnl ############################################################
38         dnl # Check for json-c
39         dnl ############################################################
40
41         dnl extra argument: --with-jsonc-include-dir=DIR
42         jsonc_include_dir=
43         AC_ARG_WITH(jsonc-include-dir,
44                 [AS_HELP_STRING([--with-jsonc-include-dir=DIR],
45                 [Directory where the json-c includes may be found])],
46                 [case "$withval" in
47                     no)
48                         AC_MSG_ERROR(Need jsonc-include-dir)
49                     ;;
50                         yes)
51                     ;;
52                     *)
53                         jsonc_include_dir="$withval"
54                     ;;
55                 esac])
56
57         dnl extra argument: --with-jsonc-lib-dir=DIR
58         jsonc_lib_dir=
59         AC_ARG_WITH(jsonc-lib-dir,
60         [AS_HELP_STRING([--with-jsonc-lib-dir=DIR],
61                 [Directory where the json-c libraries may be found])],
62                 [case "$withval" in
63                     no)
64                         AC_MSG_ERROR(Need jsonc-lib-dir)
65                         ;;
66                     yes)
67                         ;;
68                     *)
69                         jsonc_lib_dir="$withval"
70                         ;;
71                 esac])
72
73         dnl extra argument: --with-jsonc-dir=DIR
74         AC_ARG_WITH(jsonc-dir,
75         [AS_HELP_STRING([--with-jsonc-dir=DIR],
76                 [Base directory where json-c is installed])],
77                 [case "$withval" in
78                     no)
79                         AC_MSG_ERROR(Need json-c-dir)
80                         ;;
81                     yes)
82                         ;;
83                     *)
84                         jsonc_lib_dir="$withval/lib"
85                         jsonc_include_dir="$withval/include"
86                         ;;
87                 esac])
88
89
90         dnl ############################################################
91         dnl # Check for json-c header files
92         dnl ############################################################
93
94         have_json="yes"
95         smart_try_dir="$jsonc_include_dir"
96         FR_SMART_CHECK_INCLUDE([json/json.h])
97         if test "x$ac_cv_header_json_json_h" != "xyes"; then
98                 have_json="no"
99                 AC_MSG_WARN([json-c headers not found. Use --with-jsonc-include-dir=<path>.])
100         fi
101
102         dnl ############################################################
103         dnl # Check for json-c libraries
104         dnl ############################################################
105
106         smart_try_dir="$jsonc_lib_dir"
107         dnl # Use a json-c specific function which is only
108         dnl # available in newer versions.
109         FR_SMART_CHECK_LIB([json-c], [json_c_version])
110         if test "x$ac_cv_lib_json_c_json_c_version" != "xyes"
111         then
112                 dnl # Use a function which is included in legacy versions
113                 dnl # but which may be available in other json libraries
114                 FR_SMART_CHECK_LIB([json], [json_tokener_new])
115                 if test "x$ac_cv_lib_json_json_tokener_new" != "xyes"
116                 then
117                         have_json="no"
118                 fi
119         fi
120
121         if test "x$have_json" = "xyes"; then
122                 dnl # Ensure we use the library we just found the rest of the checks
123                 LDFLAGS="$SMART_LIBS"
124
125                 dnl # Add any optional functions here
126                 AC_CHECK_FUNCS(\
127                         json_c_version \
128                         json_type_to_name
129                 )
130
131                 AC_DEFINE([HAVE_JSON],[1],[Build with JSON support from json-c])
132         else
133                 AC_MSG_WARN([json-c libraries not found. Use --with-jsonc-lib-dir=<path>.])
134                 AC_MSG_WARN([silently building without JSON support. requires: json-c])
135         fi
136
137         targetname=modname
138 else
139         targetname=
140         echo \*\*\* module modname is disabled.
141 fi
142
143 dnl  Don't change this section.
144 if test x"$fail" != x""; then
145         if test x"${enable_strict_dependencies}" = x"yes"; then
146                 AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])
147         else
148                 AC_MSG_WARN([silently not building ]modname[.])
149                 AC_MSG_WARN([FAILURE: ]modname[ requires: $fail.]);
150                 targetname=""
151         fi
152 fi
153
154 mod_ldflags="$LIBCURL $SMART_LIBS"
155 mod_cflags="$SMART_CPPFLAGS"
156
157 AC_SUBST(mod_cflags)
158 AC_SUBST(mod_ldflags)
159
160 AC_SUBST(targetname)
161 AC_OUTPUT(all.mk)
162