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

# MacPorts specification for the TAO CORBA package.
# Includes ACE even though the ace port is available
# since TAO can not be built against an installed version of ACE.
# Thanks to the boost port maintainers for a great example to follow.
# Thomas Lockhart
# 2012-02-06

PortSystem          1.0
PortGroup           github 1.0

github.setup        DOCGroup ACE_TAO 8_0_0 ACE+TAO-
github.tarball_from releases

name                tao
set name_package    ACE+TAO
version             [string map {_ .} ${github.version}]
revision            0
distname            ${name_package}-${version}
categories          devel
license             BSD
maintainers         {gmail.com:tlockhart1976 @lockhart} {remedy.nl:jwillemsen @jwillemsen} openmaintainer
description         The ACE ORB CORBA real-time middleware
long_description    The ACE ORB (TAO) is a real-time implementation of CORBA built using the \
                    framework components and patterns provided by ACE. TAO contains the \
                    network interface, OS, communication protocol, and CORBA middleware \
                    components and features. TAO is based on the standard OMG CORBA \
                    reference model, with the enhancements designed to overcome the \
                    shortcomings of conventional ORBs for high-performance and real-time \
                    applications.
homepage            https://www.dre.vanderbilt.edu/~schmidt/TAO.html

checksums           rmd160  c01fbbd43ae24c785b00b71f65d7cc7faa551e39 \
                    sha256  dc49e7e4b3116fcb57ccbb187ed2480184d54e62269057e4f22c76078b4969c3 \
                    size    24065586

conflicts           ace

universal_variant   yes
default_variants    +server

use_bzip2           yes

worksrcdir          ACE_wrappers

patchfiles          patch-ace-config.h.diff \
                    patch-ace-config-macosx.h.diff \
                    patch-ace-config-macosx-sierra.h.diff \
                    patch-include-makeinclude-platform_macros.GNU.diff \
                    patch-archflags.diff

set logdir          ${prefix}/var/log/tao
set taodaemon       tao_cosnaming
set daemondir       ${prefix}/etc/LaunchDaemons/org.macports.${taodaemon}
set taouser         _tao
set subdirs         { ace ACEXML ASNMP Kokyu apps netsvcs TAO/TAO_IDL TAO/tao TAO/orbsvcs TAO/utils }

add_users ${taouser} group=${taouser} realname=TAO\ Server

post-patch {
    reinplace "s|@@CFLAGS@@|[get_canonical_archflags cc]|" \
        ${worksrcpath}/include/makeinclude/platform_macosx_common.GNU
    set stdlib_flag [expr {[string match *-stdlib=* ${configure.cxxflags}] ? " -stdlib=${configure.cxx_stdlib}" : ""}]
    reinplace "s|@@LDFLAGS@@|[get_canonical_archflags ld]${stdlib_flag}|" \
        ${worksrcpath}/include/makeinclude/platform_macosx_common.GNU
    reinplace "s|@@CXXFLAGS@@|[get_canonical_archflags cxx]${stdlib_flag}|" \
        ${worksrcpath}/include/makeinclude/platform_macosx_common.GNU
}

depends_lib-append  path:bin/perl:perl5 \
                    port:tcl \
                    port:zlib

variant ssl description {Enable SSL} {
    depends_lib-append path:lib/libssl.dylib:openssl

    post-patch {
        reinplace "s|ssl=0|ssl=1|g" \
            ${worksrcpath}/include/makeinclude/platform_macros.GNU
    }
}

variant server description {Enable CosNaming server} {
    startupitem.create  yes
    startupitem.name    ${taodaemon}
    startupitem.executable  ${prefix}/bin/${taodaemon} -ORBListenEndpoints iiop://:2809
}

use_configure       no

use_parallel_build  no

compiler.cxx_standard \
                    2017

build.env           DYLD_LIBRARY_PATH=${worksrcpath}/lib \
                    ACE_ROOT=${worksrcpath} \
                    TAO_ROOT=${worksrcpath}/TAO
build.args          CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    INSTALL_PREFIX=${prefix}
build {
    foreach {subdir} $subdirs {
        build.dir ${worksrcpath}/${subdir}
        command_exec build
    }
}

destroot.env        {*}${build.env}
destroot.args       {*}${build.args}
destroot.keepdirs   ${destroot}${logdir}
destroot {
    xinstall -d -o ${taouser} -m 0755 ${destroot}${logdir}
    foreach {subdir} $subdirs {
        destroot.dir ${worksrcpath}/${subdir}
        command_exec destroot
    }
    # Files required to build CosEvent classes but not installed
    copy ${worksrcpath}/TAO/orbsvcs/orbsvcs/ESF ${destroot}${prefix}/include/orbsvcs/ESF
}

pre-activate {
    # Prevent activation failure for upgrades. This can be removed after 2025-07-21.
    set filepath ${logdir}/.turd_${subport}
    if {[file exists ${filepath}] && [registry_file_registered ${filepath}] == "0"} {
        if {[catch {delete ${filepath}}]} {
            ui_warn "Cannot delete ${filepath}; please remove it manually"
        }
    }
}

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     "ACE\\+TAO-(\[0-9.\]+\[0-9\]+)${extract.suffix}"
