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

# pdewacht/brlaser is unmaintained; Owl-Maintain is the fork other
# distributions have moved to.
github.setup    Owl-Maintain brlaser 6.2.8 v
github.tarball_from archive
# Upstream has both a branch and a tag named v${version}, so the default
# archive URL is ambiguous (https://trac.macports.org/ticket/70652).
github.master_sites ${github.homepage}/archive/refs/tags/${git.branch}
revision        0
categories      print
license         GPL-2+
maintainers     {@evanmiller} openmaintainer
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 c08061b1878131f3b65bb1557c96f3993dea0c21 \
                sha256 16dae855aa7fff0eef0c05398fab37678243d7d610fa5f9af0d3a2cc9bf08cb0 \
                size 29401

# /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-absolute-filter-path.diff \
                patch-no-stack-protector.diff \
                patch-density-default.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
}
