# -*- 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           github 1.0
PortGroup           select 1.0

# Permanently pinned at upstream tag v2.1.2 (legacy 2.x line).
name                voc2
github.setup        vishapoberon compiler 2.1.2 v
revision            0
github.tarball_from archive

categories          lang
license             GPL-3
maintainers         {freebsd.am:antranigv @antranigv} openmaintainer

description         Vishap Oberon Compiler ${version} (legacy)
long_description    Vishap Oberon (voc) ${version} is the legacy 2.x release of \
                    the free Oberon-2 compiler with a C backend. This port stays \
                    pinned at ${version} for users who need that ABI/layout. \
                    Parallel install with a select-aware voc is via \
                    port:voc_select ('sudo port select --set voc voc2'). The \
                    compiler binary reports itself as 2.1.0 (upstream did not \
                    bump O_VER for the v${version} tag).

homepage            https://vishap.oberon.am

checksums           rmd160  54e0abadfa729c4168eb144168b8359bca8b7105 \
                    sha256  c9c4d3b964b46290db5ee98c7190c0a06660fe4711cb899b251266cc8b32e9c0 \
                    size    1136536

# Upstream targets clang on Darwin.
compiler.blacklist  *gcc*

depends_run-append  port:voc_select

select.group        voc
select.file         ${filespath}/voc2

# Single versioned tree; binaries on PATH are voc2/showdef2, with plain
# voc/showdef provided by 'port select'.
set voc2.installdir ${prefix}/libexec/${name}

# INSTALLDIR is compiled into the binary (see configure.c). DESTDIR-style
# staging is not supported by the 2.1.2 makefile, so bake the final path and
# copy the local install/ image into destroot.
#
# Layout:
#   ${prefix}/libexec/voc2/{bin,lib,2,C}/...
#   ${prefix}/bin/voc2 -> ${prefix}/libexec/voc2/bin/voc
#   ${prefix}/bin/showdef2 -> ${prefix}/libexec/voc2/bin/showdef

patchfiles          patch-configure-headerpad.diff

use_configure       no
use_parallel_build  no
universal_variant   no

build.env-append    CC=${configure.cc} \
                    INSTALLDIR=${voc2.installdir}
build.args-append   INSTALLDIR=${voc2.installdir}
build.target        full

# 'make full' already runs confidence tests.
test.run            no

destroot {
    set imagedir ${worksrcpath}/install
    if {![file isdirectory ${imagedir}]} {
        ui_error "Expected local install image at ${imagedir} after build."
        return -code error "missing install image"
    }

    xinstall -d ${destroot}${voc2.installdir}
    # 2.1.2 has no DESTDIR; stage the local install/ image as the versioned tree.
    foreach item {bin lib 2 C} {
        if {[file exists ${imagedir}/${item}]} {
            file copy ${imagedir}/${item} ${destroot}${voc2.installdir}/${item}
        }
    }

    # Versioned names on PATH for select and direct use.
    xinstall -d ${destroot}${prefix}/bin
    ln -s ${voc2.installdir}/bin/voc ${destroot}${prefix}/bin/voc2
    if {[file exists ${destroot}${voc2.installdir}/bin/showdef]} {
        ln -s ${voc2.installdir}/bin/showdef ${destroot}${prefix}/bin/showdef2
    }

    # Absolute dylib install names under the versioned tree (Darwin).
    if {${os.platform} eq "darwin"} {
        foreach dylib {libvoc-O2.dylib libvoc-OC.dylib} {
            set path ${destroot}${voc2.installdir}/lib/${dylib}
            if {[file exists ${path}]} {
                system "install_name_tool -id ${voc2.installdir}/lib/${dylib} ${path}"
            }
        }
    }

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 -W ${worksrcpath} ReadMe.md LICENSE \
        ${destroot}${prefix}/share/doc/${name}
}

notes "
To make this the default Vishap Oberon compiler (i.e., the version run by\
the 'voc' and 'showdef' commands), run:

    sudo port select --set voc voc2
"

# Permanently pinned; do not follow newer upstream tags.
livecheck.type      none
