golang: Use clang for native build
[termux-packages] / packages / clang / build.sh
CommitLineData
59f0d218
FF
1TERMUX_PKG_HOMEPAGE=http://clang.llvm.org/
2TERMUX_PKG_DESCRIPTION="C and C++ frontend for the LLVM compiler"
51872374 3_PKG_MAJOR_VERSION=3.9
d1fd5e29 4TERMUX_PKG_VERSION=${_PKG_MAJOR_VERSION}.1
59f0d218 5TERMUX_PKG_SRCURL=http://llvm.org/releases/${TERMUX_PKG_VERSION}/llvm-${TERMUX_PKG_VERSION}.src.tar.xz
d1fd5e29 6TERMUX_PKG_SHA256=1fd90354b9cf19232e8f168faf2220e79be555df3aa743242700879e8fd329ee
59f0d218
FF
7TERMUX_PKG_HOSTBUILD=true
8TERMUX_PKG_RM_AFTER_INSTALL="bin/macho-dump bin/bugpoint bin/llvm-tblgen lib/BugpointPasses.so lib/LLVMHello.so"
3f300a10 9TERMUX_PKG_DEPENDS="binutils, ncurses, ndk-sysroot, ndk-stl, libgcc"
768ce14e
FF
10# Replace gcc since gcc is deprecated by google on android and is not maintained upstream.
11TERMUX_PKG_CONFLICTS=gcc
12TERMUX_PKG_REPLACES=gcc
58f7a21c
VB
13TERMUX_PKG_EXTRA_CONFIGURE_ARGS="-DCMAKE_INSTALL_ALWAYS=1 -DLLVM_ENABLE_PIC=ON -DLLVM_BUILD_TESTS=OFF"
14TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF -DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF"
15TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DBUILD_SHARED_LIBS=ON -DLLVM_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/llvm-tblgen"
16TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DCLANG_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/clang-tblgen"
17TERMUX_PKG_FORCE_CMAKE=yes
59f0d218
FF
18
19termux_step_post_extract_package () {
20 CLANG_SRC_TAR=cfe-${TERMUX_PKG_VERSION}.src.tar.xz
51872374
FF
21 test ! -f $TERMUX_PKG_CACHEDIR/$CLANG_SRC_TAR && termux_download http://llvm.org/releases/${TERMUX_PKG_VERSION}/$CLANG_SRC_TAR \
22 $TERMUX_PKG_CACHEDIR/$CLANG_SRC_TAR \
d1fd5e29 23 e6c4cebb96dee827fa0470af313dff265af391cb6da8d429842ef208c8f25e63
59f0d218 24
f01cc586
FF
25 # COMPILERRT_SRC_TAR=compiler-rt-${TERMUX_PKG_VERSION}.src.tar.xz
26 # test ! -f $TERMUX_PKG_CACHEDIR/$COMPILERRT_SRC_TAR && curl http://llvm.org/releases/${TERMUX_PKG_VERSION}/${COMPILERRT_SRC_TAR} > $TERMUX_PKG_CACHEDIR/$COMPILERRT_SRC_TAR
27
59f0d218
FF
28 tar -xf $TERMUX_PKG_CACHEDIR/$CLANG_SRC_TAR -C tools
29 mv tools/cfe-${TERMUX_PKG_VERSION}.src tools/clang
e34d8413 30
f01cc586
FF
31 # tar -xf $TERMUX_PKG_CACHEDIR/$COMPILERRT_SRC_TAR -C projects
32 # mv projects/compiler-rt-${TERMUX_PKG_VERSION}.src projects/compiler-rt
33
e34d8413
FF
34 # Remove symlinks which are not overwritten on repeated builds even with CMAKE_INSTALL_ALWAYS=1:
35 rm -f $TERMUX_PREFIX/{bin/llvm*,lib/libLLVM*,lib/libclang*}
59f0d218
FF
36}
37
38termux_step_host_build () {
51872374
FF
39 cmake -G "Unix Makefiles" $TERMUX_PKG_SRCDIR \
40 -DLLVM_BUILD_TESTS=OFF \
41 -DLLVM_INCLUDE_TESTS=OFF
ae0899e7 42 make -j $TERMUX_MAKE_PROCESSES clang-tblgen llvm-tblgen
59f0d218
FF
43}
44
58f7a21c 45termux_step_pre_configure () {
59f0d218 46 cd $TERMUX_PKG_BUILDDIR
4936e557
FF
47 LLVM_DEFAULT_TARGET_TRIPLE=$TERMUX_HOST_PLATFORM
48 if [ $TERMUX_ARCH = "arm" ]; then
49 LLVM_TARGET_ARCH=ARM
8f36e264
FF
50 # See https://github.com/termux/termux-packages/issues/282
51 LLVM_DEFAULT_TARGET_TRIPLE="armv7a-linux-androideabi"
88b27cc6
FF
52 elif [ $TERMUX_ARCH = "aarch64" ]; then
53 LLVM_TARGET_ARCH=AArch64
4936e557
FF
54 elif [ $TERMUX_ARCH = "i686" ]; then
55 LLVM_TARGET_ARCH=X86
56 elif [ $TERMUX_ARCH = "x86_64" ]; then
57 LLVM_TARGET_ARCH=X86
58 else
59 echo "Invalid arch: $TERMUX_ARCH"
60 exit 1
61 fi
59f0d218 62 # see CMakeLists.txt and tools/clang/CMakeLists.txt
58f7a21c
VB
63 TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_DEFAULT_TARGET_TRIPLE=$LLVM_DEFAULT_TARGET_TRIPLE"
64 TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_TARGET_ARCH=$LLVM_TARGET_ARCH -DLLVM_TARGETS_TO_BUILD=$LLVM_TARGET_ARCH"
59f0d218
FF
65}
66
67termux_step_post_make_install () {
768ce14e
FF
68 cd $TERMUX_PREFIX/bin
69
290517e8
FF
70 for tool in clang clang++ cc c++ cpp gcc g++ ${TERMUX_HOST_PLATFORM}-{gcc,g++,cpp}; do
71 ln -f -s clang-${_PKG_MAJOR_VERSION} $tool
72 done
59f0d218 73}