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

name            db47
version         4.7.25
revision        3
set branch      [join [lrange [split ${version} .] 0 1] {}]
categories      databases
license         Sleepycat
maintainers     {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
platforms       darwin
description     The Berkeley DB package, version 4.7
long_description \
    Version 4.7 of the Berkeley Data Base library which \
    offers (key/value) storage with optional concurrent \
    access or transactions interface.  This port will \
    install the AES (American Encryption Standard) \
    enabled version.

homepage        http://www.oracle.com/us/products/database/berkeley-db/db/overview/index.html
master_sites    http://download.oracle.com/berkeley-db/
patch_sites     http://download.oracle.com/berkeley-db/patches/db/${version}/
patchfiles      patch.${version}.1 \
                patch.${version}.2 \
                patch.${version}.3 \
                patch.${version}.4

distname        db-${version}
patch.dir       ${workpath}/${distname}

checksums       ${distname}${extract.suffix} \
                md5     ec2b87e833779681a0c3a814aa71359e \
                sha1    957c10358df1211e1dc37ea997aadef42117d6a5 \
                rmd160  9a5d8149d61452906c3f1c36f2859a2033c8bc3b \
                patch.${version}.1 \
                md5     5fdf101259e5164dea1c8c86214fde38 \
                sha1    3ae3c02fb541dc8f8dee903a75450d2dbc0736a7 \
                rmd160  89c58f5235f95e82e65bab447d1b9019bf26ed25 \
                patch.${version}.2 \
                md5     bd410a11c71fee52fddb6aa2d8d4f80c \
                sha1    e3d56ad6e4a9bc092495f62c40c0cdf11ab2443c \
                rmd160  097a6bc3e8efd43fe5bd0fd77a4b793cd0d6bc18 \
                patch.${version}.3 \
                md5     6fcd69f64f5b34bfe8f0a63cc2e402c1 \
                sha1    1f707e6c65c8ebe9fa7b36333c6de76f2d480cf5 \
                rmd160  a0ef673d8127be825444aaa12711dcf75b7fda1a \
                patch.${version}.4 \
                md5     c71830a1303cd34595ca655257196eec \
                sha1    0eb5566ad2ca2232b92d8c71285bfaf32aba54dc \
                rmd160  0b235122060785887eb41fa7657379bd4f1e57bf

configure.dir   ${worksrcpath}/build_unix
build.dir       ${configure.dir}

configure.cmd   ../dist/configure
configure.args  --enable-cxx \
                --includedir=\\\${prefix}/include/db${branch} \
                --libdir=\\\${prefix}/lib/db${branch}

set cxx_stdlibflags {}
if {[string match *clang* ${configure.cxx}]} {
    set cxx_stdlibflags -stdlib=${configure.cxx_stdlib}
}
configure.cxx ${configure.cxx} ${cxx_stdlibflags}

destroot.destdir \
    prefix=${destroot}${prefix} \
    docdir=${destroot}${prefix}/share/doc/${name}

post-destroot {
    foreach bin [glob -tails -directory ${destroot}${prefix}/bin/ db_*] {
        set newbin [regsub {^db_} ${bin} "db${branch}_"]
        move ${destroot}${prefix}/bin/${bin} \
            ${destroot}${prefix}/bin/${newbin}
    }
}

variant java conflicts no_java description {Build the Java API} {
    configure.args-append   --enable-java
    platform macosx {
        pre-configure {
            if {![file isfile "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h"]} {
                ui_error "${name} requires the Java for Mac OS X development headers."
                if {${os.major} == 10} {
                    ui_error "Download the Java Developer Package from: <https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719>"
                } elseif {${os.major} == 9} {
                    ui_error "Download the Java Developer Package from: <https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20720>"
                } else {
                    ui_error "Make sure your Xcode installation is complete."
                }
                return -code error "missing Java headers"
            }
        }
    }
}
variant no_java conflicts java description {Legacy compatibility variant} {}
if {[variant_isset no_java]} {
    default_variants -java
} elseif {${os.subplatform} eq "macosx" && ${os.major} < 11} {
    default_variants +java
}

variant tcl description {build Tcl API} {
    depends_lib-append      port:tcl
    configure.args-append   --enable-tcl --with-tcl=${prefix}/lib
}

if { [variant_isset universal] } {
    if {${os.arch} eq "i386"} {
        if { ${os.major} >= 10 } {
            set merger_configure_args(ppc) --with-mutex=Darwin/_spin_lock_try
        }
        set merger_configure_args(ppc64)   --with-mutex=Darwin/_spin_lock_try
    } else {
        set merger_configure_args(i386)    --with-mutex=x86/gcc-assembly
        set merger_configure_args(x86_64)  --with-mutex=x86_64/gcc-assembly
    }
}

livecheck.type  regex
livecheck.url   http://www.oracle.com/technetwork/database/berkeleydb/downloads/index-082944.html
livecheck.regex {(4\.7(?:\.\d+)*)\.tar\.gz}
