# -*- 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 117042 2014-02-13 20:19:13Z ryandesign@macports.org $

PortSystem          1.0

name                swarm
version             2.4.1
revision            7
categories          science
maintainers         nomaintainer
license             GPL-2
description         Swarm is a platform for agent-based models (ABMs).
long_description    ${description}
homepage            http://www.swarm.org/
platforms           darwin
master_sites        http://ftp.swarm.org/pub/swarm/src/swarm/

checksums           sha1    7869b678a445c430a55b71e3631e5aa511d02d47 \
                    rmd160  f76274f48509ceb4d346c9724f6fd9070e42c6e2 \
                    sha256  04b78811235722c2da199a538ac4465aaf4030f1aaf8554b94785fc1482d2c95

depends_lib         port:blt \
                    port:tcl \
                    port:tk \
                    port:xpm \
                    port:libffi \
                    port:zlib \
                    port:libpng \
                    port:hdf5-18

# https://savannah.nongnu.org/bugs/?41491
# src/defobj/make-h2x needs GNU sed; causes build failure if only BSD sed is
# available. The path to gsed is baked into ${prefix}/bin/libtool-swarm.
depends_lib-append  port:gsed

universal_variant   no

patchfiles          patch-libpng-1.5.diff

post-patch {
    reinplace {s:-fgnu-runtime:-DH5_USE_16_API -fnested-functions -fgnu-runtime:g} \
        ${worksrcpath}/configure \
        ${worksrcpath}/libobjc/configure
}

#sendmsg.c:200:10: error: use of unknown builtin '__builtin_apply' [-Wimplicit-function-declaration]
#sendmsg.c:507:10: error: use of unknown builtin '__builtin_apply_args' [-Wimplicit-function-declaration]
#sendmsg.c:510:5: error: use of unknown builtin '__builtin_return' [-Wimplicit-function-declaration]
# Nested functions
# Buggy C++
compiler.blacklist  *clang*

configure.args      --with-x \
                    --x-include=${prefix}/include \
                    --x-lib=${prefix}/lib \
                    --with-tcl=${prefix}/lib \
                    --with-tk=${prefix}/lib

# Ensure MacPorts grep is not used, even if it is already installed, because
# its path would be baked into ${prefix}/bin/libtool-swarm.
configure.args-append ac_cv_path_GREP=/usr/bin/grep

# Fix build with Tcl 8.6+
configure.cppflags-append -DUSE_INTERP_RESULT

pre-configure {
    configure.args-append --with-ffidir=[glob ${prefix}/lib/libffi-*]

    if {[file exists /System/Library/Frameworks/JavaVM.framework]} {
        configure.args-append --with-jdkdir=/System/Library/Frameworks/JavaVM.framework
    }
}

# sed: RE error: illegal byte sequence
build.env           LANG=C

post-destroot {
    # http://trac.macports.org/ticket/34232
    file delete -force ${destroot}${prefix}/include
}
