# Maintainer: PktSurf <smlinux@pktsurf.in>
app=lua
version=5.1.5
build=1sml
homepage="https://www.lua.org/home.html"
download="https://www.lua.org/ftp/lua-$version.tar.gz"
desc="a powerful, fast, light-weight, embeddable scripting language"
requires="readline"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version 
  fixbuilddirpermissions
}

build() {
  sed -i "s@#define LUA_ROOT\t"'"/usr/local/"@#define LUA_ROOT "/"@' src/luaconf.h
  sed -i 's@INSTALL_TOP= /usr/local@INSTALL_TOP='"$dest"'@' Makefile

  make linux CFLAGS="$CFLAGS"

  make linux install \
    CFLAGS="$CFLAGS" \
    INSTALL_TOP="$pkg" \
    INSTALL_MAN="$pkg/share/man/man1"

  # Build the shared library
  mkdir -p shared && cd shared
  ar -x $pkg/lib/liblua.a
  gcc -lreadline -lhistory -lncurses -lm -ldl -shared *.o -o liblua.so.$version
  cp -a liblua.so.$version $pkg/lib/
  ( cd $pkg/lib 
    ln -s liblua.so.$version liblua.so.5.1
    ln -s liblua.so.$version liblua.so.5
    ln -s liblua.so.$version liblua.so
  )
  cd ..

  cp COPYRIGHT $pkgdocs/
  install -Dm 644 etc/lua.pc $pkg/lib/pkgconfig/lua.pc

  mkfinalpkg
}

sha512sums="
55973895c2dfd6e3b051ae1baec6c70760f7a63db464aa4801ece6ca465039beda7de1be7c0d40a3c0bf6de3f06cb3d9952822dcee32d9a03c60a44ab85a4a9d  lua-5.1.5.tar.lz
"
