1# LIBICONV_CHECK_CONFIG ([DEFAULT-ACTION])
2# ----------------------------------------------------------
3#    Alexander Vladishev                      Feb-02-2007
4#
5# Checks for iconv.  DEFAULT-ACTION is the string yes or no to
6# specify whether to default to --with-iconv or --without-iconv.
7# If not supplied, DEFAULT-ACTION is no.
8#
9# This macro #defines HAVE_ICONV if a required header files is
10# found, and sets @ICONV_LDFLAGS@ and @ICONV_CFLAGS@ to the necessary
11# values.
12#
13# This macro is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17AC_DEFUN([LIBICONV_TRY_LINK],
18[
19found_iconv=$1
20AC_TRY_LINK(
21[
22#include <stdlib.h>
23#include <iconv.h>
24],
25[
26	iconv_t cd = iconv_open("","");
27	iconv(cd, NULL, NULL, NULL, NULL);
28	iconv_close(cd);
29],
30found_iconv="yes")
31])dnl
32
33AC_DEFUN([LIBICONV_CHECK_CONFIG],
34[
35	AC_ARG_WITH([iconv],[
36If you want to specify iconv installation directories:
37AC_HELP_STRING([--with-iconv@<:@=DIR@:>@], [use iconv from given base install directory (DIR), default is to search through a number of common places for the iconv files.])],
38		[
39			if test "$withval" = "yes"; then
40				ICONV_CFLAGS="-I/usr/include"
41				ICONV_LDFLAGS="-L/usr/lib"
42				_iconv_dir_set=$withval
43			elif test "$withval" != "no"; then
44				_iconv_dir_lib="$withval/lib"
45				ICONV_CFLAGS="-I$withval/include"
46				ICONV_LDFLAGS="-L$_iconv_dir_lib"
47				_iconv_dir_set="yes"
48			fi
49		]
50	)
51
52	AC_ARG_WITH([iconv-include],
53		AC_HELP_STRING([--with-iconv-include@<:@=DIR@:>@],
54			[use iconv include headers from given path.]
55		),
56		[
57			ICONV_CFLAGS="-I$withval"
58			_iconv_dir_set="yes"
59		]
60	)
61
62	AC_ARG_WITH([iconv-lib],
63		AC_HELP_STRING([--with-iconv-lib@<:@=DIR@:>@],
64			[use iconv libraries from given path.]
65		),
66		[
67			ICONV_LDFLAGS="-L$withval"
68			_iconv_dir_lib="-L$withval"
69			_iconv_dir_set="yes"
70		]
71	)
72
73	AC_CHECK_HEADER([iconv.h],[found_iconv=yes])
74	AC_MSG_CHECKING(for ICONV support)
75	if test -n "$_iconv_dir_set" -o "x$found_iconv" = xyes; then
76		found_iconv="yes"
77	elif test -f /usr/local/include/iconv.h; then
78		ICONV_CFLAGS="-I/usr/local/include"
79		ICONV_LDFLAGS="-L/usr/local/lib"
80		found_iconv="yes"
81	else
82		found_iconv="no"
83		AC_MSG_RESULT(no)
84	fi
85
86	if test "x$found_iconv" = "xyes"; then
87		am_save_CFLAGS="$CFLAGS"
88		am_save_LDFLAGS="$LDFLAGS"
89		am_save_LIBS="$LIBS"
90
91		CFLAGS="$CFLAGS $ICONV_CFLAGS"
92		LDFLAGS="$LDFLAGS $ICONV_LDFLAGS"
93
94		LIBICONV_TRY_LINK([no])
95
96		if test "x$found_iconv" = "xno"; then
97			ICONV_LIBS="-liconv"
98			if test "x$enable_static_libs" = "xyes"; then
99				test "x$static_linking_support" = "xno" -a -z "$_iconv_dir_lib" && AC_MSG_ERROR(["Compiler not support statically linked libs from default folders"])
100
101				if test "x$static_linking_support" = "xno"; then
102					ICONV_LIBS="$_iconv_dir_lib/libiconv.a"
103				else
104					ICONV_LIBS="${static_linking_support}static $ICONV_LIBS ${static_linking_support}dynamic"
105				fi
106			fi
107			LIBS="$LIBS $ICONV_LIBS"
108			LIBICONV_TRY_LINK([no])
109		fi
110
111		LIBS="$am_save_LIBS"
112		CFLAGS="$am_save_CFLAGS"
113		LDFLAGS="$am_save_LDFLAGS"
114	fi
115
116	if test "x$found_iconv" = "xyes"; then
117		AC_DEFINE([HAVE_ICONV], 1, [Define to 1 if you have the 'libiconv' library (-liconv)])
118		AC_MSG_RESULT(yes)
119	else
120		ICONV_LIBS=""
121		ICONV_CFLAGS=""
122		ICONV_LDFLAGS=""
123	fi
124
125	AC_SUBST(ICONV_LIBS)
126	AC_SUBST(ICONV_CFLAGS)
127	AC_SUBST(ICONV_LDFLAGS)
128])dnl
129