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