# -*- 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 87366 2011-11-18 23:08:38Z hum@macports.org $

PortSystem          1.0

name                chasen
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    ChaSen is a tool to analyze a text according to a set of dictionaries that \
                    specifies grammar, part of speech of words, and so on. \
                    This port depends on ChaSen base analyzer and a Japanese dictionary.

distfiles

depends_lib         port:chasen-base

use_configure       no
supported_archs     noarch

build {}

variant eucjp description {Enable EUC-JP encoding} {}

variant utf8 description {Add chasen-utf8 for UTF-8 texts} {
    post-destroot {
        set encoding     utf8
        set nkf_encoding w
        set script  ${destroot}${prefix}/bin/chasen-${encoding}
        xinstall -m 755 ${filespath}/chasen.in         ${script}
        reinplace "s|@NKF_ENCODING@|${nkf_encoding}|"  ${script}
        reinplace "s|@RC_FILE@|${prefix}/etc/chasen/chasenrc-${encoding}|" \
            ${script}
    }
    notes-append  "You can run 'chasen-utf8' for UTF-8 texts."
}

variant sjis description {Add chasen-sjis for Shift-JIS texts} {
    post-destroot {
        set encoding     sjis
        set nkf_encoding s
        set script  ${destroot}${prefix}/bin/chasen-${encoding}
        xinstall -m 755 ${filespath}/chasen.in         ${script}
        reinplace "s|@NKF_ENCODING@|${nkf_encoding}|"  ${script}
        reinplace "s|@RC_FILE@|${prefix}/etc/chasen/chasenrc-${encoding}|" \
            ${script}
    }
    notes-append  "You can run 'chasen-sjis' for Shift-JIS texts."
}

default_variants    +eucjp +utf8

set dicname         ipadic

variant ipadic conflicts naistjdic description {Use ipadic} {
    set dicname         ipadic
    if {[variant_isset eucjp]} {
        depends_lib-append  port:chasen-${dicname}
    }
    foreach encoding {utf8 sjis} {
        if {[variant_isset ${encoding}]} {
            depends_lib-append  port:chasen-${dicname}-${encoding}
        }
    }
}

variant naistjdic conflicts ipadic description {Use naist-jdic} {
    set dicname         naist-jdic
    if {[variant_isset eucjp]} {
        depends_lib-append  port:chasen-${dicname}
    }
    foreach encoding {utf8 sjis} {
        if {[variant_isset ${encoding}]} {
            depends_lib-append  port:chasen-${dicname}-${encoding}
        }
    }
}

if {![variant_isset naistjdic]} {
    default_variants    +ipadic
}

destroot {
    set dest_chasen ${destroot}${prefix}/etc/chasen
    file mkdir ${dest_chasen}
    ln -s chasenrc-${dicname} ${dest_chasen}/chasenrc
    foreach encoding {utf8 sjis} {
        if {[variant_isset ${encoding}]} {
            ln -s chasenrc-${dicname}-${encoding} ${dest_chasen}/chasenrc-${encoding}
        }
    }
}

livecheck.type  none
