Files
llvm/source.sh
T

98 lines
3.9 KiB
Bash

# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE
# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT
# The prepare function is executed in the root of the temp directory
# This function is used for putting downloaded files to the correct location or applying patches
prepare() {
cd "$BPM_SOURCE"/tools
patch -Np1 -i "$BPM_WORKDIR"/enable-fstack-protector-strong-by-default.patch
}
# The build function is executed in the source directory
# This function is used to compile the source code
build() {
export CC=gcc CXX=g++
cmake -B build -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-DLLVM_ENABLE_FFI=ON \
-DLLVM_BUILD_LLVM_DYLIB=ON \
-DLLVM_LINK_LLVM_DYLIB=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_BINUTILS_INCDIR=/usr/include \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DCLANG_DEFAULT_PIE_ON_LINUX=ON \
-DCLANG_CONFIG_FILE_SYSTEM_DIR=/etc/clang \
-Wno-dev -G Ninja
cmake --build build
}
_pick() {
local p="$1" f d; shift
for f; do
[ -d "$BPM_WORKDIR"/output_"$p" ] || { echo "Split package $p not found"; exit 1; }
d="$BPM_WORKDIR"/output_"$p"/"${f#$BPM_OUTPUT}"
mkdir -p "$(dirname "$d")"
mv "$f" "$d"
rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
done
}
# The package function is executed in the source directory
# This function is used to move the compiled files into the output directory
package_llvm() {
DESTDIR="$BPM_OUTPUT" cmake --install build
# Install missing binary
install -Dm755 "$BPM_SOURCE"/build/bin/FileCheck "$BPM_OUTPUT"/usr/bin/FileCheck
cd "$BPM_OUTPUT"
# Move compiler-rt files into split packag
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/bin/hwasan_symbolize
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/include/fuzzer
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/include/orc
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/include/profile
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/include/sanitizer
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/include/xray
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/lib
_pick compiler-rt usr/lib/clang/${BPM_PKG_VERSION%%.*}/share
# Move clang files into split package
_pick clang usr/bin/{amdgpu-arch,analyze-build,c-index-test,diagtool,git-clang-format,hmaptool,intercept-build,nvptx-arch,scan-build,scan-build-py,scan-view}
_pick clang usr/bin/clang*
_pick clang usr/lib/libclang*
_pick clang usr/lib/cmake/clang
_pick clang usr/include/clang-c/
_pick clang usr/include/clang
_pick clang usr/lib/clang
_pick clang usr/share/clang
_pick clang usr/share/man/man1/scan-build.1
_pick clang usr/share/scan-build
_pick clang usr/share/scan-view
# Move runtime libraries into split package
for lib in libLLVM libLLVM-"${BPM_PKG_VERSION%%.*}" libLTO libRemarks; do
_pick llvm-libs "$BPM_OUTPUT"/usr/lib/"$lib".so*
done
# Install package license
install -Dm644 "$BPM_SOURCE"/LICENSE.TXT "$BPM_OUTPUT"/usr/share/licenses/llvm/LICENSE.TXT
}
package_llvm-libs() {
# Install package license
install -Dm644 "$BPM_SOURCE"/LICENSE.TXT "$BPM_OUTPUT"/usr/share/licenses/llvm-libs/LICENSE.TXT
}
package_compiler-rt() {
# Install package license
install -Dm644 "$BPM_SOURCE"/LICENSE.TXT "$BPM_OUTPUT"/usr/share/licenses/compiler-rt/LICENSE.TXT
}
package_clang() {
# Install package license
install -Dm644 "$BPM_SOURCE"/LICENSE.TXT "$BPM_OUTPUT"/usr/share/licenses/clang/LICENSE.TXT
}