configure.ac: define ICONV_OMITS_BOM if necessary
From commit 79444c9294, ("utf8: handle systems that don't write BOM for UTF-16", 2019-02-12), we're supporting those systems with iconv that omits BOM with: make ICONV_OMITS_BOM=Yes However, configure script wasn't taught to detect those systems. Teach configure to do so. Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Doan Tran Cong Danh committed
Nov 8, 2019 at 16:43 UTC
1ba6e7aecdd2c72df1b0da7a89502e82485f7819
1 file changed
+49
configure.ac
+49
@@ -844,12 +844,61 @@ AC_MSG_CHECKING([for old iconv()])
844
AC_COMPILE_IFELSE([OLDICONVTEST_SRC],
845
[AC_MSG_RESULT([no])],
846
[AC_MSG_RESULT([yes])
847
+ AC_DEFINE(HAVE_OLD_ICONV, 1)
848
OLD_ICONV=UnfortunatelyYes])
849
850
GIT_UNSTASH_FLAGS($ICONVDIR)
851
852
GIT_CONF_SUBST([OLD_ICONV])
853
854
+#
855
+# Define ICONV_OMITS_BOM if you are on a system which
856
+# iconv omits bom for utf-{16,32}
857
+if test -z "$NO_ICONV"; then
858
+AC_CACHE_CHECK([whether iconv omits bom for utf-16 and utf-32],
859
+ [ac_cv_iconv_omits_bom],
860
+[
861
+old_LIBS="$LIBS"
862
+if test -n "$NEEDS_LIBICONV"; then
863
+ LIBS="$LIBS -liconv"
864
+fi
865
+
866
+AC_RUN_IFELSE(
867
+ [AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
868
+ #include <iconv.h>
869
+ #ifdef HAVE_OLD_ICONV
870
+ typedef const char *iconv_ibp;
871
+ #else
872
+ typedef char *iconv_ibp;
873
+ #endif
874
+ ],
875
+ [[
876
+ int v;
877
+ iconv_t conv;
878
+ char in[] = "a"; iconv_ibp pin = in;
879
+ char out[20] = ""; char *pout = out;
880
+ size_t isz = sizeof in;
881
+ size_t osz = sizeof out;
882
+
883
+ conv = iconv_open("UTF-16", "UTF-8");
884
+ iconv(conv, &pin, &isz, &pout, &osz);
885
+ iconv_close(conv);
886
+ v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
887
+ return v != 0xfe + 0xff;
888
+ ]])],
889
+ [ac_cv_iconv_omits_bom=no],
890
+ [ac_cv_iconv_omits_bom=yes])
891
+
892
+LIBS="$old_LIBS"
893
+])
894
+if test "x$ac_cv_iconv_omits_bom" = xyes; then
895
+ ICONV_OMITS_BOM=Yes
896
+else
897
+ ICONV_OMITS_BOM=
898
+fi
899
+GIT_CONF_SUBST([ICONV_OMITS_BOM])
900
+fi
901
+
902
## Checks for typedefs, structures, and compiler characteristics.
903
AC_MSG_NOTICE([CHECKS for typedefs, structures, and compiler characteristics])
904
#