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 ####################################
85 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
86 # check for CRLF line endings
87 ifneq (0,$(shell $(PERL
) -e
'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR
)/client.mk
))
88 $(error This source tree appears to have Windows-style line endings. To \
89 convert it to Unix-style line endings
, run \
90 "python mozilla/build/win32/mozilla-dos2unix.py")
94 ####################################
95 # Load mozconfig Options
97 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
99 MOZCONFIG_LOADER
:= build
/autoconf
/mozconfig2client-mk
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
109 $(eval
$(subst ||
,$(CR
),$(shell _PYMAKE
=$(.PYMAKE
) $(TOPSRCDIR
)/$(MOZCONFIG_LOADER
) $(TOPSRCDIR
) 2> $(TOPSRCDIR
)/.mozconfig.out | sed
's/$$/||/')))
112 # Automatically add -jN to make flags if not defined. N defaults to number of cores.
113 ifeq (,$(findstring -j
,$(MOZ_MAKE_FLAGS
)))
114 cores
=$(shell $(PYTHON
) -c
'import multiprocessing; print(multiprocessing.cpu_count())')
115 MOZ_MAKE_FLAGS
+= -j
$(cores
)
120 MOZ_OBJDIR
= obj-
$(CONFIG_GUESS
)
122 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
123 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
124 ifeq (1_a
,$(.PYMAKE
)_
$(firstword a
$(subst /, ,$(MOZ_OBJDIR
))))
125 $(error For Windows Pymake builds
, MOZ_OBJDIR must be a Windows
[and not MSYS
] style path.
)
130 ifdef MOZ_BUILD_PROJECTS
132 ifdef MOZ_CURRENT_PROJECT
133 OBJDIR
= $(MOZ_OBJDIR
)/$(MOZ_CURRENT_PROJECT
)
134 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
135 BUILD_PROJECT_ARG
= MOZ_BUILD_APP
=$(MOZ_CURRENT_PROJECT
)
137 OBJDIR
= $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
138 MOZ_MAKE
= $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
141 else # MOZ_BUILD_PROJECTS
143 OBJDIR
= $(MOZ_OBJDIR
)
144 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
146 endif # MOZ_BUILD_PROJECTS
148 # 'configure' scripts generated by autoconf.
149 CONFIGURES
:= $(TOPSRCDIR
)/configure
150 CONFIGURES
+= $(TOPSRCDIR
)/js
/src
/configure
152 # Make targets that are going to be passed to the real build system
153 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
155 #######################################################################
158 # The default rule is build
160 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$(if
$(MOZ_PGO
),profiledbuild
,realbuild
)
163 include $(TOPSRCDIR
)/config
/makefiles
/makeutils.mk
164 include $(TOPSRCDIR
)/config
/makefiles
/autotargets.mk
166 # Print out any options loaded from mozconfig.
167 all realbuild
clean depend
distclean export libs
install realclean::
168 @if
test -f .mozconfig.out
; then \
169 cat .mozconfig.out
; \
170 rm -f .mozconfig.out
; \
174 # Windows equivalents
176 build_all_dep
: alldep
177 build_all_depend
: alldep
178 clobber clobber_all
: clean
180 # helper target for mobile
181 build_and_deploy
: build fast-package
install
183 # Do everything from scratch
184 everything
: clean build
186 ####################################
187 # Profile-Guided Optimization
188 # To use this, you should set the following variables in your mozconfig
189 # mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
191 # The profile script should exercise the functionality to be included
192 # in the profile feedback.
194 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
195 # is usable in multi-pass builds, where you might not have a runnable
196 # application until all the build passes and postflight scripts have run.
198 PGO_OBJDIR
= $(MOZ_OBJDIR
)
200 PGO_OBJDIR
:= $(TOPSRCDIR
)
204 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_GENERATE
=1 MOZ_PGO_INSTRUMENTED
=1
205 $(MAKE
) -C
$(PGO_OBJDIR
) package MOZ_PGO_INSTRUMENTED
=1 MOZ_INTERNAL_SIGNING_FORMAT
= MOZ_EXTERNAL_SIGNING_FORMAT
=
206 MOZ_PGO_INSTRUMENTED
=1 OBJDIR
=${PGO_OBJDIR} JARLOG_DIR
=${PGO_OBJDIR}/jarlog
/en-US
$(PROFILE_GEN_SCRIPT
)
207 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk maybe_clobber_profiledbuild
208 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_USE
=1
210 #####################################################
211 # Build date unification
213 ifdef MOZ_UNIFY_BDATE
214 ifndef MOZ_BUILD_DATE
215 ifdef MOZ_BUILD_PROJECTS
216 MOZ_BUILD_DATE
= $(shell $(PYTHON
) $(TOPSRCDIR
)/toolkit
/xre
/make-platformini.py
--print-buildid
)
217 export MOZ_BUILD_DATE
222 #####################################################
223 # Preflight, before building any project
225 realbuild alldep preflight_all
::
226 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_PREFLIGHT_ALL
),,1))
227 # Don't run preflight_all for individual projects in multi-project builds
228 # (when MOZ_CURRENT_PROJECT is set.)
229 ifndef MOZ_BUILD_PROJECTS
230 # Building a single project, OBJDIR is usable.
232 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
233 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
236 # OBJDIR refers to the project-specific OBJDIR, which is not available at
237 # this point when building multiple projects. Only MOZ_OBJDIR is available.
239 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
240 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
245 # If we're building multiple projects, but haven't specified which project,
248 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_BUILD_PROJECTS
),,1))
249 configure depend realbuild preflight postflight
$(OBJDIR_TARGETS
)::
251 for app in
$(MOZ_BUILD_PROJECTS
); do \
252 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$@ MOZ_CURRENT_PROJECT
=$$app; \
257 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
258 # individual project in a multi-project build.
260 ####################################
263 MAKEFILE
= $(wildcard $(OBJDIR
)/Makefile
)
264 CONFIG_STATUS
= $(wildcard $(OBJDIR
)/config.status
)
265 CONFIG_CACHE
= $(wildcard $(OBJDIR
)/config.cache
)
267 EXTRA_CONFIG_DEPS
:= \
268 $(TOPSRCDIR
)/aclocal.m4 \
269 $(wildcard $(TOPSRCDIR
)/build
/autoconf
/*.m4
) \
270 $(TOPSRCDIR
)/js
/src
/aclocal.m4 \
273 $(CONFIGURES
): %: %.in
$(EXTRA_CONFIG_DEPS
)
274 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/build
$(TOPSRCDIR
)/build
275 @echo Generating
$@ using autoconf
276 cd
$(@D
); $(AUTOCONF
)
278 CONFIG_STATUS_DEPS
:= \
279 $(wildcard $(TOPSRCDIR
)/*/confvars.sh
) \
281 $(TOPSRCDIR
)/allmakefiles.sh \
282 $(TOPSRCDIR
)/CLOBBER \
283 $(TOPSRCDIR
)/nsprpub
/configure \
284 $(TOPSRCDIR
)/config
/milestone.txt \
285 $(TOPSRCDIR
)/js
/src
/config
/milestone.txt \
286 $(TOPSRCDIR
)/browser
/config
/version.txt \
287 $(TOPSRCDIR
)/build
/virtualenv
/packages.txt \
288 $(TOPSRCDIR
)/build
/virtualenv
/populate_virtualenv.py \
291 CONFIGURE_ENV_ARGS
+= \
295 # configure uses the program name to determine @srcdir@. Calling it without
296 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
297 # path of $(TOPSRCDIR).
298 ifeq ($(TOPSRCDIR
),$(OBJDIR
))
299 CONFIGURE
= .
/configure
301 CONFIGURE
= $(TOPSRCDIR
)/configure
304 configure-files
: $(CONFIGURES
)
308 $(call mkdir_deps
,$(OBJDIR
)) \
309 $(if
$(MOZ_BUILD_PROJECTS
),$(call mkdir_deps
,$(MOZ_OBJDIR
))) \
313 save-mozconfig
: $(FOUND_MOZCONFIG
)
314 -cp
$(FOUND_MOZCONFIG
) $(OBJDIR
)/.mozconfig
316 configure
:: $(configure-preqs
)
318 @echo
$(CONFIGURE
) $(CONFIGURE_ARGS
)
319 @cd
$(OBJDIR
) && $(BUILD_PROJECT_ARG
) $(CONFIGURE_ENV_ARGS
) $(CONFIGURE
) $(CONFIGURE_ARGS
) \
320 ||
( echo
"*** Fix above errors and then restart with\
321 \"$(MAKE) -f client.mk build\"" && exit
1 )
322 @touch
$(OBJDIR
)/Makefile
325 $(OBJDIR
)/Makefile
: $(OBJDIR
)/config.status
327 $(OBJDIR
)/config.status
: $(CONFIG_STATUS_DEPS
)
329 $(OBJDIR
)/Makefile
: $(CONFIG_STATUS_DEPS
)
331 @
$(MAKE
) -f
$(TOPSRCDIR
)/client.mk configure
333 ifneq (,$(CONFIG_STATUS
))
334 $(OBJDIR
)/config
/autoconf.mk
: $(TOPSRCDIR
)/config
/autoconf.mk.in
335 $(PYTHON
) $(OBJDIR
)/config.status
-n
--file
=$(OBJDIR
)/config
/autoconf.mk
339 ####################################
342 depend
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
343 $(MOZ_MAKE
) export && $(MOZ_MAKE
) depend
345 ####################################
348 realbuild alldep preflight
::
351 for mkfile in
$(MOZ_PREFLIGHT
); do \
352 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
356 ####################################
359 realbuild
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status check-sync-dirs-config
362 ####################################
365 # Pass these target onto the real build system
366 $(OBJDIR_TARGETS
):: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
369 ####################################
372 realbuild alldep postflight
::
375 for mkfile in
$(MOZ_POSTFLIGHT
); do \
376 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
380 endif # MOZ_CURRENT_PROJECT
382 ####################################
383 # Postflight, after building all projects
385 realbuild alldep postflight_all
::
386 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_POSTFLIGHT_ALL
),,1))
387 # Don't run postflight_all for individual projects in multi-project builds
388 # (when MOZ_CURRENT_PROJECT is set.)
389 ifndef MOZ_BUILD_PROJECTS
390 # Building a single project, OBJDIR is usable.
392 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
393 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
396 # OBJDIR refers to the project-specific OBJDIR, which is not available at
397 # this point when building multiple projects. Only MOZ_OBJDIR is available.
399 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
400 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
407 if
[ -f Makefile
]; then \
408 $(MAKE
) distclean ; \
410 echo
"Removing object files from srcdir..."; \
411 rm -fr
`find . -type d \( -name .deps -print -o -name CVS \
412 -o -exec test ! -d {}/CVS \; \) -prune \
413 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
414 build
/autoconf
/clean-config.sh
; \
417 # Because SpiderMonkey can be distributed and built independently
418 # of the Mozilla source tree, it contains its own copies of many of
419 # the files used by the top-level Mozilla build process, from the
420 # 'config' and 'build' subtrees.
422 # To make it simpler to keep the copies in sync, we follow the policy
423 # that the SpiderMonkey copies must always be exact copies of those in
424 # the containing Mozilla tree. If you've made a change in one, it
425 # belongs in the other as well. If the change isn't right for both
426 # places, then that's something to bring up with the other developers.
428 # Some files are reasonable to diverge; for example,
429 # js/src/config/autoconf.mk.in doesn't need most of the stuff in
430 # config/autoconf.mk.in.
431 .PHONY
: check-sync-dirs
432 check-sync-dirs
: check-sync-dirs-build check-sync-dirs-config
434 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/$* $(TOPSRCDIR
)/$*
439 # This makefile doesn't support parallel execution. It does pass
440 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
444 .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
)