[source]
same_as = "../llvm21"

[build]
template = "custom"
dependencies = [
    "llvm21",
    "zstd",
]
dev-dependencies = [
    "llvm21.dev",
    "llvm21.runtime",
]
script = """
DYNAMIC_INIT
ARCH="$(echo "${TARGET}" | cut -d - -f1)"

generate_cookbook_cmake_file "$COOKBOOK_HOST_TARGET" "" "$COOKBOOK_TOOLCHAIN" native.cmake

if [ "$TARGET" = "$COOKBOOK_HOST_TARGET" ]; then
COOKBOOK_CMAKE_FLAGS+=( -DLLVM_TABLEGEN_EXE=${COOKBOOK_TOOLCHAIN}/bin/llvm-tblgen )
else
COOKBOOK_CMAKE_FLAGS+=( -DLLVM_TABLEGEN_EXE=${COOKBOOK_HOST_SYSROOT}/bin/llvm-tblgen )
fi

COOKBOOK_CMAKE_FLAGS+=(
    -DLLVM_ROOT="${COOKBOOK_SYSROOT}"
    -DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_TOOLCHAIN_FILE=$(realpath native.cmake)"
    -DLLVM_USE_STATIC_ZSTD=On

# the shared options from llvm
    -DCMAKE_CXX_FLAGS="--std=gnu++11"
    -DBUILD_SHARED_LIBS=False
    -DLLVM_BUILD_EXAMPLES=Off
    -DLLVM_BUILD_TESTS=Off
    -DLLVM_DEFAULT_TARGET_TRIPLE="${TARGET}"
    -DLLVM_ENABLE_LTO=Off
    -DLLVM_ENABLE_RTTI=On
    -DLLVM_ENABLE_THREADS=On
    -DLLVM_INCLUDE_EXAMPLES=Off
    -DLLVM_INCLUDE_TESTS=Off
    -DLLVM_OPTIMIZED_TABLEGEN=On
    -DLLVM_TARGET_ARCH=$ARCH
    -DLLVM_TOOLS_INSTALL_DIR=bin
    -DLLVM_UTILS_INSTALL_DIR=bin
    -DUNIX=1
)

COOKBOOK_SOURCE="$COOKBOOK_SOURCE/lld"

cookbook_cmake
"""

[[optional-packages]]
name = "dev"
dependencies = []
files = [
    "usr/include/lld*/**",
    "usr/lib/liblld*.a",
    "usr/lib/cmake/lld/**",
]
