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

github.setup        tibirna qgit 2.13 qgit-
revision            0
categories          devel aqua
license             GPL-2
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Qt graphical interface to git repositories
long_description    {*}${description}

checksums           rmd160  3b625853fda0db4c58cb92c087168ae68af3e66e \
                    sha256  9fa64b011963b7b876b8634b140ec5339a81a422317df71b619fcee5740a364a \
                    size    1106606
github.tarball_from archive

if {${os.platform} eq "darwin" && ${os.major} < 22} {
    PortGroup       qt4 1.0

    # FIXME: scrolling in the app is wrong with qt4-mac-devel for some reason.
    depends_lib-append \
                    port:qt4-mac

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

}

patchfiles-append   patch_src_qgit.cpp.diff

# https://github.com/tibirna/qgit/pull/161
patchfiles-append   0001-Unbreak-build-with-Qt4.patch

# https://github.com/RJVB/macstrop/commit/27d936933c15eed3d66032e66c5e62eeb991da39
patchfiles-append   patch-nullptr-checks.diff

post-patch {
    reinplace "s,@PREFIX@,${prefix}," ${worksrcpath}/src/qgit.cpp
}

depends_run-append  path:bin/git:git

# ui files need this.
compiler.cxx_standard   2011

pre-configure {
    configure.pre_args-append   "QMAKE_CXX=${configure.cxx}" \
                                "QMAKE_CXXFLAGS=\"${configure.cxxflags} [get_canonical_archflags cxx]\"" \
                                "QMAKE_LINK=${configure.cxx}" \
                                "QMAKE_LINK_SHLIB=${configure.cxx}"
}

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
}
