Bug 1728524 [wpt PR 30282] - Add CONNECT response WPTs for WebTransport, a=testonly
[gecko.git] / config / rules.mk
blobd842689b7628f2a47db6f3759fccf0503d38d4ff
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 USE_AUTOTARGETS_MK = 1
24 include $(MOZILLA_DIR)/config/makefiles/makeutils.mk
26 ifdef REBUILD_CHECK
27 REPORT_BUILD = $(info $(shell $(PYTHON3) $(MOZILLA_DIR)/config/rebuild_check.py $@ $^))
28 REPORT_BUILD_VERBOSE = $(REPORT_BUILD)
29 else
30 REPORT_BUILD = $(info $(relativesrcdir)/$(notdir $@))
32 ifdef BUILD_VERBOSE_LOG
33 REPORT_BUILD_VERBOSE = $(REPORT_BUILD)
34 else
35 REPORT_BUILD_VERBOSE = $(call BUILDSTATUS,BUILD_VERBOSE $(relativesrcdir))
36 endif
38 endif
40 EXEC = exec
42 ################################################################################
43 # Testing frameworks support
44 ################################################################################
46 testxpcobjdir = $(DEPTH)/_tests/xpcshell
48 ifdef ENABLE_TESTS
49 ifdef CPP_UNIT_TESTS
50 ifdef COMPILE_ENVIRONMENT
52 # Compile the tests to $(DIST)/bin. Make lots of niceties available by default
53 # through TestHarness.h, by modifying the list of includes and the libs against
54 # which stuff links.
55 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS)
57 ifndef MOZ_PROFILE_GENERATE
58 CPP_UNIT_TESTS_FILES = $(CPP_UNIT_TESTS)
59 CPP_UNIT_TESTS_DEST = $(DIST)/cppunittests
60 CPP_UNIT_TESTS_TARGET = target
61 INSTALL_TARGETS += CPP_UNIT_TESTS
62 endif
64 run-cppunittests::
65 @$(PYTHON3) $(MOZILLA_DIR)/testing/runcppunittests.py --xre-path=$(DIST)/bin --symbols-path=$(DIST)/crashreporter-symbols $(CPP_UNIT_TESTS)
67 cppunittests-remote:
68 $(PYTHON3) -u $(MOZILLA_DIR)/testing/remotecppunittests.py \
69 --xre-path=$(DEPTH)/dist/bin \
70 --localLib=$(DEPTH)/dist/$(MOZ_APP_NAME) \
71 --deviceIP=${TEST_DEVICE} \
72 $(CPP_UNIT_TESTS) $(EXTRA_TEST_ARGS); \
74 endif # COMPILE_ENVIRONMENT
75 endif # CPP_UNIT_TESTS
76 endif # ENABLE_TESTS
80 # Library rules
82 # If FORCE_STATIC_LIB is set, build a static library.
83 # Otherwise, build a shared library.
86 ifndef LIBRARY
87 ifdef REAL_LIBRARY
88 ifdef NO_EXPAND_LIBS
89 # Only build actual library if it is requested.
90 LIBRARY := $(REAL_LIBRARY)
91 endif
92 endif
93 endif
95 ifdef FORCE_SHARED_LIB
96 ifdef MKSHLIB
98 ifdef LIB_IS_C_ONLY
99 MKSHLIB = $(MKCSHLIB)
100 endif
102 endif # MKSHLIB
103 endif # FORCE_SHARED_LIB
105 ifeq ($(OS_ARCH),WINNT)
108 # This next line captures both the default (non-MOZ_COPY_PDBS)
109 # case as well as the MOZ_COPY_PDBS-for-mingwclang case.
111 # For the default case, placing the pdb in the build
112 # directory is needed.
114 # For the MOZ_COPY_PDBS, non-mingwclang case - we need to
115 # build the pdb next to the executable (handled in the if
116 # statement immediately below.)
118 # For the MOZ_COPY_PDBS, mingwclang case - we also need to
119 # build the pdb next to the executable, but this macro doesn't
120 # work for jsapi-tests which is a little special, so we specify
121 # the output directory below with MOZ_PROGRAM_LDFLAGS.
123 LINK_PDBFILE ?= $(basename $(@F)).pdb
125 ifdef MOZ_COPY_PDBS
126 ifneq ($(CC_TYPE),clang)
127 LINK_PDBFILE = $(basename $@).pdb
128 endif
129 endif
131 ifndef GNU_CC
133 ifdef SIMPLE_PROGRAMS
134 COMPILE_PDB_FLAG ?= -Fd$(basename $(@F)).pdb
135 COMPILE_CFLAGS += $(COMPILE_PDB_FLAG)
136 COMPILE_CXXFLAGS += $(COMPILE_PDB_FLAG)
137 endif
139 ifdef MOZ_DEBUG
140 CODFILE=$(basename $(@F)).cod
141 endif
143 endif # !GNU_CC
144 endif # WINNT
146 ifeq (arm-Darwin,$(CPU_ARCH)-$(OS_TARGET))
147 ifdef PROGRAM
148 MOZ_PROGRAM_LDFLAGS += -Wl,-rpath -Wl,@executable_path/Frameworks
149 endif
150 endif
152 ifeq ($(OS_ARCH),WINNT)
153 ifeq ($(CC_TYPE),clang)
154 MOZ_PROGRAM_LDFLAGS += -Wl,-pdb,$(dir $@)/$(LINK_PDBFILE)
155 endif
156 endif
158 ifeq ($(HOST_OS_ARCH),WINNT)
159 HOST_PDBFILE=$(basename $(@F)).pdb
160 HOST_PDB_FLAG ?= -PDB:$(HOST_PDBFILE)
161 HOST_C_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
162 HOST_CXX_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
163 endif
165 # Don't build SIMPLE_PROGRAMS during the MOZ_PROFILE_GENERATE pass, and do not
166 # attempt to install them
167 ifdef MOZ_PROFILE_GENERATE
168 $(foreach category,$(INSTALL_TARGETS),\
169 $(eval $(category)_FILES := $(foreach file,$($(category)_FILES),$(if $(filter $(SIMPLE_PROGRAMS),$(notdir $(file))),,$(file)))))
170 SIMPLE_PROGRAMS :=
171 endif
173 ifdef COMPILE_ENVIRONMENT
174 ifndef TARGETS
175 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY) $(WASM_LIBRARY)
176 endif
178 COBJS = $(notdir $(CSRCS:.c=.$(OBJ_SUFFIX)))
179 CWASMOBJS = $(notdir $(WASM_CSRCS:.c=.$(WASM_OBJ_SUFFIX)))
180 SOBJS = $(notdir $(SSRCS:.S=.$(OBJ_SUFFIX)))
181 # CPPSRCS can have different extensions (eg: .cpp, .cc)
182 CPPOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(CPPSRCS))))
183 CPPWASMOBJS = $(notdir $(addsuffix .$(WASM_OBJ_SUFFIX),$(basename $(WASM_CPPSRCS))))
184 CMOBJS = $(notdir $(CMSRCS:.m=.$(OBJ_SUFFIX)))
185 CMMOBJS = $(notdir $(CMMSRCS:.mm=.$(OBJ_SUFFIX)))
186 # ASFILES can have different extensions (.s, .asm)
187 ASOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(ASFILES))))
188 RS_STATICLIB_CRATE_OBJ = $(addprefix lib,$(notdir $(RS_STATICLIB_CRATE_SRC:.rs=.$(LIB_SUFFIX))))
189 ifndef OBJS
190 _OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS) $(CWASMOBJS) $(CPPWASMOBJS)
191 OBJS = $(strip $(_OBJS))
192 endif
194 HOST_COBJS = $(addprefix host_,$(notdir $(HOST_CSRCS:.c=.$(OBJ_SUFFIX))))
195 # HOST_CPPOBJS can have different extensions (eg: .cpp, .cc)
196 HOST_CPPOBJS = $(addprefix host_,$(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(HOST_CPPSRCS)))))
197 HOST_CMOBJS = $(addprefix host_,$(notdir $(HOST_CMSRCS:.m=.$(OBJ_SUFFIX))))
198 HOST_CMMOBJS = $(addprefix host_,$(notdir $(HOST_CMMSRCS:.mm=.$(OBJ_SUFFIX))))
199 ifndef HOST_OBJS
200 _HOST_OBJS = $(HOST_COBJS) $(HOST_CPPOBJS) $(HOST_CMOBJS) $(HOST_CMMOBJS)
201 HOST_OBJS = $(strip $(_HOST_OBJS))
202 endif
203 else
204 LIBRARY :=
205 SHARED_LIBRARY :=
206 IMPORT_LIBRARY :=
207 REAL_LIBRARY :=
208 PROGRAM :=
209 SIMPLE_PROGRAMS :=
210 HOST_SHARED_LIBRARY :=
211 HOST_PROGRAM :=
212 HOST_SIMPLE_PROGRAMS :=
213 WASM_LIBRARY :=
214 endif
216 WASM_ARCHIVE = $(addsuffix .$(WASM_OBJ_SUFFIX),$(WASM_LIBRARY))
217 ifneq (,$(WASM_ARCHIVE))
218 CSRCS += $(addsuffix .c,$(WASM_ARCHIVE))
219 endif
221 ifdef MACH
222 ifndef NO_BUILDSTATUS_MESSAGES
223 define BUILDSTATUS
224 @echo 'BUILDSTATUS $1'
226 endef
227 endif
228 endif
230 define SUBMAKE # $(call SUBMAKE,target,directory,static)
231 +@$(MAKE) $(if $(2),-C $(2)) $(1)
233 endef # The extra line is important here! don't delete it
235 define TIER_DIR_SUBMAKE
236 $(call SUBMAKE,$(4),$(3),$(5))
238 endef # Ths empty line is important.
240 ifneq (,$(strip $(DIRS)))
241 LOOP_OVER_DIRS = \
242 $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
243 endif
246 # Now we can differentiate between objects used to build a library, and
247 # objects used to build an executable in the same directory.
249 ifndef PROGOBJS
250 PROGOBJS = $(OBJS)
251 endif
253 ifndef HOST_PROGOBJS
254 HOST_PROGOBJS = $(HOST_OBJS)
255 endif
258 # Tags: emacs (etags), vi (ctags)
259 # TAG_PROGRAM := ctags -L -
261 TAG_PROGRAM = xargs etags -a
264 # Turn on C++ linking if we have any .cpp or .mm files
265 # (moved this from config.mk so that config.mk can be included
266 # before the CPPSRCS are defined)
268 ifneq ($(HOST_CPPSRCS)$(HOST_CMMSRCS),)
269 HOST_CPP_PROG_LINK = 1
270 endif
273 # MacOS X specific stuff
276 ifeq ($(OS_ARCH),Darwin)
277 ifneq (,$(SHARED_LIBRARY)$(WASM_LIBRARY))
278 _LOADER_PATH := @executable_path
279 EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$@ -compatibility_version 1 -current_version 1 -single_module
280 endif
281 endif
284 # GNU doesn't have path length limitation
287 ifeq ($(OS_ARCH),GNU)
288 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
289 endif
292 # MINGW32
294 ifeq ($(OS_ARCH),WINNT)
295 ifdef GNU_CC
296 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
297 endif
298 endif
300 ifeq ($(USE_TVFS),1)
301 IFLAGS1 = -rb
302 IFLAGS2 = -rb
303 else
304 IFLAGS1 = -m 644
305 IFLAGS2 = -m 755
306 endif
308 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
309 OUTOPTION = -Fo# eol
310 else
311 OUTOPTION = -o # eol
312 endif # WINNT && !GNU_CC
314 ifeq (,$(CROSS_COMPILE))
315 HOST_OUTOPTION = $(OUTOPTION)
316 else
317 # Windows-to-Windows cross compiles should always use MSVC-style options for
318 # host compiles.
319 ifeq (WINNT_WINNT,$(HOST_OS_ARCH)_$(OS_ARCH))
320 ifneq (,$(filter-out clang-cl,$(HOST_CC_TYPE)))
321 $(error MSVC-style compilers should be used for host compilations!)
322 endif
323 HOST_OUTOPTION = -Fo# eol
324 else
325 HOST_OUTOPTION = -o # eol
326 endif
327 endif
328 ################################################################################
330 # Ensure the build config is up to date. This is done automatically when builds
331 # are performed through |mach build|. The check here is to catch people not
332 # using mach. If we ever enforce builds through mach, this code can be removed.
333 ifndef MOZBUILD_BACKEND_CHECKED
334 ifndef MACH
335 ifndef TOPLEVEL_BUILD
336 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
337 $(DEPTH)/backend.%Backend:
338 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
340 define build_backend_rule
341 $(1): $$(shell cat $(1).in)
343 endef
344 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
346 default:: $(BUILD_BACKEND_FILES)
348 export MOZBUILD_BACKEND_CHECKED=1
349 endif
350 endif
351 endif
353 # The root makefile doesn't want to do a plain export/libs, because
354 # of the tiers and because of libxul. Suppress the default rules in favor
355 # of something else. Makefiles which use this var *must* provide a sensible
356 # default rule before including rules.mk
357 default all::
358 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
360 ifdef BUILD_VERBOSE_LOG
361 ECHO := echo
362 QUIET :=
363 else
364 ECHO := true
365 QUIET := -q
366 endif
368 # Dependencies which, if modified, should cause everything to rebuild
369 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
371 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
372 # We always build .res files for programs and shared libraries
373 resfile = $(notdir $1).res
374 # We also build .res files for simple programs if a corresponding manifest
375 # exists. We'll generate a .rc file that includes the manifest.
376 ifdef GNU_CC
377 # Skip on mingw builds because of bug 1657863
378 resfile_for_manifest =
379 else
380 resfile_for_manifest = $(if $(wildcard $(srcdir)/$(notdir $1).manifest),$(call resfile,$1))
381 endif
382 else
383 resfile =
384 resfile_for_manifest =
385 endif
387 ##############################################
388 ifdef COMPILE_ENVIRONMENT
389 compile:: host target
391 host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
393 target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE) $(RUST_PROGRAMS) $(WASM_LIBRARY))
395 ifndef LIBRARY
396 ifdef OBJS
397 target:: $(OBJS)
398 endif
399 endif
401 target-objects: $(OBJS) $(PROGOBJS)
402 host-objects: $(HOST_OBJS) $(HOST_PROGOBJS)
404 syms::
406 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
407 endif
409 alltags:
410 $(RM) TAGS
411 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
413 define EXPAND_CC_OR_CXX
414 $(if $(PROG_IS_C_ONLY_$(1)),$(CC),$(CCC))
415 endef
418 # PROGRAM = Foo
419 # creates OBJS, links with LIBS to create Foo
421 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile,$(PROGRAM)) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
422 $(REPORT_BUILD)
423 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
424 $(LINKER) -OUT:$@ -PDB:$(LINK_PDBFILE) -IMPLIB:$(basename $(@F)).lib $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $($(notdir $@)_OBJS) $(filter %.res,$^) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
425 else # !WINNT || GNU_CC
426 $(call EXPAND_CC_OR_CXX,$@) -o $@ $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) $($(notdir $@)_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
427 $(call py_action,check_binary,--target $@)
428 endif # WINNT && !GNU_CC
430 ifdef ENABLE_STRIP
431 $(STRIP) $(STRIP_FLAGS) $@
432 endif
433 ifdef MOZ_POST_PROGRAM_COMMAND
434 $(MOZ_POST_PROGRAM_COMMAND) $@
435 endif
437 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
438 $(REPORT_BUILD)
439 ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
440 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
441 else
442 ifeq ($(HOST_CPP_PROG_LINK),1)
443 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
444 else
445 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
446 endif # HOST_CPP_PROG_LINK
447 endif
448 ifndef CROSS_COMPILE
449 $(call py_action,check_binary,--host $@)
450 endif
453 # This is an attempt to support generation of multiple binaries
454 # in one directory, it assumes everything to compile Foo is in
455 # Foo.o (from either Foo.c or Foo.cpp).
457 # SIMPLE_PROGRAMS = Foo Bar
458 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
460 define simple_program_deps
461 $1: $(1:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile_for_manifest,$1) $(GLOBAL_DEPS)
462 endef
463 $(foreach p,$(SIMPLE_PROGRAMS),$(eval $(call simple_program_deps,$(p))))
465 $(SIMPLE_PROGRAMS):
466 $(REPORT_BUILD)
467 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
468 $(LINKER) -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
469 else
470 $(call EXPAND_CC_OR_CXX,$@) $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) -o $@ $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
471 $(call py_action,check_binary,--target $@)
472 endif # WINNT && !GNU_CC
474 ifdef ENABLE_STRIP
475 $(STRIP) $(STRIP_FLAGS) $@
476 endif
477 ifdef MOZ_POST_PROGRAM_COMMAND
478 $(MOZ_POST_PROGRAM_COMMAND) $@
479 endif
481 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
482 $(REPORT_BUILD)
483 ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
484 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
485 else
486 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
487 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
488 else
489 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
490 endif
491 endif
492 ifndef CROSS_COMPILE
493 $(call py_action,check_binary,--host $@)
494 endif
496 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
497 $(REPORT_BUILD)
498 $(RM) $(REAL_LIBRARY)
499 $(AR) $(AR_FLAGS) $($@_OBJS)
501 $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
502 $(REPORT_BUILD_VERBOSE)
503 $(RM) $(WASM_ARCHIVE)
504 $(WASM_CXX) -o $@ -Wl,--export-all -Wl,--stack-first -Wl,-z,stack-size=$(if $(MOZ_OPTIMIZE),262144,1048576) -Wl,--no-entry -Wl,--growable-table $(CWASMOBJS) $(CPPWASMOBJS)
506 $(addsuffix .c,$(WASM_ARCHIVE)): $(WASM_ARCHIVE)
507 $(DIST)/host/bin/wasm2c -o $@ $<
509 $(WASM_LIBRARY): DSO_SONAME=$@
510 $(WASM_LIBRARY): IMPORT_LIBRARY=$(WASM_LIBRARY:$(DLL_PREFIX)%$(DLL_SUFFIX)=$(IMPORT_LIB_PREFIX)%$(IMPORT_LIB_SUFFIX))
511 $(WASM_LIBRARY): $(filter %.$(OBJ_SUFFIX),$(OBJS))
512 $(REPORT_BUILD)
513 $(RM) $(WASM_LIBRARY)
514 $(MKCSHLIB) $(filter %.$(OBJ_SUFFIX),$(OBJS)) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
515 $(call py_action,check_binary,--target $@)
517 ifeq ($(OS_ARCH),WINNT)
518 # Import libraries are created by the rules creating shared libraries.
519 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
520 # but make will happily consider the import library before it is refreshed
521 # when rebuilding the corresponding shared library. Defining an empty recipe
522 # for import libraries forces make to wait for the shared library recipe to
523 # have run before considering other targets that depend on the import library.
524 # See bug 795204.
525 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
526 endif
528 $(HOST_SHARED_LIBRARY): Makefile
529 $(REPORT_BUILD)
530 $(RM) $@
531 ifneq (,$(filter clang-cl,$(HOST_CC_TYPE)))
532 $(HOST_LINKER) -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
533 else
534 $(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
535 endif
537 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
538 # so instead of deleting .o files after repacking them into a dylib, we make
539 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
540 # so no need to conditionalize on OS version or debugging format.
542 $(SHARED_LIBRARY): $(OBJS) $(call resfile,$(SHARED_LIBRARY)) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
543 $(REPORT_BUILD)
544 ifndef INCREMENTAL_LINKER
545 $(RM) $@
546 endif
547 $(MKSHLIB) $($@_OBJS) $(filter %.res,$^) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
548 $(call py_action,check_binary,--target $@)
550 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
551 endif # WINNT && !GCC
552 chmod +x $@
553 ifdef ENABLE_STRIP
554 $(STRIP) $(STRIP_FLAGS) $@
555 endif
557 # The object file is in the current directory, and the source file can be any
558 # relative path. This macro adds the dependency obj: src for each source file.
559 # This dependency must be first for the $< flag to work correctly, and the
560 # rules that have commands for these targets must not list any other
561 # prerequisites, or they will override the $< variable.
562 define src_objdep
563 $(basename $3$(notdir $1)).$2: $1 $$(call mkdir_deps,$$(MDDEPDIR))
564 endef
565 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX))))
566 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS) $(HOST_CMSRCS) $(HOST_CMMSRCS),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX),host_)))
567 $(foreach f,$(WASM_CSRCS) $(WASM_CPPSRCS),$(eval $(call src_objdep,$(f),wasm)))
569 # The Rust compiler only outputs library objects, and so we need different
570 # mangling to generate dependency rules for it.
571 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
572 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
573 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
575 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
577 # Rules for building native targets must come first because of the host_ prefix
578 $(HOST_COBJS):
579 $(REPORT_BUILD_VERBOSE)
580 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $<
582 $(HOST_CPPOBJS):
583 $(REPORT_BUILD_VERBOSE)
584 $(call BUILDSTATUS,OBJECT_FILE $@)
585 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $<
587 $(HOST_CMOBJS):
588 $(REPORT_BUILD_VERBOSE)
589 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(HOST_CMFLAGS) $(NSPR_CFLAGS) $<
591 $(HOST_CMMOBJS):
592 $(REPORT_BUILD_VERBOSE)
593 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(HOST_CMMFLAGS) $(NSPR_CFLAGS) $<
595 $(COBJS):
596 $(REPORT_BUILD_VERBOSE)
597 $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
599 $(CWASMOBJS):
600 $(REPORT_BUILD_VERBOSE)
601 $(WASM_CC) -o $@ -c $(WASM_CFLAGS) $($(notdir $<)_FLAGS) $<
603 WINEWRAP = $(if $(and $(filter %.exe,$1),$(WINE)),$(WINE) $1,$1)
605 # Windows program run via Wine don't like Unix absolute paths (they look
606 # like command line arguments). So when needed, create relative paths
607 # from absolute paths. We start with $(DEPTH), which gets us to topobjdir,
608 # then add "/.." for each component of topobjdir, which gets us to /.
609 # then we can add the absolute path after that and we have a relative path,
610 # albeit longer than it could be.
611 ifdef WINE
612 relativize = $(if $(filter /%,$1),$(DEPTH)$(subst $(space),,$(foreach d,$(subst /, ,$(topobjdir)),/..))$1,$1)
613 else
614 relativize = $1
615 endif
617 ifdef ASFILES
618 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
619 # a '-c' flag.
620 $(ASOBJS):
621 $(REPORT_BUILD_VERBOSE)
622 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $(call relativize,$<)
623 endif
625 define syms_template
626 syms:: $(2)
627 $(2): $(1)
628 ifdef MOZ_CRASHREPORTER
629 $$(call py_action,dumpsymbols,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
630 ifeq ($(OS_ARCH),WINNT)
631 ifdef WINCHECKSEC
632 $$(PYTHON3) $$(topsrcdir)/build/win32/autowinchecksec.py $$<
633 endif # WINCHECKSEC
634 endif # WINNT
635 endif
636 endef
638 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
639 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(WASM_LIBRARY)
640 endif
642 ifdef MOZ_AUTOMATION
643 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
644 DUMP_SYMS_TARGETS :=
645 endif
646 endif
648 ifdef MOZ_COPY_PDBS
649 MAIN_PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
650 MAIN_PDB_DEST ?= $(FINAL_TARGET)
651 MAIN_PDB_TARGET = syms
652 INSTALL_TARGETS += MAIN_PDB
654 ifdef CPP_UNIT_TESTS
655 CPP_UNIT_TESTS_PDB_FILES = $(addsuffix .pdb,$(basename $(CPP_UNIT_TESTS)))
656 CPP_UNIT_TESTS_PDB_DEST = $(DIST)/cppunittests
657 CPP_UNIT_TESTS_PDB_TARGET = syms
658 INSTALL_TARGETS += CPP_UNIT_TESTS_PDB
659 endif
661 else ifdef MOZ_CRASHREPORTER
662 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
663 endif
665 ifneq (,$(RUST_TESTS)$(RUST_LIBRARY_FILE)$(HOST_RUST_LIBRARY_FILE)$(RUST_PROGRAMS)$(HOST_RUST_PROGRAMS))
666 include $(MOZILLA_DIR)/config/makefiles/rust.mk
667 endif
669 $(SOBJS):
670 $(REPORT_BUILD)
671 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $(call relativize,$<)
673 $(CPPOBJS):
674 $(REPORT_BUILD_VERBOSE)
675 $(call BUILDSTATUS,OBJECT_FILE $@)
676 $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
678 $(CPPWASMOBJS):
679 $(REPORT_BUILD_VERBOSE)
680 $(call BUILDSTATUS,OBJECT_FILE $@)
681 $(WASM_CXX) -o $@ -c $(WASM_CXXFLAGS) $($(notdir $<)_FLAGS) $<
683 $(CMMOBJS):
684 $(REPORT_BUILD_VERBOSE)
685 $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $<
687 $(CMOBJS):
688 $(REPORT_BUILD_VERBOSE)
689 $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $<
691 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
692 $(REPORT_BUILD_VERBOSE)
693 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
695 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
696 $(REPORT_BUILD_VERBOSE)
697 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
699 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
700 $(REPORT_BUILD_VERBOSE)
701 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
703 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
704 $(REPORT_BUILD_VERBOSE)
705 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
707 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
708 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
709 # of the full sources, as well as the $(notdir) version. So:
710 # foo.cpp sub/bar.cpp
711 # becomes:
712 # foo.cpp sub/bar.cpp bar.cpp
714 # This way we can match both 'make sub/bar.i' and 'make bar.i'
715 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
717 define PREPROCESS_RULES
718 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
719 # Make preprocessed files PHONY so they are always executed, since they are
720 # manual targets and we don't necessarily write to $@.
721 .PHONY: $$(_PREPROCESSED_$1_FILES)
723 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
724 # reach $(srcdir)/frontend/Parser.i
725 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
726 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
728 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
729 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
730 $$(REPORT_BUILD_VERBOSE)
731 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
732 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$<
734 endef
736 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
737 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
738 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
739 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
740 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
742 # Default to pre-processing the actual unified file. This can be overridden
743 # at the command-line to pre-process only the individual source file.
744 PP_UNIFIED ?= 1
746 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
747 # infinite loop if the filename doesn't exist in the unified source files.
748 ifndef PP_REINVOKE
750 MATCH_cpp = \(cpp\|cc|cxx\)
751 UPPER_c = C
752 UPPER_cpp = CPP
753 UPPER_mm = CMM
755 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
756 # find a matching pathname.
757 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
758 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
759 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
760 all_c_sources := $(call _get_all_sources,$(CSRCS))
761 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
763 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
764 # one of the *SRCS variables. The two code paths depend on whether or not
765 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
767 # PP_UNIFIED=1:
768 # - Look for it in any of the Unified files, and re-exec make with
769 # Unified_foo0.i as the target. This gets us the full unified preprocessed
770 # file.
772 # PP_UNIFIED=0:
773 # - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
774 # make with that filename as the target. The *SRCS variables are modified
775 # to have the Unified sources appended to them so that the static pattern
776 # rules will match.
777 %.i: FORCE
778 ifeq ($(PP_UNIFIED),1)
779 @$(MAKE) PP_REINVOKE=1 \
780 $(or $(addsuffix .i, \
781 $(foreach type,c cpp mm, \
782 $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
783 $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
784 ))),$(error "File not found for preprocessing: $@"))
785 else
786 @$(MAKE) PP_REINVOKE=1 $@ \
787 $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
788 endif
790 endif
792 endif
794 # EXTRA_DEPS contains manifests (manually added in Makefile.in ; bug 1498414)
795 %.res: $(or $(RCFILE),%.rc) $(MOZILLA_DIR)/config/create_res.py $(EXTRA_DEPS)
796 $(REPORT_BUILD)
797 $(PYTHON3) $(MOZILLA_DIR)/config/create_res.py $(DEFINES) $(INCLUDES) -o $@ $<
799 $(notdir $(addsuffix .rc,$(PROGRAM) $(SHARED_LIBRARY) $(SIMPLE_PROGRAMS) module)): %.rc: $(RCINCLUDE) $(MOZILLA_DIR)/config/create_rc.py
800 $(PYTHON3) $(MOZILLA_DIR)/config/create_rc.py '$(if $(filter module,$*),,$*)' '$(RCINCLUDE)'
802 # Cancel GNU make built-in implicit rules
803 MAKEFLAGS += -r
805 ifneq (,$(filter WINNT,$(OS_ARCH)))
806 SEP := ;
807 else
808 SEP := :
809 endif
811 EMPTY :=
812 SPACE := $(EMPTY) $(EMPTY)
814 ###############################################################################
815 # Bunch of things that extend the 'export' rule (in order):
816 ###############################################################################
818 ifneq ($(XPI_NAME),)
819 $(FINAL_TARGET):
820 $(NSINSTALL) -D $@
822 export:: $(FINAL_TARGET)
823 endif
825 ################################################################################
826 # The default location for prefs is the gre prefs directory.
827 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
828 PREF_DIR = defaults/pref
830 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
831 # different and that we are building app related resources. Hence,
832 # PREF_DIR should point to the app prefs location.
833 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
834 PREF_DIR = defaults/preferences
835 endif
837 ################################################################################
838 # CHROME PACKAGING
840 chrome::
841 $(MAKE) realchrome
842 $(LOOP_OVER_DIRS)
844 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
846 ifneq (,$(JAR_MANIFEST))
847 ifndef NO_DIST_INSTALL
849 ifdef XPI_NAME
850 ifdef XPI_ROOT_APPID
851 # For add-on packaging we may specify that an application
852 # sub-dir should be added to the root chrome manifest with
853 # a specific application id.
854 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
855 endif
857 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
858 # no way langpacks will get packaged right, so error out.
859 ifneq (,$(DIST_SUBDIR))
860 ifndef XPI_ROOT_APPID
861 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
862 endif
863 endif
864 endif
866 misc realchrome:: $(FINAL_TARGET)/chrome
867 $(call py_action,jar_maker,\
868 $(QUIET) -d $(FINAL_TARGET) \
869 $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
870 $(JAR_MANIFEST))
872 ifdef AB_CD
873 .PHONY: l10n
874 l10n: misc ;
875 endif
876 endif
878 endif
880 # When you move this out of the tools tier, please remove the corresponding
881 # hacks in recursivemake.py that check if Makefile.in sets the variable.
882 ifneq ($(XPI_PKGNAME),)
883 tools realchrome::
884 @echo 'Packaging $(XPI_PKGNAME).xpi...'
885 $(call py_action,zip,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
886 endif
888 # See comment above about moving this out of the tools tier.
889 ifdef INSTALL_EXTENSION_ID
890 ifndef XPI_NAME
891 $(error XPI_NAME must be set for INSTALL_EXTENSION_ID)
892 endif
894 tools::
895 $(RM) -r '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
896 $(NSINSTALL) -D '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
897 $(call copy_dir,$(FINAL_TARGET),$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID))
899 endif
901 #############################################################################
902 # MDDEPDIR is the subdirectory where all the dependency files are placed.
903 # This uses a make rule (instead of a macro) to support parallel
904 # builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
905 # processes could simultaneously try to create the same directory.
907 # We use $(CURDIR) in the rule's target to ensure that we don't find
908 # a dependency directory in the source tree via VPATH (perhaps from
909 # a previous build in the source tree) and thus neglect to create a
910 # dependency directory in the object directory, where we really need
911 # it.
913 _MDDEPEND_FILES :=
915 ifneq (,$(filter target-objects target all default,$(MAKECMDGOALS)))
916 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS))))
917 endif
919 ifneq (,$(filter host-objects host all default,$(MAKECMDGOALS)))
920 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(HOST_OBJS) $(HOST_PROGOBJS))))
921 endif
923 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(_MDDEPEND_FILES))))
924 MDDEPEND_FILES += $(EXTRA_MDDEPEND_FILES)
926 ifneq (,$(MDDEPEND_FILES))
927 -include $(MDDEPEND_FILES)
928 endif
930 ################################################################################
931 # Install/copy rules
933 # The INSTALL_TARGETS variable contains a list of all install target
934 # categories. Each category defines a list of files and executables, and an
935 # install destination,
937 # FOO_FILES := foo bar
938 # FOO_EXECUTABLES := baz
939 # FOO_DEST := target_path
940 # INSTALL_TARGETS += FOO
942 # Additionally, a FOO_TARGET variable may be added to indicate the target for
943 # which the files and executables are installed. Default is "libs".
945 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
946 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
947 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
948 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
950 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
951 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
952 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
953 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
955 define install_cmd_override
956 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
957 endef
958 endif
959 endif
961 install_target_tier = $(or $($(1)_TARGET),libs)
962 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
964 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
965 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
966 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
968 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
969 # See details in bug 934864.
970 define create_dependency
971 $(1): $(2)
972 $(1): $(2)
973 endef
975 define install_target_template
976 $(call install_cmd_override,$(2))
977 $(call create_dependency,$(2),$(1))
978 endef
980 $(foreach category,$(INSTALL_TARGETS),\
981 $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
982 $(foreach tier,$(call install_target_tier,$(category)),\
983 $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
984 $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
986 $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
987 $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
991 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
992 $(eval $(tier):: $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
995 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
997 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
998 $(install_targets_sanity)
999 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
1001 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
1002 $(install_targets_sanity)
1003 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
1005 ################################################################################
1006 # Preprocessing rules
1008 # The PP_TARGETS variable contains a list of all preprocessing target
1009 # categories. Each category has associated variables listing input files, the
1010 # output directory, extra preprocessor flags, and so on. For example:
1012 # FOO := input-file
1013 # FOO_PATH := target-directory
1014 # FOO_FLAGS := -Dsome_flag
1015 # PP_TARGETS += FOO
1017 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
1018 # following make variables to see what to do:
1020 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
1021 # We search VPATH for the names given here. If an input file name ends in
1022 # '.in', that suffix is omitted from the output file name.
1024 # - <C>_PATH names the directory in which to place the preprocessed output
1025 # files. We create this directory if it does not already exist. Setting
1026 # this variable is optional; if unset, we install the files in $(CURDIR).
1028 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
1029 # to the usual bunch. Setting this variable is optional.
1031 # - <C>_TARGET names the 'make' target that should depend on creating the output
1032 # files. Setting this variable is optional; if unset, we preprocess the
1033 # files for the 'libs' target.
1035 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
1036 # kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
1037 # $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
1038 # instead of $(DIST)/include/qux.h.
1040 pp_target_tier = $(or $($(1)_TARGET),libs)
1041 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
1043 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
1044 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
1046 $(foreach category,$(PP_TARGETS), \
1047 $(foreach tier,$(call pp_target_tier,$(category)), \
1048 $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
1050 $(foreach file,$($(category)), \
1051 $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
1052 $(file) $(GLOBAL_DEPS))) \
1054 $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
1057 $(foreach tier,$(PP_TARGETS_TIERS), \
1058 $(eval $(tier):: $(PP_TARGETS_RESULTS_$(tier))) \
1061 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
1062 $(PP_TARGETS_ALL_RESULTS):
1063 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
1064 $(RM) '$@'
1065 $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
1067 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
1069 # The depfile is based on the filename, and we don't want conflicts. So check
1070 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
1071 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
1072 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
1073 $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
1074 $(error Multiple preprocessing rules are creating a $(file) file) \
1078 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
1079 # If the depfile for a preprocessed file doesn't exist, add a dep to force
1080 # re-preprocessing.
1081 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
1082 $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
1084 $(eval $(file): FORCE) \
1088 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
1090 ifneq (,$(MDDEPEND_FILES))
1091 -include $(MDDEPEND_FILES)
1092 endif
1094 endif
1096 # Pull in non-recursive targets if this is a partial tree build.
1097 ifndef TOPLEVEL_BUILD
1098 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
1099 endif
1101 ################################################################################
1102 # Special gmake rules.
1103 ################################################################################
1107 # Re-define the list of default suffixes, so gmake won't have to churn through
1108 # hundreds of built-in suffix rules for stuff we don't need.
1110 .SUFFIXES:
1113 # Fake targets. Always run these rules, even if a file/directory with that
1114 # name already exists.
1116 .PHONY: all alltags boot chrome realchrome export install libs makefiles run_apprunner tools $(DIRS) FORCE
1118 # Used as a dependency to force targets to rebuild
1119 FORCE:
1121 # Delete target if error occurs when building target
1122 .DELETE_ON_ERROR:
1124 tags: TAGS
1126 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1127 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1128 $(LOOP_OVER_DIRS)
1130 ifndef INCLUDED_DEBUGMAKE_MK #{
1131 ## Only parse when an echo* or show* target is requested
1132 ifneq (,$(call isTargetStem,echo,show))
1133 include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
1134 endif #}
1135 endif #}
1137 FREEZE_VARIABLES = \
1138 CSRCS \
1139 CPPSRCS \
1140 EXPORTS \
1141 DIRS \
1142 LIBRARY \
1143 WASM_LIBRARY \
1144 MODULE \
1145 $(NULL)
1147 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
1149 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
1150 $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
1152 libs export::
1153 $(CHECK_FROZEN_VARIABLES)
1155 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
1157 #############################################################################
1158 # Derived targets and dependencies
1160 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
1161 ifneq ($(NULL),$(AUTO_DEPS))
1162 default all libs tools export:: $(AUTO_DEPS)
1163 endif