# -*- 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 54924 2009-08-04 18:41:22Z snc@macports.org $

PortSystem 1.0

name                    gambit-c
version                 4.4.4
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              lang scheme
platforms               darwin
maintainers             gmail.com:arto.bendiken
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://www.iro.umontreal.ca/~gambit/
master_sites            ${homepage}download/gambit/v${branch}/source/
distname                gambc-v[strsed ${version} {g/\./_/}]
extract.suffix          .tgz
checksums           md5     5fa55e7e7cb7a3f3b646786d6f5fc9f4 \
                    sha1    81a704d4c3b7c89e321c1a98ddaca4f7b77dde1f \
                    rmd160  f17010c79cfaef3a14f40b405f713c20a3f635a2

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

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

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

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
}

