Bug 1471604 [wpt PR 11687] - Update links to feature policy documentation., a=testonly
[gecko.git] / config / rules.mk
blob4d92720bc26f6c9d60ed6adcc0c22b0915b0c5b8
1 # -*- makefile -*-
2 # vim:set ts=8 sw=8 sts=8 noet:
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 # You can obtain one at http://mozilla.org/MPL/2.0/.
9 ifndef topsrcdir
10 $(error topsrcdir was not set))
11 endif
13 # Define an include-at-most-once flag
14 ifdef INCLUDED_RULES_MK
15 $(error Do not include rules.mk twice!)
16 endif
17 INCLUDED_RULES_MK = 1
19 ifndef INCLUDED_CONFIG_MK
20 include $(topsrcdir)/config/config.mk
21 endif
23 ifndef INCLUDED_VERSION_MK
24 include $(MOZILLA_DIR)/config/version.mk
25 endif
27 USE_AUTOTARGETS_MK = 1
28 include $(MOZILLA_DIR)/config/makefiles/makeutils.mk
30 ifdef REBUILD_CHECK
31 REPORT_BUILD = $(info $(shell $(PYTHON) $(MOZILLA_DIR)/config/rebuild_check.py $@ $^))
32 REPORT_BUILD_VERBOSE = $(REPORT_BUILD)
33 else
34 REPORT_BUILD = $(info $(notdir $@))
36 ifdef BUILD_VERBOSE_LOG
37 REPORT_BUILD_VERBOSE = $(REPORT_BUILD)
38 else
39 REPORT_BUILD_VERBOSE = $(call BUILDSTATUS,BUILD_VERBOSE $(relativesrcdir))
40 endif
42 endif
44 EXEC = exec
46 # ELOG prints out failed command when building silently (gmake -s). Pymake
47 # prints out failed commands anyway, so ELOG just makes things worse by
48 # forcing shell invocations.
49 ifneq (,$(findstring -s, $(filter-out --%, $(MAKEFLAGS))))
50 ELOG := $(EXEC) sh $(BUILD_TOOLS)/print-failed-commands.sh
51 else
52 ELOG :=
53 endif # -s
55 _VPATH_SRCS = $(abspath $<)
57 ################################################################################
58 # Testing frameworks support
59 ################################################################################
61 testxpcobjdir = $(DEPTH)/_tests/xpcshell
63 ifdef ENABLE_TESTS
64 ifdef CPP_UNIT_TESTS
65 ifdef COMPILE_ENVIRONMENT
67 # Compile the tests to $(DIST)/bin. Make lots of niceties available by default
68 # through TestHarness.h, by modifying the list of includes and the libs against
69 # which stuff links.
70 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS)
72 ifndef MOZ_PROFILE_GENERATE
73 CPP_UNIT_TESTS_FILES = $(CPP_UNIT_TESTS)
74 CPP_UNIT_TESTS_DEST = $(DIST)/cppunittests
75 CPP_UNIT_TESTS_TARGET = target
76 INSTALL_TARGETS += CPP_UNIT_TESTS
77 endif
79 run-cppunittests::
80 @$(PYTHON) $(MOZILLA_DIR)/testing/runcppunittests.py --xre-path=$(DIST)/bin --symbols-path=$(DIST)/crashreporter-symbols $(CPP_UNIT_TESTS)
82 cppunittests-remote:
83 $(PYTHON) -u $(MOZILLA_DIR)/testing/remotecppunittests.py \
84 --xre-path=$(DEPTH)/dist/bin \
85 --localLib=$(DEPTH)/dist/$(MOZ_APP_NAME) \
86 --deviceIP=${TEST_DEVICE} \
87 $(CPP_UNIT_TESTS) $(EXTRA_TEST_ARGS); \
89 endif # COMPILE_ENVIRONMENT
90 endif # CPP_UNIT_TESTS
91 endif # ENABLE_TESTS
95 # Library rules
97 # If FORCE_STATIC_LIB is set, build a static library.
98 # Otherwise, build a shared library.
101 ifndef LIBRARY
102 ifdef REAL_LIBRARY
103 ifdef NO_EXPAND_LIBS
104 # Only build actual library if it is requested.
105 LIBRARY := $(REAL_LIBRARY)
106 endif
107 endif
108 endif
110 ifndef HOST_LIBRARY
111 ifdef HOST_LIBRARY_NAME
112 HOST_LIBRARY := $(LIB_PREFIX)$(HOST_LIBRARY_NAME).$(LIB_SUFFIX)
113 endif
114 endif
116 ifdef FORCE_SHARED_LIB
117 ifdef MKSHLIB
119 ifdef LIB_IS_C_ONLY
120 MKSHLIB = $(MKCSHLIB)
121 endif
123 EMBED_MANIFEST_AT=2
125 endif # MKSHLIB
126 endif # FORCE_SHARED_LIB
128 ifeq ($(OS_ARCH),WINNT)
129 ifndef GNU_CC
132 # Unless we're building SIMPLE_PROGRAMS, all C++ files share a PDB file per
133 # directory. For parallel builds, this PDB file is shared and locked by
134 # MSPDBSRV.EXE, starting with MSVC8 SP1. If you're using MSVC 7.1 or MSVC8
135 # without SP1, don't do parallel builds.
137 # The final PDB for libraries and programs is created by the linker and uses
138 # a different name from the single PDB file created by the compiler. See
139 # bug 462740.
142 ifdef SIMPLE_PROGRAMS
143 COMPILE_PDB_FLAG ?= -Fd$(basename $(@F)).pdb
144 else
145 COMPILE_PDB_FLAG ?= -Fdgenerated.pdb -FS
146 endif
147 COMPILE_CFLAGS += $(COMPILE_PDB_FLAG)
148 COMPILE_CXXFLAGS += $(COMPILE_PDB_FLAG)
150 LINK_PDBFILE ?= $(basename $(@F)).pdb
151 ifdef MOZ_DEBUG
152 CODFILE=$(basename $(@F)).cod
153 endif
155 endif # !GNU_CC
157 EXTRA_DEPS += $(DEFFILE)
159 endif # WINNT
161 ifeq (arm-Darwin,$(CPU_ARCH)-$(OS_TARGET))
162 ifdef PROGRAM
163 MOZ_PROGRAM_LDFLAGS += -Wl,-rpath -Wl,@executable_path/Frameworks
164 endif
165 endif
167 ifeq ($(HOST_OS_ARCH),WINNT)
168 HOST_PDBFILE=$(basename $(@F)).pdb
169 HOST_PDB_FLAG ?= -Fd$(HOST_PDBFILE)
170 HOST_CFLAGS += $(HOST_PDB_FLAG)
171 HOST_CXXFLAGS += $(HOST_PDB_FLAG)
172 HOST_C_LDFLAGS += $(HOST_PDB_FLAG)
173 HOST_CXX_LDFLAGS += $(HOST_PDB_FLAG)
174 endif
176 # Don't build SIMPLE_PROGRAMS during the MOZ_PROFILE_GENERATE pass, and do not
177 # attempt to install them
178 ifdef MOZ_PROFILE_GENERATE
179 $(foreach category,$(INSTALL_TARGETS),\
180 $(eval $(category)_FILES := $(foreach file,$($(category)_FILES),$(if $(filter $(SIMPLE_PROGRAMS),$(notdir $(file))),,$(file)))))
181 SIMPLE_PROGRAMS :=
182 endif
184 ifdef COMPILE_ENVIRONMENT
185 ifndef TARGETS
186 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_LIBRARY) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY)
187 endif
189 ifdef MOZ_PROFILE_GENERATE
190 CPPSRCS := $(CPPSRCS) $(PGO_GEN_ONLY_CPPSRCS)
191 endif
193 COBJS = $(notdir $(CSRCS:.c=.$(OBJ_SUFFIX)))
194 SOBJS = $(notdir $(SSRCS:.S=.$(OBJ_SUFFIX)))
195 # CPPSRCS can have different extensions (eg: .cpp, .cc)
196 CPPOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(CPPSRCS))))
197 CMOBJS = $(notdir $(CMSRCS:.m=.$(OBJ_SUFFIX)))
198 CMMOBJS = $(notdir $(CMMSRCS:.mm=.$(OBJ_SUFFIX)))
199 # ASFILES can have different extensions (.s, .asm)
200 ASOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(ASFILES))))
201 RS_STATICLIB_CRATE_OBJ = $(addprefix lib,$(notdir $(RS_STATICLIB_CRATE_SRC:.rs=.$(LIB_SUFFIX))))
202 ifndef OBJS
203 _OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS)
204 OBJS = $(strip $(_OBJS))
205 endif
207 HOST_COBJS = $(addprefix host_,$(notdir $(HOST_CSRCS:.c=.$(OBJ_SUFFIX))))
208 # HOST_CPPOBJS can have different extensions (eg: .cpp, .cc)
209 HOST_CPPOBJS = $(addprefix host_,$(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(HOST_CPPSRCS)))))
210 HOST_CMOBJS = $(addprefix host_,$(notdir $(HOST_CMSRCS:.m=.$(OBJ_SUFFIX))))
211 HOST_CMMOBJS = $(addprefix host_,$(notdir $(HOST_CMMSRCS:.mm=.$(OBJ_SUFFIX))))
212 ifndef HOST_OBJS
213 _HOST_OBJS = $(HOST_COBJS) $(HOST_CPPOBJS) $(HOST_CMOBJS) $(HOST_CMMOBJS)
214 HOST_OBJS = $(strip $(_HOST_OBJS))
215 endif
216 else
217 LIBRARY :=
218 SHARED_LIBRARY :=
219 IMPORT_LIBRARY :=
220 REAL_LIBRARY :=
221 PROGRAM :=
222 SIMPLE_PROGRAMS :=
223 HOST_LIBRARY :=
224 HOST_SHARED_LIBRARY :=
225 HOST_PROGRAM :=
226 HOST_SIMPLE_PROGRAMS :=
227 endif
229 ALL_TRASH = \
230 $(GARBAGE) $(TARGETS) $(OBJS) $(PROGOBJS) LOGS TAGS a.out \
231 $(filter-out $(ASFILES),$(OBJS:.$(OBJ_SUFFIX)=.s)) $(OBJS:.$(OBJ_SUFFIX)=.ii) \
232 $(OBJS:.$(OBJ_SUFFIX)=.i) $(OBJS:.$(OBJ_SUFFIX)=.i_o) \
233 $(HOST_PROGOBJS) $(HOST_OBJS) $(IMPORT_LIBRARY) \
234 so_locations _gen _stubs $(wildcard *.res) $(wildcard *.RES) \
235 $(wildcard *.pdb) $(CODFILE) $(IMPORT_LIBRARY) \
236 $(SHARED_LIBRARY:$(DLL_SUFFIX)=.exp) $(wildcard *.ilk) \
237 $(PROGRAM:$(BIN_SUFFIX)=.exp) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.exp) \
238 $(PROGRAM:$(BIN_SUFFIX)=.lib) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.lib) \
239 $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) \
240 $(wildcard gts_tmp_*) $(LIBRARY:%.a=.%.timestamp)
241 ALL_TRASH_DIRS = \
242 $(GARBAGE_DIRS) /no-such-file
244 ifdef QTDIR
245 GARBAGE += $(MOCSRCS)
246 endif
248 ifdef SIMPLE_PROGRAMS
249 GARBAGE += $(SIMPLE_PROGRAMS:%=%.$(OBJ_SUFFIX))
250 endif
252 ifdef HOST_SIMPLE_PROGRAMS
253 GARBAGE += $(HOST_SIMPLE_PROGRAMS:%=%.$(OBJ_SUFFIX))
254 endif
256 ifdef MACH
257 ifndef NO_BUILDSTATUS_MESSAGES
258 define BUILDSTATUS
259 @echo 'BUILDSTATUS $1'
261 endef
262 endif
263 endif
265 define SUBMAKE # $(call SUBMAKE,target,directory,static)
266 +@$(MAKE) $(if $(2),-C $(2)) $(1)
268 endef # The extra line is important here! don't delete it
270 define TIER_DIR_SUBMAKE
271 $(call SUBMAKE,$(4),$(3),$(5))
273 endef # Ths empty line is important.
275 ifneq (,$(strip $(DIRS)))
276 LOOP_OVER_DIRS = \
277 $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
278 endif
281 # Now we can differentiate between objects used to build a library, and
282 # objects used to build an executable in the same directory.
284 ifndef PROGOBJS
285 PROGOBJS = $(OBJS)
286 endif
288 ifndef HOST_PROGOBJS
289 HOST_PROGOBJS = $(HOST_OBJS)
290 endif
292 GARBAGE_DIRS += $(wildcard $(CURDIR)/$(MDDEPDIR))
295 # Tags: emacs (etags), vi (ctags)
296 # TAG_PROGRAM := ctags -L -
298 TAG_PROGRAM = xargs etags -a
301 # Turn on C++ linking if we have any .cpp or .mm files
302 # (moved this from config.mk so that config.mk can be included
303 # before the CPPSRCS are defined)
305 ifneq ($(HOST_CPPSRCS)$(HOST_CMMSRCS),)
306 HOST_CPP_PROG_LINK = 1
307 endif
310 # MacOS X specific stuff
313 ifeq ($(OS_ARCH),Darwin)
314 ifdef SHARED_LIBRARY
315 ifdef MOZ_IOS
316 _LOADER_PATH := @rpath
317 else
318 _LOADER_PATH := @executable_path
319 endif
320 EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$(SHARED_LIBRARY) -compatibility_version 1 -current_version 1 -single_module
321 endif
322 endif
324 ifeq ($(OS_ARCH),NetBSD)
325 ifneq (,$(filter arc cobalt hpcmips mipsco newsmips pmax sgimips,$(OS_TEST)))
326 ifneq (,$(filter layout/%,$(relativesrcdir)))
327 OS_CFLAGS += -Wa,-xgot
328 OS_CXXFLAGS += -Wa,-xgot
329 endif
330 endif
331 endif
333 ifdef SYMBOLS_FILE
334 ifeq ($(OS_TARGET),WINNT)
335 ifndef GNU_CC
336 EXTRA_DSO_LDOPTS += -DEF:$(call normalizepath,$(SYMBOLS_FILE))
337 else
338 EXTRA_DSO_LDOPTS += $(call normalizepath,$(SYMBOLS_FILE))
339 endif
340 else
341 ifdef GCC_USE_GNU_LD
342 EXTRA_DSO_LDOPTS += -Wl,--version-script,$(SYMBOLS_FILE)
343 else
344 ifeq ($(OS_TARGET),Darwin)
345 EXTRA_DSO_LDOPTS += -Wl,-exported_symbols_list,$(SYMBOLS_FILE)
346 endif
347 endif
348 endif
349 EXTRA_DEPS += $(SYMBOLS_FILE)
350 endif
352 # GNU doesn't have path length limitation
355 ifeq ($(OS_ARCH),GNU)
356 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
357 endif
360 # MINGW32
362 ifeq ($(OS_ARCH),WINNT)
363 ifdef GNU_CC
364 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
365 endif
366 endif
368 ifeq ($(USE_TVFS),1)
369 IFLAGS1 = -rb
370 IFLAGS2 = -rb
371 else
372 IFLAGS1 = -m 644
373 IFLAGS2 = -m 755
374 endif
376 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
377 OUTOPTION = -Fo# eol
378 else
379 OUTOPTION = -o # eol
380 endif # WINNT && !GNU_CC
382 ifneq (,$(filter ml%,$(AS)))
383 ASOUTOPTION = -Fo# eol
384 else
385 ASOUTOPTION = -o # eol
386 endif
388 ifeq (,$(CROSS_COMPILE))
389 HOST_OUTOPTION = $(OUTOPTION)
390 else
391 HOST_OUTOPTION = -o # eol
392 endif
393 ################################################################################
395 # Ensure the build config is up to date. This is done automatically when builds
396 # are performed through |mach build|. The check here is to catch people not
397 # using mach. If we ever enforce builds through mach, this code can be removed.
398 ifndef MOZBUILD_BACKEND_CHECKED
399 ifndef MACH
400 ifndef TOPLEVEL_BUILD
401 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
402 $(DEPTH)/backend.%Backend:
403 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
405 define build_backend_rule
406 $(1): $$(shell cat $(1).in)
408 endef
409 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
411 default:: $(BUILD_BACKEND_FILES)
413 export MOZBUILD_BACKEND_CHECKED=1
414 endif
415 endif
416 endif
418 # The root makefile doesn't want to do a plain export/libs, because
419 # of the tiers and because of libxul. Suppress the default rules in favor
420 # of something else. Makefiles which use this var *must* provide a sensible
421 # default rule before including rules.mk
422 default all::
423 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
425 ifeq ($(findstring s,$(filter-out --%, $(MAKEFLAGS))),)
426 ECHO := echo
427 QUIET :=
428 else
429 ECHO := true
430 QUIET := -q
431 endif
433 # Do everything from scratch
434 everything::
435 $(MAKE) clean
436 $(MAKE) all
438 # Dependencies which, if modified, should cause everything to rebuild
439 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
441 ##############################################
442 ifdef COMPILE_ENVIRONMENT
443 OBJ_TARGETS = $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS)
445 compile:: host target
447 host:: $(HOST_LIBRARY) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
449 target:: $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE) $(RUST_PROGRAMS)
451 ifndef LIBRARY
452 ifdef OBJS
453 target:: $(OBJS)
454 endif
455 endif
457 syms::
459 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
460 endif
462 ##############################################
463 ifneq (1,$(NO_PROFILE_GUIDED_OPTIMIZE))
464 ifdef MOZ_PROFILE_USE
465 ifeq ($(OS_ARCH)_$(GNU_CC), WINNT_)
466 # When building with PGO, we have to make sure to re-link
467 # in the MOZ_PROFILE_USE phase if we linked in the
468 # MOZ_PROFILE_GENERATE phase. We'll touch this pgo.relink
469 # file in the link rule in the GENERATE phase to indicate
470 # that we need a relink.
471 ifdef SHARED_LIBRARY
472 $(SHARED_LIBRARY): pgo.relink
473 endif
474 ifdef PROGRAM
475 $(PROGRAM): pgo.relink
476 endif
478 # In the second pass, we need to merge the pgc files into the pgd file.
479 # The compiler would do this for us automatically if they were in the right
480 # place, but they're in dist/bin.
481 ifneq (,$(SHARED_LIBRARY)$(PROGRAM))
482 export::
483 ifdef PROGRAM
484 $(PYTHON) $(MOZILLA_DIR)/build/win32/pgomerge.py \
485 $(PROGRAM:$(BIN_SUFFIX)=) $(DIST)/bin
486 endif
487 ifdef SHARED_LIBRARY
488 $(PYTHON) $(MOZILLA_DIR)/build/win32/pgomerge.py \
489 $(patsubst $(DLL_PREFIX)%$(DLL_SUFFIX),%,$(SHARED_LIBRARY)) $(DIST)/bin
490 endif
491 endif # SHARED_LIBRARY || PROGRAM
492 endif # WINNT_
493 endif # MOZ_PROFILE_USE
494 ifdef MOZ_PROFILE_GENERATE
495 # Clean up profiling data during PROFILE_GENERATE phase
496 export::
497 ifeq ($(OS_ARCH)_$(GNU_CC), WINNT_)
498 $(foreach pgd,$(wildcard *.pgd),pgomgr -clear $(pgd);)
499 else
500 ifdef GNU_CC
501 -$(RM) *.gcda
502 endif
503 endif
504 endif
506 ifneq (,$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
507 ifneq (,$(filter target,$(MAKECMDGOALS)))
508 ifdef GNU_CC
509 # Force rebuilding libraries and programs in both passes because each
510 # pass uses different object files.
511 $(PROGRAM) $(SHARED_LIBRARY) $(LIBRARY): FORCE
512 endif
513 endif
514 endif
516 endif # NO_PROFILE_GUIDED_OPTIMIZE
518 ##############################################
520 clean clobber realclean clobber_all::
521 -$(RM) $(ALL_TRASH)
522 -$(RM) -r $(ALL_TRASH_DIRS)
524 clean clobber realclean clobber_all distclean::
525 $(foreach dir,$(DIRS),-$(call SUBMAKE,$@,$(dir)))
527 distclean::
528 -$(RM) -r $(ALL_TRASH_DIRS)
529 -$(RM) $(ALL_TRASH) \
530 Makefile .HSancillary \
531 $(wildcard *.$(OBJ_SUFFIX)) $(wildcard *.ho) $(wildcard host_*.o*) \
532 $(wildcard *.$(LIB_SUFFIX)) $(wildcard *$(DLL_SUFFIX)) \
533 $(wildcard *.$(IMPORT_LIB_SUFFIX))
535 alltags:
536 $(RM) TAGS
537 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
539 define EXPAND_CC_OR_CXX
540 $(if $(PROG_IS_C_ONLY_$(1)),$(CC),$(CCC))
541 endef
544 # PROGRAM = Foo
545 # creates OBJS, links with LIBS to create Foo
547 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(RESFILE) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
548 $(REPORT_BUILD)
549 @$(RM) $@.manifest
550 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
551 $(LINKER) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) -IMPLIB:$(basename $(@F)).lib $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $($(notdir $@)_$(OBJS_VAR_SUFFIX)) $(RESFILE) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
552 ifdef MSMANIFEST_TOOL
553 @if test -f $@.manifest; then \
554 if test -f '$(srcdir)/$(notdir $@).manifest'; then \
555 echo 'Embedding manifest from $(srcdir)/$(notdir $@).manifest and $@.manifest'; \
556 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$(notdir $@).manifest' $@.manifest -OUTPUTRESOURCE:$@\;1; \
557 else \
558 echo 'Embedding manifest from $@.manifest'; \
559 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
560 fi; \
561 elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
562 echo 'Embedding manifest from $(srcdir)/$(notdir $@).manifest'; \
563 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
565 endif # MSVC with manifest tool
566 ifdef MOZ_PROFILE_GENERATE
567 # touch it a few seconds into the future to work around FAT's
568 # 2-second granularity
569 touch -t `date +%Y%m%d%H%M.%S -d 'now+5seconds'` pgo.relink
570 endif
571 else # !WINNT || GNU_CC
572 $(call EXPAND_CC_OR_CXX,$@) -o $@ $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) $($(notdir $@)_$(OBJS_VAR_SUFFIX)) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
573 $(call py_action,check_binary,--target $@)
574 endif # WINNT && !GNU_CC
576 ifdef ENABLE_STRIP
577 $(STRIP) $(STRIP_FLAGS) $@
578 endif
579 ifdef MOZ_POST_PROGRAM_COMMAND
580 $(MOZ_POST_PROGRAM_COMMAND) $@
581 endif
583 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
584 $(REPORT_BUILD)
585 ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
586 $(LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $(HOST_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
587 ifdef MSMANIFEST_TOOL
588 @if test -f $@.manifest; then \
589 if test -f '$(srcdir)/$(notdir $@).manifest'; then \
590 echo 'Embedding manifest from $(srcdir)/$(notdir $@).manifest and $@.manifest'; \
591 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$(notdir $@).manifest' $@.manifest -OUTPUTRESOURCE:$@\;1; \
592 else \
593 echo 'Embedding manifest from $@.manifest'; \
594 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
595 fi; \
596 elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
597 echo 'Embedding manifest from $(srcdir)/$(notdir $@).manifest'; \
598 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
600 endif # MSVC with manifest tool
601 else
602 ifeq ($(HOST_CPP_PROG_LINK),1)
603 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
604 else
605 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
606 endif # HOST_CPP_PROG_LINK
607 endif
608 ifndef CROSS_COMPILE
609 $(call py_action,check_binary,--host $@)
610 endif
613 # This is an attempt to support generation of multiple binaries
614 # in one directory, it assumes everything to compile Foo is in
615 # Foo.o (from either Foo.c or Foo.cpp).
617 # SIMPLE_PROGRAMS = Foo Bar
618 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
620 $(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
621 $(REPORT_BUILD)
622 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
623 $(LINKER) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $($@_$(OBJS_VAR_SUFFIX)) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
624 ifdef MSMANIFEST_TOOL
625 @if test -f $@.manifest; then \
626 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
627 rm -f $@.manifest; \
629 endif # MSVC with manifest tool
630 else
631 $(call EXPAND_CC_OR_CXX,$@) $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) -o $@ $($@_$(OBJS_VAR_SUFFIX)) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
632 $(call py_action,check_binary,--target $@)
633 endif # WINNT && !GNU_CC
635 ifdef ENABLE_STRIP
636 $(STRIP) $(STRIP_FLAGS) $@
637 endif
638 ifdef MOZ_POST_PROGRAM_COMMAND
639 $(MOZ_POST_PROGRAM_COMMAND) $@
640 endif
642 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): host_%.$(OBJ_SUFFIX) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
643 $(REPORT_BUILD)
644 ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
645 $(LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
646 else
647 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
648 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $< $(HOST_LIBS) $(HOST_EXTRA_LIBS)
649 else
650 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $< $(HOST_LIBS) $(HOST_EXTRA_LIBS)
651 endif
652 endif
653 ifndef CROSS_COMPILE
654 $(call py_action,check_binary,--host $@)
655 endif
657 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
658 $(REPORT_BUILD)
659 $(RM) $(REAL_LIBRARY)
660 $(AR) $(AR_FLAGS) $(OBJS) $($@_$(OBJS_VAR_SUFFIX))
662 ifeq ($(OS_ARCH),WINNT)
663 # Import libraries are created by the rules creating shared libraries.
664 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
665 # but make will happily consider the import library before it is refreshed
666 # when rebuilding the corresponding shared library. Defining an empty recipe
667 # for import libraries forces make to wait for the shared library recipe to
668 # have run before considering other targets that depend on the import library.
669 # See bug 795204.
670 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
671 endif
673 $(HOST_LIBRARY): $(HOST_OBJS) Makefile
674 $(REPORT_BUILD)
675 $(RM) $@
676 $(HOST_AR) $(HOST_AR_FLAGS) $(HOST_OBJS)
678 $(HOST_SHARED_LIBRARY): $(HOST_OBJS) Makefile
679 $(REPORT_BUILD)
680 $(RM) $@
681 ifdef _MSC_VER
682 # /!\ We assume host and target are using the same compiler
683 $(LINKER) -NOLOGO -DLL -OUT:$@ $(HOST_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
684 else
685 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
686 endif
688 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
689 # so instead of deleting .o files after repacking them into a dylib, we make
690 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
691 # so no need to conditionalize on OS version or debugging format.
693 $(SHARED_LIBRARY): $(OBJS) $(RESFILE) $(RUST_STATIC_LIB_FOR_SHARED_LIB) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
694 $(REPORT_BUILD)
695 ifndef INCREMENTAL_LINKER
696 $(RM) $@
697 endif
698 $(MKSHLIB) $($@_$(OBJS_VAR_SUFFIX)) $(RESFILE) $(LDFLAGS) $(STATIC_LIBS) $(RUST_STATIC_LIB_FOR_SHARED_LIB) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
699 $(call py_action,check_binary,--target $@)
701 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
702 ifdef MSMANIFEST_TOOL
703 ifdef EMBED_MANIFEST_AT
704 @if test -f $@.manifest; then \
705 if test -f '$(srcdir)/$@.manifest'; then \
706 echo 'Embedding manifest from $(srcdir)/$@.manifest and $@.manifest'; \
707 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$@.manifest' $@.manifest -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
708 else \
709 echo 'Embedding manifest from $@.manifest'; \
710 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
711 fi; \
712 elif test -f '$(srcdir)/$@.manifest'; then \
713 echo 'Embedding manifest from $(srcdir)/$@.manifest'; \
714 $(MT) -NOLOGO -MANIFEST '$(win_srcdir)/$@.manifest' -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
716 endif # EMBED_MANIFEST_AT
717 endif # MSVC with manifest tool
718 ifdef MOZ_PROFILE_GENERATE
719 touch -t `date +%Y%m%d%H%M.%S -d 'now+5seconds'` pgo.relink
720 endif
721 endif # WINNT && !GCC
722 chmod +x $@
723 ifdef ENABLE_STRIP
724 $(STRIP) $(STRIP_FLAGS) $@
725 endif
727 # The object file is in the current directory, and the source file can be any
728 # relative path. This macro adds the dependency obj: src for each source file.
729 # This dependency must be first for the $< flag to work correctly, and the
730 # rules that have commands for these targets must not list any other
731 # prerequisites, or they will override the $< variable.
732 define src_objdep
733 $(basename $2$(notdir $1)).$(OBJ_SUFFIX): $1 $$(call mkdir_deps,$$(MDDEPDIR))
734 endef
735 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f))))
736 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS) $(HOST_CMSRCS) $(HOST_CMMSRCS),$(eval $(call src_objdep,$(f),host_)))
738 # The Rust compiler only outputs library objects, and so we need different
739 # mangling to generate dependency rules for it.
740 mk_libname = $(basename lib$(notdir $1)).rlib
741 src_libdep = $(call mk_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
742 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
743 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
744 $(foreach f,$(RSSRCS),$(eval $(call src_libdep,$(f))))
745 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
747 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
749 # Rules for building native targets must come first because of the host_ prefix
750 $(HOST_COBJS):
751 $(REPORT_BUILD_VERBOSE)
752 $(ELOG) $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $(_VPATH_SRCS)
754 $(HOST_CPPOBJS):
755 $(REPORT_BUILD_VERBOSE)
756 $(call BUILDSTATUS,OBJECT_FILE $@)
757 $(ELOG) $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $(_VPATH_SRCS)
759 $(HOST_CMOBJS):
760 $(REPORT_BUILD_VERBOSE)
761 $(ELOG) $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(HOST_CMFLAGS) $(NSPR_CFLAGS) $(_VPATH_SRCS)
763 $(HOST_CMMOBJS):
764 $(REPORT_BUILD_VERBOSE)
765 $(ELOG) $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(HOST_CMMFLAGS) $(NSPR_CFLAGS) $(_VPATH_SRCS)
767 $(COBJS):
768 $(REPORT_BUILD_VERBOSE)
769 $(ELOG) $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
771 # DEFINES and ACDEFINES are needed here to enable conditional compilation of Q_OBJECTs:
772 # 'moc' only knows about #defines it gets on the command line (-D...), not in
773 # included headers like mozilla-config.h
774 $(filter moc_%.cpp,$(CPPSRCS)): moc_%.cpp: %.h
775 $(REPORT_BUILD_VERBOSE)
776 $(ELOG) $(MOC) $(DEFINES) $(ACDEFINES) $< $(OUTOPTION)$@
778 $(filter moc_%.cc,$(CPPSRCS)): moc_%.cc: %.cc
779 $(REPORT_BUILD_VERBOSE)
780 $(ELOG) $(MOC) $(DEFINES) $(ACDEFINES) $(_VPATH_SRCS:.cc=.h) $(OUTOPTION)$@
782 $(filter qrc_%.cpp,$(CPPSRCS)): qrc_%.cpp: %.qrc
783 $(REPORT_BUILD_VERBOSE)
784 $(ELOG) $(RCC) -name $* $< $(OUTOPTION)$@
786 ifdef ASFILES
787 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
788 # a '-c' flag.
789 $(ASOBJS):
790 $(REPORT_BUILD_VERBOSE)
791 $(AS) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $(_VPATH_SRCS)
792 endif
794 define syms_template
795 syms:: $(2)
796 $(2): $(1)
797 ifdef MOZ_CRASHREPORTER
798 $$(call py_action,dumpsymbols,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
799 endif
800 endef
802 ifndef MOZ_PROFILE_GENERATE
803 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
804 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
805 endif
806 endif
808 ifdef MOZ_AUTOMATION
809 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
810 DUMP_SYMS_TARGETS :=
811 endif
812 endif
814 ifdef MOZ_CRASHREPORTER
815 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
816 else ifneq (,$(and $(LLVM_SYMBOLIZER),$(filter WINNT,$(OS_ARCH)),$(MOZ_AUTOMATION)))
817 PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
818 PDB_DEST ?= $(FINAL_TARGET)
819 PDB_TARGET = syms
820 INSTALL_TARGETS += PDB
821 endif
823 cargo_host_flag := --target=$(RUST_HOST_TARGET)
824 cargo_target_flag := --target=$(RUST_TARGET)
826 # Permit users to pass flags to cargo from their mozconfigs (e.g. --color=always).
827 cargo_build_flags = $(CARGOFLAGS)
828 ifndef MOZ_DEBUG_RUST
829 cargo_build_flags += --release
830 endif
831 cargo_build_flags += --frozen
833 cargo_build_flags += --manifest-path $(CARGO_FILE)
834 ifdef BUILD_VERBOSE_LOG
835 cargo_build_flags += -vv
836 else
837 ifdef MOZ_AUTOMATION
838 cargo_build_flags += -vv
839 endif # MOZ_AUTOMATION
840 endif # BUILD_VERBOSE_LOG
842 # Enable color output if original stdout was a TTY and color settings
843 # aren't already present. This essentially restores the default behavior
844 # of cargo when running via `mach`.
845 ifdef MACH_STDOUT_ISATTY
846 ifeq (,$(findstring --color,$(cargo_build_flags)))
847 cargo_build_flags += --color=always
848 endif
849 endif
851 # These flags are passed via `cargo rustc` and only apply to the final rustc
852 # invocation (i.e., only the top-level crate, not its dependencies).
853 cargo_rustc_flags = $(CARGO_RUSTCFLAGS)
854 ifndef DEVELOPER_OPTIONS
855 ifndef MOZ_DEBUG_RUST
856 # Enable link-time optimization for release builds.
857 cargo_rustc_flags += -C lto
858 endif
859 endif
861 ifdef CARGO_INCREMENTAL
862 cargo_incremental := CARGO_INCREMENTAL=$(CARGO_INCREMENTAL)
863 endif
865 rustflags_neon =
866 ifeq (neon,$(MOZ_FPU))
867 rustflags_neon += -C target_feature=+neon
868 endif
870 rustflags_override = RUSTFLAGS='$(MOZ_RUST_DEFAULT_FLAGS) $(RUSTFLAGS) $(rustflags_neon)'
872 ifdef MOZ_MSVCBITS
873 # If we are building a MozillaBuild shell, we want to clear out the
874 # vcvars.bat environment variables for cargo builds. This is because
875 # a 32-bit MozillaBuild shell on a 64-bit machine will try to use
876 # the 32-bit compiler/linker for everything, while cargo/rustc wants
877 # to use the 64-bit linker for build.rs scripts. This conflict results
878 # in a build failure (see bug 1350001). So we clear out the environment
879 # variables that are actually relevant to 32- vs 64-bit builds.
880 environment_cleaner = -u VCINSTALLDIR PATH='' LIB='' LIBPATH=''
881 # The servo build needs to know where python is, and we're removing the PATH
882 # so we tell it explicitly via the PYTHON env var.
883 environment_cleaner += PYTHON='$(shell which $(PYTHON))'
884 else
885 environment_cleaner =
886 endif
888 rust_unlock_unstable =
889 ifdef MOZ_RUST_SIMD
890 rust_unlock_unstable += RUSTC_BOOTSTRAP=1
891 endif
893 ifdef MOZ_USING_SCCACHE
894 sccache_wrap := RUSTC_WRAPPER='$(CCACHE)'
895 endif
897 # We use the + prefix to pass down the jobserver fds to cargo, but we
898 # don't use the prefix when make -n is used, so that cargo doesn't run
899 # in that case)
900 define RUN_CARGO
901 $(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)env $(environment_cleaner) $(rust_unlock_unstable) $(rustflags_override) $(sccache_wrap) \
902 CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
903 RUSTC=$(RUSTC) \
904 RUSTDOC=$(RUSTDOC) \
905 RUSTFMT=$(RUSTFMT) \
906 MOZ_SRC=$(topsrcdir) \
907 MOZ_DIST=$(ABS_DIST) \
908 LIBCLANG_PATH="$(MOZ_LIBCLANG_PATH)" \
909 CLANG_PATH="$(MOZ_CLANG_PATH)" \
910 PKG_CONFIG_ALLOW_CROSS=1 \
911 RUST_BACKTRACE=full \
912 MOZ_TOPOBJDIR=$(topobjdir) \
913 $(cargo_incremental) \
914 $(2) \
915 $(CARGO) $(1) $(cargo_build_flags)
916 endef
918 # This function is intended to be called by:
920 # $(call CARGO_BUILD,EXTRA_ENV_VAR1=X EXTRA_ENV_VAR2=Y ...)
922 # but, given the idiosyncracies of make, can also be called without arguments:
924 # $(call CARGO_BUILD)
925 define CARGO_BUILD
926 $(call RUN_CARGO,rustc,$(1))
927 endef
929 define CARGO_CHECK
930 $(call RUN_CARGO,check,$(1))
931 endef
933 cargo_linker_env_var := CARGO_TARGET_$(RUST_TARGET_ENV_NAME)_LINKER
935 # Don't define a custom linker on Windows, as it's difficult to have a
936 # non-binary file that will get executed correctly by Cargo. We don't
937 # have to worry about a cross-compiling (besides x86-64 -> x86, which
938 # already works with the current setup) setup on Windows, and we don't
939 # have to pass in any special linker options on Windows.
940 ifneq (WINNT,$(OS_ARCH))
942 # Defining all of this for ASan/TSan builds results in crashes while running
943 # some crates's build scripts (!), so disable it for now.
944 ifndef MOZ_ASAN
945 ifndef MOZ_TSAN
946 # Cargo needs the same linker flags as the C/C++ compiler,
947 # but not the final libraries. Filter those out because they
948 # cause problems on macOS 10.7; see bug 1365993 for details.
949 # Also, we don't want to pass PGO flags until cargo supports them.
950 target_cargo_env_vars := \
951 MOZ_CARGO_WRAP_LDFLAGS="$(filter-out -framework Cocoa -lobjc AudioToolbox ExceptionHandling -fprofile-%,$(LDFLAGS))" \
952 MOZ_CARGO_WRAP_LD="$(CC)" \
953 $(cargo_linker_env_var)=$(topsrcdir)/build/cargo-linker
954 endif # MOZ_TSAN
955 endif # MOZ_ASAN
957 endif # ifneq WINNT
959 ifdef RUST_LIBRARY_FILE
961 ifdef RUST_LIBRARY_FEATURES
962 rust_features_flag := --features "$(RUST_LIBRARY_FEATURES)"
963 endif
965 # Assume any system libraries rustc links against are already in the target's LIBS.
967 # We need to run cargo unconditionally, because cargo is the only thing that
968 # has full visibility into how changes in Rust sources might affect the final
969 # build.
970 force-cargo-library-build:
971 $(REPORT_BUILD)
972 $(call CARGO_BUILD,$(target_cargo_env_vars)) --lib $(cargo_target_flag) $(rust_features_flag) -- $(cargo_rustc_flags)
974 $(RUST_LIBRARY_FILE): force-cargo-library-build
976 force-cargo-library-check:
977 $(call CARGO_CHECK,$(target_cargo_env_vars)) --lib $(cargo_target_flag) $(rust_features_flag)
978 else
979 force-cargo-library-check:
980 @true
981 endif # RUST_LIBRARY_FILE
983 ifdef RUST_TESTS
985 rust_test_options := $(foreach test,$(RUST_TESTS),-p $(test))
987 ifdef RUST_TEST_FEATURES
988 rust_features_flag := --features "$(RUST_TEST_FEATURES)"
989 endif
991 # Don't stop at the first failure. We want to list all failures together.
992 rust_test_flag := --no-fail-fast
994 force-cargo-test-run:
995 $(call RUN_CARGO,test $(cargo_target_flag) $(rust_test_flag) $(rust_test_options) $(rust_features_flag),$(target_cargo_env_vars))
997 check:: force-cargo-test-run
998 endif
1000 ifdef HOST_RUST_LIBRARY_FILE
1002 ifdef HOST_RUST_LIBRARY_FEATURES
1003 host_rust_features_flag := --features "$(HOST_RUST_LIBRARY_FEATURES)"
1004 endif
1006 force-cargo-host-library-build:
1007 $(REPORT_BUILD)
1008 $(call CARGO_BUILD) --lib $(cargo_host_flag) $(host_rust_features_flag)
1010 $(HOST_RUST_LIBRARY_FILE): force-cargo-host-library-build
1012 force-cargo-host-library-check:
1013 $(call CARGO_CHECK) --lib $(cargo_host_flag) $(host_rust_features_flag)
1014 else
1015 force-cargo-host-library-check:
1016 @true
1017 endif # HOST_RUST_LIBRARY_FILE
1019 ifdef RUST_PROGRAMS
1020 force-cargo-program-build:
1021 $(REPORT_BUILD)
1022 $(call CARGO_BUILD,$(target_cargo_env_vars)) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag)
1024 $(RUST_PROGRAMS): force-cargo-program-build
1026 force-cargo-program-check:
1027 $(call CARGO_CHECK,$(target_cargo_env_vars)) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag)
1028 else
1029 force-cargo-program-check:
1030 @true
1031 endif # RUST_PROGRAMS
1032 ifdef HOST_RUST_PROGRAMS
1033 force-cargo-host-program-build:
1034 $(REPORT_BUILD)
1035 $(call CARGO_BUILD) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag)
1037 $(HOST_RUST_PROGRAMS): force-cargo-host-program-build
1039 force-cargo-host-program-check:
1040 $(REPORT_BUILD)
1041 $(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag)
1042 else
1043 force-cargo-host-program-check:
1044 @true
1045 endif # HOST_RUST_PROGRAMS
1047 $(SOBJS):
1048 $(REPORT_BUILD)
1049 $(AS) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $<
1051 $(CPPOBJS):
1052 $(REPORT_BUILD_VERBOSE)
1053 $(call BUILDSTATUS,OBJECT_FILE $@)
1054 $(ELOG) $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1056 $(CMMOBJS):
1057 $(REPORT_BUILD_VERBOSE)
1058 $(ELOG) $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1060 $(CMOBJS):
1061 $(REPORT_BUILD_VERBOSE)
1062 $(ELOG) $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1064 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
1065 $(REPORT_BUILD_VERBOSE)
1066 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1068 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
1069 $(REPORT_BUILD_VERBOSE)
1070 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1072 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
1073 $(REPORT_BUILD_VERBOSE)
1074 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1076 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
1077 $(REPORT_BUILD_VERBOSE)
1078 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $(_VPATH_SRCS)
1080 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
1081 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
1082 # of the full sources, as well as the $(notdir) version. So:
1083 # foo.cpp sub/bar.cpp
1084 # becomes:
1085 # foo.cpp sub/bar.cpp bar.cpp
1087 # This way we can match both 'make sub/bar.i' and 'make bar.i'
1088 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
1090 define PREPROCESS_RULES
1091 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
1092 # Make preprocessed files PHONY so they are always executed, since they are
1093 # manual targets and we don't necessarily write to $@.
1094 .PHONY: $$(_PREPROCESSED_$1_FILES)
1096 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
1097 # reach $(srcdir)/frontend/Parser.i
1098 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
1099 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
1101 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
1102 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
1103 $$(REPORT_BUILD_VERBOSE)
1104 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
1105 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$(_VPATH_SRCS)
1107 endef
1109 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
1110 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
1111 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
1112 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
1113 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
1115 # Default to pre-processing the actual unified file. This can be overridden
1116 # at the command-line to pre-process only the individual source file.
1117 PP_UNIFIED ?= 1
1119 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
1120 # infinite loop if the filename doesn't exist in the unified source files.
1121 ifndef PP_REINVOKE
1123 MATCH_cpp = \(cpp\|cc|cxx\)
1124 UPPER_c = C
1125 UPPER_cpp = CPP
1126 UPPER_mm = CMM
1128 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
1129 # find a matching pathname.
1130 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
1131 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
1132 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
1133 all_c_sources := $(call _get_all_sources,$(CSRCS))
1134 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
1136 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
1137 # one of the *SRCS variables. The two code paths depend on whether or not
1138 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
1140 # PP_UNIFIED=1:
1141 # - Look for it in any of the Unified files, and re-exec make with
1142 # Unified_foo0.i as the target. This gets us the full unified preprocessed
1143 # file.
1145 # PP_UNIFIED=0:
1146 # - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
1147 # make with that filename as the target. The *SRCS variables are modified
1148 # to have the Unified sources appended to them so that the static pattern
1149 # rules will match.
1150 %.i: FORCE
1151 ifeq ($(PP_UNIFIED),1)
1152 @$(MAKE) PP_REINVOKE=1 \
1153 $(or $(addsuffix .i, \
1154 $(foreach type,c cpp mm, \
1155 $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
1156 $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
1157 ))),$(error "File not found for preprocessing: $@"))
1158 else
1159 @$(MAKE) PP_REINVOKE=1 $@ \
1160 $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
1161 endif
1163 endif
1165 endif
1167 $(RESFILE): %.res: %.rc
1168 $(REPORT_BUILD)
1169 @echo Creating Resource file: $@
1170 ifdef GNU_CC
1171 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) $(OUTOPTION)$@ $(_VPATH_SRCS)
1172 else
1173 $(RC) $(RCFLAGS) -r $(DEFINES) $(INCLUDES) $(OUTOPTION)$@ $(_VPATH_SRCS)
1174 endif
1176 # Cancel GNU make built-in implicit rules
1177 MAKEFLAGS += -r
1179 ifneq (,$(filter WINNT,$(OS_ARCH)))
1180 SEP := ;
1181 else
1182 SEP := :
1183 endif
1185 EMPTY :=
1186 SPACE := $(EMPTY) $(EMPTY)
1188 # MSYS has its own special path form, but javac expects the source and class
1189 # paths to be in the DOS form (i.e. e:/builds/...). This function does the
1190 # appropriate conversion on Windows, but is a noop on other systems.
1191 ifeq ($(HOST_OS_ARCH),WINNT)
1192 # We use 'pwd -W' to get DOS form of the path. However, since the given path
1193 # could be a file or a non-existent path, we cannot call 'pwd -W' directly
1194 # on the path. Instead, we extract the root path (i.e. "c:/"), call 'pwd -W'
1195 # on it, then merge with the rest of the path.
1196 root-path = $(shell echo $(1) | sed -e 's|\(/[^/]*\)/\?\(.*\)|\1|')
1197 non-root-path = $(shell echo $(1) | sed -e 's|\(/[^/]*\)/\?\(.*\)|\2|')
1198 normalizepath = $(foreach p,$(1),$(if $(filter /%,$(1)),$(patsubst %/,%,$(shell cd $(call root-path,$(1)) && pwd -W))/$(call non-root-path,$(1)),$(1)))
1199 else
1200 normalizepath = $(1)
1201 endif
1203 ###############################################################################
1204 # Bunch of things that extend the 'export' rule (in order):
1205 ###############################################################################
1207 ifneq ($(XPI_NAME),)
1208 $(FINAL_TARGET):
1209 $(NSINSTALL) -D $@
1211 export:: $(FINAL_TARGET)
1212 endif
1214 ################################################################################
1215 # The default location for prefs is the gre prefs directory.
1216 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
1217 PREF_DIR = defaults/pref
1219 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
1220 # different and that we are building app related resources. Hence,
1221 # PREF_DIR should point to the app prefs location.
1222 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
1223 PREF_DIR = defaults/preferences
1224 endif
1226 ################################################################################
1227 # CHROME PACKAGING
1229 chrome::
1230 $(MAKE) realchrome
1231 $(LOOP_OVER_DIRS)
1233 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
1235 ifneq (,$(JAR_MANIFEST))
1236 ifndef NO_DIST_INSTALL
1238 ifdef XPI_NAME
1239 ifdef XPI_ROOT_APPID
1240 # For add-on packaging we may specify that an application
1241 # sub-dir should be added to the root chrome manifest with
1242 # a specific application id.
1243 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
1244 endif
1246 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
1247 # no way langpacks will get packaged right, so error out.
1248 ifneq (,$(DIST_SUBDIR))
1249 ifndef XPI_ROOT_APPID
1250 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
1251 endif
1252 endif
1253 endif
1255 libs realchrome:: $(FINAL_TARGET)/chrome
1256 $(call py_action,jar_maker,\
1257 $(QUIET) -d $(FINAL_TARGET) \
1258 $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
1259 $(JAR_MANIFEST))
1261 endif
1263 endif
1265 # When you move this out of the tools tier, please remove the corresponding
1266 # hacks in recursivemake.py that check if Makefile.in sets the variable.
1267 ifneq ($(XPI_PKGNAME),)
1268 tools realchrome::
1269 ifdef STRIP_XPI
1270 ifndef MOZ_DEBUG
1271 @echo 'Stripping $(XPI_PKGNAME) package directory...'
1272 @echo $(FINAL_TARGET)
1273 @cd $(FINAL_TARGET) && find . ! -type d \
1274 ! -name '*.js' \
1275 ! -name '*.xpt' \
1276 ! -name '*.gif' \
1277 ! -name '*.jpg' \
1278 ! -name '*.png' \
1279 ! -name '*.xpm' \
1280 ! -name '*.txt' \
1281 ! -name '*.rdf' \
1282 ! -name '*.sh' \
1283 ! -name '*.properties' \
1284 ! -name '*.dtd' \
1285 ! -name '*.html' \
1286 ! -name '*.xul' \
1287 ! -name '*.css' \
1288 ! -name '*.xml' \
1289 ! -name '*.jar' \
1290 ! -name '*.dat' \
1291 ! -name '*.tbl' \
1292 ! -name '*.src' \
1293 ! -name '*.reg' \
1294 $(PLATFORM_EXCLUDE_LIST) \
1295 -exec $(STRIP) $(STRIP_FLAGS) {} >/dev/null 2>&1 \;
1296 endif
1297 endif
1298 @echo 'Packaging $(XPI_PKGNAME).xpi...'
1299 $(call py_action,zip,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
1300 endif
1302 # See comment above about moving this out of the tools tier.
1303 ifdef INSTALL_EXTENSION_ID
1304 ifndef XPI_NAME
1305 $(error XPI_NAME must be set for INSTALL_EXTENSION_ID)
1306 endif
1308 tools::
1309 $(RM) -r '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
1310 $(NSINSTALL) -D '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
1311 $(call copy_dir,$(FINAL_TARGET),$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID))
1313 endif
1315 #############################################################################
1316 # MDDEPDIR is the subdirectory where all the dependency files are placed.
1317 # This uses a make rule (instead of a macro) to support parallel
1318 # builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
1319 # processes could simultaneously try to create the same directory.
1321 # We use $(CURDIR) in the rule's target to ensure that we don't find
1322 # a dependency directory in the source tree via VPATH (perhaps from
1323 # a previous build in the source tree) and thus neglect to create a
1324 # dependency directory in the object directory, where we really need
1325 # it.
1327 ifneq (,$(filter-out all chrome default export realchrome clean clobber clobber_all distclean realclean,$(MAKECMDGOALS)))
1328 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS)))))))
1330 ifneq (,$(MDDEPEND_FILES))
1331 -include $(MDDEPEND_FILES)
1332 endif
1334 endif
1336 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(EXTRA_MDDEPEND_FILES))))
1338 ifneq (,$(MDDEPEND_FILES))
1339 -include $(MDDEPEND_FILES)
1340 endif
1342 ################################################################################
1343 # Install/copy rules
1345 # The INSTALL_TARGETS variable contains a list of all install target
1346 # categories. Each category defines a list of files and executables, and an
1347 # install destination,
1349 # FOO_FILES := foo bar
1350 # FOO_EXECUTABLES := baz
1351 # FOO_DEST := target_path
1352 # INSTALL_TARGETS += FOO
1354 # Additionally, a FOO_TARGET variable may be added to indicate the target for
1355 # which the files and executables are installed. Default is "libs".
1357 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
1358 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
1359 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
1360 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
1362 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
1363 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
1364 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
1365 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
1367 define install_cmd_override
1368 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
1369 endef
1370 endif
1371 endif
1373 install_target_tier = $(or $($(1)_TARGET),libs)
1374 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
1376 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
1377 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
1378 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
1380 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
1381 # See details in bug 934864.
1382 define create_dependency
1383 $(1): $(2)
1384 $(1): $(2)
1385 endef
1387 define install_target_template
1388 $(call install_cmd_override,$(2))
1389 $(call create_dependency,$(2),$(1))
1390 endef
1392 $(foreach category,$(INSTALL_TARGETS),\
1393 $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
1394 $(foreach tier,$(call install_target_tier,$(category)),\
1395 $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
1396 $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
1398 $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
1399 $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
1403 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
1404 $(eval $(tier):: $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
1407 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
1409 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
1410 $(install_targets_sanity)
1411 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
1413 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
1414 $(install_targets_sanity)
1415 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
1417 ################################################################################
1418 # Preprocessing rules
1420 # The PP_TARGETS variable contains a list of all preprocessing target
1421 # categories. Each category has associated variables listing input files, the
1422 # output directory, extra preprocessor flags, and so on. For example:
1424 # FOO := input-file
1425 # FOO_PATH := target-directory
1426 # FOO_FLAGS := -Dsome_flag
1427 # PP_TARGETS += FOO
1429 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
1430 # following make variables to see what to do:
1432 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
1433 # We search VPATH for the names given here. If an input file name ends in
1434 # '.in', that suffix is omitted from the output file name.
1436 # - <C>_PATH names the directory in which to place the preprocessed output
1437 # files. We create this directory if it does not already exist. Setting
1438 # this variable is optional; if unset, we install the files in $(CURDIR).
1440 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
1441 # to the usual bunch. Setting this variable is optional.
1443 # - <C>_TARGET names the 'make' target that should depend on creating the output
1444 # files. Setting this variable is optional; if unset, we preprocess the
1445 # files for the 'libs' target.
1447 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
1448 # kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
1449 # $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
1450 # instead of $(DIST)/include/qux.h.
1452 pp_target_tier = $(or $($(1)_TARGET),libs)
1453 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
1455 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
1456 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
1458 $(foreach category,$(PP_TARGETS), \
1459 $(foreach tier,$(call pp_target_tier,$(category)), \
1460 $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
1462 $(foreach file,$($(category)), \
1463 $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
1464 $(file) $(GLOBAL_DEPS))) \
1466 $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
1469 $(foreach tier,$(PP_TARGETS_TIERS), \
1470 $(eval $(tier):: $(PP_TARGETS_RESULTS_$(tier))) \
1473 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
1474 $(PP_TARGETS_ALL_RESULTS):
1475 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
1476 $(RM) '$@'
1477 $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
1479 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
1481 # The depfile is based on the filename, and we don't want conflicts. So check
1482 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
1483 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
1484 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
1485 $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
1486 $(error Multiple preprocessing rules are creating a $(file) file) \
1490 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
1491 # If the depfile for a preprocessed file doesn't exist, add a dep to force
1492 # re-preprocessing.
1493 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
1494 $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
1496 $(eval $(file): FORCE) \
1500 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
1502 ifneq (,$(MDDEPEND_FILES))
1503 -include $(MDDEPEND_FILES)
1504 endif
1506 endif
1508 # Pull in non-recursive targets if this is a partial tree build.
1509 ifndef TOPLEVEL_BUILD
1510 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
1511 endif
1513 ################################################################################
1514 # Special gmake rules.
1515 ################################################################################
1519 # Re-define the list of default suffixes, so gmake won't have to churn through
1520 # hundreds of built-in suffix rules for stuff we don't need.
1522 .SUFFIXES:
1525 # Fake targets. Always run these rules, even if a file/directory with that
1526 # name already exists.
1528 .PHONY: all alltags boot chrome realchrome clean clobber clobber_all export install libs makefiles realclean run_apprunner tools $(DIRS) FORCE
1530 # Used as a dependency to force targets to rebuild
1531 FORCE:
1533 # Delete target if error occurs when building target
1534 .DELETE_ON_ERROR:
1536 tags: TAGS
1538 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1539 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1540 $(LOOP_OVER_DIRS)
1542 ifndef INCLUDED_DEBUGMAKE_MK #{
1543 ## Only parse when an echo* or show* target is requested
1544 ifneq (,$(call isTargetStem,echo,show))
1545 include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
1546 endif #}
1547 endif #}
1549 documentation:
1550 @cd $(DEPTH)
1551 $(DOXYGEN) $(DEPTH)/config/doxygen.cfg
1553 FREEZE_VARIABLES = \
1554 CSRCS \
1555 CPPSRCS \
1556 EXPORTS \
1557 DIRS \
1558 LIBRARY \
1559 MODULE \
1560 $(NULL)
1562 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
1564 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
1565 $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
1567 libs export::
1568 $(CHECK_FROZEN_VARIABLES)
1570 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
1572 #############################################################################
1573 # Derived targets and dependencies
1575 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
1576 ifneq ($(NULL),$(AUTO_DEPS))
1577 default all libs tools export:: $(AUTO_DEPS)
1578 endif