Bug 1601859 - Vendor cubeb-pulse-rs. r=kinetik
[gecko.git] / config / rules.mk
blobc3b63e9addbcbdab37171b9707bbce78e4fc7144
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 $(relativesrcdir)/$(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 ################################################################################
47 # Testing frameworks support
48 ################################################################################
50 testxpcobjdir = $(DEPTH)/_tests/xpcshell
52 ifdef ENABLE_TESTS
53 ifdef CPP_UNIT_TESTS
54 ifdef COMPILE_ENVIRONMENT
56 # Compile the tests to $(DIST)/bin. Make lots of niceties available by default
57 # through TestHarness.h, by modifying the list of includes and the libs against
58 # which stuff links.
59 SIMPLE_PROGRAMS += $(CPP_UNIT_TESTS)
61 ifndef MOZ_PROFILE_GENERATE
62 CPP_UNIT_TESTS_FILES = $(CPP_UNIT_TESTS)
63 CPP_UNIT_TESTS_DEST = $(DIST)/cppunittests
64 CPP_UNIT_TESTS_TARGET = target
65 INSTALL_TARGETS += CPP_UNIT_TESTS
66 endif
68 run-cppunittests::
69 @$(PYTHON) $(MOZILLA_DIR)/testing/runcppunittests.py --xre-path=$(DIST)/bin --symbols-path=$(DIST)/crashreporter-symbols $(CPP_UNIT_TESTS)
71 cppunittests-remote:
72 $(PYTHON) -u $(MOZILLA_DIR)/testing/remotecppunittests.py \
73 --xre-path=$(DEPTH)/dist/bin \
74 --localLib=$(DEPTH)/dist/$(MOZ_APP_NAME) \
75 --deviceIP=${TEST_DEVICE} \
76 $(CPP_UNIT_TESTS) $(EXTRA_TEST_ARGS); \
78 endif # COMPILE_ENVIRONMENT
79 endif # CPP_UNIT_TESTS
80 endif # ENABLE_TESTS
84 # Library rules
86 # If FORCE_STATIC_LIB is set, build a static library.
87 # Otherwise, build a shared library.
90 ifndef LIBRARY
91 ifdef REAL_LIBRARY
92 ifdef NO_EXPAND_LIBS
93 # Only build actual library if it is requested.
94 LIBRARY := $(REAL_LIBRARY)
95 endif
96 endif
97 endif
99 ifdef FORCE_SHARED_LIB
100 ifdef MKSHLIB
102 ifdef LIB_IS_C_ONLY
103 MKSHLIB = $(MKCSHLIB)
104 endif
106 EMBED_MANIFEST_AT=2
108 endif # MKSHLIB
109 endif # FORCE_SHARED_LIB
111 ifeq ($(OS_ARCH),WINNT)
114 # This next line captures both the default (non-MOZ_COPY_PDBS)
115 # case as well as the MOZ_COPY_PDBS-for-mingwclang case.
117 # For the default case, placing the pdb in the build
118 # directory is needed.
120 # For the MOZ_COPY_PDBS, non-mingwclang case - we need to
121 # build the pdb next to the executable (handled in the if
122 # statement immediately below.)
124 # For the MOZ_COPY_PDBS, mingwclang case - we also need to
125 # build the pdb next to the executable, but this macro doesn't
126 # work for jsapi-tests which is a little special, so we specify
127 # the output directory below with MOZ_PROGRAM_LDFLAGS.
129 LINK_PDBFILE ?= $(basename $(@F)).pdb
131 ifdef MOZ_COPY_PDBS
132 ifneq ($(CC_TYPE),clang)
133 LINK_PDBFILE = $(basename $@).pdb
134 endif
135 endif
137 ifndef GNU_CC
139 ifdef SIMPLE_PROGRAMS
140 COMPILE_PDB_FLAG ?= -Fd$(basename $(@F)).pdb
141 COMPILE_CFLAGS += $(COMPILE_PDB_FLAG)
142 COMPILE_CXXFLAGS += $(COMPILE_PDB_FLAG)
143 endif
145 ifdef MOZ_DEBUG
146 CODFILE=$(basename $(@F)).cod
147 endif
149 endif # !GNU_CC
150 endif # WINNT
152 ifeq (arm-Darwin,$(CPU_ARCH)-$(OS_TARGET))
153 ifdef PROGRAM
154 MOZ_PROGRAM_LDFLAGS += -Wl,-rpath -Wl,@executable_path/Frameworks
155 endif
156 endif
158 ifeq ($(OS_ARCH),WINNT)
159 ifeq ($(CC_TYPE),clang)
160 MOZ_PROGRAM_LDFLAGS += -Wl,-pdb,$(dir $@)/$(LINK_PDBFILE)
161 endif
162 endif
164 ifeq ($(HOST_OS_ARCH),WINNT)
165 HOST_PDBFILE=$(basename $(@F)).pdb
166 HOST_PDB_FLAG ?= -PDB:$(HOST_PDBFILE)
167 HOST_C_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
168 HOST_CXX_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
169 endif
171 # Don't build SIMPLE_PROGRAMS during the MOZ_PROFILE_GENERATE pass, and do not
172 # attempt to install them
173 ifdef MOZ_PROFILE_GENERATE
174 $(foreach category,$(INSTALL_TARGETS),\
175 $(eval $(category)_FILES := $(foreach file,$($(category)_FILES),$(if $(filter $(SIMPLE_PROGRAMS),$(notdir $(file))),,$(file)))))
176 SIMPLE_PROGRAMS :=
177 endif
179 ifdef COMPILE_ENVIRONMENT
180 ifndef TARGETS
181 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY) $(WASM_LIBRARY)
182 endif
184 COBJS = $(notdir $(CSRCS:.c=.$(OBJ_SUFFIX)))
185 CWASMOBJS = $(notdir $(WASM_CSRCS:.c=.$(WASM_OBJ_SUFFIX)))
186 SOBJS = $(notdir $(SSRCS:.S=.$(OBJ_SUFFIX)))
187 # CPPSRCS can have different extensions (eg: .cpp, .cc)
188 CPPOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(CPPSRCS))))
189 CPPWASMOBJS = $(notdir $(addsuffix .$(WASM_OBJ_SUFFIX),$(basename $(WASM_CPPSRCS))))
190 CMOBJS = $(notdir $(CMSRCS:.m=.$(OBJ_SUFFIX)))
191 CMMOBJS = $(notdir $(CMMSRCS:.mm=.$(OBJ_SUFFIX)))
192 # ASFILES can have different extensions (.s, .asm)
193 ASOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(ASFILES))))
194 RS_STATICLIB_CRATE_OBJ = $(addprefix lib,$(notdir $(RS_STATICLIB_CRATE_SRC:.rs=.$(LIB_SUFFIX))))
195 ifndef OBJS
196 _OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS) $(CWASMOBJS) $(CPPWASMOBJS)
197 OBJS = $(strip $(_OBJS))
198 endif
200 HOST_COBJS = $(addprefix host_,$(notdir $(HOST_CSRCS:.c=.$(_OBJ_SUFFIX))))
201 # HOST_CPPOBJS can have different extensions (eg: .cpp, .cc)
202 HOST_CPPOBJS = $(addprefix host_,$(notdir $(addsuffix .$(_OBJ_SUFFIX),$(basename $(HOST_CPPSRCS)))))
203 HOST_CMOBJS = $(addprefix host_,$(notdir $(HOST_CMSRCS:.m=.$(_OBJ_SUFFIX))))
204 HOST_CMMOBJS = $(addprefix host_,$(notdir $(HOST_CMMSRCS:.mm=.$(_OBJ_SUFFIX))))
205 ifndef HOST_OBJS
206 _HOST_OBJS = $(HOST_COBJS) $(HOST_CPPOBJS) $(HOST_CMOBJS) $(HOST_CMMOBJS)
207 HOST_OBJS = $(strip $(_HOST_OBJS))
208 endif
209 else
210 LIBRARY :=
211 SHARED_LIBRARY :=
212 IMPORT_LIBRARY :=
213 REAL_LIBRARY :=
214 PROGRAM :=
215 SIMPLE_PROGRAMS :=
216 HOST_SHARED_LIBRARY :=
217 HOST_PROGRAM :=
218 HOST_SIMPLE_PROGRAMS :=
219 WASM_LIBRARY :=
220 endif
222 WASM_ARCHIVE = $(addsuffix .$(WASM_OBJ_SUFFIX),$(WASM_LIBRARY))
224 ALL_TRASH = \
225 $(GARBAGE) $(TARGETS) $(OBJS) $(PROGOBJS) LOGS TAGS a.out \
226 $(filter-out $(ASFILES),$(OBJS:.$(OBJ_SUFFIX)=.s)) $(OBJS:.$(OBJ_SUFFIX)=.ii) \
227 $(OBJS:.$(OBJ_SUFFIX)=.i) $(OBJS:.$(OBJ_SUFFIX)=.i_o) \
228 $(HOST_PROGOBJS) $(HOST_OBJS) $(IMPORT_LIBRARY) \
229 so_locations _gen _stubs $(wildcard *.res) $(wildcard *.RES) \
230 $(wildcard *.pdb) $(CODFILE) $(IMPORT_LIBRARY) \
231 $(SHARED_LIBRARY:$(DLL_SUFFIX)=.exp) $(wildcard *.ilk) \
232 $(PROGRAM:$(BIN_SUFFIX)=.exp) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.exp) \
233 $(PROGRAM:$(BIN_SUFFIX)=.lib) $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.lib) \
234 $(SIMPLE_PROGRAMS:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) \
235 $(WASM_ARCHIVE) $(wildcard gts_tmp_*) $(LIBRARY:%.a=.%.timestamp)
236 ALL_TRASH_DIRS = \
237 $(GARBAGE_DIRS) /no-such-file
239 ifdef QTDIR
240 GARBAGE += $(MOCSRCS)
241 endif
243 ifdef SIMPLE_PROGRAMS
244 GARBAGE += $(SIMPLE_PROGRAMS:%=%.$(OBJ_SUFFIX))
245 endif
247 ifdef HOST_SIMPLE_PROGRAMS
248 GARBAGE += $(HOST_SIMPLE_PROGRAMS:%=%.$(_OBJ_SUFFIX))
249 endif
251 ifdef MACH
252 ifndef NO_BUILDSTATUS_MESSAGES
253 define BUILDSTATUS
254 @echo 'BUILDSTATUS $1'
256 endef
257 endif
258 endif
260 define SUBMAKE # $(call SUBMAKE,target,directory,static)
261 +@$(MAKE) $(if $(2),-C $(2)) $(1)
263 endef # The extra line is important here! don't delete it
265 define TIER_DIR_SUBMAKE
266 $(call SUBMAKE,$(4),$(3),$(5))
268 endef # Ths empty line is important.
270 ifneq (,$(strip $(DIRS)))
271 LOOP_OVER_DIRS = \
272 $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
273 endif
276 # Now we can differentiate between objects used to build a library, and
277 # objects used to build an executable in the same directory.
279 ifndef PROGOBJS
280 PROGOBJS = $(OBJS)
281 endif
283 ifndef HOST_PROGOBJS
284 HOST_PROGOBJS = $(HOST_OBJS)
285 endif
287 GARBAGE_DIRS += $(wildcard $(CURDIR)/$(MDDEPDIR))
290 # Tags: emacs (etags), vi (ctags)
291 # TAG_PROGRAM := ctags -L -
293 TAG_PROGRAM = xargs etags -a
296 # Turn on C++ linking if we have any .cpp or .mm files
297 # (moved this from config.mk so that config.mk can be included
298 # before the CPPSRCS are defined)
300 ifneq ($(HOST_CPPSRCS)$(HOST_CMMSRCS),)
301 HOST_CPP_PROG_LINK = 1
302 endif
305 # MacOS X specific stuff
308 ifeq ($(OS_ARCH),Darwin)
309 ifdef SHARED_LIBRARY
310 ifdef MOZ_IOS
311 _LOADER_PATH := @rpath
312 else
313 _LOADER_PATH := @executable_path
314 endif
315 EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$(SHARED_LIBRARY) -compatibility_version 1 -current_version 1 -single_module
316 endif
317 endif
320 # GNU doesn't have path length limitation
323 ifeq ($(OS_ARCH),GNU)
324 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
325 endif
328 # MINGW32
330 ifeq ($(OS_ARCH),WINNT)
331 ifdef GNU_CC
332 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
333 endif
334 endif
336 ifeq ($(USE_TVFS),1)
337 IFLAGS1 = -rb
338 IFLAGS2 = -rb
339 else
340 IFLAGS1 = -m 644
341 IFLAGS2 = -m 755
342 endif
344 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
345 OUTOPTION = -Fo# eol
346 else
347 OUTOPTION = -o # eol
348 endif # WINNT && !GNU_CC
350 ifeq (,$(CROSS_COMPILE))
351 HOST_OUTOPTION = $(OUTOPTION)
352 else
353 # Windows-to-Windows cross compiles should always use MSVC-style options for
354 # host compiles.
355 ifeq (WINNT_WINNT,$(HOST_OS_ARCH)_$(OS_ARCH))
356 ifneq (,$(filter-out clang-cl,$(HOST_CC_TYPE)))
357 $(error MSVC-style compilers should be used for host compilations!)
358 endif
359 HOST_OUTOPTION = -Fo# eol
360 else
361 HOST_OUTOPTION = -o # eol
362 endif
363 endif
364 ################################################################################
366 # Ensure the build config is up to date. This is done automatically when builds
367 # are performed through |mach build|. The check here is to catch people not
368 # using mach. If we ever enforce builds through mach, this code can be removed.
369 ifndef MOZBUILD_BACKEND_CHECKED
370 ifndef MACH
371 ifndef TOPLEVEL_BUILD
372 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
373 $(DEPTH)/backend.%Backend:
374 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
376 define build_backend_rule
377 $(1): $$(shell cat $(1).in)
379 endef
380 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
382 default:: $(BUILD_BACKEND_FILES)
384 export MOZBUILD_BACKEND_CHECKED=1
385 endif
386 endif
387 endif
389 # The root makefile doesn't want to do a plain export/libs, because
390 # of the tiers and because of libxul. Suppress the default rules in favor
391 # of something else. Makefiles which use this var *must* provide a sensible
392 # default rule before including rules.mk
393 default all::
394 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
396 ifdef BUILD_VERBOSE_LOG
397 ECHO := echo
398 QUIET :=
399 else
400 ECHO := true
401 QUIET := -q
402 endif
404 # Do everything from scratch
405 everything::
406 $(MAKE) clean
407 $(MAKE) all
409 # Dependencies which, if modified, should cause everything to rebuild
410 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
412 ##############################################
413 ifdef COMPILE_ENVIRONMENT
414 compile:: host target
416 host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
418 target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE) $(RUST_PROGRAMS) $(WASM_LIBRARY))
420 ifndef LIBRARY
421 ifdef OBJS
422 target:: $(OBJS)
423 endif
424 endif
426 target-objects: $(OBJS) $(PROGOBJS)
427 host-objects: $(HOST_OBJS) $(HOST_PROGOBJS)
429 syms::
431 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
432 endif
434 clean clobber realclean clobber_all::
435 -$(RM) $(ALL_TRASH)
436 -$(RM) -r $(ALL_TRASH_DIRS)
438 clean clobber realclean clobber_all distclean::
439 $(foreach dir,$(DIRS),-$(call SUBMAKE,$@,$(dir)))
441 distclean::
442 -$(RM) -r $(ALL_TRASH_DIRS)
443 -$(RM) $(ALL_TRASH) \
444 Makefile .HSancillary \
445 $(wildcard *.$(OBJ_SUFFIX)) $(wildcard *.ho) $(wildcard host_*.o*) \
446 $(wildcard *.$(LIB_SUFFIX)) $(wildcard *$(DLL_SUFFIX)) \
447 $(wildcard *.$(IMPORT_LIB_SUFFIX))
449 alltags:
450 $(RM) TAGS
451 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
453 define EXPAND_CC_OR_CXX
454 $(if $(PROG_IS_C_ONLY_$(1)),$(CC),$(CCC))
455 endef
458 # PROGRAM = Foo
459 # creates OBJS, links with LIBS to create Foo
461 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(RESFILE) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
462 $(REPORT_BUILD)
463 @$(RM) $@.manifest
464 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
465 $(LINKER) -NOLOGO -OUT:$@ -PDB:$(LINK_PDBFILE) -IMPLIB:$(basename $(@F)).lib $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $($(notdir $@)_OBJS) $(RESFILE) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
466 ifdef MSMANIFEST_TOOL
467 @if test -f $@.manifest; then \
468 if test -f '$(srcdir)/$(notdir $@).manifest'; then \
469 echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest and $@.manifest'; \
470 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' $@.manifest -OUTPUTRESOURCE:$@\;1; \
471 else \
472 echo 'Embedding manifest from $@.manifest'; \
473 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
474 fi; \
475 elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
476 echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest'; \
477 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
479 endif # MSVC with manifest tool
480 else # !WINNT || GNU_CC
481 $(call EXPAND_CC_OR_CXX,$@) -o $@ $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) $($(notdir $@)_OBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
482 $(call py_action,check_binary,--target $@)
483 endif # WINNT && !GNU_CC
485 ifdef ENABLE_STRIP
486 $(STRIP) $(STRIP_FLAGS) $@
487 endif
488 ifdef MOZ_POST_PROGRAM_COMMAND
489 $(MOZ_POST_PROGRAM_COMMAND) $@
490 endif
492 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
493 $(REPORT_BUILD)
494 ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
495 $(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
496 ifdef MSMANIFEST_TOOL
497 @if test -f $@.manifest; then \
498 if test -f '$(srcdir)/$(notdir $@).manifest'; then \
499 echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest and $@.manifest'; \
500 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' $@.manifest -OUTPUTRESOURCE:$@\;1; \
501 else \
502 echo 'Embedding manifest from $@.manifest'; \
503 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
504 fi; \
505 elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
506 echo 'Embedding manifest from $(srcdir_rel)/$(notdir $@).manifest'; \
507 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
509 endif # MSVC with manifest tool
510 else
511 ifeq ($(HOST_CPP_PROG_LINK),1)
512 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
513 else
514 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
515 endif # HOST_CPP_PROG_LINK
516 endif
517 ifndef CROSS_COMPILE
518 $(call py_action,check_binary,--host $@)
519 endif
522 # This is an attempt to support generation of multiple binaries
523 # in one directory, it assumes everything to compile Foo is in
524 # Foo.o (from either Foo.c or Foo.cpp).
526 # SIMPLE_PROGRAMS = Foo Bar
527 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
529 $(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
530 $(REPORT_BUILD)
531 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
532 $(LINKER) -nologo -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
533 ifdef MSMANIFEST_TOOL
534 @if test -f $@.manifest; then \
535 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
536 rm -f $@.manifest; \
537 elif test -f '$(srcdir)/$(notdir $@).manifest'; then \
538 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$(notdir $@).manifest' -OUTPUTRESOURCE:$@\;1; \
540 endif # MSVC with manifest tool
541 else
542 $(call EXPAND_CC_OR_CXX,$@) $(COMPUTED_CXX_LDFLAGS) $(PGO_CFLAGS) -o $@ $($@_OBJS) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
543 $(call py_action,check_binary,--target $@)
544 endif # WINNT && !GNU_CC
546 ifdef ENABLE_STRIP
547 $(STRIP) $(STRIP_FLAGS) $@
548 endif
549 ifdef MOZ_POST_PROGRAM_COMMAND
550 $(MOZ_POST_PROGRAM_COMMAND) $@
551 endif
553 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
554 $(REPORT_BUILD)
555 ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
556 $(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
557 else
558 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
559 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
560 else
561 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
562 endif
563 endif
564 ifndef CROSS_COMPILE
565 $(call py_action,check_binary,--host $@)
566 endif
568 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
569 $(REPORT_BUILD)
570 $(RM) $(REAL_LIBRARY)
571 $(AR) $(AR_FLAGS) $($@_OBJS)
573 $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
574 $(REPORT_BUILD_VERBOSE)
575 $(RM) $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
576 $(WASM_CXX) $(OUTOPTION)$@ -Wl,--export-all $(WASM_LDFLAGS) $(CWASMOBJS) $(CPPWASMOBJS)
577 $(WASM_LIBRARY): $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX)
578 $(REPORT_BUILD)
579 $(RM) $(WASM_LIBRARY)
580 $(LUCETC) --bindings $(topsrcdir)/third_party/rust/lucet-wasi/bindings.json $(WASM_LIBRARY).$(WASM_OBJ_SUFFIX) --opt-level 2 -o $(WASM_LIBRARY)
582 ifeq ($(OS_ARCH),WINNT)
583 # Import libraries are created by the rules creating shared libraries.
584 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
585 # but make will happily consider the import library before it is refreshed
586 # when rebuilding the corresponding shared library. Defining an empty recipe
587 # for import libraries forces make to wait for the shared library recipe to
588 # have run before considering other targets that depend on the import library.
589 # See bug 795204.
590 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
591 endif
593 $(HOST_SHARED_LIBRARY): Makefile
594 $(REPORT_BUILD)
595 $(RM) $@
596 ifneq (,$(filter clang-cl,$(HOST_CC_TYPE)))
597 $(HOST_LINKER) -NOLOGO -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
598 else
599 $(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
600 endif
602 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
603 # so instead of deleting .o files after repacking them into a dylib, we make
604 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
605 # so no need to conditionalize on OS version or debugging format.
607 $(SHARED_LIBRARY): $(OBJS) $(RESFILE) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
608 $(REPORT_BUILD)
609 ifndef INCREMENTAL_LINKER
610 $(RM) $@
611 endif
612 $(MKSHLIB) $($@_OBJS) $(RESFILE) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
613 $(call py_action,check_binary,--target $@)
615 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
616 ifdef MSMANIFEST_TOOL
617 ifdef EMBED_MANIFEST_AT
618 @if test -f $@.manifest; then \
619 if test -f '$(srcdir)/$@.manifest'; then \
620 echo 'Embedding manifest from $(srcdir_rel)/$@.manifest and $@.manifest'; \
621 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$@.manifest' $@.manifest -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
622 else \
623 echo 'Embedding manifest from $@.manifest'; \
624 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
625 fi; \
626 elif test -f '$(srcdir)/$@.manifest'; then \
627 echo 'Embedding manifest from $(srcdir_rel)/$@.manifest'; \
628 $(MT) -NOLOGO -MANIFEST '$(srcdir_rel)/$@.manifest' -OUTPUTRESOURCE:$@\;$(EMBED_MANIFEST_AT); \
630 endif # EMBED_MANIFEST_AT
631 endif # MSVC with manifest tool
632 endif # WINNT && !GCC
633 chmod +x $@
634 ifdef ENABLE_STRIP
635 $(STRIP) $(STRIP_FLAGS) $@
636 endif
638 # The object file is in the current directory, and the source file can be any
639 # relative path. This macro adds the dependency obj: src for each source file.
640 # This dependency must be first for the $< flag to work correctly, and the
641 # rules that have commands for these targets must not list any other
642 # prerequisites, or they will override the $< variable.
643 define src_objdep
644 $(basename $3$(notdir $1)).$2: $1 $$(call mkdir_deps,$$(MDDEPDIR))
645 endef
646 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX))))
647 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS) $(HOST_CMSRCS) $(HOST_CMMSRCS),$(eval $(call src_objdep,$(f),$(_OBJ_SUFFIX),host_)))
648 $(foreach f,$(WASM_CSRCS) $(WASM_CPPSRCS),$(eval $(call src_objdep,$(f),wasm)))
650 # The Rust compiler only outputs library objects, and so we need different
651 # mangling to generate dependency rules for it.
652 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
653 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
654 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
656 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
658 # Rules for building native targets must come first because of the host_ prefix
659 $(HOST_COBJS):
660 $(REPORT_BUILD_VERBOSE)
661 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $<
663 $(HOST_CPPOBJS):
664 $(REPORT_BUILD_VERBOSE)
665 $(call BUILDSTATUS,OBJECT_FILE $@)
666 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $<
668 $(HOST_CMOBJS):
669 $(REPORT_BUILD_VERBOSE)
670 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(HOST_CMFLAGS) $(NSPR_CFLAGS) $<
672 $(HOST_CMMOBJS):
673 $(REPORT_BUILD_VERBOSE)
674 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(HOST_CMMFLAGS) $(NSPR_CFLAGS) $<
676 $(COBJS):
677 $(REPORT_BUILD_VERBOSE)
678 $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
680 $(CWASMOBJS):
681 $(REPORT_BUILD_VERBOSE)
682 $(WASM_CC) $(OUTOPTION)$@ -c $(WASM_CFLAGS) $($(notdir $<)_FLAGS) $<
684 ifdef ASFILES
685 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
686 # a '-c' flag.
687 $(ASOBJS):
688 $(REPORT_BUILD_VERBOSE)
689 $(AS) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $<
690 endif
692 define syms_template
693 syms:: $(2)
694 $(2): $(1)
695 ifdef MOZ_CRASHREPORTER
696 $$(call py_action,dumpsymbols,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
697 endif
698 endef
700 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
701 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
702 endif
704 ifdef MOZ_AUTOMATION
705 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
706 DUMP_SYMS_TARGETS :=
707 endif
708 endif
710 ifdef MOZ_COPY_PDBS
711 MAIN_PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
712 MAIN_PDB_DEST ?= $(FINAL_TARGET)
713 MAIN_PDB_TARGET = syms
714 INSTALL_TARGETS += MAIN_PDB
716 ifdef CPP_UNIT_TESTS
717 CPP_UNIT_TESTS_PDB_FILES = $(addsuffix .pdb,$(basename $(CPP_UNIT_TESTS)))
718 CPP_UNIT_TESTS_PDB_DEST = $(DIST)/cppunittests
719 CPP_UNIT_TESTS_PDB_TARGET = syms
720 INSTALL_TARGETS += CPP_UNIT_TESTS_PDB
721 endif
723 else ifdef MOZ_CRASHREPORTER
724 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
725 endif
727 ifneq (,$(RUST_TESTS)$(RUST_LIBRARY_FILE)$(HOST_RUST_LIBRARY_FILE)$(RUST_PROGRAMS)$(HOST_RUST_PROGRAMS))
728 include $(MOZILLA_DIR)/config/makefiles/rust.mk
729 endif
731 $(SOBJS):
732 $(REPORT_BUILD)
733 $(AS) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $<
735 $(CPPOBJS):
736 $(REPORT_BUILD_VERBOSE)
737 $(call BUILDSTATUS,OBJECT_FILE $@)
738 $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
740 $(CPPWASMOBJS):
741 $(REPORT_BUILD_VERBOSE)
742 $(call BUILDSTATUS,OBJECT_FILE $@)
743 $(WASM_CXX) $(OUTOPTION)$@ -c $(WASM_CXXFLAGS) $($(notdir $<)_FLAGS) $<
745 $(CMMOBJS):
746 $(REPORT_BUILD_VERBOSE)
747 $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $<
749 $(CMOBJS):
750 $(REPORT_BUILD_VERBOSE)
751 $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $<
753 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
754 $(REPORT_BUILD_VERBOSE)
755 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
757 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
758 $(REPORT_BUILD_VERBOSE)
759 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
761 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
762 $(REPORT_BUILD_VERBOSE)
763 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
765 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
766 $(REPORT_BUILD_VERBOSE)
767 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
769 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
770 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
771 # of the full sources, as well as the $(notdir) version. So:
772 # foo.cpp sub/bar.cpp
773 # becomes:
774 # foo.cpp sub/bar.cpp bar.cpp
776 # This way we can match both 'make sub/bar.i' and 'make bar.i'
777 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
779 define PREPROCESS_RULES
780 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
781 # Make preprocessed files PHONY so they are always executed, since they are
782 # manual targets and we don't necessarily write to $@.
783 .PHONY: $$(_PREPROCESSED_$1_FILES)
785 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
786 # reach $(srcdir)/frontend/Parser.i
787 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
788 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
790 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
791 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
792 $$(REPORT_BUILD_VERBOSE)
793 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
794 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$<
796 endef
798 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
799 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
800 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
801 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
802 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
804 # Default to pre-processing the actual unified file. This can be overridden
805 # at the command-line to pre-process only the individual source file.
806 PP_UNIFIED ?= 1
808 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
809 # infinite loop if the filename doesn't exist in the unified source files.
810 ifndef PP_REINVOKE
812 MATCH_cpp = \(cpp\|cc|cxx\)
813 UPPER_c = C
814 UPPER_cpp = CPP
815 UPPER_mm = CMM
817 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
818 # find a matching pathname.
819 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
820 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
821 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
822 all_c_sources := $(call _get_all_sources,$(CSRCS))
823 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
825 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
826 # one of the *SRCS variables. The two code paths depend on whether or not
827 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
829 # PP_UNIFIED=1:
830 # - Look for it in any of the Unified files, and re-exec make with
831 # Unified_foo0.i as the target. This gets us the full unified preprocessed
832 # file.
834 # PP_UNIFIED=0:
835 # - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
836 # make with that filename as the target. The *SRCS variables are modified
837 # to have the Unified sources appended to them so that the static pattern
838 # rules will match.
839 %.i: FORCE
840 ifeq ($(PP_UNIFIED),1)
841 @$(MAKE) PP_REINVOKE=1 \
842 $(or $(addsuffix .i, \
843 $(foreach type,c cpp mm, \
844 $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
845 $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
846 ))),$(error "File not found for preprocessing: $@"))
847 else
848 @$(MAKE) PP_REINVOKE=1 $@ \
849 $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
850 endif
852 endif
854 endif
856 $(RESFILE): %.res: $(RCFILE)
857 $(REPORT_BUILD)
858 @echo Creating Resource file: $@
859 ifdef GNU_CC
860 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) $(OUTOPTION)$@ $<
861 else
862 $(RC) $(RCFLAGS) -r $(DEFINES) $(INCLUDES) $(OUTOPTION)$@ $<
863 endif
865 # Cancel GNU make built-in implicit rules
866 MAKEFLAGS += -r
868 ifneq (,$(filter WINNT,$(OS_ARCH)))
869 SEP := ;
870 else
871 SEP := :
872 endif
874 EMPTY :=
875 SPACE := $(EMPTY) $(EMPTY)
877 ###############################################################################
878 # Bunch of things that extend the 'export' rule (in order):
879 ###############################################################################
881 ifneq ($(XPI_NAME),)
882 $(FINAL_TARGET):
883 $(NSINSTALL) -D $@
885 export:: $(FINAL_TARGET)
886 endif
888 ################################################################################
889 # The default location for prefs is the gre prefs directory.
890 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
891 PREF_DIR = defaults/pref
893 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
894 # different and that we are building app related resources. Hence,
895 # PREF_DIR should point to the app prefs location.
896 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
897 PREF_DIR = defaults/preferences
898 endif
900 ################################################################################
901 # CHROME PACKAGING
903 chrome::
904 $(MAKE) realchrome
905 $(LOOP_OVER_DIRS)
907 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
909 ifneq (,$(JAR_MANIFEST))
910 ifndef NO_DIST_INSTALL
912 ifdef XPI_NAME
913 ifdef XPI_ROOT_APPID
914 # For add-on packaging we may specify that an application
915 # sub-dir should be added to the root chrome manifest with
916 # a specific application id.
917 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
918 endif
920 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
921 # no way langpacks will get packaged right, so error out.
922 ifneq (,$(DIST_SUBDIR))
923 ifndef XPI_ROOT_APPID
924 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
925 endif
926 endif
927 endif
929 libs realchrome:: $(FINAL_TARGET)/chrome
930 $(call py_action,jar_maker,\
931 $(QUIET) -d $(FINAL_TARGET) \
932 $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
933 $(JAR_MANIFEST))
935 endif
937 endif
939 # When you move this out of the tools tier, please remove the corresponding
940 # hacks in recursivemake.py that check if Makefile.in sets the variable.
941 ifneq ($(XPI_PKGNAME),)
942 tools realchrome::
943 ifdef STRIP_XPI
944 ifndef MOZ_DEBUG
945 @echo 'Stripping $(XPI_PKGNAME) package directory...'
946 @echo $(FINAL_TARGET)
947 @cd $(FINAL_TARGET) && find . ! -type d \
948 ! -name '*.js' \
949 ! -name '*.xpt' \
950 ! -name '*.gif' \
951 ! -name '*.jpg' \
952 ! -name '*.png' \
953 ! -name '*.xpm' \
954 ! -name '*.txt' \
955 ! -name '*.rdf' \
956 ! -name '*.sh' \
957 ! -name '*.properties' \
958 ! -name '*.dtd' \
959 ! -name '*.html' \
960 ! -name '*.xul' \
961 ! -name '*.css' \
962 ! -name '*.xml' \
963 ! -name '*.jar' \
964 ! -name '*.dat' \
965 ! -name '*.tbl' \
966 ! -name '*.src' \
967 ! -name '*.reg' \
968 $(PLATFORM_EXCLUDE_LIST) \
969 -exec $(STRIP) $(STRIP_FLAGS) {} >/dev/null 2>&1 \;
970 endif
971 endif
972 @echo 'Packaging $(XPI_PKGNAME).xpi...'
973 $(call py_action,zip,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
974 endif
976 # See comment above about moving this out of the tools tier.
977 ifdef INSTALL_EXTENSION_ID
978 ifndef XPI_NAME
979 $(error XPI_NAME must be set for INSTALL_EXTENSION_ID)
980 endif
982 tools::
983 $(RM) -r '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
984 $(NSINSTALL) -D '$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID)'
985 $(call copy_dir,$(FINAL_TARGET),$(DIST)/bin/distribution$(DIST_SUBDIR:%=/%)/extensions/$(INSTALL_EXTENSION_ID))
987 endif
989 #############################################################################
990 # MDDEPDIR is the subdirectory where all the dependency files are placed.
991 # This uses a make rule (instead of a macro) to support parallel
992 # builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
993 # processes could simultaneously try to create the same directory.
995 # We use $(CURDIR) in the rule's target to ensure that we don't find
996 # a dependency directory in the source tree via VPATH (perhaps from
997 # a previous build in the source tree) and thus neglect to create a
998 # dependency directory in the object directory, where we really need
999 # it.
1001 _MDDEPEND_FILES :=
1003 ifneq (,$(filter target-objects target all default,$(MAKECMDGOALS)))
1004 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS))))
1005 endif
1007 ifneq (,$(filter host-objects host all default,$(MAKECMDGOALS)))
1008 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(HOST_OBJS) $(HOST_PROGOBJS))))
1009 endif
1011 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(_MDDEPEND_FILES))))
1012 MDDEPEND_FILES += $(EXTRA_MDDEPEND_FILES)
1014 ifneq (,$(MDDEPEND_FILES))
1015 -include $(MDDEPEND_FILES)
1016 endif
1018 ################################################################################
1019 # Install/copy rules
1021 # The INSTALL_TARGETS variable contains a list of all install target
1022 # categories. Each category defines a list of files and executables, and an
1023 # install destination,
1025 # FOO_FILES := foo bar
1026 # FOO_EXECUTABLES := baz
1027 # FOO_DEST := target_path
1028 # INSTALL_TARGETS += FOO
1030 # Additionally, a FOO_TARGET variable may be added to indicate the target for
1031 # which the files and executables are installed. Default is "libs".
1033 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
1034 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
1035 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
1036 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
1038 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
1039 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
1040 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
1041 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
1043 define install_cmd_override
1044 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
1045 endef
1046 endif
1047 endif
1049 install_target_tier = $(or $($(1)_TARGET),libs)
1050 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
1052 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
1053 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
1054 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
1056 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
1057 # See details in bug 934864.
1058 define create_dependency
1059 $(1): $(2)
1060 $(1): $(2)
1061 endef
1063 define install_target_template
1064 $(call install_cmd_override,$(2))
1065 $(call create_dependency,$(2),$(1))
1066 endef
1068 $(foreach category,$(INSTALL_TARGETS),\
1069 $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
1070 $(foreach tier,$(call install_target_tier,$(category)),\
1071 $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
1072 $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
1074 $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
1075 $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
1079 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
1080 $(eval $(tier):: $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
1083 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
1085 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
1086 $(install_targets_sanity)
1087 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
1089 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
1090 $(install_targets_sanity)
1091 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
1093 ################################################################################
1094 # Preprocessing rules
1096 # The PP_TARGETS variable contains a list of all preprocessing target
1097 # categories. Each category has associated variables listing input files, the
1098 # output directory, extra preprocessor flags, and so on. For example:
1100 # FOO := input-file
1101 # FOO_PATH := target-directory
1102 # FOO_FLAGS := -Dsome_flag
1103 # PP_TARGETS += FOO
1105 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
1106 # following make variables to see what to do:
1108 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
1109 # We search VPATH for the names given here. If an input file name ends in
1110 # '.in', that suffix is omitted from the output file name.
1112 # - <C>_PATH names the directory in which to place the preprocessed output
1113 # files. We create this directory if it does not already exist. Setting
1114 # this variable is optional; if unset, we install the files in $(CURDIR).
1116 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
1117 # to the usual bunch. Setting this variable is optional.
1119 # - <C>_TARGET names the 'make' target that should depend on creating the output
1120 # files. Setting this variable is optional; if unset, we preprocess the
1121 # files for the 'libs' target.
1123 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
1124 # kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
1125 # $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
1126 # instead of $(DIST)/include/qux.h.
1128 pp_target_tier = $(or $($(1)_TARGET),libs)
1129 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
1131 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
1132 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
1134 $(foreach category,$(PP_TARGETS), \
1135 $(foreach tier,$(call pp_target_tier,$(category)), \
1136 $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
1138 $(foreach file,$($(category)), \
1139 $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
1140 $(file) $(GLOBAL_DEPS))) \
1142 $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
1145 $(foreach tier,$(PP_TARGETS_TIERS), \
1146 $(eval $(tier):: $(PP_TARGETS_RESULTS_$(tier))) \
1149 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
1150 $(PP_TARGETS_ALL_RESULTS):
1151 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
1152 $(RM) '$@'
1153 $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
1155 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
1157 # The depfile is based on the filename, and we don't want conflicts. So check
1158 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
1159 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
1160 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
1161 $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
1162 $(error Multiple preprocessing rules are creating a $(file) file) \
1166 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
1167 # If the depfile for a preprocessed file doesn't exist, add a dep to force
1168 # re-preprocessing.
1169 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
1170 $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
1172 $(eval $(file): FORCE) \
1176 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
1178 ifneq (,$(MDDEPEND_FILES))
1179 -include $(MDDEPEND_FILES)
1180 endif
1182 endif
1184 # Pull in non-recursive targets if this is a partial tree build.
1185 ifndef TOPLEVEL_BUILD
1186 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
1187 endif
1189 ################################################################################
1190 # Special gmake rules.
1191 ################################################################################
1195 # Re-define the list of default suffixes, so gmake won't have to churn through
1196 # hundreds of built-in suffix rules for stuff we don't need.
1198 .SUFFIXES:
1201 # Fake targets. Always run these rules, even if a file/directory with that
1202 # name already exists.
1204 .PHONY: all alltags boot chrome realchrome clean clobber clobber_all export install libs makefiles realclean run_apprunner tools $(DIRS) FORCE
1206 # Used as a dependency to force targets to rebuild
1207 FORCE:
1209 # Delete target if error occurs when building target
1210 .DELETE_ON_ERROR:
1212 tags: TAGS
1214 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1215 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1216 $(LOOP_OVER_DIRS)
1218 ifndef INCLUDED_DEBUGMAKE_MK #{
1219 ## Only parse when an echo* or show* target is requested
1220 ifneq (,$(call isTargetStem,echo,show))
1221 include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
1222 endif #}
1223 endif #}
1225 documentation:
1226 @cd $(DEPTH)
1227 $(DOXYGEN) $(DEPTH)/config/doxygen.cfg
1229 FREEZE_VARIABLES = \
1230 CSRCS \
1231 CPPSRCS \
1232 EXPORTS \
1233 DIRS \
1234 LIBRARY \
1235 WASM_LIBRARY \
1236 MODULE \
1237 $(NULL)
1239 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
1241 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
1242 $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
1244 libs export::
1245 $(CHECK_FROZEN_VARIABLES)
1247 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
1249 #############################################################################
1250 # Derived targets and dependencies
1252 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
1253 ifneq ($(NULL),$(AUTO_DEPS))
1254 default all libs tools export:: $(AUTO_DEPS)
1255 endif