# Description: Compiler runtime libraries for clang
# URL: https://compiler-rt.llvm.org/
# Maintainer: CRUX System Team, core-ports at crux dot nu
# Depends on: clang

name=compiler-rt
version=22.1.8
release=1
source=(https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/llvm-project-$version.src.tar.xz)

build() {
    if prt-get isinst clang; then
        if ! /usr/bin/ldd /usr/bin/clang | grep -q -E '.*not found'; then
            export CC=clang
            export CXX=clang++
        fi
    fi

    cmake -S llvm-project-$version.src/compiler-rt -B build -G Ninja $PKGMK_COMPILER_RT \
        -D CMAKE_INSTALL_PREFIX=/usr \
        -D CMAKE_BUILD_TYPE=Release \
        -D CMAKE_C_FLAGS_RELEASE="$CFLAGS -fno-exceptions" \
        -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
        -D COMPILER_RT_INSTALL_PATH=/usr/lib/clang/${version:0:2} \
        -D Python3_EXECUTABLE=/usr/bin/python3 \
        -D COMPILER_RT_INCLUDE_TESTS=OFF \
        -D CAN_TARGET_i386=ON \
        -D CAN_TARGET_x86_64=ON \
        -Wno-dev
    cmake --build build -j ${JOBS:-1}
    DESTDIR=$PKG cmake --install build
}
