# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lld
pkgver=5.0.1
pkgrel=0
_llvmver=${pkgver%%.*}
pkgdesc="The LLVM Linker"
url="http://llvm.org"
arch="all"
license="UOI-NCSA"
makedepends="
	cmake
	libedit-dev
	llvm-dev>=$_llvmver
	llvm-static>=$_llvmver
	llvm-test-utils=>$_llvmver
	zlib-dev"
checkdepends="gtest gtest-dev"
subpackages="$pkgname-dev"
source="https://llvm.org/releases/$pkgver/$pkgname-$pkgver.src.tar.xz"
builddir="$srcdir/$pkgname-$pkgver.src"

build() {
	mkdir -p "$builddir"/build
	cd "$builddir"/build

	cmake .. \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_VERBOSE_MAKEFILE=OFF \
		-DCMAKE_C_FLAGS_MINSIZEREL_INIT="$CFLAGS" \
		-DCMAKE_CXX_FLAGS_MINSIZEREL_INIT="$CXXFLAGS" \
		-DCMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT="$LDFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		\
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DLLVM_INCLUDE_TESTS=ON
	make
}

check() {
	cd "$builddir/build"
	[ "$CARCH" = "armhf" ] && return 0
	make check-lld
}

package() {
	cd "$builddir"/build

	make install DESTDIR="$pkgdir"
}

sha512sums="62c9682ae4e18a64af2c9e13d45925fbe022ca332d03b1c4232c6b730dab327418555c8da2b2bf8c6126032dfd378a0b9dedba83351d928784bf2b1f30dfaaca  lld-5.0.1.src.tar.xz"
