2 # vim:set ts=8 sw=8 sts=8 noet:
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
16 # The Original Code is mozilla.org code.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1998
21 # the Initial Developer. All Rights Reserved.
25 # Benjamin Smedberg <bsmedberg@covad.net>
26 # Chase Phillips <chase@mozilla.org>
27 # Mark Mentovai <mark@moxienet.com>
28 # Joey Armstrong <joey@mozilla.com>
30 # Alternatively, the contents of this file may be used under the terms of
31 # either the GNU General Public License Version 2 or later (the "GPL"), or
32 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 # in which case the provisions of the GPL or the LGPL are applicable instead
34 # of those above. If you wish to allow use of your version of this file only
35 # under the terms of either the GPL or the LGPL, and not to allow others to
36 # use your version of this file under the terms of the MPL, indicate your
37 # decision by deleting the provisions above and replace them with the notice
38 # and other provisions required by the GPL or the LGPL. If you do not delete
39 # the provisions above, a recipient may use your version of this file under
40 # the terms of any one of the MPL, the GPL or the LGPL.
42 # ***** END LICENSE BLOCK *****
44 # Build a mozilla application.
47 # 1. hg clone ssh://hg.mozilla.org/mozilla-central mozilla
49 # 3. create your .mozconfig file with
50 # ac_add_options --enable-application=browser
51 # 4. gmake -f client.mk
53 # Other targets (gmake -f client.mk [targets...]),
55 # clean (realclean is now the same as clean)
58 # See http://developer.mozilla.org/en/docs/Build_Documentation for
62 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
64 # MOZ_OBJDIR - Destination object directory
65 # MOZ_MAKE_FLAGS - Flags to pass to $(MAKE)
66 # MOZ_PREFLIGHT_ALL } - Makefiles to run before any project in
67 # MOZ_PREFLIGHT } MOZ_BUILD_PROJECTS, before each project, after
68 # MOZ_POSTFLIGHT } each project, and after all projects; these
69 # MOZ_POSTFLIGHT_ALL } variables contain space-separated lists
70 # MOZ_UNIFY_BDATE - Set to use the same bdate for each project in
73 #######################################################################
79 ifneq (1,$(words $(CWD
)))
80 $(error The mozilla directory cannot be located in a path with spaces.
)
88 ifeq (,$(wildcard client.mk
))
89 TOPSRCDIR
:= $(patsubst %/,%,$(dir $(MAKEFILE_LIST
)))
96 # try to find autoconf 2.13 - discard errors from 'which'
97 # MacOS X 10.4 sends "no autoconf*" errors to stdout, discard those via grep
98 AUTOCONF ?
= $(shell which autoconf-2.13 autoconf2.13 autoconf213
2>/dev
/null | grep
-v
'^no autoconf' | head
-1)
100 ifeq (,$(strip $(AUTOCONF
)))
101 AUTOCONF
=$(error Could not find autoconf
2.13)
109 CONFIG_GUESS_SCRIPT
:= $(wildcard $(TOPSRCDIR
)/build
/autoconf
/config.guess
)
110 ifdef CONFIG_GUESS_SCRIPT
111 CONFIG_GUESS
= $(shell $(CONFIG_GUESS_SCRIPT
))
115 ####################################
118 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
119 # check for CRLF line endings
120 ifneq (0,$(shell $(PERL
) -e
'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR
)/client.mk
))
121 $(error This source tree appears to have Windows-style line endings. To \
122 convert it to Unix-style line endings
, run \
123 "python mozilla/build/win32/mozilla-dos2unix.py")
127 ####################################
128 # Load mozconfig Options
130 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
132 MOZCONFIG_LOADER
:= build
/autoconf
/mozconfig2client-mk
133 MOZCONFIG_FINDER
:= build
/autoconf
/mozconfig-find
134 MOZCONFIG_MODULES
:= build
/unix
/uniq.pl
136 run_for_side_effects
:= \
137 $(shell $(TOPSRCDIR
)/$(MOZCONFIG_LOADER
) $(TOPSRCDIR
) $(TOPSRCDIR
)/.mozconfig.mk
> $(TOPSRCDIR
)/.mozconfig.out
)
139 include $(TOPSRCDIR
)/.mozconfig.mk
142 MOZ_OBJDIR
= obj-
$(CONFIG_GUESS
)
144 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
145 ifneq (,$(findstring mingw
,$(CONFIG_GUESS
)))
146 ifeq (1_a
,$(.PYMAKE
)_
$(firstword a
$(subst /, ,$(MOZ_OBJDIR
))))
147 $(error For Windows Pymake builds
, MOZ_OBJDIR must be a Windows
[and not MSYS
] style path.
)
152 ifdef MOZ_BUILD_PROJECTS
154 ifdef MOZ_CURRENT_PROJECT
155 OBJDIR
= $(MOZ_OBJDIR
)/$(MOZ_CURRENT_PROJECT
)
156 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
157 BUILD_PROJECT_ARG
= MOZ_BUILD_APP
=$(MOZ_CURRENT_PROJECT
)
159 OBJDIR
= $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
160 MOZ_MAKE
= $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.
)
163 else # MOZ_BUILD_PROJECTS
165 OBJDIR
= $(MOZ_OBJDIR
)
166 MOZ_MAKE
= $(MAKE
) $(MOZ_MAKE_FLAGS
) -C
$(OBJDIR
)
168 endif # MOZ_BUILD_PROJECTS
170 # 'configure' scripts generated by autoconf.
171 CONFIGURES
:= $(TOPSRCDIR
)/configure
172 CONFIGURES
+= $(TOPSRCDIR
)/js
/src
/configure
174 # Make targets that are going to be passed to the real build system
175 OBJDIR_TARGETS
= install export libs
clean realclean distclean alldep maybe_clobber_profiledbuild upload sdk installer package package-compare stage-package source-package l10n-check
177 #######################################################################
180 # The default rule is build
182 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$(if
$(MOZ_PGO
),profiledbuild
,realbuild
)
185 # Print out any options loaded from mozconfig.
186 all realbuild
clean depend
distclean export libs
install realclean::
187 @if
test -f .mozconfig.out
; then \
188 cat .mozconfig.out
; \
189 rm -f .mozconfig.out
; \
193 # Windows equivalents
195 build_all_dep
: alldep
196 build_all_depend
: alldep
197 clobber clobber_all
: clean
199 # Do everything from scratch
200 everything
: clean build
202 ####################################
203 # Profile-Guided Optimization
204 # To use this, you should set the following variables in your mozconfig
205 # mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
207 # The profile script should exercise the functionality to be included
208 # in the profile feedback.
210 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
211 # is usable in multi-pass builds, where you might not have a runnable
212 # application until all the build passes and postflight scripts have run.
214 PGO_OBJDIR
= $(MOZ_OBJDIR
)
216 PGO_OBJDIR
:= $(TOPSRCDIR
)
220 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_GENERATE
=1 MOZ_PGO_INSTRUMENTED
=1
221 $(MAKE
) -C
$(PGO_OBJDIR
) stage-package MOZ_PGO_INSTRUMENTED
=1
222 MOZ_PGO_INSTRUMENTED
=1 OBJDIR
=${PGO_OBJDIR} JARLOG_DIR
=${PGO_OBJDIR}/jarlog
/en-US
$(PROFILE_GEN_SCRIPT
)
223 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk maybe_clobber_profiledbuild
224 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk realbuild MOZ_PROFILE_USE
=1
226 #####################################################
227 # Build date unification
229 ifdef MOZ_UNIFY_BDATE
230 ifndef MOZ_BUILD_DATE
231 ifdef MOZ_BUILD_PROJECTS
232 MOZ_BUILD_DATE
= $(shell $(PYTHON
) $(TOPSRCDIR
)/toolkit
/xre
/make-platformini.py
--print-buildid
)
233 export MOZ_BUILD_DATE
238 #####################################################
239 # Preflight, before building any project
241 realbuild alldep preflight_all
::
242 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_PREFLIGHT_ALL
),,1))
243 # Don't run preflight_all for individual projects in multi-project builds
244 # (when MOZ_CURRENT_PROJECT is set.)
245 ifndef MOZ_BUILD_PROJECTS
246 # Building a single project, OBJDIR is usable.
248 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
249 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
252 # OBJDIR refers to the project-specific OBJDIR, which is not available at
253 # this point when building multiple projects. Only MOZ_OBJDIR is available.
255 for mkfile in
$(MOZ_PREFLIGHT_ALL
); do \
256 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
261 # If we're building multiple projects, but haven't specified which project,
264 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_BUILD_PROJECTS
),,1))
265 configure depend realbuild preflight postflight
$(OBJDIR_TARGETS
)::
267 for app in
$(MOZ_BUILD_PROJECTS
); do \
268 $(MAKE
) -f
$(TOPSRCDIR
)/client.mk
$@ MOZ_CURRENT_PROJECT
=$$app; \
273 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
274 # individual project in a multi-project build.
276 ####################################
279 MAKEFILE
= $(wildcard $(OBJDIR
)/Makefile
)
280 CONFIG_STATUS
= $(wildcard $(OBJDIR
)/config.status
)
281 CONFIG_CACHE
= $(wildcard $(OBJDIR
)/config.cache
)
283 EXTRA_CONFIG_DEPS
:= \
284 $(TOPSRCDIR
)/aclocal.m4 \
285 $(wildcard $(TOPSRCDIR
)/build
/autoconf
/*.m4
) \
286 $(TOPSRCDIR
)/js
/src
/aclocal.m4 \
289 $(CONFIGURES
): %: %.in
$(EXTRA_CONFIG_DEPS
)
290 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/build
$(TOPSRCDIR
)/build
291 @echo Generating
$@ using autoconf
292 cd
$(@D
); $(AUTOCONF
)
294 CONFIG_STATUS_DEPS
:= \
295 $(wildcard $(CONFIGURES
)) \
296 $(TOPSRCDIR
)/allmakefiles.sh \
297 $(wildcard $(TOPSRCDIR
)/nsprpub
/configure
) \
298 $(wildcard $(TOPSRCDIR
)/config
/milestone.txt
) \
299 $(wildcard $(TOPSRCDIR
)/js
/src
/config
/milestone.txt
) \
300 $(wildcard $(TOPSRCDIR
)/browser
/config
/version.txt
) \
301 $(wildcard $(addsuffix confvars.sh
,$(wildcard $(TOPSRCDIR
)/*/))) \
304 CONFIGURE_ENV_ARGS
+= \
308 # configure uses the program name to determine @srcdir@. Calling it without
309 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
310 # path of $(TOPSRCDIR).
311 ifeq ($(TOPSRCDIR
),$(OBJDIR
))
312 CONFIGURE
= .
/configure
314 CONFIGURE
= $(TOPSRCDIR
)/configure
317 configure-files
: $(CONFIGURES
)
319 configure
:: configure-files
320 ifdef MOZ_BUILD_PROJECTS
321 @if
test ! -d
$(MOZ_OBJDIR
); then
$(MKDIR
) $(MOZ_OBJDIR
); else true
; fi
323 @if
test ! -d
$(OBJDIR
); then
$(MKDIR
) $(OBJDIR
); else true
; fi
325 @echo
$(CONFIGURE
) $(CONFIGURE_ARGS
)
326 @cd
$(OBJDIR
) && $(BUILD_PROJECT_ARG
) $(CONFIGURE_ENV_ARGS
) $(CONFIGURE
) $(CONFIGURE_ARGS
) \
327 ||
( echo
"*** Fix above errors and then restart with\
328 \"$(MAKE) -f client.mk build\"" && exit
1 )
329 @touch
$(OBJDIR
)/Makefile
332 $(OBJDIR
)/Makefile
: $(OBJDIR
)/config.status
334 $(OBJDIR
)/config.status
: $(CONFIG_STATUS_DEPS
)
336 $(OBJDIR
)/Makefile
: $(CONFIG_STATUS_DEPS
)
338 @
$(MAKE
) -f
$(TOPSRCDIR
)/client.mk configure
340 ifneq (,$(CONFIG_STATUS
))
341 $(OBJDIR
)/config
/autoconf.mk
: $(TOPSRCDIR
)/config
/autoconf.mk.in
343 CONFIG_FILES
=config
/autoconf.mk .
/config.status
347 ####################################
350 depend
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
351 $(MOZ_MAKE
) export && $(MOZ_MAKE
) depend
353 ####################################
356 realbuild alldep preflight
::
359 for mkfile in
$(MOZ_PREFLIGHT
); do \
360 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile preflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
364 ####################################
367 realbuild
:: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
368 @
$(PYTHON
) $(TOPSRCDIR
)/js
/src
/config
/check-sync-dirs.py
$(TOPSRCDIR
)/js
/src
/config
$(TOPSRCDIR
)/config
371 ####################################
374 # Pass these target onto the real build system
375 $(OBJDIR_TARGETS
):: $(OBJDIR
)/Makefile
$(OBJDIR
)/config.status
378 ####################################
381 realbuild alldep postflight
::
384 for mkfile in
$(MOZ_POSTFLIGHT
); do \
385 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
389 endif # MOZ_CURRENT_PROJECT
391 ####################################
392 # Postflight, after building all projects
394 realbuild alldep postflight_all
::
395 ifeq (,$(MOZ_CURRENT_PROJECT
)$(if
$(MOZ_POSTFLIGHT_ALL
),,1))
396 # Don't run postflight_all for individual projects in multi-project builds
397 # (when MOZ_CURRENT_PROJECT is set.)
398 ifndef MOZ_BUILD_PROJECTS
399 # Building a single project, OBJDIR is usable.
401 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
402 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) OBJDIR
=$(OBJDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
); \
405 # OBJDIR refers to the project-specific OBJDIR, which is not available at
406 # this point when building multiple projects. Only MOZ_OBJDIR is available.
408 for mkfile in
$(MOZ_POSTFLIGHT_ALL
); do \
409 $(MAKE
) -f
$(TOPSRCDIR
)/$$mkfile postflight_all TOPSRCDIR
=$(TOPSRCDIR
) MOZ_OBJDIR
=$(MOZ_OBJDIR
) MOZ_BUILD_PROJECTS
="$(MOZ_BUILD_PROJECTS)"; \
416 if
[ -f Makefile
]; then \
417 $(MAKE
) distclean ; \
419 echo
"Removing object files from srcdir..."; \
420 rm -fr
`find . -type d \( -name .deps -print -o -name CVS \
421 -o -exec test ! -d {}/CVS \; \) -prune \
422 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
423 build
/autoconf
/clean-config.sh
; \
429 # This makefile doesn't support parallel execution. It does pass
430 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
434 .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
)