# Template file for 'lua55'
pkgname=lua55
version=5.5.0
revision=1
makedepends="readline-devel"
short_desc="Powerful, fast, lightweight, embeddable scripting language (5.5.x)"
maintainer="Jose Arellano <jose.4rellano@gmail.com>"
license="MIT"
homepage="https://www.lua.org"
distfiles="https://www.lua.org/ftp/lua-${version}.tar.gz"
checksum=57ccc32bbbd005cab75bcc52444052535af691789dba2b9016d5c50640d68b3d
alternatives="
 lua:lua:/usr/bin/lua5.5
 lua:luac:/usr/bin/luac5.5
 lua:lua.1:/usr/share/man/man1/lua5.5.1
 lua:luac.1:/usr/share/man/man1/luac5.5.1
"
do_build() {
	sed -i src/Makefile -r \
		-e '/^LUA_(SO|A|T)=/ s;lua;lua5.5;' \
		-e '/^LUAC_T=/ s;luac;luac5.5;'
	make MYCFLAGS="$CFLAGS -fPIC -DLUA_USE_READLINE" MYLDFLAGS="$LDFLAGS" \
		MYLIBS="-lreadline" \
		CMCFLAGS="" CC="$CC" RANLIB="$RANLIB" \
		INSTALL_DATA="cp -d" LUA_SO=liblua5.5.so ${makejobs} linux
}
do_install() {
	make INSTALL_DATA="cp -d" INSTALL_TOP="${DESTDIR}/usr" \
		TO_BIN="lua5.5 luac5.5" \
		TO_LIB="liblua5.5.a liblua5.5.so liblua5.5.so.${version%.*} liblua5.5.so.${version}" \
		INSTALL_INC="${DESTDIR}/usr/include/lua5.5" \
		INSTALL_MAN="${DESTDIR}/usr/share/man/man1" install
	sed ${FILESDIR}/lua.pc \
		-e "s;%VER%;${version%.*};g;s;%REL%;${version};g" \
		> lua5.5.pc
	vinstall lua5.5.pc 644 usr/lib/pkgconfig
	# Install the documentation
	rm -f doc/*.1
	vmkdir usr/share/doc/lua5.5
	cp -R doc/* ${DESTDIR}/usr/share/doc/lua5.5
	vlicense doc/readme.html
	# Rename man pages
	mv ${DESTDIR}/usr/share/man/man1/lua{,5.5}.1
	mv ${DESTDIR}/usr/share/man/man1/luac{,5.5}.1
}
lua55-devel_package() {
	depends="lua55>=${version}_${revision}"
	short_desc+=" - development files"
	alternatives="
	 lua-devel:lua:/usr/share/doc/lua5.5
	 lua-devel:lua.pc:/usr/lib/pkgconfig/lua5.5.pc
	"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
		vmove usr/share/doc
	}
}
