Local macro's for configure.in.
[gedcom-parse.git] / acinclude.m4
1 dnl From iconv.m4:
2 #serial AM2
3
4 dnl From Bruno Haible.
5
6 AC_DEFUN([AM_ICONV],
7 [
8   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
9   dnl those with the standalone portable GNU libiconv installed).
10
11   AC_ARG_WITH([libiconv-prefix],
12 [  --with-libiconv-prefix=DIR  search for libiconv in DIR/include and DIR/lib], [
13     for dir in `echo "$withval" | tr : ' '`; do
14       if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
15       if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
16     done
17    ])
18
19   AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
20     am_cv_func_iconv="no, consider installing GNU libiconv"
21     am_cv_lib_iconv=no
22     AC_TRY_LINK([#include <stdlib.h>
23 #include <iconv.h>],
24       [iconv_t cd = iconv_open("","");
25        iconv(cd,NULL,NULL,NULL,NULL);
26        iconv_close(cd);],
27       am_cv_func_iconv=yes)
28     if test "$am_cv_func_iconv" != yes; then
29       am_save_LIBS="$LIBS"
30       LIBS="$LIBS -liconv"
31       AC_TRY_LINK([#include <stdlib.h>
32 #include <iconv.h>],
33         [iconv_t cd = iconv_open("","");
34          iconv(cd,NULL,NULL,NULL,NULL);
35          iconv_close(cd);],
36         am_cv_lib_iconv=yes
37         am_cv_func_iconv=yes)
38       LIBS="$am_save_LIBS"
39     fi
40   ])
41   if test "$am_cv_func_iconv" = yes; then
42     AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
43     AC_MSG_CHECKING([for iconv declaration])
44     AC_CACHE_VAL(am_cv_proto_iconv, [
45       AC_TRY_COMPILE([
46 #include <stdlib.h>
47 #include <iconv.h>
48 extern
49 #ifdef __cplusplus
50 "C"
51 #endif
52 #if defined(__STDC__) || defined(__cplusplus)
53 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
54 #else
55 size_t iconv();
56 #endif
57 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
58       am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
59     am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
60     AC_MSG_RESULT([$]{ac_t:-
61          }[$]am_cv_proto_iconv)
62     AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
63       [Define as const if the declaration of iconv() needs const.])
64   fi
65   LIBICONV=
66   if test "$am_cv_lib_iconv" = yes; then
67     LIBICONV="-liconv"
68   fi
69   AC_SUBST(LIBICONV)
70 ])
71
72 dnl Own functions
73 dnl AC_GLIBC_ICONV()
74 dnl Checks whether iconv is coming from glibc, defines USE_GLIBC_ICONV if so
75 dnl The variable $is_glibc_iconv contains yes or no
76 AC_DEFUN(AC_GLIBC_ICONV, [
77   AC_CACHE_CHECK(for the GNU C Library iconv implementation, is_glibc_iconv, [
78     AC_EGREP_CPP(yes,
79     [
80 #include <iconv.h>
81 #ifdef __GLIBC__
82 yes
83 #endif
84     ], is_glibc_iconv=yes, is_glibc_iconv=no)
85   ])
86   if test "$is_glibc_iconv" = yes; then
87     AC_DEFINE(USE_GLIBC_ICONV,1,
88       [Define if the GNU implementation of iconv in glibc is used])
89   fi
90 ])
91
92 dnl AC_LIBICONV_HAS_ANSEL()
93 dnl Checks whether libiconv has ANSEL support
94 dnl The variable $is_ansel_supported contains yes or no
95 AC_DEFUN(AC_LIBICONV_HAS_ANSEL, [
96   AC_CACHE_CHECK(for ANSEL support in libiconv, is_ansel_supported, [
97     my_save_LIBS="$LIBS"
98     LIBS="$LIBS $LIBICONV"
99     AC_TRY_RUN([
100 #include <iconv.h>
101 int main() {
102   iconv_t cd = iconv_open("UTF-8","ANSEL");
103   return (cd == (iconv_t)-1);
104 }
105     ],
106     is_ansel_supported=yes,
107     is_ansel_supported=no,
108     is_ansel_supported=no)
109     LIBS="$my_save_LIBS"
110   ])
111 ])