source: branches/samba-3.5.x/lib/replace/libreplace_macros.m4

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 9.9 KB
Line 
1#
2# This is a collection of useful autoconf macros
3#
4
5############################################
6# Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags
7# Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action)
8# changes CFLAGS to add -AC99 or -c99 if needed
9AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
10[
11saved_CFLAGS="$CFLAGS";
12c99_init=no
13if test x"$c99_init" = x"no"; then
14 AC_MSG_CHECKING(for C99 designated initializers)
15 CFLAGS="$saved_CFLAGS";
16 AC_TRY_COMPILE([#include <stdio.h>],
17 [ struct foo {int x;char y;};
18 struct foo bar = { .y = 'X', .x = 1 };
19 ],
20 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
21fi
22if test x"$c99_init" = x"no"; then
23 AC_MSG_CHECKING(for C99 designated initializers with -AC99)
24 CFLAGS="$saved_CFLAGS -AC99";
25 AC_TRY_COMPILE([#include <stdio.h>],
26 [ struct foo {int x;char y;};
27 struct foo bar = { .y = 'X', .x = 1 };
28 ],
29 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
30fi
31if test x"$c99_init" = x"no"; then
32 AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=extc99)
33 CFLAGS="$saved_CFLAGS -qlanglvl=extc99";
34 AC_TRY_COMPILE([#include <stdio.h>],
35 [ struct foo {int x;char y;};
36 struct foo bar = { .y = 'X', .x = 1 };
37 ],
38 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
39fi
40if test x"$c99_init" = x"no"; then
41 AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=stdc99)
42 CFLAGS="$saved_CFLAGS -qlanglvl=stdc99";
43 AC_TRY_COMPILE([#include <stdio.h>],
44 [ struct foo {int x;char y;};
45 struct foo bar = { .y = 'X', .x = 1 };
46 ],
47 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
48fi
49if test x"$c99_init" = x"no"; then
50 AC_MSG_CHECKING(for C99 designated initializers with -c99)
51 CFLAGS="$saved_CFLAGS -c99"
52 AC_TRY_COMPILE([#include <stdio.h>],
53 [ struct foo {int x;char y;};
54 struct foo bar = { .y = 'X', .x = 1 };
55 ],
56 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
57fi
58
59if test "`uname`" = "HP-UX"; then
60 if test "$ac_cv_c_compiler_gnu" = no; then
61 # special override for broken HP-UX compiler - I can't find a way to test
62 # this properly (its a compiler bug)
63 CFLAGS="$CFLAGS -AC99";
64 c99_init=yes;
65 fi
66fi
67
68if test x"$c99_init" = x"yes"; then
69 saved_CFLAGS=""
70 $1
71else
72 CFLAGS="$saved_CFLAGS"
73 saved_CFLAGS=""
74 $2
75fi
76])
77
78dnl AC_PROG_CC_FLAG(flag)
79AC_DEFUN(AC_PROG_CC_FLAG,
80[AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1,
81[echo 'void f(){}' > conftest.c
82if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then
83 ac_cv_prog_cc_$1=yes
84else
85 ac_cv_prog_cc_$1=no
86fi
87rm -f conftest*
88])])
89
90dnl see if a declaration exists for a function or variable
91dnl defines HAVE_function_DECL if it exists
92dnl AC_HAVE_DECL(var, includes)
93AC_DEFUN(AC_HAVE_DECL,
94[
95 AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
96 AC_TRY_COMPILE([$2],[int i = (int)$1],
97 ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
98 if test x"$ac_cv_have_$1_decl" = x"yes"; then
99 AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
100 fi
101])
102
103
104# AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
105# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
106# [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
107# ------------------------------------------------------
108#
109# Use a cache variable name containing both the library and function name,
110# because the test really is for library $1 defining function $3, not
111# just for library $1. Separate tests with the same $1 and different $3s
112# may have different results.
113#
114# Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
115# is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
116# ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence
117# the AS_LITERAL_IF indirection.
118#
119# FIXME: This macro is extremely suspicious. It DEFINEs unconditionally,
120# whatever the FUNCTION, in addition to not being a *S macro. Note
121# that the cache does depend upon the function we are looking for.
122#
123# It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
124# `ac_save_LIBS': there are many macros which don't want to see `LIBS'
125# changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
126# And ``ac_save_LIBS' is too tempting a name, so let's leave them some
127# freedom.
128AC_DEFUN([AC_CHECK_LIB_EXT],
129[
130AH_CHECK_LIB_EXT([$1])
131ac_check_lib_ext_save_LIBS=$LIBS
132LIBS="-l$1 $$2 $7 $LIBS"
133AS_LITERAL_IF([$1],
134 [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
135 [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
136
137m4_ifval([$3],
138 [
139 AH_CHECK_FUNC_EXT([$3])
140 AS_LITERAL_IF([$1],
141 [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
142 [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
143 AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
144 [AC_TRY_LINK_FUNC($3,
145 [AS_VAR_SET(ac_Lib_func, yes);
146 AS_VAR_SET(ac_Lib_ext, yes)],
147 [AS_VAR_SET(ac_Lib_func, no);
148 AS_VAR_SET(ac_Lib_ext, no)])
149 ])
150 AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
151 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
152 AS_VAR_POPDEF([ac_Lib_func])dnl
153 ],[
154 AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
155 [AC_TRY_LINK_FUNC([main],
156 [AS_VAR_SET(ac_Lib_ext, yes)],
157 [AS_VAR_SET(ac_Lib_ext, no)])
158 ])
159 ])
160LIBS=$ac_check_lib_ext_save_LIBS
161
162AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
163 [m4_default([$4],
164 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
165 case "$$2" in
166 *-l$1*)
167 ;;
168 *)
169 $2="-l$1 $$2"
170 ;;
171 esac])
172 [$6]
173 ],
174 [$5])dnl
175AS_VAR_POPDEF([ac_Lib_ext])dnl
176])# AC_CHECK_LIB_EXT
177
178# AH_CHECK_LIB_EXT(LIBNAME)
179# ---------------------
180m4_define([AH_CHECK_LIB_EXT],
181[AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
182 [Define to 1 if you have the `]$1[' library (-l]$1[).])])
183
184dnl AC_SEARCH_LIBS_EXT(FUNCTION, SEARCH-LIBS, EXT_LIBS,
185dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
186dnl [OTHER-LIBRARIES])
187dnl --------------------------------------------------------
188dnl Search for a library defining FUNC, if it's not already available.
189AC_DEFUN([AC_SEARCH_LIBS_EXT],
190[AC_CACHE_CHECK([for library containing $1], [ac_cv_search_ext_$1],
191[
192ac_func_search_ext_save_LIBS=$LIBS
193ac_cv_search_ext_$1=no
194AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
195 [ac_cv_search_ext_$1="none required"])
196if test "$ac_cv_search_ext_$1" = no; then
197 for ac_lib in $2; do
198 LIBS="-l$ac_lib $$3 $6 $ac_func_search_save_ext_LIBS"
199 AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
200 [ac_cv_search_ext_$1="-l$ac_lib"
201break])
202 done
203fi
204LIBS=$ac_func_search_ext_save_LIBS])
205AS_IF([test "$ac_cv_search_ext_$1" != no],
206 [test "$ac_cv_search_ext_$1" = "none required" || $3="$ac_cv_search_ext_$1 $$3"
207 $4],
208 [$5])dnl
209])
210
211dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
212dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
213AC_DEFUN([AC_CHECK_FUNC_EXT],
214[
215 AH_CHECK_FUNC_EXT($1)
216 ac_check_func_ext_save_LIBS=$LIBS
217 LIBS="$2 $LIBS"
218 AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
219 AC_CACHE_CHECK([for $1], ac_var,
220 [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
221 [AS_VAR_SET(ac_var, yes)],
222 [AS_VAR_SET(ac_var, no)])])
223 LIBS=$ac_check_func_ext_save_LIBS
224 AS_IF([test AS_VAR_GET(ac_var) = yes],
225 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3],
226 [$4])dnl
227AS_VAR_POPDEF([ac_var])dnl
228])# AC_CHECK_FUNC
229
230# AH_CHECK_FUNC_EXT(FUNCNAME)
231# ---------------------
232m4_define([AH_CHECK_FUNC_EXT],
233[AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
234 [Define to 1 if you have the `]$1[' function.])])
235
236dnl Define an AC_DEFINE with ifndef guard.
237dnl AC_N_DEFINE(VARIABLE [, VALUE])
238AC_DEFUN([AC_N_DEFINE],
239[
240AH_VERBATIM([$1], [
241#ifndef $1
242# undef $1
243#endif
244])
245
246 cat >>confdefs.h <<\EOF
247#ifndef $1
248[#define] $1 m4_if($#, 1, 1, [$2])
249#endif
250EOF
251])
252
253dnl Add an #include
254dnl AC_ADD_INCLUDE(VARIABLE)
255define(AC_ADD_INCLUDE,
256[cat >> confdefs.h <<\EOF
257[#include] $1
258EOF
259])
260
261dnl remove an #include
262dnl AC_REMOVE_INCLUDE(VARIABLE)
263define(AC_REMOVE_INCLUDE,
264[
265grep -v '[#include] $1' confdefs.h >confdefs.h.tmp
266cat confdefs.h.tmp > confdefs.h
267rm confdefs.h.tmp
268])
269
270dnl remove an #define
271dnl AC_REMOVE_DEFINE(VARIABLE)
272define(AC_REMOVE_DEFINE,
273[
274grep -v '[#define] $1 ' confdefs.h |grep -v '[#define] $1[$]'>confdefs.h.tmp
275cat confdefs.h.tmp > confdefs.h
276rm confdefs.h.tmp
277])
278
279dnl AS_HELP_STRING is not available in autoconf 2.57, and AC_HELP_STRING is deprecated
280dnl in autoconf 2.59, so define AS_HELP_STRING to be AC_HELP_STRING unless it is already
281dnl defined.
282m4_ifdef([AS_HELP_STRING], , [m4_define([AS_HELP_STRING], m4_defn([AC_HELP_STRING]))])
283
284dnl check if the prototype in the header matches the given one
285dnl AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders])
286AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
287[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
288 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
289 AC_INCLUDES_DEFAULT
290 $5
291 $1
292 {
293 $2
294 }
295 ])],[
296 AS_TR_SH([ac_cv_c_prototype_$1])=yes
297 ],[
298 AS_TR_SH([ac_cv_c_prototype_$1])=no
299 ])
300)
301AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
302])
303
304AC_DEFUN(LIBREPLACE_PROVIDE_HEADER,
305[AC_CHECK_HEADER([$1],
306 [ AC_CONFIG_COMMANDS(rm-$1, [rm -f $libreplacedir/$1], [libreplacedir=$libreplacedir]) ],
307 [ AC_CONFIG_COMMANDS(mk-$1, [echo "#include \"replace.h\"" > $libreplacedir/$1], [libreplacedir=$libreplacedir]) ]
308 )
309])
310
311dnl AC_HAVE_TYPE(TYPE,INCLUDES)
312AC_DEFUN([AC_HAVE_TYPE], [
313AC_REQUIRE([AC_HEADER_STDC])
314cv=`echo "$1" | sed 'y%./+- %__p__%'`
315AC_MSG_CHECKING(for $1)
316AC_CACHE_VAL([ac_cv_type_$cv],
317AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
318AC_INCLUDES_DEFAULT
319$2]],
320[[$1 foo;]])],
321[eval "ac_cv_type_$cv=yes"],
322[eval "ac_cv_type_$cv=no"]))dnl
323ac_foo=`eval echo \\$ac_cv_type_$cv`
324AC_MSG_RESULT($ac_foo)
325if test "$ac_foo" = yes; then
326 ac_tr_hdr=HAVE_`echo $1 | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'`
327if false; then
328 AC_CHECK_TYPES($1)
329fi
330 AC_DEFINE_UNQUOTED($ac_tr_hdr, 1, [Define if you have type `$1'])
331fi
332])
Note: See TracBrowser for help on using the repository browser.