# $Id: Portfile 67860 2010-05-20 05:53:03Z blair@macports.org $

PortSystem 1.0

name            ice-cpp
version         3.4.0
revision        2
set branch      [join [lrange [split ${version} .] 0 1] .]
categories      devel
maintainers     blair
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}
patchfiles      patch-ice.cpp.config.Make.rules.diff \
                patch-ice.cpp.config.Make.rules.Darwin.diff \
                patch-ice.cpp.src.Ice.Instance.cpp.diff \
                745d1268183564-patch-1-ice-3-4-0-slice2cpp-stream-issue-patch-stream.txt \
                747d1269356146-patch-2-ice-3-4-0-slice2cpp-stream-issue-2-patch-stream2.txt
patch.pre_args  -p1
checksums       md5 998b10627ade020cb00f5beb73efc0e0 \
                sha1 1c8fe296af8d65d16cddac39a8bc24b71e069f75 \
                rmd160 e874749f8d7d1916c1e3b19c006a7f2216e10f53
platforms       darwin

depends_lib     port:libiconv \
                port:db46 \
                port:expat \
                port:openssl \
                port:readline \
                port:mcpp

build.dir       ${worksrcpath}/cpp

post-patch {
        # Remove this reinplace when 3.4.1 is released.
        reinplace "s/nodarwing/nodarwin/" \
                ${worksrcpath}/scripts/TestUtil.py

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

        # To prevent a compilation failure by picking up header files
        # from an older installed version of Ice, put the $(CPPFLAGS)
        # before $(READLINE_FLAGS).
        reinplace "s|\$\(READLINE_FLAGS\) \$\(CPPFLAGS\)|\$\(CPPFLAGS\) \$\(READLINE_FLAGS\)|" \
                ${build.dir}/demo/Freeze/library/Makefile \
                ${build.dir}/demo/Freeze/phonebook/Makefile \
                ${build.dir}/demo/book/evictor_filesystem/Makefile \
                ${build.dir}/demo/book/lifecycle/Makefile \
                ${build.dir}/demo/book/map_filesystem/Makefile

        # 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.*.
        reinplace "s/,Ice/,ZeroCIce/" \
                ${build.dir}/src/Ice/Makefile
        reinplace "s/-lIce /-lZeroCIce /" \
                ${build.dir}/config/Make.rules.Darwin
        foreach {f} [exec find ${build.dir} -name Makefile] {
                reinplace "s/-lIce /-lZeroCIce /" ${f}
        }
}

use_configure   no

build {
        set cmd "cd ${build.dir} && make 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}' LDPLATFORMFLAGS= all && cd doc && make"
        ui_debug ${cmd}
        system ${cmd}
}

test.run        yes
test.target     test

destroot.target prefix="${destroot}${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 rename ${destroot}${prefix}/slice ${sharedir}/slice

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

        foreach f {CHANGES RELEASE_NOTES} {
                file copy ${worksrcpath}/${f} ${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} {
}
