### this file is sourced not run
PKGVER=2025.07.25 # pull date - we use git-master because tarball is 3 months behind
PKGBUILD=1
PKGARCH=x86_64

# source: james
TARBALL=quickjs-$PKGVER.tar.gz
MD5SUM=d7447c9f72f32317b1dd91d62bdcd06f
SRC_URL=https://github.com/bellard/quickjs/archive/1fdc768fdc8571300755cdd3e4654ce99c0255ce.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
"

# for git checkout only
# git checkout has no docs, and we can't build it (needs TeX), so fetch online version instead
pkg_download() {
	local p
	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_prepare
### 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
}
