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"

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

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

  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="
0142fefcbd13afcd9b201403592aa60620011cc8e8559d4d2db2f92739d18186860989f48caa45830ff4f99bfc7483287fd3ff3a16d4dec928e2767ce4d542a9  lua-5.1.5.tar.gz
"
