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