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