Merge tag 'release_3_0_1' into tr-integ
[freeradius.git] / acinclude.m4
1 dnl Checks to see if this is SUNPro we're building with
2 dnl Usage:
3 dnl AC_PROG_CC_SUNPRO
4 AC_DEFUN([AC_PROG_CC_SUNPRO],
5 [AC_CACHE_CHECK(whether we are using SUNPro C, ac_cv_prog_suncc,
6 [dnl The semicolon is to pacify NeXT's syntax-checking cpp.
7 cat > conftest.c <<EOF
8 #ifdef __SUNPRO_C
9   yes;
10 #endif
11 EOF
12 if AC_TRY_COMMAND(${CC-cc} -E conftest.c) | egrep yes >/dev/null 2>&1; then
13   ac_cv_prog_suncc=yes
14 else
15   ac_cv_prog_suncc=no
16 fi])])
17
18 dnl #
19 dnl # FR_CHECK_TYPE_INCLUDE([#includes ...], type, default-C-types)
20 dnl #
21 dnl # This function is like AC_CHECK_TYPE, but you can give this one
22 dnl # a list of include files to check.
23 dnl #
24 AC_DEFUN([FR_CHECK_TYPE_INCLUDE],
25 [
26   AC_CACHE_CHECK(for $2, ac_cv_type_$2,
27     [ ac_cv_type_$2=no
28       AC_TRY_COMPILE($1,
29         [$2 foo],
30         ac_cv_type_$2=yes,
31       )
32     ]
33   )
34
35   if test "$ac_cv_type_$2" != "yes"; then
36          AC_DEFINE($2, $3, $4)
37   fi
38 ])
39
40 dnl #
41 dnl #  Locate the directory in which a particular file is found.
42 dnl #
43 dnl #  Usage: FR_LOCATE_DIR(MYSQLLIB_DIR, libmysqlclient.a)
44 dnl #
45 dnl #    Defines the variable MYSQLLIB_DIR to be the directory(s) in
46 dnl #    which the file libmysqlclient.a is to be found.
47 dnl #
48 dnl #
49 AC_DEFUN([FR_LOCATE_DIR],
50 [
51 dnl # If we have the program 'locate', then the problem of finding a
52 dnl # particular file becomes MUCH easier.
53 dnl #
54
55 dnl #
56 dnl #  No 'locate' defined, do NOT do anything.
57 dnl #
58 if test "x$LOCATE" != "x"; then
59   dnl #
60   dnl #  Root through a series of directories, looking for the given file.
61   dnl #
62   DIRS=
63   file=$2
64
65   for x in `${LOCATE} $file 2>/dev/null`; do
66     dnl #
67     dnl #  When asked for 'foo', locate will also find 'foo_bar', which we
68     dnl #  don't want.  We want that EXACT filename.
69     dnl #
70     dnl #  We ALSO want to be able to look for files like 'mysql/mysql.h',
71     dnl #  and properly match them, too.  So we try to strip off the last
72     dnl #  part of the filename, using the name of the file we're looking
73     dnl #  for.  If we CANNOT strip it off, then the name will be unchanged.
74     dnl #
75     base=`echo $x | sed "s%/${file}%%"`
76     if test "x$x" = "x$base"; then
77       continue;
78     fi
79
80     dir=`${DIRNAME} $x 2>/dev/null`
81     dnl #
82     dnl #  Exclude a number of directories.
83     dnl #
84     exclude=`echo ${dir} | ${GREP} /home`
85     if test "x$exclude" != "x"; then
86       continue
87     fi
88
89     dnl #
90     dnl #  OK, we have an exact match.  Let's be sure that we only find ONE
91     dnl #  matching directory.
92     dnl #
93     already=`echo \$$1 ${DIRS} | ${GREP} ${dir}`
94     if test "x$already" = "x"; then
95       DIRS="$DIRS $dir"
96     fi
97   done
98 fi
99
100 dnl #
101 dnl #  And remember the directory in which we found the file.
102 dnl #
103 eval "$1=\"\$$1 $DIRS\""
104 ])
105
106
107 dnl #######################################################################
108 dnl #
109 dnl #  Look for a library in a number of places.
110 dnl #
111 dnl #  FR_SMART_CHECK_LIB(library, function)
112 dnl #
113 AC_DEFUN([FR_SMART_CHECK_LIB], [
114
115 sm_lib_safe=`echo "$1" | sed 'y%./+-%__p_%'`
116 sm_func_safe=`echo "$2" | sed 'y%./+-%__p_%'`
117
118 old_LIBS="$LIBS"
119 smart_lib=
120 smart_lib_dir=
121
122 dnl #
123 dnl #  Try first any user-specified directory, otherwise we may pick up
124 dnl #  the wrong version.
125 dnl #
126 if test "x$smart_try_dir" != "x"; then
127   for try in $smart_try_dir; do
128     AC_MSG_CHECKING([for $2 in -l$1 in $try])
129     LIBS="-L$try -l$1 $old_LIBS -Wl,-rpath,$try"
130     AC_TRY_LINK([extern char $2();],
131                 [$2()],
132                 [
133                  smart_lib="-L$try -l$1 -Wl,-rpath,$try"
134                  AC_MSG_RESULT(yes)
135                  break
136                 ],
137                 [AC_MSG_RESULT(no)])
138   done
139   LIBS="$old_LIBS"
140 fi
141
142 dnl #
143 dnl #  Try using the default library path
144 dnl #
145 if test "x$smart_lib" = "x"; then
146   AC_MSG_CHECKING([for $2 in -l$1])
147   LIBS="-l$1 $old_LIBS"
148   AC_TRY_LINK([extern char $2();],
149               [$2()],
150               [
151                 smart_lib="-l$1"
152                 AC_MSG_RESULT(yes)
153               ],
154               [AC_MSG_RESULT(no)])
155   LIBS="$old_LIBS"
156 fi
157
158 dnl #
159 dnl #  Try to guess possible locations.
160 dnl #
161 if test "x$smart_lib" = "x"; then
162   FR_LOCATE_DIR(smart_lib_dir,[lib$1${libltdl_cv_shlibext}])
163   FR_LOCATE_DIR(smart_lib_dir,[lib$1.a])
164
165   for try in $smart_lib_dir /usr/local/lib /opt/lib; do
166     AC_MSG_CHECKING([for $2 in -l$1 in $try])
167     LIBS="-L$try -l$1 $old_LIBS -Wl,-rpath,$try"
168     AC_TRY_LINK([extern char $2();],
169                 [$2()],
170                 [
171                   smart_lib="-L$try -l$1 -Wl,-rpath,$try"
172                   AC_MSG_RESULT(yes)
173                   break
174                 ],
175                 [AC_MSG_RESULT(no)])
176   done
177   LIBS="$old_LIBS"
178 fi
179
180 dnl #
181 dnl #  Found it, set the appropriate variable.
182 dnl #
183 if test "x$smart_lib" != "x"; then
184   eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
185   LIBS="$smart_lib $old_LIBS"
186   SMART_LIBS="$smart_lib $SMART_LIBS"
187 fi
188 ])
189
190 dnl #######################################################################
191 dnl #
192 dnl #  Look for a header file in a number of places.
193 dnl #
194 dnl #  FR_SMART_CHECK_INCLUDE(foo.h, [ #include <other.h> ])
195 dnl #
196 AC_DEFUN([FR_SMART_CHECK_INCLUDE], [
197
198 ac_safe=`echo "$1" | sed 'y%./+-%__pm%'`
199 old_CFLAGS="$CFLAGS"
200 smart_include=
201 smart_include_dir=
202
203 dnl #
204 dnl #  Try first any user-specified directory, otherwise we may pick up
205 dnl #  the wrong version.
206 dnl #
207 if test "x$smart_try_dir" != "x"; then
208   for try in $smart_try_dir; do
209     AC_MSG_CHECKING([for $1 in $try])
210     CFLAGS="$old_CFLAGS -isystem $try"
211     AC_TRY_COMPILE([$2
212                     #include <$1>],
213                    [int a = 1;],
214                    [
215                      smart_include="-isystem $try"
216                      AC_MSG_RESULT(yes)
217                      break
218                    ],
219                    [
220                      smart_include=
221                      AC_MSG_RESULT(no)
222                    ])
223   done
224   CFLAGS="$old_CFLAGS"
225 fi
226
227 dnl #
228 dnl #  Try using the default includes.
229 dnl #
230 if test "x$smart_include" = "x"; then
231   AC_MSG_CHECKING([for $1])
232   AC_TRY_COMPILE([$2
233                   #include <$1>],
234                  [int a = 1;],
235                  [
236                    smart_include=" "
237                    AC_MSG_RESULT(yes)
238                    break
239                  ],
240                  [
241                    smart_include=
242                    AC_MSG_RESULT(no)
243                  ])
244 fi
245
246 dnl #
247 dnl #  Try to guess possible locations.
248 dnl #
249 if test "x$smart_include" = "x"; then
250   FR_LOCATE_DIR(smart_include_dir,$1)
251   for try in $smart_include_dir /usr/local/include /opt/include; do
252     AC_MSG_CHECKING([for $1 in $try])
253     CFLAGS="$old_CFLAGS -isystem $try"
254     AC_TRY_COMPILE([$2
255                     #include <$1>],
256                    [int a = 1;],
257                    [
258                      smart_include="-isystem $try"
259                      AC_MSG_RESULT(yes)
260                      break
261                    ],
262                    [
263                      smart_include=
264                      AC_MSG_RESULT(no)
265                    ])
266   done
267   CFLAGS="$old_CFLAGS"
268 fi
269
270 dnl #
271 dnl #  Found it, set the appropriate variable.
272 dnl #
273 if test "x$smart_include" != "x"; then
274   eval "ac_cv_header_$ac_safe=yes"
275   CFLAGS="$old_CFLAGS $smart_include"
276   SMART_CFLAGS="$SMART_CFLAGS $smart_include"
277 fi
278 ])
279
280 dnl #######################################################################
281 dnl #
282 dnl #  Look for a header file in a number of places.
283 dnl #
284 dnl #  Usage:  FR_CHECK_STRUCT_HAS_MEMBER([#include <foo.h>], [struct foo], member)
285 dnl #  If the member is defined, then the variable
286 dnl #     ac_cv_type_struct_foo_has_member is set to 'yes'
287 dnl #
288 AC_DEFUN([FR_CHECK_STRUCT_HAS_MEMBER], [
289   AC_MSG_CHECKING([for $3 in $2])
290
291 dnl BASED on 'offsetof':
292 dnl #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
293 dnl
294
295   AC_TRY_COMPILE([
296 $1
297 #ifdef HAVE_STDDEF_H
298 #include <stddef.h>
299 #endif
300 #ifndef offsetof
301 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
302 #endif
303 ],
304                  [ int foo = offsetof($2, $3) ],
305                  has_element=" ",
306                  has_element=)
307
308   ac_safe_type=`echo "$2" | sed 'y% %_%'`
309   if test "x$has_element" != "x"; then
310     AC_MSG_RESULT(yes)
311     eval "ac_cv_type_${ac_safe_type}_has_$3=yes"
312   else
313     AC_MSG_RESULT(no)
314     eval "ac_cv_type_${ac_safe_type}_has_$3="
315  fi
316 ])
317
318 dnl Autoconf 2.61 breaks the support for chained configure scripts
319 dnl in combination with config.cache
320 m4_pushdef([AC_OUTPUT],
321 [
322   unset ac_cv_env_LIBS_set
323   unset ac_cv_env_LIBS_value
324   m4_popdef([AC_OUTPUT])
325   AC_OUTPUT([$1],[$2],[$3])
326 ])
327
328
329 #  See if the compilation works with __thread, for thread-local storage
330 #
331 AC_DEFUN([FR_TLS],
332 [
333   AC_MSG_CHECKING(for __thread support in compiler)
334   AC_RUN_IFELSE(
335     [AC_LANG_SOURCE(
336       [[
337         static __thread int val;
338         int main(int argc, char **argv) {
339           val = 0;
340           return val;
341         }
342       ]])
343     ],[have_tls=yes],[have_tls=no],[have_tls=no])
344   AC_MSG_RESULT($have_tls)
345   if test "x$have_tls" = "xyes"; then
346     AC_DEFINE([HAVE_THREAD_TLS],[1],[Define if the compiler supports __thread])
347   fi
348 ])
349
350
351 AC_DEFUN([VL_LIB_READLINE], [
352   AC_CACHE_CHECK([for a readline compatible library],
353                  vl_cv_lib_readline, [
354     ORIG_LIBS="$LIBS"
355     for readline_lib in readline edit editline; do
356       for termcap_lib in "" termcap curses ncurses; do
357         if test -z "$termcap_lib"; then
358           TRY_LIB="-l$readline_lib"
359         else
360           TRY_LIB="-l$readline_lib -l$termcap_lib"
361         fi
362         LIBS="$ORIG_LIBS $TRY_LIB"
363         AC_TRY_LINK_FUNC(readline, vl_cv_lib_readline="$TRY_LIB")
364         if test -n "$vl_cv_lib_readline"; then
365           break
366         fi
367       done
368       if test -n "$vl_cv_lib_readline"; then
369         break
370       fi
371     done
372     if test -z "$vl_cv_lib_readline"; then
373       vl_cv_lib_readline="no"
374       LIBS="$ORIG_LIBS"
375     fi
376   ])
377
378   if test "$vl_cv_lib_readline" != "no"; then
379     LIBREADLINE="$vl_cv_lib_readline"
380     AC_DEFINE(HAVE_LIBREADLINE, 1,
381               [Define if you have a readline compatible library])
382     AC_CHECK_HEADERS(readline.h readline/readline.h)
383     AC_CACHE_CHECK([whether readline supports history],
384                    [vl_cv_lib_readline_history], [
385       vl_cv_lib_readline_history="no"
386       AC_TRY_LINK_FUNC([add_history], [vl_cv_lib_readline_history="yes"])
387     ])
388     if test "$vl_cv_lib_readline_history" = "yes"; then
389       AC_DEFINE(HAVE_READLINE_HISTORY, 1,
390                 [Define if your readline library has \`add_history'])
391       AC_CHECK_HEADERS(history.h readline/history.h)
392     fi
393   fi
394   AC_SUBST(LIBREADLINE)
395 ])dnl
396
397 AC_INCLUDE(aclocal.m4)