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