r15260: Don't dereference NULL pointers to obtain array lengths - found by
[samba.git] / source / 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 dnl AC_SEARCH_LIBS_EXT(FUNCTION, SEARCH-LIBS, EXT_LIBS,
121 dnl                    [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
122 dnl                    [OTHER-LIBRARIES])
123 dnl --------------------------------------------------------
124 dnl Search for a library defining FUNC, if it's not already available.
125 AC_DEFUN([AC_SEARCH_LIBS_EXT],
126 [AC_CACHE_CHECK([for library containing $1], [ac_cv_search_ext_$1],
127 [
128 ac_func_search_ext_save_LIBS=$LIBS
129 ac_cv_search_ext_$1=no
130 AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
131                [ac_cv_search_ext_$1="none required"])
132 if test "$ac_cv_search_ext_$1" = no; then
133   for ac_lib in $2; do
134     LIBS="-l$ac_lib $$3 $6 $ac_func_search_save_ext_LIBS"
135     AC_LINK_IFELSE([AC_LANG_CALL([], [$1])],
136                    [ac_cv_search_ext_$1="-l$ac_lib"
137 break])
138   done
139 fi
140 LIBS=$ac_func_search_ext_save_LIBS])
141 AS_IF([test "$ac_cv_search_ext_$1" != no],
142   [test "$ac_cv_search_ext_$1" = "none required" || $3="$ac_cv_search_ext_$1 $$3"
143   $4],
144       [$5])dnl
145 ])
146
147 dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
148 dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
149 AC_DEFUN([AC_CHECK_FUNC_EXT],
150 [
151     AH_CHECK_FUNC_EXT($1)       
152     ac_check_func_ext_save_LIBS=$LIBS
153     LIBS="$2 $LIBS"
154     AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
155     AC_CACHE_CHECK([for $1], ac_var,
156         [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
157                 [AS_VAR_SET(ac_var, yes)],
158                 [AS_VAR_SET(ac_var, no)])])
159     LIBS=$ac_check_func_ext_save_LIBS
160     AS_IF([test AS_VAR_GET(ac_var) = yes], 
161             [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3], 
162             [$4])dnl
163 AS_VAR_POPDEF([ac_var])dnl
164 ])# AC_CHECK_FUNC
165
166 # AH_CHECK_FUNC_EXT(FUNCNAME)
167 # ---------------------
168 m4_define([AH_CHECK_FUNC_EXT],
169 [AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
170              [Define to 1 if you have the `]$1[' function.])])
171
172 dnl Define an AC_DEFINE with ifndef guard.
173 dnl AC_N_DEFINE(VARIABLE [, VALUE])
174 define(AC_N_DEFINE,
175 [cat >> confdefs.h <<\EOF
176 [#ifndef] $1
177 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
178 [#endif]
179 EOF
180 ])
181
182 dnl Add an #include
183 dnl AC_ADD_INCLUDE(VARIABLE)
184 define(AC_ADD_INCLUDE,
185 [cat >> confdefs.h <<\EOF
186 [#include] $1
187 EOF
188 ])
189
190 dnl Copied from libtool.m4
191 AC_DEFUN(AC_PROG_LD_GNU,
192 [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld,
193 [# I'd rather use --version here, but apparently some GNU ld's only accept -v.
194 if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
195   ac_cv_prog_gnu_ld=yes
196 else
197   ac_cv_prog_gnu_ld=no
198 fi])
199 ])
200
201 dnl Removes -I/usr/include/? from given variable
202 AC_DEFUN(CFLAGS_REMOVE_USR_INCLUDE,[
203   ac_new_flags=""
204   for i in [$]$1; do
205     case [$]i in
206     -I/usr/include|-I/usr/include/) ;;
207     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
208     esac
209   done
210   $1=[$]ac_new_flags
211 ])
212     
213 dnl Removes -L/usr/lib/? from given variable
214 AC_DEFUN(LIB_REMOVE_USR_LIB,[
215   ac_new_flags=""
216   for i in [$]$1; do
217     case [$]i in
218     -L/usr/lib|-L/usr/lib/) ;;
219     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
220     esac
221   done
222   $1=[$]ac_new_flags
223 ])
224
225 dnl From Bruno Haible.
226
227 AC_DEFUN(jm_ICONV,
228 [
229   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
230   dnl those with the standalone portable libiconv installed).
231   AC_MSG_CHECKING(for iconv in $1)
232     jm_cv_func_iconv="no"
233     jm_cv_lib_iconv=no
234     jm_cv_giconv=no
235     AC_TRY_LINK([#include <stdlib.h>
236 #include <giconv.h>],
237       [iconv_t cd = iconv_open("","");
238        iconv(cd,NULL,NULL,NULL,NULL);
239        iconv_close(cd);],
240       jm_cv_func_iconv=yes
241       jm_cv_giconv=yes)
242
243     if test "$jm_cv_func_iconv" != yes; then
244       AC_TRY_LINK([#include <stdlib.h>
245 #include <iconv.h>],
246         [iconv_t cd = iconv_open("","");
247          iconv(cd,NULL,NULL,NULL,NULL);
248          iconv_close(cd);],
249         jm_cv_func_iconv=yes)
250
251         if test "$jm_cv_lib_iconv" != yes; then
252           jm_save_LIBS="$LIBS"
253           LIBS="$LIBS -lgiconv"
254           AC_TRY_LINK([#include <stdlib.h>
255 #include <giconv.h>],
256             [iconv_t cd = iconv_open("","");
257              iconv(cd,NULL,NULL,NULL,NULL);
258              iconv_close(cd);],
259             jm_cv_lib_iconv=yes
260             jm_cv_func_iconv=yes
261             jm_cv_giconv=yes)
262           LIBS="$jm_save_LIBS"
263
264       if test "$jm_cv_func_iconv" != yes; then
265         jm_save_LIBS="$LIBS"
266         LIBS="$LIBS -liconv"
267         AC_TRY_LINK([#include <stdlib.h>
268 #include <iconv.h>],
269           [iconv_t cd = iconv_open("","");
270            iconv(cd,NULL,NULL,NULL,NULL);
271            iconv_close(cd);],
272           jm_cv_lib_iconv=yes
273           jm_cv_func_iconv=yes)
274         LIBS="$jm_save_LIBS"
275         fi
276       fi
277     fi
278
279   if test "$jm_cv_func_iconv" = yes; then
280     if test "$jm_cv_giconv" = yes; then
281       AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h])
282       AC_MSG_RESULT(yes)
283       ICONV_FOUND=yes
284     else
285       AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h])
286       AC_MSG_RESULT(yes)
287       ICONV_FOUND=yes
288     fi
289   else
290     AC_MSG_RESULT(no)
291   fi
292   if test "$jm_cv_lib_iconv" = yes; then
293     if test "$jm_cv_giconv" = yes; then
294       LIBS="$LIBS -lgiconv"
295     else
296       LIBS="$LIBS -liconv"
297     fi
298   fi
299 ])
300
301 dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR)
302 dnl This function doesn't add -I/usr/include into CFLAGS
303 AC_DEFUN(CFLAGS_ADD_DIR,[
304 if test "$2" != "/usr/include" ; then
305     $1="$$1 -I$2"
306 fi
307 ])
308
309 dnl LIB_ADD_DIR(LDFLAGS, $LIBDIR)
310 dnl This function doesn't add -L/usr/lib into LDFLAGS
311 AC_DEFUN(LIB_ADD_DIR,[
312 if test "$2" != "/usr/lib" ; then
313     $1="$$1 -L$2"
314 fi
315 ])
316
317 sinclude(build/m4/public.m4)
318 sinclude(build/m4/core.m4)
319 sinclude(build/m4/ax_cflags_gcc_option.m4)
320 sinclude(build/m4/ax_cflags_irix_option.m4)
321 sinclude(build/m4/smb_cc_features.m4)