# -*- 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                lookup
set ver_main        1.4
set ver_media       20121122
version             ${ver_main}-media-${ver_media}
revision            1
categories          textproc japanese
maintainers         nomaintainer
description         Dictionary search interface for Emacs, including the media patch
long_description    ${description}
platforms           darwin
license             GPL-2+
homepage            http://green.ribbon.to/~ikazuhiro/lookup/lookup.html
master_sites        http://green.ribbon.to/~ikazuhiro/lookup/files/:lookup \
                    http://svn.sourceforge.jp/svnroot/macports-jp/distfiles/lookup/:texinfo-jp \
                    ftp://fsci.fuk.kindai.ac.jp/pub/ptex/utils/:texinfo-jp
distfiles           ${name}-${ver_main}+media-${ver_media}${extract.suffix}:lookup

checksums           ${name}-${ver_main}+media-${ver_media}${extract.suffix} \
                    rmd160  1f975a956c769a9eec8e5c513f1b037960dbb389 \
                    sha256  417fb5d854816d0264be55377b960382a833a467364deeffce18d7a44138fe72 \
                    texinfo.tex \
                    rmd160  c5db8b73738942572423eb39dbe21ea91cdd84d2 \
                    sha256  a25a0391f1ad2c9b9d76056676fda0166a334976a12719a857d9ebe66df0c63d

depends_lib         path:bin/emacs:emacs \
                    port:eblook
depends_build       port:texinfo

extract.only        ${name}-${ver_main}+media-${ver_media}${extract.suffix}
worksrcdir          ${name}-${ver_main}+media-${ver_media}

set dir_info        ${prefix}/share/info
configure.args      --infodir=${dir_info}

use_parallel_build  yes

# The following line is a workaround to avoid "Searching for program: unknown error: 0" problem.
build.env           SHELL=/bin/bash

#test.run        yes
#test.target     check

post-destroot {
    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
    set docs {AUTHORS COPYING ChangeLog NEWS README README.org VERSION}
    foreach f ${docs} {
        xinstall -m 644 ${worksrcpath}/${f} ${destroot}${prefix}/share/doc/${name}
    }

    delete ${destroot}${dir_info}/dir
}

# MacPorts does not have post-deactivate phase yet.
#set infos {lookup-guide lookup}
#post-activate {
#    foreach f ${infos} {
#        system "install-info --info-dir=${dir_info} ${prefix}/share/info/${f}.info"
#    }
#}
#post-deactivate {
#    foreach f ${infos} {
#        system "install-info --delete --info-dir=${dir_info} ${prefix}/share/info/${f}.info"
#    }
#}

universal_variant   no

variant emacs_app conflicts carbon_emacs_package description {Use this package with Emacs.app} {
    depends_lib-delete      path:bin/emacs:emacs
    depends_lib-append      path:${applications_dir}/Emacs.app/Contents/MacOS/Emacs:emacs-app
    set dir_info            ${applications_dir}/Emacs.app/Contents/Resources/info
    configure.env           EMACS=${applications_dir}/Emacs.app/Contents/MacOS/Emacs
    configure.args          --with-lispdir=${applications_dir}/Emacs.app/Contents/Resources/site-lisp/lookup \
                            --infodir=${dir_info}
    notes-append "Before using lookup with emacs.app, put \"(setq exec-path (cons \"${prefix}/bin\" exec-path))\" in your .emacs"
}

variant carbon_emacs_package conflicts emacs_app description {Use this package with Carbon Emacs Package} {
    depends_lib-delete      path:bin/emacs:emacs
    set dir_info            /Applications/Emacs.app/Contents/Resources/info
    configure.env           EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
    configure.args          --with-lispdir=/Applications/Emacs.app/Contents/Resources/site-lisp/lookup \
                            --infodir=${dir_info}
    pre-configure {
        if {![file exists /Applications/Emacs.app/Contents/MacOS/Emacs]} {
            return -code error "Before building this port, please install Carbon Emacs Package into /Application folder."
        }
    }
    destroot.violate_mtree  yes
    notes-append "This variant has been deprecated. Please consider using +emacs_app instead."
}

variant ptex description {Build and install PDF documents using pTeX} {
    distfiles-append        texinfo.tex:texinfo-jp
    depends_build-append    port:texlive-lang-japanese \
                            port:texlive-fonts-recommended
    post-extract {
        # this is texinfo.tex 2008-11-25.16 with Japanese support
        copy ${distpath}/texinfo.tex ${worksrcpath}/texi
    }
    post-patch {
        reinplace "s|documentlanguage ja|documentlanguage en|" ${worksrcpath}/texi/lookup.texi
    }
    post-build {
        # A little glitch remains in the concept index page
        # because MacPorts's texinfo isn't jtexinfo (i.e. texinfo with Japanese support.)
        system "cd ${worksrcpath}/texi && ptex -kanji=utf8 lookup.texi && texindex lookup.?? && ptex -kanji=utf8 lookup.texi && dvipdfmx lookup.dvi"
    }
    post-destroot {
        xinstall -m 644 ${worksrcpath}/texi/lookup.pdf ${destroot}${prefix}/share/doc/${name}
    }
}

livecheck.type      regex
livecheck.version   ${ver_main}+media-${ver_media}
livecheck.regex     "${name}-(\[0-9.a-z\+\-\]+).tar.gz"