# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 91878 2012-04-12 08:30:18Z easieste@macports.org $

PortSystem      1.0

name		    ccl
version         1.8
revision        0

set shortversion    ${version}

categories      lang
maintainers     gwright easieste openmaintainer
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/ccl

fetch.type      svn
worksrcdir      ccl
depends_build   port:docbook-xsl
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"
    system -W ${worksrcpath}/doc/src "make -f Makefile.macports"
}

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

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${destroot}${prefix}/share/examples
    xinstall -m 644 -W ${worksrcpath}/doc ccl-documentation.html LGPL LICENSE \
             release-notes-1.1.txt release-notes-1.2.txt release-notes.txt \
             ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/examples ${destroot}${prefix}/share/examples/${name}
}

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"
}

