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

name                mecab
version             0.996
categories          textproc japanese
maintainers         nomaintainer

set encoding        eucjp

subport mecab-sjis {
    set encoding    sjis
    conflicts       mecab mecab-utf8
    livecheck.type  none
}

subport mecab-utf8 {
    set encoding    utf8
    conflicts       mecab mecab-sjis
    livecheck.type  none
}

description         yet another part-of-speech and morphological analyzer
long_description    MeCab is {*}${description}. \
                    This port depends on MeCab base analyzer and a Japanese \
                    dictionary of ${encoding} encoding.

homepage            http://taku910.github.io/mecab/
platforms           any
license             {GPL LGPL BSD}

distfiles

depends_lib         port:mecab-base

conflicts           mecab-sjis mecab-utf8

use_configure       no
supported_archs     noarch

build               {}

set dicname         ipadic

variant ipadic conflicts jumandic naistjdic unidic neologd description {Use ipadic} {
    set dicname         ipadic
    if {${encoding} == "eucjp"} {
        depends_lib-append  port:mecab-${dicname}
    } else {
        depends_lib-append  port:mecab-${dicname}-${encoding}
    }
}

variant jumandic conflicts ipadic naistjdic unidic neologd description {Use jumandic} {
    set dicname         jumandic
    if {${encoding} == "eucjp"} {
        depends_lib-append  port:mecab-${dicname}
    } else {
        depends_lib-append  port:mecab-${dicname}-${encoding}
    }
}

variant naistjdic conflicts ipadic jumandic unidic neologd description {Use naist-jdic} {
    set dicname         naist-jdic
    if {${encoding} == "eucjp"} {
        depends_lib-append  port:mecab-${dicname}
    } else {
        depends_lib-append  port:mecab-${dicname}-${encoding}
    }
}

if {${encoding} == "utf8"} {
    variant unidic conflicts ipadic jumandic naistjdic neologd description {Use unidic} {
        set dicname         unidic
        depends_lib-append  port:unidic-mecab
    }

    variant neologd conflicts ipadic jumandic naistjdic unidic description {Use neologd} {
        set dicname         neologd
        depends_lib-append  port:mecab-ipadic-neologd
    }
}

if {([variant_isset unidic] || [variant_isset neologd]) && ${encoding} != "utf8"} {
    ui_error "Please install 'mecab-utf8' to use 'unidic' or 'neologd'." 
    error "invalid variant"
}

variant sjis description {Deprecated, install mecab-sjis instead} {
    ui_msg "Deprecated: please install 'mecab-sjis' instead of 'mecab +sjis'."
    ui_msg "Note: upgrading mecab will be completed if mecab-sjis is successfully installed, although the process fails due to a conflict."
    depends_lib         port:mecab-sjis
}

variant utf8 description {Deprecated, install mecab-utf8 instead} {
    ui_msg "Deprecated: please install 'mecab-utf8' instead of 'mecab +utf8'."
    ui_msg "Note: upgrading mecab will be completed if mecab-utf8 is successfully installed, although the process fails due to a conflict."
    depends_lib         port:mecab-utf8
}

if {![variant_isset jumandic] && ![variant_isset naistjdic] &&
    ![variant_isset unidic] && ![variant_isset neologd]} {
    default_variants    +ipadic
}

destroot {
    set dest_dic ${destroot}${prefix}/lib/mecab/dic
    file mkdir ${dest_dic}
    ln -s ${dicname}-${encoding} ${dest_dic}/sysdic
}

livecheck.type      none
