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

if {${os.platform} eq "darwin" && ${os.major} < 15} {
    # New version requires Qt5 5.11+. To minimize number of versions, use Qt4 for all early systems.
    PortGroup       qt4 1.0

    github.setup    tibirna qgit 2.7 qgit-
    checksums       rmd160  82052f8402610065bf64bba38cc66d4fcbc14cf1 \
                    sha256  183d116b2fb38c6a76c99577f6cc86f0241f8b6bdc74042be4cb8631567f5e9e \
                    size    259624
    github.tarball_from archive

    patchfiles-append   patch-fix-comparison.diff

    pre-configure {
        configure.args-append \
                        CONFIG+=\"${qt_arch_types}\"
    }
} else {
    PortGroup       qt5 1.0

    # This one should be updated following upstream.
    github.setup    tibirna qgit 2.10 qgit-
    checksums       rmd160  84864b94ef24469f1c40b4e064d385a4653935f1 \
                    sha256  1fc74fbd25c8ccbee9f7d4a8817b0a82ffa5a3a281b324febe4e90ea7c721153 \
                    size    222077
    github.tarball_from archive

    # App icon seems corrupt on arm64: https://github.com/tibirna/qgit/issues/141
}

categories          devel
license             GPL-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         A Qt graphical interface to git repositories
long_description    {*}${description}

depends_lib-append  port:git

patchfiles-append   patch_src_qgit.cpp.diff

variant debug description "Build as both release and debug" {}

post-patch {
    # when not doing debug ...
    if {![variant_isset debug]} {
        # ... build just the release version
        reinplace "s@debug_and_release@release@" ${worksrcpath}/qgit.pro
        reinplace "s@debug_and_release@release@" ${worksrcpath}/src/src.pro
    }
    # nothing to do if +debug is specified; this is the default.
}

# --disable-dependency-tracking is not recognized.
configure.universal_args-delete --disable-dependency-tracking

configure.cmd       ${qt_qmake_cmd}
configure.pre_args
configure.post_args

destroot {
    xinstall -m 755 -d ${destroot}${qt_apps_dir}
    copy ${worksrcpath}/bin/qgit.app ${destroot}${qt_apps_dir}

    # Also link to ${prefix}/bin for easier access from the command line
    # Especially useful since qgit is supposed to be started from
    # the GIT repository location.
    ln -s ${qt_apps_dir}/qgit.app/Contents/MacOS/qgit ${destroot}${prefix}/bin
}