# Lua has no configure step: its module search path is compiled in
# from LUA_ROOT, so point it at PREFIX.
prepare() {
	sed -i "s|^\(#define LUA_ROOT[[:space:]]*\)\"/usr/local/\"|\1\"$PREFIX/\"|" src/luaconf.h
	grep -q "^#define LUA_ROOT[[:space:]]*\"$PREFIX/\"" src/luaconf.h
}

# -fPIC: liblua.a is the only library (upstream builds no shared one) and
# programs that embed it (Hyprland) are position-independent.
compile() {
	make linux MYCFLAGS="${CFLAGS:--O2} -fPIC" MYLDFLAGS="$LDFLAGS"
}

# Upstream ships no pkg-config file; programs look for lua.pc.
package() {
	make install INSTALL_TOP="$DESTDIR$PREFIX" INSTALL_MAN="$DESTDIR$PREFIX/share/man/man1"
	mkdir -p "$DESTDIR$PREFIX/lib/pkgconfig"
	cat > "$DESTDIR$PREFIX/lib/pkgconfig/lua.pc" <<EOP
prefix=$PREFIX
libdir=\${prefix}/lib
includedir=\${prefix}/include

Name: Lua
Description: Lua scripting language
Version: $VER
Libs: -L\${libdir} -llua -lm
Cflags: -I\${includedir}
EOP
}
