Fix build failure when --disable-util-dso is used.
[apr-util.git] / build / apu-iconv.m4
blob13042273edabd0817e60cd5262c24320c2fed6f3
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Licensed to the Apache Software Foundation (ASF) under one or more
3 dnl contributor license agreements.  See the NOTICE file distributed with
4 dnl this work for additional information regarding copyright ownership.
5 dnl The ASF licenses this file to You under the Apache License, Version 2.0
6 dnl (the "License"); you may not use this file except in compliance with
7 dnl the License.  You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
17 dnl
18 dnl APU_TRY_ICONV[ IF-SUCCESS, IF-FAILURE ]: try to compile for iconv.
19 dnl
20 AC_DEFUN([APU_TRY_ICONV], [
21   AC_TRY_LINK([
22 #include <stdlib.h>
23 #include <iconv.h>
26   iconv_t cd = iconv_open("", "");
27   iconv(cd, NULL, NULL, NULL, NULL);
28 ], [$1], [$2])
31 dnl
32 dnl APU_FIND_ICONV: find an iconv library
33 dnl
34 AC_DEFUN([APU_FIND_ICONV], [
36 apu_iconv_dir="unknown"
37 have_apr_iconv="0"
38 want_iconv="1"
39 AC_ARG_WITH(iconv,[  --with-iconv[=DIR]        path to iconv installation],
40   [ apu_iconv_dir="$withval"
41     if test "$apu_iconv_dir" = "no"; then
42       have_apr_iconv="0"
43       have_iconv="0"
44       want_iconv="0"
45     elif test "$apu_iconv_dir" != "yes"; then
46       if test -f "$apu_iconv_dir/include/apr-1/api_version.h"; then
47         have_apr_iconv="1"
48         have_iconv="0"
49         APR_ADDTO(APRUTIL_INCLUDES,[-I$apu_iconv_dir/include/apr-1])
50         APR_ADDTO(APRUTIL_LIBS,[$apu_iconv_dir/lib/libapriconv-1.la])
51         AC_MSG_RESULT(using apr-iconv)
52       elif test -f "$apu_iconv_dir/include/iconv.h"; then
53         have_apr_iconv="0"
54         have_iconv="1"
55         APR_ADDTO(CPPFLAGS,[-I$apu_iconv_dir/include])
56         APR_ADDTO(LDFLAGS,[-L$apu_iconv_dir/lib])
57       fi
58     fi
59   ])
61 if test "$want_iconv" = "1" -a "$have_apr_iconv" != "1"; then
62   AC_CHECK_HEADER(iconv.h, [
63     APU_TRY_ICONV([ have_iconv="1" ], [
65     APR_ADDTO(LIBS,[-liconv])
67     APU_TRY_ICONV([
68       APR_ADDTO(APRUTIL_LIBS,[-liconv])
69       APR_ADDTO(APRUTIL_EXPORT_LIBS,[-liconv])
70       have_iconv="1" ],
71       [ have_iconv="0" ])
73     APR_REMOVEFROM(LIBS,[-liconv])
75     ])
76   ], [ have_iconv="0" ])
79 if test "$want_iconv" = "1" -a "$apu_iconv_dir" != "unknown"; then
80   if test "$have_iconv" != "1"; then
81     if test "$have_apr_iconv" != "1"; then 
82       AC_MSG_ERROR([iconv support requested, but not found])
83     fi
84   fi
85   APR_REMOVEFROM(CPPFLAGS,[-I$apu_iconv_dir/include])
86   APR_REMOVEFROM(LDFLAGS,[-L$apu_iconv_dir/lib])
87   APR_ADDTO(APRUTIL_INCLUDES,[-I$apu_iconv_dir/include])
88   APR_ADDTO(APRUTIL_LDFLAGS,[-L$apu_iconv_dir/lib])
91 if test "$have_iconv" = "1"; then
92   APU_CHECK_ICONV_INBUF
95 APR_FLAG_HEADERS(iconv.h langinfo.h)
96 APR_FLAG_FUNCS(nl_langinfo)
97 APR_CHECK_DEFINE(CODESET, langinfo.h, [CODESET defined in langinfo.h])
99 AC_SUBST(have_iconv)
100 AC_SUBST(have_apr_iconv)
101 ])dnl
104 dnl APU_CHECK_ICONV_INBUF
106 dnl  Decide whether or not the inbuf parameter to iconv() is const.
108 dnl  We try to compile something without const.  If it fails to 
109 dnl  compile, we assume that the system's iconv() has const.  
110 dnl  Unfortunately, we won't realize when there was a compile
111 dnl  warning, so we allow a variable -- apu_iconv_inbuf_const -- to
112 dnl  be set in hints.m4 to specify whether or not iconv() has const
113 dnl  on this parameter.
115 AC_DEFUN([APU_CHECK_ICONV_INBUF], [
116 AC_MSG_CHECKING(for type of inbuf parameter to iconv)
117 if test "x$apu_iconv_inbuf_const" = "x"; then
118     APR_TRY_COMPILE_NO_WARNING([
119     #include <stddef.h>
120     #include <iconv.h>
121     ],[
122     iconv(0,(char **)0,(size_t *)0,(char **)0,(size_t *)0);
123     ], apu_iconv_inbuf_const="0", apu_iconv_inbuf_const="1")
125 if test "$apu_iconv_inbuf_const" = "1"; then
126     AC_DEFINE(APU_ICONV_INBUF_CONST, 1, [Define if the inbuf parm to iconv() is const char **])
127     msg="const char **"
128 else
129     msg="char **"
131 AC_MSG_RESULT([$msg])
132 ])dnl