# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

pkgname=lua
pkgver=5.4.8
_majorver=${pkgver%.*}
pkgrel=1
pkgdesc='Powerful lightweight programming language designed for extending applications'
arch=('x86_64')
url='https://www.lua.org/'
msys2_references=(
  'anitya: 1847'
  'archlinux: lua'
  'cpe: cpe:2.3:a:lua:lua'
  'gentoo: dev-lang/lua'
)
makedepends=('make' 'gcc')
license=('spdx:MIT')
source=(https://www.lua.org/ftp/lua-$pkgver.tar.gz
        lua.pc)
sha256sums=('4f18ddae154e793e46eeab727c59ef1c0c0c2b744e7b94219710d76f530629ae'
            '925fd82adde7e6a83a6f63531b7c21f5c5133436e8947aeaab0c707ef3972858')

prepare() {
  sed "s/%VER%/$_majorver/g;s/%REL%/$pkgver/g" lua.pc > lua-$pkgver/lua.pc
}

build() {
  cd "lua-$pkgver"

  make \
    CFLAGS="${CFLAGS}" \
    AR="${CC} -shared -Wl,--out-implib,liblua.dll.a -o" \
    RANLIB=: \
    LUA_A="msys-lua-${_majorver}.dll" \
    linux
}

package() {
  cd "lua-$pkgver"

  make \
    TO_BIN="msys-lua-${_majorver}.dll lua.exe luac.exe" \
    TO_LIB="liblua.dll.a" \
    INSTALL_TOP="$pkgdir"/usr \
    INSTALL_INC="$pkgdir"/usr/include \
    INSTALL_LIB="$pkgdir"/usr/lib \
    INSTALL_MAN="$pkgdir"/usr/share/man/man1 \
    install

  install -Dm644 lua.pc "$pkgdir"/usr/lib/pkgconfig/lua.pc
}
