# $Id: Portfile,v 1.1 2006/07/19 08:24:34 takanori Exp $

PortSystem      1.0
PortGroup       ruby 1.0
name            rb-hyperestraier
version         1.3.3
maintainers     rsky0711@gmail.com
platforms       darwin
description     Ruby binding of Hyper Estraier
long_description ${description}

homepage        http://hyperestraier.sourceforge.net/
master_sites    http://hyperestraier.sourceforge.net/
dist_subdir     hyperestraier
distname        hyperestraier-${version}
worksrcdir      hyperestraier-${version}/rubynative
checksums       md5    d2c544f48b8b92a62d7028c68736ce40 \
                sha1   857dba712fd30be7e8d0fbec5ea0a150664522e6 \
                rmd160 834f401f02231a5f48c7b8354d8ab8599d82155b

categories      ruby textproc
depends_lib     port:ruby port:hyperestraier

post-extract {
    # configure
    reinplace "s|\$HOME|${prefix}|g" \
        ${worksrcpath}/configure
    reinplace "s|\"sitelibdir\"|\"sitearchdir\"|g" \
        ${worksrcpath}/configure
    # Makefile.in
    reinplace "s|\$(HOME)|${prefix}|g" \
        ${worksrcpath}/Makefile.in
    reinplace "s|MYRBLIBS = estraier\.so|MYRBLIBS = estraier.bundle|g" \
        ${worksrcpath}/Makefile.in
    # estcmd.rb
    reinplace "s|/usr/bin/ruby|${ruby.bin}|g" \
        ${worksrcpath}/estcmd.rb

    if { [variant_isset p2p] } {
        # configure
        reinplace "s|\$HOME|${prefix}|g" \
            ${workpath}/${distname}/rubypure/configure
        # Makefile.in
        reinplace "s|@RUBY@|${ruby.bin}|g" \
            ${workpath}/${distname}/rubypure/Makefile.in
        # estcall.rb
        reinplace "s|/usr/bin/ruby|${ruby.bin}|g" \
            ${workpath}/${distname}/rubypure/estcall.rb
    }
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}/examples
    xinstall -m 644 ${worksrcpath}/overview \
        ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath}/example \
        example001.rb example002.rb \
        ${destroot}${prefix}/share/doc/${name}/examples

    if { [variant_isset p2p] } {
        system "cd ${workpath}/${distname}/rubypure; \
            ./configure --prefix=${prefix} && \
            ${build.cmd} && \
            ${destroot.cmd} install ${destroot.destdir}"

        xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}/p2p/examples
        xinstall -m 644 ${workpath}/${distname}/rubypure/overview \
            ${destroot}${prefix}/share/doc/${name}/p2p
        xinstall -m 644 -W ${workpath}/${distname}/rubypure/example \
            example001.rb example002.rb \
            ${destroot}${prefix}/share/doc/${name}/p2p/examples
    }
}

variant p2p {
    categories-append   net
}
