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

name                        cliclick
categories                  sysutils
maintainers                 {ryandesign @ryandesign}
license                     BSD

description                 a utility for simulating mouse and keyboard events

long_description            ${name}, short for \"Command-Line Interface \
                            Click\", is a tiny shell/Terminal application that \
                            emulates mouse clicks (including double-clicks and \
                            Control-clicks) at arbitrary screen coordinates. \
                            It also lets you move the mouse, get the current \
                            mouse coordinates, press modifier keys, enter \
                            text, and more.

if {${os.platform} ne "darwin" || ${os.major} >= 19} {
    github.setup            BlueM cliclick 5.0.1
    revision                0
    checksums               rmd160  98c441982cf58fb9542545fd7724ac8d879fe34d \
                            sha256  798fb8b26f6a42b5002ca58e018b91f7677162c4f035b38aee8d905829db64a7 \
                            size    36195
    github.tarball_from     archive

    # https://github.com/BlueM/cliclick/issues/178
    if {${os.platform} eq "darwin" && [vercmp ${macosx_deployment_target} >= 15.0]} {
        macosx_deployment_target 14.0
    }

    if {${os.platform} eq "darwin" && ${os.major} >= 21} {
        # There is no /usr/bin/php anymore.
        set php             php83
        depends_build-append \
                            port:${php}
        post-patch {
            reinplace "s|^#!/usr/bin/php|#!${prefix}/bin/${php} --no-php-ini|" ${worksrcpath}/generate-characterinfo.php
        }
    }
} else {
    github.setup            BlueM cliclick 4.0.1
    revision                1
    checksums               rmd160  c79e26f413cb829c49e92cf45a5cab2042bd99dd \
                            sha256  c218b3356a804d768d5f074fc64eb1ff6842083bf476a80b363d95211deff59f \
                            size    35710

    patchfiles-append       32-bit.patch \
                            c89.patch \
                            fix-comments.patch \
                            implicit-conversion.patch \
                            incompatible-types.patch \
                            legacy.patch
}

if {${os.major} < 9} {
    known_fail              yes
    pre-fetch {
        ui_error "${name} @${version} requires Mac OS X 10.5 or greater."
        return -code error "incompatible Mac OS X version"
    }
} elseif {${os.major} < 13} {
    # https://github.com/BlueM/cliclick/issues/81
    notes-append "
${name} @${version} officially supports OS X 10.9 and later. Support\
for earlier systems is provided by MacPorts.
"
}

xcode.configuration         Release

destroot {
    xinstall ${worksrcpath}/build/${xcode.configuration}/${name} ${destroot}${prefix}/bin
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 -W ${worksrcpath} README.markdown ${destroot}${prefix}/share/doc/${name}
}
