summaryrefslogtreecommitdiff
path: root/build/iconv.m4
blob: f6eba10e7bbac70a0388a335e36e941743c2826d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
dnl -------------------------------------------------------- -*- autoconf -*-
dnl Licensed to the Apache Software Foundation (ASF) under one or more
dnl contributor license agreements.  See the NOTICE file distributed with
dnl this work for additional information regarding copyright ownership.
dnl The ASF licenses this file to You under the Apache License, Version 2.0
dnl (the "License"); you may not use this file except in compliance with
dnl the License.  You may obtain a copy of the License at
dnl
dnl     http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl Unless required by applicable law or agreed to in writing, software
dnl distributed under the License is distributed on an "AS IS" BASIS,
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dnl See the License for the specific language governing permissions and
dnl limitations under the License.

dnl
dnl APU_TRY_ICONV[ IF-SUCCESS, IF-FAILURE ]: try to compile for iconv.
dnl
AC_DEFUN([APU_TRY_ICONV], [
  AC_TRY_LINK([
#include <stdlib.h>
#include <iconv.h>
],
[
  iconv_t cd = iconv_open("", "");
  iconv(cd, NULL, NULL, NULL, NULL);
], [$1], [$2])
])

dnl
dnl APU_FIND_ICONV: find an iconv library
dnl
AC_DEFUN([APU_FIND_ICONV], [

apu_iconv_dir="unknown"
want_iconv="1"
AC_ARG_WITH(iconv,[  --with-iconv[=DIR]        path to iconv installation],
  [ apu_iconv_dir="$withval"
    if test "$apu_iconv_dir" = "no"; then
      have_iconv="0"
      want_iconv="0"
    elif test "$apu_iconv_dir" != "yes"; then
      if test -f "$apu_iconv_dir/include/iconv.h"; then
        have_iconv="1"
        APR_ADDTO(CPPFLAGS,[-I$apu_iconv_dir/include])
        APR_ADDTO(LDFLAGS,[-L$apu_iconv_dir/lib])
      fi
    fi
  ])

if test "$want_iconv" = "1"; then
  AC_CHECK_HEADER(iconv.h, [
    APU_TRY_ICONV([ have_iconv="1" ], [

    APR_ADDTO(LIBS,[-liconv])

    APU_TRY_ICONV([
      APR_ADDTO(LIBS,[-liconv])
      APR_ADDTO(APRUTIL_EXPORT_LIBS,[-liconv])
      have_iconv="1" ],
      [ have_iconv="0" ])

    APR_REMOVEFROM(LIBS,[-liconv])

    ])
  ], [ have_iconv="0" ])
fi

if test "$want_iconv" = "1" -a "$apu_iconv_dir" != "unknown"; then
  if test "$have_iconv" != "1"; then
    AC_MSG_ERROR([iconv support requested, but not found])
  fi
  APR_REMOVEFROM(CPPFLAGS,[-I$apu_iconv_dir/include])
  APR_ADDTO(INCLUDES,[-I$apu_iconv_dir/include])
  APR_ADDTO(LDFLAGS,[-L$apu_iconv_dir/lib])
fi

if test "$have_iconv" = "1"; then
  APU_CHECK_ICONV_INBUF
fi

APR_FLAG_HEADERS(iconv.h langinfo.h)
APR_FLAG_FUNCS(nl_langinfo)
APR_CHECK_DEFINE(CODESET, langinfo.h, [CODESET defined in langinfo.h])

AC_SUBST(have_iconv)
])dnl

dnl
dnl APU_CHECK_ICONV_INBUF
dnl
dnl  Decide whether or not the inbuf parameter to iconv() is const.
dnl
dnl  We try to compile something without const.  If it fails to 
dnl  compile, we assume that the system's iconv() has const.  
dnl  Unfortunately, we won't realize when there was a compile
dnl  warning, so we allow a variable -- apu_iconv_inbuf_const -- to
dnl  be set in hints.m4 to specify whether or not iconv() has const
dnl  on this parameter.
dnl
AC_DEFUN([APU_CHECK_ICONV_INBUF], [
AC_MSG_CHECKING(for type of inbuf parameter to iconv)
if test "x$apu_iconv_inbuf_const" = "x"; then
    APR_TRY_COMPILE_NO_WARNING([
    #include <stddef.h>
    #include <iconv.h>
    ],[
    iconv(0,(char **)0,(size_t *)0,(char **)0,(size_t *)0);
    ], apu_iconv_inbuf_const="0", apu_iconv_inbuf_const="1")
fi
if test "$apu_iconv_inbuf_const" = "1"; then
    AC_DEFINE(APU_ICONV_INBUF_CONST, 1, [Define if the inbuf parm to iconv() is const char **])
    msg="const char **"
else
    msg="char **"
fi
AC_MSG_RESULT([$msg])
])dnl