# Template file for 'lua54'
pkgname=lua54
version=5.4.4
revision=1
makedepends="readline-devel"
short_desc="Powerful, fast, lightweight, embeddable scripting language (5.4.x)"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://www.lua.org"
distfiles="https://www.lua.org/ftp/lua-${version}.tar.gz"
checksum=164c7849653b80ae67bec4b7473b884bf5cc8d2dca05653475ec2ed27b9ebf61

alternatives="
 lua:lua:/usr/bin/lua5.4
 lua:luac:/usr/bin/luac5.4
 lua:lua.1:/usr/share/man/man1/lua5.4.1
 lua:luac.1:/usr/share/man/man1/luac5.4.1
"

do_build() {
	sed -i src/Makefile -r \
		-e '/^LUA_(SO|A|T)=/ s;lua;lua5.4;' \
		-e '/^LUAC_T=/ s;luac;luac5.4;'
	make MYCFLAGS="$CFLAGS -fPIC" MYLDFLAGS="$LDFLAGS" \
		CMCFLAGS="" CC="$CC" RANLIB="$RANLIB" \
		INSTALL_DATA="cp -d" LUA_SO=liblua5.4.so ${makejobs} linux-readline
}

do_install() {
	make INSTALL_DATA="cp -d" INSTALL_TOP="${DESTDIR}/usr" \
		TO_BIN="lua5.4 luac5.4" \
		TO_LIB="liblua5.4.a liblua5.4.so liblua5.4.so.${version%.*} liblua5.4.so.${version}" \
		INSTALL_INC="${DESTDIR}/usr/include/lua5.4" \
		INSTALL_MAN="${DESTDIR}/usr/share/man/man1" install

	sed ${FILESDIR}/lua.pc \
		-e "s;%VER%;${version%.*};g;s;%REL%;${version};g" \
		> lua5.4.pc

	vinstall lua5.4.pc 644 usr/lib/pkgconfig

	# Install the documentation
	rm -f doc/*.1
	vmkdir usr/share/doc/lua5.4
	cp -R doc/* ${DESTDIR}/usr/share/doc/lua5.4

	vlicense doc/readme.html

	# Rename man pages
	mv ${DESTDIR}/usr/share/man/man1/lua{,5.4}.1
	mv ${DESTDIR}/usr/share/man/man1/luac{,5.4}.1
}

lua54-devel_package() {
	depends="lua54>=${version}_${revision}"
	short_desc+=" - development files"
	alternatives="
	 lua-devel:lua:/usr/share/doc/lua5.4
	 lua-devel:lua.pc:/usr/lib/pkgconfig/lua5.4.pc
	"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
		vmove usr/share/doc
	}
}
