Use of libcharset (for portability).
[gedcom-parse.git] / acinclude.m4
1 dnl $Id$
2 dnl $Name$
3
4 dnl From codeset.m4 (in libcharset):
5 #serial 2
6
7 dnl From Bruno Haible.
8
9 AC_DEFUN(jm_LANGINFO_CODESET,
10 [
11   AC_CHECK_HEADERS(langinfo.h)
12   AC_CHECK_FUNCS(nl_langinfo)
13
14   AC_CACHE_CHECK([for nl_langinfo and CODESET], jm_cv_langinfo_codeset,
15     [AC_TRY_LINK([#include <langinfo.h>],
16       [char* cs = nl_langinfo(CODESET);],
17       jm_cv_langinfo_codeset=yes,
18       jm_cv_langinfo_codeset=no)
19     ])
20   if test $jm_cv_langinfo_codeset = yes; then
21     AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
22       [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
23   fi
24 ])
25
26 dnl From glibc21.m4 (in libcharset):
27 #serial 2
28
29 # Test for the GNU C Library, version 2.1 or newer.
30 # From Bruno Haible.
31
32 AC_DEFUN(jm_GLIBC21,
33   [
34     AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer,
35       ac_cv_gnu_library_2_1,
36       [AC_EGREP_CPP([Lucky GNU user],
37         [
38 #include <features.h>
39 #ifdef __GNU_LIBRARY__
40  #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
41   Lucky GNU user
42  #endif
43 #endif
44         ],
45         ac_cv_gnu_library_2_1=yes,
46         ac_cv_gnu_library_2_1=no)
47       ]
48     )
49     AC_SUBST(GLIBC21)
50     GLIBC21="$ac_cv_gnu_library_2_1"
51   ]
52 )
53
54 dnl From iconv.m4:
55 #serial AM2
56
57 dnl From Bruno Haible.
58
59 AC_DEFUN([AM_ICONV],
60 [
61   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
62   dnl those with the standalone portable GNU libiconv installed).
63
64   AC_ARG_WITH([libiconv-prefix],
65 [  --with-libiconv-prefix=DIR  search for libiconv in DIR/include and DIR/lib], [
66     # Addition Peter Verthez
67     ICONV_PATH=`echo "$withval" | tr : '/bin'`
68     ICONV_PATH="$ICONV_PATH/bin"
69     AC_SUBST(ICONV_PATH)
70     # end of addition
71
72     for dir in `echo "$withval" | tr : ' '`; do
73       if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
74       if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
75     done
76    ])
77
78   AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
79     am_cv_func_iconv="no, consider installing GNU libiconv"
80     am_cv_lib_iconv=no
81     AC_TRY_LINK([#include <stdlib.h>
82 #include <iconv.h>],
83       [iconv_t cd = iconv_open("","");
84        iconv(cd,NULL,NULL,NULL,NULL);
85        iconv_close(cd);],
86       am_cv_func_iconv=yes)
87     if test "$am_cv_func_iconv" != yes; then
88       am_save_LIBS="$LIBS"
89       LIBS="$LIBS -liconv"
90       AC_TRY_LINK([#include <stdlib.h>
91 #include <iconv.h>],
92         [iconv_t cd = iconv_open("","");
93          iconv(cd,NULL,NULL,NULL,NULL);
94          iconv_close(cd);],
95         am_cv_lib_iconv=yes
96         am_cv_func_iconv=yes)
97       LIBS="$am_save_LIBS"
98     fi
99   ])
100   if test "$am_cv_func_iconv" = yes; then
101     AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
102     AC_MSG_CHECKING([for iconv declaration])
103     AC_CACHE_VAL(am_cv_proto_iconv, [
104       AC_TRY_COMPILE([
105 #include <stdlib.h>
106 #include <iconv.h>
107 extern
108 #ifdef __cplusplus
109 "C"
110 #endif
111 #if defined(__STDC__) || defined(__cplusplus)
112 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
113 #else
114 size_t iconv();
115 #endif
116 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
117       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);"])
118     am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
119     AC_MSG_RESULT([$]{ac_t:-
120          }[$]am_cv_proto_iconv)
121     AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
122       [Define as const if the declaration of iconv() needs const.])
123   fi
124   LIBICONV=
125   if test "$am_cv_lib_iconv" = yes; then
126     LIBICONV="-liconv"
127   fi
128   AC_SUBST(LIBICONV)
129 ])
130
131 dnl Own functions
132 dnl AC_GLIBC_ICONV()
133 dnl Checks whether iconv is coming from glibc, defines USE_GLIBC_ICONV if so
134 dnl The variable $is_glibc_iconv contains yes or no
135 AC_DEFUN(AC_GLIBC_ICONV, [
136   AC_CACHE_CHECK(for the GNU C Library iconv implementation, is_glibc_iconv, [
137     AC_EGREP_CPP(yes,
138     [
139 #include <iconv.h>
140 #ifdef __GLIBC__
141 yes
142 #endif
143     ], is_glibc_iconv=yes, is_glibc_iconv=no)
144   ])
145   if test "$is_glibc_iconv" = yes; then
146     AC_DEFINE(USE_GLIBC_ICONV,1,
147       [Define if the GNU implementation of iconv in glibc is used])
148   fi
149 ])
150
151 dnl AC_LIBICONV_HAS_ANSEL()
152 dnl Checks whether libiconv has ANSEL support
153 dnl The variable $is_ansel_supported contains yes or no
154 AC_DEFUN(AC_LIBICONV_HAS_ANSEL, [
155   AC_CACHE_CHECK(for ANSEL support in libiconv, is_ansel_supported, [
156     my_save_LIBS="$LIBS"
157     LIBS="$LIBS $LIBICONV"
158     AC_TRY_RUN([
159 #include <iconv.h>
160 int main() {
161   iconv_t cd = iconv_open("UTF-8","ANSEL");
162   return (cd == (iconv_t)-1);
163 }
164     ],
165     is_ansel_supported=yes,
166     is_ansel_supported=no,
167     is_ansel_supported=no)
168     LIBS="$my_save_LIBS"
169   ])
170 ])