mozjs_sys 0.51.4

System crate for the Mozilla SpiderMonkey JavaScript engine.
Documentation
# We need to use bash here, as there are a couple of targets below
# that use [[ to do conditional things
SHELL := /usr/bin/env bash

# Default flags
CONFIGURE_FLAGS := \
	--disable-jemalloc \
	--disable-js-shell \
	--disable-tests \
	--build-backends=RecursiveMake

ifneq ($(HOST),$(TARGET))

	ifeq (armv7-linux-androideabi,$(TARGET))
		# Reset TARGET variable because armv7 target name used by Rust is not 
		# the same as the target name needed for the CXX toolchain.
		TARGET = arm-linux-androideabi
		CONFIGURE_FLAGS += \
			--with-arch=armv7-a \
			--with-fpu=neon \
			$(NULL)
	endif

	ifeq (android,$(findstring android,$(TARGET)))
		CONFIGURE_FLAGS += \
			--with-android-ndk=$(ANDROID_NDK) \
			--with-android-toolchain=$(ANDROID_TOOLCHAIN) \
			--with-android-version=$(NDK_ANDROID_VERSION) \
			$(NULL)
	endif

CC ?= $(TARGET)-gcc
CPP ?= $(TARGET)-gcc -E
CXX ?= $(TARGET)-g++
AR ?= $(TARGET)-ar

CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold

else

ifeq (,$(VCINSTALLDIR))
	ifeq (freebsd,$(findstring freebsd,$(TARGET)))
		# Does not symlink clang as "gcc" like macOS does
		CC ?= clang
		CPP ?= clang -E
		CXX ?= clang++
	else
		CC ?= gcc
		CPP ?= gcc -E
		CXX ?= g++
	endif
AR ?= ar

# check if python2 is a valid Python executable, otherwise fall back to python
ifeq (, $(findstring Python 2.,$(shell python2 --version 2> /dev/null)))
PYTHON ?= python2
else
PYTHON ?= python
endif 

endif

endif

ifneq (,$(CARGO_FEATURE_DEBUGMOZJS))
	CONFIGURE_FLAGS += --enable-debug --disable-optimize --enable-gczeal
endif

ifneq (,$(CARGO_FEATURE_PROMISES))
	CONFIGURE_FLAGS += --enable-sm-promise
endif

ifneq (,$(CCACHE))
	CONFIGURE_FLAGS += --with-ccache=$(CCACHE)
endif

ifneq ($(VCINSTALLDIR),)
	# Visual Studio build
	NEED_WIN_PYTHON := 1

	# There's no cygpath in mozilla-build, and we're expecting to
	# be building with MOZ_BUILD_TOOLS, so do our best
	OUT_DIR:=$(subst \,/,$(OUT_DIR))

ifeq ($(findstring x86_64,$(TARGET)),x86_64)
	# This is the correct target for MSVC builds
	CONFIGURE_FLAGS += --target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32
endif
	CONFIGURE_FLAGS += --without-pthreads
	MOZ_TOOLS=/

else ifeq ($(MSYSTEM),MINGW64)
	# MSYS2/MINGW64 build
	NEED_WIN_PYTHON := 1

	# msys2 sets CC=cc as default. however, there is no `cc.exe`.
	# overwrite it here.
	ifeq ($(CC),cc)
		CC = gcc
		CPP = gcc -E
	endif

	# cargo uses Windows native path. msys2 make unfortunately doesn't understand it.
	OUT_DIR:=$(shell cygpath "$(OUT_DIR)")

	# Fake out the SM build with a dummy dir here; just needs $(MOZ_TOOLS)/bin
	# to exist
	MOZ_TOOLS=/

	# We don't need to build shared JS, and we need to disable export attrs
	CONFIGURE_FLAGS += --disable-shared-js --disable-export-js --without-pthreads
else
	# We don't need to build shared JS
	CONFIGURE_FLAGS += --disable-shared-js
endif

# If we need to do extra work to find an appropriate python on
# Windows, do it here
ifeq ($(NEED_WIN_PYTHON),1)
	ifneq (,$(NATIVE_WIN32_PYTHON))
		PYTHON := $(NATIVE_WIN32_PYTHON)
	else ifneq (,$(wildcard c:/python27/python.exe))
		PYTHON := c:/python27/python.exe
	else
		$(message You must either have the Native Win32 python installed in C:/python27, or set NATIVE_WIN32_PYTHON to point to the appropriate python.exe.)
		$(message Download the Python installer from  https://www.python.org/downloads/release/python-2710/)
		$(error Native Win32 Python not found)
	endif
endif

SRC_DIR = $(shell pwd)

.PHONY : all maybe-configure

all: maybe-configure
	cd $(OUT_DIR) && $(MAKE) -f Makefile

# Only touch and run configure if we need to, to avoid unnecessary rebuilds.
# The second two time checks handle the case of configure.in and configure having
# the same timestamp (e.g. after a git checkout)
JSSRC := $(SRC_DIR)/mozjs/js/src
maybe-configure:
	[[ $(JSSRC)/configure -ot $(JSSRC)/configure.in ]] && touch $(JSSRC)/configure || true
	[[ $(JSSRC)/old-configure -ot $(JSSRC)/old-configure.in ]] && touch $(JSSRC)/old-configure || true
	! [[ $(JSSRC)/configure.in -ot $(JSSRC)/configure ]] && touch $(JSSRC)/configure || true
	! [[ $(JSSRC)/old-configure.in -ot $(JSSRC)/old-configure ]] && touch $(JSSRC)/old-configure || true
	if [[ $(JSSRC)/configure -nt $(OUT_DIR)/config.status ]] ; then \
	  cd $(OUT_DIR) && \
	  PYTHON="$(PYTHON)" MOZ_TOOLS="$(MOZ_TOOLS)" \
	  CC="$(CC)" CPP="$(CPP)" CXX="$(CXX)" AR="$(AR)" \
	  $(JSSRC)/configure $(strip $(CONFIGURE_FLAGS)) || (cat config.log && exit 1) ; \
	fi