# Template file for 'nim'
pkgname=nim
version=0.13.0
revision=1
depends="gcc"
hostmakedepends="ed"
short_desc="The Nim programming language"
maintainer="allan <mail@may.mooo.com>"
license="MIT"
homepage="http://nim-lang.org/"
distfiles="https://github.com/nim-lang/Nim/archive/v${version}.tar.gz
 https://github.com/nim-lang/csources/archive/v${version}.tar.gz>csources.tar.gz"
checksum="52ccb73986faadb1abbf0d216cea95cf7d2f11ebed0b39e57150fe0c5be25ccf
 fe6aee48c5c2585eea14a7cb338bd3766e3d104a22195a79a53c35c8de371f64"
build_wrksrc=Nim-$version
create_wrksrc=yes

post_extract() {
	mv csources-$version $build_wrksrc/csources
}

do_build() {
	cd csources
	sh build.sh
	cd ..

	bin/nim c koch
	./koch boot -d:release

	case "$XBPS_TARGET_MACHINE" in
		arm*)
			ed config/nim.cfg <<-EDIT
				,s/^arm.linux.gcc.exe .*/arm.linux.gcc.exe = "$CC"/
				,s/^arm.linux.gcc.linkerexe .*/arm.linux.gcc.linkerexe = "$CC"/
				w
				q
			EDIT
			bin/nim c -d:release --os:linux --cpu:arm compiler/nim;;
	esac
}

do_install() {
	./koch install ${DESTDIR}/usr/lib

	if [ "$CROSS_BUILD" ]; then
		mv compiler/nim ${DESTDIR}/usr/lib/nim/bin/nim
	fi

	vmkdir usr/bin
	vmkdir usr/share/nim
	ln -sf /usr/lib/nim/bin/nim ${DESTDIR}/usr/bin/nim
	cp -r doc examples ${DESTDIR}/usr/lib/nim
	ln -sf /usr/lib/nim/doc ${DESTDIR}/usr/share/nim/doc
	ln -sf /usr/lib/nim/examples ${DESTDIR}/usr/share/nim/examples
	vlicense copying.txt
}
