Skip to content

Commit eb3aac2

Browse files
committedJul 29, 2015
Android: fix horrible libiconv build
Before, our libiconv build was a joke. We first called configure for our own build host system, then called make, before we executed a Android.mk script we provided as patch. The first "native make" always failed, and the LIBICONV_LIB file setting in our Makefile didn't match the built one, resulting in an always-rebuild of iconv. This commit cleans up this total mess, removes the double-build, and the Android.mk, and properly calls ./configure with the according target platform, and uses a built toolchain. As we have to deal with the android bug "NDK: Support for prebuild libs with full sonames" https://code.google.com/p/android/issues/detail?id=55868 as the 2013 patch https://lists.gnu.org/archive/html/libtool-patches/2013-06/msg00002.html by Google's David Turner wasn't inside the 2011 libtool, we pass -avoid-version to libtool. Thanks to the proper build, wide_to_utf8 works for android now, removing us of the need to disable it.
1 parent f97c270 commit eb3aac2

File tree

5 files changed

+47
-104
lines changed

5 files changed

+47
-104
lines changed
 

Diff for: ‎build/android/Makefile

+38-35
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ FREETYPE_URL_GIT = https://github.com/cdave1/freetype2-android
133133

134134
ICONV_VERSION = 1.14
135135
ICONV_DIR = $(ROOT)/deps/libiconv/
136-
ICONV_LIB = $(ICONV_DIR)/iconv.so
136+
ICONV_LIB = $(ICONV_DIR)/lib/.libs/libiconv.so
137137
ICONV_TIMESTAMP = $(ICONV_DIR)timestamp
138138
ICONV_TIMESTAMP_INT = $(ROOT)/deps/iconv_timestamp
139139
ICONV_URL_HTTP = http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$(ICONV_VERSION).tar.gz
@@ -445,52 +445,55 @@ $(ICONV_TIMESTAMP) : iconv_download
445445
fi
446446

447447
iconv_download :
448-
@if [ ! -d ${ICONV_DIR} ] ; then \
449-
echo "iconv sources missing, downloading..."; \
450-
mkdir -p ${ROOT}/deps; \
451-
cd ${ROOT}/deps; \
452-
wget ${ICONV_URL_HTTP} || exit 1; \
453-
tar -xzf libiconv-${ICONV_VERSION}.tar.gz || exit 1; \
454-
rm libiconv-${ICONV_VERSION}.tar.gz; \
455-
ln -s libiconv-${ICONV_VERSION} libiconv; \
456-
cd ${ICONV_DIR}; \
457-
patch -p1 < ${ROOT}/libiconv_android.patch; \
458-
patch -p1 < ${ROOT}/libiconv_android_mk.patch; \
459-
patch -p1 < ${ROOT}/libiconv_stdio.patch; \
460-
cd jni; \
461-
ln -s .. src; \
448+
@if [ ! -d ${ICONV_DIR} ] ; then \
449+
echo "iconv sources missing, downloading..."; \
450+
mkdir -p ${ROOT}/deps; \
451+
cd ${ROOT}/deps; \
452+
wget ${ICONV_URL_HTTP} || exit 1; \
453+
tar -xzf libiconv-${ICONV_VERSION}.tar.gz || exit 1; \
454+
rm libiconv-${ICONV_VERSION}.tar.gz; \
455+
ln -s libiconv-${ICONV_VERSION} libiconv; \
456+
cd ${ICONV_DIR}; \
457+
patch -p1 < ${ROOT}/libiconv_android.patch; \
458+
patch -p1 < ${ROOT}/libiconv_stdio.patch; \
462459
fi
463460

464461
iconv : $(ICONV_LIB)
465462

466463
$(ICONV_LIB) : $(ICONV_TIMESTAMP)
467464
@REFRESH=0; \
468-
if [ ! -e ${ICONV_TIMESTAMP_INT} ] ; then \
469-
REFRESH=1; \
465+
if [ ! -e ${ICONV_TIMESTAMP_INT} ] ; then \
466+
REFRESH=1; \
470467
fi; \
471-
if [ ! -e ${ICONV_LIB} ] ; then \
472-
REFRESH=1; \
468+
if [ ! -e ${ICONV_LIB} ] ; then \
469+
REFRESH=1; \
473470
fi; \
474-
if [ ${ICONV_TIMESTAMP} -nt ${ICONV_TIMESTAMP_INT} ] ; then \
475-
REFRESH=1; \
471+
if [ ${ICONV_TIMESTAMP} -nt ${ICONV_TIMESTAMP_INT} ] ; then \
472+
REFRESH=1; \
476473
fi; \
477474
if [ $$REFRESH -ne 0 ] ; then \
478-
mkdir -p ${ICONV_DIR}; \
475+
mkdir -p ${ICONV_DIR}; \
479476
export PATH=$$PATH:${SDKFOLDER}/platform-tools:${ANDROID_NDK}; \
480-
echo "changed timestamp for iconv detected building..."; \
481-
cd ${ICONV_DIR}; \
482-
./configure; \
483-
make; \
484-
export NDK_PROJECT_PATH=${ICONV_DIR}; \
485-
ndk-build NDEBUG=${NDEBUG} NDK_MODULE_PATH=${NDK_MODULE_PATH} \
486-
APP_PLATFORM=${APP_PLATFORM} APP_ABI=${TARGET_ABI} \
487-
TARGET_CFLAGS+="${TARGET_CFLAGS_ADDON}" \
488-
TARGET_LDFLAGS+="${TARGET_LDFLAGS_ADDON}" \
489-
TARGET_CXXFLAGS+="${TARGET_CXXFLAGS_ADDON}" || exit 1; \
490-
touch ${ICONV_TIMESTAMP}; \
491-
touch ${ICONV_TIMESTAMP_INT}; \
477+
echo "changed timestamp for iconv detected building..."; \
478+
cd ${ICONV_DIR}; \
479+
\
480+
export TOOLCHAIN=/tmp/ndk-${TARGET_HOST}-iconv; \
481+
${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \
482+
--toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \
483+
--install-dir=$${TOOLCHAIN}; \
484+
export PATH="$${TOOLCHAIN}/bin:$${PATH}"; \
485+
export CC=${CROSS_PREFIX}gcc; \
486+
export CXX=${CROSS_PREFIX}g++; \
487+
export TARGET_OS=OS_ANDROID_CROSSCOMPILE; \
488+
./configure --host=${TARGET_HOST} || exit 1; \
489+
sed -i 's/LIBICONV_VERSION_INFO) /LIBICONV_VERSION_INFO) -avoid-version /g' lib/Makefile; \
490+
grep "iconv_LDFLAGS" src/Makefile; \
491+
$(MAKE) -s || exit 1; \
492+
touch ${ICONV_TIMESTAMP}; \
493+
touch ${ICONV_TIMESTAMP_INT}; \
494+
rm -rf ${TOOLCHAIN}; \
492495
else \
493-
echo "nothing to be done for iconv"; \
496+
echo "nothing to be done for iconv"; \
494497
fi
495498

496499
clean_iconv :

Diff for: ‎build/android/jni/Android.mk

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ include $(PREBUILT_STATIC_LIBRARY)
2626

2727
include $(CLEAR_VARS)
2828
LOCAL_MODULE := iconv
29-
LOCAL_SRC_FILES := deps/libiconv/obj/local/$(TARGET_ARCH_ABI)/libiconv.a
30-
include $(PREBUILT_STATIC_LIBRARY)
29+
LOCAL_SRC_FILES := deps/libiconv/lib/.libs/libiconv.so
30+
include $(PREBUILT_SHARED_LIBRARY)
3131

3232
include $(CLEAR_VARS)
3333
LOCAL_MODULE := openal
@@ -355,8 +355,8 @@ LOCAL_SRC_FILES += \
355355
# json
356356
LOCAL_SRC_FILES += jni/src/json/jsoncpp.cpp
357357

358-
LOCAL_SHARED_LIBRARIES := openal ogg vorbis gmp
359-
LOCAL_STATIC_LIBRARIES := Irrlicht iconv freetype curl ssl crypto android_native_app_glue $(PROFILER_LIBS)
358+
LOCAL_SHARED_LIBRARIES := iconv openal ogg vorbis gmp
359+
LOCAL_STATIC_LIBRARIES := Irrlicht freetype curl ssl crypto android_native_app_glue $(PROFILER_LIBS)
360360

361361
ifeq ($(HAVE_LEVELDB), 1)
362362
LOCAL_STATIC_LIBRARIES += LevelDB

Diff for: ‎build/android/libiconv_android_mk.patch

-51
This file was deleted.

Diff for: ‎build/android/libiconv_stdio.patch

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
--- a/srclib/stdio.in.h 2011-08-07 15:42:06.000000000 +0200
22
+++ b/srclib/stdio.in.h 2015-06-10 09:27:58.129056262 +0200
3-
@@ -695,7 +696,8 @@ _GL_CXXALIASWARN (gets);
3+
@@ -695,8 +696,9 @@ _GL_CXXALIASWARN (gets);
44
/* It is very rare that the developer ever has full control of stdin,
55
so any use of gets warrants an unconditional warning. Assume it is
66
always declared, since it is required by C89. */
77
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
88
+/*_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");*/
99
+#define gets(a) fgets( a, sizeof(*(a)), stdin)
10-
#endif
10+
#endif
11+
12+
13+
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@

Diff for: ‎src/util/string.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ std::wstring utf8_to_wide(const std::string &input)
102102
return out;
103103
}
104104

105-
#ifdef __ANDROID__
106-
107-
// TODO: this is an ugly fix for wide_to_utf8 somehow not working on android
108-
std::string wide_to_utf8(const std::wstring &input)
109-
{
110-
return wide_to_narrow(input);
111-
}
112-
113-
#else // __ANDROID__
114-
115105
std::string wide_to_utf8(const std::wstring &input)
116106
{
117107
size_t inbuf_size = (input.length() + 1) * sizeof(wchar_t);
@@ -138,8 +128,6 @@ std::string wide_to_utf8(const std::wstring &input)
138128
return out;
139129
}
140130

141-
#endif // __ANDROID__
142-
143131
#else // _WIN32
144132

145133
std::wstring utf8_to_wide(const std::string &input)

0 commit comments

Comments
 (0)
Please sign in to comment.