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

github.setup        libffi libffi 3.4.6 v
revision            2

checksums           rmd160  8e927f6bc340564414a87cc5b6dffc9ce53eefd8 \
                    sha256  b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e \
                    size    1391684

github.tarball_from releases
categories          devel
license             MIT
maintainers         {fwright.net:fw @fhgwright} openmaintainer

description         A 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/


# Patches derived from MacPorts-enhanced GitHub fork at
# github.com/fhgwright/libffi

# patch-sources.diff: fixes for various issues.
#
# This includes one upstream fix for a build problem on Sequoia.  Although
# v3.4.7 includes this fix, it also has more test failures than v3.4.6,
# so for now we just cherry-pick the needed change.
#
# This diff is from v3.4.6 vs. macports-3.4.6r2.
#
patchfiles          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
}

# 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.
#
# This is a more general fix than the former fix for 10.6/ppc/Rosetta
#
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

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

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