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

name                        ccls
github.setup                MaskRay ccls 0.20261004
github.tarball_from         archive
revision                    0

categories                  devel
license                     Apache-2
maintainers                 {egorenar @egorenar} {mascguy @mascguy} openmaintainer

description                 C/C++/ObjC language server supporting cross references,\
                            hierarchies, completion and semantic highlighting
long_description            {*}${description}

checksums                   rmd160  bb2d1f2a615b1e138a5127e6128fe566193dddcc \
                            sha256  8e022718ac8d54aef36cd728a177ad036994d7abf535941b948ae14d1a9085dd \
                            size    168574

set ccls_default            ccls-clang-10
set select_path             ${filespath}/portselect

subport ccls_select {
    PortGroup               select 1.0
    PortGroup               stub 1.0

    supported_archs         noarch
    platforms               any

    post-destroot {
        select::install ${name} ${select_path}/base
        select::install ${name} ${select_path}/none
    }
}

foreach clang_v {10 11 12 13 14 15 16 17 18 19 20 21 22 23} {
    subport ccls-clang-${clang_v} {
        PortGroup             cmake 1.1
        PortGroup             legacysupport 1.1
        PortGroup             select 1.0

        select.group          ${name}
        select.file           ${select_path}/${subport}

        legacysupport.newest_darwin_requires_legacy \
                              15
        legacysupport.use_mp_libcxx \
                              yes

        compiler.whitelist    macports-clang-${clang_v}
        compiler.cxx_standard 2017
        cmake.set_cxx_standard yes

        # Reduce compilation warnings
        configure.cppflags-append \
                              -Wno-deprecated-declarations

        cmake.prefix_path-append \
                              ${prefix}/libexec/llvm-${clang_v}

        configure.args-append -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE \
                              -DUSE_SYSTEM_RAPIDJSON=ON \
                              -DCCLS_VERSION="${version}"

        depends_build-append \
                              port:pkgconfig

        depends_lib-append \
                              port:clang-${clang_v} \
                              port:libffi \
                              port:libxml2 \
                              port:ncurses \
                              port:rapidjson \
                              port:zlib

        depends_run-append \
                              port:ccls_select

        post-destroot {
            # Avoid conflicts between different clang builds
            move ${destroot}${prefix}/bin/ccls ${destroot}${prefix}/bin/${subport}
        }
    }
}

if {${subport} eq ${name}} {
    PortGroup               stub 1.0

    supported_archs         noarch
    platforms               any

    description             {*}${description} (meta port)

    depends_lib-append      port:${ccls_default}
} else {
    livecheck.type          none
}
