-
-
Save paulwratt/19b244d37de3d6079bb6f444ad61f62f to your computer and use it in GitHub Desktop.
Build TinyCC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
PATH="$(pwd)/tinycc/temp:$(pwd)/tinycc/build/bin:$(pwd)/google-ndk:$(pwd)/google-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}" | |
if [[ -d tinycc ]]; then | |
rm -rf tinycc | |
fi | |
git clone --depth=1 https://repo.or.cz/tinycc.git | |
cd tinycc | |
patch -p1 < ../patches/tinycc/libtcc.c.patch | |
patch -p1 < ../patches/tinycc/tccelf.c.patch | |
PREFIX='<TinyCC Prefix>' | |
build() { | |
mkdir -p temp | |
echo '#!/bin/bash' > ./temp/$1-clang | |
echo "$2-clang \"\$@\"" >> ./temp/$1-clang | |
chmod +x ./temp/$1-clang | |
if [[ "$4" = "armeabi-v7a" ]] || [[ "$4}" = "x86" ]]; then | |
ELF_INTERPRETER_PATH='/system/bin/linker' | |
ANDROID_LIB_PATH='/system/lib:/system/vendor/lib' | |
else | |
ELF_INTERPRETER_PATH='/system/bin/linker64' | |
ANDROID_LIB_PATH='/system/lib64:/system/vendor/lib64' | |
fi | |
./configure --prefix="/tmp/tcc.$3" \ | |
--cpu=$3 | |
make tcc | |
mv -f tcc tcc.$3 | |
make distclean | |
./configure --prefix="${PREFIX}" \ | |
--cross-prefix="$1-" \ | |
--cc=clang \ | |
--cpu="$3" \ | |
--disable-rpath \ | |
--elfinterp="${ELF_INTERPRETER_PATH}" \ | |
--crtprefix="${PREFIX}/lib" \ | |
--sysincludepaths="${PREFIX}/include:${PREFIX}/include/$1:${PREFIX}/lib/tcc/include" \ | |
--libpaths="${PREFIX}/lib:${PREFIX}/lib/tcc:${ANDROID_LIB_PATH}" | |
mv tcc.$3 tcc | |
touch -d "next minute" tcc | |
make libtcc1.a | |
rm -f tcc | |
make tcc | |
./configure --prefix="$(pwd)/build-$4" | |
make install | |
mkdir -p build-$4/lib | |
mkdir -p build-$4/include | |
cp -Rf ../google-ndk/sysroot/usr/include/. \ | |
build-$4/include | |
echo -e '#define __va_list\n'"$(cat build-$4/include/sys/types.h)" > build-$4/include/sys/types.h | |
if [[ $5 = "x86_64" ]]; then | |
cp -Rf ../google-ndk/platforms/android-21/arch-$5/usr/lib64/* \ | |
build-$4/lib | |
else | |
cp -Rf ../google-ndk/platforms/android-21/arch-$5/usr/lib/* \ | |
build-$4/lib | |
fi | |
make distclean clean | |
} | |
build arm-linux-androideabi armv7a-linux-androideabi21 armv7a armeabi-v7a arm | |
build aarch64-linux-android aarch64-linux-android21 aarch64 arm64-v8a arm64 | |
build i686-linux-android i686-linux-android21 x86 x86 x86 | |
build x86_64-linux-android x86_64-linux-android21 x86_64 x86_64 x86_64 | |
cd ../ | |
#rm -rf tinycc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -uNr tcc/libtcc.c tcc/libtcc.c | |
--- tcc/libtcc.c 2017-12-17 10:27:05.000000000 +0200 | |
+++ tcc/libtcc.c 2018-08-09 19:25:44.086756864 +0300 | |
@@ -974,9 +974,20 @@ | |
/* add libc crt1/crti objects */ | |
if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && | |
!s->nostdlib) { | |
- if (output_type != TCC_OUTPUT_DLL) | |
+ | |
+#ifdef __ANDROID__ | |
+ if (output_type != TCC_OUTPUT_DLL) { | |
+ tcc_add_crt(s, "crtbegin_dynamic.o"); | |
+ } else { | |
+ tcc_add_crt(s, "crtbegin_so.o"); | |
+ } | |
+#else | |
+ if (output_type != TCC_OUTPUT_DLL) { | |
tcc_add_crt(s, "crt1.o"); | |
+ } | |
tcc_add_crt(s, "crti.o"); | |
+#endif // __ANDROID__ | |
+ | |
} | |
#endif | |
return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -uNr tcc/tccelf.c tcc/tccelf.c | |
--- tcc/tccelf.c 2017-12-17 10:27:05.000000000 +0200 | |
+++ tcc/tccelf.c 2018-08-09 19:28:33.036752853 +0300 | |
@@ -1202,8 +1202,17 @@ | |
#endif | |
tcc_add_support(s1, TCC_LIBTCC1); | |
/* add crt end if not memory output */ | |
- if (s1->output_type != TCC_OUTPUT_MEMORY) | |
+ if (s1->output_type != TCC_OUTPUT_MEMORY) { | |
+#ifdef __ANDROID__ | |
+ if (s1->output_type == TCC_OUTPUT_DLL) { | |
+ tcc_add_crt(s1, "crtend_so.o"); | |
+ } else { | |
+ tcc_add_crt(s1, "crtend_android.o"); | |
+ } | |
+#else | |
tcc_add_crt(s1, "crtn.o"); | |
+#endif | |
+ } | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment