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

github.setup        OpenLightingProject ola 0.10.9
github.tarball_from releases
revision            1

categories          net comms
license             GPL-2+ LGPL-2.1+
maintainers         {pjnewman.co.uk:bugs @peternewman} \
                    openmaintainer

homepage            https://www.openlighting.org/ola/
description         open framework for DMX512 lighting control
long_description    The Open Lighting Architecture (OLA) provides a \
                    plug-in framework for distributing DMX512 control \
                    signals on Mac and Linux. It provides C++ and \
                    Python libraries which abstract away the \
                    underlying DMX over IP protocol or DMX interface.

checksums           rmd160  eb3f8f6d823b5a8ae85bece80580290f6a8feb68 \
                    sha256  44073698c147fe641507398253c2e52ff8dc7eac8606cbf286c29f37939a4ebf \
                    size    2578760

depends_build       port:pkgconfig
# temporary workaround (else configure fails)
depends_build-append \
                    port:cppunit
depends_lib         port:protobuf3-cpp
depends_test        port:cppunit

post-patch {
    # Work around compile error:
    #   cannot initialize a variable of type 'lo_blob' (aka
    #   'lo_blob_ *') with an lvalue of type 'lo_arg *'.
    # Reported upstream in
    # https://github.com/OpenLightingProject/ola/issues/1949.
    # The below fix was implemented as a part of
    # https://github.com/OpenLightingProject/ola/pull/1954.
    # The following statement will probably need to be removed when
    # updating this port to version 0.10.10.
    reinplace "s/lo_blob blob = argv/lo_blob blob = (lo_blob)argv/" \
        ${worksrcpath}/plugins/osc/OSCNode.cpp

    # Work around compile error:
    #   no matching function for call to 'lo_server_add_method'
    #   note: candidate function not viable: no known conversion from
    #   'int (const char *, const char *, lo_arg **, int, void *,
    #   void *)' to 'lo_method_handler' (aka 'int (*)(const char *,
    #   const char *, lo_arg **, int, lo_message_ *, void *)')
    #   for 4th argument
    # The below fix was also implemented as a part of
    # https://github.com/OpenLightingProject/ola/pull/1954.
    # The following statement will probably need to be removed when
    # updating this port to version 0.10.10.
    reinplace \
        "/int OSCDataHandler/,/OLA_DEBUG <</s/int argc, void \\*,/int argc, lo_message,/" \
        ${worksrcpath}/plugins/osc/OSCNode.cpp
}

use_autoreconf      yes

compiler.cxx_standard   2011

configure.args      --disable-fatal-warnings \
                    --disable-libftdi \
                    --disable-http \
                    --disable-libusb \
                    --disable-osc

variant python27 description {Enable the Python 2.7 API} {
    depends_lib-append      port:python27 port:py27-protobuf3
    configure.args-append   --enable-python-libs
    configure.python        ${prefix}/bin/python2.7
}

variant rdm_tests requires python27 description {Enable the RDM Tests} {
    depends_lib-append      port:py27-numpy
    configure.args-append   --enable-rdm-tests
}

variant http description {Build with embedded web server} {
    depends_lib-append      port:libmicrohttpd
    configure.args-delete   --disable-http
}

variant libftdi0 conflicts libftdi1 \
    description {Build with libftdi0 support} \
{
    depends_lib-append      port:libftdi0
    configure.args-delete   --disable-libftdi
}

variant libftdi1 conflicts libftdi0 \
    description {Build with libftdi1 support} \
{
    depends_lib-append      port:libftdi1
    configure.args-delete   --disable-libftdi
}

variant libusb description {Build with libusb support} {
    depends_lib-append      path:lib/pkgconfig/libusb-1.0.pc:libusb
    configure.args-delete   --disable-libusb
}

variant osc description {Build with OSC support} {
    depends_lib-append      port:liblo
    configure.args-delete   --disable-osc
}

default_variants    +http +libusb +osc +python27
if {![variant_isset libftdi0]} {
    default_variants-append +libftdi1
}

test.run            yes
test.target         check
