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

name                    libmacho
version                 949.0.1
subport ${name}-headers { }
categories              devel
maintainers             {jeremyhu @jeremyhu} openmaintainer
license                 APSL-2
description             libmacho is a library for managing mach-o files (parsing sections, etc)
long_description        {*}${description} \
                        It is included as part of the host libSystem on OS X, but this version \
                        may be needed for newer functionality.

homepage                https://opensource.apple.com/source/cctools/
master_sites            https://github.com/apple-oss-distributions/cctools/archive/

# handle stealth update; remove with next version change
dist_subdir             ${name}/${version}_1
distname                cctools-${version}
worksrcdir              cctools-${distname}

checksums               rmd160  54a8e318087547b827eee4e5dbb21a8f3956402f \
                        sha256  8b2d8dc371a57e42852fa6102efaf324ef004adf86072bf9957e2ac9005326c1 \
                        size    1967695

patchfiles              cctools-921-noavx512.patch \
                        cctools-949-libstuff-add-args-c.diff \
                        cctools-949-redo_prebinding-add-segg-addr-table-header.diff \
                        cctools-949-build-with-SDKs-older-than-1012.diff \
                        cctools-949-nm-allow-no-lto-support.diff \
                        cctools-949-write_object-fix.diff

platform darwin 8 {
    # https://trac.macports.org/ticket/57755
    patchfiles-append   patch-libmacho-no-xcrun-Tiger.diff
}

use_configure           no

if {${subport} eq "${name}-headers"} {
    supported_archs         noarch
    platforms               any
    build {}

    destroot.args           DSTROOT=${destroot}${prefix} RC_ProjectSourceVersion=${version}
    destroot.target         installhdrs

    post-destroot {
        file rename -force ${destroot}${prefix}/usr/include ${destroot}${prefix}/
        file delete -force ${destroot}${prefix}/usr
    }
    # Having the stdlib set to libc++ on 10.6 causes a macports-clang
    # compiler to be selected (which is a problem for bootstrapping).
    configure.cxx_stdlib
} elseif {${subport} eq "${name}"} {
    # Technically not needed, but subports will expect depending on libunwind to pull in the headers
    depends_lib-append port:libmacho-headers

    variant universal       {}
    if {${os.major} < 18 || ${os.major} >= 20} {
        default_variants +universal
    }

    build.dir               ${worksrcpath}/libmacho
    destroot.dir            ${build.dir}

    build.target            libmacho.a libmacho.dylib
    build.args \
        CC="${configure.cc}" \
        RC_CFLAGS="${configure.cflags} [get_canonical_archflags]" \
        RC_ARCHS="[get_canonical_archs]" \
        DEPENDENT_LIBS="" \
        RC_ProjectSourceVersion=${version} \
        INSTALL_NAME="${prefix}/lib/libmacho.1.dylib"

    destroot {
        xinstall -m 644 ${destroot.dir}/libmacho.a ${destroot}${prefix}/lib
        xinstall -m 755 ${destroot.dir}/libmacho.dylib ${destroot}${prefix}/lib/libmacho.1.dylib
        ln -s libmacho.1.dylib ${destroot}${prefix}/lib/libmacho.dylib
    }
}

livecheck.type          regex
livecheck.regex         "cctools-(\[\\d.\]+)"
