# $Id: Portfile 60534 2009-11-14 23:10:00Z ryandesign@macports.org $

PortSystem              1.0

name                    lua
version                 5.1.4
categories              lang
platforms               darwin
maintainers             pmq openmaintainer

description             powerful, lightweight programming language
long_description        Lua is a powerful, light-weight programming language \
			designed for extending applications. Lua is also frequently \
			used as a general-purpose, standalone language.

homepage                http://www.lua.org
master_sites		${homepage}/ftp/
checksums               sha1 2b11c8e60306efb7f0734b747588f57995493db7 \
			rmd160 c867c8364295d3e4fb4e4d8ebb27fa2b2312cdef

depends_lib		port:readline
build.target		macosx

test.run		yes
test.env		DYLD_LIBRARY_PATH=./lib

post-patch {
	reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/Makefile
	reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/src/luaconf.h
	reinplace "s|/man/man1|/share/man/man1|g" ${worksrcpath}/Makefile

	# for the pkgconfig file
	reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/etc/lua.pc
}

configure {
	set myldflags ${configure.ldflags}
	set cflags "${configure.cflags} ${configure.cppflags}"

	if {[variant_isset universal]} {
		set myldflags "${myldflags} ${configure.universal_ldflags}"
		set cflags "${cflags} ${configure.universal_cflags} ${configure.universal_cppflags}"
	}

	reinplace -E "/^MYLDFLAGS=/s|\$| ${myldflags}|" ${worksrcpath}/src/Makefile
	reinplace -E "/^CFLAGS=/s|\$| ${cflags}|" ${worksrcpath}/src/Makefile
	reinplace "s|CC= .*\$|CC= ${configure.cc}|" ${worksrcpath}/src/Makefile
}

use_parallel_build  yes

destroot.target	install INSTALL_TOP=${destroot}${prefix}
post-destroot {
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 ${worksrcpath}/README ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 ${worksrcpath}/COPYRIGHT ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 ${worksrcpath}/HISTORY ${destroot}${prefix}/share/doc/${name}
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/html
	foreach html [glob ${worksrcpath}/doc/*.html ${worksrcpath}/doc/*.gif] {
		xinstall -m 0644 ${html} ${destroot}${prefix}/share/doc/${name}/html
	}
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/test
	foreach test [glob ${worksrcpath}/test/README ${worksrcpath}/test/*.lua] {
		xinstall -m 0644 ${test} ${destroot}${prefix}/share/doc/${name}/test
	}
	xinstall -d -m 0755 ${destroot}${prefix}/lib/pkgconfig
	xinstall -m 0644 ${worksrcpath}/etc/lua.pc ${destroot}${prefix}/lib/pkgconfig/lua.pc
}

livecheck.type  regex
livecheck.url   ${master_sites}
livecheck.regex {lua-(\d+(?:\.\d+)*)}
