# $Id: Portfile 57864 2009-09-17 19:38:15Z blb@macports.org $

PortSystem          1.0
PortGroup           ruby 1.0
set myname          ncurses-ruby
ruby.setup          ${myname} 1.2.3 fetch
revision            1
categories-append   devel
maintainers         nomaintainer
description         Ruby access to ncurses functionality
long_description \
   ncurses-ruby is an extension module that makes the functions and \
   constants of the FSF's ncurses library accessible from the ruby \
   programming language

platforms           darwin

homepage            http://developer.berlios.de/projects/ncurses-ruby
master_sites        http://download.berlios.de/${myname}/ \
                    http://download2.berlios.de/${myname}/
distname            ${myname}-${version}
use_bzip2           yes

checksums           md5     e00bc593fc0dbc6e311e3b6836bb5801 \
                    sha1    156e6e663fc3ecae9b48da8e1227427e583c489a \
                    rmd160  daad8a5044238755c1e79fc2c327e7dfe219733e

depends_lib-append  port:ncurses port:rb-rubygems

# Do a fake gem-like install by first generating a gem, then install it

# Use gemspec from pkgsrc
# http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/devel/ruby-ncurses/files/gemspec
post-extract {
   copy ${filespath}/${myname}.gemspec ${worksrcpath}
}

use_configure       no

build {
   system "cd ${worksrcpath} && ${ruby.gem} build ${myname}.gemspec"
}

destroot {
   # This is basically just copied from the ruby portgroup, with a 
   # change to the gem location since we just built it
   xinstall -d -m 0755 ${destroot}${prefix}/lib/ruby/gems/${ruby.version}
   system "cd ${worksrcpath} && ${ruby.gem} install --local --force --install-dir ${destroot}${prefix}/lib/ruby/gems/${ruby.version} ${worksrcpath}/ncurses-${version}.gem"
   set binDir ${destroot}${prefix}/lib/ruby/gems/${ruby.version}/bin
   if {[file isdirectory $binDir]} {
      foreach file [readdir $binDir] {
         file copy [file join $binDir $file] ${destroot}${prefix}/bin
      }
   }
   # symlink to the vendor location so software expecting a non-gem
   # install can still find it
   set rubyarch [exec ${prefix}/bin/ruby -rrbconfig -e "puts Config::CONFIG\['sitearch'\]"]
   file mkdir ${destroot}${ruby.lib}/${rubyarch}
   set ruby.gemdir ${prefix}/lib/ruby/gems/${ruby.version}/gems
   ln -s ${ruby.gemdir}/ncurses-${version}/lib/ncurses.rb ${destroot}${ruby.lib}
   ln -s ${ruby.gemdir}/ncurses-${version}/lib/ncurses_bin.bundle \
      ${destroot}${ruby.lib}/${rubyarch}
}

