1# -*- makefile -*-
2# vim:set ts=8 sw=8 sts=8 noet:
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7# Defines main targets for driving the Firefox build system.
8#
9# This make file should not be invoked directly. Instead, use
10# `mach` (likely `mach build`) for invoking the build system.
11#
12# Options:
13#   MOZ_OBJDIR           - Destination object directory
14#   MOZ_MAKE_FLAGS       - Flags to pass to $(MAKE)
15#
16#######################################################################
17
18ifndef MACH
19$(error client.mk must be used via `mach`. Try running \
20`./mach $(firstword $(MAKECMDGOALS) $(.DEFAULT_GOAL))`)
21endif
22
23### Load mozconfig options
24include $(OBJDIR)/.mozconfig-client-mk
25
26### Set up make flags
27ifdef MOZ_AUTOMATION
28ifeq (4.0,$(firstword $(sort 4.0 $(MAKE_VERSION))))
29MOZ_MAKE_FLAGS += --output-sync=line
30endif
31endif
32
33MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
34
35### Rules
36# The default rule is build
37build::
38
39# In automation, manage an sccache daemon. The starting of the server
40# needs to be in a make file so sccache inherits the jobserver.
41ifdef MOZBUILD_MANAGE_SCCACHE_DAEMON
42SCCACHE_STOP = $(MOZBUILD_MANAGE_SCCACHE_DAEMON) --stop-server
43
44# When a command fails, make is going to abort, but we need to terminate the
45# sccache server, otherwise it will prevent make itself from terminating
46# because it would still be running and holding a jobserver token.
47# However, we also need to preserve the command's exit code, thus the
48# gymnastics.
49SCCACHE_STOP_ON_FAILURE = || (x=$$?; $(SCCACHE_STOP) || true; exit $$x)
50
51build::
52	# Terminate any sccache server that might still be around.
53	-$(SCCACHE_STOP) > /dev/null 2>&1
54	# Start a new server, ensuring it gets the jobserver file descriptors
55	# from make (but don't use the + prefix when make -n is used, so that
56	# the command doesn't run in that case)
57	mkdir -p $(UPLOAD_PATH)
58	$(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)env SCCACHE_LOG=sccache=debug SCCACHE_ERROR_LOG=$(UPLOAD_PATH)/sccache.log $(MOZBUILD_MANAGE_SCCACHE_DAEMON) --start-server
59endif
60
61### Build it
62build::
63	+$(MOZ_MAKE) $(SCCACHE_STOP_ON_FAILURE)
64
65ifdef MOZ_AUTOMATION
66build::
67	+$(MOZ_MAKE) automation/build $(SCCACHE_STOP_ON_FAILURE)
68endif
69
70ifdef MOZBUILD_MANAGE_SCCACHE_DAEMON
71build::
72	# Terminate sccache server. This prints sccache stats.
73	-$(SCCACHE_STOP)
74endif
75
76.PHONY: \
77    build
78