fi
-if test "${newlib_iconv}" = "yes"; then
-cat >> confdefs.h <<EOF
-#define _ICONV_ENABLED 1
-EOF
-
-fi
-
cat >> confdefs.h <<EOF
#define _NEWLIB_VERSION "$VERSION"
EOF
multilib_arg=
fi
+if test "${newlib_iconv}" = "yes"; then
+cat >> confdefs.h <<EOF
+#define _ICONV_ENABLED 1
+EOF
+
+fi
+
+if test "x${builtin_converters}" != "x"; then
+
+ if test x${newlib_iconv} = x; then
+ { echo "configure: error: --enable-newlib-builtin-converters option can't be used if iconv library is disabled - use --enable-newlib-iconv to enable it" 1>&2; exit 1; }
+ fi
+
+ builtin_converters=`echo "${builtin_converters}" | sed -e 's/,/ /g' -e 's/-/_/g' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+
+ available_converters=`cat "${srcdir}/libc/iconv/charset.aliases" | sed -e '/#/d' | sed -e 'N; s/\n //;'`
+
+ builtin_converters1="${builtin_converters}"
+ builtin_converters=""
+ for converter in ${builtin_converters1}; do
+ result=`echo "${available_converters}" | grep -e "\(^\| \)${converter}\( \|\$\)"`
+ if test $? != "0"; then
+ { echo "configure: error: ${converter} is not supported - see ${srcdir}/libc/iconv/charset.aliases file for the list of available converters" 1>&2; exit 1; }
+ fi
+ converter1=`echo "${result}" | sed -e 's/\(^[^ ]*\).*$/\1/'`
+ builtin_converters="${builtin_converters} ${converter1}"
+ done
+
+ for converter in ${builtin_converters}; do
+ opt=_ICONV_CONVERTER_`echo "${converter}" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+ cat >> confdefs.h <<EOF
+#define $opt 1
+EOF
+
+ done
+fi;
trap '' 1 2 15
cat > confcache <<\EOF
AC_DEFINE_UNQUOTED(_MB_LEN_MAX,1)
fi
-if test "${newlib_iconv}" = "yes"; then
-AC_DEFINE_UNQUOTED(_ICONV_ENABLED,1)
-fi
-
AC_DEFINE_UNQUOTED(_NEWLIB_VERSION,"$VERSION")
if test "${multilib}" = "yes"; then
multilib_arg=
fi
+if test "${newlib_iconv}" = "yes"; then
+AC_DEFINE_UNQUOTED(_ICONV_ENABLED,1)
+fi
+
+dnl Parse --enable-newlib-builtin-converters option argument
+if test "x${builtin_converters}" != "x"; then
+
+ dnl Check that --enable-newlib-iconv was enabled
+ if test x${newlib_iconv} = x; then
+ AC_MSG_ERROR(--enable-newlib-builtin-converters option can't be used if iconv library is disabled - use --enable-newlib-iconv to enable it)
+ fi
+
+ dnl Normalize converter names and delete commas
+ builtin_converters=`echo "${builtin_converters}" | sed -e 's/,/ /g' -e 's/-/_/g' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
+
+ dnl Get the list of available converters excluding comments
+ dnl Join line with previous if the first character is whitespace
+ available_converters=`cat "${srcdir}/libc/iconv/charset.aliases" | sed -e '/#/d' | sed -e 'N; s/\n //;'`
+
+ dnl Check if required converters are supported
+ dnl Convert aliases to "official" names
+ builtin_converters1="${builtin_converters}"
+ builtin_converters=""
+ for converter in ${builtin_converters1}; do
+ result=`echo "${available_converters}" | grep -e "\(^\| \)${converter}\( \|\$\)"`
+ if test $? != "0"; then
+ AC_MSG_ERROR(${converter} is not supported - see ${srcdir}/libc/iconv/charset.aliases file for the list of available converters)
+ fi
+ converter1=`echo "${result}" | sed -e 's/\(^[[^ ]]*\).*$/\1/'`
+ builtin_converters="${builtin_converters} ${converter1}"
+ done
+
+ dnl Enable appropriate option in newlib.h
+ for converter in ${builtin_converters}; do
+ opt=_ICONV_CONVERTER_`echo "${converter}" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+ AC_DEFINE_UNQUOTED($opt,1)
+ done
+fi;
AC_OUTPUT(Makefile,
[if test -n "$CONFIG_FILES"; then
/* ICONV enabled */
#undef _ICONV_ENABLED
+/*
+ * ICONV converters enabled
+ */
+#undef _ICONV_CONVERTER_US_ASCII
+#undef _ICONV_CONVERTER_BIG5
+#undef _ICONV_CONVERTER_SHIFT_JIS
+#undef _ICONV_CONVERTER_GB_2312_80
+#undef _ICONV_CONVERTER_CP866
+#undef _ICONV_CONVERTER_CP855
+#undef _ICONV_CONVERTER_CP852
+#undef _ICONV_CONVERTER_CP850
+#undef _ICONV_CONVERTER_CP775
+#undef _ICONV_CONVERTER_KOI8_U
+#undef _ICONV_CONVERTER_KOI8_R
+#undef _ICONV_CONVERTER_ISO_8859_1
+#undef _ICONV_CONVERTER_ISO_8859_2
+#undef _ICONV_CONVERTER_ISO_8859_4
+#undef _ICONV_CONVERTER_ISO_8859_5
+#undef _ICONV_CONVERTER_ISO_8859_15
+#undef _ICONV_CONVERTER_EUC_JP
+#undef _ICONV_CONVERTER_EUC_KR
+#undef _ICONV_CONVERTER_EUC_TW
+#undef _ICONV_CONVERTER_ISO_10646_UCS_2
+#undef _ICONV_CONVERTER_ISO_10646_UCS_4
+#undef _ICONV_CONVERTER_UCS_2_INTERNAL
+#undef _ICONV_CONVERTER_UCS_4_INTERNAL
+#undef _ICONV_CONVERTER_UTF_16
+#undef _ICONV_CONVERTER_UTF_8
+
#endif /* !__NEWLIB_H__ */