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