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

name                leiningen
version             2.13.0
categories          devel java
maintainers         {easieste @easye} openmaintainer
supported_archs     noarch
platforms           any
license             EPL-1

description         A build tool for Clojure designed to not set your hair on fire.
long_description    {*}${description}

homepage            https://leiningen.org

master_sites \
    https://codeberg.org/leiningen/leiningen/archive/:source \
    https://github.com/technomancy/leiningen/releases/download/${version}/:standalone

distfiles \
    ${version}.tar.gz:source \
    ${name}-${version}-standalone.jar:standalone

checksums \
    ${version}.tar.gz \
                    rmd160  1def1c093c19ab4019dd644798de72411febd37d \
                    sha256  e21a752dff9e182e2ce01262f07349f2a7b43f873ed69074c9019d1d4bab397b \
                    size    982010 \
    ${name}-${version}-standalone.jar \
                    rmd160  64b2dfbabb93d01a94d4f065801c628035e49569 \
                    sha256  5f5231f06c3c7924e3241e3dfa52885577fb44ddf8a9ea373d2c5e2f27217565 \
                    size    17056184

depends_build-append \
    bin:gzip:gzip
depends_run-append \
    bin:bash:bash

java.version        1.8+
java.fallback       openjdk25

worksrcdir          ${name}
extract.only        ${version}.tar.gz

patchfiles          correct-jar.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/bin/lein-pkg
}

use_configure       no

build {
    system -W ${worksrcpath}/doc "gzip lein.1"
}

destroot {
    set destbashdir ${destroot}${prefix}/etc/bash_completion.d
    set destbindir  ${destroot}${prefix}/bin
    set destdocdir  ${destroot}${prefix}/share/doc/${name}
    set destjavadir ${destroot}${prefix}/share/java
    set destmandir  ${destroot}${prefix}/share/man
    set destzshdir  ${destroot}${prefix}/share/zsh/site-functions

    xinstall -d ${destbindir}
    xinstall -m 755 \
        ${worksrcpath}/bin/lein-pkg \
        ${destbindir}/lein

    xinstall -d ${destjavadir}
    xinstall -m 644 \
        ${distpath}/${name}-${version}-standalone.jar \
        ${destjavadir}/${name}-standalone.jar

    xinstall -d ${destbashdir}
    xinstall -m 644 \
        ${worksrcpath}/bash_completion.bash \
        ${destbashdir}/lein

    xinstall -d ${destzshdir}
    xinstall -m 644 \
        ${worksrcpath}/zsh_completion.zsh \
        ${destzshdir}/_lein

    xinstall -d ${destdocdir}
    xinstall -m 644 \
        ${worksrcpath}/CONTRIBUTING.md \
        ${worksrcpath}/COPYING \
        ${worksrcpath}/NEWS.md \
        ${worksrcpath}/README.md \
        {*}[glob -directory ${worksrcpath}/doc *.md] \
        ${destdocdir}

    xinstall -d ${destmandir}/man1
    xinstall -m 444 \
        ${worksrcpath}/doc/lein.1.gz \
        ${destmandir}/man1
}
