PortSystem      1.0
PortGroup       ruby 1.0
ruby.setup      hyperestraier 1.4.13 gnu {}
maintainers     nomaintainer
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 847aefb9e23266545280378d797f3981 \
                sha1 21c3f325f42019fef096172105c2fc16f3e72fc0 \
                rmd160 8af0af25df6d5bd45a09e9abfbb26300339b5a2c

categories      ruby textproc
depends_lib     port:ruby port:hyperestraier
# fix old ruby C-API
patchfiles      patch-rubynative-src-estraier.c.diff \
                patch-rubynative-configure.diff

configure.args-append --bindir=${ruby.bindir}
configure.env-append RUBY=${ruby.bin} RDOC=${ruby.rdoc} HOME=${prefix}

post-extract {
    # 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
}
