mozjs_sys 0.140.5-10

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

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

ifeq (,$(CARGO_FEATURE_JIT))
    CONFIGURE_FLAGS += --disable-jit
endif

ifneq (,$(CARGO_FEATURE_JITSPEW))
    CONFIGURE_FLAGS += --enable-jitspew
endif

ifeq (,$(CARGO_FEATURE_INTL))
    CONFIGURE_FLAGS += --without-intl-api
endif

ifneq (,$(CARGO_FEATURE_DEBUGMOZJS))
	CONFIGURE_FLAGS += --enable-debug --enable-gczeal
	ifneq (,$(findstring -wasi,$(TARGET)))
		# wasm-opt chokes on -O0 builds.
		CONFIGURE_FLAGS += --enable-optimize=-O1
	else
		CONFIGURE_FLAGS += --disable-optimize
	endif
endif

ifneq (,$(CARGO_FEATURE_PROFILEMOZJS))
	CONFIGURE_FLAGS += --enable-profiling
endif

ifneq (,$(CARGO_FEATURE_LIBZ_RS))
	CONFIGURE_FLAGS += --enable-libz-rs
endif

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


ifneq (,$(MACOS_SDK_PATH))
	CONFIGURE_FLAGS += --with-macos-sdk=$(MACOS_SDK_PATH)
endif

ifeq (windows,$(findstring windows,$(TARGET)))
	WINDOWS := 1
	# Override any attempt to use the debug CRT when building with debug.
	CFLAGS += -MD
	CXXFLAGS += -MD
else
	WINDOWS :=
endif

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 = armv7a-linux-androideabi
		CONFIGURE_FLAGS += \
			--with-arch=armv7-a \
			--with-fpu=neon \
			$(NULL)
	endif

	ifeq (armv7-unknown-linux-gnueabihf,$(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-gnueabihf
		CONFIGURE_FLAGS += \
			--with-arch=armv7-a \
			$(NULL)
	endif

	ifeq (aarch64-unknown-linux-gnu,$(TARGET))
	    # Reset TARGET variable because aarch64 target name used by Rust is not
		# the same as the target name needed for the CXX toolchain.
		TARGET = aarch64-linux-gnu
	endif

    ifneq (,$(findstring -wasi,$(TARGET)))
        ifeq (,$(WASI_SDK_PATH))
            $(error WASI_SDK_PATH environment variable must be set when building for wasm32)
        endif
        WASI_SYSROOT = $(WASI_SDK_PATH)/share/wasi-sysroot
        CC = $(WASI_SDK_PATH)/bin/clang
        CPP = $(WASI_SDK_PATH)/bin/clang -E
        CXX = $(WASI_SDK_PATH)/bin/clang++
        AR = $(WASI_SDK_PATH)/bin/ar
        HOST_CC = clang
        HOST_CXX = clang++
        CONFIGURE_FLAGS += \
            --enable-portable-baseline-interp \
            --disable-clang-plugin \
            --disable-jit \
            --disable-shared-memory \
            --with-sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot \
            $(NULL)
        # LTO makes `cargo test --wasm32-wasi` take a very very long time. Since build scripts
        # don't have a way to detect if the build is for `cargo test`, enable LTO for release
        # builds only.
        ifneq (debug,$(PROFILE))
            CONFIGURE_FLAGS += --lto=thin
        endif
    endif

	ifeq (android,$(findstring android,$(TARGET)))
		# Force use of lld on android. Mozilla build system tries to use
		# gold or bfd linker on Android to support their 'elfhack'functionality in
		# non-developer builds, but NDK r25c ships with only lld.
		CONFIGURE_FLAGS += \
			--with-android-ndk=$(ANDROID_NDK_ROOT) \
			--with-android-version=$(ANDROID_API_LEVEL) \
			--enable-linker=lld \
			$(NULL)
	endif

	ifeq ($(WINDOWS),)
		CC ?= $(TARGET)-gcc
		CPP ?= $(TARGET)-gcc -E
		CXX ?= $(TARGET)-g++
		AR ?= $(TARGET)-ar
		CONFIGURE_FLAGS += --target=$(TARGET)
	endif

else

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

endif

ifneq ($(WINDOWS),)

	ifeq ($(findstring x86_64,$(TARGET)),x86_64)
		# This is the correct target for MSVC builds
		CONFIGURE_FLAGS += --target=x86_64-pc-windows-msvc
	else ifeq ($(findstring i686,$(TARGET)),i686)
		# This is the correct target for MSVC builds
		CONFIGURE_FLAGS += --target=i686-pc-windows-msvc
	else ifeq ($(findstring aarch64,$(TARGET)),aarch64)
		# This is the correct target for MSVC builds
		CONFIGURE_FLAGS += --target=aarch64-pc-windows-msvc
	endif

	# 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))

else ifeq ($(MSYSTEM),MINGW64)

	# 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)")

endif

.PHONY : all maybe-configure

all: maybe-configure
	$(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)'/js/src
# Keep track of all input variables to configure, so we don't skip reconfigure
# when we do need to reconfigure
CONFIGURE_INPUTS := "$(CC)$(CFLAGS)$(CPP)$(CPPFLAGS)$(CXX)$(CXXFLAGS)$(AS)$(AR)$(HOST_CC)$(HOST_CXX)$(WASI_SYSROOT)$(CONFIGURE_FLAGS)"
LAST_CONFIGURE_INPUTS := "$(shell cat reconfigure.inputs)"
maybe-configure:
	[[ $(JSSRC)/configure -ot $(JSSRC)/configure.in ]] && touch $(JSSRC)/configure || true
	[[ $(LAST_CONFIGURE_INPUTS) != $(CONFIGURE_INPUTS) ]] && touch $(JSSRC)/configure || true
	! [[ $(JSSRC)/configure.in -ot $(JSSRC)/configure ]] && touch $(JSSRC)/configure || true
	if [[ $(JSSRC)/configure -nt config.status ]] ; then \
	  ( echo "$(CONFIGURE_INPUTS)" > reconfigure.inputs ); \
	  CC="$(CC)" CFLAGS="$(CFLAGS)" \
	  CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" \
	  CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
	  HOST_CC="$(HOST_CC)" \
	  HOST_CXX="$(HOST_CXX)" \
	  WASI_SYSROOT="$(WASI_SYSROOT)" \
	  AS="$(AS)" AR="$(AR)" \
	  $(JSSRC)/configure $(strip $(CONFIGURE_FLAGS)) || (cat config.log && exit 1) ; \
	fi