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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup    OpenPrinting cups 2.4.2 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
name            cups-ppdc
categories      print textproc
license         Apache-2
maintainers     nomaintainer
description     Compiler for PostScript Printer Description (PPD) files
long_description \
    cups-ppdc is a collection of utilities taken from the Common UNIX Printing System (CUPS) \
    for working with PostScript Printer Description (PPD) files\; \
    PPD files can be used to set up a printer when proprietary drivers are not available. \
    See the ppdcfile(5) man page for information on the PPD file format.

checksums       rmd160  a478c8491061a4a57b2517ebb58cf5f078b246dd \
                sha256  1d81213edf70ae2bab9a994a572c0b7898ae6386f75bdebec4a7610e8ddb8089 \
                size    8173291

patchfiles      patch-static-targets.diff \
                patch-cups-getifaddrs.diff

platform darwin 8 {
    patchfiles-append \
                patch-cups-transcode-iconv.diff
}

# Until patch-cups-network.diff and patch-cups-compiler.diff are merged
use_autoconf    yes

configure.args  --disable-gssapi \
                --disable-shared \
                --without-dnssd \
                --without-ondemand \
                --without-tls \
                --with-bundledir=""
# code signing is broken on Snow Leopard - "sign" with /usr/bin/true
configure.env-append CODE_SIGN=/usr/bin/true
if {${os.platform} eq "darwin" && ${os.major} < 10} {
    configure.cflags-append -U__BLOCKS__
    configure.cxxflags-append -U__BLOCKS__
}

post-configure {
    platform darwin 8 {
        # res_init() symbol is found, but the prototype is never included due
        # to broken resolv.h on Tiger. Don't need networking so just tell the
        # build we've never heard of res_init().
        reinplace "s|#define HAVE_RES_INIT 1|/* #undef HAVE_RES_INIT */|" config.h
    }
}

build {
    system -W ${worksrcpath}/cups ${build.cmd}
    foreach tool {ppdc ppdi ppdpo ppdhtml ppdmerge} {
        system -W ${worksrcpath}/ppdc "${build.cmd} ${tool}-static"
    }
}

destroot {
    xinstall -d ${destroot}${prefix}/share/cups/ppdc

    xinstall -m 0644 -W ${worksrcpath}/data \
        font.defs media.defs raster.defs \
        epson.h hp.h label.h \
        ${destroot}${prefix}/share/cups/ppdc

    foreach tool {ppdc ppdi ppdpo ppdhtml ppdmerge} {
        xinstall -m 0755 ${worksrcpath}/ppdc/${tool}-static \
            ${destroot}${prefix}/bin
        file rename ${destroot}${prefix}/bin/${tool}-static \
            ${destroot}${prefix}/bin/${tool}
    }

    foreach tool {ppdc ppdi ppdpo ppdhtml ppdmerge} {
        xinstall -m 0644 ${worksrcpath}/man/${tool}.1 \
            ${destroot}${prefix}/share/man/man1
    }
    xinstall -m 0644 ${worksrcpath}/man/ppdcfile.5 \
        ${destroot}${prefix}/share/man/man5
}
