Bug 1664775 [wpt PR 25515] - Fieldset NG: Fix hit-testing for the rendered legend...
[gecko.git] / config / rules.mk
blob19c2590bd9f1b15b3493ec6d3d7e1bc6fecfcfa2
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))
218 ALL_TRASH = \
219 $(GARBAGE) $(TARGETS) $(OBJS) $(PROGOBJS) LOGS TAGS a.out \
220 $(filter-out $(ASFILES),$(OBJS:.$(OBJ_SUFFIX)=.s)) $(OBJS:.$(OBJ_SUFFIX)=.ii) \
221 $(OBJS:.$(OBJ_SUFFIX)=.i) \
222 $(HOST_PROGOBJS) $(HOST_OBJS) $(IMPORT_LIBRARY) \
223 so_locations _gen _stubs $(wildcard *.res) $(wildcard *.RES) \
224 $(wildcard *.pdb) $(CODFILE) $(IMPORT_LIBRARY) \
225 $(SHARED_LIBRARY:$(DLL_SUFFIX)=.exp) $(wildcard *.ilk) \
226 $(PROGRAM:$(BIN_SUFFIX)=.exp) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.exp) \
227 $(PROGRAM:$(BIN_SUFFIX)=.lib) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.lib) \
228 $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) \
229 $(WASM_ARCHIVE) $(wildcard gts_tmp_*) $(LIBRARY:%.a=.%.timestamp)
230 ALL_TRASH_DIRS = \
231 $(GARBAGE_DIRS) /no-such-file
233 ifdef QTDIR
234 GARBAGE += $(MOCSRCS)
235 endif
237 ifdef SIMPLE_PROGRAMS
238 GARBAGE += $(SIMPLE_PROGRAMS:%=%.$(OBJ_SUFFIX))
239 endif
241 ifdef HOST_SIMPLE_PROGRAMS
242 GARBAGE += $(HOST_SIMPLE_PROGRAMS:%=%.$(OBJ_SUFFIX))
243 endif
245 ifdef MACH
246 ifndef NO_BUILDSTATUS_MESSAGES
247 define BUILDSTATUS
248 @echo 'BUILDSTATUS $1'
250 endef
251 endif
252 endif
254 define SUBMAKE # $(call SUBMAKE,target,directory,static)
255 +@$(MAKE) $(if $(2),-C $(2)) $(1)
257 endef # The extra line is important here! don't delete it
259 define TIER_DIR_SUBMAKE
260 $(call SUBMAKE,$(4),$(3),$(5))
262 endef # Ths empty line is important.
264 ifneq (,$(strip $(DIRS)))
265 LOOP_OVER_DIRS = \
266 $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
267 endif
270 # Now we can differentiate between objects used to build a library, and
271 # objects used to build an executable in the same directory.
273 ifndef PROGOBJS
274 PROGOBJS = $(OBJS)
275 endif
277 ifndef HOST_PROGOBJS
278 HOST_PROGOBJS = $(HOST_OBJS)
279 endif
281 GARBAGE_DIRS += $(wildcard $(CURDIR)/$(MDDEPDIR))
284 # Tags: emacs (etags), vi (ctags)
285 # TAG_PROGRAM := ctags -L -
287 TAG_PROGRAM = xargs etags -a
290 # Turn on C++ linking if we have any .cpp or .mm files
291 # (moved this from config.mk so that config.mk can be included
292 # before the CPPSRCS are defined)
294 ifneq ($(HOST_CPPSRCS)$(HOST_CMMSRCS),)
295 HOST_CPP_PROG_LINK = 1
296 endif
299 # MacOS X specific stuff
302 ifeq ($(OS_ARCH),Darwin)
303 ifdef SHARED_LIBRARY
304 _LOADER_PATH := @executable_path
305 EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$(SHARED_LIBRARY) -compatibility_version 1 -current_version 1 -single_module
306 endif
307 endif
310 # GNU doesn't have path length limitation
313 ifeq ($(OS_ARCH),GNU)
314 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
315 endif
318 # MINGW32
320 ifeq ($(OS_ARCH),WINNT)
321 ifdef GNU_CC
322 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
323 endif
324 endif
326 ifeq ($(USE_TVFS),1)
327 IFLAGS1 = -rb
328 IFLAGS2 = -rb
329 else
330 IFLAGS1 = -m 644
331 IFLAGS2 = -m 755
332 endif
334 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
335 OUTOPTION = -Fo# eol
336 else
337 OUTOPTION = -o # eol
338 endif # WINNT && !GNU_CC
340 ifeq (,$(CROSS_COMPILE))
341 HOST_OUTOPTION = $(OUTOPTION)
342 else
343 # Windows-to-Windows cross compiles should always use MSVC-style options for
344 # host compiles.
345 ifeq (WINNT_WINNT,$(HOST_OS_ARCH)_$(OS_ARCH))
346 ifneq (,$(filter-out clang-cl,$(HOST_CC_TYPE)))
347 $(error MSVC-style compilers should be used for host compilations!)
348 endif
349 HOST_OUTOPTION = -Fo# eol
350 else
351 HOST_OUTOPTION = -o # eol
352 endif
353 endif
354 ################################################################################
356 # Ensure the build config is up to date. This is done automatically when builds
357 # are performed through |mach build|. The check here is to catch people not
358 # using mach. If we ever enforce builds through mach, this code can be removed.
359 ifndef MOZBUILD_BACKEND_CHECKED
360 ifndef MACH
361 ifndef TOPLEVEL_BUILD
362 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
363 $(DEPTH)/backend.%Backend:
364 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
366 define build_backend_rule
367 $(1): $$(shell cat $(1).in)
369 endef
370 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
372 default:: $(BUILD_BACKEND_FILES)
374 export MOZBUILD_BACKEND_CHECKED=1
375 endif
376 endif
377 endif
379 # The root makefile doesn't want to do a plain export/libs, because
380 # of the tiers and because of libxul. Suppress the default rules in favor
381 # of something else. Makefiles which use this var *must* provide a sensible
382 # default rule before including rules.mk
383 default all::
384 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
386 ifdef BUILD_VERBOSE_LOG
387 ECHO := echo
388 QUIET :=
389 else
390 ECHO := true
391 QUIET := -q
392 endif
394 # Do everything from scratch
395 everything::
396 $(MAKE) clean
397 $(MAKE) all
399 # Dependencies which, if modified, should cause everything to rebuild
400 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
402 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
403 # We always build .res files for programs and shared libraries
404 resfile = $(notdir $1).res
405 # We also build .res files for simple programs if a corresponding manifest
406 # exists. We'll generate a .rc file that includes the manifest.
407 ifdef GNU_CC
408 # Skip on mingw builds because of bug 1657863
409 resfile_for_manifest =
410 else
411 resfile_for_manifest = $(if $(wildcard $(srcdir)/$(notdir $1).manifest),$(call resfile,$1))
412 endif
413 else
414 resfile =
415 resfile_for_manifest =
416 endif
418 ##############################################
419 ifdef COMPILE_ENVIRONMENT
420 compile:: host target
422 host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
424 target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE) $(RUST_PROGRAMS) $(WASM_LIBRARY))
426 ifndef LIBRARY
427 ifdef OBJS
428 target:: $(OBJS)
429 endif
430 endif
432 target-objects: $(OBJS) $(PROGOBJS)
433 host-objects: $(HOST_OBJS) $(HOST_PROGOBJS)
435 syms::
437 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
438 endif
440 clean clobber realclean clobber_all::
441 -$(RM) $(ALL_TRASH)
442 -$(RM) -r $(ALL_TRASH_DIRS)
444 clean clobber realclean clobber_all distclean::
445 $(foreach dir,$(DIRS),-$(call SUBMAKE,$@,$(dir)))
447 distclean::
448 -$(RM) -r $(ALL_TRASH_DIRS)
449 -$(RM) $(ALL_TRASH) \
450 Makefile .HSancillary \
451 $(wildcard *.$(OBJ_SUFFIX)) $(wildcard *.ho) $(wildcard host_*.o*) \
452 $(wildcard *.$(LIB_SUFFIX)) $(wildcard *$(DLL_SUFFIX)) \
453 $(wildcard *.$(IMPORT_LIB_SUFFIX))
455 alltags:
456 $(RM) TAGS
457 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
459 define EXPAND_CC_OR_CXX
460 $(if $(PROG_IS_C_ONLY_$(1)),$(CC),$(CCC))
461 endef
464 # PROGRAM = Foo
465 # creates OBJS, links with LIBS to create Foo
467 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile,$(PROGRAM)) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
468 $(REPORT_BUILD)
469 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
470 $(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)
471 else # !WINNT || GNU_CC
472 $(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)
473 $(call py_action,check_binary,--target $@)
474 endif # WINNT && !GNU_CC
476 ifdef ENABLE_STRIP
477 $(STRIP) $(STRIP_FLAGS) $@
478 endif
479 ifdef MOZ_POST_PROGRAM_COMMAND
480 $(MOZ_POST_PROGRAM_COMMAND) $@
481 endif
483 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
484 $(REPORT_BUILD)
485 ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
486 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
487 else
488 ifeq ($(HOST_CPP_PROG_LINK),1)
489 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
490 else
491 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
492 endif # HOST_CPP_PROG_LINK
493 endif
494 ifndef CROSS_COMPILE
495 $(call py_action,check_binary,--host $@)
496 endif
499 # This is an attempt to support generation of multiple binaries
500 # in one directory, it assumes everything to compile Foo is in
501 # Foo.o (from either Foo.c or Foo.cpp).
503 # SIMPLE_PROGRAMS = Foo Bar
504 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
506 define simple_program_deps
507 $1: $(1:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile_for_manifest,$1) $(GLOBAL_DEPS)
508 endef
509 $(foreach p,$(SIMPLE_PROGRAMS),$(eval $(call simple_program_deps,$(p))))
511 $(SIMPLE_PROGRAMS):
512 $(REPORT_BUILD)
513 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
514 $(LINKER) -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
515 else
516 $(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)
517 $(call py_action,check_binary,--target $@)
518 endif # WINNT && !GNU_CC
520 ifdef ENABLE_STRIP
521 $(STRIP) $(STRIP_FLAGS) $@
522 endif
523 ifdef MOZ_POST_PROGRAM_COMMAND
524 $(MOZ_POST_PROGRAM_COMMAND) $@
525 endif
527 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
528 $(REPORT_BUILD)
529 ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
530 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
531 else
532 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
533 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
534 else
535 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
536 endif
537 endif
538 ifndef CROSS_COMPILE
539 $(call py_action,check_binary,--host $@)
540 endif
542 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
543 $(REPORT_BUILD)
544 $(RM) $(REAL_LIBRARY)
545 $(AR) $(AR_FLAGS) $($@_OBJS)
547 $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
548 $(REPORT_BUILD_VERBOSE)
549 $(RM) $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
550 $(WASM_CXX) $(OUTOPTION)$@ -Wl,--export-all $(WASM_LDFLAGS) $(CWASMOBJS) $(CPPWASMOBJS)
552 lucet_options := \
553 --target $(LUCETC_TARGET) \
554 --target-cpu baseline \
555 --bindings $(topsrcdir)/third_party/rust/lucet-wasi-wasmsbx/bindings.json \
556 --guard-size 4GiB \
557 --min-reserved-size 4GiB \
558 --max-reserved-size 4GiB \
559 --opt-level 2
561 $(WASM_LIBRARY): $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
562 $(REPORT_BUILD)
563 $(RM) $(WASM_LIBRARY)
564 env LD="$(CC)" LDFLAGS="$(LUCETC_LDFLAGS)" $(LUCETC) $(lucet_options) $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX) -o $(WASM_LIBRARY)
566 ifeq ($(OS_ARCH),WINNT)
567 # Import libraries are created by the rules creating shared libraries.
568 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
569 # but make will happily consider the import library before it is refreshed
570 # when rebuilding the corresponding shared library. Defining an empty recipe
571 # for import libraries forces make to wait for the shared library recipe to
572 # have run before considering other targets that depend on the import library.
573 # See bug 795204.
574 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
575 endif
577 $(HOST_SHARED_LIBRARY): Makefile
578 $(REPORT_BUILD)
579 $(RM) $@
580 ifneq (,$(filter clang-cl,$(HOST_CC_TYPE)))
581 $(HOST_LINKER) -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
582 else
583 $(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
584 endif
586 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
587 # so instead of deleting .o files after repacking them into a dylib, we make
588 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
589 # so no need to conditionalize on OS version or debugging format.
591 $(SHARED_LIBRARY): $(OBJS) $(call resfile,$(SHARED_LIBRARY)) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
592 $(REPORT_BUILD)
593 ifndef INCREMENTAL_LINKER
594 $(RM) $@
595 endif
596 $(MKSHLIB) $($@_OBJS) $(filter %.res,$^) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
597 $(call py_action,check_binary,--target $@)
599 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
600 endif # WINNT && !GCC
601 chmod +x $@
602 ifdef ENABLE_STRIP
603 $(STRIP) $(STRIP_FLAGS) $@
604 endif
606 # The object file is in the current directory, and the source file can be any
607 # relative path. This macro adds the dependency obj: src for each source file.
608 # This dependency must be first for the $< flag to work correctly, and the
609 # rules that have commands for these targets must not list any other
610 # prerequisites, or they will override the $< variable.
611 define src_objdep
612 $(basename $3$(notdir $1)).$2: $1 $$(call mkdir_deps,$$(MDDEPDIR))
613 endef
614 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX))))
615 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS) $(HOST_CMSRCS) $(HOST_CMMSRCS),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX),host_)))
616 $(foreach f,$(WASM_CSRCS) $(WASM_CPPSRCS),$(eval $(call src_objdep,$(f),wasm)))
618 # The Rust compiler only outputs library objects, and so we need different
619 # mangling to generate dependency rules for it.
620 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
621 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
622 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
624 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
626 # Rules for building native targets must come first because of the host_ prefix
627 $(HOST_COBJS):
628 $(REPORT_BUILD_VERBOSE)
629 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $<
631 $(HOST_CPPOBJS):
632 $(REPORT_BUILD_VERBOSE)
633 $(call BUILDSTATUS,OBJECT_FILE $@)
634 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $<
636 $(HOST_CMOBJS):
637 $(REPORT_BUILD_VERBOSE)
638 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(HOST_CMFLAGS) $(NSPR_CFLAGS) $<
640 $(HOST_CMMOBJS):
641 $(REPORT_BUILD_VERBOSE)
642 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(HOST_CMMFLAGS) $(NSPR_CFLAGS) $<
644 $(COBJS):
645 $(REPORT_BUILD_VERBOSE)
646 $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
648 $(CWASMOBJS):
649 $(REPORT_BUILD_VERBOSE)
650 $(WASM_CC) $(OUTOPTION)$@ -c $(WASM_CFLAGS) $($(notdir $<)_FLAGS) $<
652 WINEWRAP = $(if $(and $(filter %.exe,$1),$(WINE)),$(WINE) $1,$1)
654 # Windows program run via Wine don't like Unix absolute paths (they look
655 # like command line arguments). So when needed, create relative paths
656 # from absolute paths. We start with $(DEPTH), which gets us to topobjdir,
657 # then add "/.." for each component of topobjdir, which gets us to /.
658 # then we can add the absolute path after that and we have a relative path,
659 # albeit longer than it could be.
660 ifdef WINE
661 relativize = $(if $(filter /%,$1),$(DEPTH)$(subst $(space),,$(foreach d,$(subst /, ,$(topobjdir)),/..))$1,$1)
662 else
663 relativize = $1
664 endif
666 ifdef ASFILES
667 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
668 # a '-c' flag.
669 $(ASOBJS):
670 $(REPORT_BUILD_VERBOSE)
671 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $(call relativize,$<)
672 endif
674 define syms_template
675 syms:: $(2)
676 $(2): $(1)
677 ifdef MOZ_CRASHREPORTER
678 $$(call py_action,dumpsymbols,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
679 ifeq ($(OS_ARCH),WINNT)
680 ifdef WINCHECKSEC
681 $$(PYTHON3) $$(topsrcdir)/build/win32/autowinchecksec.py $$<
682 endif # WINCHECKSEC
683 endif # WINNT
684 endif
685 endef
687 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
688 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
689 endif
691 ifdef MOZ_AUTOMATION
692 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
693 DUMP_SYMS_TARGETS :=
694 endif
695 endif
697 ifdef MOZ_COPY_PDBS
698 MAIN_PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
699 MAIN_PDB_DEST ?= $(FINAL_TARGET)
700 MAIN_PDB_TARGET = syms
701 INSTALL_TARGETS += MAIN_PDB
703 ifdef CPP_UNIT_TESTS
704 CPP_UNIT_TESTS_PDB_FILES = $(addsuffix .pdb,$(basename $(CPP_UNIT_TESTS)))
705 CPP_UNIT_TESTS_PDB_DEST = $(DIST)/cppunittests
706 CPP_UNIT_TESTS_PDB_TARGET = syms
707 INSTALL_TARGETS += CPP_UNIT_TESTS_PDB
708 endif
710 else ifdef MOZ_CRASHREPORTER
711 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
712 endif
714 ifneq (,$(RUST_TESTS)$(RUST_LIBRARY_FILE)$(HOST_RUST_LIBRARY_FILE)$(RUST_PROGRAMS)$(HOST_RUST_PROGRAMS))
715 include $(MOZILLA_DIR)/config/makefiles/rust.mk
716 endif
718 $(SOBJS):
719 $(REPORT_BUILD)
720 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $(call relativize,$<)
722 $(CPPOBJS):
723 $(REPORT_BUILD_VERBOSE)
724 $(call BUILDSTATUS,OBJECT_FILE $@)
725 $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
727 $(CPPWASMOBJS):
728 $(REPORT_BUILD_VERBOSE)
729 $(call BUILDSTATUS,OBJECT_FILE $@)
730 $(WASM_CXX) $(OUTOPTION)$@ -c $(WASM_CXXFLAGS) $($(notdir $<)_FLAGS) $<
732 $(CMMOBJS):
733 $(REPORT_BUILD_VERBOSE)
734 $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $<
736 $(CMOBJS):
737 $(REPORT_BUILD_VERBOSE)
738 $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $<
740 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
741 $(REPORT_BUILD_VERBOSE)
742 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
744 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
745 $(REPORT_BUILD_VERBOSE)
746 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
748 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
749 $(REPORT_BUILD_VERBOSE)
750 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
752 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
753 $(REPORT_BUILD_VERBOSE)
754 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
756 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
757 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
758 # of the full sources, as well as the $(notdir) version. So:
759 # foo.cpp sub/bar.cpp
760 # becomes:
761 # foo.cpp sub/bar.cpp bar.cpp
763 # This way we can match both 'make sub/bar.i' and 'make bar.i'
764 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
766 define PREPROCESS_RULES
767 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
768 # Make preprocessed files PHONY so they are always executed, since they are
769 # manual targets and we don't necessarily write to $@.
770 .PHONY: $$(_PREPROCESSED_$1_FILES)
772 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
773 # reach $(srcdir)/frontend/Parser.i
774 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
775 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
777 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
778 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
779 $$(REPORT_BUILD_VERBOSE)
780 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
781 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$<
783 endef
785 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
786 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
787 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
788 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
789 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
791 # Default to pre-processing the actual unified file. This can be overridden
792 # at the command-line to pre-process only the individual source file.
793 PP_UNIFIED ?= 1
795 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
796 # infinite loop if the filename doesn't exist in the unified source files.
797 ifndef PP_REINVOKE
799 MATCH_cpp = \(cpp\|cc|cxx\)
800 UPPER_c = C
801 UPPER_cpp = CPP
802 UPPER_mm = CMM
804 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
805 # find a matching pathname.
806 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
807 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
808 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
809 all_c_sources := $(call _get_all_sources,$(CSRCS))
810 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
812 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
813 # one of the *SRCS variables. The two code paths depend on whether or not
814 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
816 # PP_UNIFIED=1:
817 # - Look for it in any of the Unified files, and re-exec make with
818 # Unified_foo0.i as the target. This gets us the full unified preprocessed
819 # file.
821 # PP_UNIFIED=0:
822 # - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
823 # make with that filename as the target. The *SRCS variables are modified
824 # to have the Unified sources appended to them so that the static pattern
825 # rules will match.
826 %.i: FORCE
827 ifeq ($(PP_UNIFIED),1)
828 @$(MAKE) PP_REINVOKE=1 \
829 $(or $(addsuffix .i, \
830 $(foreach type,c cpp mm, \
831 $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
832 $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
833 ))),$(error "File not found for preprocessing: $@"))
834 else
835 @$(MAKE) PP_REINVOKE=1 $@ \
836 $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
837 endif
839 endif
841 endif
843 # EXTRA_DEPS contains manifests (manually added in Makefile.in ; bug 1498414)
844 %.res: $(or $(RCFILE),%.rc) $(MOZILLA_DIR)/config/create_res.py $(EXTRA_DEPS)
845 $(REPORT_BUILD)
846 $(PYTHON3) $(MOZILLA_DIR)/config/create_res.py $(DEFINES) $(INCLUDES) -o $@ $<
848 $(notdir $(addsuffix .rc,$(PROGRAM) $(SHARED_LIBRARY) $(SIMPLE_PROGRAMS) module)): %.rc: $(RCINCLUDE) $(MOZILLA_DIR)/config/create_rc.py
849 $(PYTHON3) $(MOZILLA_DIR)/config/create_rc.py '$(if $(filter module,$*),,$*)' '$(RCINCLUDE)'
851 # Cancel GNU make built-in implicit rules
852 MAKEFLAGS += -r
854 ifneq (,$(filter WINNT,$(OS_ARCH)))
855 SEP := ;
856 else
857 SEP := :
858 endif
860 EMPTY :=
861 SPACE := $(EMPTY) $(EMPTY)
863 ###############################################################################
864 # Bunch of things that extend the 'export' rule (in order):
865 ###############################################################################
867 ifneq ($(XPI_NAME),)
868 $(FINAL_TARGET):
869 $(NSINSTALL) -D $@
871 export:: $(FINAL_TARGET)
872 endif
874 ################################################################################
875 # The default location for prefs is the gre prefs directory.
876 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
877 PREF_DIR = defaults/pref
879 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
880 # different and that we are building app related resources. Hence,
881 # PREF_DIR should point to the app prefs location.
882 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
883 PREF_DIR = defaults/preferences
884 endif
886 ################################################################################
887 # CHROME PACKAGING
889 chrome::
890 $(MAKE) realchrome
891 $(LOOP_OVER_DIRS)
893 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
895 ifneq (,$(JAR_MANIFEST))
896 ifndef NO_DIST_INSTALL
898 ifdef XPI_NAME
899 ifdef XPI_ROOT_APPID
900 # For add-on packaging we may specify that an application
901 # sub-dir should be added to the root chrome manifest with
902 # a specific application id.
903 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
904 endif
906 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
907 # no way langpacks will get packaged right, so error out.
908 ifneq (,$(DIST_SUBDIR))
909 ifndef XPI_ROOT_APPID
910 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
911 endif
912 endif
913 endif
915 misc realchrome:: $(FINAL_TARGET)/chrome
916 $(call py_action,jar_maker,\
917 $(QUIET) -d $(FINAL_TARGET) \
918 $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
919 $(JAR_MANIFEST))
921 ifdef AB_CD
922 .PHONY: l10n
923 l10n: misc ;
924 endif
925 endif
927 endif
929 # When you move this out of the tools tier, please remove the corresponding
930 # hacks in recursivemake.py that check if Makefile.in sets the variable.
931 ifneq ($(XPI_PKGNAME),)
932 tools realchrome::
933 ifdef STRIP_XPI
934 ifndef MOZ_DEBUG
935 @echo 'Stripping $(XPI_PKGNAME) package directory...'
936 @echo $(FINAL_TARGET)
937 @cd $(FINAL_TARGET) && find . ! -type d \
938 ! -name '*.js' \
939 ! -name '*.xpt' \
940 ! -name '*.gif' \
941 ! -name '*.jpg' \
942 ! -name '*.png' \
943 ! -name '*.xpm' \
944 ! -name '*.txt' \
945 ! -name '*.rdf' \
946 ! -name '*.sh' \
947 ! -name '*.properties' \
948 ! -name '*.dtd' \
949 ! -name '*.html' \
950 ! -name '*.xul' \
951 ! -name '*.css' \
952 ! -name '*.xml' \
953 ! -name '*.jar' \
954 ! -name '*.dat' \
955 ! -name '*.tbl' \
956 ! -name '*.src' \
957 ! -name '*.reg' \
958 $(PLATFORM_EXCLUDE_LIST) \
959 -exec $(STRIP) $(STRIP_FLAGS) {} >/dev/null 2>&1 \;
960 endif
961 endif
962 @echo 'Packaging $(XPI_PKGNAME).xpi...'
963 $(call py_action,zip,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
964 endif
966 # See comment above about moving this out of the tools tier.
967 ifdef INSTALL_EXTENSION_ID
968 ifndef XPI_NAME
969 $(error XPI_NAME must be set for INSTALL_EXTENSION_ID)
970 endif
972 tools::
973 $(RM) -r '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
974 $(NSINSTALL) -D '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
975 $(call copy_dir,$(FINAL_TARGET),$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID))
977 endif
979 #############################################################################
980 # MDDEPDIR is the subdirectory where all the dependency files are placed.
981 # This uses a make rule (instead of a macro) to support parallel
982 # builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
983 # processes could simultaneously try to create the same directory.
985 # We use $(CURDIR) in the rule's target to ensure that we don't find
986 # a dependency directory in the source tree via VPATH (perhaps from
987 # a previous build in the source tree) and thus neglect to create a
988 # dependency directory in the object directory, where we really need
989 # it.
991 _MDDEPEND_FILES :=
993 ifneq (,$(filter target-objects target all default,$(MAKECMDGOALS)))
994 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS))))
995 endif
997 ifneq (,$(filter host-objects host all default,$(MAKECMDGOALS)))
998 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(HOST_OBJS) $(HOST_PROGOBJS))))
999 endif
1001 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(_MDDEPEND_FILES))))
1002 MDDEPEND_FILES += $(EXTRA_MDDEPEND_FILES)
1004 ifneq (,$(MDDEPEND_FILES))
1005 -include $(MDDEPEND_FILES)
1006 endif
1008 ################################################################################
1009 # Install/copy rules
1011 # The INSTALL_TARGETS variable contains a list of all install target
1012 # categories. Each category defines a list of files and executables, and an
1013 # install destination,
1015 # FOO_FILES := foo bar
1016 # FOO_EXECUTABLES := baz
1017 # FOO_DEST := target_path
1018 # INSTALL_TARGETS += FOO
1020 # Additionally, a FOO_TARGET variable may be added to indicate the target for
1021 # which the files and executables are installed. Default is "libs".
1023 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
1024 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
1025 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
1026 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
1028 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
1029 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
1030 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
1031 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
1033 define install_cmd_override
1034 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
1035 endef
1036 endif
1037 endif
1039 install_target_tier = $(or $($(1)_TARGET),libs)
1040 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
1042 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
1043 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
1044 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
1046 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
1047 # See details in bug 934864.
1048 define create_dependency
1049 $(1): $(2)
1050 $(1): $(2)
1051 endef
1053 define install_target_template
1054 $(call install_cmd_override,$(2))
1055 $(call create_dependency,$(2),$(1))
1056 endef
1058 $(foreach category,$(INSTALL_TARGETS),\
1059 $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
1060 $(foreach tier,$(call install_target_tier,$(category)),\
1061 $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
1062 $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
1064 $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
1065 $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
1069 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
1070 $(eval $(tier):: $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
1073 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
1075 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
1076 $(install_targets_sanity)
1077 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
1079 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
1080 $(install_targets_sanity)
1081 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
1083 ################################################################################
1084 # Preprocessing rules
1086 # The PP_TARGETS variable contains a list of all preprocessing target
1087 # categories. Each category has associated variables listing input files, the
1088 # output directory, extra preprocessor flags, and so on. For example:
1090 # FOO := input-file
1091 # FOO_PATH := target-directory
1092 # FOO_FLAGS := -Dsome_flag
1093 # PP_TARGETS += FOO
1095 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
1096 # following make variables to see what to do:
1098 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
1099 # We search VPATH for the names given here. If an input file name ends in
1100 # '.in', that suffix is omitted from the output file name.
1102 # - <C>_PATH names the directory in which to place the preprocessed output
1103 # files. We create this directory if it does not already exist. Setting
1104 # this variable is optional; if unset, we install the files in $(CURDIR).
1106 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
1107 # to the usual bunch. Setting this variable is optional.
1109 # - <C>_TARGET names the 'make' target that should depend on creating the output
1110 # files. Setting this variable is optional; if unset, we preprocess the
1111 # files for the 'libs' target.
1113 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
1114 # kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
1115 # $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
1116 # instead of $(DIST)/include/qux.h.
1118 pp_target_tier = $(or $($(1)_TARGET),libs)
1119 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
1121 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
1122 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
1124 $(foreach category,$(PP_TARGETS), \
1125 $(foreach tier,$(call pp_target_tier,$(category)), \
1126 $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
1128 $(foreach file,$($(category)), \
1129 $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
1130 $(file) $(GLOBAL_DEPS))) \
1132 $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
1135 $(foreach tier,$(PP_TARGETS_TIERS), \
1136 $(eval $(tier):: $(PP_TARGETS_RESULTS_$(tier))) \
1139 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
1140 $(PP_TARGETS_ALL_RESULTS):
1141 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
1142 $(RM) '$@'
1143 $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
1145 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
1147 # The depfile is based on the filename, and we don't want conflicts. So check
1148 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
1149 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
1150 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
1151 $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
1152 $(error Multiple preprocessing rules are creating a $(file) file) \
1156 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
1157 # If the depfile for a preprocessed file doesn't exist, add a dep to force
1158 # re-preprocessing.
1159 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
1160 $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
1162 $(eval $(file): FORCE) \
1166 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
1168 ifneq (,$(MDDEPEND_FILES))
1169 -include $(MDDEPEND_FILES)
1170 endif
1172 endif
1174 # Pull in non-recursive targets if this is a partial tree build.
1175 ifndef TOPLEVEL_BUILD
1176 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
1177 endif
1179 ################################################################################
1180 # Special gmake rules.
1181 ################################################################################
1185 # Re-define the list of default suffixes, so gmake won't have to churn through
1186 # hundreds of built-in suffix rules for stuff we don't need.
1188 .SUFFIXES:
1191 # Fake targets. Always run these rules, even if a file/directory with that
1192 # name already exists.
1194 .PHONY: all alltags boot chrome realchrome clean clobber clobber_all export install libs makefiles realclean run_apprunner tools $(DIRS) FORCE
1196 # Used as a dependency to force targets to rebuild
1197 FORCE:
1199 # Delete target if error occurs when building target
1200 .DELETE_ON_ERROR:
1202 tags: TAGS
1204 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1205 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1206 $(LOOP_OVER_DIRS)
1208 ifndef INCLUDED_DEBUGMAKE_MK #{
1209 ## Only parse when an echo* or show* target is requested
1210 ifneq (,$(call isTargetStem,echo,show))
1211 include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
1212 endif #}
1213 endif #}
1215 FREEZE_VARIABLES = \
1216 CSRCS \
1217 CPPSRCS \
1218 EXPORTS \
1219 DIRS \
1220 LIBRARY \
1221 WASM_LIBRARY \
1222 MODULE \
1223 $(NULL)
1225 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
1227 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
1228 $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
1230 libs export::
1231 $(CHECK_FROZEN_VARIABLES)
1233 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
1235 #############################################################################
1236 # Derived targets and dependencies
1238 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
1239 ifneq ($(NULL),$(AUTO_DEPS))
1240 default all libs tools export:: $(AUTO_DEPS)
1241 endif