# Template file for 'llvm22-bootstrap'
pkgname=llvm22-bootstrap
version=22.1.1
revision=1
_spirv_version=v22.1.0
build_wrksrc=llvm
build_style=cmake
configure_args="
 -DCMAKE_BUILD_TYPE=Release -Wno-dev
 -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="Duncaen <duncaen@voidlinux.org>"
license="Apache-2.0 AND NCSA AND custom:Apache-2.0-with-llvm-exception"
homepage="https://www.llvm.org"
distfiles="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-${version/rc/-rc}.tar.gz
 https://github.com/KhronosGroup/SPIRV-LLVM-Translator/archive/${_spirv_version}.tar.gz"
checksum="c48878550911a8a8993a749e6118446082656768e62b26456ac7d39c4422b409
 a5d476404ab88ac0d148211da50428178c89caef8af8042a3ca8e71e58ed9427"

skip_extraction=${_spirv_version}.tar.gz

conflicts="llvm22>=0 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"
}
