Bug 1036561 - Reduce log spam from SharedBufferManagerChild. r=nical, a=bajaj
[gecko.git] / client.mk
blobce11dd9d2ac009f2f7466db67f71bb55281445f3
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 MOZ_OBJDIR = .
54 else
55 TOPSRCDIR := $(CWD)
56 endif
57 endif
59 # try to find autoconf 2.13 - discard errors from 'which'
60 # MacOS X 10.4 sends "no autoconf*" errors to stdout, discard those via grep
61 AUTOCONF ?= $(shell which autoconf-2.13 autoconf2.13 autoconf213 2>/dev/null | grep -v '^no autoconf' | head -1)
63 # See if the autoconf package was installed through fink
64 ifeq (,$(strip $(AUTOCONF)))
65 AUTOCONF = $(shell which fink >/dev/null 2>&1 && echo `which fink`/../../lib/autoconf2.13/bin/autoconf)
66 endif
68 ifeq (,$(strip $(AUTOCONF)))
69 AUTOCONF=$(error Could not find autoconf 2.13)
70 endif
72 SH := /bin/sh
73 PERL ?= perl
74 PYTHON ?= python
76 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
77 ifdef CONFIG_GUESS_SCRIPT
78 CONFIG_GUESS := $(shell $(CONFIG_GUESS_SCRIPT))
79 endif
82 ####################################
83 # Sanity checks
85 # Windows checks.
86 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
88 # check for CRLF line endings
89 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
90 $(error This source tree appears to have Windows-style line endings. To \
91 convert it to Unix-style line endings, check \
92 "https://developer.mozilla.org/en-US/docs/Developer_Guide/Mozilla_build_FAQ\#Win32-specific_questions" \
93 for a workaround of this issue.)
94 endif
95 endif
97 ####################################
98 # Load mozconfig Options
100 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
102 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
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 MOZCONFIG_CONTENT := $(subst ||,$(CR),$(subst || ,$(CR),$(shell MOZ_PGO=$(MOZ_PGO) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) | sed 's/$$/||/')))
116 $(eval $(MOZCONFIG_CONTENT))
118 export FOUND_MOZCONFIG
120 # As '||' was used as a newline separator, it means it's not occurring in
121 # lines themselves. It can thus safely be used to replaces normal spaces,
122 # to then replace newlines with normal spaces. This allows to get a list
123 # of mozconfig output lines.
124 MOZCONFIG_OUT_LINES := $(subst $(CR), ,$(subst $(NULL) $(NULL),||,$(MOZCONFIG_CONTENT)))
125 # Filter-out comments from those lines.
126 START_COMMENT = \#
127 MOZCONFIG_OUT_FILTERED := $(filter-out $(START_COMMENT)%,$(MOZCONFIG_OUT_LINES))
129 ifdef AUTOCLOBBER
130 export AUTOCLOBBER=1
131 endif
132 export MOZ_PGO
134 ifdef MOZ_PARALLEL_BUILD
135 MOZ_MAKE_FLAGS := $(filter-out -j%,$(MOZ_MAKE_FLAGS))
136 MOZ_MAKE_FLAGS += -j$(MOZ_PARALLEL_BUILD)
137 endif
139 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
140 ifeq (,$(findstring -j,$(MOZ_MAKE_FLAGS)))
141 cores=$(shell $(PYTHON) -c 'import multiprocessing; print(multiprocessing.cpu_count())')
142 MOZ_MAKE_FLAGS += -j$(cores)
143 endif
146 ifndef MOZ_OBJDIR
147 MOZ_OBJDIR = obj-$(CONFIG_GUESS)
148 else
149 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
150 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
151 ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(MOZ_OBJDIR))))
152 $(error For Windows Pymake builds, MOZ_OBJDIR must be a Windows [and not MSYS] style path.)
153 endif
154 endif
155 endif
157 ifdef MOZ_BUILD_PROJECTS
159 ifdef MOZ_CURRENT_PROJECT
160 OBJDIR = $(MOZ_OBJDIR)/$(MOZ_CURRENT_PROJECT)
161 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
162 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
163 else
164 OBJDIR = $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
165 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
166 endif
168 else # MOZ_BUILD_PROJECTS
170 OBJDIR = $(MOZ_OBJDIR)
171 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
173 endif # MOZ_BUILD_PROJECTS
175 # 'configure' scripts generated by autoconf.
176 CONFIGURES := $(TOPSRCDIR)/configure
177 CONFIGURES += $(TOPSRCDIR)/js/src/configure
179 # Make targets that are going to be passed to the real build system
180 OBJDIR_TARGETS = install export libs clean realclean distclean maybe_clobber_profiledbuild upload sdk installer package package-compare stage-package source-package l10n-check
182 #######################################################################
183 # Rules
185 # The default rule is build
186 build::
187 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild)
189 # Define mkdir
190 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
191 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
193 # Create a makefile containing the mk_add_options values from mozconfig,
194 # but only do so when OBJDIR is defined (see further above).
195 ifdef MOZ_BUILD_PROJECTS
196 ifdef MOZ_CURRENT_PROJECT
197 WANT_MOZCONFIG_MK = 1
198 else
199 WANT_MOZCONFIG_MK =
200 endif
201 else
202 WANT_MOZCONFIG_MK = 1
203 endif
205 ifdef WANT_MOZCONFIG_MK
206 # For now, only output "export" lines from mozconfig2client-mk output.
207 MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES))
208 $(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER
209 $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@
211 # Include that makefile so that it is created. This should not actually change
212 # the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
213 # from, has already been eval'ed.
214 include $(OBJDIR)/.mozconfig.mk
215 endif
217 # Print out any options loaded from mozconfig.
218 all realbuild clean distclean export libs install realclean::
219 ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
220 $(info Adding client.mk options from $(FOUND_MOZCONFIG):)
221 $(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
222 endif
224 # Windows equivalents
225 build_all: build
226 clobber clobber_all: clean
228 # helper target for mobile
229 build_and_deploy: build package install
231 # Do everything from scratch
232 everything: clean build
234 ####################################
235 # Profile-Guided Optimization
236 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
237 # is usable in multi-pass builds, where you might not have a runnable
238 # application until all the build passes and postflight scripts have run.
239 ifdef MOZ_OBJDIR
240 PGO_OBJDIR = $(MOZ_OBJDIR)
241 else
242 PGO_OBJDIR := $(TOPSRCDIR)
243 endif
245 profiledbuild::
246 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1
247 $(MAKE) -C $(PGO_OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
248 rm -f ${PGO_OBJDIR}/jarlog/en-US.log
249 MOZ_PGO_INSTRUMENTED=1 JARLOG_FILE=jarlog/en-US.log EXTRA_TEST_ARGS=10 $(MAKE) -C $(PGO_OBJDIR) pgo-profile-run
250 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild
251 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1
253 #####################################################
254 # Build date unification
256 ifdef MOZ_UNIFY_BDATE
257 ifndef MOZ_BUILD_DATE
258 ifdef MOZ_BUILD_PROJECTS
259 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
260 export MOZ_BUILD_DATE
261 endif
262 endif
263 endif
265 #####################################################
266 # Preflight, before building any project
268 realbuild preflight_all::
269 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
270 # Don't run preflight_all for individual projects in multi-project builds
271 # (when MOZ_CURRENT_PROJECT is set.)
272 ifndef MOZ_BUILD_PROJECTS
273 # Building a single project, OBJDIR is usable.
274 set -e; \
275 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
276 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
277 done
278 else
279 # OBJDIR refers to the project-specific OBJDIR, which is not available at
280 # this point when building multiple projects. Only MOZ_OBJDIR is available.
281 set -e; \
282 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
283 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
284 done
285 endif
286 endif
288 # If we're building multiple projects, but haven't specified which project,
289 # loop through them.
291 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
292 configure realbuild preflight postflight $(OBJDIR_TARGETS)::
293 set -e; \
294 for app in $(MOZ_BUILD_PROJECTS); do \
295 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
296 done
298 else
300 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
301 # individual project in a multi-project build.
303 ####################################
304 # Configure
306 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
307 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
308 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
310 EXTRA_CONFIG_DEPS := \
311 $(TOPSRCDIR)/aclocal.m4 \
312 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
313 $(TOPSRCDIR)/js/src/aclocal.m4 \
314 $(NULL)
316 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
317 @echo Generating $@ using autoconf
318 cd $(@D); $(AUTOCONF)
320 CONFIG_STATUS_DEPS := \
321 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
322 $(CONFIGURES) \
323 $(TOPSRCDIR)/CLOBBER \
324 $(TOPSRCDIR)/nsprpub/configure \
325 $(TOPSRCDIR)/config/milestone.txt \
326 $(TOPSRCDIR)/browser/config/version.txt \
327 $(TOPSRCDIR)/build/virtualenv_packages.txt \
328 $(TOPSRCDIR)/python/mozbuild/mozbuild/virtualenv.py \
329 $(TOPSRCDIR)/testing/mozbase/packages.txt \
330 $(NULL)
332 CONFIGURE_ENV_ARGS += \
333 MAKE='$(MAKE)' \
334 $(NULL)
336 # configure uses the program name to determine @srcdir@. Calling it without
337 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
338 # path of $(TOPSRCDIR).
339 ifeq ($(TOPSRCDIR),$(OBJDIR))
340 CONFIGURE = ./configure
341 else
342 CONFIGURE = $(TOPSRCDIR)/configure
343 endif
345 $(OBJDIR)/CLOBBER: $(TOPSRCDIR)/CLOBBER
346 $(PYTHON) $(TOPSRCDIR)/config/pythonpath.py -I $(TOPSRCDIR)/testing/mozbase/mozfile \
347 $(TOPSRCDIR)/python/mozbuild/mozbuild/controller/clobber.py $(TOPSRCDIR) $(OBJDIR)
349 configure-files: $(CONFIGURES)
351 configure-preqs = \
352 $(OBJDIR)/CLOBBER \
353 configure-files \
354 $(call mkdir_deps,$(OBJDIR)) \
355 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
356 save-mozconfig \
357 $(NULL)
359 save-mozconfig: $(FOUND_MOZCONFIG)
360 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
362 configure:: $(configure-preqs)
363 @echo cd $(OBJDIR);
364 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
365 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
366 || ( echo '*** Fix above errors and then restart with\
367 "$(MAKE) -f client.mk build"' && exit 1 )
368 @touch $(OBJDIR)/Makefile
370 ifneq (,$(MAKEFILE))
371 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
373 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
374 else
375 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
376 endif
377 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
379 ifneq (,$(CONFIG_STATUS))
380 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
381 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
382 endif
385 ####################################
386 # Preflight
388 realbuild preflight::
389 ifdef MOZ_PREFLIGHT
390 set -e; \
391 for mkfile in $(MOZ_PREFLIGHT); do \
392 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
393 done
394 endif
396 ####################################
397 # Build it
399 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
400 +$(MOZ_MAKE)
402 ####################################
403 # Other targets
405 # Pass these target onto the real build system
406 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
407 +$(MOZ_MAKE) $@
409 ####################################
410 # Postflight
412 realbuild postflight::
413 ifdef MOZ_POSTFLIGHT
414 set -e; \
415 for mkfile in $(MOZ_POSTFLIGHT); do \
416 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
417 done
418 endif
420 endif # MOZ_CURRENT_PROJECT
422 ####################################
423 # Postflight, after building all projects
425 realbuild postflight_all::
426 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
427 # Don't run postflight_all for individual projects in multi-project builds
428 # (when MOZ_CURRENT_PROJECT is set.)
429 ifndef MOZ_BUILD_PROJECTS
430 # Building a single project, OBJDIR is usable.
431 set -e; \
432 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
433 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
434 done
435 else
436 # OBJDIR refers to the project-specific OBJDIR, which is not available at
437 # this point when building multiple projects. Only MOZ_OBJDIR is available.
438 set -e; \
439 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
440 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
441 done
442 endif
443 endif
445 cleansrcdir:
446 @cd $(TOPSRCDIR); \
447 if [ -f Makefile ]; then \
448 $(MAKE) distclean ; \
449 else \
450 echo 'Removing object files from srcdir...'; \
451 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
452 -o -exec test ! -d {}/CVS \; \) -prune \
453 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
454 build/autoconf/clean-config.sh; \
457 echo-variable-%:
458 @echo $($*)
460 # This makefile doesn't support parallel execution. It does pass
461 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
462 # in parallel.
463 .NOTPARALLEL:
465 .PHONY: checkout \
466 real_checkout \
467 realbuild \
468 build \
469 profiledbuild \
470 cleansrcdir \
471 pull_all \
472 build_all \
473 clobber \
474 clobber_all \
475 pull_and_build_all \
476 everything \
477 configure \
478 preflight_all \
479 preflight \
480 postflight \
481 postflight_all \
482 $(OBJDIR_TARGETS)