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

name                openjdk7-bootstrap
version             1.7.0_2
revision            1
set build           2012-03-14
categories          java devel
platforms           {darwin < 11}
supported_archs     ppc
license             GPL-2+
maintainers         {@barracuda156 gmail.com:vital.had} \
                    openmaintainer
description         OpenJDK 7 Boot JDK
long_description    OpenJDK 7 Boot JDK to bootstrap Openjdk8 port
homepage            https://openjdk.org/projects/bsd-port
master_sites        https://macintoshgarden.org/sites/macintoshgarden.org/files/apps \
                    http://mirror.macintosharchive.org/macintoshgarden.org/files/apps \
                    http://old.macintosh.garden/apps \
                    ftp://repo1.macintoshgarden.org/Garden/apps

checksums           rmd160  872bea18c8c153d0509d2d18ebe6da6a71161e3f \
                    sha256  0d3ffaa7c5a2873ec26fc97ce1f592bafa18e3ae52605f0a2ba039a75d4860a8 \
                    size    54392585

distname            openjdk7u2-macppc-fcs-${build}
distfiles           ${distname}.tar_.bz2
use_bzip2           yes
worksrcdir          ${distname}
use_xcode           no
use_configure       no

depends_lib         port:freetype \
                    port:xorg-libX11 \
                    port:xorg-libXext \
                    port:xorg-libXi \
                    port:xorg-libXtst \
                    port:xrender

build               {}

set path /Library/Java/JavaVirtualMachines/${name}

destroot {
    xinstall -m 755 -d ${destroot}${path}
    copy ${worksrcpath}/ASSEMBLY_EXCEPTION ${destroot}${path}
    copy ${worksrcpath}/bin ${destroot}${path}
    copy ${worksrcpath}/demo ${destroot}${path}
    copy ${worksrcpath}/include ${destroot}${path}
    copy ${worksrcpath}/jre ${destroot}${path}
    copy ${worksrcpath}/lib ${destroot}${path}
    copy ${worksrcpath}/LICENSE ${destroot}${path}
    copy ${worksrcpath}/man ${destroot}${path}
    copy ${worksrcpath}/release ${destroot}${path}
    copy ${worksrcpath}/sample ${destroot}${path}
    copy ${worksrcpath}/src.zip ${destroot}${path}
    copy ${worksrcpath}/THIRD_PARTY_README ${destroot}${path}
}

destroot.violate_mtree  yes

variant apple_x11 description "Use Apple version of X11" {
    depends_lib-delete \
                    port:xorg-libX11 port:xorg-libXext \
                    port:xorg-libXi port:xorg-libXtst \
                    port:xrender
}

post-destroot {
    # This is a required change, since the Apple one is too old:
    # Incompatible library version: /Library/Java/JavaVirtualMachines/openjdk7-bootstrap/jre/lib/ppc/libfontmanager.dylib
    # requires version 13.0.0 or later
    system "install_name_tool -change /usr/X11/lib/libfreetype.6.dylib \
                    ${prefix}/lib/libfreetype.6.dylib ${destroot}${path}/jre/lib/ppc/libfontmanager.dylib"

    # Remaining ones are optional, however we rather avoid depending on Apple X11, since it is not a part
    # of macOS as such, and can be missing or uninstalled later. Also, having two X11 versions tends to create conflicts
    # and lead to obscure bugs. It is safer to use only Macports X11.
    if {![variant_isset apple_x11]} {
        foreach x11lib [list libX11.6 libXext.6 libXi.6 libXrender.1 libXtst.6] {
            system "install_name_tool -change /usr/X11/lib/${x11lib}.dylib \
                    ${prefix}/lib/${x11lib}.dylib ${destroot}${path}/bin/appletviewer"
            system "install_name_tool -change /usr/X11/lib/${x11lib}.dylib \
                    ${prefix}/lib/${x11lib}.dylib ${destroot}${path}/bin/policytool"
            system "install_name_tool -change /usr/X11/lib/${x11lib}.dylib \
                    ${prefix}/lib/${x11lib}.dylib ${destroot}${path}/jre/bin/policytool"
            system "install_name_tool -change /usr/X11/lib/${x11lib}.dylib \
                    ${prefix}/lib/${x11lib}.dylib ${destroot}${path}/jre/lib/ppc/libsplashscreen.dylib"
            system "install_name_tool -change /usr/X11/lib/${x11lib}.dylib \
                    ${prefix}/lib/${x11lib}.dylib ${destroot}${path}/jre/lib/ppc/xawt/libmawt.dylib"
        }
    }
}
