Code

Use the more advanced iconv.m4 script from ELinks
authorJonas Fonseca <fonseca@diku.dk>
Fri, 14 Sep 2007 12:46:00 +0000 (14:46 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Fri, 14 Sep 2007 12:52:31 +0000 (14:52 +0200)
Makefile
acinclude.m4 [new file with mode: 0644]
configure.ac
tig.c

index 69668d46275a2fcef88f7bcead7a22580ba9c8f8..5bf60e33c13147d04e33ca9bb634bcd6df190136 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -105,7 +105,7 @@ dist: tig.spec
 rpm: dist
        rpmbuild -ta $(TARNAME).tar.gz
 
-configure: configure.ac
+configure: configure.ac acinclude.m4
        $(AUTORECONF) -v
 
 # Maintainer stuff
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644 (file)
index 0000000..d3d618f
--- /dev/null
@@ -0,0 +1,62 @@
+dnl From Bruno Haible.
+AC_DEFUN([AM_ICONV],
+[
+  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
+  dnl those with the standalone portable GNU libiconv installed).
+
+  AC_ARG_WITH([libiconv],
+[  --with-libiconv=DIR     search for libiconv in DIR/include and DIR/lib], [
+    for dir in `echo "$withval" | tr : ' '`; do
+      if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
+      if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
+    done
+   ])
+
+  AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+#include <iconv.h>]], [[iconv_t cd = iconv_open("","");
+       iconv(cd,NULL,NULL,NULL,NULL);
+       iconv_close(cd);]])],[am_cv_func_iconv=yes],[])
+    if test "$am_cv_func_iconv" != yes; then
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS -liconv"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+#include <iconv.h>]], [[iconv_t cd = iconv_open("","");
+         iconv(cd,NULL,NULL,NULL,NULL);
+         iconv_close(cd);]])],[am_cv_lib_iconv=yes
+        am_cv_func_iconv=yes],[])
+      LIBS="$am_save_LIBS"
+    fi
+  ])
+  if test "$am_cv_func_iconv" = yes; then
+    AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+    AC_MSG_CHECKING([for iconv declaration])
+    AC_CACHE_VAL(am_cv_proto_iconv, [
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#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
+]], [[]])],[am_cv_proto_iconv_arg1=""],[am_cv_proto_iconv_arg1="const"])
+      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);"])
+    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+    AC_MSG_RESULT([$]{ac_t:-
+         }[$]am_cv_proto_iconv)
+    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
+      [Define as const if the declaration of iconv() needs const.])
+  else
+    AC_MSG_FAILURE([iconv() not found. Please install libiconv and use --with-libiconv=/path/to/dir.],[1])
+  fi
+  if test "$am_cv_lib_iconv" = yes; then
+    LIBS="$LIBS -liconv"
+  fi
+])
index f60d43eab2424a50f64bf3478762117dbe8016c9..55d81a98811306f99a733084d2e2f5ab9c3fdc41 100644 (file)
@@ -5,47 +5,8 @@ AC_LANG([C])
 AC_CONFIG_HEADER(config.h)
 AC_CONFIG_SRCDIR(tig.c)
 
-AC_ARG_WITH(libiconv,
-        AC_HELP_STRING([--with-libiconv=DIRECTORY],[base directory for libiconv]))
-if test "$with_libiconv" != ""
-then
-       CFLAGS="$CFLAGS -I$with_libiconv/include"
-       LDFLAGS="$LDFLAGS -L$with_libiconv/lib"
-fi
-
-dnl
-dnl See if we need to link with -liconv to get the iconv() function.
-dnl
 AC_SEARCH_LIBS([wclear], [ncurses curses])
-AC_SEARCH_LIBS([iconv], [iconv])
-
-if test "$ac_cv_search_iconv" = "no"
-then
-       AC_MSG_FAILURE([iconv() not found. Please install libiconv.],[1])
-fi
-
-dnl
-dnl See if iconv() requires a const char ** for the input buffer.
-dnl
-if test "$GCC" = "yes"
-then
-       OLD_CFLAGS="$CFLAGS"
-       CFLAGS="$CFLAGS -Werror"
-       AC_MSG_CHECKING([whether iconv needs const char **])
-       AC_COMPILE_IFELSE(
-               [AC_LANG_PROGRAM([[#include <iconv.h>]],
-                                [[char **buf;
-                                  size_t *size;
-                                  iconv_t cd;
-                                  iconv(cd, buf, size, buf, size);]])],
-               [AC_DEFINE([ICONV_INBUF_TYPE],[char *],
-                          [Type of iconv() input buffer])
-                AC_MSG_RESULT([no])],
-               [AC_DEFINE([ICONV_INBUF_TYPE],[const char *],
-                          [Type of iconv() input buffer])
-                AC_MSG_RESULT([yes])])
-       CFLAGS="$OLD_CFLAGS"
-fi
+AM_ICONV
 
 AC_PROG_CC
 AC_CHECK_PROGS(GIT_CONFIG, [git-config git-repo-config])
diff --git a/tig.c b/tig.c
index 51d0feeede36eab21d5d6d9af597fc8693fd5dbc..0390b3a00276a2ce4060daf9bd323aedd45e6f04 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -80,9 +80,6 @@ static size_t utf8_length(const char *string, size_t max_width, int *coloffset,
 #define COLOR_DEFAULT  (-1)
 
 #define ICONV_NONE     ((iconv_t) -1)
-#ifndef ICONV_INBUF_TYPE
-#define ICONV_INBUF_TYPE char *
-#endif
 
 /* The format and size of the date column in the main view. */
 #define DATE_FORMAT    "%Y-%m-%d %H:%M"
@@ -1943,7 +1940,7 @@ update_view(struct view *view)
                        line[linelen - 1] = 0;
 
                if (opt_iconv != ICONV_NONE) {
-                       ICONV_INBUF_TYPE inbuf = line;
+                       ICONV_CONST char *inbuf = line;
                        size_t inlen = linelen;
 
                        char *outbuf = out_buffer;