# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4; -*-
# $Id: Portfile 48920 2009-03-31 11:28:38Z ryandesign@macports.org $
# vim: set fileencoding=utf-8 tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab filetype=tcl :

PortSystem				1.0

name					free42
version					1.4.44
revision				2
platforms				darwin
categories				emulators
maintainers				krischik:macports.org
description				a HP-42s Simulator
long_description		Free42 is a complete re-implementation of the HP-42S	\
						calculator and the HP-82240 printer. Free42 was written \
						from scratch, without using any HP code. You do not		\
						need any ROM images in order to use it, yet it is fully \
						HP-42S compatible.

homepage				http://free42.sourceforge.net/
master_sites			sourceforge

set prog				free42.${version}.tgz
set skin				Free42Skins.zip

distfiles				${prog} \
						${skin}

extract.only			${prog}

checksums				${prog} sha1 a116ab15c3d7faef0bfd9b1e59426964248b4242	\
						${skin} sha1 db0c327224fa163423003e287bee58e7f906f7b8

depends_lib				port:gtk2

worksrcdir				${name}
use_configure			no
use_parallel_build		no
build.dir				${worksrcpath}/gtk
build.target			free42bin
build.env-delete		BCD_MATH

post-extract {
	system "unzip -q ${distpath}/${skin} -d ${workpath}/skin"
}

platform darwin {
	build.env-append	LIBS="-lm -lXm -lXpm -lXp -lXmu -lXt -lX11"
	post-patch {
		reinplace "s|CXXFLAGS := |CXXFLAGS := -DNO_SINCOS |g" ${build.dir}/Makefile
	}
}

post-build {
	# The build phase builds the binary version.
	# Now build again to get the decimal version.
	build.target		clean free42dec
	build.env-append 	BCD_MATH=1
	command_exec build
}

destroot {
	xinstall -m 775 -d ${destroot}${prefix}/share/free42
	xinstall -m 775 -d ${destroot}${applications_dir}

	eval xinstall -m 444								\
		[glob ${workpath}/skin/*.gif]					\
		[glob ${workpath}/skin/*.layout]				\
		${workpath}/skin/README.txt						\
		${destroot}${prefix}/share/free42

	xinstall -m 775										\
		-W ${build.dir}									\
		free42bin										\
		free42dec										\
		${destroot}${prefix}/bin
}

platform macosx {
	post-destroot {
	xinstall -m 775 -d ${destroot}${applications_dir}
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Binary.app
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Binary.app/Contents
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Binary.app/Contents/MacOS
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Binary.app/Contents/Resources

	xinstall -m 644 -W ${filespath}																\
		Free42-Binary.app/Contents/Info.plist													\
		${destroot}${applications_dir}/Free42-Binary.app/Contents/Info.plist
	xinstall -m 644 -W ${filespath}																\
		Free42-Binary.app/Contents/Resources/Free42-Binary.icns									\
		${destroot}${applications_dir}/Free42-Binary.app/Contents/Resources/Free42-Binary.icns
	xinstall -m 755 -W ${filespath}																\
		Free42-Binary.app/Contents/MacOS/Free42-Binary.command									\
		${destroot}${applications_dir}/Free42-Binary.app/Contents/MacOS/Free42-Binary.command

	reinplace																					\
		s|@PREFIX@|${prefix}|g																	\
		${destroot}${applications_dir}/Free42-Binary.app/Contents/MacOS/Free42-Binary.command

	xinstall -m 775 -d ${destroot}${applications_dir}
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Decimal.app
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Decimal.app/Contents
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Decimal.app/Contents/MacOS
	xinstall -m 755 -d ${destroot}${applications_dir}/Free42-Decimal.app/Contents/Resources

	xinstall -m 644 -W ${filespath}																\
		Free42-Decimal.app/Contents/Info.plist													\
		${destroot}${applications_dir}/Free42-Decimal.app/Contents/Info.plist
	xinstall -m 644 -W ${filespath}																\
		Free42-Decimal.app/Contents/Resources/Free42-Decimal.icns								\
		${destroot}${applications_dir}/Free42-Decimal.app/Contents/Resources/Free42-Decimal.icns
	xinstall -m 755 -W ${filespath}																\
		Free42-Decimal.app/Contents/MacOS/Free42-Decimal.command								\
		${destroot}${applications_dir}/Free42-Decimal.app/Contents/MacOS/Free42-Decimal.command

	reinplace																					\
		s|@PREFIX@|${prefix}|g																	\
		${destroot}${applications_dir}/Free42-Decimal.app/Contents/MacOS/Free42-Decimal.command
	}
}

