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