# Template file for 'dmd2.091'
pkgname=dmd2.091
version=2.091.0
revision=1
create_wrksrc=yes
hostmakedepends="dmd2.081 which"
makedepends="git"
depends="gcc"
short_desc="Digital Mars D compiler, 2.091"
maintainer="Auri <me@aurieh.me>"
license="BSL-1.0"
homepage="http://www.digitalmars.com/d/2.0/"
distfiles="
 https://github.com/dlang/dmd/archive/v${version}.tar.gz>dmd-${version}.tar.gz
 https://github.com/dlang/druntime/archive/v${version}.tar.gz>druntime-${version}.tar.gz
 https://github.com/dlang/phobos/archive/v${version}.tar.gz>phobos-${version}.tar.gz
 http://downloads.dlang.org/releases/2.x/${version}/dmd.${version}.linux.tar.xz"
checksum="bcca38f4b80b51ae0a1955dc29e6cbfaa4d01d94869ddfcacf9292898c34343a
 cc8ba196b08cca04488d97d0e35c878f7351b7d8128aec90eaa312d2bd9a6af2
 df9f81eecda4366adc5ca9ed31a0b4474c248544b120ff6fa3f6cb45917d8769
 6e4bd4ee73a553921cdca7e3e21768b842b18186d07c0b4898fbd13a359875c0"
conf_files="/etc/dmd.conf"
provides="d-compiler-${version}_${revision}"
conflicts="dmd-bootstrap dmd2.081 libphobos2.081"
nopie=yes
nocross=yes
disable_parallel_build=yes
LDFLAGS="-lpthread"

case "$XBPS_TARGET_MACHINE" in
	x86_64*) _archbits=64;;
	i686) _archbits=32;;
	*) broken="unsupported arch upstream";;
esac

post_extract() {
	mv dmd-${version} dmd
	mv druntime-${version} druntime
	mv phobos-${version} phobos
}

do_build() {
	local dmd

	cd dmd
	make ${makejobs} -f posix.mak MODEL=${_archbits} TARGET_CPU=X86 ENABLE_RELEASE=1 PIC=1
	dmd=${wrksrc}/dmd/generated/linux/release/$_archbits/dmd

	make ${makejobs} -C docs

	cd ../druntime
	make ${makejobs} -f posix.mak MODEL=${_archbits} DMD=$dmd ENABLE_RELEASE=1 PIC=1

	cd ../phobos
	make ${makejobs} -f posix.mak MODEL=${_archbits} DMD=$dmd ENABLE_RELEASE=1 PIC=1
}

do_install() {
	cd dmd
	vbin generated/linux/release/$_archbits/dmd
	vinstall ${FILESDIR}/dmd.conf 644 etc

	# note: dmd, druntime and phobos all share the same license
	vlicense LICENSE.txt

	vman generated/docs/man/man1/dmd.1
	vman generated/docs/man/man5/dmd.conf.5

	vmkdir usr/include/d

	cd ../phobos
	cp -r ./{*.d,etc,std} ${PKGDESTDIR}/usr/include/d
	vinstall generated/linux/release/$_archbits/libphobos2.a 644 usr/lib libphobos2.a

	cd ../druntime
	vmkdir usr/include/d/druntime
	cp -r import ${PKGDESTDIR}/usr/include/d/druntime
	vinstall generated/linux/release/$_archbits/libdruntime.a 644 usr/lib libdruntime.a
}
