Writing metadata xattr on directories with sticky bit set, FR#94
[netatalk.git] / macros / iconv.m4
1 AC_DEFUN([AC_NETATALK_CHECK_ICONV],
2 [
3
4 dnl     #################################################
5 dnl     # check for libiconv support
6         saved_CPPFLAGS="$CPPFLAGS"
7         savedcflags="$CFLAGS"
8         savedldflags="$LDFLAGS"
9         ICONV_CFLAGS=""
10         ICONV_LIBS=""
11
12         AC_ARG_WITH(libiconv,
13         [  --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include [[default=auto]]],
14         [ case "$withval" in
15           no)
16             ;;
17           yes)
18             ;;
19           *)
20             ICONV_CFLAGS="-I$withval/include"
21             ICONV_LIBS="-L$withval/$atalk_libname"
22             ;;
23           esac ],
24           withval="no"
25         )       
26
27         CFLAGS="$ICONV_CFLAGS $CFLAGS"
28         LDFLAGS="$LDFLAGS $ICONV_LIBS -liconv"
29
30         AC_CACHE_CHECK([for libiconv],netatalk_cv_iconv,[
31           AC_TRY_LINK([
32 #include <stdlib.h>
33 #include <iconv.h>
34 ],[
35         iconv_t cd = iconv_open("","");
36         iconv(cd,NULL,NULL,NULL,NULL);
37         iconv_close(cd);
38 ], netatalk_cv_iconv=yes, netatalk_cv_iconv=no, netatalk_cv_iconv=cross)])
39
40         if test x"$netatalk_cv_iconv" = x"yes"; then
41             ICONV_LIBS="$ICONV_LIBS -liconv"
42         else
43 dnl         # unset C-/LDFLAGS so we can detect glibc iconv, if available
44             CFLAGS="$savedcflags"
45             LDFLAGS="$savedldflags"
46             ICONV_LIBS=""
47             ICONV_CFLAGS=""
48             if test x"$withval" != x"no"; then
49                 AC_MSG_ERROR([libiconv not found])
50             fi
51         fi
52
53
54         CFLAGS_REMOVE_USR_INCLUDE(ICONV_CFLAGS)
55         LIB_REMOVE_USR_LIB(ICONV_LIBS)
56         AC_SUBST(ICONV_CFLAGS)
57         AC_SUBST(ICONV_LIBS)
58
59 dnl     ############
60 dnl     # check for iconv usability
61
62         AC_CACHE_CHECK([for working iconv],netatalk_cv_HAVE_USABLE_ICONV,[
63                 AC_TRY_RUN([\
64 #include <iconv.h>
65 main() {
66        iconv_t cd = iconv_open("ASCII", "UTF-8");
67        if (cd == 0 || cd == (iconv_t)-1) return -1;
68        return 0;
69 }
70 ], netatalk_cv_HAVE_USABLE_ICONV=yes,netatalk_cv_HAVE_USABLE_ICONV=no,netatalk_cv_HAVE_USABLE_ICONV=cross)])
71
72         if test x"$netatalk_cv_HAVE_USABLE_ICONV" = x"yes"; then
73             AC_DEFINE(HAVE_USABLE_ICONV,1,[Whether to use native iconv])
74         fi
75
76 dnl     ###########
77 dnl     # check if iconv needs const
78         if test x"$netatalk_cv_HAVE_USABLE_ICONV" = x"yes"; then
79                 AC_CACHE_VAL(am_cv_proto_iconv, [
80                 AC_TRY_COMPILE([\
81 #include <stdlib.h>
82 #include <iconv.h>
83 extern
84 #ifdef __cplusplus
85 "C"
86 #endif
87 #if defined(__STDC__) || defined(__cplusplus)
88 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
89 #else
90 size_t iconv();
91 #endif
92 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
93                 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);"])
94                 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
95                         [Define as const if the declaration of iconv() needs const.])
96         fi
97
98 dnl     ###########
99 dnl     # check if (lib)iconv supports UCS-2-INTERNAL
100         if test x"$netatalk_cv_HAVE_USABLE_ICONV" = x"yes"; then
101             AC_CACHE_CHECK([whether iconv supports UCS-2-INTERNAL],netatalk_cv_HAVE_UCS2INTERNAL,[
102                 AC_TRY_RUN([\
103 #include <iconv.h>
104 int main() {
105        iconv_t cd = iconv_open("ASCII", "UCS-2-INTERNAL");
106        if (cd == 0 || cd == (iconv_t)-1) return -1;
107        return 0;
108 }
109 ], netatalk_cv_HAVE_UCS2INTERNAL=yes,netatalk_cv_HAVE_UCS2INTERNAL=no,netatalk_cv_HAVEUCS2INTERNAL=cross)])
110
111         if test x"$netatalk_cv_HAVE_UCS2INTERNAL" = x"yes"; then
112                 AC_DEFINE(HAVE_UCS2INTERNAL,1,[Whether UCS-2-INTERNAL is supported])
113         fi
114         fi
115
116         CFLAGS="$savedcflags"
117         LDFLAGS="$savedldflags"
118         CPPFLAGS="$saved_CPPFLAGS"
119         
120 ])