# Description: A programming language designed for extending applications
# URL: https://www.lua.org/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: readline

name=lua
version=5.4.6
release=2
source=(https://www.lua.org/ftp/$name-$version.tar.gz
  liblua.so.patch lua.pc)

build() {
  cd $name-$version

  patch -p1 -i $SRC/liblua.so.patch

  sed "s/%VER%/${version:0:3}/g;s/%REL%/$version/g" $SRC/lua.pc > lua.pc

  make MYCFLAGS="$CFLAGS -fPIC" MYLDFLAGS="$LDFLAGS" linux

  make \
    TO_LIB="liblua.a liblua.so liblua.so.${version:0:3} liblua.so.$version" \
    INSTALL_DATA='cp -d' \
    INSTALL_TOP=$PKG/usr \
    INSTALL_MAN=$PKG/usr/share/man/man1 \
    install

  ln -s lua $PKG/usr/bin/lua${version:0:3}
  ln -s luac $PKG/usr/bin/luac${version:0:3}
  ln -s liblua.so.$version $PKG/usr/lib/liblua${version:0:3}.so

  install -m 0644 -D lua.pc $PKG/usr/lib/pkgconfig/lua${version:0:1}${version:2:1}.pc
  ln -s lua${version:0:1}${version:2:1}.pc $PKG/usr/lib/pkgconfig/lua.pc
  ln -s lua${version:0:1}${version:2:1}.pc $PKG/usr/lib/pkgconfig/lua${version:0:3}.pc
  ln -s lua${version:0:1}${version:2:1}.pc $PKG/usr/lib/pkgconfig/lua-${version:0:3}.pc
}
