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

PortSystem          1.0

name                ace
set name_package    ACE
version             6.3.3
distname            ${name_package}-${version}
categories          devel
maintainers         gmail.com:tlockhart1976 openmaintainer
platforms           darwin
license             BSD
description         ACE is an object-oriented framework that implements many core patterns for \
                    concurrent communication software.
long_description    The ADAPTIVE Communication Environment (ACE) is a freely available, \
                    open-source object-oriented (OO) framework that implements many core \
                    patterns for concurrent communication software. ACE provides a rich set \
                    of reusable C++ wrapper facades and framework components that perform \
                    common communication software tasks across a range of OS platforms. The \
                    communication software tasks provided by ACE include event \
                    demultiplexing and event handler dispatching, signal handling, service \
                    initialization, interprocess communication, shared memory management, \
                    message routing, dynamic (re)configuration of distributed services, \
                    concurrent execution and synchronization.

conflicts           tao

homepage            http://www.cs.wustl.edu/~schmidt/ACE.html
master_sites        http://download.dre.vanderbilt.edu/previous_versions

universal_variant   yes

use_bzip2           yes

worksrcdir          ACE_wrappers

patch.pre_args      -p1
patchfiles          patch-ace-config.h.diff \
                    patch-include-makeinclude-platform_macros.GNU.diff

checksums           rmd160  01e77b057b9533fb61d05185bda03a8e019c949f \
                    sha256  f362e45f624db3343db529654b601d5df69b5f56fa4597cf453da35d80989888

set os.name "mavericks"
array set os.names {
     7  panther
     8  tiger
     9  leopard
    10  snowleopard
    11  lion
    12  mountainlion
    13  mavericks
}
foreach {key value} [array get os.names]  {
    if {${key} == ${os.major}} {
        set os.name ${value}
    }
}

set libenv          DYLD_LIBRARY_PATH=${worksrcpath}/lib
set aceenv          ACE_ROOT=${worksrcpath}
set makearg         INSTALL_PREFIX=${prefix}
# omit examples and test programs to cut build time by 60%
# set subdirs         { . }
set subdirs         { ace ACEXML ASNMP Kokyu apps netsvcs }

post-patch {
    reinplace "s|@MACOSX@|${os.name}|g" \
        ${worksrcpath}/ace/config.h \
        ${worksrcpath}/include/makeinclude/platform_macros.GNU
    # disable the assignment for compilers in lion and use our environment instead
    ui_info "patching platform_macosx_lion.GNU"
    reinplace "s|^\\(CXX:=.*\\)|# \\1|g" \
        ${worksrcpath}/include/makeinclude/platform_macosx_lion.GNU
    reinplace "s|^\\(CC:=.*\\)|# \\1|g" \
        ${worksrcpath}/include/makeinclude/platform_macosx_lion.GNU
}

depends_lib-append  path:bin/perl:perl5

proc setuniversalflags {fname cxxflags ldflags} {
    set apat "-arch \[ \]*\[a-z\]\[_a-z0-9\]*"
    if {[file exists ${fname}]} {
        reinplace "s|^\\(\[ \]*FLAGS_C_CC\[ \]*+=\[ \]*\\)${apat}\\(\[ \]*${apat}\\)*|\\1${cxxflags}|g" \
            ${fname}
        reinplace "s|^\\(\[ \]*LDFLAGS\[ \]*+=\[ \]*\\)${apat}\\(\[ \]*${apat}\\)*|\\1${ldflags}|g" \
            ${fname}
    } else {
        ui_warn "File ${fname} not found for patching"
    }
}

variant universal {
    post-patch {
        ui_info "patching platform_macros.GNU"
        reinplace "s|buildbits=64|buildbits=universal|g" \
            ${worksrcpath}/include/makeinclude/platform_macros.GNU
        setuniversalflags ${worksrcpath}/include/makeinclude/platform_macosx_${os.name}.GNU \
            ${configure.universal_cxxflags} ${configure.universal_ldflags}
    }
}

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
    }
}

use_configure       no

use_parallel_build  no

build.env           "${libenv} ${aceenv}"
build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp}
build.pre_args      ${makearg} all
build {
    foreach {subdir} $subdirs {
        build.dir ${worksrcpath}/${subdir}
        command_exec build
    }
}

destroot.env        "${libenv} ${aceenv}"
destroot.args-append CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp}
destroot.pre_args   ${makearg} install
destroot {
    foreach {subdir} $subdirs {
        destroot.dir ${worksrcpath}/${subdir}
        command_exec destroot
    }
}

livecheck.url       ${master_sites}
livecheck.regex     ${name_package}-(\\d+\[0-9a-z.\]*)${extract.suffix}