#!/bin/sh
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

PKGNAME=mozjs52
PKGVERSION=52.9.0
PKGREVISION=1
PKGLICENSE="MPLv20"
PKGSUMMARY="Mozilla Javascript engine also know as SpiderMonkey"
PKGDOWNLOAD="http://releases.mozilla.org/pub/firefox/releases/${PKGVERSION}esr/source/firefox-${PKGVERSION}esr.source.tar.xz"
PKGDEPENDS="shells/bash:build python/python2:build lib/libffi lib/icu compression/zlib"

: ${CC:=clang}
: ${CXX:=clang++}

build()
{
	rm -rf firefox-${PKGVERSION}esr
	tar xvf firefox-${PKGVERSION}esr.source.tar.xz
	cd firefox-${PKGVERSION}esr

	# credits to FreeBSD.
	unset DOXYGEN
	patch -p0 < ../patch-clang.patch
	cd js/src
	CC="$CC" HOST_CC="$CC" \
	CXX="$CXX" HOST_CXX="$CXX" \
	SHELL="/bin/bash" PYTHON="/bin/python2" \
	./configure \
		--prefix= \
		--disable-tests \
		--disable-jemalloc \
		--enable-shared-js \
		--enable-ctypes \
		--with-system-icu \
		--with-system-nspr \
		--with-system-zlib
	SHELL="/bin/bash" PYTHON="/bin/python2" \
	make
	make install DESTDIR=$DESTDIR
	cd ..

	cd ..
	rm -rf firefox-${PKGVERSION}esr
}
