xref: /netbsd-src/external/gpl2/diffutils/dist/m4/iconv.m4 (revision 75f6d617e282811cb173c2ccfbf5df0dd71f7045)
1*75f6d617Schristos# iconv.m4 serial AM3 (gettext-0.11)
2*75f6d617Schristosdnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
3*75f6d617Schristosdnl This file is free software, distributed under the terms of the GNU
4*75f6d617Schristosdnl General Public License.  As a special exception to the GNU General
5*75f6d617Schristosdnl Public License, this file may be distributed as part of a program
6*75f6d617Schristosdnl that contains a configuration script generated by Autoconf, under
7*75f6d617Schristosdnl the same distribution terms as the rest of that program.
8*75f6d617Schristos
9*75f6d617Schristosdnl From Bruno Haible.
10*75f6d617Schristos
11*75f6d617SchristosAC_DEFUN([AM_ICONV_LINK],
12*75f6d617Schristos[
13*75f6d617Schristos  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
14*75f6d617Schristos  dnl those with the standalone portable GNU libiconv installed).
15*75f6d617Schristos
16*75f6d617Schristos  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
17*75f6d617Schristos  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
18*75f6d617Schristos  AC_REQUIRE([AC_LIB_RPATH])
19*75f6d617Schristos
20*75f6d617Schristos  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
21*75f6d617Schristos  dnl accordingly.
22*75f6d617Schristos  AC_LIB_LINKFLAGS_BODY([iconv])
23*75f6d617Schristos
24*75f6d617Schristos  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
25*75f6d617Schristos  dnl because if the user has installed libiconv and not disabled its use
26*75f6d617Schristos  dnl via --without-libiconv-prefix, he wants to use it. The first
27*75f6d617Schristos  dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
28*75f6d617Schristos  am_save_CPPFLAGS="$CPPFLAGS"
29*75f6d617Schristos  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
30*75f6d617Schristos
31*75f6d617Schristos  AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
32*75f6d617Schristos    am_cv_func_iconv="no, consider installing GNU libiconv"
33*75f6d617Schristos    am_cv_lib_iconv=no
34*75f6d617Schristos    AC_TRY_LINK([#include <stdlib.h>
35*75f6d617Schristos#include <iconv.h>],
36*75f6d617Schristos      [iconv_t cd = iconv_open("","");
37*75f6d617Schristos       iconv(cd,NULL,NULL,NULL,NULL);
38*75f6d617Schristos       iconv_close(cd);],
39*75f6d617Schristos      am_cv_func_iconv=yes)
40*75f6d617Schristos    if test "$am_cv_func_iconv" != yes; then
41*75f6d617Schristos      am_save_LIBS="$LIBS"
42*75f6d617Schristos      LIBS="$LIBS $LIBICONV"
43*75f6d617Schristos      AC_TRY_LINK([#include <stdlib.h>
44*75f6d617Schristos#include <iconv.h>],
45*75f6d617Schristos        [iconv_t cd = iconv_open("","");
46*75f6d617Schristos         iconv(cd,NULL,NULL,NULL,NULL);
47*75f6d617Schristos         iconv_close(cd);],
48*75f6d617Schristos        am_cv_lib_iconv=yes
49*75f6d617Schristos        am_cv_func_iconv=yes)
50*75f6d617Schristos      LIBS="$am_save_LIBS"
51*75f6d617Schristos    fi
52*75f6d617Schristos  ])
53*75f6d617Schristos  if test "$am_cv_func_iconv" = yes; then
54*75f6d617Schristos    AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
55*75f6d617Schristos  fi
56*75f6d617Schristos  if test "$am_cv_lib_iconv" = yes; then
57*75f6d617Schristos    AC_MSG_CHECKING([how to link with libiconv])
58*75f6d617Schristos    AC_MSG_RESULT([$LIBICONV])
59*75f6d617Schristos  else
60*75f6d617Schristos    dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
61*75f6d617Schristos    dnl either.
62*75f6d617Schristos    CPPFLAGS="$am_save_CPPFLAGS"
63*75f6d617Schristos    LIBICONV=
64*75f6d617Schristos    LTLIBICONV=
65*75f6d617Schristos  fi
66*75f6d617Schristos  AC_SUBST(LIBICONV)
67*75f6d617Schristos  AC_SUBST(LTLIBICONV)
68*75f6d617Schristos])
69*75f6d617Schristos
70*75f6d617SchristosAC_DEFUN([AM_ICONV],
71*75f6d617Schristos[
72*75f6d617Schristos  AC_REQUIRE([AM_ICONV_LINK])
73*75f6d617Schristos  if test "$am_cv_func_iconv" = yes; then
74*75f6d617Schristos    AC_MSG_CHECKING([for iconv declaration])
75*75f6d617Schristos    AC_CACHE_VAL(am_cv_proto_iconv, [
76*75f6d617Schristos      AC_TRY_COMPILE([
77*75f6d617Schristos#include <stdlib.h>
78*75f6d617Schristos#include <iconv.h>
79*75f6d617Schristosextern
80*75f6d617Schristos#ifdef __cplusplus
81*75f6d617Schristos"C"
82*75f6d617Schristos#endif
83*75f6d617Schristos#if defined(__STDC__) || defined(__cplusplus)
84*75f6d617Schristossize_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
85*75f6d617Schristos#else
86*75f6d617Schristossize_t iconv();
87*75f6d617Schristos#endif
88*75f6d617Schristos], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
89*75f6d617Schristos      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);"])
90*75f6d617Schristos    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
91*75f6d617Schristos    AC_MSG_RESULT([$]{ac_t:-
92*75f6d617Schristos         }[$]am_cv_proto_iconv)
93*75f6d617Schristos    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
94*75f6d617Schristos      [Define as const if the declaration of iconv() needs const.])
95*75f6d617Schristos  fi
96*75f6d617Schristos])
97