# Template file for 'llvm19-bootstrap'
pkgname=llvm19-bootstrap
version=19.1.4
revision=1
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 19"
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=v19.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="010e1fd3cabee8799bd2f8a6fbc68f28207494f315cf9da7057a2820f79fd531
 7f6f7a1af0eb40910ddf3a7647d2186c8c5dc5a47945afa935aeec56bacf4336"
skip_extraction=${_spirv_version}.tar.gz
conflicts="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
}
