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

name                qbs
version             2.6.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  6c414a20f490883fde5f87d981b21f16e4c3e93e \
                    sha256  9f7f1a1f7daaa4a39fe3604f1851d0e520b576ee7750a7f97bf9401bcb849f2d \
                    size    5733859

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

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
}
