# -*- 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

PortSystem          1.0

set dicname         naist-jdic
set encoding        sjis
set nkf_encoding    s
name                chasen-${dicname}-${encoding}
version             0.4.3
categories          textproc japanese
maintainers         nomaintainer
homepage            http://sourceforge.jp/projects/${dicname}/
description         NAIST Japanese dictionary of Shift-JIS encoding for ChaSen
long_description    {*}${description}
platforms           any
license             BSD

dist_subdir         chasen
distname            ${dicname}-${version}

master_sites        sourceforge_jp:${dicname}/31880

checksums           rmd160  6d32e07e9fce6096a93603d148b6ee71a0a912c9 \
                    sha256  f4b830877b51c770cb8491efb6e7bccf0c9011d3682351e5507eb864b0729bb1

depends_build       port:nkf
depends_lib         port:chasen-base

if {[file exists ${prefix}/share/doc/chasen/chasen_dartsclone]} {
    default_variants    +dartsclone
}

variant dartsclone description {Use darts-clone instead of darts} {}

supported_archs     noarch
configure.args      --with-chasenrc-path=${destroot}${prefix}/etc/chasen/chasenrc-${dicname}-${encoding}

pre-configure {
    if {[variant_isset dartsclone]} {
        set dartslib "dartsclone"
    } else {
        set dartslib "darts"
    }
    if {![file exists ${prefix}/share/doc/chasen/chasen_${dartslib}]} {
        return -code error "The variant you chose is not compatible with the ChaSen you've installed."
    }
}

use_parallel_build  no

post-patch {
    reinplace "s|PACKAGE=${dicname}|PACKAGE=${dicname}-${encoding}|" ${worksrcpath}/configure
    reinplace "s|/makemat|/makemat -i ${nkf_encoding}|"              ${worksrcpath}/Makefile.in
    reinplace "s|/makeda|/makeda -i ${nkf_encoding}|"                ${worksrcpath}/Makefile.in
    foreach f [glob ${worksrcpath}/*.cha ${worksrcpath}/*.dic ${worksrcpath}/chasenrc.in] {
        move ${f} ${f}_
        system "${prefix}/bin/nkf -E -${nkf_encoding} ${f}_ > ${f}"
        delete ${f}_
    }
}

pre-destroot {
    file mkdir ${destroot}${prefix}/etc/chasen
}

livecheck.type      none
