s3:build: add an optional full version argument to the SMB_LIBRARY() macro.
[Samba.git] / source3 / m4 / aclocal.m4
blobafd7c7491a12d327ece8f4d68c2eecb11200aa1a
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])
14 dnl Mark specified module as shared
15 dnl SMB_MODULE(name,static_files,shared_files,subsystem,whatif-static,whatif-shared)
16 AC_DEFUN(SMB_MODULE,
18         AC_MSG_CHECKING([how to build $1])
19         if test "$[MODULE_][$1]"; then
20                 DEST=$[MODULE_][$1]
21         elif test "$[MODULE_]translit([$4], [A-Z], [a-z])" -a "$[MODULE_DEFAULT_][$1]"; then
22                 DEST=$[MODULE_]translit([$4], [A-Z], [a-z])
23         else
24                 DEST=$[MODULE_DEFAULT_][$1]
25         fi
26         
27         if test x"$DEST" = xSHARED; then
28                 AC_DEFINE([$1][_init], [init_samba_module], [Whether to build $1 as shared module])
29                 $4_MODULES="$$4_MODULES $3"
30                 AC_MSG_RESULT([shared])
31                 [$6]
32                 string_shared_modules="$string_shared_modules $1"
33         elif test x"$DEST" = xSTATIC; then
34                 [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z])  $1_init();"
35                 [decl_static_modules_]translit([$4], [A-Z], [a-z])="$[decl_static_modules_]translit([$4], [A-Z], [a-z]) extern NTSTATUS $1_init(void);"
36                 string_static_modules="$string_static_modules $1"
37                 $4_STATIC="$$4_STATIC $2"
38                 AC_SUBST($4_STATIC)
39                 [$5]
40                 AC_MSG_RESULT([static])
41         else
42             string_ignored_modules="$string_ignored_modules $1"
43                 AC_MSG_RESULT([not])
44         fi
47 AC_DEFUN(SMB_SUBSYSTEM,
49         AC_SUBST($1_STATIC)
50         AC_SUBST($1_MODULES)
51         AC_DEFINE_UNQUOTED([static_init_]translit([$1], [A-Z], [a-z]), [{$init_static_modules_]translit([$1], [A-Z], [a-z])[}], [Static init functions])
52         AC_DEFINE_UNQUOTED([static_decl_]translit([$1], [A-Z], [a-z]), [$decl_static_modules_]translit([$1], [A-Z], [a-z]), [Decl of Static init functions])
53         ifelse([$2], , :, [rm -f $2])
57 dnl SMB_LIBRARY(name, soversion, fullversion, default, reason)
58 dnl
59 dnl configure build and use of an (internal) shared library
60 dnl
61 AC_DEFUN([SMB_LIBRARY],
63 m4_pushdef([LIBNAME], [lib$1])
64 m4_pushdef([LIBUC], [m4_toupper(LIBNAME)])
65 m4_pushdef([LIBLIBS], [-l$1])
67 LIBUC[_SHARED_TARGET]=bin/LIBNAME.$SHLIBEXT
68 LIBUC[_STATIC_TARGET]=bin/LIBNAME.a
69 LIBUC[_SHARED]=
70 LIBUC[_STATIC]=
71 LIBUC[_LIBS]=LIBLIBS
72 LIBUC[_TARGET]=
73 [INSTALL_]LIBUC=
74 [UNINSTALL_]LIBUC=
76 m4_if([$2], [], [LIBUC[_SOVER]=0], [LIBUC[_SOVER]=$2])
77 m4_if([$3], [], [LIBUC[_FULLVER]=$LIBUC[_SOVER]], [LIBUC[_FULLVER]=$3])
79 AC_SUBST(LIBUC[_SHARED_TARGET])
80 AC_SUBST(LIBUC[_STATIC_TARGET])
81 AC_SUBST(LIBUC[_SHARED])
82 AC_SUBST(LIBUC[_STATIC])
83 AC_SUBST(LIBUC[_LIBS])
84 AC_SUBST(LIBUC[_TARGET])
85 AC_SUBST([INSTALL_]LIBUC)
86 AC_SUBST([UNINSTALL_]LIBUC)
87 AC_SUBST(LIBUC[_SOVER])
88 AC_SUBST(LIBUC[_FULLVER])
90 AC_MSG_CHECKING([whether to build the LIBNAME shared library])
91 m4_if([$4], [no], [
92 dnl set the default to not build the shared lib
93 AC_ARG_WITH(LIBNAME,
94 AS_HELP_STRING([--with-]LIBNAME,
95         m4_if([$5], [],
96                 [Build the LIBNAME shared library (default=no)],
97                 [Build the LIBNAME shared library (default=no ($5))])),
99 case "$withval" in
100         yes)
101                 build_lib=yes
102                 ;;
103         *)
104                 AC_MSG_RESULT(no)
105                 build_lib=no
106                 ;;
107 esac
110 # if unspecified, default is not to build
111 AC_MSG_RESULT(no)
112 build_lib=no
116 dnl by default, try to build the shared lib
117 AC_ARG_WITH(LIBNAME,
118 AS_HELP_STRING([--with-]LIBNAME,
119         [Build the LIBNAME shared library (default=yes if shared libs supported)]),
121 case "$withval" in
122         no)
123                 AC_MSG_RESULT(no)
124                 build_lib=no
125                 ;;
126         *)
127                 build_lib=yes
128                 ;;
129 esac
132 # if unspecified, default is to build it if possible.
133 build_lib=yes
138 if eval test x"$build_lib" = "xyes" ; then
139         # only set the install targets if the user chose the library
140         [INSTALL_]LIBUC=[install]LIBNAME
141         [UNINSTALL_]LIBUC=[uninstall]LIBNAME
142         if eval $BLDSHARED = true; then
143                 LIBUC[_SHARED]=$LIBUC[_SHARED_TARGET]
144                 LIBUC[_TARGET]=$LIBUC[_SHARED_TARGET]
145                 AC_MSG_RESULT(yes)
146                 if test x"$USESHARED" != x"true" -o x"$[LINK_]LIBUC" = "xSTATIC" ; then
147                         enable_static=yes
148                         LIBUC[_TARGET]=$LIBUC[_STATIC_TARGET]
149                         LIBUC[_LIBS]=$LIBUC[_STATIC_TARGET]
150                 else
151                         LIBUC[_LIBS]=LIBLIBS
152                 fi
153         else
154                 enable_static=yes
155                 LIBUC[_TARGET]=$LIBUC[_STATIC_TARGET]
156                 LIBUC[_LIBS]=$LIBUC[_STATIC_TARGET]
157                 AC_MSG_RESULT(no shared library support -- will supply static library)
158         fi
159 else
160         enable_static=yes
161         AC_MSG_RESULT(shared library not selected, but will supply static library)
163 if test $enable_static = yes; then
164         LIBUC[_STATIC]=$LIBUC[_STATIC_TARGET]
167 m4_popdef([LIBNAME])
168 m4_popdef([LIBUC])
169 m4_popdef([LIBLIBS])
174 dnl AC_LIBTESTFUNC(lib, function, [actions if found], [actions if not found])
175 dnl Check for a function in a library, but don't keep adding the same library
176 dnl to the LIBS variable.  Check whether the function is available in the
177 dnl current LIBS before adding the library which prevents us spuriously
178 dnl adding libraries for symbols that are in libc.
180 dnl On success, the default actions ensure that HAVE_FOO is defined. The lib
181 dnl is always added to $LIBS if it was found to be necessary. The caller
182 dnl can use SMB_REMOVE_LIB to strp this if necessary.
183 AC_DEFUN([AC_LIBTESTFUNC],
185   AC_CHECK_FUNCS($2,
186       [
187         # $2 was found in libc or existing $LIBS
188         m4_ifval([$3],
189             [
190                 $3
191             ],
192             [
193                 AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
194                     [Whether $2 is available])
195             ])
196       ],
197       [
198         # $2 was not found, try adding lib$1
199         case " $LIBS " in
200           *\ -l$1\ *)
201             m4_ifval([$4],
202                 [
203                     $4
204                 ],
205                 [
206                     # $2 was not found and we already had lib$1
207                     # nothing to do here by default
208                     true
209                 ])
210             ;;
211           *)
212             # $2 was not found, try adding lib$1
213             AC_CHECK_LIB($1, $2,
214               [
215                 LIBS="-l$1 $LIBS"
216                 m4_ifval([$3],
217                     [
218                         $3
219                     ],
220                     [
221                         AC_DEFINE(translit([HAVE_$2], [a-z], [A-Z]), 1,
222                             [Whether $2 is available])
223                     ])
224               ],
225               [
226                 m4_ifval([$4],
227                     [
228                         $4
229                     ],
230                     [
231                         # $2 was not found in lib$1
232                         # nothing to do here by default
233                         true
234                     ])
235               ])
236           ;;
237         esac
238       ])
241 # AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
242 #              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
243 #              [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
244 # ------------------------------------------------------
246 # Use a cache variable name containing both the library and function name,
247 # because the test really is for library $1 defining function $3, not
248 # just for library $1.  Separate tests with the same $1 and different $3s
249 # may have different results.
251 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
252 # is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
253 # ac_cv_lib_$lib_fun, which is definitely not what was meant.  Hence
254 # the AS_LITERAL_IF indirection.
256 # FIXME: This macro is extremely suspicious.  It DEFINEs unconditionally,
257 # whatever the FUNCTION, in addition to not being a *S macro.  Note
258 # that the cache does depend upon the function we are looking for.
260 # It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
261 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
262 # changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
263 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
264 # freedom.
265 AC_DEFUN([AC_CHECK_LIB_EXT],
267 AH_CHECK_LIB_EXT([$1])
268 ac_check_lib_ext_save_LIBS=$LIBS
269 LIBS="-l$1 $$2 $7 $LIBS"
270 AS_LITERAL_IF([$1],
271       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
272       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
274 m4_ifval([$3],
276     AH_CHECK_FUNC_EXT([$3])
277     AS_LITERAL_IF([$1],
278               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
279               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
280     AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
281         [AC_TRY_LINK_FUNC($3,
282                  [AS_VAR_SET(ac_Lib_func, yes);
283                   AS_VAR_SET(ac_Lib_ext, yes)],
284                  [AS_VAR_SET(ac_Lib_func, no);
285                   AS_VAR_SET(ac_Lib_ext, no)])
286         ])
287     AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
288         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
289     AS_VAR_POPDEF([ac_Lib_func])dnl
290  ],[
291     AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
292         [AC_TRY_LINK_FUNC([main],
293                  [AS_VAR_SET(ac_Lib_ext, yes)],
294                  [AS_VAR_SET(ac_Lib_ext, no)])
295         ])
296  ])
297 LIBS=$ac_check_lib_ext_save_LIBS
299 AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
300     [m4_default([$4], 
301         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
302                 case "$$2" in
303                     *-l$1*)
304                         ;;
305                     *)
306                         $2="-l$1 $$2"
307                         ;;
308                 esac])
309                 [$6]
310             ],
311             [$5])dnl
312 AS_VAR_POPDEF([ac_Lib_ext])dnl
313 ])# AC_CHECK_LIB_EXT
315 # AH_CHECK_LIB_EXT(LIBNAME)
316 # ---------------------
317 m4_define([AH_CHECK_LIB_EXT],
318 [AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
319              [Define to 1 if you have the `]$1[' library (-l]$1[).])])
321 # AC_CHECK_FUNCS_EXT(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
322 # -----------------------------------------------------------------
323 dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
324 dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
325 AC_DEFUN([AC_CHECK_FUNC_EXT],
327     AH_CHECK_FUNC_EXT($1)       
328     ac_check_func_ext_save_LIBS=$LIBS
329     LIBS="$2 $LIBS"
330     AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
331     AC_CACHE_CHECK([for $1], ac_var,
332         [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
333                 [AS_VAR_SET(ac_var, yes)],
334                 [AS_VAR_SET(ac_var, no)])])
335     LIBS=$ac_check_func_ext_save_LIBS
336     AS_IF([test AS_VAR_GET(ac_var) = yes], 
337             [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3], 
338             [$4])dnl
339 AS_VAR_POPDEF([ac_var])dnl
340 ])# AC_CHECK_FUNC_EXT
342 # AH_CHECK_FUNC_EXT(FUNCNAME)
343 # ---------------------
344 m4_define([AH_CHECK_FUNC_EXT],
345 [AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
346              [Define to 1 if you have the `]$1[' function.])])
348 dnl Define an AC_DEFINE with ifndef guard.
349 dnl AC_N_DEFINE(VARIABLE [, VALUE])
350 define(AC_N_DEFINE,
351 [cat >> confdefs.h <<\EOF
352 [#ifndef] $1
353 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
354 [#endif]
358 dnl Add an #include
359 dnl AC_ADD_INCLUDE(VARIABLE)
360 define(AC_ADD_INCLUDE,
361 [cat >> confdefs.h <<\EOF
362 [#include] $1
366 dnl Copied from libtool.m4
367 AC_DEFUN(AC_PROG_LD_GNU,
368 [AC_CACHE_CHECK([if the linker used by compiler is GNU ld], ac_cv_prog_gnu_ld,
369 [# I'd rather use --version here, but apparently some GNU ld's only accept -v.
370 if $CC -Wl,-v /dev/null 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
371   ac_cv_prog_gnu_ld=yes
372 else
373   ac_cv_prog_gnu_ld=no
374 fi])
377 dnl Removes -I/usr/include/? from given variable
378 AC_DEFUN(CFLAGS_REMOVE_USR_INCLUDE,[
379   ac_new_flags=""
380   for i in [$]$1; do
381     case [$]i in
382     -I/usr/include|-I/usr/include/) ;;
383     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
384     esac
385   done
386   $1=[$]ac_new_flags
389 dnl Removes '-L/usr/lib[/]', '-Wl,-rpath,/usr/lib[/]'
390 dnl and '-Wl,-rpath -Wl,/usr/lib[/]' from given variable
391 AC_DEFUN(LIB_REMOVE_USR_LIB,[
392   ac_new_flags=""
393   l=""
394   for i in [$]$1; do
395     case [$]l[$]i in
396     -L/usr/lib) ;;
397     -L/usr/lib/) ;;
398     -L/usr/lib64) ;;
399     -L/usr/lib64/) ;;
400     -Wl,-rpath,/usr/lib) l="";;
401     -Wl,-rpath,/usr/lib/) l="";;
402     -Wl,-rpath,/usr/lib64) l="";;
403     -Wl,-rpath,/usr/lib64/) l="";;
404     -Wl,-rpath) l=[$]i;;
405     -Wl,-rpath-Wl,/usr/lib) l="";;
406     -Wl,-rpath-Wl,/usr/lib/) l="";;
407     -Wl,-rpath-Wl,/usr/lib64) l="";;
408     -Wl,-rpath-Wl,/usr/lib64/) l="";;
409     *)
410         s=" "
411         if test x"[$]ac_new_flags" = x""; then
412             s="";
413         fi
414         if test x"[$]l" = x""; then
415             ac_new_flags="[$]ac_new_flags[$]s[$]i";
416         else
417             ac_new_flags="[$]ac_new_flags[$]s[$]l [$]i";
418         fi
419         l=""
420         ;;
421     esac
422   done
423   $1=[$]ac_new_flags
426 dnl From Bruno Haible.
428 AC_DEFUN(jm_ICONV,
430   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
431   dnl those with the standalone portable libiconv installed).
432   AC_MSG_CHECKING(for iconv in $1)
433     jm_cv_func_iconv="no"
434     jm_cv_lib_iconv=""
435     jm_cv_giconv=no
436     jm_save_LIBS="$LIBS"
438   dnl Check for include in giconv.h but no lib needed
439   if test "$jm_cv_func_iconv" != yes; then
440     AC_TRY_LINK([#include <stdlib.h>
441 #include <giconv.h>],
442       [iconv_t cd = iconv_open("","");
443        iconv(cd,NULL,NULL,NULL,NULL);
444        iconv_close(cd);],
445        jm_cv_func_iconv=yes
446        jm_cv_include="giconv.h"
447        jm_cv_giconv="yes"
448        jm_cv_lib_iconv="")
450     dnl Standard iconv.h include, lib in glibc or libc ...
451     if test "$jm_cv_func_iconv" != yes; then
452       AC_TRY_LINK([#include <stdlib.h>
453 #include <iconv.h>],
454         [iconv_t cd = iconv_open("","");
455          iconv(cd,NULL,NULL,NULL,NULL);
456          iconv_close(cd);],
457          jm_cv_include="iconv.h"
458          jm_cv_func_iconv=yes
459          jm_cv_lib_iconv="")
461       dnl Include in giconv.h, libgiconv needed to link
462       if test "$jm_cv_func_iconv" != yes; then
463         jm_save_LIBS="$LIBS"
464         LIBS="$LIBS -lgiconv"
465         AC_TRY_LINK([#include <stdlib.h>
466 #include <giconv.h>],
467           [iconv_t cd = iconv_open("","");
468            iconv(cd,NULL,NULL,NULL,NULL);
469            iconv_close(cd);],
470           jm_cv_lib_iconv=yes
471           jm_cv_func_iconv=yes
472           jm_cv_include="giconv.h"
473           jm_cv_giconv=yes
474           jm_cv_lib_iconv="giconv")
476         LIBS="$jm_save_LIBS"
478         dnl Include in iconv.h, libiconv needed to link
479         if test "$jm_cv_func_iconv" != yes; then
480           jm_save_LIBS="$LIBS"
481           LIBS="$LIBS -liconv"
482           AC_TRY_LINK([#include <stdlib.h>
483 #include <iconv.h>],
484             [iconv_t cd = iconv_open("","");
485              iconv(cd,NULL,NULL,NULL,NULL);
486              iconv_close(cd);],
487             jm_cv_include="iconv.h"
488             jm_cv_func_iconv=yes
489             jm_cv_lib_iconv="iconv")
490           LIBS="$jm_save_LIBS"
492           dnl Include in biconv.h, libbiconv needed to link
493           if test "$jm_cv_func_iconv" != yes; then
494             jm_save_LIBS="$LIBS"
495             LIBS="$LIBS -lbiconv"
496             AC_TRY_LINK([#include <stdlib.h>
497 #include <biconv.h>],
498               [iconv_t cd = iconv_open("","");
499                iconv(cd,NULL,NULL,NULL,NULL);
500                iconv_close(cd);],
501               jm_cv_lib_iconv=yes
502               jm_cv_func_iconv=yes
503               jm_cv_include="biconv.h"
504               jm_cv_biconv=yes
505               jm_cv_lib_iconv="biconv")
507             LIBS="$jm_save_LIBS"
508           fi
509         fi
510       fi
511     fi
512   fi
513   if test "$jm_cv_func_iconv" = yes; then
514     if test "$jm_cv_giconv" = yes; then
515       AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h])
516       AC_MSG_RESULT(yes)
517       ICONV_FOUND=yes
518     else
519       if test "$jm_cv_biconv" = yes; then
520         AC_DEFINE(HAVE_BICONV, 1, [What header to include for iconv() function: biconv.h])
521         AC_MSG_RESULT(yes)
522         ICONV_FOUND=yes
523       else 
524         AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h])
525         AC_MSG_RESULT(yes)
526         ICONV_FOUND=yes
527       fi
528     fi
529   else
530     AC_MSG_RESULT(no)
531   fi
534 AC_DEFUN(rjs_CHARSET,[
535   dnl Find out if we can convert from $1 to UCS2-LE
536   AC_MSG_CHECKING([can we convert from $1 to UCS2-LE?])
537   AC_TRY_RUN([
538 #include <$jm_cv_include>
539 main(){
540     iconv_t cd = iconv_open("$1", "UCS-2LE");
541     if (cd == 0 || cd == (iconv_t)-1) {
542         return -1;
543     }
544     return 0;
546   ],ICONV_CHARSET=$1,ICONV_CHARSET=no,ICONV_CHARSET=cross)
547   AC_MSG_RESULT($ICONV_CHARSET)
550 dnl AC_ENABLE_SHARED - implement the --enable-shared flag
551 dnl Usage: AC_ENABLE_SHARED[(DEFAULT)]
552 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
553 dnl   `yes'.
554 AC_DEFUN([AC_ENABLE_SHARED],
555 [define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
556 AC_ARG_ENABLE(shared,
557 changequote(<<, >>)dnl
558 <<  --enable-shared[=PKGS]    build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT],
559 changequote([, ])dnl
560 [p=${PACKAGE-default}
561 case $enableval in
562 yes) enable_shared=yes ;;
563 no) enable_shared=no ;;
565   enable_shared=no
566   # Look at the argument we got.  We use all the common list separators.
567   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
568   for pkg in $enableval; do
569     if test "X$pkg" = "X$p"; then
570       enable_shared=yes
571     fi
573   done
574   IFS="$ac_save_ifs"
575   ;;
576 esac],
577 enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl
580 dnl AC_ENABLE_STATIC - implement the --enable-static flag
581 dnl Usage: AC_ENABLE_STATIC[(DEFAULT)]
582 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
583 dnl   `yes'.
584 AC_DEFUN([AC_ENABLE_STATIC],
585 [define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
586 AC_ARG_ENABLE(static,
587 changequote(<<, >>)dnl
588 <<  --enable-static[=PKGS]    build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT],
589 changequote([, ])dnl
590 [p=${PACKAGE-default}
591 case $enableval in
592 yes) enable_static=yes ;;
593 no) enable_static=no ;;
595   enable_static=no
596   # Look at the argument we got.  We use all the common list separators.
597   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
598   for pkg in $enableval; do
599     if test "X$pkg" = "X$p"; then
600       enable_static=yes
601     fi
602   done
603   IFS="$ac_save_ifs"
604   ;;
605 esac],
606 enable_static=AC_ENABLE_STATIC_DEFAULT)dnl
609 dnl AC_DISABLE_STATIC - set the default static flag to --disable-static
610 AC_DEFUN([AC_DISABLE_STATIC],
611 [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
612 AC_ENABLE_STATIC(no)])
614 dnl AC_TRY_COMMAND_NO_STDERR - also fail if there is output on stderr
615 AC_DEFUN( [AC_TRY_COMMAND_NO_STDERR],
617         { OUT=`($1) 3>&AS_MESSAGE_LOG_FD 2>&1 1>&3`
618         RC=$?
619         echo "\$?=$RC" >&AS_MESSAGE_LOG_FD
620         if test x"$OUT" != x ; then
621                 echo "stderr:" >&AS_MESSAGE_LOG_FD
622                 echo "$OUT" >&AS_MESSAGE_LOG_FD
623         fi
624         test $RC -eq 0 -a x"$OUT" = x ; }
627 dnl AC_TRY_RUN_STRICT(PROGRAM,CFLAGS,CPPFLAGS,LDFLAGS,
628 dnl             [ACTION-IF-TRUE],[ACTION-IF-FALSE],
629 dnl             [ACTION-IF-CROSS-COMPILING = RUNTIME-ERROR])
630 AC_DEFUN( [AC_TRY_RUN_STRICT],
632         old_CFLAGS="$CFLAGS";
633         CFLAGS="$2";
634         export CFLAGS;
635         old_CPPFLAGS="$CPPFLAGS";
636         CPPFLAGS="$3";
637         export CPPFLAGS;
638         old_LDFLAGS="$LDFLAGS";
639         LDFLAGS="$4";
640         export LDFLAGS;
641         AC_TRY_RUN([$1],[$5],[$6],[$7])
642         CFLAGS="$old_CFLAGS";
643         old_CFLAGS="";
644         export CFLAGS;
645         CPPFLAGS="$old_CPPFLAGS";
646         old_CPPFLAGS="";
647         export CPPFLAGS;
648         LDFLAGS="$old_LDFLAGS";
649         old_LDFLAGS="";
650         export LDFLAGS;
653 dnl SMB_CHECK_SYSCONF(varname)
654 dnl Tests whether the sysconf(3) variable "varname" is available.
655 AC_DEFUN([SMB_CHECK_SYSCONF],
657     AC_CACHE_CHECK([for sysconf($1)],
658         samba_cv_SYSCONF$1,
659         [
660             AC_TRY_LINK([#include <unistd.h>],
661                 [ return sysconf($1) == -1 ? 1 : 0; ],
662                 [ samba_cv_SYSCONF$1=yes ],
663                 [ samba_cv_SYSCONF$1=no ])
664         ])
666     if test x"$samba_cv_SYSCONF$1" = x"yes" ; then
667         AC_DEFINE(SYSCONF$1, 1, [Whether sysconf($1) is available])
668     fi
671 dnl SMB_IS_LIBPTHREAD_LINKED([actions if true], [actions if false])
672 dnl Test whether the current LIBS results in libpthread being present.
673 dnl Execute the corresponding user action list.
674 AC_DEFUN([SMB_IS_LIBPTHREAD_LINKED],
676     AC_MSG_CHECKING(if libpthread is linked)
677     AC_TRY_LINK([],
678         [return pthread_create(0, 0, 0, 0);],
679         [
680             AC_MSG_RESULT(yes)
681             $1
682         ],
683         [
684             AC_MSG_RESULT(no)
685             $2
686         ])
689 dnl SMB_REMOVE_LIB(lib)
690 dnl Remove the given library from $LIBS
691 AC_DEFUN([SMB_REMOVE_LIB],
693     LIBS=`echo $LIBS | sed '-es/-l$1//g'`
696 dnl SMB_CHECK_DMAPI([actions if true], [actions if false])
697 dnl Check whether DMAPI is available and is a version that we know
698 dnl how to deal with. The default truth action is to set samba_dmapi_libs
699 dnl to the list of necessary libraries, and to define USE_DMAPI.
700 AC_DEFUN([SMB_CHECK_DMAPI],
702     samba_dmapi_libs=""
704     if test x"$samba_dmapi_libs" = x"" ; then
705         AC_CHECK_LIB(dm, dm_get_eventlist,
706                 [ samba_dmapi_libs="-ldm"], [])
707     fi
709     if test x"$samba_dmapi_libs" = x"" ; then
710         AC_CHECK_LIB(jfsdm, dm_get_eventlist,
711                 [samba_dmapi_libs="-ljfsdm"], [])
712     fi
714     if test x"$samba_dmapi_libs" = x"" ; then
715         AC_CHECK_LIB(dmapi, dm_get_eventlist,
716                 [samba_dmapi_libs="-ldmapi"], [])
717     fi
719     if test x"$samba_dmapi_libs" = x"" ; then
720         AC_CHECK_LIB(xdsm, dm_get_eventlist,
721                 [samba_dmapi_libs="-lxdsm"], [])
722     fi
725     # Only bother to test ehaders if we have a candidate DMAPI library
726     if test x"$samba_dmapi_libs" != x"" ; then
727         AC_CHECK_HEADERS(sys/dmi.h xfs/dmapi.h sys/jfsdmapi.h sys/dmapi.h dmapi.h)
728     fi
730     if test x"$samba_dmapi_libs" != x"" ; then
731         samba_dmapi_save_LIBS="$LIBS"
732         LIBS="$LIBS $samba_dmapi_libs"
733         AC_TRY_LINK(
734                 [
735 #include <time.h>      /* needed by Tru64 */
736 #include <sys/types.h> /* needed by AIX */
737 #ifdef HAVE_XFS_DMAPI_H
738 #include <xfs/dmapi.h>
739 #elif defined(HAVE_SYS_DMI_H)
740 #include <sys/dmi.h>
741 #elif defined(HAVE_SYS_JFSDMAPI_H)
742 #include <sys/jfsdmapi.h>
743 #elif defined(HAVE_SYS_DMAPI_H)
744 #include <sys/dmapi.h>
745 #elif defined(HAVE_DMAPI_H)
746 #include <dmapi.h>
747 #endif
748                 ],
749                 [
750 /* This link test is designed to fail on IRI 6.4, but should
751  * succeed on Linux, IRIX 6.5 and AIX.
752  */
753         char * version;
754         dm_eventset_t events;
755         /* This doesn't take an argument on IRIX 6.4. */
756         dm_init_service(&version);
757         /* IRIX 6.4 expects events to be a pointer. */
758         DMEV_ISSET(DM_EVENT_READ, events);
759                 ],
760                 [
761                     true # DMAPI link test succeeded
762                 ],
763                 [
764                     # DMAPI link failure
765                     samba_dmapi_libs=
766                 ])
767         LIBS="$samba_dmapi_save_LIBS"
768     fi
770     if test x"$samba_dmapi_libs" = x"" ; then
771         # DMAPI detection failure actions begin
772         ifelse($2, [],
773             [
774                 AC_ERROR(Failed to detect a supported DMAPI implementation)
775             ],
776             [
777                 $2
778             ])
779         # DMAPI detection failure actions end
780     else
781         # DMAPI detection success actions start
782         ifelse($1, [],
783             [
784                 AC_DEFINE(USE_DMAPI, 1,
785                     [Whether we should build DMAPI integration components])
786                 AC_MSG_NOTICE(Found DMAPI support in $samba_dmapi_libs)
787             ],
788             [
789                 $1
790             ])
791         # DMAPI detection success actions end
792     fi
796 dnl SMB_IF_RTSIGNAL_BUG([actions if true],
797 dnl                     [actions if false],
798 dnl                     [actions if cross compiling])
799 dnl Test whether we can call sigaction with RT_SIGNAL_NOTIFY and
800 dnl RT_SIGNAL_LEASE (also RT_SIGNAL_AIO for good measure, though
801 dnl I don't believe that triggers any bug.
803 dnl See the samba-technical thread titled "Failed to setup
804 dnl RT_SIGNAL_NOTIFY handler" for details on the bug in question.
805 AC_DEFUN([SMB_IF_RTSIGNAL_BUG],
807     rt_signal_notify_works=yes
808     rt_signal_lease_works=yes
809     rt_signal_aio_works=yes
811     AC_MSG_CHECKING(if sigaction works with realtime signals)
812     AC_TRY_RUN(
813         [
814 #include <sys/types.h>
815 #include <fcntl.h>
816 #include <signal.h>
818 #ifndef SIGRTMIN
819 #define SIGRTMIN NSIG
820 #endif
821 /* from smbd/notify_kernel.c */
822 #ifndef RT_SIGNAL_NOTIFY
823 #define RT_SIGNAL_NOTIFY (SIGRTMIN+2)
824 #endif
826 /* from smbd/aio.c */
827 #ifndef RT_SIGNAL_AIO
828 #define RT_SIGNAL_AIO (SIGRTMIN+3)
829 #endif
831 /* from smbd/oplock_linux.c */
832 #ifndef RT_SIGNAL_LEASE
833 #define RT_SIGNAL_LEASE (SIGRTMIN+1)
834 #endif
836 static void signal_handler(int sig, siginfo_t *info, void *unused)
838     int do_nothing = 0;
841 int main(void)
843     int result = 0;
844     struct sigaction act = {0};
846     act.sa_sigaction = signal_handler;
847     act.sa_flags = SA_SIGINFO;
848     sigemptyset( &act.sa_mask );
850     if (sigaction(RT_SIGNAL_LEASE, &act, 0) != 0) {
851             /* Failed to setup RT_SIGNAL_LEASE handler */
852             result += 1;
853     }
855     if (sigaction(RT_SIGNAL_NOTIFY, &act, 0) != 0) {
856             /* Failed to setup RT_SIGNAL_NOTIFY handler */
857             result += 10;
858     }
860     if (sigaction(RT_SIGNAL_AIO, &act, 0) != 0) {
861             /* Failed to setup RT_SIGNAL_AIO handler */
862             result += 100;
863     }
865     /* zero on success */
866     return result;
868         ],
869         [
870             AC_MSG_RESULT(yes)
871             $2
872         ],
873         [
874             AC_MSG_RESULT(no)
875             case "$ac_status" in
876                 1|11|101|111)  rt_signal_lease_ok=no ;;
877             esac
878             case "$ac_status" in
879                 10|11|110|111)  rt_signal_notify_ok=no ;;
880             esac
881             case "$ac_status" in
882                 100|110|101|111)  rt_signal_aio_ok=no ;;
883             esac
884             $2
885         ],
886         [
887             AC_MSG_RESULT(cross)
888             $3
889         ])
892 m4_include(../lib/replace/libreplace.m4)