Bug 732976 - SingleSourceFactory should generate checksums file. r=ted
[gecko.git] / client.mk
blobe4d3ef38dcb8db3a39adc485bff961fbf72966c0
1 # -*- makefile -*-
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
14 # License.
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.
23 # Contributor(s):
24 # Stephen Lamm
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.
46 # To build a tree,
47 # 1. hg clone ssh://hg.mozilla.org/mozilla-central mozilla
48 # 2. cd 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...]),
54 # build
55 # clean (realclean is now the same as clean)
56 # distclean
58 # See http://developer.mozilla.org/en/docs/Build_Documentation for
59 # more information.
61 # Options:
62 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
63 # of MOZ_OBJDIR
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
71 # MOZ_BUILD_PROJECTS
73 #######################################################################
74 # Defines
76 comma := ,
78 CWD := $(CURDIR)
79 ifneq (1,$(words $(CWD)))
80 $(error The mozilla directory cannot be located in a path with spaces.)
81 endif
83 ifeq "$(CWD)" "/"
84 CWD := /.
85 endif
87 ifndef TOPSRCDIR
88 ifeq (,$(wildcard client.mk))
89 TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST)))
90 MOZ_OBJDIR = .
91 else
92 TOPSRCDIR := $(CWD)
93 endif
94 endif
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)
102 endif
104 MKDIR := mkdir
105 SH := /bin/sh
106 PERL ?= perl
107 PYTHON ?= python
109 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
110 ifdef CONFIG_GUESS_SCRIPT
111 CONFIG_GUESS = $(shell $(CONFIG_GUESS_SCRIPT))
112 endif
115 ####################################
116 # Sanity checks
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")
124 endif
125 endif
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
141 ifndef MOZ_OBJDIR
142 MOZ_OBJDIR = obj-$(CONFIG_GUESS)
143 else
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.)
148 endif
149 endif
150 endif
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)
158 else
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.)
161 endif
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 #######################################################################
178 # Rules
180 # The default rule is build
181 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; \
190 else true; \
193 # Windows equivalents
194 build_all: build
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.
213 ifdef MOZ_OBJDIR
214 PGO_OBJDIR = $(MOZ_OBJDIR)
215 else
216 PGO_OBJDIR := $(TOPSRCDIR)
217 endif
219 profiledbuild::
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
234 endif
235 endif
236 endif
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.
247 set -e; \
248 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
249 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
250 done
251 else
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.
254 set -e; \
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)"; \
257 done
258 endif
259 endif
261 # If we're building multiple projects, but haven't specified which project,
262 # loop through them.
264 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
265 configure depend realbuild preflight postflight $(OBJDIR_TARGETS)::
266 set -e; \
267 for app in $(MOZ_BUILD_PROJECTS); do \
268 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
269 done
271 else
273 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
274 # individual project in a multi-project build.
276 ####################################
277 # Configure
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 \
287 $(NULL)
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)/*/))) \
302 $(NULL)
304 CONFIGURE_ENV_ARGS += \
305 MAKE="$(MAKE)" \
306 $(NULL)
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
313 else
314 CONFIGURE = $(TOPSRCDIR)/configure
315 endif
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
322 endif
323 @if test ! -d $(OBJDIR); then $(MKDIR) $(OBJDIR); else true; fi
324 @echo cd $(OBJDIR);
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
331 ifneq (,$(MAKEFILE))
332 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
334 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
335 else
336 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
337 endif
338 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
340 ifneq (,$(CONFIG_STATUS))
341 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
342 cd $(OBJDIR); \
343 CONFIG_FILES=config/autoconf.mk ./config.status
344 endif
347 ####################################
348 # Depend
350 depend:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
351 $(MOZ_MAKE) export && $(MOZ_MAKE) depend
353 ####################################
354 # Preflight
356 realbuild alldep preflight::
357 ifdef MOZ_PREFLIGHT
358 set -e; \
359 for mkfile in $(MOZ_PREFLIGHT); do \
360 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
361 done
362 endif
364 ####################################
365 # Build it
367 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
368 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/config $(TOPSRCDIR)/config
369 $(MOZ_MAKE)
371 ####################################
372 # Other targets
374 # Pass these target onto the real build system
375 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
376 $(MOZ_MAKE) $@
378 ####################################
379 # Postflight
381 realbuild alldep postflight::
382 ifdef MOZ_POSTFLIGHT
383 set -e; \
384 for mkfile in $(MOZ_POSTFLIGHT); do \
385 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
386 done
387 endif
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.
400 set -e; \
401 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
402 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
403 done
404 else
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.
407 set -e; \
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)"; \
410 done
411 endif
412 endif
414 cleansrcdir:
415 @cd $(TOPSRCDIR); \
416 if [ -f Makefile ]; then \
417 $(MAKE) distclean ; \
418 else \
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; \
426 echo-variable-%:
427 @echo $($*)
429 # This makefile doesn't support parallel execution. It does pass
430 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
431 # in parallel.
432 .NOTPARALLEL:
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)