From b809abcfd0821d9595be4e036af6c140cae9b1fd Mon Sep 17 00:00:00 2001
From: mathias <mathias>
Date: Thu, 21 Apr 2005 19:09:10 +0000
Subject: fix iconv-issues on *BSD and MacOSX

---
 ChangeLog    |  2 ++
 configure.in | 82 ++++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 49 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0023543..0b38ba6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 (Format: Year/Month/Day)
 Changes for 0.9.13
 *05/04/21:
+  * Fixed iconv-issues on *BSD/MacOSX (Mathias)
+    configure.in
   * Fixed #1133809, ArrangeWindows covers Toolbar/Slit (Mathias)
     WorkspaceCmd.cc
 *05/04/20:
diff --git a/configure.in b/configure.in
index ec6b858..c525f64 100644
--- a/configure.in
+++ b/configure.in
@@ -25,7 +25,12 @@ fi
 
 dnl Check for system header files
 AC_HEADER_STDC
-AC_CHECK_HEADERS(errno.h ctype.h dirent.h fcntl.h libgen.h locale.h nl_types.h process.h signal.h stdarg.h stdio.h time.h unistd.h sys/param.h sys/select.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/wait.h)
+AC_CHECK_HEADERS(errno.h ctype.h dirent.h fcntl.h libgen.h \
+                 locale.h nl_types.h process.h signal.h stdarg.h \
+                 stdio.h time.h unistd.h \
+                 sys/param.h sys/select.h sys/signal.h sys/stat.h \
+                 sys/time.h sys/types.h sys/wait.h \
+                 iconv.h)
 
 AC_CHECK_HEADERS(sstream, ,
         [ AC_CHECK_HEADERS(strstream,,
@@ -63,42 +68,49 @@ size_t x = strftime(s, 5, "%a", localtime(&t));
 ],
 [AC_MSG_RESULT(no)])
 
-AC_MSG_CHECKING([for iconv])
-AC_TRY_COMPILE(
-[#include <iconv.h>],
-[iconv_t cd = iconv_open("", "")],
-HAVE_ICONV=yes, 
-HAVE_ICONV=no)
-
-if test x"$HAVE_ICONV" = x"yes"; then
-    AC_DEFINE(HAVE_ICONV, 1, "iconv")
-dnl now check for const char *msg argument in iconv(..)
-    AC_TRY_COMPILE(
-    [#include <iconv.h>],
-    [
-        char **msg, **new_msg; 
-        size_t result, inleft, outleft; 
-        result = iconv((iconv_t)(-1), msg, &inleft, new_msg, &outleft);
-        return 0;
-    ],
-    [ AC_MSG_RESULT([yes (non const msg)])],
-    [ AC_DEFINE(HAVE_CONST_ICONV, 1, "iconv")
-      AC_MSG_RESULT([yes (const msg)])])
-
-dnl Check if iconv is part of libiconv
-    AC_CHECK_LIB(iconv, iconv_close,
-      AC_MSG_CHECKING([for iconv_close in libiconv])
-      AC_TRY_LINK(
-        #include <iconv.h>,
-        [int main() { return iconv_close((iconv_t)(-1)); }],
-        AC_MSG_RESULT([yes]),
-        LIBS="$LIBS -liconv"
-      )
-    )
-else
-    AC_MSG_RESULT([no])
+
+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
+      LIBS="-liconv $LIBS"
+    fi
+  fi
+fi
+if test "x$ac_found_iconv" = xyes; then
+  AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
 fi
 
+
+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 <stdlib.h>
+        #include <iconv.h>]],
+        [[#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([HAVE_CONST_ICONV], $ac_cv_iconv_const,
+    [Define as const if the declaration of iconv() needs const.])
+fi
+
+
 AC_CHECK_LIB(nsl, t_open, LIBS="$LIBS -lnsl")
 AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
 
-- 
cgit v0.11.2