# $Id: Portfile 88718 2012-01-09 20:05:39Z and.damore@macports.org $

PortSystem 1.0
PortGroup  muniversal 1.0

name                    db46
set minor_version       21
version                 4.6.${minor_version}
revision                6
categories              databases
license                 Sleepycat
maintainers             blair openmaintainer
platforms               darwin
use_parallel_build      yes
description             The Berkeley DB package, version 4.6
long_description        Version 4.6 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/database/berkeley-db/index.html
master_sites            http://download-west.oracle.com/berkeley-db/ \
                        http://download-east.oracle.com/berkeley-db/ \
                        http://download-uk.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}
dist_subdir             db4/${version}_6
checksums               ${distname}${extract.suffix} \
                        md5     718082e7e35fc48478a2334b0bc4cd11 \
                        sha1    5be3beb82e42a78ff671a3f5a4c30e5652972119 \
                        rmd160  ccf9a4b85cc0464b2f3c2f2da29d99328fd4978e \
                        patch.${version}.1 \
                        md5     4878872edfc53c6ecb871b1062a4bdaf \
                        sha1    c7c155705687e4de03d06c2ea86940f573fdac0b \
                        rmd160  8c11e9b991ac6559f22ece2d93617b16126049e8 \
                        patch.${version}.2 \
                        md5     55074e53d3acae2dcbeae8322f96e522 \
                        sha1    a694b71088ba99b74042e7568f395fe467bb6590 \
                        rmd160  f8abf554552db668037e046dea54700ce3340bf8 \
                        patch.${version}.3 \
                        md5     7a6e11b54712caf752f9c4a52babe60c \
                        sha1    d52aa498943cfaa339ad6bf2cf7b836a40627701 \
                        rmd160  4e6b7ed1e1c69cba54351d76a0b8543107a655b8 \
                        patch.${version}.4 \
                        md5     ae7d3d587355fe85b512ef09b9a77d19 \
                        sha1    e2190185c667edb97e800495ce6eb4f95f43eb87 \
                        rmd160  f1d18e59c311fb4e1f00a3b6220269fca17df312

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

configure.cmd           ../dist/configure
configure.args          --enable-cxx \
                                --includedir=\\\${prefix}/include/db46 \
                                --libdir=\\\${prefix}/lib/db46 \
                                --program-transform-name="s,^db,db46," \
                                --enable-dump185 \
                                --disable-tcl

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

pre-extract {
        if {[file exists "/usr/local/include/db.h"]} {
                ui_error "You have a conflicting install of Berkeley DB in /usr/local, please move it aside before building ${name}"
                return -code error "Berkeley DB in /usr/local is in the way"
        }
}

post-destroot {
        foreach bin { archive hotbackup dump printlog upgrade checkpoint recover verify deadlock load stat codegen dump185 } {
                move ${destroot}${prefix}/bin/db_${bin} \
                        ${destroot}${prefix}/bin/db46_${bin}
        }
}

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} == "macosx" && ${os.major} < 11} {
    default_variants +java
}

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

if { [variant_isset universal] } {
        if { ${os.arch}=="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.version       ${minor_version}
livecheck.regex         {4.6.(\d+(?:\.\d+)*)}
