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

name                nspr
version             4.39
revision            0

categories          devel
maintainers         nomaintainer
license             {MPL-1.1 GPL-2+ LGPL-2.1+}

description         A platform-neutral API for system level and libc like functions.
long_description    {*}${description}

homepage            https://www.mozilla.org/projects/nspr
master_sites        https://ftp.mozilla.org/pub/nspr/releases/v${version}/src/

checksums           rmd160  ba55a6362137757084d14f6084e9a1df46655635 \
                    sha256  bbd02ee87a55676063a63e5bc819e0227de2666b47307b2a0134414cdf42368e \
                    size    1014093

worksrcdir          ${worksrcdir}/nspr

post-patch {
    reinplace "s:@LDFLAGS@:${configure.ldflags}:" \
        ${worksrcpath}/config/nspr-config.in
    reinplace "s|@executable_path|${prefix}/lib/nspr|g" \
        ${worksrcpath}/configure
}

configure.args \
    --disable-debug \
    --enable-optimize='${configure.optflags}' \
    --libdir=${prefix}/lib/nspr

platform darwin 9 {
    if {${build_arch} eq "ppc" || ${build_arch} eq "ppc64"} {
    # We need to enable missing ppc64 atomics
    post-extract {
        copy ${worksrcpath}/pr/src/md/unix/os_Darwin_ppc.s ${worksrcpath}/pr/src/md/unix/os_Darwin_ppc64.s
        }
    patchfiles-append      patch-darwin-ppc64.diff
    }
}

platform darwin 10 {
    if {${build_arch} eq "ppc"} {
    # Otherwise Intel flags are used on Rosetta: https://trac.macports.org/ticket/64900
        configure.args-append --build=powerpc-apple-darwin${os.major}
    }
}

if {(!${universal_possible} || ![variant_isset universal]) && ${configure.build_arch} in [list arm64 ppc64 x86_64]} {
    configure.args-append --enable-64bit
}

set merger_configure_args(arm64)  "--enable-64bit"
set merger_configure_args(ppc64)  "--enable-64bit"
set merger_configure_args(x86_64) "--enable-64bit"

variant debug description "build with debugging symbols" {
    configure.args-delete   --disable-debug \
                            --enable-optimize='${configure.optflags}'

    configure.args-append   --enable-debug='-ggdb3' \
                            --disable-optimize

    configure.cflags ""
}

post-destroot {
    file mkdir ${destroot}${prefix}/lib/pkgconfig
    copy ${filespath}/nspr.pc ${destroot}${prefix}/lib/pkgconfig
    reinplace "s|@@prefix@@|${prefix}|" ${destroot}${prefix}/lib/pkgconfig/nspr.pc
    set mylibs [exec ${destroot}${prefix}/bin/nspr-config --libs]
    set mycflags [exec ${destroot}${prefix}/bin/nspr-config --cflags]
    set myversion [exec ${destroot}${prefix}/bin/nspr-config --version]
    reinplace "s|@@FULL_NSPR_LIBS@@|${mylibs}|" ${destroot}${prefix}/lib/pkgconfig/nspr.pc
    reinplace "s|@@FULL_NSPR_CFLAGS@@|${mycflags}|" ${destroot}${prefix}/lib/pkgconfig/nspr.pc
    reinplace "s|@@NSPR_VERSION@@|${myversion}|" ${destroot}${prefix}/lib/pkgconfig/nspr.pc
}

livecheck.type      regex
#livecheck.url   [lindex ${master_sites} 0]
livecheck.url       https://ftp.mozilla.org/pub/nspr/releases/
livecheck.regex     "v(\\d+(?:\\.\\d+)*)"
