Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / client.mk
blob95c1c5569d89d63ce4322b1f761beb88cd7edde0
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/.
7 # Build a mozilla application.
9 # To build a tree,
10 # 1. hg clone ssh://hg.mozilla.org/mozilla-central mozilla
11 # 2. cd mozilla
12 # 3. create your .mozconfig file with
13 # ac_add_options --enable-application=browser
14 # 4. gmake -f client.mk
16 # Other targets (gmake -f client.mk [targets...]),
17 # build
18 # clean (realclean is now the same as clean)
19 # distclean
21 # See http://developer.mozilla.org/en/docs/Build_Documentation for
22 # more information.
24 # Options:
25 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
26 # of MOZ_OBJDIR
27 # MOZ_OBJDIR - Destination object directory
28 # MOZ_MAKE_FLAGS - Flags to pass to $(MAKE)
29 # MOZ_PREFLIGHT_ALL } - Makefiles to run before any project in
30 # MOZ_PREFLIGHT } MOZ_BUILD_PROJECTS, before each project, after
31 # MOZ_POSTFLIGHT } each project, and after all projects; these
32 # MOZ_POSTFLIGHT_ALL } variables contain space-separated lists
33 # MOZ_UNIFY_BDATE - Set to use the same bdate for each project in
34 # MOZ_BUILD_PROJECTS
36 #######################################################################
37 # Defines
39 comma := ,
41 CWD := $(CURDIR)
42 ifneq (1,$(words $(CWD)))
43 $(error The mozilla directory cannot be located in a path with spaces.)
44 endif
46 ifeq "$(CWD)" "/"
47 CWD := /.
48 endif
50 ifndef TOPSRCDIR
51 ifeq (,$(wildcard client.mk))
52 TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST)))
53 else
54 TOPSRCDIR := $(CWD)
55 endif
56 endif
58 # try to find autoconf 2.13 - discard errors from 'which'
59 # MacOS X 10.4 sends "no autoconf*" errors to stdout, discard those via grep
60 AUTOCONF ?= $(shell which autoconf-2.13 autoconf2.13 autoconf213 2>/dev/null | grep -v '^no autoconf' | head -1)
62 # See if the autoconf package was installed through fink
63 ifeq (,$(strip $(AUTOCONF)))
64 AUTOCONF = $(shell which fink >/dev/null 2>&1 && echo `which fink`/../../lib/autoconf2.13/bin/autoconf)
65 endif
67 ifeq (,$(strip $(AUTOCONF)))
68 AUTOCONF=$(error Could not find autoconf 2.13)
69 endif
71 SH := /bin/sh
72 PERL ?= perl
73 PYTHON ?= $(shell which python2.7 > /dev/null 2>&1 && echo python2.7 || echo python)
75 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
76 ifdef CONFIG_GUESS_SCRIPT
77 CONFIG_GUESS := $(shell $(CONFIG_GUESS_SCRIPT))
78 endif
81 ####################################
82 # Sanity checks
84 # Windows checks.
85 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
87 # check for CRLF line endings
88 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
89 $(error This source tree appears to have Windows-style line endings. To \
90 convert it to Unix-style line endings, check \
91 "https://developer.mozilla.org/en-US/docs/Developer_Guide/Mozilla_build_FAQ\#Win32-specific_questions" \
92 for a workaround of this issue.)
93 endif
95 # Set this for baseconfig.mk
96 HOST_OS_ARCH=WINNT
97 endif
99 ####################################
100 # Load mozconfig Options
102 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
104 define CR
107 endef
109 # As $(shell) doesn't preserve newlines, use sed to replace them with an
110 # unlikely sequence (||), which is then replaced back to newlines by make
111 # before evaluation. $(shell) replacing newlines with spaces, || is always
112 # followed by a space (since sed doesn't remove newlines), except on the
113 # last line, so replace both '|| ' and '||'.
114 # Also, make MOZ_PGO available to mozconfig when passed on make command line.
115 # Likewise for MOZ_CURRENT_PROJECT.
116 MOZCONFIG_CONTENT := $(subst ||,$(CR),$(subst || ,$(CR),$(shell $(addprefix MOZ_CURRENT_PROJECT=,$(MOZ_CURRENT_PROJECT)) MOZ_PGO=$(MOZ_PGO) $(TOPSRCDIR)/mach environment --format=client.mk | sed 's/$$/||/')))
117 $(eval $(MOZCONFIG_CONTENT))
119 export FOUND_MOZCONFIG
121 # As '||' was used as a newline separator, it means it's not occurring in
122 # lines themselves. It can thus safely be used to replaces normal spaces,
123 # to then replace newlines with normal spaces. This allows to get a list
124 # of mozconfig output lines.
125 MOZCONFIG_OUT_LINES := $(subst $(CR), ,$(subst $(NULL) $(NULL),||,$(MOZCONFIG_CONTENT)))
126 # Filter-out comments from those lines.
127 START_COMMENT = \#
128 MOZCONFIG_OUT_FILTERED := $(filter-out $(START_COMMENT)%,$(MOZCONFIG_OUT_LINES))
130 ifdef AUTOCLOBBER
131 export AUTOCLOBBER=1
132 endif
133 export MOZ_PGO
135 ifdef MOZ_PARALLEL_BUILD
136 MOZ_MAKE_FLAGS := $(filter-out -j%,$(MOZ_MAKE_FLAGS))
137 MOZ_MAKE_FLAGS += -j$(MOZ_PARALLEL_BUILD)
138 endif
140 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
141 ifeq (,$(findstring -j,$(MOZ_MAKE_FLAGS)))
142 cores=$(shell $(PYTHON) -c 'import multiprocessing; print(multiprocessing.cpu_count())')
143 MOZ_MAKE_FLAGS += -j$(cores)
144 endif
147 ifdef MOZ_BUILD_PROJECTS
149 ifdef MOZ_CURRENT_PROJECT
150 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
151 export MOZ_CURRENT_PROJECT
152 else
153 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
154 endif
155 endif # MOZ_BUILD_PROJECTS
157 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
159 # 'configure' scripts generated by autoconf.
160 CONFIGURES := $(TOPSRCDIR)/configure
161 CONFIGURES += $(TOPSRCDIR)/js/src/configure
163 # Make targets that are going to be passed to the real build system
164 OBJDIR_TARGETS = install export libs clean realclean distclean maybe_clobber_profiledbuild upload sdk installer package package-compare stage-package source-package l10n-check automation/build
166 #######################################################################
167 # Rules
169 # The default rule is build
170 build::
171 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild) CREATE_MOZCONFIG_JSON=
173 # Include baseconfig.mk for its $(MAKE) validation.
174 include $(TOPSRCDIR)/config/baseconfig.mk
176 # Define mkdir
177 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
178 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
180 # Create a makefile containing the mk_add_options values from mozconfig,
181 # but only do so when OBJDIR is defined (see further above).
182 ifdef MOZ_BUILD_PROJECTS
183 ifdef MOZ_CURRENT_PROJECT
184 WANT_MOZCONFIG_MK = 1
185 else
186 WANT_MOZCONFIG_MK =
187 endif
188 else
189 WANT_MOZCONFIG_MK = 1
190 endif
192 ifdef WANT_MOZCONFIG_MK
193 # For now, only output "export" lines from mach environment --format=client.mk output.
194 MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES))
195 $(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER
196 $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@
198 # Include that makefile so that it is created. This should not actually change
199 # the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
200 # from, has already been eval'ed.
201 include $(OBJDIR)/.mozconfig.mk
202 endif
204 # UPLOAD_EXTRA_FILES is appended to and exported from mozconfig, which makes
205 # submakes as well as configure add even more to that, so just unexport it
206 # for submakes to pick it from .mozconfig.mk and for configure to pick it
207 # from mach environment.
208 unexport UPLOAD_EXTRA_FILES
210 # Print out any options loaded from mozconfig.
211 all realbuild clean distclean export libs install realclean::
212 ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
213 $(info Adding client.mk options from $(FOUND_MOZCONFIG):)
214 $(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
215 endif
217 # Windows equivalents
218 build_all: build
219 clobber clobber_all: clean
221 # helper target for mobile
222 build_and_deploy: build package install
224 # Do everything from scratch
225 everything: clean build
227 ####################################
228 # Profile-Guided Optimization
229 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
230 # is usable in multi-pass builds, where you might not have a runnable
231 # application until all the build passes and postflight scripts have run.
232 profiledbuild::
233 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1 CREATE_MOZCONFIG_JSON=
234 $(MAKE) -C $(OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
235 rm -f $(OBJDIR)/jarlog/en-US.log
236 MOZ_PGO_INSTRUMENTED=1 JARLOG_FILE=jarlog/en-US.log EXTRA_TEST_ARGS=10 $(MAKE) -C $(OBJDIR) pgo-profile-run
237 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild CREATE_MOZCONFIG_JSON=
238 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1 CREATE_MOZCONFIG_JSON=
240 #####################################################
241 # Build date unification
243 ifdef MOZ_UNIFY_BDATE
244 ifndef MOZ_BUILD_DATE
245 ifdef MOZ_BUILD_PROJECTS
246 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
247 export MOZ_BUILD_DATE
248 endif
249 endif
250 endif
252 #####################################################
253 # Preflight, before building any project
255 realbuild preflight_all::
256 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
257 # Don't run preflight_all for individual projects in multi-project builds
258 # (when MOZ_CURRENT_PROJECT is set.)
259 ifndef MOZ_BUILD_PROJECTS
260 # Building a single project, OBJDIR is usable.
261 set -e; \
262 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
263 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
264 done
265 else
266 # OBJDIR refers to the project-specific OBJDIR, which is not available at
267 # this point when building multiple projects. Only MOZ_OBJDIR is available.
268 set -e; \
269 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
270 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
271 done
272 endif
273 endif
275 # If we're building multiple projects, but haven't specified which project,
276 # loop through them.
278 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
279 configure realbuild preflight postflight $(OBJDIR_TARGETS)::
280 set -e; \
281 for app in $(MOZ_BUILD_PROJECTS); do \
282 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
283 done
285 else
287 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
288 # individual project in a multi-project build.
290 ####################################
291 # Configure
293 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
294 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
295 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
297 EXTRA_CONFIG_DEPS := \
298 $(TOPSRCDIR)/aclocal.m4 \
299 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
300 $(TOPSRCDIR)/js/src/aclocal.m4 \
301 $(NULL)
303 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
304 @echo Generating $@ using autoconf
305 cd $(@D); $(AUTOCONF)
307 CONFIG_STATUS_DEPS := \
308 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
309 $(CONFIGURES) \
310 $(TOPSRCDIR)/CLOBBER \
311 $(TOPSRCDIR)/nsprpub/configure \
312 $(TOPSRCDIR)/config/milestone.txt \
313 $(TOPSRCDIR)/browser/config/version.txt \
314 $(TOPSRCDIR)/build/virtualenv_packages.txt \
315 $(TOPSRCDIR)/python/mozbuild/mozbuild/virtualenv.py \
316 $(TOPSRCDIR)/testing/mozbase/packages.txt \
317 $(OBJDIR)/.mozconfig.json \
318 $(NULL)
320 CONFIGURE_ENV_ARGS += \
321 MAKE='$(MAKE)' \
322 $(NULL)
324 # configure uses the program name to determine @srcdir@. Calling it without
325 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
326 # path of $(TOPSRCDIR).
327 ifeq ($(TOPSRCDIR),$(OBJDIR))
328 CONFIGURE = ./configure
329 else
330 CONFIGURE = $(TOPSRCDIR)/configure
331 endif
333 $(OBJDIR)/CLOBBER: $(TOPSRCDIR)/CLOBBER
334 $(PYTHON) $(TOPSRCDIR)/config/pythonpath.py -I $(TOPSRCDIR)/testing/mozbase/mozfile \
335 $(TOPSRCDIR)/python/mozbuild/mozbuild/controller/clobber.py $(TOPSRCDIR) $(OBJDIR)
337 configure-files: $(CONFIGURES)
339 configure-preqs = \
340 $(OBJDIR)/CLOBBER \
341 configure-files \
342 $(call mkdir_deps,$(OBJDIR)) \
343 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
344 save-mozconfig \
345 $(OBJDIR)/.mozconfig.json \
346 $(NULL)
348 CREATE_MOZCONFIG_JSON = $(shell $(TOPSRCDIR)/mach environment --format=json -o $(OBJDIR)/.mozconfig.json)
349 # Force CREATE_MOZCONFIG_JSON above to be resolved, without side effects in
350 # case the result is non empty, and allowing an override on the make command
351 # line not running the command (using := $(shell) still runs the shell command).
352 ifneq (,$(CREATE_MOZCONFIG_JSON))
353 endif
355 $(OBJDIR)/.mozconfig.json: $(call mkdir_deps,$(OBJDIR)) ;
357 save-mozconfig: $(FOUND_MOZCONFIG)
358 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
360 configure:: $(configure-preqs)
361 @echo cd $(OBJDIR);
362 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
363 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
364 || ( echo '*** Fix above errors and then restart with\
365 "$(MAKE) -f client.mk build"' && exit 1 )
366 @touch $(OBJDIR)/Makefile
368 ifneq (,$(MAKEFILE))
369 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
371 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
372 else
373 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
374 endif
375 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure CREATE_MOZCONFIG_JSON=
377 ifneq (,$(CONFIG_STATUS))
378 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
379 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
380 endif
383 ####################################
384 # Preflight
386 realbuild preflight::
387 ifdef MOZ_PREFLIGHT
388 set -e; \
389 for mkfile in $(MOZ_PREFLIGHT); do \
390 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
391 done
392 endif
394 ####################################
395 # Build it
397 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
398 +$(MOZ_MAKE)
400 ####################################
401 # Other targets
403 # Pass these target onto the real build system
404 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
405 +$(MOZ_MAKE) $@
407 ####################################
408 # Postflight
410 realbuild postflight::
411 ifdef MOZ_POSTFLIGHT
412 set -e; \
413 for mkfile in $(MOZ_POSTFLIGHT); do \
414 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
415 done
416 endif
418 endif # MOZ_CURRENT_PROJECT
420 ####################################
421 # Postflight, after building all projects
423 realbuild postflight_all::
424 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
425 # Don't run postflight_all for individual projects in multi-project builds
426 # (when MOZ_CURRENT_PROJECT is set.)
427 ifndef MOZ_BUILD_PROJECTS
428 # Building a single project, OBJDIR is usable.
429 set -e; \
430 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
431 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
432 done
433 else
434 # OBJDIR refers to the project-specific OBJDIR, which is not available at
435 # this point when building multiple projects. Only MOZ_OBJDIR is available.
436 set -e; \
437 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
438 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
439 done
440 endif
441 endif
443 cleansrcdir:
444 @cd $(TOPSRCDIR); \
445 if [ -f Makefile ]; then \
446 $(MAKE) distclean ; \
447 else \
448 echo 'Removing object files from srcdir...'; \
449 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
450 -o -exec test ! -d {}/CVS \; \) -prune \
451 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
452 build/autoconf/clean-config.sh; \
455 echo-variable-%:
456 @echo $($*)
458 # This makefile doesn't support parallel execution. It does pass
459 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
460 # in parallel.
461 .NOTPARALLEL:
463 .PHONY: checkout \
464 real_checkout \
465 realbuild \
466 build \
467 profiledbuild \
468 cleansrcdir \
469 pull_all \
470 build_all \
471 clobber \
472 clobber_all \
473 pull_and_build_all \
474 everything \
475 configure \
476 preflight_all \
477 preflight \
478 postflight \
479 postflight_all \
480 $(OBJDIR_TARGETS)