Permalink
Browse files

Use the more advanced iconv.m4 script from ELinks

  • Loading branch information...
1 parent ad8878a commit e47afdf2f78acbcb5c08f422be5ce37e0e99a5fc @jonas committed Sep 14, 2007
Showing with 65 additions and 45 deletions.
  1. +1 −1 Makefile
  2. +62 −0 acinclude.m4
  3. +1 −40 configure.ac
  4. +1 −4 tig.c
View
@@ -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
View
@@ -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
+])
View
@@ -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])
View
5 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;

0 comments on commit e47afdf

Please sign in to comment.