Add checks for compiler support for unicode string literals

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34239 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-12-02 11:21:45 +00:00
parent 93dd8e8f57
commit 3f437faaab
6 changed files with 259 additions and 2 deletions

View file

@ -1,3 +1,20 @@
2011-12-02 Richard Frith-Macdonald <rfm@gnu.org>
* config/config.constant-string-encoding.c: test for string literal
encoding behavior ... irrespective of source encoding we need to put
utf-8 in the executable. Can't check all cases, so just check the
most common one ... that building latin1 source in a latin1 locale
produces a utf8 string literal in the executable.
* configure.ac: add check for encoding.
* config.mak.in: specify charset for string literal in source
* base.make.in: specify charset for string literal in executable
* configure: regenerate
Check compiler behavior ... if well behaved, that's OK, no action to
take. If well behaved when given specific options to control input
and output encodings, then note the options to be used when building.
If neither, then abort with an error message giving the option of
disabling unicode string literal checks.
2011-11-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSUserDefaults.m: rewrite to store defaults in multiple files,

View file

@ -50,6 +50,10 @@ ifeq ($(BASE_MAKE_LOADED),)
FND_LIBS = -lgnustep-baseadd -framework Foundation
endif
# For literal string handling, base requires the compiler to store the
# string as UTF-8
AUXILIARY_OBJCFLAGS += @GS_EXEC_CHARSET@
GNUSTEP_BASE_HAVE_GNUTLS=@HAVE_GNUTLS@
GNUSTEP_BASE_HAVE_LIBXML=@HAVE_LIBXML@
GNUSTEP_BASE_HAVE_MDNS=@HAVE_MDNS@

View file

@ -41,6 +41,11 @@ GNUSTEP_BASE_HAVE_MDNS=@HAVE_MDNS@
GNUSTEP_BASE_HAVE_AVAHI=@HAVE_AVAHI@
GNUSTEP_BASE_HAVE_ICU=@HAVE_ICU@
# Futureproofing ... if we ever use non-ascii string constants in base,
# we need to make sure that anyone building base uses the expected input
# characterset
AUXILIARY_OBJCFLAGS += @GS_INPUT_CHARSET@
# Default to building only -baseadd
# on non *-gnu-* library combos
ifneq ($(FOUNDATION_LIB),gnu)

View file

@ -0,0 +1,20 @@
/*
Copyright (C) 2011 Free Software Foundation
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
*/
int main ()
{
/* Check that latin1 pound sign in source is utf8 in executable
*/
const unsigned char *str = "£";
if (str[0] != 0xc2 || str[1] != 0xa3)
{
return 1;
}
return 0;
}

162
configure vendored
View file

@ -729,6 +729,8 @@ GS_WORDS_BIGENDIAN
OBJC_WITH_GC
PKGCONFIG
WHOAMI
GS_INPUT_CHARSET
GS_EXEC_CHARSET
EGREP
GREP
CPP
@ -799,6 +801,7 @@ enable_environment_config_file
enable_importing_config_file
with_default_config
with_installation_domain
enable_unicodeconstants
enable_nxconstantstring
enable_mixedabi
enable_bfd
@ -1485,6 +1488,9 @@ Optional Features:
--disable-importing-config-file
Disable importing of an existing GNUstep config
file and use inbuilt defaults instead.
--disable-unicodeconstants
Permits the use of a compiler which does not support unicode
string constants.
--enable-nxconstantstring
Enables the use of the NXConstantString class for old compilers.
--disable-mixedabi
@ -5126,7 +5132,161 @@ $as_echo "$as_me: error: You are running configure with the compiler ($CC) set t
exit 1
fi
#-------------------------------------------------------------------r
#--------------------------------------------------------------------
# Check wether the compiler supports UTF-8 constant strings
#--------------------------------------------------------------------
GS_EXEC_CHARSET=
GS_INPUT_CHARSET=
# Check whether --enable-unicodeconstants was given.
if test "${enable_unicodeconstants+set}" = set; then
enableval=$enable_unicodeconstants;
fi
if test "$enable_unicodeconstants" != "no"; then
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:$LINENO: checking whether compiler supports UTF-8 constants in executable" >&5
$as_echo_n "checking whether compiler supports UTF-8 constants in executable... " >&6; }
saved_CFLAGS="$CFLAGS"
saved_LANG="$LANG"
saved_LC_ALL="$LC_ALL"
export LANG="en_US.ISO-8859-1"
export LC_ALL="en_US.ISO-8859-1"
# We are working in a latin1 locale so we can build a program containing
# a latin1 pound character, and see if the executable has a utf-8 literal.
if test "$cross_compiling" = yes; then
utf8literal_ok=no
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include "$srcdir/config/config.constant-string-encoding.c"
_ACEOF
rm -f conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$ac_try_echo") >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$ac_try_echo") >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
utf8literal_ok=yes
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
( exit $ac_status )
utf8literal_ok=no
fi
rm -rf conftest.dSYM
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
if test "$utf8literal_ok" = "yes"; then
{ $as_echo "$as_me:$LINENO: result: yes" >&5
$as_echo "yes" >&6; };
else
# The compiler did not produce a utf-8 literal ... see if it does so when
# given the appropriate flags to tell it what charactersets to use.
CFLAGS="$CFLAGS -finput-charset=ISO-8859-1 -fexec-charset=UTF-8"
if test "$cross_compiling" = yes; then
utf8literal_ok=no
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include "$srcdir/config/config.constant-string-encoding.c"
_ACEOF
rm -f conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$ac_try_echo") >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$ac_try_echo") >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
utf8literal_ok=yes
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
( exit $ac_status )
utf8literal_ok=no
fi
rm -rf conftest.dSYM
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
if test "$utf8literal_ok" = "yes"; then
{ $as_echo "$as_me:$LINENO: result: yes" >&5
$as_echo "yes" >&6; };
GS_EXEC_CHARSET=-fexec-charset=UTF-8
GS_INPUT_CHARSET=-finput-charset=UTF-8
else
{ $as_echo "$as_me:$LINENO: result: no" >&5
$as_echo "no" >&6; };
{ { $as_echo "$as_me:$LINENO: error: Your compiler does not appear to support UTF-8 string constants and any code which depends on non US-ASCII text in string constants would perform incorrectly. If you do not carte about this, please confgure using --disable-unicodeconstants" >&5
$as_echo "$as_me: error: Your compiler does not appear to support UTF-8 string constants and any code which depends on non US-ASCII text in string constants would perform incorrectly. If you do not carte about this, please confgure using --disable-unicodeconstants" >&2;}
{ (exit 1); exit 1; }; }
fi
fi
export LANG="$saved_LANG"
export LC_ALL="$saved_LC_ALL"
CFLAGS="$saved_CFLAGS"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
fi
#--------------------------------------------------------------------
# Check how to enable builtins for atomic operations
#--------------------------------------------------------------------

View file

@ -1023,7 +1023,58 @@ if test "$CC" != "$MAKECC"; then
exit 1
fi
#-------------------------------------------------------------------r
#--------------------------------------------------------------------
# Check wether the compiler supports UTF-8 constant strings
#--------------------------------------------------------------------
GS_EXEC_CHARSET=
GS_INPUT_CHARSET=
AC_ARG_ENABLE(unicodeconstants,
[ --disable-unicodeconstants
Permits the use of a compiler which does not support unicode
string constants.],,)
if test "$enable_unicodeconstants" != "no"; then
AC_LANG_PUSH(C)
AC_MSG_CHECKING(whether compiler supports UTF-8 constants in executable)
saved_CFLAGS="$CFLAGS"
saved_LANG="$LANG"
saved_LC_ALL="$LC_ALL"
export LANG="en_US.ISO-8859-1"
export LC_ALL="en_US.ISO-8859-1"
# We are working in a latin1 locale so we can build a program containing
# a latin1 pound character, and see if the executable has a utf-8 literal.
AC_TRY_RUN([#include "$srcdir/config/config.constant-string-encoding.c"],
utf8literal_ok=yes,
utf8literal_ok=no,
utf8literal_ok=no)
if test "$utf8literal_ok" = "yes"; then
AC_MSG_RESULT([yes]);
else
# The compiler did not produce a utf-8 literal ... see if it does so when
# given the appropriate flags to tell it what charactersets to use.
CFLAGS="$CFLAGS -finput-charset=ISO-8859-1 -fexec-charset=UTF-8"
AC_TRY_RUN([#include "$srcdir/config/config.constant-string-encoding.c"],
utf8literal_ok=yes,
utf8literal_ok=no,
utf8literal_ok=no)
if test "$utf8literal_ok" = "yes"; then
AC_MSG_RESULT([yes]);
GS_EXEC_CHARSET=-fexec-charset=UTF-8
GS_INPUT_CHARSET=-finput-charset=UTF-8
else
AC_MSG_RESULT([no]);
AC_MSG_ERROR([Your compiler does not appear to support UTF-8 string constants and any code which depends on non US-ASCII text in string constants would perform incorrectly. If you do not carte about this, please confgure using --disable-unicodeconstants])
fi
fi
export LANG="$saved_LANG"
export LC_ALL="$saved_LC_ALL"
CFLAGS="$saved_CFLAGS"
AC_LANG_POP(C)
fi
AC_SUBST(GS_EXEC_CHARSET)
AC_SUBST(GS_INPUT_CHARSET)
#--------------------------------------------------------------------
# Check how to enable builtins for atomic operations
#--------------------------------------------------------------------