Always rebuild modules after running ./configure (to prevent
[jra/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     AC_TRY_LINK([#include <stdlib.h>
537 #include <giconv.h>],
538       [iconv_t cd = iconv_open("","");
539        iconv(cd,NULL,NULL,NULL,NULL);
540        iconv_close(cd);],
541       jm_cv_func_iconv=yes
542       jm_cv_giconv=yes)
543
544     if test "$jm_cv_func_iconv" != yes; then
545       AC_TRY_LINK([#include <stdlib.h>
546 #include <iconv.h>],
547         [iconv_t cd = iconv_open("","");
548          iconv(cd,NULL,NULL,NULL,NULL);
549          iconv_close(cd);],
550         jm_cv_func_iconv=yes)
551
552         if test "$jm_cv_lib_iconv" != yes; then
553           jm_save_LIBS="$LIBS"
554           LIBS="$LIBS -lgiconv"
555           AC_TRY_LINK([#include <stdlib.h>
556 #include <giconv.h>],
557             [iconv_t cd = iconv_open("","");
558              iconv(cd,NULL,NULL,NULL,NULL);
559              iconv_close(cd);],
560             jm_cv_lib_iconv=yes
561             jm_cv_func_iconv=yes
562             jm_cv_giconv=yes)
563           LIBS="$jm_save_LIBS"
564
565       if test "$jm_cv_func_iconv" != yes; then
566         jm_save_LIBS="$LIBS"
567         LIBS="$LIBS -liconv"
568         AC_TRY_LINK([#include <stdlib.h>
569 #include <iconv.h>],
570           [iconv_t cd = iconv_open("","");
571            iconv(cd,NULL,NULL,NULL,NULL);
572            iconv_close(cd);],
573           jm_cv_lib_iconv=yes
574           jm_cv_func_iconv=yes)
575         LIBS="$jm_save_LIBS"
576         fi
577       fi
578     fi
579
580   if test "$jm_cv_func_iconv" = yes; then
581     if test "$jm_cv_giconv" = yes; then
582       AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h])
583       AC_MSG_RESULT(yes)
584       ICONV_FOUND=yes
585     else
586       AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h])
587       AC_MSG_RESULT(yes)
588       ICONV_FOUND=yes
589     fi
590   else
591     AC_MSG_RESULT(no)
592   fi
593   if test "$jm_cv_lib_iconv" = yes; then
594     if test "$jm_cv_giconv" = yes; then
595       LIBS="$LIBS -lgiconv"
596     else
597       LIBS="$LIBS -liconv"
598     fi
599   fi
600 ])
601
602 dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR)
603 dnl This function doesn't add -I/usr/include into CFLAGS
604 AC_DEFUN(CFLAGS_ADD_DIR,[
605 if test "$2" != "/usr/include" ; then
606     $1="$$1 -I$2"
607 fi
608 ])
609
610 dnl LIB_ADD_DIR(LDFLAGS, $LIBDIR)
611 dnl This function doesn't add -L/usr/lib into LDFLAGS
612 AC_DEFUN(LIB_ADD_DIR,[
613 if test "$2" != "/usr/lib" ; then
614     $1="$$1 -L$2"
615 fi
616 ])
617
618 dnl AC_ENABLE_SHARED - implement the --enable-shared flag
619 dnl Usage: AC_ENABLE_SHARED[(DEFAULT)]
620 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
621 dnl   `yes'.
622 AC_DEFUN([AC_ENABLE_SHARED],
623 [define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
624 AC_ARG_ENABLE(shared,
625 changequote(<<, >>)dnl
626 <<  --enable-shared[=PKGS]    build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT],
627 changequote([, ])dnl
628 [p=${PACKAGE-default}
629 case $enableval in
630 yes) enable_shared=yes ;;
631 no) enable_shared=no ;;
632 *)
633   enable_shared=no
634   # Look at the argument we got.  We use all the common list separators.
635   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
636   for pkg in $enableval; do
637     if test "X$pkg" = "X$p"; then
638       enable_shared=yes
639     fi
640
641   done
642   IFS="$ac_save_ifs"
643   ;;
644 esac],
645 enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl
646 ])
647
648 dnl AC_ENABLE_STATIC - implement the --enable-static flag
649 dnl Usage: AC_ENABLE_STATIC[(DEFAULT)]
650 dnl   Where DEFAULT is either `yes' or `no'.  If omitted, it defaults to
651 dnl   `yes'.
652 AC_DEFUN([AC_ENABLE_STATIC],
653 [define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
654 AC_ARG_ENABLE(static,
655 changequote(<<, >>)dnl
656 <<  --enable-static[=PKGS]    build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT],
657 changequote([, ])dnl
658 [p=${PACKAGE-default}
659 case $enableval in
660 yes) enable_static=yes ;;
661 no) enable_static=no ;;
662 *)
663   enable_static=no
664   # Look at the argument we got.  We use all the common list separators.
665   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:,"
666   for pkg in $enableval; do
667     if test "X$pkg" = "X$p"; then
668       enable_static=yes
669     fi
670   done
671   IFS="$ac_save_ifs"
672   ;;
673 esac],
674 enable_static=AC_ENABLE_STATIC_DEFAULT)dnl
675 ])
676
677 dnl AC_DISABLE_STATIC - set the default static flag to --disable-static
678 AC_DEFUN([AC_DISABLE_STATIC],
679 [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
680 AC_ENABLE_STATIC(no)])