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