Browse code

improve iconv() detection, by actually trying to link a test-program (bb #599).

git-svn: trunk@3485

Török Edvin authored on 2008/01/07 03:06:56
Showing 5 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sun Jan  6 19:35:28 EET 2008 (edwin)
2
+------------------------------------
3
+ * build system: improve iconv() detection, by actually trying to link a
4
+ test-program (bb #599).
5
+
1 6
 Sun Jan  6 18:26:57 EET 2008 (edwin)
2 7
 ------------------------------------
3 8
  * build system: avoid bringing in checks for languages we don't use
... ...
@@ -147,8 +147,8 @@
147 147
 /* Define to 1 if you have the <grp.h> header file. */
148 148
 #undef HAVE_GRP_H
149 149
 
150
-/* Define to 1 if you have the <iconv.h> header file. */
151
-#undef HAVE_ICONV_H
150
+/* iconv() available */
151
+#undef HAVE_ICONV
152 152
 
153 153
 /* Define to 1 if you have the `inet_ntop' function. */
154 154
 #undef HAVE_INET_NTOP
... ...
@@ -1511,6 +1511,7 @@ Optional Packages:
1511 1511
   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
1512 1512
   --with-pic              try to use only PIC/non-PIC objects [default=use
1513 1513
                           both]
1514
+  --with-iconv supports iconv() (default=auto)
1514 1515
   --with-zlib=DIR	  path to directory containing zlib library (default=
1515 1516
 			  /usr/local or /usr if not found in /usr/local)
1516 1517
   --with-sendmail=PATH    specify location of Sendmail binary (default=auto find)
... ...
@@ -4724,7 +4725,7 @@ ia64-*-hpux*)
4724 4724
   ;;
4725 4725
 *-*-irix6*)
4726 4726
   # Find out which ABI we are using.
4727
-  echo '#line 4727 "configure"' > conftest.$ac_ext
4727
+  echo '#line 4728 "configure"' > conftest.$ac_ext
4728 4728
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
4729 4729
   (eval $ac_compile) 2>&5
4730 4730
   ac_status=$?
... ...
@@ -6494,11 +6495,11 @@ else
6494 6494
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
6495 6495
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
6496 6496
    -e 's:$: $lt_compiler_flag:'`
6497
-   (eval echo "\"\$as_me:6497: $lt_compile\"" >&5)
6497
+   (eval echo "\"\$as_me:6498: $lt_compile\"" >&5)
6498 6498
    (eval "$lt_compile" 2>conftest.err)
6499 6499
    ac_status=$?
6500 6500
    cat conftest.err >&5
6501
-   echo "$as_me:6501: \$? = $ac_status" >&5
6501
+   echo "$as_me:6502: \$? = $ac_status" >&5
6502 6502
    if (exit $ac_status) && test -s "$ac_outfile"; then
6503 6503
      # The compiler can only warn and ignore the option if not recognized
6504 6504
      # So say no if there are warnings other than the usual output.
... ...
@@ -6784,11 +6785,11 @@ else
6784 6784
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
6785 6785
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
6786 6786
    -e 's:$: $lt_compiler_flag:'`
6787
-   (eval echo "\"\$as_me:6787: $lt_compile\"" >&5)
6787
+   (eval echo "\"\$as_me:6788: $lt_compile\"" >&5)
6788 6788
    (eval "$lt_compile" 2>conftest.err)
6789 6789
    ac_status=$?
6790 6790
    cat conftest.err >&5
6791
-   echo "$as_me:6791: \$? = $ac_status" >&5
6791
+   echo "$as_me:6792: \$? = $ac_status" >&5
6792 6792
    if (exit $ac_status) && test -s "$ac_outfile"; then
6793 6793
      # The compiler can only warn and ignore the option if not recognized
6794 6794
      # So say no if there are warnings other than the usual output.
... ...
@@ -6888,11 +6889,11 @@ else
6888 6888
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
6889 6889
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
6890 6890
    -e 's:$: $lt_compiler_flag:'`
6891
-   (eval echo "\"\$as_me:6891: $lt_compile\"" >&5)
6891
+   (eval echo "\"\$as_me:6892: $lt_compile\"" >&5)
6892 6892
    (eval "$lt_compile" 2>out/conftest.err)
6893 6893
    ac_status=$?
6894 6894
    cat out/conftest.err >&5
6895
-   echo "$as_me:6895: \$? = $ac_status" >&5
6895
+   echo "$as_me:6896: \$? = $ac_status" >&5
6896 6896
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
6897 6897
    then
6898 6898
      # The compiler can only warn and ignore the option if not recognized
... ...
@@ -9250,7 +9251,7 @@ else
9250 9250
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
9251 9251
   lt_status=$lt_dlunknown
9252 9252
   cat > conftest.$ac_ext <<EOF
9253
-#line 9253 "configure"
9253
+#line 9254 "configure"
9254 9254
 #include "confdefs.h"
9255 9255
 
9256 9256
 #if HAVE_DLFCN_H
... ...
@@ -9350,7 +9351,7 @@ else
9350 9350
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
9351 9351
   lt_status=$lt_dlunknown
9352 9352
   cat > conftest.$ac_ext <<EOF
9353
-#line 9353 "configure"
9353
+#line 9354 "configure"
9354 9354
 #include "confdefs.h"
9355 9355
 
9356 9356
 #if HAVE_DLFCN_H
... ...
@@ -10542,8 +10543,7 @@ fi
10542 10542
 
10543 10543
 
10544 10544
 
10545
-
10546
-for ac_header in stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h pwd.h grp.h
10545
+for ac_header in stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h limits.h sys/filio.h sys/uio.h termios.h stdbool.h pwd.h grp.h
10547 10546
 do
10548 10547
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
10549 10548
 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
... ...
@@ -11300,7 +11300,22 @@ if test $ac_cv_lib_nsl_gethostent = yes; then
11300 11300
 fi
11301 11301
 
11302 11302
 
11303
-{ echo "$as_me:$LINENO: checking for libiconv_open in -liconv" >&5
11303
+
11304
+# Check whether --with-iconv was given.
11305
+if test "${with_iconv+set}" = set; then
11306
+  withval=$with_iconv;
11307
+ case "$withval" in
11308
+	 yes|no) wiconv="$withval";;
11309
+	 *) { { echo "$as_me:$LINENO: error: --with-iconv does not take an argument" >&5
11310
+echo "$as_me: error: --with-iconv does not take an argument" >&2;}
11311
+   { (exit 1); exit 1; }; };;
11312
+ esac
11313
+else
11314
+   wiconv=auto
11315
+fi
11316
+
11317
+if test "X$wiconv" != "Xno"; then
11318
+	{ echo "$as_me:$LINENO: checking for libiconv_open in -liconv" >&5
11304 11319
 echo $ECHO_N "checking for libiconv_open in -liconv... $ECHO_C" >&6; }
11305 11320
 if test "${ac_cv_lib_iconv_libiconv_open+set}" = set; then
11306 11321
   echo $ECHO_N "(cached) $ECHO_C" >&6
... ...
@@ -11365,6 +11380,78 @@ if test $ac_cv_lib_iconv_libiconv_open = yes; then
11365 11365
   LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -liconv"
11366 11366
 fi
11367 11367
 
11368
+	{ echo "$as_me:$LINENO: checking for iconv" >&5
11369
+echo $ECHO_N "checking for iconv... $ECHO_C" >&6; }
11370
+	save_LIBS="$LIBS"
11371
+	LIBS="$LIBCLAMAV_LIBS"
11372
+	cat >conftest.$ac_ext <<_ACEOF
11373
+/* confdefs.h.  */
11374
+_ACEOF
11375
+cat confdefs.h >>conftest.$ac_ext
11376
+cat >>conftest.$ac_ext <<_ACEOF
11377
+/* end confdefs.h.  */
11378
+
11379
+		     #include <iconv.h>
11380
+
11381
+int
11382
+main ()
11383
+{
11384
+
11385
+int main(int argc, char** argv) {
11386
+	char** xin,**xout;
11387
+	unsigned il,ol;
11388
+	int rc;
11389
+	iconv_t iconv_struct = iconv_open("UTF-16BE","UTF-8");
11390
+	rc = iconv(iconv_struct,xin,&il,xout,&ol);
11391
+	iconv_close(iconv_struct);
11392
+	return 0;
11393
+}
11394
+
11395
+  ;
11396
+  return 0;
11397
+}
11398
+_ACEOF
11399
+rm -f conftest.$ac_objext conftest$ac_exeext
11400
+if { (ac_try="$ac_link"
11401
+case "(($ac_try" in
11402
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
11403
+  *) ac_try_echo=$ac_try;;
11404
+esac
11405
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
11406
+  (eval "$ac_link") 2>conftest.er1
11407
+  ac_status=$?
11408
+  grep -v '^ *+' conftest.er1 >conftest.err
11409
+  rm -f conftest.er1
11410
+  cat conftest.err >&5
11411
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
11412
+  (exit $ac_status); } && {
11413
+	 test -z "$ac_c_werror_flag" ||
11414
+	 test ! -s conftest.err
11415
+       } && test -s conftest$ac_exeext &&
11416
+       $as_test_x conftest$ac_exeext; then
11417
+
11418
+   { echo "$as_me:$LINENO: result: yes" >&5
11419
+echo "${ECHO_T}yes" >&6; }
11420
+
11421
+cat >>confdefs.h <<\_ACEOF
11422
+#define HAVE_ICONV 1
11423
+_ACEOF
11424
+
11425
+
11426
+else
11427
+  echo "$as_me: failed program was:" >&5
11428
+sed 's/^/| /' conftest.$ac_ext >&5
11429
+
11430
+
11431
+	{ echo "$as_me:$LINENO: result: no" >&5
11432
+echo "${ECHO_T}no" >&6; }
11433
+
11434
+fi
11435
+
11436
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
11437
+      conftest$ac_exeext conftest.$ac_ext
11438
+	LIBS="$save_LIBS"
11439
+fi
11368 11440
 
11369 11441
 
11370 11442
 
... ...
@@ -193,7 +193,7 @@ int main()
193 193
 ], [AC_MSG_RESULT([ok, bug not present])],
194 194
 [AC_MSG_ERROR([your compiler has a bug that causes clamav 670, use a different compiler, see http://bugs.clamav.net/bugzilla/show_bug.cgi?id=670])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
195 195
 
196
-AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h limits.h sys/filio.h sys/uio.h termios.h iconv.h stdbool.h pwd.h grp.h)
196
+AC_CHECK_HEADERS(stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h limits.h sys/filio.h sys/uio.h termios.h stdbool.h pwd.h grp.h)
197 197
 AC_CHECK_HEADER(syslog.h,AC_DEFINE(USE_SYSLOG,1,[use syslog]),)
198 198
 
199 199
 AC_TYPE_OFF_T
... ...
@@ -213,7 +213,40 @@ fi
213 213
 AC_CHECK_LIB(socket, bind, [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsocket"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsocket"; CLAMD_LIBS="$CLAMD_LIBS -lsocket"])
214 214
 AC_CHECK_LIB(nsl, gethostent, [LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl"])
215 215
 
216
-AC_CHECK_LIB(iconv, libiconv_open, LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -liconv")
216
+dnl we need to try to link with iconv, otherwise there could be a 
217
+dnl mismatch between a 32-bit and 64-bit lib. Detect this at configure time.
218
+AC_ARG_WITH(iconv, [  --with-iconv supports iconv() (default=auto)],
219
+[
220
+ case "$withval" in
221
+	 yes|no) wiconv="$withval";;
222
+	 *) AC_MSG_ERROR([--with-iconv does not take an argument]);;
223
+ esac],
224
+[ wiconv=auto ])
225
+if test "X$wiconv" != "Xno"; then
226
+	AC_CHECK_LIB(iconv, libiconv_open, LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -liconv")
227
+	AC_MSG_CHECKING([for iconv])
228
+	save_LIBS="$LIBS"
229
+	LIBS="$LIBCLAMAV_LIBS"
230
+	AC_TRY_LINK([
231
+		     #include <iconv.h>
232
+	],[
233
+int main(int argc, char** argv) {
234
+	char** xin,**xout;
235
+	unsigned il,ol;
236
+	int rc;
237
+	iconv_t iconv_struct = iconv_open("UTF-16BE","UTF-8");
238
+	rc = iconv(iconv_struct,xin,&il,xout,&ol);
239
+	iconv_close(iconv_struct);
240
+	return 0;
241
+}
242
+],[
243
+   AC_MSG_RESULT(yes)
244
+   AC_DEFINE(HAVE_ICONV, 1, [iconv() available])
245
+],[
246
+	AC_MSG_RESULT(no)
247
+])
248
+	LIBS="$save_LIBS"
249
+fi
217 250
 
218 251
 AC_CHECK_FUNCS(poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp)
219 252
 AC_FUNC_MMAP
... ...
@@ -40,9 +40,10 @@
40 40
 #include "entitylist.h"
41 41
 #include "cltypes.h"
42 42
 
43
-#ifdef HAVE_ICONV_H
43
+#ifdef HAVE_ICONV
44 44
 #include <iconv.h>
45 45
 #endif
46
+
46 47
 #include "encoding_aliases.h"
47 48
 
48 49
 
... ...
@@ -178,7 +179,7 @@ static size_t encoding_bytes(const unsigned char* fromcode, enum encodings* enco
178 178
 	}
179 179
 	}
180 180
 
181
-#ifndef HAVE_ICONV_H
181
+#ifndef HAVE_ICONV
182 182
 typedef struct {
183 183
 	enum encodings encoding;
184 184
 	size_t size;