# Template file for 'llvm21-bootstrap'
pkgname=llvm21-bootstrap
version=21.1.7
revision=1
build_wrksrc=llvm
build_style=cmake
configure_args="
 -DCMAKE_BUILD_TYPE=Release
 -DENABLE_LINKER_BUILD_ID=YES
 -DLLVM_INSTALL_UTILS=YES
 -DLLVM_BINUTILS_INCDIR=/usr/include
 -DBASE_LLVM_VERSION=${version}
 -DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=/usr
 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=NO
 -DLLVM_TARGETS_TO_BUILD=Native
 -DLLVM_ENABLE_PROJECTS=clang;lld
"
hostmakedepends="perl python3 pkg-config"
makedepends="python3-devel zlib-devel elfutils-devel libffi-devel libedit-devel
 libxml2-devel binutils-devel z3-devel SPIRV-Headers SPIRV-Tools-devel"
short_desc="LLVM Compiler Infrastructure Project - Version ${_major}"
maintainer="Daniel Martinez <danielmartinez@cock.li>"
license="Apache-2.0 AND NCSA AND custom:Apache-2.0-with-llvm-exception"
homepage="https://www.llvm.org"
_spirv_version=v21.1.1
distfiles="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version}.tar.gz
 https://github.com/KhronosGroup/SPIRV-LLVM-Translator/archive/refs/tags/${_spirv_version}.tar.gz"
checksum="9ee167cdf8f6b5221d6b02dbe9a664cf8c6fee70fab071aaa4a3889c7c265258
 dda46febdb060a1d5cc2ceeb9682ccaf33e55ae294fd0793274531b54f07c46b"
skip_extraction=${_spirv_version}.tar.gz
conflicts="llvm21>=0 llvm19>=0 llvm18>=0 llvm17>=0 llvm15>=0"
lib32disabled=yes
python_version=3
nodebug=yes
repository=bootstrap
nocross="bootstrap package"

# fails to build with libquadmth on musl
case "$XBPS_TARGET_MACHINE" in
	x86_64|i686) makedepends+=" libquadmath-devel" ;;
esac

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	configure_args+=" -DLIBCXX_HAS_MUSL_LIBC=YES
	 -DCOMPILER_RT_BUILD_GWP_ASAN=OFF"
fi

case "$XBPS_TARGET_MACHINE" in
	i686*) _arch="X86";;
	x86_64*) _arch="X86";;
	armv5*) _arch="Armv5te";;
	armv6*) _arch="Armv6";;
	armv7*) _arch="Armv7";;
	aarch64*) _arch="AArch64";;
	mips*) _arch="Mips";;
	ppc*) _arch="PowerPC";;
	riscv64*) _arch="RISCV64";;
esac

configure_args+=" -DLLVM_TARGET_ARCH=${_arch}"

pre_configure() {
	configure_args+=" -DLLVM_HOST_TRIPLE=$($CC -dumpmachine)"
	configure_args+=" -DLLVM_DEFAULT_TARGET_TRIPLE=$($CXX -dumpmachine)"
}

post_extract() {
	vsrcextract -C llvm/projects/llvm-spirv "${_spirv_version}.tar.gz"
}

post_install() {
	vlicense "${wrksrc}/LICENSE.TXT"
}
