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