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