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

name                Platypus
version             5.4.1
revision            0
license             GPL-2
categories          aqua devel
maintainers         {amake @amake} openmaintainer
conflicts           Platypus44
description         Program for creating application wrappers around scripts.

long_description    Platypus is a program for creating application \
    wrappers around scripts, i.e. creating Mac OS X applications that execute a \
    script they are bundled with. Scripts can thus be run transparently from \
    the graphical window environment without having to resort to using the \
    command line interface. It supports drag and drop on created apps, running \
    as root using Authentication Manager and more.

homepage            http://www.sveinbjorn.org/platypus/
master_sites        http://www.sveinbjorn.org/files/software/platypus/
distname            platypus${version}.src
use_zip             yes

checksums           md5     225a4064ba07f0e8e0943d9d18cf5fe7 \
                    sha1    2afec63a051ee2b1f4412a5ce699d2636178e2be \
                    rmd160  a2125465330db99c6fca7e1c616bff8f9eb33222 \
                    sha256  b2dc96707c4d34588b5d743d2a1a998f8935e3f7daf19b28ab804abb786fbcc4 \
                    size    26159125

if {${os.major} < 15} {
    known_fail      yes
    pre-fetch {
        return -code error "This version of ${name} is only for OS X 10.11 or later."
    }
}

supported_archs     x86_64 arm64

macosx_deployment_target 10.11

xcode.target        Platypus

universal_variant   no

worksrcdir          .

patchfiles          0001-Remove-install-CLI-tool.patch \
                    0002-Remove-Sparkle.patch \
                    0003-Remove-uninstall-feature.patch

patch.pre_args-replace  -p0 -p1

post-patch {
    reinplace "s|/usr/local|${prefix}|" ${worksrcpath}/CLT/man/platypus.1 ${worksrcpath}/Common.h
}

xcode.build.settings-append \
    -parallelizeTargets

# macOS 13/Xcode 14 seems to be requiring code signing
if {${os.major} >= 22} {
    xcode.build.settings-append \
        CODE_SIGN_IDENTITY=-
} else {
    xcode.build.settings-append \
        CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
}

destroot {
	copy "${build.dir}/build/${xcode.configuration}/${name}.app" \
		${destroot}${applications_dir}

    file copy ${worksrcpath}/Application/Resources/InstallCommandLineTool.sh ${worksrcpath}
    set cli_install_script ${worksrcpath}/InstallCommandLineTool.sh
    reinplace "s|^chown|#chown|g" ${cli_install_script}
    # The program dynamically replaces these template placeholders on invocation.
    # See Common.h and InstallCommandLineTool.sh
    reinplace "s|%%CMDLINE_PROGNAME_BUNDLE%%|platypus_clt.gz|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_SCRIPTEXEC_GZIP_NAME%%|ScriptExec.gz|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_MANPAGE_NAME%%|platypus.1.gz|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_NIB_NAME%%|MainMenu.nib|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_BIN_PATH%%|${destroot}${prefix}/bin|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_TOOL_PATH%%|${destroot}${prefix}/bin/platypus|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_SHARE_PATH%%|${destroot}${prefix}/share/platypus|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_MANDIR_PATH%%|${destroot}${prefix}/share/man/man1|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_MANPAGE_PATH%%|${destroot}${prefix}/share/man/man1/platypus.1.gz|g" ${cli_install_script}
    reinplace "s|%%CMDLINE_SCRIPT_EXEC_PATH%%|${destroot}${prefix}/share/platypus/ScriptExec|g" ${cli_install_script}

    system -W ${worksrcpath} "./InstallCommandLineTool.sh ${destroot}${applications_dir}/Platypus.app/Contents/Resources"
}

livecheck.type  regex
livecheck.url   ${homepage}
livecheck.regex "${name} (\\d+(?:\\.\\d+)*)"
