# $Id: Portfile,v 1.4 2006/07/19 09:00:38 takanori Exp $

PortSystem      1.0
name            mecab
version         0.92
categories      textproc japanese
maintainers     rsky0711@gmail.com
platforms       darwin
description     MeCab is a yet another part-of-speech and morphological analyzer.
long_description ${description}
homepage        http://mecab.sourceforge.jp/

set sfj         20917
set sfj_dic     20904
set dic_name    mecab-ipadic
set dic_version 2.7.0-20060707
set dictionary  ${dic_name}-${dic_version}
set charset     euc-jp

distfiles-append ${dictionary}${extract.suffix}:ipadic

master_sites    http://osdn.dl.sourceforge.jp/mecab/${sfj}/ \
                http://keihanna.dl.sourceforge.jp/mecab/${sfj}/ \
                http://qgpop.dl.sourceforge.jp/mecab/${sfj}/ \
                http://osdn.dl.sourceforge.jp/mecab/${sfj_dic}/:ipadic \
                http://keihanna.dl.sourceforge.jp/mecab/${sfj_dic}/:ipadic \
                http://qgpop.dl.sourceforge.jp/mecab/${sfj_dic}/:ipadic
checksums \
        ${distname}${extract.suffix} \
                md5    381dd3e289647a2cf6df0a1f3e782609 \
                sha1   74e1549c6334beb58a0423c25a8d430cb0ca7d2f \
                rmd160 07b1947c9695271d157a0caf924891dd74988e9c \
        ${dictionary}${extract.suffix} \
                md5    45b9f822700ad4eceb6722d6edcc2a46 \
                sha1   373be900f9be22957636acc54f120fea013f8818 \
                rmd160 cf2f7ad97e50cae6d0a9e9f13bc9328aeab33304

depends_lib     port:libiconv

patchfiles      patch-configure.diff

configure.args  --mandir=${prefix}/share/man \
                --with-libiconv-prefix=${prefix}
configure.env   CPPFLAGS="-I${prefix}/include" LDFLAGS="-L${prefix}/lib"

post-extract {
    # Makefile.in (dictionary)
    reinplace s|@MECAB_DICT_INDEX@|${destroot}${prefix}/libexec/mecab/mecab-dict-index|g \
        ${workpath}/${dictionary}/Makefile.in
}

post-destroot {
    system "cd ${workpath}/${dictionary}; \
        ./configure \
            --with-mecab-config=${destroot}${prefix}/bin/mecab-config \
            --with-charset=${charset} && \
        DYLD_LIBRARY_PATH=\"${destroot}${prefix}/lib\" ${build.cmd} && \
        ${destroot.cmd} install ${destroot.destdir}"
}

post-activate {
    system "ranlib ${prefix}/lib/libmecab.a"
}

platform darwin 7 {
    configure.env-append    MACOSX_DEPLOYMENT_TARGET=10.3
}

platform darwin 8 {
    configure.env-append    MACOSX_DEPLOYMENT_TARGET=10.4 \
                            CC=/usr/bin/gcc-4.0 CXX=/usr/bin/g++-4.0
}

variant sjis conflicts utf8 utf8only {
    set charset shift_jis
}

variant utf8 conflicts sjis utf8only {
    set charset utf8
}

variant utf8only conflicts sjis utf8 {
    set charset utf8
    configure.args-append   --enable-utf8-only
}
