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