# -*- coding: utf-8; mode: tcl; tab-width: 4; truncate-lines: t; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem                  1.0

name                        sane-backends
version                     1.3.1
revision                    0
set upload_tag              83bdbb6c9a115184c2d48f1fdc6847db
checksums                   rmd160  1f62e34a17dc6446da1c13f295c55da44b4cf546 \
                            sha256  aa82f76f409b88f8ea9793d4771fce01254d9b6549ec84d6295b8f59a3879a0c \
                            size    7432184

categories                  graphics
# Some content is LGPL-2+ or public-domain, but the package as a whole is GPL-2+
license                     GPL-2+
maintainers                 nomaintainer
homepage                    http://www.sane-project.org/

description                 Backends for scanner access

long_description            These are the backends for the Scanner Access Now \
                            Easy project. They allow you to access various \
                            scanners either locally or remotely using saned.

master_sites                https://gitlab.com/sane-project/backends/uploads/${upload_tag}/

depends_build               path:bin/pkg-config:pkgconfig

depends_lib                 path:include/turbojpeg.h:libjpeg-turbo \
                            path:lib/pkgconfig/libusb-1.0.pc:libusb \
                            port:tiff \
                            port:zlib \
                            port:libxml2

# The installed sane-config uses pkg-config.
depends_run                 path:bin/pkg-config:pkgconfig

# magicolor backend requires libcrypto from openssl
depends_lib-append          path:lib/libcrypto.dylib:openssl

patchfiles                  patch-configure.diff \
                            send.patch

# The configure script checks for python 2.7 or later which fails on Mac OS X
# 10.6 which has python 2.6. Python isn't actually used when building from a
# release tarball. Python is only used to generate pixma_sane_options.h
# from pixma.c but release tarballs already have an up-to-date version.
post-extract {
    file mkdir ${workpath}/bin
    set fp [open ${workpath}/bin/python w]
    puts ${fp} {#!/bin/sh}
    puts ${fp} {echo disabled}
    close ${fp}
    file attributes ${workpath}/bin/python -permissions a+x
}
configure.env               PATH=${workpath}/bin:$env(PATH)
configure.python            python
post-configure {
    # Ensure that if in the future the build does actually try to use python it
    # will fail so that we can revisit this.
    set fp [open ${workpath}/bin/python a]
    puts ${fp} {exit 1}
    close ${fp}
}

compiler.c_standard         1999
# genesys backend now uses C++11
compiler.cxx_standard       2011

configure.cppflags-append   -fno-common

configure.args              --without-avahi \
                            --without-gphoto2 \
                            --without-libcurl \
                            --without-poppler-glib \
                            --without-snmp

post-configure {
    reinplace -E {s|-arch [a-z0-9_]+||g} \
        ${worksrcpath}/tools/sane-backends.pc
}

build.env-append LC_CTYPE=C

pre-destroot {
    xinstall -d -o root -g admin -m 0775 ${destroot}${prefix}/var/lock
}

destroot.keepdirs ${destroot}${prefix}/var/lock

default_variants            +avahi +snmp

variant no_local conflicts pnm gphoto2 description "turn off compilation of all backends but net" {
    depends_lib-delete      port:libusb-compat
    configure.args-append   --disable-local-backends --without-usb

    compiler.cxx_standard   1998
}

variant pnm conflicts no_local description "enable the pnm backend for testing frontends (possible security risk, see PROBLEMS file)" {
    configure.args-append   --enable-pnm-backend
}

variant gphoto2 conflicts no_local description "include the gphoto2 backend" {
    depends_lib-append      port:libexif \
                            port:libgphoto2 \
                            port:pkgconfig
    configure.args-delete   --without-gphoto2
    configure.args-append   --with-gphoto2
}

variant avahi description "enable Avahi support for saned and the net backend" {
    depends_lib-append      port:avahi
    configure.args-delete   --without-avahi
    configure.args-append   --with-avahi
}

variant escl requires avahi description "include the eSCL backend" {
    depends_lib-append      port:curl \
                            path:lib/pkgconfig/poppler.pc:poppler
    configure.args-delete   --without-libcurl \
                            --without-poppler-glib
    configure.args-append   --with-libcurl \
                            --with-poppler-glib
}

variant snmp description "enable automatic network discovery via SNMP" {
    depends_lib-append      port:net-snmp
    configure.args-delete   --without-snmp
    configure.args-append   --with-snmp
}

livecheck.type              regex
livecheck.url               https://gitlab.com/sane-project/backends/-/tags
livecheck.regex             "backends-(\\d+(?:\\.\\d+)*)${extract.suffix}"

notes "\
    Edit ${prefix}/etc/sane.d/dll.conf to enable only\
    specific backends for a noticeable performance gain."