# -*- 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       github 1.0
PortGroup       legacysupport 1.1

# Need getline(), strndup()
legacysupport.newest_darwin_requires_legacy 10

github.setup    rrthomas libpaper 2.2.6 v
revision        0
checksums       rmd160  38306fdd1811a65bde49a105355f5750809893e3 \
                sha256  500d39dc58768ee09688738c8b5bfe07640ba2fd6c25a6dc78810eb69c719e93 \
                size    1345476

github.tarball_from releases

categories      print
# libpaper is LGPLv2.1+, paperspecs is public domain
license         LGPL-2.1+ public-domain
maintainers     nomaintainer
description     A library providing routines for paper size management
long_description \
                The paper library and accompanying files are intended \
                to provide a simple way for applications to take \
                actions based on a system- or user-specified paper size.

subport libpaper-utils {
    revision    0
    # We introduce a subport for files with different licenses.
    # Including them in the 'libpaper' port would prevent the
    # distribution of MacPorts binary archives for some prominent
    # tools like Ghostscript or ImagicMagick.
    description         The executables of the libpaper package
    long_description    Provide the new 'paper' and deprecated 'paperconf' \
                        utility programs that come with the libpaper \
                        library. Both are used to print paper size \
                        information.
    # `paper` is GPL-3+, `paperconf` is GPL-2
    license             GPL-3+ GPL-2
}

configure.args  --enable-relocatable \
                --disable-silent-rules

# https://trac.macports.org/ticket/69112
platform darwin 8 {
    configure.args-replace \
                --enable-relocatable --disable-relocatable
}

if {${subport} eq ${name}} {
    test.run    yes
    test.target check

    post-destroot {
        # Using --enable-relocatable is unfortunately needed for the
        # tests to work, but we don't actually want to use rpath in the
        # installed library.
        system "install_name_tool -id \
                ${prefix}/lib/libpaper.2.dylib \
                ${destroot}${prefix}/lib/libpaper.2.dylib"
        # remove `paper` and `paperconf`
        delete "${destroot}${prefix}/bin"
        delete "${destroot}${prefix}/share/man/man1"
    }
} else {
    depends_lib-append  port:libpaper

    post-destroot {
        # https://trac.macports.org/ticket/69112
        foreach bin {paper paperconf} {
            system "install_name_tool -change @rpath/libpaper.2.dylib \
                ${prefix}/lib/libpaper.2.dylib \
                ${destroot}${prefix}/bin/$bin"
        }
        # remove library-related files (which are already present)
        delete "${destroot}${prefix}/etc"
        delete "${destroot}${prefix}/include"
        delete "${destroot}${prefix}/lib"
        delete "${destroot}${prefix}/share/doc/libpaper"
        delete "${destroot}${prefix}/share/man/man5"
    }
}
