backout 29799f914cab, Bug 917642 - [Helix] Please update the helix blobs
[gecko.git] / client.mk
blob4b50c43e7f9fc4ee459073a896f2a9ae6d28c361
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, run \
92 "python mozilla/build/win32/mozilla-dos2unix.py")
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 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
103 define CR
106 endef
108 # As $(shell) doesn't preserve newlines, use sed to replace them with an
109 # unlikely sequence (||), which is then replaced back to newlines by make
110 # before evaluation. $(shell) replacing newlines with spaces, || is always
111 # followed by a space (since sed doesn't remove newlines), except on the
112 # last line, so replace both '|| ' and '||'.
113 MOZCONFIG_CONTENT := $(subst ||,$(CR),$(subst || ,$(CR),$(shell $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) | 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
131 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
132 ifeq (,$(findstring -j,$(MOZ_MAKE_FLAGS)))
133 cores=$(shell $(PYTHON) -c 'import multiprocessing; print(multiprocessing.cpu_count())')
134 MOZ_MAKE_FLAGS += -j$(cores)
135 endif
138 ifndef MOZ_OBJDIR
139 MOZ_OBJDIR = obj-$(CONFIG_GUESS)
140 else
141 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
142 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
143 ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(MOZ_OBJDIR))))
144 $(error For Windows Pymake builds, MOZ_OBJDIR must be a Windows [and not MSYS] style path.)
145 endif
146 endif
147 endif
149 ifdef MOZ_BUILD_PROJECTS
151 ifdef MOZ_CURRENT_PROJECT
152 OBJDIR = $(MOZ_OBJDIR)/$(MOZ_CURRENT_PROJECT)
153 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
154 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
155 else
156 OBJDIR = $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
157 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
158 endif
160 else # MOZ_BUILD_PROJECTS
162 OBJDIR = $(MOZ_OBJDIR)
163 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
165 endif # MOZ_BUILD_PROJECTS
167 # 'configure' scripts generated by autoconf.
168 CONFIGURES := $(TOPSRCDIR)/configure
169 CONFIGURES += $(TOPSRCDIR)/js/src/configure
171 # Make targets that are going to be passed to the real build system
172 OBJDIR_TARGETS = install export libs clean realclean distclean maybe_clobber_profiledbuild upload sdk installer package fast-package package-compare stage-package source-package l10n-check
174 #######################################################################
175 # Rules
177 # The default rule is build
178 build::
179 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild)
181 # Define mkdir
182 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
183 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
185 # Create a makefile containing the mk_add_options values from mozconfig,
186 # but only do so when OBJDIR is defined (see further above).
187 ifdef MOZ_BUILD_PROJECTS
188 ifdef MOZ_CURRENT_PROJECT
189 WANT_MOZCONFIG_MK = 1
190 else
191 WANT_MOZCONFIG_MK =
192 endif
193 else
194 WANT_MOZCONFIG_MK = 1
195 endif
197 ifdef WANT_MOZCONFIG_MK
198 # For now, only output "export" lines from mozconfig2client-mk output.
199 MOZCONFIG_MK_LINES := $(filter export||%,$(MOZCONFIG_OUT_LINES))
200 $(OBJDIR)/.mozconfig.mk: $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR))
201 $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo "$(subst ||, ,$(line))";) )) > $@
203 # Include that makefile so that it is created. This should not actually change
204 # the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
205 # from, has already been eval'ed.
206 -include $(OBJDIR)/.mozconfig.mk
207 endif
209 # Print out any options loaded from mozconfig.
210 all realbuild clean distclean export libs install realclean::
211 ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
212 $(info Adding client.mk options from $(FOUND_MOZCONFIG):)
213 $(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
214 endif
216 # Windows equivalents
217 build_all: build
218 clobber clobber_all: clean
220 # helper target for mobile
221 build_and_deploy: build fast-package install
223 # Do everything from scratch
224 everything: clean build
226 ####################################
227 # Profile-Guided Optimization
228 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
229 # is usable in multi-pass builds, where you might not have a runnable
230 # application until all the build passes and postflight scripts have run.
231 ifdef MOZ_OBJDIR
232 PGO_OBJDIR = $(MOZ_OBJDIR)
233 else
234 PGO_OBJDIR := $(TOPSRCDIR)
235 endif
237 profiledbuild::
238 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1
239 $(MAKE) -C $(PGO_OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
240 rm -f ${PGO_OBJDIR}/jarlog/en-US.log
241 MOZ_PGO_INSTRUMENTED=1 JARLOG_FILE=jarlog/en-US.log EXTRA_TEST_ARGS=10 $(MAKE) -C $(PGO_OBJDIR) pgo-profile-run
242 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild
243 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1
245 #####################################################
246 # Build date unification
248 ifdef MOZ_UNIFY_BDATE
249 ifndef MOZ_BUILD_DATE
250 ifdef MOZ_BUILD_PROJECTS
251 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
252 export MOZ_BUILD_DATE
253 endif
254 endif
255 endif
257 #####################################################
258 # Preflight, before building any project
260 realbuild preflight_all::
261 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
262 # Don't run preflight_all for individual projects in multi-project builds
263 # (when MOZ_CURRENT_PROJECT is set.)
264 ifndef MOZ_BUILD_PROJECTS
265 # Building a single project, OBJDIR is usable.
266 set -e; \
267 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
268 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
269 done
270 else
271 # OBJDIR refers to the project-specific OBJDIR, which is not available at
272 # this point when building multiple projects. Only MOZ_OBJDIR is available.
273 set -e; \
274 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
275 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
276 done
277 endif
278 endif
280 # If we're building multiple projects, but haven't specified which project,
281 # loop through them.
283 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
284 configure realbuild preflight postflight $(OBJDIR_TARGETS)::
285 set -e; \
286 for app in $(MOZ_BUILD_PROJECTS); do \
287 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
288 done
290 else
292 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
293 # individual project in a multi-project build.
295 ####################################
296 # Configure
298 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
299 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
300 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
302 EXTRA_CONFIG_DEPS := \
303 $(TOPSRCDIR)/aclocal.m4 \
304 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
305 $(TOPSRCDIR)/js/src/aclocal.m4 \
306 $(NULL)
308 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
309 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/build $(TOPSRCDIR)/build
310 @echo Generating $@ using autoconf
311 cd $(@D); $(AUTOCONF)
313 CONFIG_STATUS_DEPS := \
314 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
315 $(CONFIGURES) \
316 $(TOPSRCDIR)/CLOBBER \
317 $(TOPSRCDIR)/nsprpub/configure \
318 $(TOPSRCDIR)/config/milestone.txt \
319 $(TOPSRCDIR)/js/src/config/milestone.txt \
320 $(TOPSRCDIR)/browser/config/version.txt \
321 $(TOPSRCDIR)/build/virtualenv_packages.txt \
322 $(TOPSRCDIR)/python/mozbuild/mozbuild/virtualenv.py \
323 $(TOPSRCDIR)/testing/mozbase/packages.txt \
324 $(NULL)
326 CONFIGURE_ENV_ARGS += \
327 MAKE="$(MAKE)" \
328 $(NULL)
330 # configure uses the program name to determine @srcdir@. Calling it without
331 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
332 # path of $(TOPSRCDIR).
333 ifeq ($(TOPSRCDIR),$(OBJDIR))
334 CONFIGURE = ./configure
335 else
336 CONFIGURE = $(TOPSRCDIR)/configure
337 endif
339 check-clobber:
340 $(PYTHON) $(TOPSRCDIR)/config/pythonpath.py -I $(TOPSRCDIR)/testing/mozbase/mozfile \
341 $(TOPSRCDIR)/python/mozbuild/mozbuild/controller/clobber.py $(TOPSRCDIR) $(OBJDIR)
343 configure-files: $(CONFIGURES)
345 configure-preqs = \
346 check-clobber \
347 configure-files \
348 $(call mkdir_deps,$(OBJDIR)) \
349 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
350 save-mozconfig \
351 $(NULL)
353 save-mozconfig: $(FOUND_MOZCONFIG)
354 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
356 configure:: $(configure-preqs)
357 @echo cd $(OBJDIR);
358 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
359 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
360 || ( echo "*** Fix above errors and then restart with\
361 \"$(MAKE) -f client.mk build\"" && exit 1 )
362 @touch $(OBJDIR)/Makefile
364 ifneq (,$(MAKEFILE))
365 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
367 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
368 else
369 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
370 endif
371 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
373 ifneq (,$(CONFIG_STATUS))
374 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
375 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
376 endif
379 ####################################
380 # Preflight
382 realbuild preflight::
383 ifdef MOZ_PREFLIGHT
384 set -e; \
385 for mkfile in $(MOZ_PREFLIGHT); do \
386 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
387 done
388 endif
390 ####################################
391 # Build it
393 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status check-sync-dirs-config
394 $(MOZ_MAKE)
396 ####################################
397 # Other targets
399 # Pass these target onto the real build system
400 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
401 $(MOZ_MAKE) $@
403 ####################################
404 # Postflight
406 realbuild postflight::
407 ifdef MOZ_POSTFLIGHT
408 set -e; \
409 for mkfile in $(MOZ_POSTFLIGHT); do \
410 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
411 done
412 endif
414 endif # MOZ_CURRENT_PROJECT
416 ####################################
417 # Postflight, after building all projects
419 realbuild postflight_all::
420 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
421 # Don't run postflight_all for individual projects in multi-project builds
422 # (when MOZ_CURRENT_PROJECT is set.)
423 ifndef MOZ_BUILD_PROJECTS
424 # Building a single project, OBJDIR is usable.
425 set -e; \
426 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
427 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
428 done
429 else
430 # OBJDIR refers to the project-specific OBJDIR, which is not available at
431 # this point when building multiple projects. Only MOZ_OBJDIR is available.
432 set -e; \
433 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
434 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
435 done
436 endif
437 endif
439 cleansrcdir:
440 @cd $(TOPSRCDIR); \
441 if [ -f Makefile ]; then \
442 $(MAKE) distclean ; \
443 else \
444 echo "Removing object files from srcdir..."; \
445 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
446 -o -exec test ! -d {}/CVS \; \) -prune \
447 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
448 build/autoconf/clean-config.sh; \
451 # Because SpiderMonkey can be distributed and built independently
452 # of the Mozilla source tree, it contains its own copies of many of
453 # the files used by the top-level Mozilla build process, from the
454 # 'config' and 'build' subtrees.
456 # To make it simpler to keep the copies in sync, we follow the policy
457 # that the SpiderMonkey copies must always be exact copies of those in
458 # the containing Mozilla tree. If you've made a change in one, it
459 # belongs in the other as well. If the change isn't right for both
460 # places, then that's something to bring up with the other developers.
462 # Some files are reasonable to diverge; for example,
463 # js/src/config/autoconf.mk.in doesn't need most of the stuff in
464 # config/autoconf.mk.in.
465 .PHONY: check-sync-dirs
466 check-sync-dirs: check-sync-dirs-build check-sync-dirs-config
467 check-sync-dirs-%:
468 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/$* $(TOPSRCDIR)/$*
470 echo-variable-%:
471 @echo $($*)
473 # This makefile doesn't support parallel execution. It does pass
474 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
475 # in parallel.
476 .NOTPARALLEL:
478 .PHONY: checkout \
479 real_checkout \
480 realbuild \
481 build \
482 profiledbuild \
483 cleansrcdir \
484 pull_all \
485 build_all \
486 check-clobber \
487 clobber \
488 clobber_all \
489 pull_and_build_all \
490 everything \
491 configure \
492 preflight_all \
493 preflight \
494 postflight \
495 postflight_all \
496 $(OBJDIR_TARGETS)