# Template file for 'flexprop'
pkgname=flexprop
version=5.1.1
revision=1
hostmakedepends="loadp2 which"
makedepends="tk-devel"
depends="loadp2 tk xterm"
short_desc="Simple GUI for creating applications on the Parallax Propeller 2"
maintainer="Jürgen Buchmüller <pullmoll@t-online.de>"
license="MIT"
homepage="https://github.com/totalspectrum/flexprop/"
distfiles="https://github.com/totalspectrum/${pkgname}/archive/v${version}.tar.gz"
checksum=65cf8b0cd04d439d3b694962579d2f44602cecfa7bd2dee24540be601cfa5f2a

do_build() {
	${CPP} -xc++ -I /usr/libexec/p2tools -DTCL_SRC < version.inp > src/version.tcl
}

do_install() {
	vinstall flexprop.tcl 755 usr/libexec/p2tools
	# Install a copy of the examples
	vcopy samples usr/libexec/p2tools
	# Let's use the system provided tcl/tk instead
	rm -rf src/tcl_library
	# No need for flexprop.c which is a Windows source file
	rm -f src/flexprop.c
	# Install a copy of the tcl/tk source scripts
	vcopy src usr/libexec/p2tools

	# Create a wrapper script to run flexprop
	vmkdir usr/bin
	cat >${DESTDIR}/usr/bin/flexprop <<EOF
#!/bin/bash
# Wrapper to run flexprop.tcl
if [ ! -d "\$HOME/.local/share/p2tools" ]; then
	echo "Installing a copy of the examples in \$HOME/.local/share/p2tools ..."
	mkdir -p \$HOME/.local/share/p2tools
	cp -a /usr/libexec/p2tools/samples \$HOME/.local/share/p2tools
fi
cd \$HOME/.local/share/p2tools
export SOURCE=/usr/libexec/p2tools/src
exec /usr/bin/wish /usr/libexec/p2tools/flexprop.tcl
EOF
	chmod 755 ${DESTDIR}/usr/bin/flexprop
	vlicense License.txt LICENSE
}
