Bug 1889091 - Part 3: Specialize calls to native functions with variadic parameters...
[gecko.git] / config / rules.mk
blobff721eabd4c6915115634433067612b87cf4c2f5
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,$(TARGET_CPU)-$(OS_TARGET))
147 ifdef PROGRAM
148 MOZ_PROGRAM_LDFLAGS += -Wl,-rpath -Wl,@executable_path/Frameworks
149 endif
150 endif
152 # For Mac executables, set the @rpath to be @executable_path by default so that
153 # shared libraries built with an @rpath install name in the same directory
154 # as the executable can be resolved. Executables not in the same directory
155 # should override the @rpath with a relative path such as @executable_path/../
156 # depending on their install location.
157 ifeq ($(OS_ARCH),Darwin)
158 MOZ_PROGRAM_LDFLAGS += -Wl,-rpath,@executable_path
159 endif
161 ifeq ($(OS_ARCH),WINNT)
162 ifeq ($(CC_TYPE),clang)
163 MOZ_PROGRAM_LDFLAGS += -Wl,-pdb,$(dir $@)/$(LINK_PDBFILE)
164 endif
165 endif
167 ifeq ($(HOST_OS_ARCH),WINNT)
168 HOST_PDBFILE=$(basename $(@F)).pdb
169 HOST_PDB_FLAG ?= -PDB:$(HOST_PDBFILE)
170 HOST_C_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
171 HOST_CXX_LDFLAGS += -DEBUG $(HOST_PDB_FLAG)
172 endif
174 # Don't build SIMPLE_PROGRAMS during the MOZ_PROFILE_GENERATE pass, and do not
175 # attempt to install them
176 ifdef MOZ_PROFILE_GENERATE
177 $(foreach category,$(INSTALL_TARGETS),\
178 $(eval $(category)_FILES := $(foreach file,$($(category)_FILES),$(if $(filter $(SIMPLE_PROGRAMS),$(notdir $(file))),,$(file)))))
179 SIMPLE_PROGRAMS :=
180 endif
182 ifdef COMPILE_ENVIRONMENT
183 ifndef TARGETS
184 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY)
185 endif
187 COBJS = $(notdir $(CSRCS:.c=.$(OBJ_SUFFIX)))
188 CWASMOBJS = $(notdir $(WASM_CSRCS:.c=.$(WASM_OBJ_SUFFIX)))
189 SOBJS = $(notdir $(SSRCS:.S=.$(OBJ_SUFFIX)))
190 # CPPSRCS can have different extensions (eg: .cpp, .cc)
191 CPPOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(CPPSRCS))))
192 CPPWASMOBJS = $(notdir $(addsuffix .$(WASM_OBJ_SUFFIX),$(basename $(WASM_CPPSRCS))))
193 CMOBJS = $(notdir $(CMSRCS:.m=.$(OBJ_SUFFIX)))
194 CMMOBJS = $(notdir $(CMMSRCS:.mm=.$(OBJ_SUFFIX)))
195 # ASFILES can have different extensions (.s, .asm)
196 ASOBJS = $(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(ASFILES))))
197 RS_STATICLIB_CRATE_OBJ = $(addprefix lib,$(notdir $(RS_STATICLIB_CRATE_SRC:.rs=.$(LIB_SUFFIX))))
198 ifndef OBJS
199 _OBJS = $(COBJS) $(SOBJS) $(CPPOBJS) $(CMOBJS) $(CMMOBJS) $(ASOBJS) $(CWASMOBJS) $(CPPWASMOBJS)
200 OBJS = $(strip $(_OBJS))
201 endif
203 HOST_COBJS = $(addprefix host_,$(notdir $(HOST_CSRCS:.c=.$(OBJ_SUFFIX))))
204 # HOST_CPPOBJS can have different extensions (eg: .cpp, .cc)
205 HOST_CPPOBJS = $(addprefix host_,$(notdir $(addsuffix .$(OBJ_SUFFIX),$(basename $(HOST_CPPSRCS)))))
206 HOST_CMOBJS = $(addprefix host_,$(notdir $(HOST_CMSRCS:.m=.$(OBJ_SUFFIX))))
207 HOST_CMMOBJS = $(addprefix host_,$(notdir $(HOST_CMMSRCS:.mm=.$(OBJ_SUFFIX))))
208 ifndef HOST_OBJS
209 _HOST_OBJS = $(HOST_COBJS) $(HOST_CPPOBJS) $(HOST_CMOBJS) $(HOST_CMMOBJS)
210 HOST_OBJS = $(strip $(_HOST_OBJS))
211 endif
212 else
213 LIBRARY :=
214 SHARED_LIBRARY :=
215 IMPORT_LIBRARY :=
216 REAL_LIBRARY :=
217 PROGRAM :=
218 SIMPLE_PROGRAMS :=
219 HOST_SHARED_LIBRARY :=
220 HOST_PROGRAM :=
221 HOST_SIMPLE_PROGRAMS :=
222 endif
224 ifdef MACH
225 ifndef NO_BUILDSTATUS_MESSAGES
226 define BUILDSTATUS
227 @echo 'BUILDSTATUS@$(relativesrcdir) $1'
229 endef
230 endif
231 endif
233 define SUBMAKE # $(call SUBMAKE,target,directory,static)
234 +@$(MAKE) $(if $(2),-C $(2)) $(1)
236 endef # The extra line is important here! don't delete it
238 define TIER_DIR_SUBMAKE
239 $(call SUBMAKE,$(4),$(3),$(5))
241 endef # Ths empty line is important.
243 ifneq (,$(strip $(DIRS)))
244 LOOP_OVER_DIRS = \
245 $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
246 endif
249 # Now we can differentiate between objects used to build a library, and
250 # objects used to build an executable in the same directory.
252 ifndef PROGOBJS
253 PROGOBJS = $(OBJS)
254 endif
256 ifndef HOST_PROGOBJS
257 HOST_PROGOBJS = $(HOST_OBJS)
258 endif
261 # Tags: emacs (etags), vi (ctags)
262 # TAG_PROGRAM := ctags -L -
264 TAG_PROGRAM = xargs etags -a
267 # Turn on C++ linking if we have any .cpp or .mm files
268 # (moved this from config.mk so that config.mk can be included
269 # before the CPPSRCS are defined)
271 ifneq ($(HOST_CPPSRCS)$(HOST_CMMSRCS),)
272 HOST_CPP_PROG_LINK = 1
273 endif
276 # MacOS X specific stuff
279 ifeq ($(OS_ARCH),Darwin)
280 ifneq (,$(SHARED_LIBRARY))
281 _LOADER_PATH := @rpath
282 EXTRA_DSO_LDOPTS += -dynamiclib -install_name $(_LOADER_PATH)/$@ -compatibility_version 1 -current_version 1
283 endif
284 endif
287 # GNU doesn't have path length limitation
290 ifeq ($(OS_ARCH),GNU)
291 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
292 endif
295 # MINGW32
297 ifeq ($(OS_ARCH),WINNT)
298 ifdef GNU_CC
299 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
300 endif
301 endif
303 ifeq ($(USE_TVFS),1)
304 IFLAGS1 = -rb
305 IFLAGS2 = -rb
306 else
307 IFLAGS1 = -m 644
308 IFLAGS2 = -m 755
309 endif
311 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
312 OUTOPTION = -Fo# eol
313 else
314 OUTOPTION = -o # eol
315 endif # WINNT && !GNU_CC
317 ifeq (,$(CROSS_COMPILE))
318 HOST_OUTOPTION = $(OUTOPTION)
319 else
320 # Windows-to-Windows cross compiles should always use MSVC-style options for
321 # host compiles.
322 ifeq (WINNT_WINNT,$(HOST_OS_ARCH)_$(OS_ARCH))
323 ifneq (,$(filter-out clang-cl,$(HOST_CC_TYPE)))
324 $(error MSVC-style compilers should be used for host compilations!)
325 endif
326 HOST_OUTOPTION = -Fo# eol
327 else
328 HOST_OUTOPTION = -o # eol
329 endif
330 endif
331 ################################################################################
333 # Ensure the build config is up to date. This is done automatically when builds
334 # are performed through |mach build|. The check here is to catch people not
335 # using mach. If we ever enforce builds through mach, this code can be removed.
336 ifndef MOZBUILD_BACKEND_CHECKED
337 ifndef MACH
338 ifndef TOPLEVEL_BUILD
339 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
340 $(DEPTH)/backend.%Backend:
341 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
343 define build_backend_rule
344 $(1): $$(shell cat $(1).in)
346 endef
347 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
349 default:: $(BUILD_BACKEND_FILES)
351 export MOZBUILD_BACKEND_CHECKED=1
352 endif
353 endif
354 endif
356 # The root makefile doesn't want to do a plain export/libs, because
357 # of the tiers and because of libxul. Suppress the default rules in favor
358 # of something else. Makefiles which use this var *must* provide a sensible
359 # default rule before including rules.mk
360 default all::
361 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
363 ifdef BUILD_VERBOSE_LOG
364 ECHO := echo
365 QUIET :=
366 else
367 ECHO := true
368 QUIET := -q
369 endif
371 # Dependencies which, if modified, should cause everything to rebuild
372 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
374 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
375 # We always build .res files for programs and shared libraries
376 resfile = $(notdir $1).res
377 # We also build .res files for simple programs if a corresponding manifest
378 # exists. We'll generate a .rc file that includes the manifest.
379 resfile_for_manifest = $(if $(wildcard $(srcdir)/$(notdir $1).manifest),$(call resfile,$1))
380 else
381 resfile =
382 resfile_for_manifest =
383 endif
385 ##############################################
386 ifdef COMPILE_ENVIRONMENT
387 compile:: host target
389 host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_SHARED_LIBRARY)
391 target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_PROGRAMS))
393 ifndef LIBRARY
394 ifdef OBJS
395 target:: $(OBJS)
396 endif
397 endif
399 target-objects: $(OBJS) $(PROGOBJS) $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(RUST_LIBRARY_FILE))
400 host-objects: $(HOST_OBJS) $(HOST_PROGOBJS) $(HOST_RUST_LIBRARY_FILE)
402 syms::
404 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
405 endif
407 alltags:
408 $(RM) TAGS
409 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
411 define EXPAND_CC_OR_CXX
412 $(if $(PROG_IS_C_ONLY_$(notdir $(1))),$(CC),$(CCC))
413 endef
416 # PROGRAM = Foo
417 # creates OBJS, links with LIBS to create Foo
419 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile,$(PROGRAM)) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
420 $(REPORT_BUILD)
421 $(call BUILDSTATUS,START_Program $(@F))
422 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
423 $(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)
424 else # !WINNT || GNU_CC
425 $(call EXPAND_CC_OR_CXX,$@) -o $@ $(COMPUTED_CXX_LDFLAGS) $($(notdir $@)_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
426 $(call py_action,check_binary $(@F),$@)
427 endif # WINNT && !GNU_CC
429 ifdef ENABLE_STRIP
430 $(STRIP) $(STRIP_FLAGS) $@
431 endif
432 ifdef MOZ_POST_PROGRAM_COMMAND
433 $(MOZ_POST_PROGRAM_COMMAND) $@
434 endif
435 $(call BUILDSTATUS,END_Program $(@F))
437 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
438 $(REPORT_BUILD)
439 $(call BUILDSTATUS,START_Program $(@F))
440 ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
441 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
442 else
443 ifeq ($(HOST_CPP_PROG_LINK),1)
444 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
445 else
446 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
447 endif # HOST_CPP_PROG_LINK
448 endif
449 $(call BUILDSTATUS,END_Program $(@F))
452 # This is an attempt to support generation of multiple binaries
453 # in one directory, it assumes everything to compile Foo is in
454 # Foo.o (from either Foo.c or Foo.cpp).
456 # SIMPLE_PROGRAMS = Foo Bar
457 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
459 define simple_program_deps
460 $1: $(1:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) $(STATIC_LIBS) $(EXTRA_DEPS) $(call resfile_for_manifest,$1) $(GLOBAL_DEPS)
461 endef
462 $(foreach p,$(SIMPLE_PROGRAMS),$(eval $(call simple_program_deps,$(p))))
464 $(SIMPLE_PROGRAMS):
465 $(REPORT_BUILD)
466 $(call BUILDSTATUS,START_Program $(@F))
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) -o $@ $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(MOZ_PROGRAM_LDFLAGS) $(SHARED_LIBS) $(OS_LIBS)
471 $(call py_action,check_binary $(@F),$@)
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
480 $(call BUILDSTATUS,END_Program $(@F))
482 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
483 $(REPORT_BUILD)
484 $(call BUILDSTATUS,START_Program $(@F))
485 ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
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 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
489 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
490 else
491 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
492 endif
493 endif
494 $(call BUILDSTATUS,END_Program $(@F))
496 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
497 $(REPORT_BUILD)
498 $(call BUILDSTATUS,START_StaticLib $@)
499 $(RM) $(REAL_LIBRARY)
500 $(AR) $(AR_FLAGS) $($@_OBJS)
501 $(call BUILDSTATUS,END_StaticLib $@)
503 $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
504 $(REPORT_BUILD_VERBOSE)
505 $(call BUILDSTATUS,START_WasmLib $@)
506 $(RM) $(WASM_ARCHIVE)
507 $(WASM_CXX) -o $@ -Wl,--export-all -Wl,--stack-first -Wl,-z,stack-size=$(if $(MOZ_OPTIMIZE),262144,1048576) -Wl,--no-entry -Wl,--import-memory -Wl,--import-table $(CWASMOBJS) $(CPPWASMOBJS) $(addprefix -l,$(WASM_LIBS))
508 $(call BUILDSTATUS,END_WasmLib $@)
510 ifeq ($(OS_ARCH),WINNT)
511 # Import libraries are created by the rules creating shared libraries.
512 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
513 # but make will happily consider the import library before it is refreshed
514 # when rebuilding the corresponding shared library. Defining an empty recipe
515 # for import libraries forces make to wait for the shared library recipe to
516 # have run before considering other targets that depend on the import library.
517 # See bug 795204.
518 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
519 endif
521 $(HOST_SHARED_LIBRARY): Makefile
522 $(REPORT_BUILD)
523 $(call BUILDSTATUS,START_SharedLib $@)
524 $(RM) $@
525 ifneq (,$(filter clang-cl,$(HOST_CC_TYPE)))
526 $(HOST_LINKER) -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
527 else
528 $(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
529 endif
530 $(call BUILDSTATUS,END_SharedLib $@)
532 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
533 # so instead of deleting .o files after repacking them into a dylib, we make
534 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
535 # so no need to conditionalize on OS version or debugging format.
537 $(SHARED_LIBRARY): $(OBJS) $(call resfile,$(SHARED_LIBRARY)) $(STATIC_LIBS) $(EXTRA_DEPS) $(GLOBAL_DEPS)
538 $(REPORT_BUILD)
539 $(call BUILDSTATUS,START_SharedLib $@)
540 $(RM) $@
541 $(MKSHLIB) $($@_OBJS) $(filter %.res,$^) $(RELRHACK_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
542 $(call py_action,check_binary,$@)
544 ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
545 endif # WINNT && !GCC
546 chmod +x $@
547 ifdef ENABLE_STRIP
548 $(STRIP) $(STRIP_FLAGS) $@
549 endif
550 $(call BUILDSTATUS,END_SharedLib $@)
552 # The object file is in the current directory, and the source file can be any
553 # relative path. This macro adds the dependency obj: src for each source file.
554 # This dependency must be first for the $< flag to work correctly, and the
555 # rules that have commands for these targets must not list any other
556 # prerequisites, or they will override the $< variable.
557 define src_objdep
558 $(basename $3$(notdir $1)).$2: $1 $$(call mkdir_deps,$$(MDDEPDIR))
559 endef
560 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX))))
561 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS) $(HOST_CMSRCS) $(HOST_CMMSRCS),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX),host_)))
562 $(foreach f,$(WASM_CSRCS) $(WASM_CPPSRCS),$(eval $(call src_objdep,$(f),wasm)))
564 # The Rust compiler only outputs library objects, and so we need different
565 # mangling to generate dependency rules for it.
566 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
567 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
568 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
570 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
572 # Rules for building native targets must come first because of the host_ prefix
573 $(HOST_COBJS):
574 $(REPORT_BUILD_VERBOSE)
575 $(call BUILDSTATUS,OBJECT_FILE $@)
576 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $<
577 $(call BUILDSTATUS,END_Object $@)
579 $(HOST_CPPOBJS):
580 $(REPORT_BUILD_VERBOSE)
581 $(call BUILDSTATUS,OBJECT_FILE $@)
582 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $<
583 $(call BUILDSTATUS,END_Object $@)
585 $(HOST_CMOBJS):
586 $(REPORT_BUILD_VERBOSE)
587 $(call BUILDSTATUS,OBJECT_FILE $@)
588 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(HOST_CMFLAGS) $(NSPR_CFLAGS) $<
589 $(call BUILDSTATUS,END_Object $@)
591 $(HOST_CMMOBJS):
592 $(REPORT_BUILD_VERBOSE)
593 $(call BUILDSTATUS,OBJECT_FILE $@)
594 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(HOST_CMMFLAGS) $(NSPR_CFLAGS) $<
595 $(call BUILDSTATUS,END_Object $@)
597 $(COBJS):
598 $(REPORT_BUILD_VERBOSE)
599 $(call BUILDSTATUS,OBJECT_FILE $@)
600 $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
601 $(call BUILDSTATUS,END_Object $@)
603 $(CWASMOBJS):
604 $(REPORT_BUILD_VERBOSE)
605 $(call BUILDSTATUS,OBJECT_FILE $@)
606 $(WASM_CC) -o $@ -c $(WASM_CFLAGS) $($(notdir $<)_FLAGS) $<
607 $(call BUILDSTATUS,END_Object $@)
609 WINEWRAP = $(if $(and $(filter %.exe,$1),$(WINE)),$(WINE) $1,$1)
611 # Windows program run via Wine don't like Unix absolute paths (they look
612 # like command line arguments). So when needed, create relative paths
613 # from absolute paths. We start with $(DEPTH), which gets us to topobjdir,
614 # then add "/.." for each component of topobjdir, which gets us to /.
615 # then we can add the absolute path after that and we have a relative path,
616 # albeit longer than it could be.
617 ifdef WINE
618 relativize = $(if $(filter /%,$1),$(DEPTH)$(subst $(space),,$(foreach d,$(subst /, ,$(topobjdir)),/..))$1,$1)
619 else
620 relativize = $1
621 endif
623 ifdef WINE
624 # asmarm64 needs a library that can be found in $PATH but for some reason,
625 # wine wants its path in $WINEPATH, so fill that to make it happy.
626 $(ASOBJS) $(SOBJS): export WINEPATH=$(subst :,;,$(PATH))
627 endif
629 ifdef ASFILES
630 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
631 # a '-c' flag.
632 $(ASOBJS):
633 $(REPORT_BUILD_VERBOSE)
634 $(call BUILDSTATUS,OBJECT_FILE $@)
635 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $(call relativize,$<)
636 $(call BUILDSTATUS,END_Object $@)
637 endif
639 define syms_template
640 $(2): $(1)
641 ifdef MOZ_CRASHREPORTER
642 $$(call py_action,dumpsymbols $$@,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
643 ifeq ($(OS_ARCH),WINNT)
644 ifdef WINCHECKSEC
645 $$(PYTHON3) $$(topsrcdir)/build/win32/autowinchecksec.py $$<
646 endif # WINCHECKSEC
647 endif # WINNT
648 endif
649 endef
651 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
652 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
653 endif
655 ifdef MOZ_AUTOMATION
656 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
657 DUMP_SYMS_TARGETS :=
658 endif
659 endif
661 ifdef MOZ_COPY_PDBS
662 MAIN_PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
663 MAIN_PDB_DEST ?= $(FINAL_TARGET)
664 MAIN_PDB_TARGET = syms
665 INSTALL_TARGETS += MAIN_PDB
667 ifdef CPP_UNIT_TESTS
668 CPP_UNIT_TESTS_PDB_FILES = $(addsuffix .pdb,$(basename $(CPP_UNIT_TESTS)))
669 CPP_UNIT_TESTS_PDB_DEST = $(DIST)/cppunittests
670 CPP_UNIT_TESTS_PDB_TARGET = syms
671 INSTALL_TARGETS += CPP_UNIT_TESTS_PDB
672 endif
674 else ifdef MOZ_CRASHREPORTER
675 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
676 syms:: $(foreach file,$(DUMP_SYMS_TARGETS),$(notdir $(file))_syms.track)
677 endif
679 ifneq (,$(RUST_TESTS)$(RUST_LIBRARY_FILE)$(HOST_RUST_LIBRARY_FILE)$(RUST_PROGRAMS)$(HOST_RUST_PROGRAMS))
680 include $(MOZILLA_DIR)/config/makefiles/rust.mk
681 endif
683 $(SOBJS):
684 $(REPORT_BUILD)
685 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $(call relativize,$<)
687 $(CPPOBJS):
688 $(REPORT_BUILD_VERBOSE)
689 $(call BUILDSTATUS,OBJECT_FILE $@)
690 $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
691 $(call BUILDSTATUS,END_Object $@)
693 $(CPPWASMOBJS):
694 $(REPORT_BUILD_VERBOSE)
695 $(call BUILDSTATUS,OBJECT_FILE $@)
696 $(WASM_CXX) -o $@ -c $(WASM_CXXFLAGS) $($(notdir $<)_FLAGS) $<
697 $(call BUILDSTATUS,END_Object $@)
699 $(CMMOBJS):
700 $(REPORT_BUILD_VERBOSE)
701 $(call BUILDSTATUS,OBJECT_FILE $@)
702 $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $<
703 $(call BUILDSTATUS,END_Object $@)
705 $(CMOBJS):
706 $(REPORT_BUILD_VERBOSE)
707 $(call BUILDSTATUS,OBJECT_FILE $@)
708 $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $<
709 $(call BUILDSTATUS,END_Object $@)
711 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
712 $(REPORT_BUILD_VERBOSE)
713 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
715 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
716 $(REPORT_BUILD_VERBOSE)
717 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
719 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
720 $(REPORT_BUILD_VERBOSE)
721 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
723 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
724 $(REPORT_BUILD_VERBOSE)
725 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
727 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
728 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
729 # of the full sources, as well as the $(notdir) version. So:
730 # foo.cpp sub/bar.cpp
731 # becomes:
732 # foo.cpp sub/bar.cpp bar.cpp
734 # This way we can match both 'make sub/bar.i' and 'make bar.i'
735 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
737 define PREPROCESS_RULES
738 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
739 # Make preprocessed files PHONY so they are always executed, since they are
740 # manual targets and we don't necessarily write to $@.
741 .PHONY: $$(_PREPROCESSED_$1_FILES)
743 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
744 # reach $(srcdir)/frontend/Parser.i
745 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
746 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
748 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
749 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
750 $$(REPORT_BUILD_VERBOSE)
751 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
752 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$<
754 endef
756 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
757 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
758 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
759 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
760 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
762 # Default to pre-processing the actual unified file. This can be overridden
763 # at the command-line to pre-process only the individual source file.
764 PP_UNIFIED ?= 1
766 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
767 # infinite loop if the filename doesn't exist in the unified source files.
768 ifndef PP_REINVOKE
770 MATCH_cpp = \(cpp\|cc|cxx\)
771 UPPER_c = C
772 UPPER_cpp = CPP
773 UPPER_mm = CMM
775 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
776 # find a matching pathname.
777 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
778 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
779 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
780 all_c_sources := $(call _get_all_sources,$(CSRCS))
781 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
783 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
784 # one of the *SRCS variables. The two code paths depend on whether or not
785 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
787 # PP_UNIFIED=1:
788 # - Look for it in any of the Unified files, and re-exec make with
789 # Unified_foo0.i as the target. This gets us the full unified preprocessed
790 # file.
792 # PP_UNIFIED=0:
793 # - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
794 # make with that filename as the target. The *SRCS variables are modified
795 # to have the Unified sources appended to them so that the static pattern
796 # rules will match.
797 %.i: FORCE
798 ifeq ($(PP_UNIFIED),1)
799 @$(MAKE) PP_REINVOKE=1 \
800 $(or $(addsuffix .i, \
801 $(foreach type,c cpp mm, \
802 $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
803 $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
804 ))),$(error "File not found for preprocessing: $@"))
805 else
806 @$(MAKE) PP_REINVOKE=1 $@ \
807 $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
808 endif
810 endif
812 endif
814 # EXTRA_DEPS contains manifests (manually added in Makefile.in ; bug 1498414)
815 %.res: $(or $(RCFILE),%.rc) $(MOZILLA_DIR)/config/create_res.py $(EXTRA_DEPS)
816 $(REPORT_BUILD)
817 $(call BUILDSTATUS,START_Res $@)
818 $(PYTHON3) $(MOZILLA_DIR)/config/create_res.py $(DEFINES) $(INCLUDES) -o $@ $<
819 $(call BUILDSTATUS,END_Res $@)
821 $(notdir $(addsuffix .rc,$(PROGRAM) $(SHARED_LIBRARY) $(SIMPLE_PROGRAMS) module)): %.rc: $(RCINCLUDE) $(MOZILLA_DIR)/config/create_rc.py
822 $(call BUILDSTATUS,START_Rc $@)
823 $(PYTHON3) $(MOZILLA_DIR)/config/create_rc.py '$(if $(filter module,$*),,$*)' '$(RCINCLUDE)'
824 $(call BUILDSTATUS,END_Rc $@)
826 # Cancel GNU make built-in implicit rules
827 MAKEFLAGS += -r
829 ifneq (,$(filter WINNT,$(OS_ARCH)))
830 SEP := ;
831 else
832 SEP := :
833 endif
835 EMPTY :=
836 SPACE := $(EMPTY) $(EMPTY)
838 ###############################################################################
839 # Bunch of things that extend the 'export' rule (in order):
840 ###############################################################################
842 ifneq ($(XPI_NAME),)
843 $(FINAL_TARGET):
844 $(NSINSTALL) -D $@
846 export:: $(FINAL_TARGET)
847 endif
849 ################################################################################
850 # The default location for prefs is the gre prefs directory.
851 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
852 PREF_DIR = defaults/pref
854 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
855 # different and that we are building app related resources. Hence,
856 # PREF_DIR should point to the app prefs location.
857 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
858 PREF_DIR = defaults/preferences
859 endif
861 ################################################################################
862 # CHROME PACKAGING
864 chrome::
865 $(MAKE) realchrome
866 $(LOOP_OVER_DIRS)
868 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
870 ifneq (,$(JAR_MANIFEST))
871 ifndef NO_DIST_INSTALL
873 ifdef XPI_NAME
874 ifdef XPI_ROOT_APPID
875 # For add-on packaging we may specify that an application
876 # sub-dir should be added to the root chrome manifest with
877 # a specific application id.
878 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
879 endif
881 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
882 # no way langpacks will get packaged right, so error out.
883 ifneq (,$(DIST_SUBDIR))
884 ifndef XPI_ROOT_APPID
885 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
886 endif
887 endif
888 endif
890 misc realchrome:: $(FINAL_TARGET)/chrome
891 $(call py_action,jar_maker $(subst $(topsrcdir)/,,$(JAR_MANIFEST)),\
892 $(QUIET) -d $(FINAL_TARGET) \
893 $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
894 $(JAR_MANIFEST))
896 ifdef AB_CD
897 .PHONY: l10n
898 l10n: misc ;
899 endif
900 endif
902 endif
904 # When you move this out of the tools tier, please remove the corresponding
905 # hacks in recursivemake.py that check if Makefile.in sets the variable.
906 ifneq ($(XPI_PKGNAME),)
907 tools realchrome::
908 @echo 'Packaging $(XPI_PKGNAME).xpi...'
909 $(call py_action,zip $(XPI_PKGNAME).xpi,-C $(FINAL_TARGET) ../$(XPI_PKGNAME).xpi '*')
910 endif
912 #############################################################################
913 # MDDEPDIR is the subdirectory where all the dependency files are placed.
914 # This uses a make rule (instead of a macro) to support parallel
915 # builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
916 # processes could simultaneously try to create the same directory.
918 # We use $(CURDIR) in the rule's target to ensure that we don't find
919 # a dependency directory in the source tree via VPATH (perhaps from
920 # a previous build in the source tree) and thus neglect to create a
921 # dependency directory in the object directory, where we really need
922 # it.
924 _MDDEPEND_FILES :=
926 ifneq (,$(filter target-objects target all default,$(MAKECMDGOALS)))
927 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS))))
928 endif
930 ifneq (,$(filter host-objects host all default,$(MAKECMDGOALS)))
931 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(HOST_OBJS) $(HOST_PROGOBJS))))
932 endif
934 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(_MDDEPEND_FILES))))
935 MDDEPEND_FILES += $(EXTRA_MDDEPEND_FILES)
937 ifneq (,$(MDDEPEND_FILES))
938 -include $(MDDEPEND_FILES)
939 endif
941 ################################################################################
942 # Install/copy rules
944 # The INSTALL_TARGETS variable contains a list of all install target
945 # categories. Each category defines a list of files and executables, and an
946 # install destination,
948 # FOO_FILES := foo bar
949 # FOO_EXECUTABLES := baz
950 # FOO_DEST := target_path
951 # INSTALL_TARGETS += FOO
953 # Additionally, a FOO_TARGET variable may be added to indicate the target for
954 # which the files and executables are installed. Default is "libs".
956 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
957 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
958 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
959 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
961 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
962 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
963 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
964 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
966 define install_cmd_override
967 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
968 endef
969 endif
970 endif
972 install_target_tier = $(or $($(1)_TARGET),libs)
973 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
975 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
976 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
977 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
979 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
980 # See details in bug 934864.
981 define create_dependency
982 $(1): $(2)
983 $(1): $(2)
984 endef
986 define install_target_template
987 $(call install_cmd_override,$(2))
988 $(call create_dependency,$(2),$(1))
989 endef
991 $(foreach category,$(INSTALL_TARGETS),\
992 $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
993 $(foreach tier,$(call install_target_tier,$(category)),\
994 $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
995 $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
997 $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
998 $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
1002 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
1003 $(eval $(if $(filter .,$(DEPTH)),recurse_$(tier):,$(tier)::) $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
1006 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
1008 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
1009 $(install_targets_sanity)
1010 $(call BUILDSTATUS,START_Install $@)
1011 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
1012 $(call BUILDSTATUS,END_Install $@)
1014 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
1015 $(install_targets_sanity)
1016 $(call BUILDSTATUS,START_Install $@)
1017 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
1018 $(call BUILDSTATUS,END_Install $@)
1020 ################################################################################
1021 # Preprocessing rules
1023 # The PP_TARGETS variable contains a list of all preprocessing target
1024 # categories. Each category has associated variables listing input files, the
1025 # output directory, extra preprocessor flags, and so on. For example:
1027 # FOO := input-file
1028 # FOO_PATH := target-directory
1029 # FOO_FLAGS := -Dsome_flag
1030 # PP_TARGETS += FOO
1032 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
1033 # following make variables to see what to do:
1035 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
1036 # We search VPATH for the names given here. If an input file name ends in
1037 # '.in', that suffix is omitted from the output file name.
1039 # - <C>_PATH names the directory in which to place the preprocessed output
1040 # files. We create this directory if it does not already exist. Setting
1041 # this variable is optional; if unset, we install the files in $(CURDIR).
1043 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
1044 # to the usual bunch. Setting this variable is optional.
1046 # - <C>_TARGET names the 'make' target that should depend on creating the output
1047 # files. Setting this variable is optional; if unset, we preprocess the
1048 # files for the 'libs' target.
1050 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
1051 # kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
1052 # $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
1053 # instead of $(DIST)/include/qux.h.
1055 pp_target_tier = $(or $($(1)_TARGET),libs)
1056 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
1058 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
1059 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
1061 $(foreach category,$(PP_TARGETS), \
1062 $(foreach tier,$(call pp_target_tier,$(category)), \
1063 $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
1065 $(foreach file,$($(category)), \
1066 $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
1067 $(file) $(GLOBAL_DEPS))) \
1069 $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
1072 $(foreach tier,$(PP_TARGETS_TIERS), \
1073 $(eval $(if $(filter .,$(DEPTH)),recurse_$(tier):,$(tier)::) $(PP_TARGETS_RESULTS_$(tier))) \
1076 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
1077 $(PP_TARGETS_ALL_RESULTS):
1078 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
1079 $(RM) '$@'
1080 $(call py_action,preprocessor $(@F),--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
1082 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
1084 # The depfile is based on the filename, and we don't want conflicts. So check
1085 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
1086 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
1087 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
1088 $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
1089 $(error Multiple preprocessing rules are creating a $(file) file) \
1093 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
1094 # If the depfile for a preprocessed file doesn't exist, add a dep to force
1095 # re-preprocessing.
1096 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
1097 $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
1099 $(eval $(file): FORCE) \
1103 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
1105 ifneq (,$(MDDEPEND_FILES))
1106 -include $(MDDEPEND_FILES)
1107 endif
1109 endif
1111 # Pull in non-recursive targets if this is a partial tree build.
1112 ifndef TOPLEVEL_BUILD
1113 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
1114 endif
1116 ################################################################################
1117 # Special gmake rules.
1118 ################################################################################
1122 # Re-define the list of default suffixes, so gmake won't have to churn through
1123 # hundreds of built-in suffix rules for stuff we don't need.
1125 .SUFFIXES:
1128 # Fake targets. Always run these rules, even if a file/directory with that
1129 # name already exists.
1131 .PHONY: all alltags boot chrome realchrome export install libs makefiles run_apprunner tools $(DIRS) FORCE
1133 # Used as a dependency to force targets to rebuild
1134 FORCE:
1136 # Delete target if error occurs when building target
1137 .DELETE_ON_ERROR:
1139 tags: TAGS
1141 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1142 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
1143 $(LOOP_OVER_DIRS)
1145 ifndef INCLUDED_DEBUGMAKE_MK #{
1146 ## Only parse when an echo* or show* target is requested
1147 ifneq (,$(call isTargetStem,echo,show))
1148 include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
1149 endif #}
1150 endif #}
1152 FREEZE_VARIABLES = \
1153 CSRCS \
1154 CPPSRCS \
1155 EXPORTS \
1156 DIRS \
1157 LIBRARY \
1158 MODULE \
1159 $(NULL)
1161 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
1163 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
1164 $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
1166 libs export::
1167 $(CHECK_FROZEN_VARIABLES)
1169 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
1171 #############################################################################
1172 # Derived targets and dependencies
1174 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
1175 ifneq ($(NULL),$(AUTO_DEPS))
1176 default all libs tools export:: $(AUTO_DEPS)
1177 endif