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

name                dpkg
version             1.21.2
revision            0

platforms           darwin
categories          sysutils archivers
license             GPL-2+
maintainers         nomaintainer
description         Debian package maintenance system
long_description    ${name} is the basis of the ${description}.

homepage            http://wiki.debian.org/Teams/Dpkg
master_sites        debian:d/${name}/
distname            ${name}_${version}
worksrcdir          ${name}-${version}

use_xz              yes

checksums           rmd160  2064bf98e1ff7db2b9a6b8e2a2fbe77e443b7165 \
                    sha256  b8fc67fca696c6bea2f40f737c80574d53384db25202f72effc7e4de4662e1ac \
                    size    5051548

perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

depends_build-append \
                    port:pkgconfig \
                    port:flex

# Use MacPorts versions explicitly
depends_lib-append  port:bzip2 \
                    path:libexec/coreutils/libstdbuf.so:coreutils \
                    port:gettext \
                    port:gnutar \
                    port:gzip \
                    port:gpatch \
                    port:libiconv \
                    port:ncurses \
                    port:xz \
                    port:zlib

depends_run-append  port:debianutils

configure.perl      ${perl5.bin}
configure.pkg_config \
                    ${prefix}/bin/pkg-config
configure.env-append \
                    TAR=${prefix}/bin/gnutar
configure.args-append \
                    --with-libintl-prefix=${prefix} \
                    --with-libiconv-prefix=${prefix} \
                    --with-admindir=${prefix}/var/db/${name} \
                    --with-logdir=${prefix}/var/log \
                    --mandir=${prefix}/share/man \
                    --with-liblzma \
                    --disable-linker-optimizations \
                    --disable-silent-rules \
                    --disable-start-stop-daemon \
                    --disable-dselect \
                    --disable-update-alternatives

compiler.blacklist-append cc gcc-3.3 gcc-4.0 apple-gcc-4.0

build.type          gnu

set vardpkg         ${destroot}${prefix}/var/db/${name}
destroot.keepdirs-append \
                    ${vardpkg} \
                    ${vardpkg}/updates \
                    ${vardpkg}/info \
                    ${destroot}${prefix}/var/log \
                    ${destroot}${prefix}/etc/${name}

patchfiles-append   patch-scripts_Dpkg_Source_Archive.pm.diff

use_autoreconf      yes
autoreconf.args     -fvi --warnings=all

pre-destroot {
    file mkdir ${destroot}${prefix}/share/doc/${name}
}

post-destroot {
    file mkdir ${vardpkg}
    file mkdir ${vardpkg}/updates
    file mkdir ${vardpkg}/info
    system "touch ${vardpkg}/available ${vardpkg}/status"
}

# This variant sometimes hangs while building...
variant docs description "Build documentation (warning: building documentation takes a long time)" {
    depends_build-append    path:bin/doxygen:doxygen \
                            path:bin/dot:graphviz \
                            port:fontconfig \
                            port:freefont-ttf

    set docdir              ${prefix}/share/doc/${name}
    configure.args-append   --docdir=${docdir} \
                            --htmldir=${docdir}/html \
                            --dvidir=${docdir}/dvi \
                            --pdfdir=${docdir}/pdf \
                            --psdir=${docdir}/ps

    build.target-append     doc

    pre-build {
        elevateToRoot "doxygen"
        system -W ${worksrcpath}/doc "${prefix}/bin/doxygen -u"
    }

    post-build {
        system -W ${worksrcpath}/doc "${prefix}/bin/doxygen"
        dropPrivileges
        set destroot_docdir ${destroot}${prefix}/share/doc/${name}
        xinstall -d ${destroot_docdir}
        copy ${worksrcpath}/doc/doc ${destroot_docdir}
        copy ${worksrcpath}/doc/html ${destroot_docdir}
        foreach docfile {coding-style.txt triggers.txt README.feature-removal-schedule frontend.txt README.api} {
            xinstall -m 644 ${worksrcpath}/doc/${docfile} ${destroot_docdir}
        }
    }
}

# Tests currently fail, this needs to be fixed eventually:
test.run            yes
test.target         check

#pre-test {
#    elevateToRoot "test"
#}
#post-test {
#    dropPrivileges
#}

livecheck.type      regex
livecheck.url       http://ftp.debian.org/debian/pool/main/d/${name}/
livecheck.regex     "${name}_(\\d+\\.\\d+(\\.\\d+)*)"
