# Template file for 'js'
pkgname=js
version=1.8.5
revision=10
build_wrksrc="js/src"
build_style=gnu-configure
hostmakedepends="zip python perl nspr-devel"
makedepends="nspr-devel"
short_desc="Spidermonkey JavaScript interpreter and library"
homepage="https://developer.mozilla.org/en/docs/SpiderMonkey"
license="MPL-1.1, GPL-2, LGPL-2.1"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
distfiles="${MOZILLA_SITE}/js/js185-1.0.0.tar.gz"
checksum=5d12f7e1f5b4a99436685d97b9b7b75f094d33580227aa998c406bbae6f2a687

case "$XBPS_TARGET_MACHINE" in
	aarch64*)
		# ./assembler/jit/ExecutableAllocator.h:395:6: error: #error "The cacheFlush support is missing on this platform."
		broken="https://build.voidlinux.eu/builders/aarch64_builder/builds/2509/steps/shell_3/logs/stdio"
		;;
esac

do_configure() {
	local _args

	if [ "$CROSS_BUILD" ]; then
		export HOST_CC=cc
		export HOST_CXX=g++
		export HOST_CFLAGS="-Os -DFORCE_LITTLE_ENDIAN -fPIE"
		export HOST_CXXFLAGS="-Os -DFORCE_LITTLE_ENDIAN -fPIE"

		case "$XBPS_MACHINE" in
			armv6l*) _args+=" --with-cpu-arch=armv6";;
			armv7l*) _args+=" --with-cpu-arch=armv7";;
		esac
		_args+=" --target=$XBPS_CROSS_TRIPLET"
	fi

	sed -e "s,-mfpu=neon -mfloat-abi=softfp,,g" -i configure
	sed -e "s,-march=armv7-a -marm -mfloat-abi=softfp,${CFLAGS},g" -i configure
	sed -e "s,-march=armv7 -marm -msoftfp,${CFLAGS},g" -i configure

	./configure --prefix=/usr --with-system-nspr --enable-threadsafe ${_args}
}

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