# -*- 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           cmake 1.1
PortGroup           qt6 1.0
PortGroup           compiler_blacklist_versions 1.0

name                qbs
version             2.4.2
revision            0

categories          devel
license             LGPL-2.1
maintainers         {@jobor qt.io:joerg.bornemann} openmaintainer
description         build tool that helps simplify the build process for \
                    developing projects across multiple platforms.
long_description    ${name} is {*}${description}

homepage            https://wiki.qt.io/Qbs
distname            qbs-src-${version}
master_sites        https://download.qt.io/official_releases/qbs/${version}/

checksums           rmd160  bf06c93fcd4b0ca2adfe37402e809ea2575d08b5 \
                    sha256  0e158433c57c8089e1bc15497eb121d3010f6bdbf5210c1f5cff5018da0e86d1 \
                    size    5718110

qt6.depends_lib qt5compat

compiler.cxx_standard 2017
# requires std::optional, above is not enough :(
# https://github.com/macports/macports-base/pull/179
compiler.blacklist-append {clang < 1001}

configure.args-append -DQBS_ENABLE_RPATH=NO

cmake.generator     Ninja

# set DYLD_LIBRARY_PATH to avoid
#    dyld: Library not loaded: ${prefix}/lib/libqbscore.1.dylib
#      Referenced from: ${worksrcpath}/bin/qbs
#      Reason: image not found
# set TMPDIR to avoid
#    SOFT ASSERT: job->state() == AbstractJob::StateRunning in api/project.cpp:153
patchfiles-append patch-environment.diff

livecheck.type      regex
livecheck.url       https://download.qt.io/official_releases/qbs/
livecheck.regex     {(\d+(?:\.\d+)+)/}

subport ${name}-docs {

    set py_ver          3.12
    set py_ver_nodot    [string map {. {}} ${py_ver}]

    platforms          any
    supported_archs    noarch
    qt6.depends_build qt5compat sqlite-plugin qttools
    depends_build-append       port:python${py_ver_nodot} \
                               port:py${py_ver_nodot}-beautifulsoup4 \
                               port:py${py_ver_nodot}-lxml

    # TODO: only HTML docs are installed, dunno how to run
    # `cmake --install .` twice
    configure.args-append -DQBS_INSTALL_HTML_DOCS=YES -DQBS_INSTALL_QCH_DOCS=Yes -DPython3_EXECUTABLE=${prefix}/bin/python${py_ver}
    build.target       qbs_docs

    destroot.pre_args  --install
    destroot.args      . --component qbs_docs
    destroot.target    ""
    destroot.cmd cmake
}
