Bug 1022862 - Revert test ordering changes because it apparently made Mnw perma-fail...
[gecko.git] / client.mk
blobbc97d05319057689a1b2c6a17deedc55fd920028
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 ?= 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
94 endif
96 ####################################
97 # Load mozconfig Options
99 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
101 define CR
104 endef
106 # As $(shell) doesn't preserve newlines, use sed to replace them with an
107 # unlikely sequence (||), which is then replaced back to newlines by make
108 # before evaluation. $(shell) replacing newlines with spaces, || is always
109 # followed by a space (since sed doesn't remove newlines), except on the
110 # last line, so replace both '|| ' and '||'.
111 # Also, make MOZ_PGO available to mozconfig when passed on make command line.
112 # Likewise for MOZ_CURRENT_PROJECT.
113 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/$$/||/')))
114 $(eval $(MOZCONFIG_CONTENT))
116 export FOUND_MOZCONFIG
118 # As '||' was used as a newline separator, it means it's not occurring in
119 # lines themselves. It can thus safely be used to replaces normal spaces,
120 # to then replace newlines with normal spaces. This allows to get a list
121 # of mozconfig output lines.
122 MOZCONFIG_OUT_LINES := $(subst $(CR), ,$(subst $(NULL) $(NULL),||,$(MOZCONFIG_CONTENT)))
123 # Filter-out comments from those lines.
124 START_COMMENT = \#
125 MOZCONFIG_OUT_FILTERED := $(filter-out $(START_COMMENT)%,$(MOZCONFIG_OUT_LINES))
127 ifdef AUTOCLOBBER
128 export AUTOCLOBBER=1
129 endif
130 export MOZ_PGO
132 ifdef MOZ_PARALLEL_BUILD
133 MOZ_MAKE_FLAGS := $(filter-out -j%,$(MOZ_MAKE_FLAGS))
134 MOZ_MAKE_FLAGS += -j$(MOZ_PARALLEL_BUILD)
135 endif
137 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
138 ifeq (,$(findstring -j,$(MOZ_MAKE_FLAGS)))
139 cores=$(shell $(PYTHON) -c 'import multiprocessing; print(multiprocessing.cpu_count())')
140 MOZ_MAKE_FLAGS += -j$(cores)
141 endif
144 ifdef MOZ_BUILD_PROJECTS
146 ifdef MOZ_CURRENT_PROJECT
147 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
148 export MOZ_CURRENT_PROJECT
149 else
150 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
151 endif
152 endif # MOZ_BUILD_PROJECTS
154 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
156 # 'configure' scripts generated by autoconf.
157 CONFIGURES := $(TOPSRCDIR)/configure
158 CONFIGURES += $(TOPSRCDIR)/js/src/configure
160 # Make targets that are going to be passed to the real build system
161 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
163 #######################################################################
164 # Rules
166 # The default rule is build
167 build::
168 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild) CREATE_MOZCONFIG_JSON=
170 # Define mkdir
171 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
172 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
174 # Create a makefile containing the mk_add_options values from mozconfig,
175 # but only do so when OBJDIR is defined (see further above).
176 ifdef MOZ_BUILD_PROJECTS
177 ifdef MOZ_CURRENT_PROJECT
178 WANT_MOZCONFIG_MK = 1
179 else
180 WANT_MOZCONFIG_MK =
181 endif
182 else
183 WANT_MOZCONFIG_MK = 1
184 endif
186 ifdef WANT_MOZCONFIG_MK
187 # For now, only output "export" lines from mach environment --format=client.mk output.
188 MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES))
189 $(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER
190 $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@
192 # Include that makefile so that it is created. This should not actually change
193 # the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
194 # from, has already been eval'ed.
195 include $(OBJDIR)/.mozconfig.mk
196 endif
198 # UPLOAD_EXTRA_FILES is appended to and exported from mozconfig, which makes
199 # submakes as well as configure add even more to that, so just unexport it
200 # for submakes to pick it from .mozconfig.mk and for configure to pick it
201 # from mach environment.
202 unexport UPLOAD_EXTRA_FILES
204 # Print out any options loaded from mozconfig.
205 all realbuild clean distclean export libs install realclean::
206 ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
207 $(info Adding client.mk options from $(FOUND_MOZCONFIG):)
208 $(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
209 endif
211 # Windows equivalents
212 build_all: build
213 clobber clobber_all: clean
215 # helper target for mobile
216 build_and_deploy: build package install
218 # Do everything from scratch
219 everything: clean build
221 ####################################
222 # Profile-Guided Optimization
223 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
224 # is usable in multi-pass builds, where you might not have a runnable
225 # application until all the build passes and postflight scripts have run.
226 profiledbuild::
227 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1 CREATE_MOZCONFIG_JSON=
228 $(MAKE) -C $(OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
229 rm -f $(OBJDIR)/jarlog/en-US.log
230 MOZ_PGO_INSTRUMENTED=1 JARLOG_FILE=jarlog/en-US.log EXTRA_TEST_ARGS=10 $(MAKE) -C $(OBJDIR) pgo-profile-run
231 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild CREATE_MOZCONFIG_JSON=
232 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1 CREATE_MOZCONFIG_JSON=
234 #####################################################
235 # Build date unification
237 ifdef MOZ_UNIFY_BDATE
238 ifndef MOZ_BUILD_DATE
239 ifdef MOZ_BUILD_PROJECTS
240 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
241 export MOZ_BUILD_DATE
242 endif
243 endif
244 endif
246 #####################################################
247 # Preflight, before building any project
249 realbuild preflight_all::
250 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
251 # Don't run preflight_all for individual projects in multi-project builds
252 # (when MOZ_CURRENT_PROJECT is set.)
253 ifndef MOZ_BUILD_PROJECTS
254 # Building a single project, OBJDIR is usable.
255 set -e; \
256 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
257 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
258 done
259 else
260 # OBJDIR refers to the project-specific OBJDIR, which is not available at
261 # this point when building multiple projects. Only MOZ_OBJDIR is available.
262 set -e; \
263 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
264 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
265 done
266 endif
267 endif
269 # If we're building multiple projects, but haven't specified which project,
270 # loop through them.
272 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
273 configure realbuild preflight postflight $(OBJDIR_TARGETS)::
274 set -e; \
275 for app in $(MOZ_BUILD_PROJECTS); do \
276 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
277 done
279 else
281 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
282 # individual project in a multi-project build.
284 ####################################
285 # Configure
287 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
288 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
289 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
291 EXTRA_CONFIG_DEPS := \
292 $(TOPSRCDIR)/aclocal.m4 \
293 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
294 $(TOPSRCDIR)/js/src/aclocal.m4 \
295 $(NULL)
297 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
298 @echo Generating $@ using autoconf
299 cd $(@D); $(AUTOCONF)
301 CONFIG_STATUS_DEPS := \
302 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
303 $(CONFIGURES) \
304 $(TOPSRCDIR)/CLOBBER \
305 $(TOPSRCDIR)/nsprpub/configure \
306 $(TOPSRCDIR)/config/milestone.txt \
307 $(TOPSRCDIR)/browser/config/version.txt \
308 $(TOPSRCDIR)/build/virtualenv_packages.txt \
309 $(TOPSRCDIR)/python/mozbuild/mozbuild/virtualenv.py \
310 $(TOPSRCDIR)/testing/mozbase/packages.txt \
311 $(OBJDIR)/.mozconfig.json \
312 $(NULL)
314 CONFIGURE_ENV_ARGS += \
315 MAKE='$(MAKE)' \
316 $(NULL)
318 # configure uses the program name to determine @srcdir@. Calling it without
319 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
320 # path of $(TOPSRCDIR).
321 ifeq ($(TOPSRCDIR),$(OBJDIR))
322 CONFIGURE = ./configure
323 else
324 CONFIGURE = $(TOPSRCDIR)/configure
325 endif
327 $(OBJDIR)/CLOBBER: $(TOPSRCDIR)/CLOBBER
328 $(PYTHON) $(TOPSRCDIR)/config/pythonpath.py -I $(TOPSRCDIR)/testing/mozbase/mozfile \
329 $(TOPSRCDIR)/python/mozbuild/mozbuild/controller/clobber.py $(TOPSRCDIR) $(OBJDIR)
331 configure-files: $(CONFIGURES)
333 configure-preqs = \
334 $(OBJDIR)/CLOBBER \
335 configure-files \
336 $(call mkdir_deps,$(OBJDIR)) \
337 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
338 save-mozconfig \
339 $(OBJDIR)/.mozconfig.json \
340 $(NULL)
342 CREATE_MOZCONFIG_JSON = $(shell $(TOPSRCDIR)/mach environment --format=json -o $(OBJDIR)/.mozconfig.json)
343 # Force CREATE_MOZCONFIG_JSON above to be resolved, without side effects in
344 # case the result is non empty, and allowing an override on the make command
345 # line not running the command (using := $(shell) still runs the shell command).
346 ifneq (,$(CREATE_MOZCONFIG_JSON))
347 endif
349 $(OBJDIR)/.mozconfig.json: $(call mkdir_deps,$(OBJDIR)) ;
351 save-mozconfig: $(FOUND_MOZCONFIG)
352 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
354 configure:: $(configure-preqs)
355 @echo cd $(OBJDIR);
356 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
357 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
358 || ( echo '*** Fix above errors and then restart with\
359 "$(MAKE) -f client.mk build"' && exit 1 )
360 @touch $(OBJDIR)/Makefile
362 ifneq (,$(MAKEFILE))
363 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
365 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
366 else
367 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
368 endif
369 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure CREATE_MOZCONFIG_JSON=
371 ifneq (,$(CONFIG_STATUS))
372 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
373 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
374 endif
377 ####################################
378 # Preflight
380 realbuild preflight::
381 ifdef MOZ_PREFLIGHT
382 set -e; \
383 for mkfile in $(MOZ_PREFLIGHT); do \
384 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
385 done
386 endif
388 ####################################
389 # Build it
391 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
392 +$(MOZ_MAKE)
394 ####################################
395 # Other targets
397 # Pass these target onto the real build system
398 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
399 +$(MOZ_MAKE) $@
401 ####################################
402 # Postflight
404 realbuild postflight::
405 ifdef MOZ_POSTFLIGHT
406 set -e; \
407 for mkfile in $(MOZ_POSTFLIGHT); do \
408 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
409 done
410 endif
412 endif # MOZ_CURRENT_PROJECT
414 ####################################
415 # Postflight, after building all projects
417 realbuild postflight_all::
418 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
419 # Don't run postflight_all for individual projects in multi-project builds
420 # (when MOZ_CURRENT_PROJECT is set.)
421 ifndef MOZ_BUILD_PROJECTS
422 # Building a single project, OBJDIR is usable.
423 set -e; \
424 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
425 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
426 done
427 else
428 # OBJDIR refers to the project-specific OBJDIR, which is not available at
429 # this point when building multiple projects. Only MOZ_OBJDIR is available.
430 set -e; \
431 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
432 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
433 done
434 endif
435 endif
437 cleansrcdir:
438 @cd $(TOPSRCDIR); \
439 if [ -f Makefile ]; then \
440 $(MAKE) distclean ; \
441 else \
442 echo 'Removing object files from srcdir...'; \
443 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
444 -o -exec test ! -d {}/CVS \; \) -prune \
445 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
446 build/autoconf/clean-config.sh; \
449 echo-variable-%:
450 @echo $($*)
452 # This makefile doesn't support parallel execution. It does pass
453 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
454 # in parallel.
455 .NOTPARALLEL:
457 .PHONY: checkout \
458 real_checkout \
459 realbuild \
460 build \
461 profiledbuild \
462 cleansrcdir \
463 pull_all \
464 build_all \
465 clobber \
466 clobber_all \
467 pull_and_build_all \
468 everything \
469 configure \
470 preflight_all \
471 preflight \
472 postflight \
473 postflight_all \
474 $(OBJDIR_TARGETS)