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