# -*- 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.2.1
revision                    1
set upload_tag              110fc43336d0fb5e514f1fdc7360dd87
categories                  graphics
platforms                   darwin
# 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}/

checksums                   rmd160  8f468934284f31ea033869c79635b473c957fd22 \
                            sha256  f832395efcb90bb5ea8acd367a820c393dda7e0dd578b16f48928b8f5bdd0524 \
                            size    7308040

depends_build               port:pkgconfig

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

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

patchfiles                  patch-configure.diff \
                            patch-frontend-scanimage.c.diff

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

use_parallel_build          no

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
}

# This project uses u_long *everywhere* and doesn't bother including sys/types.h
configure.cppflags-append   -include sys/types.h

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."
