# -*- 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        expert-lsp expert 0.1.5 v
revision            0

categories          devel
description         Official Elixir Language Server Protocol implementation
long_description    {*}${description}
license             Apache-2
maintainers         {@lsdrfrx gmail.com:lsdrfrx} \
                    openmaintainer

checksums           rmd160  e4dbcd4ed31ca5f613e51af366ec2c08747663fa \
                    sha256  cbe134490b7bf52953807c82503bf109131f5e90d5c883cee3210c0a5e4f636b \
                    size    1447763
github.tarball_from archive

depends_build-append \
                    port:curl-ca-bundle \
                    port:elixir

use_configure       no

# https://github.com/expert-lsp/expert/issues/771
build {
    set build_env   "SSL_CERT_FILE=${prefix}/share/curl/curl-ca-bundle.crt \
                    HEX_CACERTS_PATH=${prefix}/share/curl/curl-ca-bundle.crt"
    system -W ${worksrcpath}/apps/engine "${build_env} ${prefix}/bin/mix deps.get"
    system -W ${worksrcpath}/apps/expert "${build_env} ${prefix}/bin/mix deps.get"
    system -W ${worksrcpath}/apps/expert "MIX_ENV=prod ${prefix}/bin/mix release plain --overwrite"
}

destroot {
    set relpath apps/expert/_build/prod/rel/plain

    xinstall -d ${destroot}${prefix}/libexec/expert
    copy ${worksrcpath}/${relpath} ${destroot}${prefix}/libexec/expert/plain

    xinstall -d ${destroot}${prefix}/bin
    ln -s ${prefix}/libexec/expert/plain/bin/start_expert \
        ${destroot}${prefix}/bin/expert
}
