# $Id: Portfile 85969 2011-10-17 23:02:38Z takanori@macports.org $

PortSystem      1.0

name            lookup
set ver_main    1.4
set ver_media   20110625
version         ${ver_main}-media-${ver_media}
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} md5     2873617afb6b630521543fefcad2837e \
                                                                        sha1    b70a66ff0b045f1e17e23005a27aae135ed79518 \
                                                                        rmd160  965c19d5905c82b61872283b191d11709643ff35 \
                texinfo.tex md5 7ca3fd1e1070bc3c169782874283757d \
                            sha1 c28232842fb669c328fd79954ea288ff7c1aa595 \
                            rmd160 c5db8b73738942572423eb39dbe21ea91cdd84d2

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:pTeX
    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"
