termux-packages/packages/libllvm/build.sh

155 lines
5.4 KiB
Bash
Raw Normal View History

2017-12-26 23:27:38 +01:00
TERMUX_PKG_HOMEPAGE=https://clang.llvm.org/
TERMUX_PKG_DESCRIPTION="Modular compiler and toolchain technologies library"
2019-01-21 13:53:58 +01:00
TERMUX_PKG_LICENSE="NCSA"
TERMUX_PKG_MAINTAINER="@buttaface"
2021-10-01 22:08:13 +02:00
TERMUX_PKG_VERSION=13.0.0
TERMUX_PKG_REVISION=2
2021-10-01 22:08:13 +02:00
TERMUX_PKG_SHA256=6075ad30f1ac0e15f07c1bf062c1e1268c241d674f11bd32cdf0e040c71f2bf3
2021-02-22 13:19:19 +01:00
TERMUX_PKG_SRCURL=https://github.com/llvm/llvm-project/releases/download/llvmorg-$TERMUX_PKG_VERSION/llvm-project-$TERMUX_PKG_VERSION.src.tar.xz
2015-06-13 01:03:31 +02:00
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_RM_AFTER_INSTALL="
2021-10-01 22:08:13 +02:00
bin/ld64.lld.darwin*
lib/libgomp.a
lib/libiomp5.a
"
2021-10-01 22:08:13 +02:00
TERMUX_PKG_DEPENDS="libc++, ncurses, libffi, zlib, libxml2"
# Replace gcc since gcc is deprecated by google on android and is not maintained upstream.
# Conflict with clang versions earlier than 3.9.1-3 since they bundled llvm.
TERMUX_PKG_CONFLICTS="gcc, clang (<< 3.9.1-3)"
TERMUX_PKG_BREAKS="libclang, libclang-dev, libllvm-dev"
TERMUX_PKG_REPLACES="gcc, libclang, libclang-dev, libllvm-dev"
TERMUX_PKG_GROUPS="base-devel"
# See http://llvm.org/docs/CMake.html:
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
2019-02-12 09:41:30 +01:00
-DPYTHON_EXECUTABLE=$(which python3)
-DLLVM_ENABLE_PIC=ON
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;compiler-rt;lld;lldb;openmp;polly
2017-07-04 13:45:47 +02:00
-DLLVM_ENABLE_LIBEDIT=OFF
-DLLVM_INCLUDE_TESTS=OFF
-DCLANG_DEFAULT_CXX_STDLIB=libc++
2021-10-01 22:08:13 +02:00
-DCLANG_DEFAULT_LINKER=lld
-DCLANG_INCLUDE_TESTS=OFF
-DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF
2021-10-01 22:08:13 +02:00
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON
-DDEFAULT_SYSROOT=$(dirname $TERMUX_PREFIX)
-DLLVM_LINK_LLVM_DYLIB=ON
-DLLDB_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/lldb-tblgen
-DLLVM_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/llvm-tblgen
-DCLANG_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/clang-tblgen
-DLIBOMP_ENABLE_SHARED=FALSE
-DOPENMP_ENABLE_LIBOMPTARGET=OFF
-DLLVM_ENABLE_SPHINX=ON
-DSPHINX_OUTPUT_MAN=ON
-DSPHINX_WARNINGS_AS_ERRORS=OFF
-DLLVM_TARGETS_TO_BUILD=all
2020-04-10 08:56:52 +02:00
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;RISCV
-DPERL_EXECUTABLE=$(which perl)
-DLLVM_ENABLE_FFI=ON
"
if [ $TERMUX_ARCH_BITS = 32 ]; then
# Do not set _FILE_OFFSET_BITS=64
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_FORCE_SMALLFILE_FOR_ANDROID=on"
fi
TERMUX_PKG_FORCE_CMAKE=true
TERMUX_PKG_HAS_DEBUG=false
# Debug build succeeds but make install with:
# cp: cannot stat '../src/projects/openmp/runtime/exports/common.min.50.ompt.optional/include/omp.h': No such file or directory
# common.min.50.ompt.optional should be common.deb.50.ompt.optional when doing debug build
2015-06-13 01:03:31 +02:00
termux_step_host_build() {
termux_setup_cmake
2020-04-10 08:56:52 +02:00
termux_setup_ninja
cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang;lldb' $TERMUX_PKG_SRCDIR/llvm
ninja -j $TERMUX_MAKE_PROCESSES clang-tblgen lldb-tblgen llvm-tblgen
2015-06-13 01:03:31 +02:00
}
termux_step_pre_configure() {
mkdir openmp/runtime/src/android
cp $TERMUX_PKG_BUILDER_DIR/nl_types.h openmp/runtime/src/android
cp $TERMUX_PKG_BUILDER_DIR/nltypes_stubs.cpp openmp/runtime/src/android
# Add unknown vendor, otherwise it screws with the default LLVM triple
# detection.
export LLVM_DEFAULT_TARGET_TRIPLE=${CCTERMUX_HOST_PLATFORM/-/-unknown-}
export LLVM_TARGET_ARCH
if [ $TERMUX_ARCH = "arm" ]; then
LLVM_TARGET_ARCH=ARM
2016-01-05 15:15:12 +01:00
elif [ $TERMUX_ARCH = "aarch64" ]; then
LLVM_TARGET_ARCH=AArch64
elif [ $TERMUX_ARCH = "i686" ] || [ $TERMUX_ARCH = "x86_64" ]; then
LLVM_TARGET_ARCH=X86
else
2017-03-05 03:30:38 +01:00
termux_error_exit "Invalid arch: $TERMUX_ARCH"
fi
2019-02-09 12:16:54 +01:00
# see CMakeLists.txt and tools/clang/CMakeLists.txt
2020-04-10 08:56:52 +02:00
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_TARGET_ARCH=$LLVM_TARGET_ARCH"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" -DLLVM_HOST_TRIPLE=$LLVM_DEFAULT_TARGET_TRIPLE"
export TERMUX_SRCDIR_SAVE=$TERMUX_PKG_SRCDIR
TERMUX_PKG_SRCDIR=$TERMUX_PKG_SRCDIR/llvm
}
termux_step_post_configure() {
TERMUX_PKG_SRCDIR=$TERMUX_SRCDIR_SAVE
2015-06-13 01:03:31 +02:00
}
2020-04-10 08:56:52 +02:00
termux_step_post_make_install() {
2019-08-13 00:39:35 +02:00
if [ "$TERMUX_CMAKE_BUILD" = Ninja ]; then
2021-04-26 16:28:42 +02:00
ninja docs-llvm-man docs-clang-man
2018-08-22 07:56:49 +02:00
else
2021-04-26 16:28:42 +02:00
make docs-llvm-man docs-clang-man
2018-08-22 07:56:49 +02:00
fi
cp docs/man/* $TERMUX_PREFIX/share/man/man1
cp tools/clang/docs/man/clang.1 $TERMUX_PREFIX/share/man/man1
cd $TERMUX_PREFIX/bin
for tool in clang clang++ cc c++ cpp gcc g++ ${TERMUX_HOST_PLATFORM}-{clang,clang++,gcc,g++,cpp}; do
2020-04-10 08:56:52 +02:00
ln -f -s clang-${TERMUX_PKG_VERSION:0:2} $tool
done
if [ $TERMUX_ARCH == "arm" ]; then
# For arm we replace symlinks with the same type of
# wrapper as the ndk uses to choose correct target
for tool in ${TERMUX_HOST_PLATFORM}-{clang,gcc}; do
unlink $tool
cat <<- EOF > $tool
#!$TERMUX_PREFIX/bin/bash
if [ "\$1" != "-cc1" ]; then
\`dirname \$0\`/clang --target=armv7a-linux-androideabi$TERMUX_PKG_API_LEVEL "\$@"
else
# Target is already an argument.
\`dirname \$0\`/clang "\$@"
fi
EOF
chmod u+x $tool
done
for tool in ${TERMUX_HOST_PLATFORM}-{clang++,g++}; do
unlink $tool
cat <<- EOF > $tool
#!$TERMUX_PREFIX/bin/bash
if [ "\$1" != "-cc1" ]; then
\`dirname \$0\`/clang++ --target=armv7a-linux-androideabi$TERMUX_PKG_API_LEVEL "\$@"
else
# Target is already an argument.
\`dirname \$0\`/clang++ "\$@"
fi
EOF
chmod u+x $tool
done
fi
2015-06-13 01:03:31 +02:00
}
termux_step_post_massage() {
2020-04-10 08:56:52 +02:00
# Not added to the package but kept around on the host for other packages like rust,
# which relies on LLVM, to use for configuration.
sed $TERMUX_PKG_BUILDER_DIR/llvm-config.in \
-e "s|@TERMUX_PKG_VERSION@|$TERMUX_PKG_VERSION|g" \
-e "s|@TERMUX_PKG_SRCDIR@|$TERMUX_PKG_SRCDIR|g" \
-e "s|@LLVM_DEFAULT_TARGET_TRIPLE@|$LLVM_DEFAULT_TARGET_TRIPLE|g" \
2020-04-10 08:56:52 +02:00
-e "s|@TERMUX_PREFIX@|$TERMUX_PREFIX|g" > $TERMUX_PREFIX/bin/llvm-config
chmod 755 $TERMUX_PREFIX/bin/llvm-config
}