# 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 \
--disable-shared-js \
--build-backends=RecursiveMake \
--enable-posix-nspr-emulation
ifeq (windows,$(findstring windows,$(TARGET)))
WINDOWS := 1
# Override any attempt to use the debug CRT when building with debug.
CFLAGS += -MD
CXXFLAGS += -MD
CONFIGURE_FLAGS += --with-visual-studio-version=2017
ifneq (,$(CARGO_FEATURE_UWP))
CONFIGURE_FLAGS += --enable-uwp --without-intl-api
CFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP
CXXFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_APP
endif
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 = arm-linux-androideabi
CONFIGURE_FLAGS += \
--with-arch=armv7-a \
--with-fpu=neon \
$(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
CONFIGURE_FLAGS += \
--with-arch=armv8-a \
$(NULL)
endif
ifeq (android,$(findstring android,$(TARGET)))
ifneq (,$(STLPORT_CPPFLAGS))
CONFIGURE_FLAGS += STLPORT_CPPFLAGS="$(STLPORT_CPPFLAGS)"
endif
ifneq (,$(ANDROID_NDK))
CONFIGURE_FLAGS += --with-android-ndk=$(ANDROID_NDK)
endif
ifneq (,$(ANDROID_NDK_VERSION))
CONFIGURE_FLAGS += --with-android-ndk-version=$(ANDROID_NDK_VERSION)
endif
ifneq (,$(ANDROID_VERSION))
CONFIGURE_FLAGS += --with-android-version=$(ANDROID_VERSION)
endif
ifneq (,$(ANDROID_PLATFORM_DIR))
CONFIGURE_FLAGS += --with-android-platform=$(ANDROID_PLATFORM_DIR)
endif
ifneq (,$(ANDROID_TOOLCHAIN_DIR))
CONFIGURE_FLAGS += --with-android-toolchain=$(ANDROID_TOOLCHAIN_DIR)
endif
ifneq (,$(ANDROID_CLANG))
CONFIGURE_FLAGS += --with-android-clang=$(ANDROID_CLANG)
endif
endif
ifeq ($(WINDOWS),)
CC ?= $(TARGET)-gcc
CPP ?= $(TARGET)-gcc -E
CXX ?= $(TARGET)-g++
AR ?= $(TARGET)-ar
CONFIGURE_FLAGS += --target=$(TARGET) --disable-gold
endif
else
ifeq (,$(WINDOWS))
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_PROFILEMOZJS))
CONFIGURE_FLAGS += --enable-profiling
endif
ifneq (,$(CCACHE))
CONFIGURE_FLAGS += --with-ccache=$(CCACHE)
endif
ifneq ($(WINDOWS),)
# 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
else ifeq ($(findstring i686,$(TARGET)),i686)
# This is the correct target for MSVC builds
CONFIGURE_FLAGS += --target=i686-pc-mingw32 --host=x86_64-pc-mingw32
else ifeq ($(findstring aarch64,$(TARGET)),aarch64)
# This is the correct target for MSVC builds
CONFIGURE_FLAGS += --target=aarch64-windows-mingw32 --host=x86_64-pc-mingw32
endif
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
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)" CFLAGS="$(CFLAGS)" \
CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" \
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
AS="$(AS)" AR="$(AR)" \
STLPORT_LIBS="$(STLPORT_LIBS)" \
RUST_TARGET="$(TARGET)" RUST_HOST="$(HOST)" \
$(JSSRC)/configure $(strip $(CONFIGURE_FLAGS)) || (cat config.log && exit 1) ; \
fi