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

PortSystem  1.0
PortGroup           muniversal 1.0

name                nspr
version             4.13
categories          devel
maintainers         nomaintainer
license             {MPL-1.1 GPL-2+ LGPL-2.1+}
platforms           darwin

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

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

checksums           rmd160  9769164662cb9349bf1c33e39e644767d1c767ae \
                    sha256  19c33334bb3fa6d24800ffa65d7d806c54ad5f8c3758a5c11352ad43212ab181

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

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       http://ftp.mozilla.org/pub/mozilla.org/nspr/releases/
livecheck.regex     "v(\\d+(?:\\.\\d+)*)"