# Template file for 'mozjs52'
pkgname=mozjs52
version=52.9.0
revision=4
wrksrc="firefox-${version}esr"
build_wrksrc="js/src"
build_style=gnu-configure
hostmakedepends="perl python pkg-config automake autoconf213 autoconf-archive which"
makedepends="icu-devel libffi-devel nspr-devel zlib-devel readline-devel"
short_desc="Mozilla JavaScript interpreter and library (52.x series)"
homepage="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey"
license="MPL-2.0"
maintainer="Enno Boland <gottox@voidlinux.org>"
distfiles="${MOZILLA_SITE}/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz"
checksum=c01d09658c53c1b3a496e353a24dad03b26b81d3b1d099abc26a06f81c199dd6
patch_args="-Np1"

# Flags for gcc6.3 conceived by Arch Linux developers
CFLAGS="-fpermissive -fno-delete-null-pointer-checks -fno-tree-vrp -fno-strict-aliasing"
CXXFLAGS="-fpermissive -fno-delete-null-pointer-checks -fno-tree-vrp -fno-strict-aliasing"
# Use BFD linker to avoid erroneous detection of llvm pr8927 with *-musl
LDFLAGS="-fuse-ld=bfd"
# Flags for gcc9.1
CFLAGS+=" -Wno-format-overflow"
CXXFLAGS+=" -Wno-format-overflow"

case "$XBPS_TARGET_MACHINE" in
	mips*|armv[56]*|ppc|ppc-musl) makedepends+=" libatomic-devel" ; LDFLAGS+=" -latomic" ;;
esac

do_configure() {
	local _args

	if [ "$CROSS_BUILD" ]; then
		export HOST_CFLAGS="-Os"
		export HOST_CXXFLAGS="-Os"
		_args+=" --target=$XBPS_CROSS_TRIPLET"
	fi

	touch ${wrksrc}/js/src/configure
	SHELL=/bin/bash PYTHON=/usr/bin/python2 ./configure --prefix=/usr \
		--disable-jemalloc --disable-optimize --enable-ctypes \
		--enable-gcgenerational --enable-pie --enable-readline \
		--enable-shared-js --enable-system-ffi --enable-tests \
		--enable-threadsafe --enable-xterm-updates --with-intl-api \
		--with-system-icu --with-system-nspr --with-system-zlib \
		${_args}
}

post_install() {
	mv $DESTDIR/usr/lib/libmozjs-52.so $DESTDIR/usr/lib/libmozjs-52.so.0
	ln -sr $DESTDIR/usr/lib/libmozjs-52.so.0 $DESTDIR/usr/lib/libmozjs-52.so
}

mozjs52-devel_package() {
	depends="nspr-devel ${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/bin/js52-config
		vmove usr/include
		vmove "usr/lib/*.so"
		vmove "usr/lib/*.ajs"
		vmove usr/lib/pkgconfig
	}
}
