# -*- 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: Portfile 89810 2012-02-11 08:55:39Z and.damore@macports.org $

PortSystem          1.0

name                chasen-base
version             2.3.3
epoch               1
categories          textproc japanese
platforms           darwin
maintainers         takanori hum openmaintainer
license             BSD

homepage            http://chasen-legacy.sourceforge.jp/
description         Japanese morphological analysis system
long_description    The base analyzer of ChaSen, ${description}.

dist_subdir         chasen
distname            chasen-${version}

master_sites        sourceforge_jp:chasen-legacy/24339
checksums           rmd160  2f2416f82fb0341023314a4672e442fed86207a9 \
                    sha256  a91b422398f30c9c6c2d27fdbcc1aeb8e026ded44d6e729fc060d5d18bfaefdb

# chasen-2.3.3-2003082[12].patch are official patches taken from http://chasen.aist-nara.ac.jp/stable/chasen/
# see http://chasen.naist.jp/hiki/ChaSen/?%A5%D0%A5%B0%BE%F0%CA%F3
patchfiles          chasen-2.3.3.20030821.patch \
                    chasen-2.3.3.20030822.patch \
                    patch-configure.diff \
                    patch-lib.diff \
                    patch-mkchadic.diff

depends_build       port:darts
depends_lib         port:libiconv

variant dartsclone description {Use darts-clone instead of darts} {
    depends_build-replace    s|port:darts|port:darts-clone|
}

post-extract {
    foreach f {tests/test-chasen.sh tests/test-dic.sh} {
        file attributes ${worksrcpath}/${f} -permissions 0755
    }
}

configure.args      --libexecdir=${prefix}/lib \
                    --sysconfdir=${prefix}/etc/chasen \
                    --with-darts=${prefix}/include \
                    --with-libiconv=${prefix}

test.run            yes
test.target         check

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/chasen
    file mkdir ${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS COPYING ChangeLog NEWS README doc/manual-j.pdf \
        ${docdir}

    if {[variant_isset dartsclone]} {
        set dartslib "dartsclone"
    } else {
        set dartslib "darts"
    }
    # this file indicates which version of chasen is installed
    set fh [open [file join ${docdir} chasen_${dartslib}] w 0644]
    puts ${fh} "This version of ChaSen depends on the ${dartslib} library."
    close ${fh}
}

# deactivate any old chasen port.
pre-activate {
    if {[file exists ${prefix}/bin/chasen]
        && ![catch {set vers [lindex [registry_active chasen] 0]}]
        && ([vercmp [lindex $vers 1] 2.4.4] < 0 ||
            [vercmp [lindex $vers 1] 2.4.4] == 0
            && [vercmp [lindex $vers 2] 1] < 1)} {
        registry_deactivate chasen "" [list ports_nodepcheck 1]
    }
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     >chasen-(\[0-9.a-z\-\]+)<
