PortSystem          1.0

name                cups-pdf
version             2.6.1
categories          print textproc
license             GPL-2+
maintainers         nomaintainer
description         Provides a print-to-PDF feature through CUPS
long_description \
   This software is designed to produce PDF files in a heterogeneous \
   network by providing a PDF printer on the central fileserver.

platforms           darwin

if {${os.platform} eq "darwin" && ${os.major} > 9} {
   set notes-darwinover9 "
   As of Mac OS X 10.6, cups can no longer write into user directories, so
   the output directory for ${name} has been updated to reflect this.
   ${name} will now write PDF files into ${prefix}/var/spool/cups-pdf/\$USER .
   You can create a symlink to this location from Desktop to have it behave as
   before:
      ln -s ${prefix}/var/spool/cups-pdf/\$USER ~/Desktop/cups-pdf

   If you are upgrading, your ${prefix}/etc/cups/cups-pdf.conf file will
   not be touched, and will probably need the Out parameter updated; see the
   ${prefix}/etc/cups/cups-pdf.conf.dist file for an example."
} else {
   set notes-darwinover9 ""
}

notes "
   *************************************************************
   If this is the first installation, there are a couple of items to do:
   -  First, symlinks in /usr are needed for CUPS to see cups-pdf, so run
      (it will run sudo so may ask for your password):
         ${prefix}/libexec/cups-pdf_links.sh
   -  Edit ${prefix}/etc/cups/cups-pdf.conf as needed
   -  Finally, tell cupsd to update (it may not be running on 10.5+):
         sudo killall -1 cupsd
   *************************************************************
   ${notes-darwinover9}"

homepage            https://www.cups-pdf.de/
master_sites        ${homepage}src/
distname            ${name}_${version}
worksrcdir          ${name}-${version}

checksums           md5     65f3fd525c4a9b1d736b91594b3166d5 \
                    sha1    6806f0004dfed5216625ab60cfe307ded23c2f6a \
                    rmd160  ebb7ed5192ff91201e2ef9d87d8f24c1c7a393cc

post-patch {
   reinplace "s|/etc|${prefix}/etc|" ${worksrcpath}/src/cups-pdf.h
   reinplace "s|/var/spool|${prefix}/var/spool|" \
      ${worksrcpath}/src/cups-pdf.h
   reinplace "s|/var/log|${prefix}/var/log|" ${worksrcpath}/src/cups-pdf.h
}

use_configure       no

build {
   system -W ${worksrcpath}/src "${configure.cc} ${configure.cflags} [get_canonical_archflags] -o cups-pdf cups-pdf.c"
}

destroot {
   xinstall -m 755 -d ${destroot}${prefix}/libexec/cups/backend \
      ${destroot}${prefix}/etc/cups ${destroot}${prefix}/share/cups/model \
      ${destroot}${prefix}/share/doc/${name} \
      ${destroot}${prefix}/var/spool/cups-pdf \
      ${destroot}${prefix}/var/log/cups
   xinstall -m 700 ${worksrcpath}/src/cups-pdf \
      ${destroot}${prefix}/libexec/cups/backend
   xinstall -m 644 ${worksrcpath}/extra/cups-pdf.conf \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   xinstall -m 644 ${worksrcpath}/extra/CUPS-PDF.ppd \
      ${destroot}${prefix}/share/cups/model
   xinstall -m 644 -W ${worksrcpath} README COPYING ChangeLog \
      ${destroot}${prefix}/share/doc/${name}

   # Some initial changes to the conf file
   if {${os.platform} eq "darwin" && ${os.major} > 9} {
      reinplace "s|#Out .*|Out ${prefix}/var/spool/cups-pdf/\${USER}/|" \
         ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   } else {
      reinplace "s|#Out .*|Out \${HOME}/Desktop/cups-pdf/|" \
         ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   }
   reinplace "s| /var/spool| ${prefix}/var/spool|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s| /var/log| ${prefix}/var/log|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#Cut .*|Cut 3|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#Label .*|Label 1|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#Log |Log |" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#Log |Log |" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#GhostScript .*|GhostScript /usr/bin/pstopdf|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#GSCall .*|GSCall %s %s -o %s %s|" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
   reinplace "s|#PDFVer .*|PDFVer |" \
      ${destroot}${prefix}/etc/cups/cups-pdf.conf.dist
}
destroot.keepdirs   ${destroot}${prefix}/var/spool/cups-pdf \
                    ${destroot}${prefix}/var/log/cups
post-destroot {
   xinstall -m 755 -W ${filespath} cups-pdf_links.sh \
      ${destroot}${prefix}/libexec/
   reinplace "s|@@PREFIX@@|${prefix}|g" \
      ${destroot}${prefix}/libexec/cups-pdf_links.sh
}

post-activate {
   if {![file exists ${prefix}/etc/cups/cups-pdf.conf]} {
      copy ${prefix}/etc/cups/cups-pdf.conf.dist \
         ${prefix}/etc/cups/cups-pdf.conf
   }
}

livecheck.type      regex
livecheck.url       http://www.cups-pdf.de/src
livecheck.regex     cups-pdf_(\\d(?:\\.\\d)+)${extract.suffix}
