Bug 1283439 - Include OpusDecoder.h only for Rust MP4 parsing r=kinetik
[gecko.git] / client.mk
blobcef82e779b4d9238138e60299392fec9cbdac5cd
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 ifdef MACH
42 ifndef NO_BUILDSTATUS_MESSAGES
43 define BUILDSTATUS
44 @echo 'BUILDSTATUS $1'
46 endef
47 endif
48 endif
51 CWD := $(CURDIR)
52 ifneq (1,$(words $(CWD)))
53 $(error The mozilla directory cannot be located in a path with spaces.)
54 endif
56 ifeq "$(CWD)" "/"
57 CWD := /.
58 endif
60 ifndef TOPSRCDIR
61 ifeq (,$(wildcard client.mk))
62 TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST)))
63 else
64 TOPSRCDIR := $(CWD)
65 endif
66 endif
68 SH := /bin/sh
69 PERL ?= perl
70 PYTHON ?= $(shell which python2.7 > /dev/null 2>&1 && echo python2.7 || echo python)
72 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
73 ifdef CONFIG_GUESS_SCRIPT
74 CONFIG_GUESS := $(shell $(CONFIG_GUESS_SCRIPT))
75 endif
78 ####################################
79 # Sanity checks
81 # Windows checks.
82 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
84 # check for CRLF line endings
85 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
86 $(error This source tree appears to have Windows-style line endings. To \
87 convert it to Unix-style line endings, check \
88 "https://developer.mozilla.org/en-US/docs/Developer_Guide/Mozilla_build_FAQ\#Win32-specific_questions" \
89 for a workaround of this issue.)
90 endif
92 # Set this for baseconfig.mk
93 HOST_OS_ARCH=WINNT
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 # Include baseconfig.mk for its $(MAKE) validation.
171 include $(TOPSRCDIR)/config/baseconfig.mk
173 # Define mkdir
174 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
175 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
177 # Create a makefile containing the mk_add_options values from mozconfig,
178 # but only do so when OBJDIR is defined (see further above).
179 ifdef MOZ_BUILD_PROJECTS
180 ifdef MOZ_CURRENT_PROJECT
181 WANT_MOZCONFIG_MK = 1
182 else
183 WANT_MOZCONFIG_MK =
184 endif
185 else
186 WANT_MOZCONFIG_MK = 1
187 endif
189 ifdef WANT_MOZCONFIG_MK
190 # For now, only output "export" lines and lines containing UPLOAD_EXTRA_FILES
191 # from mach environment --format=client.mk output.
192 MOZCONFIG_MK_LINES := $(filter export||% UPLOAD_EXTRA_FILES% %UPLOAD_EXTRA_FILES%,$(MOZCONFIG_OUT_LINES))
193 $(OBJDIR)/.mozconfig.mk: $(TOPSRCDIR)/client.mk $(FOUND_MOZCONFIG) $(call mkdir_deps,$(OBJDIR)) $(OBJDIR)/CLOBBER
194 $(if $(MOZCONFIG_MK_LINES),( $(foreach line,$(MOZCONFIG_MK_LINES), echo '$(subst ||, ,$(line))';) )) > $@
195 ifdef MOZ_CURRENT_PROJECT
196 echo export MOZ_CURRENT_PROJECT=$(MOZ_CURRENT_PROJECT) >> $@
197 endif
199 # Include that makefile so that it is created. This should not actually change
200 # the environment since MOZCONFIG_CONTENT, which MOZCONFIG_OUT_LINES derives
201 # from, has already been eval'ed.
202 include $(OBJDIR)/.mozconfig.mk
203 endif
205 # Print out any options loaded from mozconfig.
206 all realbuild clean distclean export libs install realclean::
207 ifneq (,$(strip $(MOZCONFIG_OUT_FILTERED)))
208 $(info Adding client.mk options from $(FOUND_MOZCONFIG):)
209 $(foreach line,$(MOZCONFIG_OUT_FILTERED),$(info $(NULL) $(NULL) $(NULL) $(NULL) $(subst ||, ,$(line))))
210 endif
212 # Windows equivalents
213 build_all: build
214 clobber clobber_all: clean
216 # helper target for mobile
217 build_and_deploy: build package install
219 # Do everything from scratch
220 everything: clean build
222 ####################################
223 # Profile-Guided Optimization
224 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
225 # is usable in multi-pass builds, where you might not have a runnable
226 # application until all the build passes and postflight scripts have run.
227 profiledbuild::
228 $(call BUILDSTATUS,TIERS pgo_profile_generate pgo_package pgo_profile pgo_clobber pgo_profile_use)
229 $(call BUILDSTATUS,TIER_START pgo_profile_generate)
230 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1 CREATE_MOZCONFIG_JSON=
231 $(call BUILDSTATUS,TIER_FINISH pgo_profile_generate)
232 $(call BUILDSTATUS,TIER_START pgo_package)
233 $(MAKE) -C $(OBJDIR) package MOZ_PGO_INSTRUMENTED=1 MOZ_INTERNAL_SIGNING_FORMAT= MOZ_EXTERNAL_SIGNING_FORMAT=
234 rm -f $(OBJDIR)/jarlog/en-US.log
235 $(call BUILDSTATUS,TIER_FINISH pgo_package)
236 $(call BUILDSTATUS,TIER_START pgo_profile)
237 MOZ_PGO_INSTRUMENTED=1 JARLOG_FILE=jarlog/en-US.log EXTRA_TEST_ARGS=10 $(MAKE) -C $(OBJDIR) pgo-profile-run
238 $(call BUILDSTATUS,TIER_FINISH pgo_profile)
239 $(call BUILDSTATUS,TIER_START pgo_clobber)
240 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild CREATE_MOZCONFIG_JSON=
241 $(call BUILDSTATUS,TIER_FINISH pgo_clobber)
242 $(call BUILDSTATUS,TIER_START pgo_profile_use)
243 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1 CREATE_MOZCONFIG_JSON=
244 $(call BUILDSTATUS,TIER_FINISH pgo_profile_use)
246 #####################################################
247 # Build date unification
249 ifdef MOZ_UNIFY_BDATE
250 ifndef MOZ_BUILD_DATE
251 ifdef MOZ_BUILD_PROJECTS
252 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/build/variables.py buildid_header | awk '{print $$3}')
253 export MOZ_BUILD_DATE
254 endif
255 endif
256 endif
258 #####################################################
259 # Preflight, before building any project
261 realbuild preflight_all::
262 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
263 # Don't run preflight_all for individual projects in multi-project builds
264 # (when MOZ_CURRENT_PROJECT is set.)
265 ifndef MOZ_BUILD_PROJECTS
266 # Building a single project, OBJDIR is usable.
267 set -e; \
268 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
269 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
270 done
271 else
272 # OBJDIR refers to the project-specific OBJDIR, which is not available at
273 # this point when building multiple projects. Only MOZ_OBJDIR is available.
274 set -e; \
275 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
276 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
277 done
278 endif
279 endif
281 # If we're building multiple projects, but haven't specified which project,
282 # loop through them.
284 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
285 configure realbuild preflight postflight $(OBJDIR_TARGETS)::
286 set -e; \
287 for app in $(MOZ_BUILD_PROJECTS); do \
288 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
289 done
291 else
293 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
294 # individual project in a multi-project build.
296 ####################################
297 # Configure
299 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
300 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
301 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
303 EXTRA_CONFIG_DEPS := \
304 $(TOPSRCDIR)/aclocal.m4 \
305 $(TOPSRCDIR)/old-configure.in \
306 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
307 $(TOPSRCDIR)/js/src/aclocal.m4 \
308 $(TOPSRCDIR)/js/src/old-configure.in \
309 $(NULL)
311 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
312 @echo Generating $@
313 sed '1,/^divert/d' $< > $@
314 chmod +x $@
316 CONFIG_STATUS_DEPS := \
317 $(wildcard $(TOPSRCDIR)/*/confvars.sh) \
318 $(CONFIGURES) \
319 $(TOPSRCDIR)/CLOBBER \
320 $(TOPSRCDIR)/nsprpub/configure \
321 $(TOPSRCDIR)/config/milestone.txt \
322 $(TOPSRCDIR)/browser/config/version.txt \
323 $(TOPSRCDIR)/browser/config/version_display.txt \
324 $(TOPSRCDIR)/build/virtualenv_packages.txt \
325 $(TOPSRCDIR)/python/mozbuild/mozbuild/virtualenv.py \
326 $(TOPSRCDIR)/testing/mozbase/packages.txt \
327 $(OBJDIR)/.mozconfig.json \
328 $(NULL)
330 CONFIGURE_ENV_ARGS += \
331 MAKE='$(MAKE)' \
332 $(NULL)
334 # configure uses the program name to determine @srcdir@. Calling it without
335 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
336 # path of $(TOPSRCDIR).
337 ifeq ($(TOPSRCDIR),$(OBJDIR))
338 CONFIGURE = ./configure
339 else
340 CONFIGURE = $(TOPSRCDIR)/configure
341 endif
343 $(OBJDIR)/CLOBBER: $(TOPSRCDIR)/CLOBBER
344 $(PYTHON) $(TOPSRCDIR)/config/pythonpath.py -I $(TOPSRCDIR)/testing/mozbase/mozfile \
345 $(TOPSRCDIR)/python/mozbuild/mozbuild/controller/clobber.py $(TOPSRCDIR) $(OBJDIR)
347 configure-files: $(CONFIGURES)
349 configure-preqs = \
350 $(OBJDIR)/CLOBBER \
351 configure-files \
352 $(call mkdir_deps,$(OBJDIR)) \
353 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
354 save-mozconfig \
355 $(OBJDIR)/.mozconfig.json \
356 $(NULL)
358 CREATE_MOZCONFIG_JSON = $(shell $(TOPSRCDIR)/mach environment --format=json -o $(OBJDIR)/.mozconfig.json)
359 # Force CREATE_MOZCONFIG_JSON above to be resolved, without side effects in
360 # case the result is non empty, and allowing an override on the make command
361 # line not running the command (using := $(shell) still runs the shell command).
362 ifneq (,$(CREATE_MOZCONFIG_JSON))
363 endif
365 $(OBJDIR)/.mozconfig.json: $(call mkdir_deps,$(OBJDIR)) ;
367 save-mozconfig: $(FOUND_MOZCONFIG)
368 ifdef FOUND_MOZCONFIG
369 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
370 endif
372 configure:: $(configure-preqs)
373 $(call BUILDSTATUS,TIERS configure)
374 $(call BUILDSTATUS,TIER_START configure)
375 @echo cd $(OBJDIR);
376 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
377 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
378 || ( echo '*** Fix above errors and then restart with\
379 "$(MAKE) -f client.mk build"' && exit 1 )
380 @touch $(OBJDIR)/Makefile
381 $(call BUILDSTATUS,TIER_FINISH configure)
383 ifneq (,$(MAKEFILE))
384 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
386 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
387 else
388 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
389 endif
390 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure CREATE_MOZCONFIG_JSON=
392 ifneq (,$(CONFIG_STATUS))
393 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
394 $(PYTHON) $(OBJDIR)/config.status -n --file=$(OBJDIR)/config/autoconf.mk
395 endif
398 ####################################
399 # Preflight
401 realbuild preflight::
402 ifdef MOZ_PREFLIGHT
403 set -e; \
404 for mkfile in $(MOZ_PREFLIGHT); do \
405 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
406 done
407 endif
409 ####################################
410 # Build it
412 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
413 +$(MOZ_MAKE)
415 ####################################
416 # Other targets
418 # Pass these target onto the real build system
419 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
420 +$(MOZ_MAKE) $@
422 ####################################
423 # Postflight
425 realbuild postflight::
426 ifdef MOZ_POSTFLIGHT
427 set -e; \
428 for mkfile in $(MOZ_POSTFLIGHT); do \
429 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
430 done
431 endif
433 endif # MOZ_CURRENT_PROJECT
435 ####################################
436 # Postflight, after building all projects
438 ifdef MOZ_AUTOMATION
439 ifndef MOZ_CURRENT_PROJECT
440 $(if $(MOZ_PGO),profiledbuild,realbuild)::
441 # Only run the automation/build target for the first project.
442 # (i.e. first platform of universal builds)
443 $(MAKE) -f $(TOPSRCDIR)/client.mk automation/build $(addprefix MOZ_CURRENT_PROJECT=,$(firstword $(MOZ_BUILD_PROJECTS)))
444 endif
445 endif
447 realbuild postflight_all::
448 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
449 # Don't run postflight_all for individual projects in multi-project builds
450 # (when MOZ_CURRENT_PROJECT is set.)
451 ifndef MOZ_BUILD_PROJECTS
452 # Building a single project, OBJDIR is usable.
453 set -e; \
454 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
455 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
456 done
457 else
458 # OBJDIR refers to the project-specific OBJDIR, which is not available at
459 # this point when building multiple projects. Only MOZ_OBJDIR is available.
460 set -e; \
461 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
462 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS='$(MOZ_BUILD_PROJECTS)'; \
463 done
464 endif
465 endif
467 cleansrcdir:
468 @cd $(TOPSRCDIR); \
469 if [ -f Makefile ]; then \
470 $(MAKE) distclean ; \
471 else \
472 echo 'Removing object files from srcdir...'; \
473 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
474 -o -exec test ! -d {}/CVS \; \) -prune \
475 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
476 build/autoconf/clean-config.sh; \
479 echo-variable-%:
480 @echo $($*)
482 # This makefile doesn't support parallel execution. It does pass
483 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
484 # in parallel.
485 .NOTPARALLEL:
487 .PHONY: checkout \
488 real_checkout \
489 realbuild \
490 build \
491 profiledbuild \
492 cleansrcdir \
493 pull_all \
494 build_all \
495 clobber \
496 clobber_all \
497 pull_and_build_all \
498 everything \
499 configure \
500 preflight_all \
501 preflight \
502 postflight \
503 postflight_all \
504 $(OBJDIR_TARGETS)