# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=mujs
pkgver=1.3.2
pkgrel=0
pkgdesc="An embeddable JavaScript interpreter"
url="https://mujs.com/"
arch="all"
license="ISC"
makedepends="readline-dev"
subpackages="$pkgname-dev $pkgname-libs"
source="https://mujs.com/downloads/mujs-$pkgver.tar.gz"
options="!check"  # no tests provided

# This is based on Debian.
_sover=${pkgver#1.}; _sover=${_sover%%.*}

# secfixes:
#   1.3.0-r0:
#     - CVE-2022-30974
#     - CVE-2022-30975

build() {
	export XCFLAGS=${CFLAGS/-Os/-O2}
	export CPPFLAGS=${CPPFLAGS/-Os/}

	make shared XCFLAGS="$XCFLAGS -Wl,-soname,libmujs.so.$_sover"
	make
}

package() {
	local ver3=${pkgver#*.*.}; ver3=${ver3%%[^0-9]*}

	make install-shared prefix=/usr DESTDIR="$pkgdir"
	make install prefix=/usr DESTDIR="$pkgdir"

	cd "$pkgdir"

	mv usr/lib/libmujs.so usr/lib/libmujs.so.$_sover.$ver3
	ldconfig -n usr/lib
	ln -s libmujs.so.$_sover.$ver3 usr/lib/libmujs.so
}

sha512sums="
ccffb04171f7ecec2cfa6f0e59859acc911836370a648e4c6703db174631ce316413a64ebf4b32eea3d3b09221ff01861cda91f4b1b9bebf495168f26f90daf5  mujs-1.3.2.tar.gz
"
