Debian Codegraph @

texk/xdvik/m4/xdvi-check-iconv.m4

raw
1 # Autoconf macros for xdvik.
2 # Copyright (C) 2004-2009 Stefan Ulrich <[email protected]>
3 # Copyright (C) 2009-2013 Peter Breitenlohner <[email protected]>
4 #
5 # This file is free software; the copyright holders
6 # give unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
8
9 # XDVI_CHECK_ICONV
10 # ----------------
11 # Check for <iconv.h>, iconv(), and for type of iconv() input argument.
12 AC_DEFUN([XDVI_CHECK_ICONV], [dnl
13 AC_ARG_WITH([iconv],
14 AS_HELP_STRING([--with-iconv],
15 [Use an iconv library @<:@default=check@:>@]),
16 [],
17 [with_iconv=check])[]dnl
18 dnl
19 AC_ARG_WITH([iconv-include],
20 AS_HELP_STRING([--with-iconv-include=DIR],
21 [Specify the location of <iconv.h> header]))[]dnl
22 AC_ARG_WITH([iconv-libdir],
23 AS_HELP_STRING([--with-iconv-libdir=DIR],
24 [Specify the location of iconv (-liconv or -lrecode) library]))[]dnl
25 AS_CASE([$with_iconv_include],
26 [yes | no | ""], [iconv_includes=],
27 [iconv_includes="-I$with_iconv_include"])
28 AS_CASE([$with_iconv_libdir],
29 [yes | no | ""], [iconv_libpath=],
30 [iconv_libpath="-L$with_iconv_libdir"])
31 dnl
32 AS_IF([test "x$with_iconv" != xno], [dnl
33 xdvi_iconv_save_CPPFLAGS=$CPPFLAGS
34 AC_CHECK_HEADERS([iconv.h], [dnl
35 # Check if -liconv or -lrecode is needed for iconv()
36 _XDVI_ICONV_LIB
37 if test "x$xdvi_cv_search_iconv" != xno; then
38 if test "x$xdvi_cv_search_iconv" = "xnone required"; then
39 iconv_libs=
40 else
41 iconv_libs=$xdvi_cv_search_iconv
42 fi
43 AC_DEFINE([HAVE_ICONV], 1,
44 [Define to 1 if you have the `iconv' function.])
45 _XDVI_ICONV_CHAR_PPTR_TYPE
46 fi], [], [AC_INCLUDES_DEFAULT])
47 CPPFLAGS=$xdvi_iconv_save_CPPFLAGS
48 ])[]dnl
49 AC_SUBST([iconv_includes])
50 AC_SUBST([iconv_libpath])
51 AC_SUBST([iconv_libs])
52 ]) # XDVI_CHECK_ICONV
53
54 # _XDVI_ICONV_LIB
55 # ---------------
56 # Check for library containing iconv(), could be -liconv or -lrecode.
57 # Much like AC_SEARCH_LIBS([iconv], [iconv recode]),
58 # but needs to '#include <iconv.h>'.
59 m4_define([_XDVI_ICONV_LIB], [dnl
60 AC_CACHE_CHECK([for library containing iconv],
61 [xdvi_cv_search_iconv], [dnl
62 xdvi_iconv_save_LDFLAGS=$LDFLAGS
63 xdvi_iconv_save_LIBS=$LIBS
64 LDFLAGS="$iconv_libpath $LDFLAGS"
65 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[#include <stdlib.h>
66 #include <iconv.h>]],
67 [[iconv_t cd = iconv_open("","");]])])
68 xdvi_cv_search_iconv=no
69 for xdvi_lib in "" -liconv -lrecode; do
70 LIBS="$xdvi_lib $xdvi_iconv_save_LIBS"
71 AC_LINK_IFELSE([],
72 [xdvi_cv_search_iconv=$xdvi_lib
73 break])
74 done
75 test "x$xdvi_cv_search_iconv" = x && xdvi_cv_search_iconv="none required"
76 LDFLAGS=$xdvi_iconv_save_LDFLAGS
77 LIBS=$xdvi_iconv_save_LIBS])
78 ]) # _XDVI_ICONV_LIB
79
80 # _XDVI_ICONV_CHAR_PPTR_TYPE
81 # --------------------------
82 # Check whether iconv takes a 'const char **' or a 'char **' input argument.
83 # According to IEEE 1003.1, `char **' is correct, but e.g. librecode
84 # uses `const char **'.
85 # Inspired by Autoconf's AC_FUNC_SELECT_ARGTYPES we do this without the need
86 # to run a test program or to use C++.
87 m4_define([_XDVI_ICONV_CHAR_PPTR_TYPE], [dnl
88 AC_CACHE_CHECK([for iconv input type],
89 [xdvi_cv_iconv_char_pptr_type],
90 [AC_COMPILE_IFELSE(
91 [AC_LANG_PROGRAM(
92 [[
93 /* iconv() definitions may differ depending on following macros ... */
94 #ifdef __hpux
95 /* On HP-UX 10.10 B and 20.10, compiling with _XOPEN_SOURCE + ..._EXTENDED
96 * leads to poll() not realizing that a file descriptor is writable in psgs.c.
97 */
98 # define _HPUX_SOURCE 1
99 #else
100 # ifndef _XOPEN_SOURCE
101 # define _XOPEN_SOURCE 600
102 # endif
103 # define _XOPEN_SOURCE_EXTENDED 1
104 # define __EXTENSIONS__ 1 /* needed to get struct timeval on SunOS 5.5 */
105 # define _SVID_SOURCE 1 /* needed to get S_IFLNK in glibc */
106 # define _BSD_SOURCE 1 /* needed to get F_SETOWN in glibc-2.1.3 */
107 #endif
108
109 #include <iconv.h>
110 ]],
111 [[extern size_t iconv(iconv_t, char **, size_t *, char**, size_t*);]])],
112 [xdvi_cv_iconv_char_pptr_type='char **'],
113 [xdvi_cv_iconv_char_pptr_type='const char **'])])
114 AC_DEFINE_UNQUOTED([ICONV_CHAR_PPTR_TYPE], [$xdvi_cv_iconv_char_pptr_type],
115 [Define the type of the iconv input string (char ** or const char **)])
116 ]) # _XDVI_ICONV_CHAR_PPTR_TYPE