Bug 767636 - Expose plugin fallback type to extensions. r=josh
[gecko.git] / client.mk
blobbdf4feea2a9e8ab550652c620316b177f3a51cdd
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 ifeq (,$(strip $(AUTOCONF)))
64 AUTOCONF=$(error Could not find autoconf 2.13)
65 endif
67 SH := /bin/sh
68 PERL ?= perl
69 PYTHON ?= python
71 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
72 ifdef CONFIG_GUESS_SCRIPT
73 CONFIG_GUESS := $(shell $(CONFIG_GUESS_SCRIPT))
74 endif
77 ####################################
78 # Sanity checks
80 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
81 # check for CRLF line endings
82 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
83 $(error This source tree appears to have Windows-style line endings. To \
84 convert it to Unix-style line endings, run \
85 "python mozilla/build/win32/mozilla-dos2unix.py")
86 endif
87 endif
89 ####################################
90 # Load mozconfig Options
92 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
94 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
96 define CR
99 endef
101 # As $(shell) doesn't preserve newlines, use sed to replace them with an
102 # unlikely sequence (||), which is then replaced back to newlines by make
103 # before evaluation.
104 $(eval $(subst ||,$(CR),$(shell _PYMAKE=$(.PYMAKE) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) 2> $(TOPSRCDIR)/.mozconfig.out | sed 's/$$/||/')))
106 ifndef MOZ_OBJDIR
107 MOZ_OBJDIR = obj-$(CONFIG_GUESS)
108 else
109 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
110 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
111 ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(MOZ_OBJDIR))))
112 $(error For Windows Pymake builds, MOZ_OBJDIR must be a Windows [and not MSYS] style path.)
113 endif
114 endif
115 endif
117 ifdef MOZ_BUILD_PROJECTS
119 ifdef MOZ_CURRENT_PROJECT
120 OBJDIR = $(MOZ_OBJDIR)/$(MOZ_CURRENT_PROJECT)
121 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
122 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
123 else
124 OBJDIR = $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
125 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
126 endif
128 else # MOZ_BUILD_PROJECTS
130 OBJDIR = $(MOZ_OBJDIR)
131 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
133 endif # MOZ_BUILD_PROJECTS
135 # 'configure' scripts generated by autoconf.
136 CONFIGURES := $(TOPSRCDIR)/configure
137 CONFIGURES += $(TOPSRCDIR)/js/src/configure
139 # Make targets that are going to be passed to the real build system
140 OBJDIR_TARGETS = install export libs clean realclean distclean alldep maybe_clobber_profiledbuild upload sdk installer package fast-package package-compare stage-package source-package l10n-check
142 #######################################################################
143 # Rules
145 # The default rule is build
146 build::
147 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild)
149 # Define mkdir
150 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
151 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
153 # Print out any options loaded from mozconfig.
154 all realbuild clean depend distclean export libs install realclean::
155 @if test -f .mozconfig.out; then \
156 cat .mozconfig.out; \
157 rm -f .mozconfig.out; \
158 else true; \
161 # Windows equivalents
162 build_all: build
163 build_all_dep: alldep
164 build_all_depend: alldep
165 clobber clobber_all: clean
167 # helper target for mobile
168 build_and_deploy: build fast-package install
170 # Do everything from scratch
171 everything: clean build
173 ####################################
174 # Profile-Guided Optimization
175 # To use this, you should set the following variables in your mozconfig
176 # mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
178 # The profile script should exercise the functionality to be included
179 # in the profile feedback.
181 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
182 # is usable in multi-pass builds, where you might not have a runnable
183 # application until all the build passes and postflight scripts have run.
184 ifdef MOZ_OBJDIR
185 PGO_OBJDIR = $(MOZ_OBJDIR)
186 else
187 PGO_OBJDIR := $(TOPSRCDIR)
188 endif
190 profiledbuild::
191 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1
192 $(MAKE) -C $(PGO_OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
193 MOZ_PGO_INSTRUMENTED=1 OBJDIR=${PGO_OBJDIR} JARLOG_DIR=${PGO_OBJDIR}/jarlog/en-US $(PROFILE_GEN_SCRIPT)
194 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild
195 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1
197 #####################################################
198 # Build date unification
200 ifdef MOZ_UNIFY_BDATE
201 ifndef MOZ_BUILD_DATE
202 ifdef MOZ_BUILD_PROJECTS
203 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
204 export MOZ_BUILD_DATE
205 endif
206 endif
207 endif
209 #####################################################
210 # Preflight, before building any project
212 realbuild alldep preflight_all::
213 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
214 # Don't run preflight_all for individual projects in multi-project builds
215 # (when MOZ_CURRENT_PROJECT is set.)
216 ifndef MOZ_BUILD_PROJECTS
217 # Building a single project, OBJDIR is usable.
218 set -e; \
219 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
220 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
221 done
222 else
223 # OBJDIR refers to the project-specific OBJDIR, which is not available at
224 # this point when building multiple projects. Only MOZ_OBJDIR is available.
225 set -e; \
226 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
227 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
228 done
229 endif
230 endif
232 # If we're building multiple projects, but haven't specified which project,
233 # loop through them.
235 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
236 configure depend realbuild preflight postflight $(OBJDIR_TARGETS)::
237 set -e; \
238 for app in $(MOZ_BUILD_PROJECTS); do \
239 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
240 done
242 else
244 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
245 # individual project in a multi-project build.
247 ####################################
248 # Configure
250 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
251 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
252 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
254 EXTRA_CONFIG_DEPS := \
255 $(TOPSRCDIR)/aclocal.m4 \
256 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
257 $(TOPSRCDIR)/js/src/aclocal.m4 \
258 $(NULL)
260 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
261 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/build $(TOPSRCDIR)/build
262 @echo Generating $@ using autoconf
263 cd $(@D); $(AUTOCONF)
265 CONFIG_STATUS_DEPS := \
266 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
267 $(CONFIGURES) \
268 $(TOPSRCDIR)/allmakefiles.sh \
269 $(TOPSRCDIR)/nsprpub/configure \
270 $(TOPSRCDIR)/config/milestone.txt \
271 $(TOPSRCDIR)/js/src/config/milestone.txt \
272 $(TOPSRCDIR)/browser/config/version.txt \
273 $(TOPSRCDIR)/build/virtualenv/packages.txt \
274 $(TOPSRCDIR)/build/virtualenv/populate_virtualenv.py \
275 $(NULL)
277 CONFIGURE_ENV_ARGS += \
278 MAKE="$(MAKE)" \
279 $(NULL)
281 # configure uses the program name to determine @srcdir@. Calling it without
282 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
283 # path of $(TOPSRCDIR).
284 ifeq ($(TOPSRCDIR),$(OBJDIR))
285 CONFIGURE = ./configure
286 else
287 CONFIGURE = $(TOPSRCDIR)/configure
288 endif
290 configure-files: $(CONFIGURES)
292 configure-preqs = \
293 configure-files \
294 $(call mkdir_deps,$(OBJDIR)) \
295 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
296 save-mozconfig \
297 $(NULL)
299 save-mozconfig: $(FOUND_MOZCONFIG)
300 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
302 configure:: $(configure-preqs)
303 @echo cd $(OBJDIR);
304 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
305 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
306 || ( echo "*** Fix above errors and then restart with\
307 \"$(MAKE) -f client.mk build\"" && exit 1 )
308 @touch $(OBJDIR)/Makefile
310 ifneq (,$(MAKEFILE))
311 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
313 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
314 else
315 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
316 endif
317 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
319 ifneq (,$(CONFIG_STATUS))
320 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
321 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
322 endif
325 ####################################
326 # Depend
328 depend:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
329 $(MOZ_MAKE) export && $(MOZ_MAKE) depend
331 ####################################
332 # Preflight
334 realbuild alldep preflight::
335 ifdef MOZ_PREFLIGHT
336 set -e; \
337 for mkfile in $(MOZ_PREFLIGHT); do \
338 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
339 done
340 endif
342 ####################################
343 # Build it
345 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status check-sync-dirs-config
346 $(MOZ_MAKE)
348 ####################################
349 # Other targets
351 # Pass these target onto the real build system
352 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
353 $(MOZ_MAKE) $@
355 ####################################
356 # Postflight
358 realbuild alldep postflight::
359 ifdef MOZ_POSTFLIGHT
360 set -e; \
361 for mkfile in $(MOZ_POSTFLIGHT); do \
362 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
363 done
364 endif
366 endif # MOZ_CURRENT_PROJECT
368 ####################################
369 # Postflight, after building all projects
371 realbuild alldep postflight_all::
372 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
373 # Don't run postflight_all for individual projects in multi-project builds
374 # (when MOZ_CURRENT_PROJECT is set.)
375 ifndef MOZ_BUILD_PROJECTS
376 # Building a single project, OBJDIR is usable.
377 set -e; \
378 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
379 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
380 done
381 else
382 # OBJDIR refers to the project-specific OBJDIR, which is not available at
383 # this point when building multiple projects. Only MOZ_OBJDIR is available.
384 set -e; \
385 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
386 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
387 done
388 endif
389 endif
391 cleansrcdir:
392 @cd $(TOPSRCDIR); \
393 if [ -f Makefile ]; then \
394 $(MAKE) distclean ; \
395 else \
396 echo "Removing object files from srcdir..."; \
397 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
398 -o -exec test ! -d {}/CVS \; \) -prune \
399 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
400 build/autoconf/clean-config.sh; \
403 # Because SpiderMonkey can be distributed and built independently
404 # of the Mozilla source tree, it contains its own copies of many of
405 # the files used by the top-level Mozilla build process, from the
406 # 'config' and 'build' subtrees.
408 # To make it simpler to keep the copies in sync, we follow the policy
409 # that the SpiderMonkey copies must always be exact copies of those in
410 # the containing Mozilla tree. If you've made a change in one, it
411 # belongs in the other as well. If the change isn't right for both
412 # places, then that's something to bring up with the other developers.
414 # Some files are reasonable to diverge; for example,
415 # js/src/config/autoconf.mk.in doesn't need most of the stuff in
416 # config/autoconf.mk.in.
417 .PHONY: check-sync-dirs
418 check-sync-dirs: check-sync-dirs-build check-sync-dirs-config
419 check-sync-dirs-%:
420 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/$* $(TOPSRCDIR)/$*
422 echo-variable-%:
423 @echo $($*)
425 # This makefile doesn't support parallel execution. It does pass
426 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
427 # in parallel.
428 .NOTPARALLEL:
430 .PHONY: checkout real_checkout depend realbuild build profiledbuild cleansrcdir pull_all build_all clobber clobber_all pull_and_build_all everything configure preflight_all preflight postflight postflight_all $(OBJDIR_TARGETS)