# $Id: Portfile 80278 2011-07-08 14:15:13Z jmr@macports.org $

PortSystem		1.0

name			squeak
version			3.9
revision                1
categories		lang squeak
maintainers		nomaintainer
description		Full, portable, Smalltalk-80 system
long_description	\
 	Squeak is a full-featured implementation of the Smalltalk programming \
	language and environment based on (and largely compatible with) the \
	original Smalltalk-80 system.  Squeak has very powerful 2- and 3-D \
	graphics, sound, video, MIDI, animation and other multimedia \
	capabilities -- and one of the most impressive development \
	environments ever created.  It also includes a customisable framework \
	for creating dynamic HTTP servers and interactively extensible Web \
	sites.  The entire Squeak system is open source software, distributed \
	freely with a liberal license.
platforms		darwin
homepage		http://www.squeak.org

set squeak_vm_version	3.9-8
set squeak_img_version	3.9
set squeak_short_vrsn	39
set squeak_patch_no	7067
set squeak_vm_src	Squeak-${squeak_vm_version}.src.tar
set squeak_img_name	Squeak${squeak_img_version}-final-${squeak_patch_no}
set squeak_img		${squeak_img_name}.image
set squeak_img_changes	${squeak_img_name}.changes
set squeak_img_src	${squeak_img_name}.zip

master_sites		http://www.squeakvm.org/unix/release/ \
			ftp://ftp.squeak.org/3.8/unix-linux \
                        ftp://ftp.squeak.org/${squeak_img_version}/

distname		Squeak-${squeak_img_version}
distfiles		${squeak_vm_src}.gz ${squeak_img_src}

checksums		${squeak_vm_src}.gz md5 645ef7e321c61601c9c70d94fa9417e4 \
			${squeak_img_src} md5 30d991c418be1cd9c5d05fb87dea2f19

extract.only		${squeak_vm_src}.gz
post-extract {
	system		"cd ${workpath} && mv Squeak-${squeak_vm_version} Squeak-${squeak_img_version}"
	file mkdir	${worksrcpath}/build
	# should do that but requires to rerun autoconf, I prefer to just patch inisqueak instead
	# reinplace	"s|imgdir=`eval echo \${libdir}/squeak`|imgdir=`eval echo \${datadir}`|" ${worksrcpath}/platforms/unix/config/configure.ac
	# reinplace	"s|plgdir=`eval echo \${imgdir}/\${VM_VERSION}`|plgdir=`eval echo \${libdir}/squeak/\${VM_VERSION}|" ${worksrcpath}/platforms/unix/config/configure.ac
}

configure.cmd		../platforms/unix/config/configure
configure.dir		${worksrcpath}/build
configure.args		--libdir=${prefix}/lib \
			--mandir=${prefix}/share/man \
			--without-quartz --without-x

build.dir		${worksrcpath}/build
build.type		gnu

destroot.destdir	 ROOT=${destroot}

post-destroot {
	set unzip	"[binaryInPath "unzip"] -o"
	set gzip	"[binaryInPath "gzip"] -f"
	
	set datadir	${prefix}/share/squeak
	
	# Have inisqueak look at the right place
	reinplace	"s|MAJOR=3|MAJOR=${squeak_short_vrsn}|" ${worksrcpath}/build/inisqueak
	reinplace	"s|imgdir=${prefix}/lib/squeak|imgdir=${datadir}|" ${worksrcpath}/build/inisqueak

	# Install inisqueak
	xinstall	-m 755 ${worksrcpath}/build/inisqueak \
				${destroot}${prefix}/bin/
	
	# fix bad doc install path (should use --docdir or --datarootdir during configure)
	xinstall 	-d ${destroot}${datadir}
	move		${destroot}${prefix}/doc ${destroot}${prefix}/share
	
	# Recompress and install the default image
	system 		"cd ${worksrcpath} && ${unzip} ${distpath}/${squeak_img_src}"
	system		"cd ${worksrcpath} && ${gzip} ${squeak_img_name}/${squeak_img}"
	system		"cd ${worksrcpath} && ${gzip} ${squeak_img_name}/${squeak_img_changes}"
	xinstall 	-d ${destroot}${datadir}
	xinstall 	-m 644 ${worksrcpath}/${squeak_img_name}/${squeak_img}.gz \
				${destroot}${datadir}
	xinstall 	-m 644 ${worksrcpath}/${squeak_img_name}/${squeak_img_changes}.gz \
				${destroot}${datadir}
	xinstall	-m 644 ${worksrcpath}/${squeak_img_name}/WelcomeSqueak${squeak_short_vrsn} \
				${destroot}${datadir}
	xinstall	-m 644 ${worksrcpath}/${squeak_img_name}/SqueakV${squeak_short_vrsn}.sources \
				${destroot}${datadir}

	# Link compressed image and changes
	system		"cd ${destroot}${datadir} && ln -s ${squeak_img}.gz squeak.image.gz"
	system		"cd ${destroot}${datadir} && ln -s ${squeak_img_changes}.gz squeak.changes.gz"
}

# "quartz" support uses NSQuickDrawView
if {${os.subplatform} == "macosx" && ((![variant_isset universal] && ![string match *64 $build_arch])
    || ([variant_isset universal] && ![string match *64* $universal_archs]))} {
    variant quartz	{
        configure.args-delete	--without-quartz
        configure.args-append	--with-quartz
    }

    default_variants	+quartz
}

variant x11 	{
	depends_lib-append      port:mesa port:xorg-libsm
	configure.args-delete	--without-x
	configure.args-append	--with-x
}

