merge:
[metze/samba/wip.git] / source4 / aclocal.m4
1 dnl AC_VALIDATE_CACHE_SYSTEM_TYPE[(cmd)]
2 dnl if the cache file is inconsistent with the current host,
3 dnl target and build system types, execute CMD or print a default
4 dnl error message.
5 AC_DEFUN(AC_VALIDATE_CACHE_SYSTEM_TYPE, [
6     AC_REQUIRE([AC_CANONICAL_SYSTEM])
7     AC_MSG_CHECKING([config.cache system type])
8     if { test x"${ac_cv_host_system_type+set}" = x"set" &&
9          test x"$ac_cv_host_system_type" != x"$host"; } ||
10        { test x"${ac_cv_build_system_type+set}" = x"set" &&
11          test x"$ac_cv_build_system_type" != x"$build"; } ||
12        { test x"${ac_cv_target_system_type+set}" = x"set" &&
13          test x"$ac_cv_target_system_type" != x"$target"; }; then
14         AC_MSG_RESULT([different])
15         ifelse($#, 1, [$1],
16                 [AC_MSG_ERROR(["you must remove config.cache and restart configure"])])
17     else
18         AC_MSG_RESULT([same])
19     fi
20     ac_cv_host_system_type="$host"
21     ac_cv_build_system_type="$build"
22     ac_cv_target_system_type="$target"
23 ])
24
25
26 dnl test whether dirent has a d_off member
27 AC_DEFUN(AC_DIRENT_D_OFF,
28 [AC_CACHE_CHECK([for d_off in dirent], ac_cv_dirent_d_off,
29 [AC_TRY_COMPILE([
30 #include <unistd.h>
31 #include <sys/types.h>
32 #include <dirent.h>], [struct dirent d; d.d_off;],
33 ac_cv_dirent_d_off=yes, ac_cv_dirent_d_off=no)])
34 if test $ac_cv_dirent_d_off = yes; then
35   AC_DEFINE(HAVE_DIRENT_D_OFF,1,[Whether dirent has a d_off member])
36 fi
37 ])
38
39 dnl Specify the default build method of this module 
40 dnl SMB_MODULE_DEFAULT(name,default_build)
41 AC_DEFUN(SMB_MODULE_DEFAULT,
42 [
43         dnl Fall back to static if dlopen() is not available
44         eval MODULE_DEFAULT_$1=$2
45
46         if test x"MODULE_DEFAULT_$1" = xSHARED -a x"$ac_cv_func_dlopen" != xyes; then
47                 eval MODULE_DEFAULT_$1=STATIC
48         fi
49 ])
50
51 dnl Mark specified module as shared
52 dnl SMB_MODULE(name,default_build,static_files,shared_files,subsystem,whatif-static,whatif-shared,whatif-not)
53 AC_DEFUN(SMB_MODULE,
54 [
55         AC_MSG_CHECKING([how to build $1])
56         if test -z "$[MODULE_DEFAULT_][$1]"; then
57                 eval MODULE_DEFAULT_$1=$2
58
59                 if test x"MODULE_DEFAULT_$1" = xSHARED -a x"$ac_cv_func_dlopen" != xyes; then
60                         eval MODULE_DEFAULT_$1=STATIC
61                 fi
62         fi
63
64         if test "$[MODULE_][$1]"; then
65                 DEST=$[MODULE_][$1]
66         elif test "$[MODULE_]translit([$5], [A-Z], [a-z])" -a "$[MODULE_DEFAULT_][$1]"; then
67                 DEST=$[MODULE_]translit([$5], [A-Z], [a-z])
68         else
69                 DEST=$[MODULE_DEFAULT_][$1]
70         fi
71         
72         if test x"$DEST" = xSHARED; then
73                 AC_DEFINE([$1][_init], [init_module], [Whether to build $1 as shared module])
74                 $5_MODULES="$$5_MODULES $4"
75                 AC_MSG_RESULT([shared])
76                 [$7]
77                 string_shared_modules="$string_shared_modules $1"
78         elif test x"$DEST" = xSTATIC; then
79                 [init_static_modules_]translit([$5], [A-Z], [a-z])="$[init_static_modules_]translit([$5], [A-Z], [a-z]) $1_init();"
80                 string_static_modules="$string_static_modules $1"
81                 $5_STATIC="$$5_STATIC $3"
82                 AC_SUBST($5_STATIC)
83                 [$6]
84                 AC_MSG_RESULT([static])
85         else
86                 string_ignored_modules="$string_ignored_modules $1"
87                 [$8]
88                 AC_MSG_RESULT([not])
89         fi
90 ])
91
92 AC_DEFUN(SMB_SUBSYSTEM,
93 [
94         AC_SUBST($1_STATIC)
95         AC_SUBST($1_MODULES)
96         AC_DEFINE_UNQUOTED([static_init_]translit([$1], [A-Z], [a-z]), [{$init_static_modules_]translit([$1], [A-Z], [a-z])[}], [Static init functions])
97         ifelse([$2], , :, [rm -f $2])
98 ])
99
100 dnl AC_PROG_CC_FLAG(flag)
101 AC_DEFUN(AC_PROG_CC_FLAG,
102 [AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1,
103 [echo 'void f(){}' > conftest.c
104 if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then
105   ac_cv_prog_cc_$1=yes
106 else
107   ac_cv_prog_cc_$1=no
108 fi
109 rm -f conftest*
110 ])])
111
112 dnl see if a declaration exists for a function or variable
113 dnl defines HAVE_function_DECL if it exists
114 dnl AC_HAVE_DECL(var, includes)
115 AC_DEFUN(AC_HAVE_DECL,
116 [
117  AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[
118     AC_TRY_COMPILE([$2],[int i = (int)$1],
119         ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)])
120  if test x"$ac_cv_have_$1_decl" = x"yes"; then
121     AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available])
122  fi
123 ])
124
125
126 dnl check for a function in a library, but don't
127 dnl keep adding the same library to the LIBS variable.
128 dnl AC_LIBTESTFUNC(lib,func)
129 AC_DEFUN(AC_LIBTESTFUNC,
130 [case "$LIBS" in
131   *-l$1*) AC_CHECK_FUNCS($2) ;;
132   *) AC_CHECK_LIB($1, $2) 
133      AC_CHECK_FUNCS($2)
134   ;;
135   esac
136 ])
137
138 # AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION],
139 #              [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
140 #              [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES])
141 # ------------------------------------------------------
142 #
143 # Use a cache variable name containing both the library and function name,
144 # because the test really is for library $1 defining function $3, not
145 # just for library $1.  Separate tests with the same $1 and different $3s
146 # may have different results.
147 #
148 # Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3])
149 # is asking for trouble, since AC_CHECK_LIB($lib, fun) would give
150 # ac_cv_lib_$lib_fun, which is definitely not what was meant.  Hence
151 # the AS_LITERAL_IF indirection.
152 #
153 # FIXME: This macro is extremely suspicious.  It DEFINEs unconditionally,
154 # whatever the FUNCTION, in addition to not being a *S macro.  Note
155 # that the cache does depend upon the function we are looking for.
156 #
157 # It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just
158 # `ac_save_LIBS': there are many macros which don't want to see `LIBS'
159 # changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'.
160 # And ``ac_save_LIBS' is too tempting a name, so let's leave them some
161 # freedom.
162 AC_DEFUN([AC_CHECK_LIB_EXT],
163 [
164 AH_CHECK_LIB_EXT([$1])
165 ac_check_lib_ext_save_LIBS=$LIBS
166 LIBS="-l$1 $$2 $7 $LIBS"
167 AS_LITERAL_IF([$1],
168       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])],
169       [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl
170
171 m4_ifval([$3],
172  [
173     AH_CHECK_FUNC_EXT([$3])
174     AS_LITERAL_IF([$1],
175               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])],
176               [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl
177     AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func,
178         [AC_TRY_LINK_FUNC($3,
179                  [AS_VAR_SET(ac_Lib_func, yes);
180                   AS_VAR_SET(ac_Lib_ext, yes)],
181                  [AS_VAR_SET(ac_Lib_func, no);
182                   AS_VAR_SET(ac_Lib_ext, no)])
183         ])
184     AS_IF([test AS_VAR_GET(ac_Lib_func) = yes],
185         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl
186     AS_VAR_POPDEF([ac_Lib_func])dnl
187  ],[
188     AC_CACHE_CHECK([for -l$1], ac_Lib_ext,
189         [AC_TRY_LINK_FUNC([main],
190                  [AS_VAR_SET(ac_Lib_ext, yes)],
191                  [AS_VAR_SET(ac_Lib_ext, no)])
192         ])
193  ])
194 LIBS=$ac_check_lib_ext_save_LIBS
195
196 AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes],
197     [m4_default([$4], 
198         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
199                 case "$$2" in
200                     *-l$1*)
201                         ;;
202                     *)
203                         $2="-l$1 $$2"
204                         ;;
205                 esac])
206                 [$6]
207             ],
208             [$5])dnl
209 AS_VAR_POPDEF([ac_Lib_ext])dnl
210 ])# AC_CHECK_LIB_EXT
211
212 # AH_CHECK_LIB_EXT(LIBNAME)
213 # ---------------------
214 m4_define([AH_CHECK_LIB_EXT],
215 [AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1),
216              [Define to 1 if you have the `]$1[' library (-l]$1[).])])
217
218 # AC_CHECK_FUNCS_EXT(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
219 # -----------------------------------------------------------------
220 dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable.
221 dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE)
222 AC_DEFUN([AC_CHECK_FUNC_EXT],
223 [
224     AH_CHECK_FUNC_EXT($1)       
225     ac_check_func_ext_save_LIBS=$LIBS
226     LIBS="$2 $LIBS"
227     AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl
228     AC_CACHE_CHECK([for $1], ac_var,
229         [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])],
230                 [AS_VAR_SET(ac_var, yes)],
231                 [AS_VAR_SET(ac_var, no)])])
232     LIBS=$ac_check_func_ext_save_LIBS
233     AS_IF([test AS_VAR_GET(ac_var) = yes], 
234             [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3], 
235             [$4])dnl
236 AS_VAR_POPDEF([ac_var])dnl
237 ])# AC_CHECK_FUNC
238
239 # AH_CHECK_FUNC_EXT(FUNCNAME)
240 # ---------------------
241 m4_define([AH_CHECK_FUNC_EXT],
242 [AH_TEMPLATE(AS_TR_CPP(HAVE_$1),
243              [Define to 1 if you have the `]$1[' function.])])
244
245 dnl Define an AC_DEFINE with ifndef guard.
246 dnl AC_N_DEFINE(VARIABLE [, VALUE])
247 define(AC_N_DEFINE,
248 [cat >> confdefs.h <<\EOF
249 [#ifndef] $1
250 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
251 [#endif]
252 EOF
253 ])
254
255 dnl Add an #include
256 dnl AC_ADD_INCLUDE(VARIABLE)
257 define(AC_ADD_INCLUDE,
258 [cat >> confdefs.h <<\EOF
259 [#include] $1
260 EOF
261 ])
262
263 dnl Copied from libtool.m4
264 AC_DEFUN(AC_PROG_LD_GNU,
265 [AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld,
266 [# I'd rather use --version here, but apparently some GNU ld's only accept -v.
267 if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
268   ac_cv_prog_gnu_ld=yes
269 else
270   ac_cv_prog_gnu_ld=no
271 fi])
272 ])
273
274 # Configure paths for LIBXML2
275 # Toshio Kuratomi 2001-04-21
276 # Adapted from:
277 # Configure paths for GLIB
278 # Owen Taylor     97-11-3
279
280 dnl AM_PATH_XML2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
281 dnl Test for XML, and define XML_CFLAGS and XML_LIBS
282 dnl
283 AC_DEFUN(AM_PATH_XML2,[ 
284 AC_ARG_WITH(xml-prefix,
285             [  --with-xml-prefix=PFX   Prefix where libxml is installed (optional)],
286             xml_config_prefix="$withval", xml_config_prefix="")
287 AC_ARG_WITH(xml-exec-prefix,
288             [  --with-xml-exec-prefix=PFX Exec prefix where libxml is installed (optional)],
289             xml_config_exec_prefix="$withval", xml_config_exec_prefix="")
290 AC_ARG_ENABLE(xmltest,
291               [  --disable-xmltest       Do not try to compile and run a test LIBXML program],,
292               enable_xmltest=yes)
293
294   if test x$xml_config_exec_prefix != x ; then
295      xml_config_args="$xml_config_args --exec-prefix=$xml_config_exec_prefix"
296      if test x${XML2_CONFIG+set} != xset ; then
297         XML2_CONFIG=$xml_config_exec_prefix/bin/xml2-config
298      fi
299   fi
300   if test x$xml_config_prefix != x ; then
301      xml_config_args="$xml_config_args --prefix=$xml_config_prefix"
302      if test x${XML2_CONFIG+set} != xset ; then
303         XML2_CONFIG=$xml_config_prefix/bin/xml2-config
304      fi
305   fi
306
307   AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
308   min_xml_version=ifelse([$1], ,2.0.0,[$1])
309   AC_MSG_CHECKING(for libxml - version >= $min_xml_version)
310   no_xml=""
311   if test "$XML2_CONFIG" = "no" ; then
312     no_xml=yes
313   else
314     XML_CFLAGS=`$XML2_CONFIG $xml_config_args --cflags`
315     XML_LIBS=`$XML2_CONFIG $xml_config_args --libs`
316     xml_config_major_version=`$XML2_CONFIG $xml_config_args --version | \
317            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
318     xml_config_minor_version=`$XML2_CONFIG $xml_config_args --version | \
319            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
320     xml_config_micro_version=`$XML2_CONFIG $xml_config_args --version | \
321            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
322     if test "x$enable_xmltest" = "xyes" ; then
323       ac_save_CFLAGS="$CFLAGS"
324       ac_save_LIBS="$LIBS"
325       CFLAGS="$CFLAGS $XML_CFLAGS"
326       LIBS="$XML_LIBS $LIBS"
327 dnl
328 dnl Now check if the installed libxml is sufficiently new.
329 dnl (Also sanity checks the results of xml2-config to some extent)
330 dnl
331       rm -f conf.xmltest
332       AC_TRY_RUN([
333 #include <stdlib.h>
334 #include <stdio.h>
335 #include <string.h>
336 #include <libxml/xmlversion.h>
337
338 int 
339 main()
340 {
341   int xml_major_version, xml_minor_version, xml_micro_version;
342   int major, minor, micro;
343   char *tmp_version;
344
345   system("touch conf.xmltest");
346
347   /* Capture xml2-config output via autoconf/configure variables */
348   /* HP/UX 9 (%@#!) writes to sscanf strings */
349   tmp_version = (char *)strdup("$min_xml_version");
350   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
351      printf("%s, bad version string from xml2-config\n", "$min_xml_version");
352      exit(1);
353    }
354    free(tmp_version);
355
356    /* Capture the version information from the header files */
357    tmp_version = (char *)strdup(LIBXML_DOTTED_VERSION);
358    if (sscanf(tmp_version, "%d.%d.%d", &xml_major_version, &xml_minor_version, &xml_micro_version) != 3) {
359      printf("%s, bad version string from libxml includes\n", "LIBXML_DOTTED_VERSION");
360      exit(1);
361    }
362    free(tmp_version);
363
364  /* Compare xml2-config output to the libxml headers */
365   if ((xml_major_version != $xml_config_major_version) ||
366       (xml_minor_version != $xml_config_minor_version) ||
367       (xml_micro_version != $xml_config_micro_version))
368     {
369       printf("*** libxml header files (version %d.%d.%d) do not match\n",
370          xml_major_version, xml_minor_version, xml_micro_version);
371       printf("*** xml2-config (version %d.%d.%d)\n",
372          $xml_config_major_version, $xml_config_minor_version, $xml_config_micro_version);
373       return 1;
374     } 
375 /* Compare the headers to the library to make sure we match */
376   /* Less than ideal -- doesn't provide us with return value feedback, 
377    * only exits if there's a serious mismatch between header and library.
378    */
379     LIBXML_TEST_VERSION;
380
381     /* Test that the library is greater than our minimum version */
382     if ((xml_major_version > major) ||
383         ((xml_major_version == major) && (xml_minor_version > minor)) ||
384         ((xml_major_version == major) && (xml_minor_version == minor) &&
385         (xml_micro_version >= micro)))
386       {
387         return 0;
388        }
389      else
390       {
391         printf("\n*** An old version of libxml (%d.%d.%d) was found.\n",
392                xml_major_version, xml_minor_version, xml_micro_version);
393         printf("*** You need a version of libxml newer than %d.%d.%d. The latest version of\n",
394            major, minor, micro);
395         printf("*** libxml is always available from ftp://ftp.xmlsoft.org.\n");
396         printf("***\n");
397         printf("*** If you have already installed a sufficiently new version, this error\n");
398         printf("*** probably means that the wrong copy of the xml2-config shell script is\n");
399         printf("*** being found. The easiest way to fix this is to remove the old version\n");
400         printf("*** of LIBXML, but you can also set the XML2_CONFIG environment to point to the\n");
401         printf("*** correct copy of xml2-config. (In this case, you will have to\n");
402         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
403         printf("*** so that the correct libraries are found at run-time))\n");
404     }
405   return 1;
406 }
407 ],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
408        CFLAGS="$ac_save_CFLAGS"
409        LIBS="$ac_save_LIBS"
410      fi
411   fi
412
413   if test "x$no_xml" = x ; then
414      AC_MSG_RESULT(yes (version $xml_config_major_version.$xml_config_minor_version.$xml_config_micro_version))
415      ifelse([$2], , :, [$2])     
416   else
417      AC_MSG_RESULT(no)
418      if test "$XML2_CONFIG" = "no" ; then
419        echo "*** The xml2-config script installed by LIBXML could not be found"
420        echo "*** If libxml was installed in PREFIX, make sure PREFIX/bin is in"
421        echo "*** your path, or set the XML2_CONFIG environment variable to the"
422        echo "*** full path to xml2-config."
423      else
424        if test -f conf.xmltest ; then
425         :
426        else
427           echo "*** Could not run libxml test program, checking why..."
428           CFLAGS="$CFLAGS $XML_CFLAGS"
429           LIBS="$LIBS $XML_LIBS"
430           AC_TRY_LINK([
431 #include <libxml/xmlversion.h>
432 #include <stdio.h>
433 ],      [ LIBXML_TEST_VERSION; return 0;],
434         [ echo "*** The test program compiled, but did not run. This usually means"
435           echo "*** that the run-time linker is not finding LIBXML or finding the wrong"
436           echo "*** version of LIBXML. If it is not finding LIBXML, you'll need to set your"
437           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
438           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
439           echo "*** is required on your system"
440           echo "***"
441           echo "*** If you have an old version installed, it is best to remove it, although"
442           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
443         [ echo "*** The test program failed to compile or link. See the file config.log for the"
444           echo "*** exact error that occured. This usually means LIBXML was incorrectly installed"
445           echo "*** or that you have moved LIBXML since it was installed. In the latter case, you"
446           echo "*** may want to edit the xml2-config script: $XML2_CONFIG" ])
447           CFLAGS="$ac_save_CFLAGS"
448           LIBS="$ac_save_LIBS"
449        fi
450      fi
451
452      XML_CFLAGS=""
453      XML_LIBS=""
454      ifelse([$3], , :, [$3])
455   fi
456   AC_SUBST(XML_CFLAGS)
457   AC_SUBST(XML_LIBS)
458   rm -f conf.xmltest
459 ])
460
461 # =========================================================================
462 # AM_PATH_MYSQL : MySQL library
463
464 dnl AM_PATH_MYSQL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
465 dnl Test for MYSQL, and define MYSQL_CFLAGS and MYSQL_LIBS
466 dnl
467 AC_DEFUN(AM_PATH_MYSQL,
468 [dnl
469 dnl Get the cflags and libraries from the mysql_config script
470 dnl
471 AC_ARG_WITH(mysql-prefix,[  --with-mysql-prefix=PFX   Prefix where MYSQL is installed (optional)],
472             mysql_prefix="$withval", mysql_prefix="")
473 AC_ARG_WITH(mysql-exec-prefix,[  --with-mysql-exec-prefix=PFX Exec prefix where MYSQL is installed (optional)],
474             mysql_exec_prefix="$withval", mysql_exec_prefix="")
475
476   if test x$mysql_exec_prefix != x ; then
477      mysql_args="$mysql_args --exec-prefix=$mysql_exec_prefix"
478      if test x${MYSQL_CONFIG+set} != xset ; then
479         MYSQL_CONFIG=$mysql_exec_prefix/bin/mysql_config
480      fi
481   fi
482   if test x$mysql_prefix != x ; then
483      mysql_args="$mysql_args --prefix=$mysql_prefix"
484      if test x${MYSQL_CONFIG+set} != xset ; then
485         MYSQL_CONFIG=$mysql_prefix/bin/mysql_config
486      fi
487   fi
488
489   AC_REQUIRE([AC_CANONICAL_TARGET])
490   AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no)
491   AC_MSG_CHECKING(for MYSQL)
492   no_mysql=""
493   if test "$MYSQL_CONFIG" = "no" ; then
494     MYSQL_CFLAGS=""
495     MYSQL_LIBS=""
496     AC_MSG_RESULT(no)
497      ifelse([$2], , :, [$2])
498   else
499     MYSQL_CFLAGS=`$MYSQL_CONFIG $mysqlconf_args --cflags | sed -e "s/'//g"`
500     MYSQL_LIBS=`$MYSQL_CONFIG $mysqlconf_args --libs | sed -e "s/'//g"`
501     AC_MSG_RESULT(yes)
502     ifelse([$1], , :, [$1])
503   fi
504   AC_SUBST(MYSQL_CFLAGS)
505   AC_SUBST(MYSQL_LIBS)
506 ])
507
508 dnl Removes -I/usr/include/? from given variable
509 AC_DEFUN(CFLAGS_REMOVE_USR_INCLUDE,[
510   ac_new_flags=""
511   for i in [$]$1; do
512     case [$]i in
513     -I/usr/include|-I/usr/include/) ;;
514     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
515     esac
516   done
517   $1=[$]ac_new_flags
518 ])
519     
520 dnl Removes -L/usr/lib/? from given variable
521 AC_DEFUN(LIB_REMOVE_USR_LIB,[
522   ac_new_flags=""
523   for i in [$]$1; do
524     case [$]i in
525     -L/usr/lib|-L/usr/lib/) ;;
526     *) ac_new_flags="[$]ac_new_flags [$]i" ;;
527     esac
528   done
529   $1=[$]ac_new_flags
530 ])
531
532 dnl From Bruno Haible.
533
534 AC_DEFUN(jm_ICONV,
535 [
536   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
537   dnl those with the standalone portable libiconv installed).
538   AC_MSG_CHECKING(for iconv in $1)
539     jm_cv_func_iconv="no"
540     jm_cv_lib_iconv=no
541     jm_cv_giconv=no
542     AC_TRY_LINK([#include <stdlib.h>
543 #include <giconv.h>],
544       [iconv_t cd = iconv_open("","");
545        iconv(cd,NULL,NULL,NULL,NULL);
546        iconv_close(cd);],
547       jm_cv_func_iconv=yes
548       jm_cv_giconv=yes)
549
550     if test "$jm_cv_func_iconv" != yes; then
551       AC_TRY_LINK([#include <stdlib.h>
552 #include <iconv.h>],
553         [iconv_t cd = iconv_open("","");
554          iconv(cd,NULL,NULL,NULL,NULL);
555          iconv_close(cd);],
556         jm_cv_func_iconv=yes)
557
558         if test "$jm_cv_lib_iconv" != yes; then
559           jm_save_LIBS="$LIBS"
560           LIBS="$LIBS -lgiconv"
561           AC_TRY_LINK([#include <stdlib.h>
562 #include <giconv.h>],
563             [iconv_t cd = iconv_open("","");
564              iconv(cd,NULL,NULL,NULL,NULL);
565              iconv_close(cd);],
566             jm_cv_lib_iconv=yes
567             jm_cv_func_iconv=yes
568             jm_cv_giconv=yes)
569           LIBS="$jm_save_LIBS"
570
571       if test "$jm_cv_func_iconv" != yes; then
572         jm_save_LIBS="$LIBS"
573         LIBS="$LIBS -liconv"
574         AC_TRY_LINK([#include <stdlib.h>
575 #include <iconv.h>],
576           [iconv_t cd = iconv_open("","");
577            iconv(cd,NULL,NULL,NULL,NULL);
578            iconv_close(cd);],
579           jm_cv_lib_iconv=yes
580           jm_cv_func_iconv=yes)
581         LIBS="$jm_save_LIBS"
582         fi
583       fi
584     fi
585
586   if test "$jm_cv_func_iconv" = yes; then
587     if test "$jm_cv_giconv" = yes; then
588       AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h])
589       AC_MSG_RESULT(yes)
590       ICONV_FOUND=yes
591     else
592       AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h])
593       AC_MSG_RESULT(yes)
594       ICONV_FOUND=yes
595     fi
596   else
597     AC_MSG_RESULT(no)
598   fi
599   if test "$jm_cv_lib_iconv" = yes; then
600     if test "$jm_cv_giconv" = yes; then
601       LIBS="$LIBS -lgiconv"
602     else
603       LIBS="$LIBS -liconv"
604     fi
605   fi
606 ])
607
608 dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR)
609 dnl This function doesn't add -I/usr/include into CFLAGS
610 AC_DEFUN(CFLAGS_ADD_DIR,[
611 if test "$2" != "/usr/include" ; then
612     $1="$$1 -I$2"
613 fi
614 ])
615
616 dnl LIB_ADD_DIR(LDFLAGS, $LIBDIR)
617 dnl This function doesn't add -L/usr/lib into LDFLAGS
618 AC_DEFUN(LIB_ADD_DIR,[
619 if test "$2" != "/usr/lib" ; then
620     $1="$$1 -L$2"
621 fi
622 ])
623
624 dnl AC_ENABLE_SHARED - implement the --enable-shared flag
625 dnl Usage: AC_ENABLE_SHARED[(DEFAULT)]
626 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
627 dnl   `yes'.
628 AC_DEFUN([AC_ENABLE_SHARED],
629 [define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
630 AC_ARG_ENABLE(shared,
631 changequote(<<, >>)dnl
632 <<  --enable-shared[=PKGS]    build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT],
633 changequote([, ])dnl
634 [p=${PACKAGE-default}
635 case $enableval in
636 yes) enable_shared=yes ;;
637 no) enable_shared=no ;;
638 *)
639   enable_shared=no
640   # Look at the argument we got.  We use all the common list separators.
641   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
642   for pkg in $enableval; do
643     if test "X$pkg" = "X$p"; then
644       enable_shared=yes
645     fi
646
647   done
648   IFS="$ac_save_ifs"
649   ;;
650 esac],
651 enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl
652 ])
653
654 dnl AC_ENABLE_STATIC - implement the --enable-static flag
655 dnl Usage: AC_ENABLE_STATIC[(DEFAULT)]
656 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
657 dnl   `yes'.
658 AC_DEFUN([AC_ENABLE_STATIC],
659 [define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
660 AC_ARG_ENABLE(static,
661 changequote(<<, >>)dnl
662 <<  --enable-static[=PKGS]    build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT],
663 changequote([, ])dnl
664 [p=${PACKAGE-default}
665 case $enableval in
666 yes) enable_static=yes ;;
667 no) enable_static=no ;;
668 *)
669   enable_static=no
670   # Look at the argument we got.  We use all the common list separators.
671   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
672   for pkg in $enableval; do
673     if test "X$pkg" = "X$p"; then
674       enable_static=yes
675     fi
676   done
677   IFS="$ac_save_ifs"
678   ;;
679 esac],
680 enable_static=AC_ENABLE_STATIC_DEFAULT)dnl
681 ])
682
683 dnl AC_DISABLE_STATIC - set the default static flag to --disable-static
684 AC_DEFUN([AC_DISABLE_STATIC],
685 [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
686 AC_ENABLE_STATIC(no)])