# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=mold
pkgver=2.39.1
pkgrel=0
pkgdesc="fast modern linker"
url="https://github.com/rui314/mold"
arch="all"
license="MIT"
makedepends="
	cmake
	linux-headers
	mimalloc2-dev
	onetbb-dev
	samurai
	zlib-dev
	zstd-dev
	"
checkdepends="
	bash
	dwarf-tools
	grep
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/rui314/mold/archive/refs/tags/v$pkgver.tar.gz"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \
		-DMOLD_LTO=ON \
		-DMOLD_USE_SYSTEM_MIMALLOC=ON \
		-DMOLD_USE_SYSTEM_TBB=ON \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)"

	cmake --build build
}

check() {
	# s390x-shared-abs-sym and riscv64-shared-abs-sym are broken
	case "$CARCH" in
		s390x) ctest --test-dir build -E s390x-shared-abs-sym;;
		riscv64) ctest --test-dir build -E riscv64-shared-abs-sym;;
		*) ctest --test-dir build;;
	esac
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
2d6d3d892d0dc6b256fbb2a1bbe7519948c2cd683549d23727da9cbccf1dad80a3af2826bf96b9d02ed56a765fa46ffc8fcd23168bb5624a1fa4b9dd21606005  mold-2.39.1.tar.gz
"
