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