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

name                qbs
version             3.1.1
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  ff30dd7b3ba5871c30bb0d0979151532cab48ee8 \
                    sha256  95e8de11cd66710975d4225d35ee01fd43691e4b65609399de367cb8a1df3af9 \
                    size    5803914

qt6.depends_lib qt5compat

compiler.cxx_standard 2017
# requires at least what qt64 requires
compiler.blacklist-append {clang < 1100}

# requires std::filesystem
legacysupport.newest_darwin_requires_legacy 18
legacysupport.use_mp_libcxx yes

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
patchfiles-append cmake.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}-typing_extensions \
                               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
}
