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

PortSystem              1.0

# from the README:
#    For 10.6 and later, universal builds are not supported.
PortGroup               muniversal 1.0

name                    chicken
version                 5.4.0
revision                0
categories              lang scheme
license                 BSD public-domain
maintainers             nomaintainer
description             Compiler for the Scheme programming language
long_description        Chicken produces portable, efficient C, supports \
                        almost all of the current Scheme language standard, \
                        the Revised5 Report on the Algorithmic Language \
                        Scheme (R5RS), and includes many enhancements and \
                        extensions.
homepage                http://www.call-cc.org/

set branch [join [lrange [split ${version} .] 0 2] .]
master_sites            http://code.call-cc.org/releases/${branch}

checksums               rmd160  d147fb71effeabe7f7307aac0c222a2621f86342 \
                        sha256  3c5d4aa61c1167bf6d9bf9eaf891da7630ba9f5f3c15bf09515a7039bfcdec5f \
                        size    4109135

use_configure           no

# Upstream explicitly requires GNU make.
build.type              gnu
build.args              C_COMPILER=${configure.cc} \
                        CXX_COMPILER=${configure.cxx} \
                        PLATFORM=macosx \
                        PREFIX=${prefix}
# Upstream does not support parallel builds.
use_parallel_build      no

# Correctly identify selected arch(s) to build system.
array set archs {ppc ppc.darwin ppc64 ppc.darwin i386 x86 x86_64 x86-64}
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_args(${arch}) \
            ARCH=$archs(${configure.build_arch})
    }
} else {
    if {[info exists archs(${configure.build_arch})]} {
        build.args-append \
            ARCH=$archs(${configure.build_arch})
    }
}

# Pass in correct arch and SDK flags.
set cflags ""
set ldflags ""
if {${configure.sdkroot} != ""} {
    set cflags  "${cflags}  -isysroot ${configure.sdkroot}"
    set ldflags "${ldflags} -Wl,-syslibroot,${configure.sdkroot}"
}
if {${universal_possible} && [variant_isset universal]} {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_args(${arch}) \
            CFLAGS='${cflags}   -arch ${arch}' \
            LDFLAGS='${ldflags} -arch ${arch}'
    }
} else {
    build.args-append \
        CFLAGS="${cflags}   -arch ${configure.build_arch}" \
        LDFLAGS="${ldflags} -arch ${configure.build_arch}"
}

destroot.args           PLATFORM=macosx \
                        PREFIX=${prefix}

test.run                yes
test.target             PLATFORM=macosx check

livecheck.type          regex
livecheck.url           http://code.call-cc.org/releases/current/
livecheck.regex         {chicken-([0-9.]+)\.tar\.gz}
