# -*- 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 55845 2009-08-20 09:55:29Z nox@macports.org $

PortSystem      1.0

name            icu
set my_name     icu4c
version         4.3.1
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]
patchfiles      patch-source_configure.diff

checksums       ${distname}-src.tgz \
                    md5     10d1cdc843f8e047fc308ec49d3d0543 \
                    sha1    ff497c2480928a0f33386bb85a55020deecf8549 \
                    rmd160  983fcd43a5e1f8c32a1f0d696b47fb7afc855027 \
                ${distname}-docs.zip \
                    md5     c2d732ce7d086257ed60071674752471 \
                    sha1    08d0a6c56f6a6872a7f15bf8c1127af5dca07997 \
                    rmd160  ac47371ca2a6a72babb10dc5e817083a4f623023

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

post-patch {
    reinplace "s;install_name ;install_name ${prefix}/lib/;" ${worksrcpath}/config/mh-darwin
}

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

# 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

build.type      gnu

use_parallel_build  no

test.run        yes
test.target     check

post-destroot {
    foreach dylib [glob -type f ${destroot}${prefix}/lib/*.dylib] {
        file attributes ${dylib} -permissions 0755
    }

    # The following line is a workaround to avoid installing improper (stub) version of libsicudata.a.
    xinstall -m 0644 ${worksrcpath}/lib/libsicudata.a ${destroot}${prefix}/lib

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

universal_variant no

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://download.icu-project.org/files/${my_name}/
livecheck.regex { (\d+(?:\.\d+)*)/}
