# -*- 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
PortGroup           github 1.0

github.setup        MacPass MacPass 0.8.1
revision            1
categories          security
platforms           darwin
license             GPL-3
maintainers         {@janosch mailbox.org:janosch1} openmaintainer
description         KeePass client for macOS
long_description    ${name} is a native macOS port of KeePass. Key features are automatic \
                    form filling and regex matching of window titles to detect the correct target application. \
                    Through the plugin MacPassHTTP, ${name} can also be used together with \
                    keepass browser extensions to integrate ${name} as a password database the browser can use.
homepage            https://macpassapp.org/

master_sites        ${github.homepage}/archive:macpass \
                    https://github.com/mstarke/DDHotKey/archive:ddhotkey
set ddhotkey_hash   a996a0a3980de926168df7c2f8b02a1231760561

distfiles           ${version}.tar.gz:macpass \
                    ${ddhotkey_hash}.tar.gz:ddhotkey

checksums           ${version}.tar.gz \
                    rmd160  07cd17c6c37bedd27879d6ad928778fc85b6499d \
                    sha256  41d66936aa48c5c17676a167b28275f1fb98b8110422055fd282f176d046e910 \
                    size    11046597 \
                    ${ddhotkey_hash}.tar.gz \
                    rmd160  12ce0935b45c9b8a1e258f267ff8d18f0429eed0 \
                    sha256  656d090cca863b236b7d319df4a5853b55ebf9af39a31a08cb471122c9bfbf56 \
                    size    27575

if {${os.platform} eq "darwin" && ${os.major} < 20} {
    known_fail yes
    pre-fetch {
        ui_error "${name} @${version} requires macOS 11 or greater"
        return -code error "incompatible OS X version"
    }
}

post-extract {
    file delete -force ${worksrcpath}/DDHotKey
    move ${workpath}/DDHotKey-${ddhotkey_hash} ${worksrcpath}/DDHotKey
}

post-patch {
    copy ${filespath}/get_commit_number.sh ${worksrcpath}
    reinplace "s|@VERSION@|${version}|g" ${worksrcpath}/get_commit_number.sh
    set build_number [exec /bin/sh ${worksrcpath}/get_commit_number.sh]0
    reinplace "s|\$\{git_count\}0|${build_number}|" ${worksrcpath}/MacPass.xcodeproj/project.pbxproj
}

depends_lib             port:KeePassKit \
                        port:HNHUi \
                        port:TransformerKit

patchfiles              patch-xcodeproj.diff \
                        patch-remove-sparkle-app.diff \
                        patch-remove-sparkle-pref.diff

xcode.target            MacPass
xcode.scheme            MacPass
xcode.configuration     Release

xcode.destroot.settings CODE_SIGN_IDENTITY=- \
                        CODE_SIGN_STYLE=Manual \
                        ENABLE_HARDENED_RUNTIME=NO \
                        FRAMEWORK_SEARCH_PATHS=${prefix}/Library/Frameworks

# xcode PortGroup sets the DerivedData to /var/root/... which is not writeable. This fixes it.
destroot.pre_args-append  -derivedDataPath ./DerivedData
destroot.args-append GCC_PREPROCESSOR_DEFINITIONS="NO_SPARKLE=TRUE"

# We skip the build phase because building will also be done in the destroot phase.
# See https://trac.macports.org/ticket/57137
build {}
