# Template file for 'plan9port'
pkgname=plan9port
version=20180726
revision=1
_githash=df2d9ec9d169626cdc2a23829bb2831738215722
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="Leah Neukirchen <leah@vuxu.org>"
license="custom"
homepage="https://9fans.github.io/plan9port/"
distfiles="https://github.com/9fans/plan9port/archive/${_githash}.tar.gz"
checksum=100c13895d75911e2f9c2d136b705f34a854fbeb38a5a38d239497fbd5611738
nocross=yes
only_for_archs="i686 x86_64"  # swapcontext

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
	sed -i '1i#include <sys/types.h>' lib/linux-isnptl.c
}
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
}
