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