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