# -*- 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 113834 2013-11-24 16:24:02Z hum@macports.org $

PortSystem          1.0

set dicname         jumandic
name                mecab-${dicname}
version             7.0-20130310
categories          textproc japanese
maintainers         hum openmaintainer

set encoding        eucjp
set nkf_encoding    e

subport mecab-${dicname}-sjis {
    set encoding     sjis
    set nkf_encoding s   
    livecheck.type   none
}

subport mecab-${dicname}-utf8 {
    set encoding    utf8
    livecheck.type  none
}

description         ${dicname} of ${encoding} encoding for MeCab
long_description    ${description}

homepage            https://code.google.com/p/mecab/
platforms           darwin
license             BSD

dist_subdir         mecab

master_sites        googlecode:mecab
checksums           rmd160  3f5009263fcfa609c3f19f0e64b8c5f8a1b3afbe \
                    sha256  eaf216758edee9a159bc3d02507007318686b9537943268c4565cc1f9ef07f15

depends_lib         port:mecab-base

if {${encoding} != "utf8"} {
    depends_build   port:nkf
}

supported_archs     noarch

post-extract {
    # ignore invalid entries in AuxV.csv.
    file rename ${worksrcpath}/AuxV.csv ${worksrcpath}/AuxV.csv.orig
    system -W ${worksrcpath} "head -n 587 AuxV.csv.orig > AuxV.csv"
    # convert character encoding of dic and def files if the target is other than utf8.
    if {${encoding} != "utf8"} {
        foreach f [glob ${worksrcpath}/*.csv ${worksrcpath}/*.def] {
            system "nkf --in-place -${nkf_encoding} ${f}"
        }
        reinplace -locale C -W ${worksrcpath} "s|utf-8|${encoding}|" Makefile.in
        reinplace -locale C -W ${worksrcpath} "s|charset: utf8|charset: ${encoding}|" model.def
    }
}

configure.args      --with-mecab-config=${prefix}/bin/mecab-config \
                    --with-charset=${encoding} \
                    --with-dicdir=${prefix}/lib/mecab/dic/${dicname}-${encoding}
