# -*- 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                    derby
version                 10.17.1.0

categories              java
maintainers             nomaintainer
platforms               any
supported_archs         noarch
license                 Apache-2
homepage                https://db.apache.org/derby

description             Relational database implemented entirely in Java
long_description        Apache Derby, an Apache DB subproject, is an open \
                        source relational database implemented entirely in \
                        Java and available under the Apache License, Version \
                        2.0.  Some key advantages include:  1) Derby has a \
                        small footprint -- about 2 megabytes for the base \
                        engine and embedded JDBC driver.  2) Derby is based \
                        on the Java, JDBC, and SQL standards.  3) Derby \
                        provides an embedded JDBC driver that lets you \
                        embed Derby in any Java-based solution.  4) Derby \
                        also supports the more familiar client/server mode \
                        with the Derby Network Client JDBC driver and Derby \
                        Network Server.  5) Derby is easy to install, deploy, \
                        and use.

depends_build           bin:ant:apache-ant \
                        port:junit

java.version            21+
java.fallback           openjdk21

master_sites            apache:db/${name}/db-${name}-${version}
distname                db-${name}-${version}-src

checksums               rmd160  7570006f4f641471ce11eaf9c1bcea3273b3f290 \
                        sha256  7f8581d16b8815f6e2799620e7f109abd5a44e4979558a033ee3ba1280ec8739 \
                        size    28204066

use_configure           no

build.cmd               ant
build.target            buildsource buildjars
build.args              -Djunit="${prefix}/share/java/junit.jar"

destroot {
    set destbindir  ${destroot}${prefix}/bin
    set destdocdir  ${destroot}${prefix}/share/doc/${name}
    set desthomedir ${destroot}${prefix}/share/${name}
    set destjavadir ${destroot}${prefix}/share/java/${name}

    xinstall -d ${destjavadir}
    xinstall -m 644 \
        {*}[glob -directory ${worksrcpath}/jars/sane "*.\[jw]ar"] \
        ${destjavadir}

    xinstall -d ${destdocdir}
    xinstall -m 644 \
        ${worksrcpath}/LICENSE \
        ${worksrcpath}/NOTICE \
        ${worksrcpath}/README \
        ${worksrcpath}/RELEASE-NOTES.html \
        ${worksrcpath}/STATUS \
        ${destdocdir}

    # Partially mimic the contents of the upstream binary distribution;
    # needed for scripts as the value of $DERBY_HOME.
    xinstall -d ${desthomedir}
    copy ${worksrcpath}/generated/bin ${desthomedir}
    ln -s ../java/${name} ${desthomedir}/lib

    if {[variant_isset bin]} {
        xinstall -d ${destbindir}
        foreach script [glob -tails -directory ${desthomedir}/bin *] {
            ln -s ../share/${name}/bin/${script} ${destbindir}
        }
    }

    if {[variant_isset doc]} {
        copy ${worksrcpath}/javadoc ${destdocdir}
        ln -s ../doc/${name}/javadoc/publishedapi ${desthomedir}/javadoc
    }
}

notes-append "
The installed scripts require the environment variable DERBY_HOME to be
set to \"${prefix}/share/${name}\".
"

livecheck.type          regex
livecheck.url           ${homepage}/derby_downloads.html
livecheck.regex         "release-(\[0-9]+(\[._]\[0-9]+)*)\\.(cgi|html)"
livecheck.version       [string map {. _} ${version}]

variant bin \
        description {Install symlinks to scripts} {
    # Keep as variant due to scripts having generic names,
    # increasing chances of a name conflict with another port.
}

variant doc \
        description {Install javadoc} {
    build.target-append javadoc
}
