# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 64637 2010-03-12 01:00:52Z raimue@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            icu
set my_name     icu4c
version         4.3.4
categories      devel textproc
platforms       darwin freebsd
maintainers     nox openmaintainer
description     International Components for Unicode

long_description \
    The International Components for Unicode (ICU) libraries provide robust \
    and full-featured Unicode services on a wide variety of platforms. ICU \
    supports the most current version of the Unicode standard, and they provide \
    support for supplementary Unicode characters (needed for GB 18030 repertoire support).

homepage        http://www.icu-project.org/
master_sites    http://download.icu-project.org/files/${my_name}/${version}/

distname        ${my_name}-[join [split ${version} .] _]
extract.suffix  .tgz
distfiles       [suffix ${distname}-src]

checksums       ${distname}-src.tgz \
checksums           md5     9736a1e69bce0e5322af6986008d89bc \
                    sha1    99c95f924f82b48c97f9e1e57ea2568cef22d6ef \
                    rmd160  2c1a42379a6d14bea2ac1585532e3a7b8a4fe836 \
                ${distname}-docs.zip \
                    md5     df164cba867cd293c4041352496537fa \
                    sha1    1ec70bb0bdb101d569cc3f164ba3dfa5a62e2fe4 \
                    rmd160  0f7f479197e1bf1993d6369e859388ade239a112

worksrcdir      ${name}/source
set docdir      ${prefix}/share/doc/${name}

patchfiles      patch-configure.diff \
                patch-config-mh-darwin.diff

post-patch {
    reinplace "s;install_name ;install_name ${prefix}/lib/;" ${worksrcpath}/config/mh-darwin
    reinplace "s|`date`|[exec date]|g" ${worksrcpath}/Makefile.in
}

set platform [switch ${os.platform} {darwin {format MacOSX} freebsd {format FreeBSD}}]
configure.cmd   ./runConfigureICU ${platform}

configure.args  --mandir=${prefix}/share/man \
                --enable-static \
                --disable-samples

configure.universal_args-delete --disable-dependency-tracking

# Fix bug #11981 that prevents ICU from building when upgrading.
# The default configure flags causes utilisation of outdated ICU
# headers/libs instead of the right ones.
configure.cppflags
configure.ldflags

# Disable ccache, #23931
configure.ccache no

build.type      gnu

use_parallel_build  yes

test.run        yes
test.target     check

post-build {
    if {[variant_isset universal]} {
        set dirs {}
        foreach arch ${universal_archs_to_use} {
            lappend dirs ${worksrcpath}-${arch}
        }
    } else {
        set dirs ${worksrcpath}
    }
    foreach dir ${dirs} {
        reinplace -E {s|-arch [a-z0-9_]+||g} \
            ${dir}/config/icu-config \
            ${dir}/config/Makefile.inc \
            ${dir}/config/pkgdata.inc
    }
}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath}/.. readme.html ${destroot}${docdir}
}

variant doc description {Install extra documentation} {
    extract.only        [suffix ${distname}-src]
    distfiles-append    ${distname}-docs.zip

    post-extract {
        system "unzip -q ${distpath}/${distname}-docs.zip -d ${workpath}/doc"
    }

    post-destroot {
        eval xinstall -m 0644 [glob ${workpath}/doc/*.{css,gif,html,png}] ${destroot}${docdir}
    }
}

platform freebsd {
    build.env       MAKE=/usr/local/bin/gmake
    destroot.env    MAKE=/usr/local/bin/gmake
}

livecheck.url   http://icu-project.org/download/latest_milestone.html
livecheck.regex {\((\d+(?:\.\d+)*)\)</title>}
