# $Id: Portfile 89962 2012-02-17 12:13:09Z kimuraw@macports.org $

PortSystem		1.0
PortGroup		muniversal 1.0

name			ruby
version			1.8.7-p358
revision		0

categories		lang ruby
maintainers		kimuraw

description		Powerful and clean object-oriented scripting language
long_description	Ruby is the interpreted scripting language for quick \
					and easy object-oriented programming. It has many \
					features to process text files and to do system \
					management tasks (as in Perl). It is simple, \
					straight-forward, extensible, and portable.
homepage		http://www.ruby-lang.org/
license			{Ruby GPL-2}
master_sites	ruby:1.8
				
dist_subdir		ruby
checksums       md5 de35f00997f4ccee3e22dff0f2d01b8a \
				rmd160 7196a000d39e4cd24e7911839c828642d54377bd \
				sha1 2b78dc421cfbca81ef1375a1c3da9f0f70c548fa

use_bzip2		yes

platforms		darwin

depends_lib		port:libiconv \
				port:readline \
				port:openssl \
				port:zlib \
				port:ncurses \
				port:gdbm

# vendordir: enable vendor-specific.rb
# #3604: gcc4 fails to detect linking at configure
# #19050: use $(CC) not cc, this change has been merged at ruby-1.8 trunk
# #15528: on some Mac, TCPServer.open("localhost", 0) raises SocketError
#         like "getaddrinfo: nodename nor servname provided, or not
#         known (SocketError)"
# c99: gperf generates code that doesn't work with clang (https://trac.macports.org/ticket/29974)
patchfiles		patch-vendordir.diff \
				patch-bug3604.diff \
				patch-bug19050.diff \
				patch-bug15528.diff \
				patch-c99.diff

# ignore getcontext() and setcontext()
# on 10.5, these functions have some problems (SEGV on ppc, slower than 1.8.6)
# http://chopine.be/lrz/ruby-osx-patches/ignore-gsetcontext.diff
patchfiles-append patch-node.h.diff

use_parallel_build		no

# #30275: ruby built with clang or llvm-gcc does not work
# see list "MacPorts on Lion (common issues, fixes, and workarounds)"
# http://lists.macosforge.org/pipermail/macports-dev/2011-July/015263.html
if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler gcc-4.2
} elseif {${configure.compiler} == "clang"} {
    depends_build-append port:apple-gcc42
    configure.compiler apple-gcc-4.2
    # base (as of 2.0.3) doesn't set cxx for apple-gcc-4.2
    configure.cxx ${prefix}/bin/g++-apple-4.2
}

configure.args	--enable-shared \
				--mandir="${prefix}/share/man" \
				--enable-pthread \
				--without-tk \
				--with-vendordir=${prefix}/lib/ruby/vendor_ruby \
				--with-opt-dir=${prefix}
# ignore minor version for archdir, like i686-darwin9
configure.env	UNAME_RELEASE=${os.major}

if {[variant_isset universal]} {
	# NOTE: directory layout of port:ruby +universal
	#   universal binary
	#     - bin/
	#     - lib/libruby*.dylib, libruby-static.a
	#   single architecture modules and headers, such as ruby.h or config.h
	#     - lib/ruby/[1.8|site_ruby/1.8|vendor_ruby/1.8]/x86_64-apple-darwin*/
	#     -                                             /i386-apple-darwin*/
	#     -                                             /ppc-apple-darwin*/
	#   pure ruby libraries
	#     - lib/ruby/[1.8|site_ruby/1.8|vendor_ruby/1.8]/
	foreach arch ${universal_archs} {
		append merger_configure_env(${arch}) "ARCH_FLAG=\"-arch ${arch}\" "
		# force environment "ac_cv_build" to specify locations of extension
		# modules(*.bundle), headers(ruby.h, config.h, ..) and rbconfig.rb.
		# like this:
		#   i386   -> ${prefix}/lib/ruby/1.8/i386-apple-darwin10/
		#   x86_64 ->                       /x86_64-apple-darwin10/
		set cpu_type ${arch}
		append merger_configure_env(${arch}) \
			"ac_cv_build=\"${cpu_type}-apple-darwin${os.major}\" "
	}
} elseif {[info exists build_arch] && ${build_arch} != ""} {
	configure.env-append ARCH_FLAG="-arch ${build_arch}"
}

destroot.target	install install-doc
post-destroot {
	foreach type {site vendor} {
		set libdir ${destroot}${prefix}/lib/ruby/${type}_ruby/1.8
		xinstall -m 0755 -d ${libdir}
		
		# special file for installation control of modules
		xinstall -m 0644 ${filespath}/${type}-specific.rb ${libdir}
		
		# prevent empty site/vendor directories from being pruned
		foreach subdir [exec find ${libdir} -type d -empty] {
			destroot.keepdirs-append ${subdir}
		}
	}
    # error at activate, for these case sensitive files
	foreach rdoc {Exception2MessageMapper/fail-i.yaml \
				  REXML/Parsers/XPathParser/predicate-i.yaml} {
		if {[file exists ${destroot}${prefix}/share/ri/1.8/system/${rdoc}]} {
			delete ${destroot}${prefix}/share/ri/1.8/system/${rdoc}
		}
	}
}

platform darwin {
	# for proper rdoc/ri creation, make sure to link to destroot libruby.dylib
	destroot.env	DYLD_LIBRARY_PATH=${destroot}${prefix}/lib
}

variant tk conflicts mactk description "enable tk support" {
	configure.args-delete	--without-tk
	configure.args-append	--with-tk
	depends_lib-append		port:tcl port:tk
}

variant mactk conflicts tk description "enable MacTk (Tk.framework without X11) support" {
	configure.args-delete	--without-tk
	configure.args-append	--enable-tcltk-framework
}

variant thread_hooks description "apply Apple's thread_hooks patch" {
	patchfiles-append		patch-thread-hooks.diff
}

variant no_doc description "do not install rdoc documents" {
	destroot.target-delete	install-doc
}

variant dtrace description "enable dtrace support" {
	# from http://www.opensource.apple.com/source/ruby/ruby-79/
	patchfiles-append		patch-apple-dtrace.diff
	configure.cflags-append	-DENABLE_DTRACE
	post-patch {
		system "cd ${worksrcpath} && dtrace -h -s ${filespath}/dtrace.d -o dtrace.h"
	}
}

default_variants	+thread_hooks

livecheck.type	regex
livecheck.url	http://ftp.ruby-lang.org/pub/ruby/1.8/
livecheck.regex	{ruby-(\d+(?:\.\d+)*(?:-p\d+))}

test.run	yes
