# -*- 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
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

github.setup        input-leap input-leap e4c31b78edc646915147011205a546898c07fd1d
version             3.0.2-20250224
revision            0
categories          aqua net sysutils
platforms           {darwin >= 16}
license             {GPL-2 OpenSSLException}
maintainers         {iki.fi:koston @Koston-0xDEADBEEF} openmaintainer
description         share a keyboard and mouse over the network
long_description    ${name} shares a keyboard, mouse, and clipboard over the network.\
                    It supports multiple operating systems, including macOS,\
                    Linux, FreeBSD, OpenBSD, and Windows. It is a fork of barrier,\
                    which in turn is a fork of synergy.

checksums           rmd160  4763f4c218fbfbb5f0b142d397230fb8cdd2948e \
                    sha256  7e2e3b56a764e1768b0754a10fbb07caa80806094683f27476ce03a0398aabef \
                    size    1765873

patchfiles          fix-macos-scroll.patch \
                    map-altgr-to-altr.patch \
                    workaround-for-unsafe-threads.patch \
                    fix-non-gui-build.patch

patch.pre_args-replace  -p0 -p1

compiler.cxx_standard 2014

configure.args-append \
    -DINPUTLEAP_BUILD_TESTS=OFF \
    -DINPUTLEAP_VERSION_DESC=[regsub -- {.*-(.*)} ${version} {\1}]

if {[variant_isset debug]} {
    cmake.build_type    Debug
    configure.optflags  -O0
} else {
    cmake.build_type    RelWithDebInfo

    # Clear optflags for non-debug build; controlled by project
    configure.optflags
}

# The GUI build is messed up, uses a jank shellscript instead of cmake/make to
# build the macOS app bundle. This needs to be fixed upstream instead of worked
# around in the Portfile using ugly hacks. The GUI isn't required for anything,
# so leaving it broken doesn't compromise utility of the port.
#
#variant gui description {Build the configuration frontend (Qt6)} {}

# the gui requires metal
if { (${os.platform} eq "darwin" && ${os.major} < 16) || (![variant_isset gui]) } {
    configure.args-append \
        -DINPUTLEAP_BUILD_GUI=OFF
} else {

    PortGroup           qt6 1.0
    PortGroup           app 1.0

    qt6.depends_build \
        qttools

    app.create yes
    app.icon   dist/macos/bundle/InputLeap.app/Contents/Resources/InputLeap.icns
    app.retina yes
}

post-destroot {
    if {[variant_isset debug]} {
        # Save debug symbols for a debug build
        system -W ${destroot}${prefix} "find ./bin -type f -perm -111 -exec dsymutil {} +"
    }
    xinstall -m 0644 -W ${worksrcpath}/doc input-leapc.1 input-leaps.1 ${destroot}${prefix}/share/man/man1
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 -W ${worksrcpath}/doc/ \
            input-leap.conf.example \
            input-leap.conf.example-advanced \
            input-leap.conf.example-barebones \
            input-leap.conf.example-basic \
            ${destroot}${prefix}/share/doc/${name}
}

notes "
Input Leap requires \"Accessibility\" permissions. If you're upgrading from a
previous version, to get prompted for permissions you may need to first
*delete* existing input-leap permissions under Privacy and Security in System
Settings.
"
