# $Id: Portfile 68599 2010-06-07 16:22:24Z jmr@macports.org $

PortSystem 1.0
name		ccl
version		1.5
revision	0
set shortversion	${version}
categories	lang
maintainers	gwright
platforms	darwin
description	The Clozure Common Lisp Implementation
long_description \
	Clozure CL is an open source Common Lisp implementation.	\
	Clozure CL used to be called OpenMCL. It is also sometimes	\
	called CCL. You will see the three names being used interchangeably. 

homepage	http://trac.clozure.com/openmcl

fetch.type	svn
worksrcdir	ccl

use_configure	no

platform darwin i386 {
	svn.url	http://svn.clozure.com/publicsvn/openmcl/release/${shortversion}/darwinx86/ccl
	global bootimg
	global ccl_script

	if { ${configure.build_arch} == "x86_64" } {
		set bootimg dx86cl64
		set ccl_script ccl64
	} elseif { ${configure.build_arch} == "i386" } {
		set bootimg dx86cl
		set ccl_script ccl
	} else {
	    pre-fetch {
		    return -code error "architecture ${configure.build_arch} is not supported by ${name}"
		}
	}
}

platform darwin powerpc {
	svn.url	http://svn.clozure.com/publicsvn/openmcl/release/${shortversion}/darwinppc/ccl
	global bootimg
	global ccl_script

	if { ${configure.build_arch} == "ppc64" } {
		set bootimg dppccl64
		set ccl_script ccl64
	} elseif { ${configure.build_arch} == "ppc" } {
		set bootimg dppccl
		set ccl_script ccl
	} else {
	    pre-fetch {
		    return -code error "architecture ${configure.build_arch} is not supported by ${name}"
		}
	}
}

build		{
		  system "cd ${worksrcpath} && echo '(ccl::rebuild-ccl :full t)' | ./${bootimg} --batch"
		}

set prefixpath  \\\"[regsub -all / [strsed ${prefix}/share/asdf-install {g/^\///}] "\\\" \\\""]\\\"

destroot	{
		  file mkdir ${destroot}/${prefix}/share/${name}/${shortversion}
		  system "cd ${worksrcpath} && tar cf - . | ( cd ${destroot}/${prefix}/share/${name}/${shortversion} && tar xf -)"
		  reinplace "s|/usr/local/src/ccl|${prefix}/share/${name}/${shortversion}|" \
		  ${workpath}/ccl/scripts/${ccl_script}
		  system "chmod +x ${workpath}/ccl/scripts/${ccl_script}"
		  file copy ${workpath}/ccl/scripts/${ccl_script} ${destroot}/${prefix}/bin
		  reinplace "s|\"usr\" \"local\" \"asdf-install\")))))|${prefixpath})))))|" \
		  ${destroot}/${prefix}/share/${name}/${shortversion}/tools/asdf-install/installer.lisp
		}

post-activate	{
		  # Prepare asdf install folders and so forth.
                  file mkdir ${prefix}/share/asdf-install
                  system "chgrp admin ${prefix}/share/asdf-install"
                  system "chmod g+w ${prefix}/share/asdf-install"
		}

