# -*- 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        nim-lang nimble 0.24.1 v
revision            0
categories          devel nim
license             BSD
maintainers         {@barracuda156 macos-powerpc.org:barracuda}
description         Package manager for the Nim programming language
long_description    Nimble is a package manager for the Nim programming language. \
                    It provides dependency management, package installation \
                    and building capabilities for Nim projects.
installs_libs       no

github.tarball_from archive

# Vendored dependencies (git submodules)
# These are commit hashes used in the v0.24.1 release:
# https://github.com/nim-lang/nimble/tree/a399f502dec7ffcd905c1cf54b13274ad990bada/vendor
set bearssl_hash    25197fec8a3988d1153be7a1a79890b70e69d6db
set bearsslc_hash   7bea48e5e850ab4cafbe68d3765cdaba13a86d6f
set checksums_hash  f8f6bd34bfa3fe12c64b919059ad856a96efcba0
set chronos_hash    bd92f8e089ccd391b9762b7035215bea2307dbc9
set httputils_hash  f142cb2e8bd812dd002a6493b6082827bb248592
set results_hash    b319652e98a198fa881ca70a76754c2dd6f09804
set sat_hash        e63eaea8baf00bed8bcd5a29ffd8823abb265b39
set stew_hash       83eb1157963b7f49351dbdd858355fa990bbe23c
set zippy_hash      bcb8c1e1be6abb0a0e35a3c6040cdd9391cc993f

master_sites-append https://github.com/status-im/nim-bearssl/archive/${bearssl_hash}/:bearssl \
                    https://github.com/status-im/BearSSL/archive/${bearsslc_hash}/:bearsslc \
                    https://github.com/nim-lang/checksums/archive/${checksums_hash}/:checksums \
                    https://github.com/status-im/nim-chronos/archive/${chronos_hash}/:chronos \
                    https://github.com/status-im/nim-http-utils/archive/${httputils_hash}/:httputils \
                    https://github.com/arnetheduck/nim-results/archive/${results_hash}/:results \
                    https://github.com/nim-lang/sat/archive/${sat_hash}/:sat \
                    https://github.com/status-im/nim-stew/archive/${stew_hash}/:stew \
                    https://github.com/guzba/zippy/archive/${zippy_hash}/:zippy

distfiles-append    bearssl-${bearssl_hash}${extract.suffix}:bearssl \
                    BearSSL-${bearsslc_hash}${extract.suffix}:bearsslc \
                    checksums-${checksums_hash}${extract.suffix}:checksums \
                    chronos-${chronos_hash}${extract.suffix}:chronos \
                    httputils-${httputils_hash}${extract.suffix}:httputils \
                    results-${results_hash}${extract.suffix}:results \
                    sat-${sat_hash}${extract.suffix}:sat \
                    stew-${stew_hash}${extract.suffix}:stew \
                    zippy-${zippy_hash}${extract.suffix}:zippy

checksums           nimble-${version}.tar.gz \
                    rmd160  731875104a0c816c07cd39fffdb4f039ab5f1866 \
                    sha256  dfa8e7bbbe7b05f8cff9bffd5aa25ddb5d73d92e85b752711df844456724e58c \
                    size    805740 \
                    bearssl-${bearssl_hash}${extract.suffix} \
                    rmd160  27e2ed96015e040adf1868165343b6263397ed6e \
                    sha256  551c2c386fb8dd38e0f569204f148d850c05d6ae14c34601e35d4b840aa25970 \
                    size    141817 \
                    BearSSL-${bearsslc_hash}${extract.suffix} \
                    rmd160  2762f346c73fb74396123c1b30955697963564e1 \
                    sha256  8f02ff853b88477a760df9c963a3feea8fa057328f50ebdb94a7be6886b862cd \
                    size    867205 \
                    checksums-${checksums_hash}${extract.suffix} \
                    rmd160  1cfcc510c07e2577f1ccae50c2d855439103a080 \
                    sha256  9cd0625ae8860ed1d6a20cff3dab81325a923c27789fc2bed82625a7c5763975 \
                    size    47503 \
                    chronos-${chronos_hash}${extract.suffix} \
                    rmd160  4711d57e6c93fc779643a77d2b632a80806286a9 \
                    sha256  5458d8a01e1e9ae6141afe693339b0a943cb5951ab20642d0408bdc947748f45 \
                    size    683005 \
                    httputils-${httputils_hash}${extract.suffix} \
                    rmd160  08350aad55adc4610206987f962aef3b189a8b87 \
                    sha256  cb097e61678f2366116d4743b8d26691d09c02b569eb131aa7b4dafc26c4c8c2 \
                    size    35438 \
                    results-${results_hash}${extract.suffix} \
                    rmd160  c21b5f3508cc7cd7e8811b9f9bb2b67c101e6b62 \
                    sha256  1e2569e47d3916cd6ffc67f5da1c36c3fd928bb38e215fb2a8a1695453c28820 \
                    size    24023 \
                    sat-${sat_hash}${extract.suffix} \
                    rmd160  ef34a699db84e6775a07ed6f55865e4af4adfb60 \
                    sha256  0846607e21cc2980ce68325fc3b4acbf2ebe4c74cbc5ee1c459fbc2abaf72856 \
                    size    10245 \
                    stew-${stew_hash}${extract.suffix} \
                    rmd160  70c957ae60ceba261cdd559411579140b1fbe000 \
                    sha256  bd4c60b25f7e99497a59e8f4bf14178229d3597002fee85a4e15336a063819bf \
                    size    122652 \
                    zippy-${zippy_hash}${extract.suffix} \
                    rmd160  50d274f7b9c6aa8c2e8036fe2f69d364830392ad \
                    sha256  d2283a8de48af729d46e78ec240449e26e32f49b566988fb6e8969fe53e0e135 \
                    size    21329585

depends_lib         port:nim \
                    path:lib/libssl.dylib:openssl

post-extract {
    set tar [findBinary tar ${portutil::autoconf::tar_command}]

    system -W ${workpath} "${tar} -zxf ${distpath}/bearssl-${bearssl_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/BearSSL-${bearsslc_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/checksums-${checksums_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/chronos-${chronos_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/httputils-${httputils_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/results-${results_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/sat-${sat_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/stew-${stew_hash}${extract.suffix}"
    system -W ${workpath} "${tar} -zxf ${distpath}/zippy-${zippy_hash}${extract.suffix}"

    delete -f ${workpath}/nim-bearssl-${bearssl_hash}/bearssl/csources
    delete -f ${worksrcpath}/vendor
    xinstall -d ${worksrcpath}/vendor

    move ${workpath}/nim-bearssl-${bearssl_hash} ${worksrcpath}/vendor/bearssl
    move ${workpath}/BearSSL-${bearsslc_hash} ${worksrcpath}/vendor/bearssl/bearssl/csources
    move ${workpath}/checksums-${checksums_hash} ${worksrcpath}/vendor/checksums
    move ${workpath}/nim-chronos-${chronos_hash} ${worksrcpath}/vendor/chronos
    move ${workpath}/nim-http-utils-${httputils_hash} ${worksrcpath}/vendor/httputils
    move ${workpath}/nim-results-${results_hash} ${worksrcpath}/vendor/results
    move ${workpath}/sat-${sat_hash} ${worksrcpath}/vendor/sat
    move ${workpath}/nim-stew-${stew_hash} ${worksrcpath}/vendor/stew
    move ${workpath}/zippy-${zippy_hash} ${worksrcpath}/vendor/zippy
}

use_configure       no

compiler.c_standard 2011

build.cmd           ${prefix}/bin/nim
build.target        c
build.args          -d:release \
                    --nimcache:${workpath}/.nimcache \
                    --parallelBuild:${build.jobs} \
                    --path:vendor

# FIXME: https://github.com/status-im/nim-bearssl/issues/107
build.args-append   --passC:-Wno-incompatible-pointer-types

platform darwin powerpc {
    set gcc_v [
        string range ${configure.compiler} [
            string length macports-gcc-
        ] end
    ]

    build.args-append \
                    --cc:gcc \
                    --gcc.path=${prefix}/bin \
                    --gcc.exe=gcc-mp-${gcc_v} \
                    --gcc.linkerexe=gcc-mp-${gcc_v}
}

build.post_args     src/nimble.nim

destroot {
    xinstall -m 0755 ${worksrcpath}/src/nimble ${destroot}${prefix}/bin/nimble

    # Install bash completion
    xinstall -d -m 0755 ${destroot}${prefix}/share/bash-completion/completions
    xinstall -m 0644 ${worksrcpath}/nimble.bash-completion \
        ${destroot}${prefix}/share/bash-completion/completions/nimble

    # Install zsh completion
    xinstall -d -m 0755 ${destroot}${prefix}/share/zsh/site-functions
    xinstall -m 0644 ${worksrcpath}/nimble.zsh-completion \
        ${destroot}${prefix}/share/zsh/site-functions/_nimble

    # Install documentation
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 ${worksrcpath}/readme.markdown \
        ${destroot}${prefix}/share/doc/${name}/
    xinstall -m 0644 ${worksrcpath}/changelog.markdown \
        ${destroot}${prefix}/share/doc/${name}/
    xinstall -m 0644 ${worksrcpath}/license.txt \
        ${destroot}${prefix}/share/doc/${name}/
}
