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.
10 # 1. hg clone ssh://hg.mozilla.org/mozilla-central 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...]),
18 # clean (realclean is now the same as clean)
21 # See http://developer.mozilla.org/en/docs/Build_Documentation for
25 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
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
36 #######################################################################
42 ifneq (1,$(words $(CWD
)))
43 $(error The mozilla directory cannot be located in a path with spaces.
)
51 ifeq (,$(wildcard client.mk
))
52 TOPSRCDIR
:= $(patsubst %/,%,$(dir $(MAKEFILE_LIST
)))
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
)
68 ifeq (,$(strip $(AUTOCONF
)))
69 AUTOCONF
=$(error Could not find autoconf
2.13)
76 CONFIG_GUESS_SCRIPT
:= $(wildcard $(TOPSRCDIR
)/build
/autoconf
/config.guess
)
77 ifdef CONFIG_GUESS_SCRIPT
78 CONFIG_GUESS
:= $(shell $(CONFIG_GUESS_SCRIPT
))
82 ####################################
86 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
88 # Require pymake (as opposed to GNU make).
90 $(error Pymake is required to build on Windows. Run |.
/mach build| to \
91 automatically use pymake. Or
, invoke pymake directly via \
92 |python build
/pymake
/make.py|.
)
95 # check for CRLF line endings
96 ifneq (0,$(shell $(PERL
) -e
'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR
)/client.mk
))
97 $(error This source tree appears to have Windows-style line endings. To \
98 convert it to Unix-style line endings
, run \
99 "python mozilla/build/win32/mozilla-dos2unix.py")
103 ####################################
104 # Load mozconfig Options
106 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
107 # mozconfig.mk needs to be loaded multiple times by configure, so we don't check
108 # for INCLUDED_MOZCONFIG_MK
109 include $(TOPSRCDIR
)/config
/makefiles
/mozconfig.mk
115 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
116 ifeq (,$(findstring -j
,$(MOZ_MAKE_FLAGS
)))
117 cores
=$(shell $(PYTHON
) -c
'import multiprocessing; print(multiprocessing.cpu_count())')
118 MOZ_MAKE_FLAGS
+= -j
$(cores
)
123 MOZ_OBJDIR
= obj-
$(CONFIG_GUESS
)
125 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
126 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
127 ifeq (1_a
,$(.PYMAKE
)_
$(firstword a
$(subst /, ,$(MOZ_OBJDIR
))))
128 $(error For Windows Pymake builds
, MOZ_OBJDIR must be a Windows
[and not MSYS
] style path.
)
133 ifdef MOZ_BUILD_PROJECTS
135 ifdef MOZ_CURRENT_PROJECT
136 OBJDIR
= $(MOZ_OBJDIR
)/$(MOZ_CURRENT_PROJECT
)
137 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
138 BUILD_PROJECT_ARG
= MOZ_BUILD_APP
=$(MOZ_CURRENT_PROJECT
)
140 OBJDIR
= $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
141 MOZ_MAKE
= $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
144 else # MOZ_BUILD_PROJECTS
146 OBJDIR
= $(MOZ_OBJDIR
)
147 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
149 endif # MOZ_BUILD_PROJECTS
151 # 'configure' scripts generated by autoconf.
152 CONFIGURES
:= $(TOPSRCDIR
)/configure
153 CONFIGURES
+= $(TOPSRCDIR
)/js
/src
/configure
155 # Make targets that are going to be passed to the real build system
156 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
158 #######################################################################
161 # The default rule is build
163 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$(if
$(MOZ_PGO
),profiledbuild
,realbuild
)
166 include $(TOPSRCDIR
)/config
/makefiles
/makeutils.mk
167 include $(TOPSRCDIR
)/config
/makefiles
/autotargets.mk
169 # Print out any options loaded from mozconfig.
170 all realbuild
clean depend
distclean export libs
install realclean::
171 @if
test -f .mozconfig.out
; then \
172 cat .mozconfig.out
; \
173 rm -f .mozconfig.out
; \
177 # Windows equivalents
179 build_all_dep
: alldep
180 build_all_depend
: alldep
181 clobber clobber_all
: clean
183 # helper target for mobile
184 build_and_deploy
: build fast-package
install
186 # Do everything from scratch
187 everything
: clean build
189 ####################################
190 # Profile-Guided Optimization
191 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
192 # is usable in multi-pass builds, where you might not have a runnable
193 # application until all the build passes and postflight scripts have run.
195 PGO_OBJDIR
= $(MOZ_OBJDIR
)
197 PGO_OBJDIR
:= $(TOPSRCDIR
)
201 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_GENERATE
=1 MOZ_PGO_INSTRUMENTED
=1
202 $(MAKE
) -C
$(PGO_OBJDIR
) package MOZ_PGO_INSTRUMENTED
=1 MOZ_INTERNAL_SIGNING_FORMAT
= MOZ_EXTERNAL_SIGNING_FORMAT
=
203 rm -f
${PGO_OBJDIR}/jarlog
/en-US.log
204 MOZ_PGO_INSTRUMENTED
=1 JARLOG_FILE
=jarlog
/en-US.log EXTRA_TEST_ARGS
=10 $(MAKE
) -C
$(PGO_OBJDIR
) pgo-profile-run
205 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk maybe_clobber_profiledbuild
206 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_USE
=1
208 #####################################################
209 # Build date unification
211 ifdef MOZ_UNIFY_BDATE
212 ifndef MOZ_BUILD_DATE
213 ifdef MOZ_BUILD_PROJECTS
214 MOZ_BUILD_DATE
= $(shell $(PYTHON
) $(TOPSRCDIR
)/toolkit
/xre
/make-platformini.py
--print-buildid
)
215 export MOZ_BUILD_DATE
220 #####################################################
221 # Preflight, before building any project
223 realbuild alldep preflight_all
::
224 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_PREFLIGHT_ALL
),,1))
225 # Don't run preflight_all for individual projects in multi-project builds
226 # (when MOZ_CURRENT_PROJECT is set.)
227 ifndef MOZ_BUILD_PROJECTS
228 # Building a single project, OBJDIR is usable.
230 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
231 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
234 # OBJDIR refers to the project-specific OBJDIR, which is not available at
235 # this point when building multiple projects. Only MOZ_OBJDIR is available.
237 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
238 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
243 # If we're building multiple projects, but haven't specified which project,
246 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_BUILD_PROJECTS
),,1))
247 configure depend realbuild preflight postflight
$(OBJDIR_TARGETS
)::
249 for app in
$(MOZ_BUILD_PROJECTS
); do \
250 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$@ MOZ_CURRENT_PROJECT
=$$app; \
255 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
256 # individual project in a multi-project build.
258 ####################################
261 MAKEFILE
= $(wildcard $(OBJDIR
)/Makefile
)
262 CONFIG_STATUS
= $(wildcard $(OBJDIR
)/config.status
)
263 CONFIG_CACHE
= $(wildcard $(OBJDIR
)/config.cache
)
265 EXTRA_CONFIG_DEPS
:= \
266 $(TOPSRCDIR
)/aclocal.m4 \
267 $(wildcard $(TOPSRCDIR
)/build
/autoconf
/*.m4
) \
268 $(TOPSRCDIR
)/js
/src
/aclocal.m4 \
271 $(CONFIGURES
): %: %.in
$(EXTRA_CONFIG_DEPS
)
272 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/build
$(TOPSRCDIR
)/build
273 @echo Generating
$@ using autoconf
274 cd
$(@D
); $(AUTOCONF
)
276 CONFIG_STATUS_DEPS
:= \
277 $(wildcard $(TOPSRCDIR
)/*/confvars.sh
) \
279 $(TOPSRCDIR
)/CLOBBER \
280 $(TOPSRCDIR
)/nsprpub
/configure \
281 $(TOPSRCDIR
)/config
/milestone.txt \
282 $(TOPSRCDIR
)/js
/src
/config
/milestone.txt \
283 $(TOPSRCDIR
)/browser
/config
/version.txt \
284 $(TOPSRCDIR
)/build
/virtualenv
/packages.txt \
285 $(TOPSRCDIR
)/build
/virtualenv
/populate_virtualenv.py \
286 $(TOPSRCDIR
)/testing
/mozbase
/packages.txt \
289 CONFIGURE_ENV_ARGS
+= \
293 # configure uses the program name to determine @srcdir@. Calling it without
294 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
295 # path of $(TOPSRCDIR).
296 ifeq ($(TOPSRCDIR
),$(OBJDIR
))
297 CONFIGURE
= .
/configure
299 CONFIGURE
= $(TOPSRCDIR
)/configure
303 $(PYTHON
) $(TOPSRCDIR
)/config
/pythonpath.py
-I
$(TOPSRCDIR
)/testing
/mozbase
/mozfile \
304 $(TOPSRCDIR
)/python
/mozbuild
/mozbuild
/controller
/clobber.py
$(TOPSRCDIR
) $(OBJDIR
)
306 configure-files
: $(CONFIGURES
)
311 $(call mkdir_deps
,$(OBJDIR
)) \
312 $(if
$(MOZ_BUILD_PROJECTS
),$(call mkdir_deps
,$(MOZ_OBJDIR
))) \
316 save-mozconfig
: $(FOUND_MOZCONFIG
)
317 -cp
$(FOUND_MOZCONFIG
) $(OBJDIR
)/.mozconfig
319 configure
:: $(configure-preqs
)
321 @echo
$(CONFIGURE
) $(CONFIGURE_ARGS
)
322 @cd
$(OBJDIR
) && $(BUILD_PROJECT_ARG
) $(CONFIGURE_ENV_ARGS
) $(CONFIGURE
) $(CONFIGURE_ARGS
) \
323 ||
( echo
"*** Fix above errors and then restart with\
324 \"$(MAKE) -f client.mk build\"" && exit
1 )
325 @touch
$(OBJDIR
)/Makefile
328 $(OBJDIR
)/Makefile
: $(OBJDIR
)/config.status
330 $(OBJDIR
)/config.status
: $(CONFIG_STATUS_DEPS
)
332 $(OBJDIR
)/Makefile
: $(CONFIG_STATUS_DEPS
)
334 @
$(MAKE
) -f
$(TOPSRCDIR
)/client.mk configure
336 ifneq (,$(CONFIG_STATUS
))
337 $(OBJDIR
)/config
/autoconf.mk
: $(TOPSRCDIR
)/config
/autoconf.mk.in
338 $(PYTHON
) $(OBJDIR
)/config.status
-n
--file
=$(OBJDIR
)/config
/autoconf.mk
342 ####################################
345 depend
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
346 $(MOZ_MAKE
) export && $(MOZ_MAKE
) depend
348 ####################################
351 realbuild alldep preflight
::
354 for mkfile in
$(MOZ_PREFLIGHT
); do \
355 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
359 ####################################
362 realbuild
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status check-sync-dirs-config
365 ####################################
368 # Pass these target onto the real build system
369 $(OBJDIR_TARGETS
):: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
372 ####################################
375 realbuild alldep postflight
::
378 for mkfile in
$(MOZ_POSTFLIGHT
); do \
379 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
383 endif # MOZ_CURRENT_PROJECT
385 ####################################
386 # Postflight, after building all projects
388 realbuild alldep postflight_all
::
389 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_POSTFLIGHT_ALL
),,1))
390 # Don't run postflight_all for individual projects in multi-project builds
391 # (when MOZ_CURRENT_PROJECT is set.)
392 ifndef MOZ_BUILD_PROJECTS
393 # Building a single project, OBJDIR is usable.
395 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
396 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
399 # OBJDIR refers to the project-specific OBJDIR, which is not available at
400 # this point when building multiple projects. Only MOZ_OBJDIR is available.
402 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
403 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
410 if
[ -f Makefile
]; then \
411 $(MAKE
) distclean ; \
413 echo
"Removing object files from srcdir..."; \
414 rm -fr
`find . -type d \( -name .deps -print -o -name CVS \
415 -o -exec test ! -d {}/CVS \; \) -prune \
416 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
417 build
/autoconf
/clean-config.sh
; \
420 # Because SpiderMonkey can be distributed and built independently
421 # of the Mozilla source tree, it contains its own copies of many of
422 # the files used by the top-level Mozilla build process, from the
423 # 'config' and 'build' subtrees.
425 # To make it simpler to keep the copies in sync, we follow the policy
426 # that the SpiderMonkey copies must always be exact copies of those in
427 # the containing Mozilla tree. If you've made a change in one, it
428 # belongs in the other as well. If the change isn't right for both
429 # places, then that's something to bring up with the other developers.
431 # Some files are reasonable to diverge; for example,
432 # js/src/config/autoconf.mk.in doesn't need most of the stuff in
433 # config/autoconf.mk.in.
434 .PHONY
: check-sync-dirs
435 check-sync-dirs
: check-sync-dirs-build check-sync-dirs-config
437 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/$* $(TOPSRCDIR
)/$*
442 # This makefile doesn't support parallel execution. It does pass
443 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute