# Template build file for 'ruby'.
_ruby_ver=2.0.0
_ruby_distpatchver=p481
_ruby_distver="${_ruby_ver}-${_ruby_distpatchver}"

pkgname=ruby
version="${_ruby_ver}${_ruby_distpatchver}"
revision=1
wrksrc="${pkgname}-${_ruby_distver}"
build_style=gnu-configure
configure_args="--enable-shared --disable-rpath
 DOXYGEN=/usr/bin/doxygen DOT=/usr/bin/dot PKG_CONFIG=/usr/bin/pkg-config"
short_desc="Ruby programming language"
homepage="http://www.ruby-lang.org/en/"
maintainer="Juan RP <xtraeme@gmail.com>"
license="BSD"
distfiles="ftp://ftp.ruby-lang.org/pub/ruby/2.0/$pkgname-${_ruby_distver}.tar.bz2"
checksum=0762dad7e96d8091bdf33b3e3176c2066fbf3dc09dfe85fbf40e74e83c63d8e2

hostmakedepends="pkg-config bison groff doxygen graphviz"
makedepends="zlib-devel readline-devel>=6.3 libffi-devel openssl-devel
 gdbm-devel libyaml-devel pango-devel"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" ruby>=${version} ruby-rdoc>=${version} ruby-ri>=${version}"
fi

pre_build() {
	# Force getaddrinfo detection.
	sed -e 's,\(checking_for("wide getaddrinfo") {try_\)run,\1link,' -i ext/socket/extconf.rb
	# Fix for readline>=6.3
	sed -e 's,(Function \*),,g' -i ext/readline/readline.c
}

ruby-devel-docs_package() {
	short_desc+=" - HTML C API documentation files"
	noarch=yes
	pkg_install() {
		vmove usr/share/doc
	}
}

ruby-devel_package() {
	depends="ruby-${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove usr/lib/ruby/2.0.0/mkmf.rb
		vmove usr/lib/pkgconfig
	}
}

ruby-gems_package() {
	depends="ruby-rdoc>=${version}"
	short_desc="Package management framework for Ruby libraries/applications"
	noarch=yes
	pkg_install() {
		vmove usr/bin/gem
		vmove usr/lib/ruby/gems
	}
}

ruby-irb_package() {
	depends="ruby"
	short_desc="Interactive Ruby"
	noarch=yes
	pkg_install() {
		vmove usr/bin/irb
		vmove usr/lib/ruby/2.0.0/irb
		vmove "usr/share/man/man1/irb*"
	}
}

ruby-rdoc_package() {
	depends="ruby-irb>=${version}"
	short_desc="Generate documentation from Ruby source files"
	noarch=yes
	pkg_install() {
		vmove usr/bin/rdoc
		vmove usr/lib/ruby/2.0.0/rdoc
	}
}

ruby-ri_package() {
	depends="ruby-rdoc>=${version}"
	short_desc="Ruby Interactive reference"
	noarch=yes
	pkg_install() {
		vmove usr/bin/ri
		vmove usr/share/ri
		vmove "usr/share/man/man1/ri*"
	}
}
