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