From: Ken Hornstein Date: Tue, 1 Jan 2013 07:40:30 +0000 (-0500) Subject: Clean up (and hopefully improve) the autoconf iconv tests. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/b3df58528443af8b4f25748bef8ca98852af9ba2?ds=inline;hp=--cc Clean up (and hopefully improve) the autoconf iconv tests. --- b3df58528443af8b4f25748bef8ca98852af9ba2 diff --git a/configure.ac b/configure.ac index f6fa38ec..7887b993 100644 --- a/configure.ac +++ b/configure.ac @@ -437,7 +437,7 @@ AS_CASE(["$host_os"], AC_HEADER_STDC AC_HEADER_TIOCGWINSZ AC_CHECK_HEADERS([errno.h fcntl.h crypt.h ncurses/termcap.h termcap.h \ - langinfo.h wchar.h wctype.h iconv.h netdb.h \ + langinfo.h wchar.h wctype.h netdb.h \ sys/param.h sys/time.h sys/stream.h]) dnl @@ -481,8 +481,12 @@ AC_CHECK_FUNC([modf], , AC_CHECK_LIB([m], [modf])) dnl Checks for network libraries (nsl, socket) NMH_CHECK_NETLIBS +dnl Check for readline support NMH_READLINE +dnl Check for iconv +NMH_CHECK_ICONV + termcap_curses_order="termcap curses ncurses" for lib in $termcap_curses_order; do AC_CHECK_LIB(${lib}, tgetent, [TERMLIB="-l$lib"; break]) @@ -492,53 +496,6 @@ AS_IF([test "x$TERMLIB" = "x"], [AC_MSG_FAILURE([Could not find tgetent in any library. Is there a curses or ncurses library or package that you can install?])]) - -dnl --------------- -dnl CHECK FOR ICONV -dnl --------------- - -dnl Find iconv. It may be in libiconv and may be iconv() or libiconv() -if test "x$ac_cv_header_iconv_h" = "xyes"; then - AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no) - if test "x$ac_found_iconv" = "xno"; then - AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes) - if test "x$ac_found_iconv" = "xno"; then - AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes) - fi - if test "x$ac_found_iconv" != "xno"; then - ICONVLIB="-liconv" - fi - else - dnl Handle case where there is a native iconv but iconv.h is from libiconv - AC_CHECK_DECL(_libiconv_version, - [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],, - [ #include ]) - fi -fi -if test "x$ac_found_iconv" = xyes; then - AC_DEFINE([HAVE_ICONV], [1], [Define if you have the iconv() function.]) -fi -AC_SUBST([ICONVLIB]) - -dnl Check if iconv uses const in prototype declaration -if test "x$ac_found_iconv" = "xyes"; then - AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const, - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include - #include ]], - [[#ifdef __cplusplus - "C" - #endif - #if defined(__STDC__) || defined(__cplusplus) - size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); - #else - size_t iconv(); - #endif]])], - [ac_cv_iconv_const=], - [ac_cv_iconv_const=const])]) - AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const, - [Define as const if the declaration of iconv() needs const.]) -fi - dnl -------------- dnl CHECK FOR NDBM dnl -------------- diff --git a/m4/iconv.m4 b/m4/iconv.m4 new file mode 100644 index 00000000..949c746d --- /dev/null +++ b/m4/iconv.m4 @@ -0,0 +1,42 @@ +dnl +dnl Check for iconv support. It may be in libiconv and may be iconv() +dnl or libiconv() +dnl + +AC_DEFUN([NMH_CHECK_ICONV], +[AC_CHECK_HEADER([iconv.h], + [AC_CHECK_FUNC([iconv], + [dnl This is where iconv is found in the default libraries (LIBS) + nmh_found_iconv=yes + dnl Handle the case where there is a native iconv but iconv.h is + dnl from libiconv + AC_CHECK_DECL([_libiconv_version], + [AC_CHECK_LIB([iconv], [libiconv], [LIBS="-liconv $LIBS"])],, + [#include ])], + [dnl Since we didn't find iconv in LIBS, check libiconv + AC_CHECK_LIB([iconv], [iconv], [nmh_found_iconv=yes], + [dnl Also check for a function called libiconv() + AC_CHECK_LIB([iconv], [libiconv], [nmh_found_iconv=yes])]) + dnl If either of these tests pass, set ICONVLIB + AS_IF([test "x$nmh_found_iconv" = "xyes"], [ICONVLIB="-liconv"])]) + dnl If we came out of that by finding iconv in some form, define + dnl HAVE_ICONV + AS_IF([test "x$nmh_found_iconv" = "xyes"], + [AC_DEFINE([HAVE_ICONV], [1], + [Define if you have the iconv() function.]) + AC_CACHE_CHECK([for iconv declaration], [nmh_cv_iconv_const], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include + #include ]], + [[#ifdef __cplusplus + "C" + #endif + #if defined(__STDC__) || defined(__cplusplus) + size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); + #else + size_t iconv(); + #endif]])], + [nmh_cv_iconv_const=], + [nmh_cv_iconv_const=const])]) + AC_DEFINE_UNQUOTED([ICONV_CONST], [$nmh_cv_iconv_const], + [Define as const if the declaration of iconv() needs const.])])]) +AC_SUBST([ICONVLIB])])