# -*- 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            zeroc-ice35
version         3.5.1
revision        5
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      devel
maintainers     nomaintainer
conflicts       zeroc-ice33 zeroc-ice34
license         GPL-2
description     Fast, object-oriented RPC for C++, Java, Python, Ruby, PHP

long_description \
    The Internet Communications Engine (Ice) is a modern alternative to \
    object middleware such as CORBA or COM/DCOM/COM+, with support for \
    C++, C#, Java, PHP, Python, Ruby and Visual Basic. \
    Ice consists of the following packages. \
    Slice: The Specification Language for Ice.  Slice establishes a \
    contract between clients and servers, and is also used to describe \
    persistent data. \
    Slice Compilers: Slice specifications are compiled into various \
    programming languages. Ice supports C++, Java, C#, Visual Basic, PHP, \
    Python and Ruby.  Ice clients and servers work together, regardless \
    of the programming language. \
    Ice: The Ice core library manages all the communication tasks using a \
    highly efficient protocol (including protocol compression and support \
    for both TCP and UDP), provides a flexible thread pool for \
    multi-threaded servers. \
    This Port provides the C++ runtime libraries, the core Slice files \
    and slice2cpp.  It also includes the slice compilers for all the \
    other languages: slice2cs, slice2java, slice2py, slice2rb and slice2vb.

homepage        http://www.zeroc.com/
master_sites    ${homepage}download/Ice/${branch}/

distname        Ice-${version}
checksums       sha1   63599ea22a1e9638a49356682c9e516b7c2c454f \
                sha256 989e51194c6adadbd156da3288e37bad847b93b3b876502e83033b70493af392
patchfiles      patch-ice.cpp.config.Make.rules.diff \
                patch-ice.cpp.config.Make.rules.Darwin.diff \
                patch-ice.cpp.src.Ice.DynamicLibrary.cpp.diff \
                patch-ice.cpp.src.IceGrid.DescriptorHelper.h.diff \
                patch-ice.cpp.test.Ice.info.AllTests.cpp.diff \
                patch-ice.cpp.test.IceGrid.admin.run.py.diff \
                patch-ice.cpp.test.IceGrid.deployer.run.py.diff \
                patch-ice.cpp.test.IceGrid.replicaGroup.run.py.diff \
                patch-ice.cpp.test.include.TestCommon.h.diff \
                patch-ice.scripts.TestUtil.py.diff

patch.pre_args-replace  -p0 -p1

depends_lib     port:db46 \
                port:expat \
                port:libiconv \
                port:mcpp \
                path:lib/libssl.dylib:openssl \
                port:readline

build.dir       ${worksrcpath}/cpp

post-patch {
    reinplace "s/-O2/-g -O2/" ${build.dir}/config/Make.rules.Darwin

    # It appears that the 10.4 and 10.5 installed versions of
    # ${prefix}/include/iconv.h have different definitions of
    # the inbuf parameter to iconv(), one is 'const char* * inbuf'
    # and the other is 'char* * inbuf'.  The Ice compile will
    # fail if the wrong #define is choosen by Ice.
    set fl [open ${prefix}/include/iconv.h]
    set data [read $fl]
    close $fl
    foreach line [split $data \n] {
        if {[string match "extern size_t iconv*const*" $line]} {
            reinplace "s/_LIBICONV_VERSION < 0x010B/1/" \
                ${build.dir}/include/Ice/IconvStringConverter.h
            break
        }
    }

    # Prevent name conflicts between libICE.* from xorg-libice and
    # libIce.* from this port by renaming libIce.* to libZerocIce.*.
    # For consistency, rename Ice's other shared libraries.
    foreach f [exec find ${build.dir} -name Makefile] {
        # To prevent replacements on slice2freeze's --dict argument,
        # match exactly on a , or a ) that follows ,Ice\w*, e.g.:
        # $(SLICE2FREEZE) --ice -I$(slicedir) --dict StringIsbnSeqDict,string,Ice::StringSeq
        reinplace -E {s/,Ice([[:alnum:]]*[,)])/,ZerocIce\1/} ${f}
        reinplace -E {s/-lIce([ A-Z]|$)/-lZerocIce\1/g} ${f}
    }
    reinplace -E {s/-lIce([ A-Z]|$)/-lZerocIce\1/g} \
        ${build.dir}/config/Make.rules \
        ${build.dir}/config/Make.rules.Darwin
}

use_configure   no

build {
    set jobsargs ""
    if {${build.jobs} > 1} {
        set jobsargs " -j${build.jobs}"
    }

    set cmd "cd ${build.dir} && make${jobsargs} prefix='${prefix}' embedded_runpath_prefix='${prefix}' CC='${configure.cc}' CXX='${configure.cxx}' OPTIMIZE='yes' BZIP2_HOME='${prefix}' DB_HOME='${prefix}' EXPAT_HOME='${prefix}' OPENSSL_HOME='${prefix}' READLINE_HOME='${prefix}' USE_READLINE=yes MCPP_HOME='${prefix}' all && cd doc && make${jobsargs}"
    ui_debug ${cmd}
    system ${cmd}
}

test.run        yes
test.target     test

destroot.target prefix="${prefix}" \
                embedded_runpath_prefix="${prefix}" \
                OPTIMIZE="yes" \
                BZIP2_HOME="${prefix}" \
                DB_HOME="${prefix}" \
                EXPAT_HOME="${prefix}" \
                OPENSSL_HOME="${prefix}" \
                READLINE_HOME="${prefix}" \
                USE_READLINE=yes \
                MCPP_HOME="${prefix}" \
                install

post-destroot {
    set sharedir ${destroot}${prefix}/share
    set docdir ${sharedir}/doc/${name}

    xinstall -m 755 -d ${sharedir}/ice
    file rename ${destroot}${prefix}/config ${sharedir}/ice
    file delete -force ${sharedir}/man
    file rename ${destroot}${prefix}/man ${sharedir}/man
    file rename ${destroot}${prefix}/slice ${sharedir}/slice

    xinstall -m 755 -d ${docdir}
    foreach f {CHANGES ICE_LICENSE LICENSE RELEASE_NOTES} {
        file rename ${destroot}${prefix}/${f} ${docdir}
    }
    file copy ${build.dir}/doc/reference ${docdir}

    if {[variant_isset demo_source_code]} {
        system "cd ${build.dir}/demo && make clean"
        file copy ${build.dir}/demo $docdir
    }
}

variant demo_source_code description {Install demonstration C++ code} {
}
