# $Id: Portfile 57375 2009-09-10 08:16:41Z ryandesign@macports.org $

PortSystem      1.0

name            lookup
set ver_main    1.4
set ver_media   20081205
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
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 00680d7a01805c719ead3f52c80fdc68 \
                                                                        sha1 e11e6fbc54ee6667d05247450212e7947b334cc6 \
                                                                        rmd160 134aef5b9238a9100d53bf481706fa40f2d3bac1 \
                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 with_carbon_emacs_package 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
}

variant with_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 {
        system "cd ${worksrcpath}/texi && ptex lookup.texi && texindex lookup.?? && ptex lookup.texi && dvipdfmx lookup.dvi"
    }
    post-destroot {
        xinstall -m 644 ${worksrcpath}/texi/lookup.pdf ${destroot}/${prefix}/share/doc/${name}
    }
}

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