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

PortSystem              1.0

name                    chicken
version                 4.8.0.2
categories              lang scheme
license                 BSD public-domain
maintainers             gmail.com:ivan.g.raikov
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-with-current-continuation.org/
platforms               darwin

# Source contains some assembly files for PPC, i386, and x86_64. Not
# sure if the PPC one can be assembled with "-arch ppc64".
supported_archs         ppc i386 x86_64

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

checksums               rmd160  7d92c10315f3f9c14003d6789a6ebdc4c0f78b25 \
                        sha256  bf933f8cc4586b8b468c9abb8ec079a9f109ea20b5f12a1af2776f694e14791d

# Allow build to pass in flags; enable universal builds with x86_64.
patchfiles              patch-Makefile.macosx.diff \
                        patch-rules.make.diff

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

variant universal {}

# Correctly identify selected arch(s) to build system.
array set archs {ppc ppc.darwin i386 x86 x86_64 x86-64}
if {[variant_isset universal]} {
    build.args-append   ARCH=universal \
                        UNIVERSAL_ARCHS="[string map [array get archs] \
                                            ${configure.universal_archs}]"
} elseif {[info exists archs(${configure.build_arch})]} {
    build.args-append   ARCH=$archs(${configure.build_arch})
}

# Pass in correct arch and SDK flags.
set cflags "[get_canonical_archflags cc]"
set ldflags "[get_canonical_archflags ld]"
if {${configure.sdkroot} != ""} {
    set cflags "${cflags} -isysroot ${configure.sdkroot}"
    set ldflags "${ldflags} -Wl,-syslibroot,${configure.sdkroot}"
}
build.args-append       CFLAGS="${cflags}" \
                        LDFLAGS="${ldflags}"

destroot.args           ${build.args}

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