# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4
# $Id: Portfile 62766 2010-01-16 19:55:53Z snc@macports.org $

PortSystem 1.0

name                    gambit-c
version                 4.6.0
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              lang scheme
platforms               darwin
maintainers             snc openmaintainer
description             Gambit-C is a fast Scheme implementation.
long_description        Gambit-C includes a Scheme interpreter and a Scheme \
                        compiler which can be used to build standalone \
                        executables. Because the compiler generates portable \
                        C code it is fairly easy to port to any platform \
                        with a decent C compiler. The thread system is very \
                        efficient and can support millions of concurrent \
                        processes. \
                        \
                        The Gambit-C system conforms to the R4RS, R5RS and \
                        IEEE Scheme standards. The full numeric tower is \
                        implemented, including: infinite precision integers \
                        (bignums), rationals, inexact reals (floating point \
                        numbers), and complex numbers.

homepage                http://dynamo.iro.umontreal.ca/~gambit/wiki/index.php/Main_Page
master_sites            http://www.iro.umontreal.ca/~gambit/download/gambit/v${branch}/source/
distname                gambc-v[strsed ${version} {g/\./_/}]
extract.suffix          .tgz
checksums           md5     4f0e8b3e90a96f2203cbaf1e1cc1388a \
                    sha1    c95dd64aa917ea5b07403c3a77536b07413f38d9 \
                    rmd160  90d73552123b3c9380afbbe3e6c8f1496ba60103

configure.args          --infodir=${prefix}/share/info \
                        --libdir=${prefix}/lib/gambit-c \
                        --enable-single-host \
                        --docdir=${prefix}/share/doc

# gsc conficts with a binary installed by Ghostscript. Recommended
# option (based on mailing list posts from Arch Linux and FreeBSD
# projects) is to rename gsc to gambit-gsc
set gsc "gambit-gsc"
set gsi "gambit-gsi"

post-extract {
    # Get rid of the incompatible version-specific installation structure
    reinplace "s|PACKAGE_SUBDIR=\"/${version}\"|PACKAGE_SUBDIR=\"\"|g" ${worksrcpath}/configure.ac
    reinplace "s|&& \$(LN_S) \.\$(PACKAGE_SUBDIR) current||g" ${worksrcpath}/makefile.in
    reinplace "s|rm -f \$(prefix)/current \$(prefix)/current.lnk||g" ${worksrcpath}/makefile.in
    reinplace "s|.B gsc|.B ${gsc}|g" ${worksrcpath}/doc/gsi.1

    # Fix target paths since the configure options are not properly used in the makefiles
    foreach makefile [exec find ${worksrcpath} -name makefile.in] {
        reinplace "s|\$(prefix)\$(PACKAGE_SUBDIR)|\$(DESTDIR)\$(prefix)|g" $makefile
        reinplace "s|\$(prefix)/info|\$(prefix)/share/info|g" $makefile
        reinplace "s|\$(prefix)/doc|\$(prefix)/share/doc/gambit-c|g" $makefile
        reinplace "s|\$(prefix)/lib|\$(prefix)/lib/gambit-c|g" $makefile
        reinplace "s|\$(prefix)/syntax-case\.scm|\$(prefix)/lib/gambit-c/syntax-case\.scm|g" $makefile
    }
}

post-destroot {
    file rename "${destroot}${prefix}/bin/gsc" "${destroot}${prefix}/bin/${gsc}"
    file delete "${destroot}${prefix}/bin/gsc-script"
    ln -s "${gsc}" "${destroot}${prefix}/bin/gsc-script"
    # Create a matching link for gambit-gsi for symmetry, even though the
    # original gsi binary doesn't conflict and isn't being removed.
    ln -s "gsi" "${destroot}${prefix}/bin/${gsi}"
}

variant optimized description "Use expensive GCC optimizations to improve speed and compactness" {
    configure.args-append --enable-gcc-opts
}

variant profile description "Enable profiling" {
    configure.args-append --enable-profile
}

livecheck.type      regex
livecheck.regex     (\\d+\\.\\d+\\.\\d+)
livecheck.url       ${homepage}
