# $Id: Portfile 50984 2009-05-14 21:08:43Z and.damore@macports.org $

PortSystem      1.0
PortGroup       ruby 1.0
name            rb-hyperestraier
version         1.4.10
maintainers     gmail.com:rsky0711
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 cf4ca3dea77d161517388050654b52a6 \
                sha1 d9e200cf237e46315df5a729bc00920e0debfc0d \
                rmd160 56022db14947c00e5f8c01834173ae3bc5daeab8

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
}
