# -*- 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       cmake 1.1

github.setup    pdewacht brlaser 6 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision        0
categories      print
license         GPL-2+
maintainers     nomaintainer
description     Driver for Brother laser printers

long_description \
    brlaser is an open-source driver for Brother-branded monochrome laser \
    printers, useful on systems where the proprietary driver is not \
    available.

notes "
    **************************************************************************
    brlaser has installed a collection of PostScript Printer Description (PPD)
    files to the following directory:

      ${prefix}/share/cups/model

    Each file corresponds to a particular Brother laser printer model. (In many
    cases, choosing an incorrect PPD file will still print correctly.)

    To install a printer, plug in your printer and open the Print & Fax pane
    in System Preferences. Click the + sign to add a printer, then locate the
    Use (or Print Using) button and choose Other. Navigate to the PPD file
    corresponding to your printer to install it.

    For example, the PPD file for a Brother HL-L2300D can be found here:

      ${prefix}/share/cups/model/brl2300d.ppd

    The brlaser MacPorts package must remain installed on the system in order
    to print to any printers added in this way.

    *************************************************************************"

checksums       rmd160 829cf057ed7e11abb42a79b2e6c631522539021c \
                sha256 d1b180b5e15eeb3d7236abdaab665f3a3ac8fc27d192ab4ad4ad250cc0520aa3 \
                size 22830

# /usr/bin/ppdc exists on 10.6 and later
if { ${os.platform} ne "darwin" || ${os.major} < 10 } {
    depends_build-append \
                port:cups-ppdc
}

patchfiles      patch-cups-1.1.diff \
                patch-tumble.diff \
                patch-absolute-filter-path.diff \
                patch-no-stack-protector.diff

if { ${os.platform} eq "darwin" && ${os.major} < 17 } {
    patchfiles-append patch-no-open_memstream.diff
}

compiler.cxx_standard   2011

configure.args-append -DCUPS_SERVER_BIN:FILEPATH=${prefix}/libexec/cups
configure.args-append -DCUPS_DATA_DIR:FILEPATH=${prefix}/share/cups

post-build {
    system -W ${workpath} "ppdc build/brlaser.drv -d build/ppd"
}

test.run yes
test.target check

destroot {
    xinstall -d ${destroot}${prefix}/libexec/cups/filter
    xinstall -m 0755 ${workpath}/build/rastertobrlaser \
        ${destroot}${prefix}/libexec/cups/filter

    xinstall -d ${destroot}${prefix}/share/cups/model
    xinstall -m 0644 {*}[glob ${workpath}/build/ppd/*.ppd] ${destroot}${prefix}/share/cups/model
}
