# Template file for 'plan9port'
pkgname=plan9port
version=20160418
revision=4
_githash=35d43924484b88b9816e40d2f6bff4547f3eec47
wrksrc="${pkgname}-${_githash}"
hostmakedepends="perl"
makedepends="libX11-devel libXt-devel libXext-devel freetype-devel fontconfig-devel"
short_desc="Port of many Plan 9 programs to Unix-like operating systems"
maintainer="Christian Neukirchen <chneukirchen@gmail.com>"
license="custom"
homepage="http://swtch.com/plan9port/"
distfiles="https://github.com/9fans/plan9port/archive/${_githash}.tar.gz"
checksum=21b0d8ccb79975e49cb16a809c51557e5fe1659061591d1098544e0c5dea1d38
nocross=yes

post_extract() {
	# add missing LDFLAGS for some rules
	sed -i '/prereq$/s/$/ $LDFLAGS/' \
		src/cmd/auth/factotum/mkfile \
		src/cmd/auth/secstore/mkfile \
		src/cmd/devdraw/mkfile \
		src/cmd/faces/mkfile \
		src/cmd/mkfile
	sed -i 's/-lX11$/& $LDFLAGS/g' src/cmd/rio/mkfile
}
do_build() {
	CFLAGS+=' -D_DEFAULT_SOURCE'
	echo "CFLAGS='$CFLAGS'" >LOCAL.config
	echo "LDFLAGS='$LDFLAGS'" >>LOCAL.config
	sed -i 's/-O2/$CFLAGS/' bin/9c

	./INSTALL
}
do_install() {
	xargs -a lib/moveplan9.files -d'\n' sed -i "s#$wrksrc#/usr/lib/plan9#"

	vinstall $FILESDIR/plan9.sh 644 etc/profile.d
	vlicense LICENSE

	vmkdir usr/lib
	cp -a $wrksrc $DESTDIR/usr/lib/plan9
	cd $DESTDIR/usr/lib/plan9
	rm -f install.{log,sum}

	sed -i -e "s|\(-specs=.*hardened-ld\)||g" -e "s|\(-specs=.*hardened-cc1\)||g" $DESTDIR/usr/lib/plan9/config $DESTDIR/usr/lib/plan9/LOCAL.config
}
