r7133: work in progress, including a HIGHLY revised and simplified schema
[kai/samba.git] / source4 / aclocal.m4
1 dnl test whether dirent has a d_off member
2 AC_DEFUN(AC_DIRENT_D_OFF,
3 [AC_CACHE_CHECK([for d_off in dirent], ac_cv_dirent_d_off,
4 [AC_TRY_COMPILE([
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <dirent.h>], [struct dirent d; d.d_off;],
8 ac_cv_dirent_d_off=yes, ac_cv_dirent_d_off=no)])
9 if test $ac_cv_dirent_d_off = yes; then
10   AC_DEFINE(HAVE_DIRENT_D_OFF,1,[Whether dirent has a d_off member])
11 fi
12 ])
13
14 dnl AC_PROG_CC_FLAG(flag)
15 AC_DEFUN(AC_PROG_CC_FLAG,
16 [AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1,
17 [echo 'void f(){}' > conftest.c
18 if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then
19   ac_cv_prog_cc_$1=yes
20 else
21   ac_cv_prog_cc_$1=no
22 fi
23 rm -f conftest*
24 ])])
25
26 dnl see if a declaration exists for a function or variable
27 dnl defines HAVE_function_DECL if it exists
28 dnl AC_HAVE_DECL(var, includes)
29 AC_DEFUN(AC_HAVE_DECL,
30 [
31  AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
32     AC_TRY_COMPILE([$2],[int i = (int)$1],
33         ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
34  if test x"$ac_cv_have_$1_decl" = x"yes"; then
35     AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
36  fi
37 ])
38
39
40 # AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
41 #              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
42 #              [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
43 # ------------------------------------------------------
44 #
45 # Use a cache variable name containing both the library and function name,
46 # because the test really is for library $1 defining function $3, not
47 # just for library $1.  Separate tests with the same $1 and different $3s
48 # may have different results.
49 #
50 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
51 # is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
52 # ac_cv_lib_$lib_fun, which is definitely not what was meant.  Hence
53 # the AS_LITERAL_IF indirection.
54 #
55 # FIXME: This macro is extremely suspicious.  It DEFINEs unconditionally,
56 # whatever the FUNCTION, in addition to not being a *S macro.  Note
57 # that the cache does depend upon the function we are looking for.
58 #
59 # It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
60 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
61 # changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
62 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
63 # freedom.
64 AC_DEFUN([AC_CHECK_LIB_EXT],
65 [
66 AH_CHECK_LIB_EXT([$1])
67 ac_check_lib_ext_save_LIBS=$LIBS
68 LIBS="-l$1 $$2 $7 $LIBS"
69 AS_LITERAL_IF([$1],
70       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
71       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
72
73 m4_ifval([$3],
74  [
75     AH_CHECK_FUNC_EXT([$3])
76     AS_LITERAL_IF([$1],
77               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
78               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
79     AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
80         [AC_TRY_LINK_FUNC($3,
81                  [AS_VAR_SET(ac_Lib_func, yes);
82                   AS_VAR_SET(ac_Lib_ext, yes)],
83                  [AS_VAR_SET(ac_Lib_func, no);
84                   AS_VAR_SET(ac_Lib_ext, no)])
85         ])
86     AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
87         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
88     AS_VAR_POPDEF([ac_Lib_func])dnl
89  ],[
90     AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
91         [AC_TRY_LINK_FUNC([main],
92                  [AS_VAR_SET(ac_Lib_ext, yes)],
93                  [AS_VAR_SET(ac_Lib_ext, no)])
94         ])
95  ])
96 LIBS=$ac_check_lib_ext_save_LIBS
97
98 AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
99     [m4_default([$4], 
100         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
101                 case "$$2" in
102                     *-l$1*)
103                         ;;
104                     *)
105                         $2="-l$1 $$2"
106                         ;;
107                 esac])
108                 [$6]
109             ],
110             [$5])dnl
111 AS_VAR_POPDEF([ac_Lib_ext])dnl
112 ])# AC_CHECK_LIB_EXT
113
114 # AH_CHECK_LIB_EXT(LIBNAME)
115 # ---------------------
116 m4_define([AH_CHECK_LIB_EXT],
117 [AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
118              [Define to 1 if you have the `]$1[' library (-l]$1[).])])
119
120 # AC_CHECK_FUNCS_EXT(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
121 # -----------------------------------------------------------------
122 dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
123 dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
124 AC_DEFUN([AC_CHECK_FUNC_EXT],
125 [
126     AH_CHECK_FUNC_EXT($1)       
127     ac_check_func_ext_save_LIBS=$LIBS
128     LIBS="$2 $LIBS"
129     AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
130     AC_CACHE_CHECK([for $1], ac_var,
131         [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
132                 [AS_VAR_SET(ac_var, yes)],
133                 [AS_VAR_SET(ac_var, no)])])
134     LIBS=$ac_check_func_ext_save_LIBS
135     AS_IF([test AS_VAR_GET(ac_var) = yes], 
136             [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3], 
137             [$4])dnl
138 AS_VAR_POPDEF([ac_var])dnl
139 ])# AC_CHECK_FUNC
140
141 # AH_CHECK_FUNC_EXT(FUNCNAME)
142 # ---------------------
143 m4_define([AH_CHECK_FUNC_EXT],
144 [AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
145              [Define to 1 if you have the `]$1[' function.])])
146
147 dnl Define an AC_DEFINE with ifndef guard.
148 dnl AC_N_DEFINE(VARIABLE [, VALUE])
149 define(AC_N_DEFINE,
150 [cat >> confdefs.h <<\EOF
151 [#ifndef] $1
152 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
153 [#endif]
154 EOF
155 ])
156
157 dnl Add an #include
158 dnl AC_ADD_INCLUDE(VARIABLE)
159 define(AC_ADD_INCLUDE,
160 [cat >> confdefs.h <<\EOF
161 [#include] $1
162 EOF
163 ])
164
165 dnl Copied from libtool.m4
166 AC_DEFUN(AC_PROG_LD_GNU,
167 [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld,
168 [# I'd rather use --version here, but apparently some GNU ld's only accept -v.
169 if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
170   ac_cv_prog_gnu_ld=yes
171 else
172   ac_cv_prog_gnu_ld=no
173 fi])
174 ])
175
176 dnl Removes -I/usr/include/? from given variable
177 AC_DEFUN(CFLAGS_REMOVE_USR_INCLUDE,[
178   ac_new_flags=""
179   for i in [$]$1; do
180     case [$]i in
181     -I/usr/include|-I/usr/include/) ;;
182     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
183     esac
184   done
185   $1=[$]ac_new_flags
186 ])
187     
188 dnl Removes -L/usr/lib/? from given variable
189 AC_DEFUN(LIB_REMOVE_USR_LIB,[
190   ac_new_flags=""
191   for i in [$]$1; do
192     case [$]i in
193     -L/usr/lib|-L/usr/lib/) ;;
194     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
195     esac
196   done
197   $1=[$]ac_new_flags
198 ])
199
200 dnl From Bruno Haible.
201
202 AC_DEFUN(jm_ICONV,
203 [
204   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
205   dnl those with the standalone portable libiconv installed).
206   AC_MSG_CHECKING(for iconv in $1)
207     jm_cv_func_iconv="no"
208     jm_cv_lib_iconv=no
209     jm_cv_giconv=no
210     AC_TRY_LINK([#include <stdlib.h>
211 #include <giconv.h>],
212       [iconv_t cd = iconv_open("","");
213        iconv(cd,NULL,NULL,NULL,NULL);
214        iconv_close(cd);],
215       jm_cv_func_iconv=yes
216       jm_cv_giconv=yes)
217
218     if test "$jm_cv_func_iconv" != yes; then
219       AC_TRY_LINK([#include <stdlib.h>
220 #include <iconv.h>],
221         [iconv_t cd = iconv_open("","");
222          iconv(cd,NULL,NULL,NULL,NULL);
223          iconv_close(cd);],
224         jm_cv_func_iconv=yes)
225
226         if test "$jm_cv_lib_iconv" != yes; then
227           jm_save_LIBS="$LIBS"
228           LIBS="$LIBS -lgiconv"
229           AC_TRY_LINK([#include <stdlib.h>
230 #include <giconv.h>],
231             [iconv_t cd = iconv_open("","");
232              iconv(cd,NULL,NULL,NULL,NULL);
233              iconv_close(cd);],
234             jm_cv_lib_iconv=yes
235             jm_cv_func_iconv=yes
236             jm_cv_giconv=yes)
237           LIBS="$jm_save_LIBS"
238
239       if test "$jm_cv_func_iconv" != yes; then
240         jm_save_LIBS="$LIBS"
241         LIBS="$LIBS -liconv"
242         AC_TRY_LINK([#include <stdlib.h>
243 #include <iconv.h>],
244           [iconv_t cd = iconv_open("","");
245            iconv(cd,NULL,NULL,NULL,NULL);
246            iconv_close(cd);],
247           jm_cv_lib_iconv=yes
248           jm_cv_func_iconv=yes)
249         LIBS="$jm_save_LIBS"
250         fi
251       fi
252     fi
253
254   if test "$jm_cv_func_iconv" = yes; then
255     if test "$jm_cv_giconv" = yes; then
256       AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h])
257       AC_MSG_RESULT(yes)
258       ICONV_FOUND=yes
259     else
260       AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h])
261       AC_MSG_RESULT(yes)
262       ICONV_FOUND=yes
263     fi
264   else
265     AC_MSG_RESULT(no)
266   fi
267   if test "$jm_cv_lib_iconv" = yes; then
268     if test "$jm_cv_giconv" = yes; then
269       LIBS="$LIBS -lgiconv"
270     else
271       LIBS="$LIBS -liconv"
272     fi
273   fi
274 ])
275
276 dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR)
277 dnl This function doesn't add -I/usr/include into CFLAGS
278 AC_DEFUN(CFLAGS_ADD_DIR,[
279 if test "$2" != "/usr/include" ; then
280     $1="$$1 -I$2"
281 fi
282 ])
283
284 dnl LIB_ADD_DIR(LDFLAGS, $LIBDIR)
285 dnl This function doesn't add -L/usr/lib into LDFLAGS
286 AC_DEFUN(LIB_ADD_DIR,[
287 if test "$2" != "/usr/lib" ; then
288     $1="$$1 -L$2"
289 fi
290 ])
291
292 sinclude(build/smb_build/public.m4)
293 sinclude(build/smb_build/core.m4)