Bug 578272: Remove Algol-like display optimization. (r=brendan)
[mozilla-central.git] / client.mk
blobbae7e80396e1f22dcdf10c996ad02a3993aaed4c
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
14 # The Original Code is mozilla.org code.
16 # The Initial Developer of the Original Code is
17 # Netscape Communications Corporation.
18 # Portions created by the Initial Developer are Copyright (C) 1998
19 # the Initial Developer. All Rights Reserved.
21 # Contributor(s):
22 # Stephen Lamm
23 # Benjamin Smedberg <bsmedberg@covad.net>
24 # Chase Phillips <chase@mozilla.org>
25 # Mark Mentovai <mark@moxienet.com>
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
41 # Build a mozilla application.
43 # To build a tree,
44 # 1. hg clone ssh://hg.mozilla.org/mozilla-central mozilla
45 # 2. cd mozilla
46 # 3. create your .mozconfig file with
47 # ac_add_options --enable-application=browser
48 # 4. gmake -f client.mk
50 # Other targets (gmake -f client.mk [targets...]),
51 # build
52 # clean (realclean is now the same as clean)
53 # distclean
55 # See http://developer.mozilla.org/en/docs/Build_Documentation for
56 # more information.
58 # Options:
59 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
60 # of MOZ_OBJDIR
61 # MOZ_OBJDIR - Destination object directory
62 # MOZ_MAKE_FLAGS - Flags to pass to $(MAKE)
63 # MOZ_PREFLIGHT_ALL } - Makefiles to run before any project in
64 # MOZ_PREFLIGHT } MOZ_BUILD_PROJECTS, before each project, after
65 # MOZ_POSTFLIGHT } each project, and after all projects; these
66 # MOZ_POSTFLIGHT_ALL } variables contain space-separated lists
67 # MOZ_UNIFY_BDATE - Set to use the same bdate for each project in
68 # MOZ_BUILD_PROJECTS
70 #######################################################################
71 # Defines
73 CVS = cvs
74 comma := ,
76 CWD := $(CURDIR)
77 ifneq (1,$(words $(CWD)))
78 $(error The mozilla directory cannot be located in a path with spaces.)
79 endif
81 ifeq "$(CWD)" "/"
82 CWD := /.
83 endif
85 ifndef TOPSRCDIR
86 ifeq (,$(wildcard client.mk))
87 TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST)))
88 MOZ_OBJDIR = .
89 else
90 TOPSRCDIR := $(CWD)
91 endif
92 endif
94 # try to find autoconf 2.13 - discard errors from 'which'
95 # MacOS X 10.4 sends "no autoconf*" errors to stdout, discard those via grep
96 AUTOCONF ?= $(shell which autoconf-2.13 autoconf2.13 autoconf213 2>/dev/null | grep -v '^no autoconf' | head -1)
98 ifeq (,$(strip $(AUTOCONF)))
99 AUTOCONF=$(error Couldn't find autoconf 2.13)
100 endif
102 MKDIR := mkdir
103 SH := /bin/sh
104 ifndef MAKE
105 MAKE := gmake
106 endif
107 PERL ?= perl
108 PYTHON ?= python
110 RUN_AUTOCONF_LOCALLY = 1
111 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
112 ifdef CONFIG_GUESS_SCRIPT
113 CONFIG_GUESS = $(shell $(CONFIG_GUESS_SCRIPT))
114 endif
117 ####################################
118 # Sanity checks
120 ifneq (,$(filter MINGW%,$(shell uname -s)))
121 # check for CRLF line endings
122 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
123 $(error This source tree appears to have Windows-style line endings. To \
124 convert it to Unix-style line endings, run \
125 "python mozilla/build/win32/mozilla-dos2unix.py")
126 endif
127 endif
129 ####################################
130 # Load mozconfig Options
132 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
134 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
135 MOZCONFIG_FINDER := build/autoconf/mozconfig-find
136 MOZCONFIG_MODULES := build/unix/uniq.pl
140 run_for_side_effects := \
141 $(shell $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) $(TOPSRCDIR)/.mozconfig.mk > $(TOPSRCDIR)/.mozconfig.out)
143 include $(TOPSRCDIR)/.mozconfig.mk
145 ifdef MOZ_BUILD_PROJECTS
147 ifndef MOZ_OBJDIR
148 $(error When MOZ_BUILD_PROJECTS is set, you must set MOZ_OBJDIR)
149 endif
150 ifdef MOZ_CURRENT_PROJECT
151 OBJDIR = $(MOZ_OBJDIR)/$(MOZ_CURRENT_PROJECT)
152 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
153 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
154 else
155 OBJDIR = $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
156 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
157 endif
159 else # MOZ_BUILD_PROJECTS
161 ifdef MOZ_OBJDIR
162 OBJDIR = $(MOZ_OBJDIR)
163 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
164 else
165 OBJDIR := $(TOPSRCDIR)
166 MOZ_MAKE := $(MAKE) $(MOZ_MAKE_FLAGS)
167 endif
169 endif # MOZ_BUILD_PROJECTS
171 # 'configure' scripts generated by autoconf.
172 CONFIGURES := $(TOPSRCDIR)/configure
173 CONFIGURES += $(TOPSRCDIR)/js/src/configure
175 #######################################################################
176 # Rules
179 # The default rule is build
180 build::
182 # Print out any options loaded from mozconfig.
183 all build clean depend distclean export libs install realclean::
184 @if test -f .mozconfig.out; then \
185 cat .mozconfig.out; \
186 rm -f .mozconfig.out; \
187 else true; \
190 # Windows equivalents
191 build_all: build
192 build_all_dep: alldep
193 build_all_depend: alldep
194 clobber clobber_all: clean
196 # Do everything from scratch
197 everything: clean build
199 ####################################
200 # Profile-Guided Optimization
201 # To use this, you should set the following variables in your mozconfig
202 # mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
204 # The profile script should exercise the functionality to be included
205 # in the profile feedback.
207 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
208 # is usable in multi-pass builds, where you might not have a runnable
209 # application until all the build passes and postflight scripts have run.
210 ifdef MOZ_OBJDIR
211 PGO_OBJDIR = $(MOZ_OBJDIR)
212 else
213 PGO_OBJDIR := $(TOPSRCDIR)
214 endif
216 profiledbuild::
217 $(MAKE) -f $(TOPSRCDIR)/client.mk build MOZ_PROFILE_GENERATE=1
218 OBJDIR=${PGO_OBJDIR} $(PROFILE_GEN_SCRIPT)
219 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild
220 $(MAKE) -f $(TOPSRCDIR)/client.mk build MOZ_PROFILE_USE=1
222 #####################################################
223 # Build date unification
225 ifdef MOZ_UNIFY_BDATE
226 ifndef MOZ_BUILD_DATE
227 ifdef MOZ_BUILD_PROJECTS
228 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
229 export MOZ_BUILD_DATE
230 endif
231 endif
232 endif
234 #####################################################
235 # Preflight, before building any project
237 build alldep preflight_all::
238 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
239 # Don't run preflight_all for individual projects in multi-project builds
240 # (when MOZ_CURRENT_PROJECT is set.)
241 ifndef MOZ_BUILD_PROJECTS
242 # Building a single project, OBJDIR is usable.
243 set -e; \
244 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
245 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
246 done
247 else
248 # OBJDIR refers to the project-specific OBJDIR, which is not available at
249 # this point when building multiple projects. Only MOZ_OBJDIR is available.
250 set -e; \
251 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
252 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
253 done
254 endif
255 endif
257 # If we're building multiple projects, but haven't specified which project,
258 # loop through them.
260 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
261 configure depend build install export libs clean realclean distclean alldep preflight postflight maybe_clobber_profiledbuild upload sdk::
262 set -e; \
263 for app in $(MOZ_BUILD_PROJECTS); do \
264 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
265 done
267 else
269 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
270 # individual project in a multi-project build.
272 ####################################
273 # Configure
275 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
276 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
278 ifdef RUN_AUTOCONF_LOCALLY
279 EXTRA_CONFIG_DEPS := \
280 $(TOPSRCDIR)/aclocal.m4 \
281 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
282 $(TOPSRCDIR)/js/src/aclocal.m4 \
283 $(NULL)
285 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
286 @echo Generating $@ using autoconf
287 cd $(@D); $(AUTOCONF)
288 endif
290 CONFIG_STATUS_DEPS := \
291 $(wildcard $(CONFIGURES)) \
292 $(TOPSRCDIR)/allmakefiles.sh \
293 $(TOPSRCDIR)/.mozconfig.mk \
294 $(wildcard $(TOPSRCDIR)/nsprpub/configure) \
295 $(wildcard $(TOPSRCDIR)/config/milestone.txt) \
296 $(wildcard $(TOPSRCDIR)/config/chrome-versions.sh) \
297 $(wildcard $(addsuffix confvars.sh,$(wildcard $(TOPSRCDIR)/*/))) \
298 $(NULL)
300 # configure uses the program name to determine @srcdir@. Calling it without
301 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
302 # path of $(TOPSRCDIR).
303 ifeq ($(TOPSRCDIR),$(OBJDIR))
304 CONFIGURE = ./configure
305 else
306 CONFIGURE = $(TOPSRCDIR)/configure
307 endif
309 ifdef MOZ_TOOLS
310 CONFIGURE = $(TOPSRCDIR)/configure
311 endif
313 configure-files: $(CONFIGURES)
315 configure:: configure-files
316 ifdef MOZ_BUILD_PROJECTS
317 @if test ! -d $(MOZ_OBJDIR); then $(MKDIR) $(MOZ_OBJDIR); else true; fi
318 endif
319 @if test ! -d $(OBJDIR); then $(MKDIR) $(OBJDIR); else true; fi
320 @echo cd $(OBJDIR);
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
327 $(OBJDIR)/Makefile $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
328 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
330 ifneq (,$(CONFIG_STATUS))
331 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
332 cd $(OBJDIR); \
333 CONFIG_FILES=config/autoconf.mk ./config.status
334 endif
337 ####################################
338 # Depend
340 depend:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
341 $(MOZ_MAKE) export && $(MOZ_MAKE) depend
343 ####################################
344 # Preflight
346 build alldep preflight::
347 ifdef MOZ_PREFLIGHT
348 set -e; \
349 for mkfile in $(MOZ_PREFLIGHT); do \
350 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
351 done
352 endif
354 ####################################
355 # Build it
357 build:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
358 $(MOZ_MAKE)
360 ####################################
361 # Other targets
363 # Pass these target onto the real build system
364 install export libs clean realclean distclean alldep maybe_clobber_profiledbuild upload sdk:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
365 $(MOZ_MAKE) $@
367 ####################################
368 # Postflight
370 build alldep postflight::
371 ifdef MOZ_POSTFLIGHT
372 set -e; \
373 for mkfile in $(MOZ_POSTFLIGHT); do \
374 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
375 done
376 endif
378 endif # MOZ_CURRENT_PROJECT
380 ####################################
381 # Postflight, after building all projects
383 build alldep postflight_all::
384 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
385 # Don't run postflight_all for individual projects in multi-project builds
386 # (when MOZ_CURRENT_PROJECT is set.)
387 ifndef MOZ_BUILD_PROJECTS
388 # Building a single project, OBJDIR is usable.
389 set -e; \
390 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
391 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
392 done
393 else
394 # OBJDIR refers to the project-specific OBJDIR, which is not available at
395 # this point when building multiple projects. Only MOZ_OBJDIR is available.
396 set -e; \
397 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
398 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
399 done
400 endif
401 endif
403 cleansrcdir:
404 @cd $(TOPSRCDIR); \
405 if [ -f Makefile ]; then \
406 $(MAKE) distclean ; \
407 else \
408 echo "Removing object files from srcdir..."; \
409 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
410 -o -exec test ! -d {}/CVS \; \) -prune \
411 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
412 build/autoconf/clean-config.sh; \
415 echo-variable-%:
416 @echo $($*)
418 # This makefile doesn't support parallel execution. It does pass
419 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
420 # in parallel.
421 .NOTPARALLEL:
423 .PHONY: checkout real_checkout depend build profiledbuild maybe_clobber_profiledbuild export libs alldep install clean realclean distclean cleansrcdir pull_all build_all clobber clobber_all pull_and_build_all everything configure preflight_all preflight postflight postflight_all