test/gcc-fat.sh
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 1797 783b9409baa0
child 4127 6cb18cf1777e
permissions -rwxr-xr-x
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

src/main/windows/SDL_windows_main.c:137:
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
     1 #!/bin/sh
     2 #
     3 # Build Universal binaries on Mac OS X, thanks Ryan!
     4 #
     5 # Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
     6 
     7 # PowerPC compiler flags (10.2 runtime compatibility)
     8 GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
     9 -DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
    10 -nostdinc \
    11 -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
    12 -I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
    13 -isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
    14 
    15 GCC_LINK_PPC="\
    16 -L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
    17 -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
    18 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
    19 
    20 # Intel compiler flags (10.4 runtime compatibility)
    21 GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
    22 -DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    23 -nostdinc \
    24 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    25 -I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
    26 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    27 
    28 GCC_LINK_X86="\
    29 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
    30 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    31 
    32 # Output both PowerPC and Intel object files
    33 args="$*"
    34 compile=yes
    35 link=yes
    36 while test x$1 != x; do
    37     case $1 in
    38         --version) exec gcc $1;;
    39         -v) exec gcc $1;;
    40         -V) exec gcc $1;;
    41         -print-prog-name=*) exec gcc $1;;
    42         -print-search-dirs) exec gcc $1;;
    43         -E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
    44             GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
    45             compile=no; link=no;;
    46         -c) link=no;;
    47         -o) output=$2;;
    48         *.c|*.cc|*.cpp|*.S) source=$1;;
    49     esac
    50     shift
    51 done
    52 if test x$link = xyes; then
    53     GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
    54     GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
    55 fi
    56 if test x"$output" = x; then
    57     if test x$link = xyes; then
    58         output=a.out
    59     elif test x$compile = xyes; then
    60         output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
    61     fi
    62 fi
    63 
    64 if test x"$output" != x; then
    65     dir=ppc/`dirname $output`
    66     if test -d $dir; then
    67         :
    68     else
    69         mkdir -p $dir
    70     fi
    71 fi
    72 set -- $args
    73 while test x$1 != x; do
    74     if test -f "ppc/$1" && test "$1" != "$output"; then
    75         ppc_args="$ppc_args ppc/$1"
    76     else
    77         ppc_args="$ppc_args $1"
    78     fi
    79     shift
    80 done
    81 $GCC_COMPILE_PPC $ppc_args || exit $?
    82 if test x"$output" != x; then
    83     cp $output ppc/$output
    84 fi
    85 
    86 if test x"$output" != x; then
    87     dir=x86/`dirname $output`
    88     if test -d $dir; then
    89         :
    90     else
    91         mkdir -p $dir
    92     fi
    93 fi
    94 set -- $args
    95 while test x$1 != x; do
    96     if test -f "x86/$1" && test "$1" != "$output"; then
    97         x86_args="$x86_args x86/$1"
    98     else
    99         x86_args="$x86_args $1"
   100     fi
   101     shift
   102 done
   103 $GCC_COMPILE_X86 $x86_args || exit $?
   104 if test x"$output" != x; then
   105     cp $output x86/$output
   106 fi
   107 
   108 if test x"$output" != x; then
   109     lipo -create -o $output ppc/$output x86/$output
   110 fi