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

name                rpm54
version             5.4.15
revision            9
set date            20140824
set branch          [join [lrange [split ${version} .] 0 1] .]
platforms           darwin freebsd linux
license             LGPL-2.1
categories          sysutils archivers
maintainers         nomaintainer
conflicts           rpm
description         The RPM package management system.
long_description    The RPM Package Manager (RPM) is a powerful command line driven \
                    package management system capable of installing, uninstalling, \
                    verifying, querying, and updating software packages. Each software \
                    package consists of an archive of files along with information about \
                    the package like its version, a description, etc.

# host rpm5.org no longer resolves, further updates unlikely
# use substitute homepage and macports_distfiles for master_sites
homepage            https://www.openhub.net/p/rpm5
master_sites        macports_distfiles:${name}
distname            rpm-${version}-0.${date}
extract.suffix      .src.rpm
checksums           rmd160  1b4af6831b864e485e6f9d9bee2c99f294e62cd8 \
                    sha256  d4ae5e9ed5df8ab9931b660f491418d20ab5c4d72eb17ed9055b80b71ef6c4ee \
                    size    15691310
worksrcdir          rpm-${version}

patchfiles          patch-rpmuuid.c.diff

depends_build       port:gawk \
                    port:pkgconfig

depends_lib         port:beecrypt \
                    port:db60 \
                    port:expat \
                    port:gettext \
                    port:libiconv \
                    port:libmagic \
                    port:neon \
                    port:ossp-uuid \
                    port:pcre \
                    port:popt \
                    port:python27 \
                    port:readline \
                    port:sqlite3 \
                    port:xar \
                    port:xz

depends_run         bin:bzip2:bzip2 \
                    bin:gzip:gzip \
                    bin:unzip:unzip \
                    path:lib/libssl.dylib:openssl

extract.cmd         ${filespath}/rpm2cpio.sh
extract.pre_args    ""
extract.post_args   "| cpio -dvim"

build.type          gnu

# use perl5 port group to create variants to match dependency ossp-uuid
# ensure ossp-uuid uses same variant

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}
require_active_variants ossp-uuid ${perl5.variant}

configure.args      --disable-nls \
                    --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man \
                    --sysconfdir=${prefix}/etc \
                    --with-beecrypt=external \
                    --with-db=external \
                    --with-libintl-prefix=${prefix} \
                    --with-libiconv-prefix=${prefix} \
                    --with-neon=external \
                    --with-path-cfg=${prefix}/etc/rpm \
                    --with-pcre=external \
                    --with-perl \
                    --with-popt=external \
                    --with-python=2.7 \
                    --with-sqlite \
                    --with-uuid=external \
                    --with-xar=external \
                    --with-xz=external \
                    --without-apidocs \
                    --without-javaglue \
                    --without-included-gettext \

configure.env       PERL=${perl5.bin} \
                    __PERL=${perl5.bin} \
                    __PYTHON=${prefix}/bin/python2.7

configure.args-append       --disable-openmp \
                            --with-lua=internal \
                            --with-syck=internal
configure.cppflags-append   -I${prefix}/include/ossp \
                            -I${prefix}/include/xar
configure.cppflags-append   -I${prefix}/include/db60
configure.ldflags-append    -L${prefix}/lib/db60

post-extract {
    system -W ${workpath} "${portutil::autoconf::tar_command} -xzf rpm-${version}.tar.gz"
}

post-patch {
    reinplace "s/, @ldaddr//" ${worksrcpath}/perl/Makefile.PL.in ; # remove -rpath flags
}

post-configure {
    reinplace "s/--tag=CC/--tag=CXX/" ${worksrcpath}/Makefile
    reinplace "s/--mode=link \$(CCLD)/--mode=link \$(CXX)/" ${worksrcpath}/Makefile
}

post-destroot {
    xinstall -d -m 755 ${destroot}${prefix}/etc/rpm
    system "${worksrcpath}/rpm --macros=${worksrcpath}/macros/macros --eval='%{_target_platform}' > ${destroot}${prefix}/etc/rpm/platform"
    system "${worksrcpath}/rpm --macros=${worksrcpath}/macros/macros --eval='noarch-%{_target_vendor}-%{_target_os}%{?_gnu}' >> ${destroot}${prefix}/etc/rpm/platform"

    delete [glob ${destroot}${prefix}/lib/perl5/*/*/*/auto/RPM/.packlist]
    delete [glob ${destroot}${prefix}/lib/perl5/*/*/perllocal.pod]

    # where the RPM database lives
    destroot.keepdirs ${destroot}${prefix}/etc/rpm \
        ${destroot}${prefix}/var/lib/rpm \
        ${destroot}${prefix}/var/spool/repackage \
        ${destroot}${prefix}/src/rpm/BUILD \
        ${destroot}${prefix}/src/rpm/RPMS \
        ${destroot}${prefix}/src/rpm/SOURCES \
        ${destroot}${prefix}/src/rpm/SPECS \
        ${destroot}${prefix}/src/rpm/SRPMS
}

platform darwin {
    configure.args-append \
                    --disable-aio \
                    --disable-optimized \
                    --disable-rpath \
                    --enable-broken-chown \
                    --with-glob

    # avoid bison-2.7 problems
    configure.env-append \
                    "YACC=/usr/bin/bison -y"

    post-destroot {
        # Mac OS X specific changes
    }
}

platform freebsd {
    post-destroot {
        # FreeBSD specific changes
        reinplace "s;/usr/bin/tar;/usr/local/bin/gtar;" ${destroot}${prefix}/lib/rpm/macros
        reinplace "s;/usr/bin/make;/usr/local/bin/gmake;" ${destroot}${prefix}/lib/rpm/macros
    }
}

platform linux {
    post-destroot {
        # Linux specific changes
    }
}

variant docs description "API documentation" {
    depends_build-append \
                    path:bin/doxygen:doxygen \
                    path:bin/dot:graphviz
    configure.args-replace \
                    --without-apidocs \
                    --with-apidocs
}


test.run            yes
test.target         check

# new releases unlikely
livecheck.type      none
