### this file is sourced not run
PKGVER=2025.09.13 # release version + 5 commits to fix memory leaks
PKGBUILD=1
PKGARCH=x86_64

# source: james
TARBALL=quickjs-$PKGVER.tar.gz
MD5SUM=6abf7b14dbf902f258a33b9a31a0eca3
SRC_URL=https://github.com/bellard/quickjs/archive/0377dab4f27ccfe15fb5bc44ae3fd9422f444266.tar.gz
BUNDLE=

DOC_URL_ROOT=https://bellard.org/quickjs/ 

SLACKREQ=
SLACKDESC="quickjs-full: quickjs-full $PKGVER (Javascript interpreter)
quickjs-full: 
quickjs-full: QuickJS is a small and embeddable Javascript engine. It supports the 
quickjs-full: ES2023 specification including modules, asynchronous generators, 
quickjs-full: proxies and BigInt.
quickjs-full:
quickjs-full: This package contains everything: the interpreter, the compiler, and 
quickjs-full: the documentation.
quickjs-full: 
quickjs-full: https://bellard.org/quickjs/
quickjs-full: https://github.com/bellard/quickjs
"

### default pkg_download

### prepare
pkg_prepare() {
	pkg_prepare_default &&

	# for git checkout only
	# git checkout has no docs, and we can't build it (needs TeX), so fetch online version instead	
	pkg_download_default &&
	for p in quickjs.html quickjs.pdf; do
		wget -O tmp/pkg/$p $DOC_URL_ROOT/$p || return 1
	done	
}

### default pkg_package

### build
pkg_build() {
	cd /tmp/quickjs* &&

	echo ${PKGVER//./-} > VERSION &&
	
	sed -i -e "s|/lib/quickjs|/$LIBDIR/quickjs|" Makefile qjsc.c &&
	CFLAGS="$CFLAGS -fPIC" && # so that our static library is relocatable
	make PREFIX=/usr &&
	make PREFIX=/usr install &&

	# install docs and examples
	install -dm755 /usr/share/doc/quickjs &&
	install -m644 doc/* /usr/share/doc/quickjs &&
	cp -r examples tests /usr/share/doc/quickjs &&

	if ! [ -e /usr/share/doc/quickjs/quickjs.html ]; then
		install -m644 /tmp/pkg/*.pdf /tmp/pkg/*.html /usr/share/doc/quickjs || return 1
	fi &&
	
	pkg_build_slackdesc
}
