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