# -*- 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
PortGroup           github 1.0
PortGroup           muniversal 1.0

github.setup        libffi libffi 3.6.0 v
revision            0
categories          devel
license             MIT
maintainers         {fwright.net:fw @fhgwright} openmaintainer

description         Portable foreign function interface library
long_description    The libffi library provides a portable, high level \
                    programming interface to various calling \
                    conventions. This allows a programmer to call any \
                    function specified by a call interface description \
                    at run-time.

homepage            https://www.sourceware.org/libffi
checksums           rmd160  30a0d01c94a0890253b00c3f8fc0f538e1153b10 \
                    sha256  31ff1fe32deaebfbb388727f32677bb254bf2a41382c51464c0b1837c9ee9828 \
                    size    1475449
github.tarball_from releases

# Upstream patch:
# https://github.com/libffi/libffi/commit/9ca53a19833dabaf80b73763638ab988bdbc42cc
patchfiles          patch-powerpc.diff

# Patches derived from MacPorts-enhanced GitHub fork at
# github.com/fhgwright/libffi
patchfiles-append   patch-sources.diff

# Don't use macports gcc or clang toolchains to build this due to dependency cycles
compiler.blacklist-append macports-*

# Since libffi doesn't use C++, the cxx_stdlib setting is irrelevant, and having it
# differ from the OS default stdlib constrains the compiler selection, possibly
# even resulting in a circular dependency. Hence, we clear the cxx_stdlib setting.

# Although libffi itself doesn't use C++, it provides support for the C++ ABI,
# and hence includes some tests written in C++. The stdlib selection is not
# expected to impact libffi's own behavior, and if it did there would need to
# be appropriate conditional code to accommodate the difference.

# On the relevant OS versions (currently 10.6-10.8), this assumption can be tested
# by running the applicable port commands with
# "configure.cxx_stdlib=libc++".

platform darwin {
    configure.cxx_stdlib
}

# Some warnings need to be disabled when building tests with gcc-4.2
if {[string match *gcc-4.2 ${configure.compiler}]} {
    test.env-append LIBFFI_TEST_OLDGCC=1
}

# The architecture-detection code in the configure script is based on the compiler's
# default architecture. We need to force this to match the target architecture to get
# the correct build. Merely providing the correct architecture options in xxFLAGS is insufficient.

if {[variant_isset universal]} {
    merger_arch_compiler yes
} else {
    configure.cc "${configure.cc} ${configure.cc_archflags}"
}

# There used to be a hack to force the use of the integrated assembler when building with clang.
# Not only is that no longer necessary, but it also causes slightly worse test results
# in at least one case.

array set merger_host {
    ppc64 powerpc-apple-darwin
}

lappend merger_dont_diff \
    ${prefix}/include/ffi.h \
    ${prefix}/include/ffitarget.h

depends_test-append port:dejagnu
test.run            yes
test.target         check

github.livecheck.regex {(\d+(?:\.\d+)+)}
