6e907aa89096625de1dd8b3dad7608c19dbc0541
[gecko.git] / client.mk
blob6e907aa89096625de1dd8b3dad7608c19dbc0541
1 # -*- makefile -*-
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.
9 # To build a tree,
10 # 1. hg clone ssh://hg.mozilla.org/mozilla-central mozilla
11 # 2. cd 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...]),
17 # build
18 # clean (realclean is now the same as clean)
19 # distclean
21 # See http://developer.mozilla.org/en/docs/Build_Documentation for
22 # more information.
24 # Options:
25 # MOZ_BUILD_PROJECTS - Build multiple projects in subdirectories
26 # of MOZ_OBJDIR
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
34 # MOZ_BUILD_PROJECTS
36 #######################################################################
37 # Defines
39 comma := ,
41 CWD := $(CURDIR)
42 ifneq (1,$(words $(CWD)))
43 $(error The mozilla directory cannot be located in a path with spaces.)
44 endif
46 ifeq "$(CWD)" "/"
47 CWD := /.
48 endif
50 ifndef TOPSRCDIR
51 ifeq (,$(wildcard client.mk))
52 TOPSRCDIR := $(patsubst %/,%,$(dir $(MAKEFILE_LIST)))
53 MOZ_OBJDIR = .
54 else
55 TOPSRCDIR := $(CWD)
56 endif
57 endif
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 ifeq (,$(strip $(AUTOCONF)))
64 AUTOCONF=$(error Could not find autoconf 2.13)
65 endif
67 SH := /bin/sh
68 PERL ?= perl
69 PYTHON ?= python
71 CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
72 ifdef CONFIG_GUESS_SCRIPT
73 CONFIG_GUESS = $(shell $(CONFIG_GUESS_SCRIPT))
74 endif
77 ####################################
78 # Sanity checks
80 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
81 # check for CRLF line endings
82 ifneq (0,$(shell $(PERL) -e 'binmode(STDIN); while (<STDIN>) { if (/\r/) { print "1"; exit } } print "0"' < $(TOPSRCDIR)/client.mk))
83 $(error This source tree appears to have Windows-style line endings. To \
84 convert it to Unix-style line endings, run \
85 "python mozilla/build/win32/mozilla-dos2unix.py")
86 endif
87 endif
89 ####################################
90 # Load mozconfig Options
92 # See build pages, http://www.mozilla.org/build/ for how to set up mozconfig.
94 MOZCONFIG_LOADER := build/autoconf/mozconfig2client-mk
95 MOZCONFIG_FINDER := build/autoconf/mozconfig-find
96 MOZCONFIG_MODULES := build/unix/uniq.pl
98 run_for_side_effects := \
99 $(shell $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) $(TOPSRCDIR)/.mozconfig.mk > $(TOPSRCDIR)/.mozconfig.out)
101 include $(TOPSRCDIR)/.mozconfig.mk
103 ifndef MOZ_OBJDIR
104 MOZ_OBJDIR = obj-$(CONFIG_GUESS)
105 else
106 # On Windows Pymake builds check MOZ_OBJDIR doesn't start with "/"
107 ifneq (,$(findstring mingw,$(CONFIG_GUESS)))
108 ifeq (1_a,$(.PYMAKE)_$(firstword a$(subst /, ,$(MOZ_OBJDIR))))
109 $(error For Windows Pymake builds, MOZ_OBJDIR must be a Windows [and not MSYS] style path.)
110 endif
111 endif
112 endif
114 ifdef MOZ_BUILD_PROJECTS
116 ifdef MOZ_CURRENT_PROJECT
117 OBJDIR = $(MOZ_OBJDIR)/$(MOZ_CURRENT_PROJECT)
118 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
119 BUILD_PROJECT_ARG = MOZ_BUILD_APP=$(MOZ_CURRENT_PROJECT)
120 else
121 OBJDIR = $(error Cannot find the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
122 MOZ_MAKE = $(error Cannot build in the OBJDIR when MOZ_CURRENT_PROJECT is not set.)
123 endif
125 else # MOZ_BUILD_PROJECTS
127 OBJDIR = $(MOZ_OBJDIR)
128 MOZ_MAKE = $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
130 endif # MOZ_BUILD_PROJECTS
132 # 'configure' scripts generated by autoconf.
133 CONFIGURES := $(TOPSRCDIR)/configure
134 CONFIGURES += $(TOPSRCDIR)/js/src/configure
136 # Make targets that are going to be passed to the real build system
137 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
139 #######################################################################
140 # Rules
142 # The default rule is build
143 build::
144 $(MAKE) -f $(TOPSRCDIR)/client.mk $(if $(MOZ_PGO),profiledbuild,realbuild)
146 # Define mkdir
147 include $(TOPSRCDIR)/config/makefiles/makeutils.mk
148 include $(TOPSRCDIR)/config/makefiles/autotargets.mk
150 # Print out any options loaded from mozconfig.
151 all realbuild clean depend distclean export libs install realclean::
152 @if test -f .mozconfig.out; then \
153 cat .mozconfig.out; \
154 rm -f .mozconfig.out; \
155 else true; \
158 # Windows equivalents
159 build_all: build
160 build_all_dep: alldep
161 build_all_depend: alldep
162 clobber clobber_all: clean
164 # helper target for mobile
165 build_and_deploy: build fast-package install
167 # Do everything from scratch
168 everything: clean build
170 ####################################
171 # Profile-Guided Optimization
172 # To use this, you should set the following variables in your mozconfig
173 # mk_add_options PROFILE_GEN_SCRIPT=/path/to/profile-script
175 # The profile script should exercise the functionality to be included
176 # in the profile feedback.
178 # This is up here, outside of the MOZ_CURRENT_PROJECT logic so that this
179 # is usable in multi-pass builds, where you might not have a runnable
180 # application until all the build passes and postflight scripts have run.
181 ifdef MOZ_OBJDIR
182 PGO_OBJDIR = $(MOZ_OBJDIR)
183 else
184 PGO_OBJDIR := $(TOPSRCDIR)
185 endif
187 profiledbuild::
188 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_GENERATE=1 MOZ_PGO_INSTRUMENTED=1
189 $(MAKE) -C $(PGO_OBJDIR) stage-package MOZ_PGO_INSTRUMENTED=1
190 MOZ_PGO_INSTRUMENTED=1 OBJDIR=${PGO_OBJDIR} JARLOG_DIR=${PGO_OBJDIR}/jarlog/en-US $(PROFILE_GEN_SCRIPT)
191 $(MAKE) -f $(TOPSRCDIR)/client.mk maybe_clobber_profiledbuild
192 $(MAKE) -f $(TOPSRCDIR)/client.mk realbuild MOZ_PROFILE_USE=1
194 #####################################################
195 # Build date unification
197 ifdef MOZ_UNIFY_BDATE
198 ifndef MOZ_BUILD_DATE
199 ifdef MOZ_BUILD_PROJECTS
200 MOZ_BUILD_DATE = $(shell $(PYTHON) $(TOPSRCDIR)/toolkit/xre/make-platformini.py --print-buildid)
201 export MOZ_BUILD_DATE
202 endif
203 endif
204 endif
206 #####################################################
207 # Preflight, before building any project
209 realbuild alldep preflight_all::
210 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_PREFLIGHT_ALL),,1))
211 # Don't run preflight_all for individual projects in multi-project builds
212 # (when MOZ_CURRENT_PROJECT is set.)
213 ifndef MOZ_BUILD_PROJECTS
214 # Building a single project, OBJDIR is usable.
215 set -e; \
216 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
217 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
218 done
219 else
220 # OBJDIR refers to the project-specific OBJDIR, which is not available at
221 # this point when building multiple projects. Only MOZ_OBJDIR is available.
222 set -e; \
223 for mkfile in $(MOZ_PREFLIGHT_ALL); do \
224 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
225 done
226 endif
227 endif
229 # If we're building multiple projects, but haven't specified which project,
230 # loop through them.
232 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_BUILD_PROJECTS),,1))
233 configure depend realbuild preflight postflight $(OBJDIR_TARGETS)::
234 set -e; \
235 for app in $(MOZ_BUILD_PROJECTS); do \
236 $(MAKE) -f $(TOPSRCDIR)/client.mk $@ MOZ_CURRENT_PROJECT=$$app; \
237 done
239 else
241 # MOZ_CURRENT_PROJECT: either doing a single-project build, or building an
242 # individual project in a multi-project build.
244 ####################################
245 # Configure
247 MAKEFILE = $(wildcard $(OBJDIR)/Makefile)
248 CONFIG_STATUS = $(wildcard $(OBJDIR)/config.status)
249 CONFIG_CACHE = $(wildcard $(OBJDIR)/config.cache)
251 EXTRA_CONFIG_DEPS := \
252 $(TOPSRCDIR)/aclocal.m4 \
253 $(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
254 $(TOPSRCDIR)/js/src/aclocal.m4 \
255 $(NULL)
257 $(CONFIGURES): %: %.in $(EXTRA_CONFIG_DEPS)
258 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/build $(TOPSRCDIR)/build
259 @echo Generating $@ using autoconf
260 cd $(@D); $(AUTOCONF)
262 CONFIG_STATUS_DEPS := \
263 $(wildcard \
264 $(CONFIGURES) \
265 $(TOPSRCDIR)/allmakefiles.sh \
266 $(TOPSRCDIR)/nsprpub/configure \
267 $(TOPSRCDIR)/config/milestone.txt \
268 $(TOPSRCDIR)/js/src/config/milestone.txt \
269 $(TOPSRCDIR)/browser/config/version.txt \
270 $(TOPSRCDIR)/*/confvars.sh \
272 $(NULL)
274 CONFIGURE_ENV_ARGS += \
275 MAKE="$(MAKE)" \
276 $(NULL)
278 # configure uses the program name to determine @srcdir@. Calling it without
279 # $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
280 # path of $(TOPSRCDIR).
281 ifeq ($(TOPSRCDIR),$(OBJDIR))
282 CONFIGURE = ./configure
283 else
284 CONFIGURE = $(TOPSRCDIR)/configure
285 endif
287 configure-files: $(CONFIGURES)
289 configure-preqs = \
290 configure-files \
291 $(call mkdir_deps,$(OBJDIR)) \
292 $(if $(MOZ_BUILD_PROJECTS),$(call mkdir_deps,$(MOZ_OBJDIR))) \
293 save-mozconfig \
294 $(NULL)
296 save-mozconfig:
297 -cp $(FOUND_MOZCONFIG) $(OBJDIR)/.mozconfig
299 configure:: $(configure-preqs)
300 @echo cd $(OBJDIR);
301 @echo $(CONFIGURE) $(CONFIGURE_ARGS)
302 @cd $(OBJDIR) && $(BUILD_PROJECT_ARG) $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
303 || ( echo "*** Fix above errors and then restart with\
304 \"$(MAKE) -f client.mk build\"" && exit 1 )
305 @touch $(OBJDIR)/Makefile
307 ifneq (,$(MAKEFILE))
308 $(OBJDIR)/Makefile: $(OBJDIR)/config.status
310 $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
311 else
312 $(OBJDIR)/Makefile: $(CONFIG_STATUS_DEPS)
313 endif
314 @$(MAKE) -f $(TOPSRCDIR)/client.mk configure
316 ifneq (,$(CONFIG_STATUS))
317 $(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
318 cd $(OBJDIR); \
319 CONFIG_FILES=config/autoconf.mk ./config.status
320 endif
323 ####################################
324 # Depend
326 depend:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
327 $(MOZ_MAKE) export && $(MOZ_MAKE) depend
329 ####################################
330 # Preflight
332 realbuild alldep preflight::
333 ifdef MOZ_PREFLIGHT
334 set -e; \
335 for mkfile in $(MOZ_PREFLIGHT); do \
336 $(MAKE) -f $(TOPSRCDIR)/$$mkfile preflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
337 done
338 endif
340 ####################################
341 # Build it
343 realbuild:: $(OBJDIR)/Makefile $(OBJDIR)/config.status check-sync-dirs-config
344 $(MOZ_MAKE)
346 ####################################
347 # Other targets
349 # Pass these target onto the real build system
350 $(OBJDIR_TARGETS):: $(OBJDIR)/Makefile $(OBJDIR)/config.status
351 $(MOZ_MAKE) $@
353 ####################################
354 # Postflight
356 realbuild alldep postflight::
357 ifdef MOZ_POSTFLIGHT
358 set -e; \
359 for mkfile in $(MOZ_POSTFLIGHT); do \
360 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
361 done
362 endif
364 endif # MOZ_CURRENT_PROJECT
366 ####################################
367 # Postflight, after building all projects
369 realbuild alldep postflight_all::
370 ifeq (,$(MOZ_CURRENT_PROJECT)$(if $(MOZ_POSTFLIGHT_ALL),,1))
371 # Don't run postflight_all for individual projects in multi-project builds
372 # (when MOZ_CURRENT_PROJECT is set.)
373 ifndef MOZ_BUILD_PROJECTS
374 # Building a single project, OBJDIR is usable.
375 set -e; \
376 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
377 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) OBJDIR=$(OBJDIR) MOZ_OBJDIR=$(MOZ_OBJDIR); \
378 done
379 else
380 # OBJDIR refers to the project-specific OBJDIR, which is not available at
381 # this point when building multiple projects. Only MOZ_OBJDIR is available.
382 set -e; \
383 for mkfile in $(MOZ_POSTFLIGHT_ALL); do \
384 $(MAKE) -f $(TOPSRCDIR)/$$mkfile postflight_all TOPSRCDIR=$(TOPSRCDIR) MOZ_OBJDIR=$(MOZ_OBJDIR) MOZ_BUILD_PROJECTS="$(MOZ_BUILD_PROJECTS)"; \
385 done
386 endif
387 endif
389 cleansrcdir:
390 @cd $(TOPSRCDIR); \
391 if [ -f Makefile ]; then \
392 $(MAKE) distclean ; \
393 else \
394 echo "Removing object files from srcdir..."; \
395 rm -fr `find . -type d \( -name .deps -print -o -name CVS \
396 -o -exec test ! -d {}/CVS \; \) -prune \
397 -o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
398 build/autoconf/clean-config.sh; \
401 ## Sanity check $X and js/src/$X are in sync
402 .PHONY: check-sync-dirs
403 check-sync-dirs: check-sync-dirs-build check-sync-dirs-config
404 check-sync-dirs-%:
405 @$(PYTHON) $(TOPSRCDIR)/js/src/config/check-sync-dirs.py $(TOPSRCDIR)/js/src/$* $(TOPSRCDIR)/$*
407 echo-variable-%:
408 @echo $($*)
410 # This makefile doesn't support parallel execution. It does pass
411 # MOZ_MAKE_FLAGS to sub-make processes, so they will correctly execute
412 # in parallel.
413 .NOTPARALLEL:
415 .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)