--- a/llvm.SlackBuild 2023-09-30 01:51:01.252515847 +0300 +++ b/llvm.SlackBuild 2023-09-30 01:57:17.598534225 +0300 @@ -51,6 +51,27 @@ if [ -z "$ARCH" ]; then esac fi +# Building lldb will be determined automatically unless BUILD_LLDB is +# preset to YES or NO: +if [ -z $BUILD_LLDB ]; then + if [ "$ARCH" = "riscv64" ]; then + BUILD_LLDB=NO + else + BUILD_LLDB=YES + fi +fi + +# Building OpenMP will be determined automatically unless BUILD_OPENMP is +# preset to YES or NO: +if [ -z $BUILD_OPENMP ]; then + if [ "$ARCH" = "riscv64" ]; then + # OpenMP not supported on RISC-V + BUILD_OPENMP=NO + else + BUILD_OPENMP=YES + fi +fi + # If the variable PRINT_PACKAGE_NAME is set, then this script will report what # the name of the created package would be, and then exit. This information # could be useful to other scripts. @@ -67,6 +88,8 @@ BUILDDIR=${TMP}/llvm-build-${VERSION} # massive warning spew: IGNORE_GNU_EXTENSIONS=${IGNORE_GNU_EXTENSIONS:--Wno-unknown-warning-option -Wno-gnu-line-marker -Wno-gnu-anonymous-struct -Wno-gnu-include-next} +LINKER="lld" + if [ "$ARCH" = "i586" ]; then SLKCFLAGS="-O2 -march=i586 -mtune=i686 $IGNORE_GNU_EXTENSIONS" LIBDIRSUFFIX="" @@ -76,11 +99,23 @@ elif [ "$ARCH" = "i686" ]; then elif [ "$ARCH" = "x86_64" ]; then SLKCFLAGS="-O2 -fPIC $IGNORE_GNU_EXTENSIONS" LIBDIRSUFFIX="64" +elif [ "$ARCH" = "aarch64" ]; then + SLKCFLAGS="-O2 -fPIC $IGNORE_GNU_EXTENSIONS" + LIBDIRSUFFIX="64" +elif [ "$ARCH" = "riscv64" ]; then + SLKCFLAGS="-O2 -fPIC $IGNORE_GNU_EXTENSIONS" + LIBDIRSUFFIX="64" + CMAKE_EXTRA="-DCMAKE_SHARED_LINKER_FLAGS=-latomic" + LINKER="bfd" else SLKCFLAGS="-O2 $IGNORE_GNU_EXTENSIONS" LIBDIRSUFFIX="" fi +# Choose a compiler (gcc/g++ or clang/clang++): +export CC=${CC:-clang} +export CXX=${CXX:-clang++} + # Building clangd will be determined automatically unless BUILD_CLANG is # preset to YES or NO: if [ -z $BUILD_CLANGD ]; then @@ -136,8 +171,10 @@ cd $PKGNAM-${VERSION}.src/tools || cd $P #tar xf $CWD/flang-$VERSION.src.tar.xz || exit 1 #mv flang-${VERSION} flang 2>/dev/null || mv flang-${VERSION}.src flang || exit 1 echo "Extracting $CWD/lldb-$VERSION.src.tar.xz..." - tar xf $CWD/lldb-$VERSION.src.tar.xz || exit 1 - mv lldb-${VERSION} lldb 2>/dev/null || mv lldb-${VERSION}.src lldb || exit 1 + if [ "$BUILD_LLDB" = "YES" ]; then + tar xf $CWD/lldb-$VERSION.src.tar.xz || exit 1 + mv lldb-${VERSION} lldb 2>/dev/null || mv lldb-${VERSION}.src lldb || exit 1 + fi echo "Extracting $CWD/lld-$VERSION.src.tar.xz..." tar xf $CWD/lld-$VERSION.src.tar.xz || exit 1 mv lld-${VERSION} lld 2>/dev/null || mv lld-${VERSION}.src lld || exit 1 @@ -157,6 +194,10 @@ cd projects || exit 1 echo "Extracting $CWD/openmp-$VERSION.src.tar.xz..." tar xf $CWD/openmp-$VERSION.src.tar.xz || exit 1 mv openmp-${VERSION} openmp 2>/dev/null || mv openmp-${VERSION}.src openmp || exit 1 + if [ "$BUILD_OPENMP" = "YES" ]; then + tar xf $CWD/openmp-$VERSION.src.tar.xz || exit 1 + mv openmp-${VERSION} openmp 2>/dev/null || mv openmp-${VERSION}.src openmp || exit 1 + fi echo "Extracting $CWD/libcxx-${VERSION}.src.tar.xz..." tar xf $CWD/libcxx-${VERSION}.src.tar.xz || exit 1 mv libcxx-${VERSION} libcxx 2>/dev/null || mv libcxx-${VERSION}.src libcxx || exit 1 @@ -175,6 +216,12 @@ cd ../ # Support GCC built for i586-slackware-linux: zcat $CWD/clang.toolchains.i586.triple.diff.gz | patch -p1 --verbose || exit 1 +xzcat $CWD/clang.dynamic.linker.aarch64.patch.xz | patch -p1 --verbose || exit 1 +xzcat $CWD/clang.toolchains.aarch64.triple.patch.xz | patch -p1 --verbose || exit 1 + +xzcat $CWD/clang.dynamic.linker.riscv64.patch.xz | patch -p1 --verbose || exit 1 +xzcat $CWD/clang.toolchains.riscv64.triple.patch.xz | patch -p1 --verbose || exit 1 + # We require libatomic on 32-bit platforms: if [ -f ./tools/lldb/source/Utility/CMakeLists.txt ]; then if [ "$ARCH" = "i586" -o "$ARCH" = "i686" ]; then @@ -194,6 +241,15 @@ cd projects ln -sf ../../cmake . cd - +# Patch invalid conversion from unwind state: +zcat $CWD/unwind_state_invalid_conversion.diff.gz | patch -p1 --verbose || exit 1 + +# Patch riscv64: AllWinner D1 does not have fence.tso instruction: +zcat $CWD/riscv64-no-fence.tso.diff.gz | patch -p1 --verbose || exit 1 + +# Patch alpha: Fix invalid variable name __alpha: +zcat $CWD/alpha_fix_variable_name.diff.gz | patch -p1 --verbose || exit 1 + chown -R root:root . find . \ \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 -o -perm 511 \) \ @@ -218,8 +274,8 @@ cd build # Nuke LLVM libunwind as it conflicts with the one already on the system: rm -r ../projects/libunwind cmake -GNinja \ - -DCMAKE_C_COMPILER="clang" \ - -DCMAKE_CXX_COMPILER="clang++" \ + -DCMAKE_C_COMPILER="$CC" \ + -DCMAKE_CXX_COMPILER="$CXX" \ -DCMAKE_C_FLAGS:STRING="$SLKCFLAGS" \ -DCMAKE_CXX_FLAGS:STRING="$SLKCFLAGS" \ -DCMAKE_INSTALL_PREFIX=/usr \ @@ -228,7 +284,7 @@ cd build -DLIBCXXABI_LIBDIR_SUFFIX=${LIBDIRSUFFIX} \ -DCMAKE_BUILD_TYPE=Release \ $SHARED_LIBRARY_OPTIONS \ - -DLLVM_USE_LINKER=lld \ + -DLLVM_USE_LINKER=$LINKER \ -DLLVM_ENABLE_RTTI=ON \ -DLLVM_ENABLE_FFI=ON \ -DLLVM_ENABLE_ZLIB=ON \ @@ -244,6 +300,7 @@ cd build -DCLANG_DEFAULT_PIE_ON_LINUX=ON \ -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \ $CLANGD \ + $CMAKE_EXTRA \ .. || exit 1 "${NINJA:=ninja}" $NUMJOBS || exit 1 @@ -286,8 +343,10 @@ python -m compileall "$PKG/usr/lib$LIBDI python -O -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY2}/site-packages/clang" python3 -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY3}/site-packages/clang" python3 -O -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY3}/site-packages/clang" -python -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY2}/site-packages/lldb" -python -O -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY2}/site-packages/lldb" +if [ "$BUILD_LLDB" = "YES" ]; then + python -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY2}/site-packages/lldb" + python -O -m compileall "$PKG/usr/lib$LIBDIRSUFFIX/python${PY2}/site-packages/lldb" +fi python -m compileall "$PKG/usr/share/scan-view" python -O -m compileall "$PKG/usr/share/scan-view" python -m compileall "$PKG/usr/share/clang"