tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rules.mk (40745B)


      1 # -*- makefile -*-
      2 # vim:set ts=8 sw=8 sts=8 noet:
      3 #
      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/.
      7 #
      8 
      9 ifndef topsrcdir
     10 $(error topsrcdir was not set))
     11 endif
     12 
     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
     18 
     19 ifndef INCLUDED_CONFIG_MK
     20 include $(topsrcdir)/config/config.mk
     21 endif
     22 
     23 USE_AUTOTARGETS_MK = 1
     24 include $(MOZILLA_DIR)/config/makefiles/makeutils.mk
     25 
     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 $@))
     31 
     32 ifdef BUILD_VERBOSE_LOG
     33 REPORT_BUILD_VERBOSE = $(REPORT_BUILD)
     34 else
     35 REPORT_BUILD_VERBOSE = $(call BUILDSTATUS,BUILD_VERBOSE $(relativesrcdir))
     36 endif
     37 
     38 endif
     39 
     40 EXEC			= exec
     41 
     42 ################################################################################
     43 # Testing frameworks support
     44 ################################################################################
     45 
     46 testxpcobjdir = $(DEPTH)/_tests/xpcshell
     47 
     48 ifdef ENABLE_TESTS
     49 ifdef CPP_UNIT_TESTS
     50 ifdef COMPILE_ENVIRONMENT
     51 
     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)
     56 
     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
     63 
     64 run-cppunittests::
     65 @$(PYTHON3) $(MOZILLA_DIR)/testing/runcppunittests.py --xre-path=$(DIST)/bin --symbols-path=$(DIST)/crashreporter-symbols $(CPP_UNIT_TESTS)
     66 
     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); \
     73 
     74 endif # COMPILE_ENVIRONMENT
     75 endif # CPP_UNIT_TESTS
     76 endif # ENABLE_TESTS
     77 
     78 
     79 #
     80 # Library rules
     81 #
     82 # If FORCE_STATIC_LIB is set, build a static library.
     83 # Otherwise, build a shared library.
     84 #
     85 
     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
     94 
     95 ifdef FORCE_SHARED_LIB
     96 ifdef MKSHLIB
     97 
     98 ifdef LIB_IS_C_ONLY
     99 MKSHLIB			= $(MKCSHLIB)
    100 endif
    101 
    102 endif # MKSHLIB
    103 endif # FORCE_SHARED_LIB
    104 
    105 ifeq ($(OS_ARCH),WINNT)
    106 
    107 #
    108 # This next line captures both the default (non-MOZ_COPY_PDBS)
    109 # case as well as the MOZ_COPY_PDBS-for-mingwclang case.
    110 #
    111 # For the default case, placing the pdb in the build
    112 # directory is needed.
    113 #
    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.)
    117 #
    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.
    122 #
    123 LINK_PDBFILE ?= $(basename $(@F)).pdb
    124 
    125 ifdef MOZ_COPY_PDBS
    126 ifneq ($(CC_TYPE),clang)
    127 LINK_PDBFILE = $(basename $@).pdb
    128 endif
    129 endif
    130 
    131 ifeq ($(CC_TYPE),clang-cl)
    132 
    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
    138 
    139 ifdef MOZ_DEBUG
    140 CODFILE=$(basename $(@F)).cod
    141 endif
    142 
    143 endif # CC_TYPE == clang-cl
    144 endif # WINNT
    145 
    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
    151 
    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
    160 
    161 ifeq ($(OS_ARCH),WINNT)
    162 ifeq ($(CC_TYPE),clang)
    163 MOZ_PROGRAM_LDFLAGS += -Wl,-pdb,$(dir $@)/$(LINK_PDBFILE)
    164 endif
    165 endif
    166 
    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
    173 
    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
    181 
    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
    186 
    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
    202 
    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 ifndef HOST_OBJS
    207 _HOST_OBJS = $(HOST_COBJS) $(HOST_CPPOBJS)
    208 HOST_OBJS = $(strip $(_HOST_OBJS))
    209 endif
    210 else
    211 LIBRARY :=
    212 SHARED_LIBRARY :=
    213 IMPORT_LIBRARY :=
    214 REAL_LIBRARY :=
    215 PROGRAM :=
    216 SIMPLE_PROGRAMS :=
    217 HOST_SHARED_LIBRARY :=
    218 HOST_PROGRAM :=
    219 HOST_SIMPLE_PROGRAMS :=
    220 endif
    221 
    222 ifdef MACH
    223 ifndef NO_BUILDSTATUS_MESSAGES
    224 define BUILDSTATUS
    225 @echo 'BUILDSTATUS@$(relativesrcdir) $1'
    226 
    227 endef
    228 endif
    229 endif
    230 
    231 define SUBMAKE # $(call SUBMAKE,target,directory,static)
    232 +@$(MAKE) $(if $(2),-C $(2)) $(1)
    233 
    234 endef # The extra line is important here! don't delete it
    235 
    236 define TIER_DIR_SUBMAKE
    237 $(call SUBMAKE,$(4),$(3),$(5))
    238 
    239 endef # Ths empty line is important.
    240 
    241 ifneq (,$(strip $(DIRS)))
    242 LOOP_OVER_DIRS = \
    243  $(foreach dir,$(DIRS),$(call SUBMAKE,$@,$(dir)))
    244 endif
    245 
    246 #
    247 # Now we can differentiate between objects used to build a library, and
    248 # objects used to build an executable in the same directory.
    249 #
    250 ifndef PROGOBJS
    251 PROGOBJS		= $(OBJS)
    252 endif
    253 
    254 ifndef HOST_PROGOBJS
    255 HOST_PROGOBJS		= $(HOST_OBJS)
    256 endif
    257 
    258 #
    259 # Tags: emacs (etags), vi (ctags)
    260 # TAG_PROGRAM := ctags -L -
    261 #
    262 TAG_PROGRAM		= xargs etags -a
    263 
    264 #
    265 # Turn on C++ linking if we have any .cpp or .mm files
    266 # (moved this from config.mk so that config.mk can be included
    267 #  before the CPPSRCS are defined)
    268 #
    269 ifneq ($(HOST_CPPSRCS),)
    270 HOST_CPP_PROG_LINK	= 1
    271 endif
    272 
    273 #
    274 # MacOS X specific stuff
    275 #
    276 
    277 ifeq ($(OS_ARCH),Darwin)
    278 ifneq (,$(SHARED_LIBRARY))
    279 _LOADER_PATH := @rpath
    280 EXTRA_DSO_LDOPTS	+= -dynamiclib -install_name $(_LOADER_PATH)/$(@F) -compatibility_version 1 -current_version 1
    281 endif
    282 endif
    283 
    284 #
    285 # GNU doesn't have path length limitation
    286 #
    287 
    288 ifeq ($(OS_ARCH),GNU)
    289 OS_CPPFLAGS += -DPATH_MAX=1024 -DMAXPATHLEN=1024
    290 endif
    291 
    292 #
    293 # MINGW32
    294 #
    295 ifeq ($(OS_ARCH),WINNT)
    296 ifneq ($(CC_TYPE),clang-cl)
    297 DSO_LDOPTS += -Wl,--out-implib -Wl,$(IMPORT_LIBRARY)
    298 endif
    299 endif
    300 
    301 ifeq ($(USE_TVFS),1)
    302 IFLAGS1 = -rb
    303 IFLAGS2 = -rb
    304 else
    305 IFLAGS1 = -m 644
    306 IFLAGS2 = -m 755
    307 endif
    308 
    309 ifeq (clang-cl_WINNT,$(CC_TYPE)_$(OS_ARCH))
    310 OUTOPTION = -Fo# eol
    311 else
    312 OUTOPTION = -o # eol
    313 endif # WINNT && clang-cl
    314 
    315 ifeq (,$(CROSS_COMPILE))
    316 HOST_OUTOPTION = $(OUTOPTION)
    317 else
    318 # Windows-to-Windows cross compiles should always use MSVC-style options for
    319 # host compiles.
    320 ifeq (WINNT_WINNT,$(HOST_OS_ARCH)_$(OS_ARCH))
    321 ifneq (,$(filter-out clang-cl,$(HOST_CC_TYPE)))
    322 $(error MSVC-style compilers should be used for host compilations!)
    323 endif
    324 HOST_OUTOPTION = -Fo# eol
    325 else
    326 HOST_OUTOPTION = -o # eol
    327 endif
    328 endif
    329 ################################################################################
    330 
    331 # Ensure the build config is up to date. This is done automatically when builds
    332 # are performed through |mach build|. The check here is to catch people not
    333 # using mach. If we ever enforce builds through mach, this code can be removed.
    334 ifndef MOZBUILD_BACKEND_CHECKED
    335 ifndef MACH
    336 ifndef TOPLEVEL_BUILD
    337 BUILD_BACKEND_FILES := $(addprefix $(DEPTH)/backend.,$(addsuffix Backend,$(BUILD_BACKENDS)))
    338 $(DEPTH)/backend.%Backend:
    339 $(error Build configuration changed. Build with |mach build| or run |mach build-backend| to regenerate build config)
    340 
    341 define build_backend_rule
    342 $(1): $$(shell cat $(1).in)
    343 
    344 endef
    345 $(foreach file,$(BUILD_BACKEND_FILES),$(eval $(call build_backend_rule,$(file))))
    346 
    347 default:: $(BUILD_BACKEND_FILES)
    348 
    349 export MOZBUILD_BACKEND_CHECKED=1
    350 endif
    351 endif
    352 endif
    353 
    354 # The root makefile doesn't want to do a plain export/libs, because
    355 # of the tiers and because of libxul. Suppress the default rules in favor
    356 # of something else. Makefiles which use this var *must* provide a sensible
    357 # default rule before including rules.mk
    358 default all::
    359 $(foreach tier,$(TIERS),$(call SUBMAKE,$(tier)))
    360 
    361 ifdef BUILD_VERBOSE_LOG
    362 ECHO := echo
    363 QUIET :=
    364 else
    365 ECHO := true
    366 QUIET := -q
    367 endif
    368 
    369 # Dependencies which, if modified, should cause everything to rebuild
    370 GLOBAL_DEPS += Makefile $(addprefix $(DEPTH)/config/,$(INCLUDED_AUTOCONF_MK)) $(MOZILLA_DIR)/config/config.mk
    371 
    372 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
    373 # We always build .res files for programs and shared libraries
    374 resfile = $(notdir $1).res
    375 # We also build .res files for simple programs if a corresponding manifest
    376 # exists. We'll generate a .rc file that includes the manifest.
    377 resfile_for_manifest = $(if $(wildcard $(srcdir)/$(notdir $1).manifest),$(call resfile,$1))
    378 else
    379 resfile =
    380 resfile_for_manifest =
    381 endif
    382 
    383 ##############################################
    384 ifdef COMPILE_ENVIRONMENT
    385 compile:: host target
    386 
    387 host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_SHARED_LIBRARY)
    388 
    389 target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_PROGRAMS))
    390 
    391 ifndef LIBRARY
    392 ifdef OBJS
    393 target:: $(OBJS)
    394 endif
    395 endif
    396 
    397 target-objects: $(OBJS) $(PROGOBJS) $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(RUST_LIBRARY_FILE))
    398 host-objects: $(HOST_OBJS) $(HOST_PROGOBJS) $(HOST_RUST_LIBRARY_FILE)
    399 
    400 syms::
    401 
    402 include $(MOZILLA_DIR)/config/makefiles/target_binaries.mk
    403 endif
    404 
    405 alltags:
    406 $(RM) TAGS
    407 find $(topsrcdir) -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' -o -name '*.idl' \) -print | $(TAG_PROGRAM)
    408 
    409 define EXPAND_CC_OR_CXX
    410 $(if $(PROG_IS_C_ONLY_$(notdir $(1))),$(CC),$(CCC))
    411 endef
    412 
    413 #
    414 # PROGRAM = Foo
    415 # creates OBJS, links with LIBS to create Foo
    416 #
    417 $(PROGRAM): $(PROGOBJS) $(STATIC_LIBS) $(call resfile,$(PROGRAM)) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
    418 $(REPORT_BUILD)
    419 $(call BUILDSTATUS,START_Program $(@F))
    420 ifeq (clang-cl_WINNT,$(CC_TYPE)_$(OS_ARCH))
    421 $(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)
    422 else # !WINNT || !clang-cl
    423 $(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)
    424 $(call py_action,check_binary $(@F),$@)
    425 endif # WINNT && clang-cl
    426 
    427 ifdef ENABLE_STRIP
    428 $(STRIP) $(STRIP_FLAGS) $@
    429 endif
    430 $(call BUILDSTATUS,END_Program $(@F))
    431 
    432 $(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
    433 $(REPORT_BUILD)
    434 $(call BUILDSTATUS,START_Program $(@F))
    435 ifeq (clang-cl_WINNT,$(HOST_CC_TYPE)_$(HOST_OS_ARCH))
    436 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    437 else
    438 ifeq ($(HOST_CPP_PROG_LINK),1)
    439 $(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    440 else
    441 $(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    442 endif # HOST_CPP_PROG_LINK
    443 endif
    444 $(call BUILDSTATUS,END_Program $(@F))
    445 
    446 #
    447 # This is an attempt to support generation of multiple binaries
    448 # in one directory, it assumes everything to compile Foo is in
    449 # Foo.o (from either Foo.c or Foo.cpp).
    450 #
    451 # SIMPLE_PROGRAMS = Foo Bar
    452 # creates Foo.o Bar.o, links with LIBS to create Foo, Bar.
    453 #
    454 define simple_program_deps
    455 $1: $(1:$(BIN_SUFFIX)=.$(OBJ_SUFFIX)) $(STATIC_LIBS) $(call resfile_for_manifest,$1) $(GLOBAL_DEPS)
    456 endef
    457 $(foreach p,$(SIMPLE_PROGRAMS),$(eval $(call simple_program_deps,$(p))))
    458 
    459 $(SIMPLE_PROGRAMS):
    460 $(REPORT_BUILD)
    461 $(call BUILDSTATUS,START_Program $(@F))
    462 ifeq (clang-cl_WINNT,$(CC_TYPE)_$(OS_ARCH))
    463 $(LINKER) -out:$@ -pdb:$(LINK_PDBFILE) $($@_OBJS) $(filter %.res,$^) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(MOZ_PROGRAM_LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(OS_LIBS)
    464 else
    465 $(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)
    466 $(call py_action,check_binary $(@F),$@)
    467 endif # WINNT && clang-cl
    468 
    469 ifdef ENABLE_STRIP
    470 $(STRIP) $(STRIP_FLAGS) $@
    471 endif
    472 $(call BUILDSTATUS,END_Program $(@F))
    473 
    474 $(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(GLOBAL_DEPS)
    475 $(REPORT_BUILD)
    476 $(call BUILDSTATUS,START_Program $(@F))
    477 ifeq (WINNT_clang-cl,$(HOST_OS_ARCH)_$(HOST_CC_TYPE))
    478 $(HOST_LINKER) -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    479 else
    480 ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
    481 $(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    482 else
    483 $(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    484 endif
    485 endif
    486 $(call BUILDSTATUS,END_Program $(@F))
    487 
    488 $(LIBRARY): $(OBJS) $(STATIC_LIBS) $(GLOBAL_DEPS)
    489 $(REPORT_BUILD)
    490 $(call BUILDSTATUS,START_StaticLib $@)
    491 $(RM) $(REAL_LIBRARY)
    492 $(AR) $(AR_FLAGS) $($@_OBJS)
    493 $(call BUILDSTATUS,END_StaticLib $@)
    494 
    495 $(WASM_ARCHIVE): $(CWASMOBJS) $(CPPWASMOBJS) $(STATIC_LIBS) $(GLOBAL_DEPS)
    496 $(REPORT_BUILD_VERBOSE)
    497 $(call BUILDSTATUS,START_WasmLib $@)
    498 $(RM) $(WASM_ARCHIVE)
    499 $(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))
    500 $(call BUILDSTATUS,END_WasmLib $@)
    501 
    502 ifeq ($(OS_ARCH),WINNT)
    503 # Import libraries are created by the rules creating shared libraries.
    504 # The rules to copy them to $(DIST)/lib depend on $(IMPORT_LIBRARY),
    505 # but make will happily consider the import library before it is refreshed
    506 # when rebuilding the corresponding shared library. Defining an empty recipe
    507 # for import libraries forces make to wait for the shared library recipe to
    508 # have run before considering other targets that depend on the import library.
    509 # See bug 795204.
    510 $(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
    511 endif
    512 
    513 $(HOST_SHARED_LIBRARY): Makefile
    514 $(REPORT_BUILD)
    515 $(call BUILDSTATUS,START_SharedLib $@)
    516 $(RM) $@
    517 ifneq (,$(filter clang-cl,$(HOST_CC_TYPE)))
    518 $(HOST_LINKER) -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LINKER_LIBPATHS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    519 else
    520 $(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
    521 endif
    522 $(call BUILDSTATUS,END_SharedLib $@)
    523 
    524 # On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,
    525 # so instead of deleting .o files after repacking them into a dylib, we make
    526 # symlinks back to the originals. The symlinks are a no-op for stabs debugging,
    527 # so no need to conditionalize on OS version or debugging format.
    528 
    529 $(SHARED_LIBRARY): $(OBJS) $(call resfile,$(SHARED_LIBRARY)) $(STATIC_LIBS) $(GLOBAL_DEPS) $(call mkdir_deps,$(FINAL_TARGET))
    530 $(REPORT_BUILD)
    531 $(call BUILDSTATUS,START_SharedLib $@)
    532 $(RM) $@
    533 $(MKSHLIB) $(if $(filter clang-cl_WINNT,$(CC_TYPE)_$(OS_ARCH)),-IMPLIB:$(basename $(@F)).lib )$($(notdir $@)_OBJS) $(filter %.res,$^) $(RELRHACK_LDFLAGS) $(LDFLAGS) $(STATIC_LIBS) $(SHARED_LIBS) $(EXTRA_DSO_LDOPTS) $(MOZ_GLUE_LDFLAGS) $(OS_LIBS)
    534 $(call py_action,check_binary,$@)
    535 
    536 ifeq (clang-cl_WINNT,$(CC_TYPE)_$(OS_ARCH))
    537 endif	# WINNT && !GCC
    538 chmod +x $@
    539 ifdef ENABLE_STRIP
    540 $(STRIP) $(STRIP_FLAGS) $@
    541 endif
    542 $(call BUILDSTATUS,END_SharedLib $@)
    543 
    544 # The object file is in the current directory, and the source file can be any
    545 # relative path. This macro adds the dependency obj: src for each source file.
    546 # This dependency must be first for the $< flag to work correctly, and the
    547 # rules that have commands for these targets must not list any other
    548 # prerequisites, or they will override the $< variable.
    549 define src_objdep
    550 $(basename $3$(notdir $1)).$2: $1 $$(call mkdir_deps,$$(MDDEPDIR))
    551 endef
    552 $(foreach f,$(CSRCS) $(SSRCS) $(CPPSRCS) $(CMSRCS) $(CMMSRCS) $(ASFILES),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX))))
    553 $(foreach f,$(HOST_CSRCS) $(HOST_CPPSRCS),$(eval $(call src_objdep,$(f),$(OBJ_SUFFIX),host_)))
    554 $(foreach f,$(WASM_CSRCS) $(WASM_CPPSRCS),$(eval $(call src_objdep,$(f),wasm)))
    555 
    556 # The Rust compiler only outputs library objects, and so we need different
    557 # mangling to generate dependency rules for it.
    558 mk_global_crate_libname = $(basename lib$(notdir $1)).$(LIB_SUFFIX)
    559 crate_src_libdep = $(call mk_global_crate_libname,$1): $1 $$(call mkdir_deps,$$(MDDEPDIR))
    560 $(foreach f,$(RS_STATICLIB_CRATE_SRC),$(eval $(call crate_src_libdep,$(f))))
    561 
    562 $(OBJS) $(HOST_OBJS) $(PROGOBJS) $(HOST_PROGOBJS): $(GLOBAL_DEPS)
    563 
    564 # Rules for building native targets must come first because of the host_ prefix
    565 $(HOST_COBJS):
    566 $(REPORT_BUILD_VERBOSE)
    567 $(call BUILDSTATUS,OBJECT_FILE $@)
    568 $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CFLAGS) $(NSPR_CFLAGS) $<
    569 $(call BUILDSTATUS,END_Object $@)
    570 
    571 $(HOST_CPPOBJS):
    572 $(REPORT_BUILD_VERBOSE)
    573 $(call BUILDSTATUS,OBJECT_FILE $@)
    574 $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CPPFLAGS) $(HOST_CXXFLAGS) $(NSPR_CFLAGS) $<
    575 $(call BUILDSTATUS,END_Object $@)
    576 
    577 $(COBJS):
    578 $(REPORT_BUILD_VERBOSE)
    579 $(call BUILDSTATUS,OBJECT_FILE $@)
    580 $(CC) $(OUTOPTION)$@ -c $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
    581 $(call BUILDSTATUS,END_Object $@)
    582 
    583 $(CWASMOBJS):
    584 $(REPORT_BUILD_VERBOSE)
    585 $(call BUILDSTATUS,OBJECT_FILE $@)
    586 $(WASM_CC) -o $@ -c $(WASM_CFLAGS) $($(notdir $<)_FLAGS) $<
    587 $(call BUILDSTATUS,END_Object $@)
    588 
    589 WINEWRAP = $(if $(and $(filter %.exe,$1),$(WINE)),$(WINE) $1,$1)
    590 
    591 # Windows program run via Wine don't like Unix absolute paths (they look
    592 # like command line arguments). So when needed, create relative paths
    593 # from absolute paths. We start with $(DEPTH), which gets us to topobjdir,
    594 # then add "/.." for each component of topobjdir, which gets us to /.
    595 # then we can add the absolute path after that and we have a relative path,
    596 # albeit longer than it could be.
    597 ifdef WINE
    598 relativize = $(if $(filter /%,$1),$(DEPTH)$(subst $(space),,$(foreach d,$(subst /, ,$(topobjdir)),/..))$1,$1)
    599 else
    600 relativize = $1
    601 endif
    602 
    603 ifdef WINE
    604 # asmarm64 needs a library that can be found in $PATH but for some reason,
    605 # wine wants its path in $WINEPATH, so fill that to make it happy.
    606 $(ASOBJS) $(SOBJS): export WINEPATH=$(subst :,;,$(PATH))
    607 endif
    608 
    609 ifdef ASFILES
    610 # The AS_DASH_C_FLAG is needed cause not all assemblers (Solaris) accept
    611 # a '-c' flag.
    612 $(ASOBJS):
    613 $(REPORT_BUILD_VERBOSE)
    614 $(call BUILDSTATUS,OBJECT_FILE $@)
    615 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(ASFLAGS) $($(notdir $<)_FLAGS) $(AS_DASH_C_FLAG) $(call relativize,$<)
    616 $(call BUILDSTATUS,END_Object $@)
    617 endif
    618 
    619 define syms_template
    620 $(2): $(1)
    621 ifdef MOZ_CRASHREPORTER
    622 $$(call py_action,dumpsymbols $$@,$$(abspath $$<) $$(abspath $$@) $$(DUMP_SYMBOLS_FLAGS))
    623 ifeq ($(OS_ARCH),WINNT)
    624 ifdef WINCHECKSEC
    625 $$(PYTHON3) $$(topsrcdir)/build/win32/autowinchecksec.py $$<
    626 endif # WINCHECKSEC
    627 endif # WINNT
    628 endif
    629 endef
    630 
    631 ifneq (,$(filter $(DIST)/bin%,$(FINAL_TARGET)))
    632 DUMP_SYMS_TARGETS := $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS)
    633 endif
    634 
    635 ifdef MOZ_AUTOMATION
    636 ifeq (,$(filter 1,$(MOZ_AUTOMATION_BUILD_SYMBOLS)))
    637 DUMP_SYMS_TARGETS :=
    638 endif
    639 endif
    640 
    641 ifdef MOZ_COPY_PDBS
    642 MAIN_PDB_FILES = $(addsuffix .pdb,$(basename $(DUMP_SYMS_TARGETS)))
    643 MAIN_PDB_DEST ?= $(FINAL_TARGET)
    644 MAIN_PDB_TARGET = syms
    645 INSTALL_TARGETS += MAIN_PDB
    646 
    647 ifdef CPP_UNIT_TESTS
    648 CPP_UNIT_TESTS_PDB_FILES = $(addsuffix .pdb,$(basename $(CPP_UNIT_TESTS)))
    649 CPP_UNIT_TESTS_PDB_DEST = $(DIST)/cppunittests
    650 CPP_UNIT_TESTS_PDB_TARGET = syms
    651 INSTALL_TARGETS += CPP_UNIT_TESTS_PDB
    652 endif
    653 
    654 else ifdef MOZ_CRASHREPORTER
    655 $(foreach file,$(DUMP_SYMS_TARGETS),$(eval $(call syms_template,$(file),$(notdir $(file))_syms.track)))
    656 syms:: $(foreach file,$(DUMP_SYMS_TARGETS),$(notdir $(file))_syms.track)
    657 endif
    658 
    659 ifneq (,$(RUST_TESTS)$(RUST_LIBRARY_FILE)$(HOST_RUST_LIBRARY_FILE)$(RUST_PROGRAMS)$(HOST_RUST_PROGRAMS))
    660 include $(MOZILLA_DIR)/config/makefiles/rust.mk
    661 endif
    662 
    663 $(SOBJS):
    664 $(REPORT_BUILD)
    665 $(call WINEWRAP,$(AS)) $(ASOUTOPTION)$@ $(SFLAGS) $($(notdir $<)_FLAGS) -c $(call relativize,$<)
    666 
    667 $(CPPOBJS):
    668 $(REPORT_BUILD_VERBOSE)
    669 $(call BUILDSTATUS,OBJECT_FILE $@)
    670 $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
    671 $(call BUILDSTATUS,END_Object $@)
    672 
    673 $(CPPWASMOBJS):
    674 $(REPORT_BUILD_VERBOSE)
    675 $(call BUILDSTATUS,OBJECT_FILE $@)
    676 $(WASM_CXX) -o $@ -c $(WASM_CXXFLAGS) $($(notdir $<)_FLAGS) $<
    677 $(call BUILDSTATUS,END_Object $@)
    678 
    679 $(CMMOBJS):
    680 $(REPORT_BUILD_VERBOSE)
    681 $(call BUILDSTATUS,OBJECT_FILE $@)
    682 $(CCC) -o $@ -c $(COMPILE_CXXFLAGS) $(COMPILE_CMMFLAGS) $($(notdir $<)_FLAGS) $<
    683 $(call BUILDSTATUS,END_Object $@)
    684 
    685 $(CMOBJS):
    686 $(REPORT_BUILD_VERBOSE)
    687 $(call BUILDSTATUS,OBJECT_FILE $@)
    688 $(CC) -o $@ -c $(COMPILE_CFLAGS) $(COMPILE_CMFLAGS) $($(notdir $<)_FLAGS) $<
    689 $(call BUILDSTATUS,END_Object $@)
    690 
    691 $(filter %.s,$(CPPSRCS:%.cpp=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
    692 $(REPORT_BUILD_VERBOSE)
    693 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
    694 
    695 $(filter %.s,$(CPPSRCS:%.cc=%.s)): %.s: %.cc $(call mkdir_deps,$(MDDEPDIR))
    696 $(REPORT_BUILD_VERBOSE)
    697 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
    698 
    699 $(filter %.s,$(CPPSRCS:%.cxx=%.s)): %.s: %.cpp $(call mkdir_deps,$(MDDEPDIR))
    700 $(REPORT_BUILD_VERBOSE)
    701 $(CCC) -S $(COMPILE_CXXFLAGS) $($(notdir $<)_FLAGS) $<
    702 
    703 $(filter %.s,$(CSRCS:%.c=%.s)): %.s: %.c $(call mkdir_deps,$(MDDEPDIR))
    704 $(REPORT_BUILD_VERBOSE)
    705 $(CC) -S $(COMPILE_CFLAGS) $($(notdir $<)_FLAGS) $<
    706 
    707 ifneq (,$(filter %.i,$(MAKECMDGOALS)))
    708 # Call as $(call _group_srcs,extension,$(SRCS)) - this will create a list
    709 # of the full sources, as well as the $(notdir) version. So:
    710 #   foo.cpp sub/bar.cpp
    711 # becomes:
    712 #   foo.cpp sub/bar.cpp bar.cpp
    713 #
    714 # This way we can match both 'make sub/bar.i' and 'make bar.i'
    715 _group_srcs = $(sort $(patsubst %.$1,%.i,$(filter %.$1,$2 $(notdir $2))))
    716 
    717 define PREPROCESS_RULES
    718 _PREPROCESSED_$1_FILES := $$(call _group_srcs,$1,$$($2))
    719 # Make preprocessed files PHONY so they are always executed, since they are
    720 # manual targets and we don't necessarily write to $@.
    721 .PHONY: $$(_PREPROCESSED_$1_FILES)
    722 
    723 # Hack up VPATH so we can reach the sources. Eg: 'make Parser.i' may need to
    724 # reach $(srcdir)/frontend/Parser.i
    725 vpath %.$1 $$(addprefix $$(srcdir)/,$$(sort $$(dir $$($2))))
    726 vpath %.$1 $$(addprefix $$(CURDIR)/,$$(sort $$(dir $$($2))))
    727 
    728 $$(_PREPROCESSED_$1_FILES): _DEPEND_CFLAGS=
    729 $$(_PREPROCESSED_$1_FILES): %.i: %.$1
    730 $$(REPORT_BUILD_VERBOSE)
    731 $$(addprefix $$(MKDIR) -p ,$$(filter-out .,$$(@D)))
    732 $$($3) -C $$(PREPROCESS_OPTION)$$@ $(foreach var,$4,$$($(var))) $$($$(notdir $$<)_FLAGS) $$<
    733 
    734 endef
    735 
    736 $(eval $(call PREPROCESS_RULES,cpp,CPPSRCS,CCC,COMPILE_CXXFLAGS))
    737 $(eval $(call PREPROCESS_RULES,cc,CPPSRCS,CCC,COMPILE_CXXFLAGS))
    738 $(eval $(call PREPROCESS_RULES,cxx,CPPSRCS,CCC,COMPILE_CXXFLAGS))
    739 $(eval $(call PREPROCESS_RULES,c,CSRCS,CC,COMPILE_CFLAGS))
    740 $(eval $(call PREPROCESS_RULES,mm,CMMSRCS,CCC,COMPILE_CXXFLAGS COMPILE_CMMFLAGS))
    741 
    742 # Default to pre-processing the actual unified file. This can be overridden
    743 # at the command-line to pre-process only the individual source file.
    744 PP_UNIFIED ?= 1
    745 
    746 # PP_REINVOKE gets set on the sub-make to prevent us from going in an
    747 # infinite loop if the filename doesn't exist in the unified source files.
    748 ifndef PP_REINVOKE
    749 
    750 MATCH_cpp = \(cpp\|cc|cxx\)
    751 UPPER_c = C
    752 UPPER_cpp = CPP
    753 UPPER_mm = CMM
    754 
    755 # When building with PP_UNIFIED=0, we also have to look in the Unified files to
    756 # find a matching pathname.
    757 _get_all_sources = $1 $(if $(filter Unified%,$1),$(shell sed -n 's/\#include "\(.*\)"$$/\1/p' $(filter Unified%,$1)))
    758 all_cpp_sources := $(call _get_all_sources,$(CPPSRCS))
    759 all_mm_sources := $(call _get_all_sources,$(CMMSRCS))
    760 all_c_sources := $(call _get_all_sources,$(CSRCS))
    761 all_sources := $(all_cpp_sources) $(all_cmm_sources) $(all_c_sources)
    762 
    763 # The catch-all %.i rule runs when we pass in a .i filename that doesn't match
    764 # one of the *SRCS variables. The two code paths depend on whether or not
    765 # we are requesting a unified file (PP_UNIFIED=1, the default) or not:
    766 #
    767 # PP_UNIFIED=1:
    768 #  - Look for it in any of the Unified files, and re-exec make with
    769 #    Unified_foo0.i as the target. This gets us the full unified preprocessed
    770 #    file.
    771 #
    772 # PP_UNIFIED=0:
    773 #  - If the .i filename is in *SRCS, or in a Unified filename, then we re-exec
    774 #    make with that filename as the target. The *SRCS variables are modified
    775 #    to have the Unified sources appended to them so that the static pattern
    776 #    rules will match.
    777 %.i: FORCE
    778 ifeq ($(PP_UNIFIED),1)
    779 @$(MAKE) PP_REINVOKE=1 \
    780     $(or $(addsuffix .i, \
    781              $(foreach type,c cpp mm, \
    782         $(if $(filter Unified%,$($(UPPER_$(type))SRCS)), \
    783           $(shell grep -l '#include "\(.*/\)\?$(basename $@).$(or $(MATCH_$(type)),$(type))"' Unified*.$(type) | sed 's/\.$(type)$$//') \
    784            ))),$(error "File not found for preprocessing: $@"))
    785 else
    786 @$(MAKE) PP_REINVOKE=1 $@ \
    787     $(foreach type,c cpp mm,$(UPPER_$(type))SRCS="$(all_$(type)_sources)")
    788 endif
    789 
    790 endif
    791 
    792 endif
    793 
    794 %.res: $(or $(RCFILE),%.rc) $(MOZILLA_DIR)/config/create_res.py
    795 $(REPORT_BUILD)
    796 $(call BUILDSTATUS,START_Res $@)
    797 $(PYTHON3) $(MOZILLA_DIR)/config/create_res.py $(DEFINES) $(INCLUDES) -o $@ $<
    798 $(call BUILDSTATUS,END_Res $@)
    799 
    800 $(notdir $(addsuffix .rc,$(PROGRAM) $(SHARED_LIBRARY) $(SIMPLE_PROGRAMS) module)): %.rc: $(RCINCLUDE) $(MOZILLA_DIR)/config/create_rc.py
    801 $(call BUILDSTATUS,START_Rc $@)
    802 $(PYTHON3) $(MOZILLA_DIR)/config/create_rc.py '$(if $(filter module,$*),,$*)' --include '$(RCINCLUDE)' --dep-file '$(MDDEPDIR)/$@.d'
    803 $(call BUILDSTATUS,END_Rc $@)
    804 
    805 -include $(addsuffix .rc.d, $(addprefix $(MDDEPDIR)/,$(PROGRAM) $(SHARED_LIBRARY) $(SIMPLE_PROGRAMS) module))
    806 
    807 # Cancel GNU make built-in implicit rules
    808 MAKEFLAGS += -r
    809 
    810 ifneq (,$(filter WINNT,$(OS_ARCH)))
    811 SEP := ;
    812 else
    813 SEP := :
    814 endif
    815 
    816 EMPTY :=
    817 SPACE := $(EMPTY) $(EMPTY)
    818 
    819 ###############################################################################
    820 # Bunch of things that extend the 'export' rule (in order):
    821 ###############################################################################
    822 
    823 ifneq ($(XPI_NAME),)
    824 $(FINAL_TARGET):
    825 $(NSINSTALL) -D $@
    826 
    827 export:: $(FINAL_TARGET)
    828 endif
    829 
    830 ################################################################################
    831 # The default location for prefs is the gre prefs directory.
    832 # PREF_DIR is used for L10N_PREF_JS_EXPORTS in various locales/ directories.
    833 PREF_DIR = defaults/pref
    834 
    835 # If DIST_SUBDIR is defined it indicates that app and gre dirs are
    836 # different and that we are building app related resources. Hence,
    837 # PREF_DIR should point to the app prefs location.
    838 ifneq (,$(DIST_SUBDIR)$(XPI_NAME))
    839 PREF_DIR = defaults/preferences
    840 endif
    841 
    842 ################################################################################
    843 # CHROME PACKAGING
    844 
    845 chrome::
    846 $(MAKE) realchrome
    847 $(LOOP_OVER_DIRS)
    848 
    849 $(FINAL_TARGET)/chrome: $(call mkdir_deps,$(FINAL_TARGET)/chrome)
    850 
    851 ifneq (,$(JAR_MANIFEST))
    852 ifndef NO_DIST_INSTALL
    853 
    854 ifdef XPI_NAME
    855 ifdef XPI_ROOT_APPID
    856 # For add-on packaging we may specify that an application
    857 # sub-dir should be added to the root chrome manifest with
    858 # a specific application id.
    859 MAKE_JARS_FLAGS += --root-manifest-entry-appid='$(XPI_ROOT_APPID)'
    860 endif
    861 
    862 # if DIST_SUBDIR is defined but XPI_ROOT_APPID is not there's
    863 # no way langpacks will get packaged right, so error out.
    864 ifneq (,$(DIST_SUBDIR))
    865 ifndef XPI_ROOT_APPID
    866 $(error XPI_ROOT_APPID is not defined - langpacks will break.)
    867 endif
    868 endif
    869 endif
    870 
    871 misc realchrome:: $(FINAL_TARGET)/chrome
    872 $(call py_action,jar_maker $(subst $(topsrcdir)/,,$(JAR_MANIFEST)),\
    873   $(QUIET) -d $(FINAL_TARGET) \
    874   $(MAKE_JARS_FLAGS) $(DEFINES) $(ACDEFINES) \
    875   $(JAR_MANIFEST))
    876 
    877 ifdef AB_CD
    878 .PHONY: l10n
    879 l10n: misc ;
    880 endif
    881 endif
    882 
    883 endif
    884 
    885 # Usage:
    886 # xpi_package_rule(package-name,directory-to-package,relative-target-directory,parent-rule)
    887 # where:
    888 #     - package-name is the name of the xpi package, without suffix
    889 #     - directory-to-package is the path to the directory to package
    890 #     - relative-target-directory is the path to the directory where
    891 #       the archive is generated, relative to directory-to-package
    892 #     - parent-rule is the name(s) of the rule(s) this rule should be added to
    893 define xpi_package_rule
    894 $$(abspath $(3))/$(1).xpi: $$(call mkdir_deps,$(3) $$(MDDEPDIR))
    895 @echo 'Packaging $(1).xpi...'
    896 $$(call py_action,zip $(1).xpi,-C $(2) $$@ '*' --dep-target $$@ --dep-file $$(MDDEPDIR)/$(1).d)
    897 
    898 $(4):: $$(abspath $(3))/$(1).xpi
    899 
    900 -include $$(MDDEPDIR)/$(1).d
    901 
    902 endef
    903 
    904 ifdef XPI_TESTDIR
    905 $(eval $(call xpi_package_rule,$(XPI_PKGNAME),$(srcdir),$(XPI_TESTDIR),misc))
    906 else
    907 # When you move this out of the tools tier, please remove the corresponding
    908 # hacks in recursivemake.py that check if Makefile.in sets the variable.
    909 ifdef XPI_PKGNAME
    910 $(eval $(call xpi_package_rule,$(XPI_PKGNAME),$(FINAL_TARGET),$(FINAL_TARGET)/..,tools realchrome))
    911 endif
    912 endif
    913 
    914 #############################################################################
    915 # MDDEPDIR is the subdirectory where all the dependency files are placed.
    916 #   This uses a make rule (instead of a macro) to support parallel
    917 #   builds (-jN). If this were done in the LOOP_OVER_DIRS macro, two
    918 #   processes could simultaneously try to create the same directory.
    919 #
    920 #   We use $(CURDIR) in the rule's target to ensure that we don't find
    921 #   a dependency directory in the source tree via VPATH (perhaps from
    922 #   a previous build in the source tree) and thus neglect to create a
    923 #   dependency directory in the object directory, where we really need
    924 #   it.
    925 
    926 _MDDEPEND_FILES :=
    927 
    928 ifneq (,$(filter target-objects target all default,$(MAKECMDGOALS)))
    929 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(OBJS) $(PROGOBJS))))
    930 endif
    931 
    932 ifneq (,$(filter host-objects host all default,$(MAKECMDGOALS)))
    933 _MDDEPEND_FILES += $(addsuffix .pp,$(notdir $(sort $(HOST_OBJS) $(HOST_PROGOBJS))))
    934 endif
    935 
    936 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(_MDDEPEND_FILES))))
    937 MDDEPEND_FILES += $(EXTRA_MDDEPEND_FILES)
    938 
    939 ifneq (,$(MDDEPEND_FILES))
    940 -include $(MDDEPEND_FILES)
    941 endif
    942 
    943 ################################################################################
    944 # Install/copy rules
    945 #
    946 # The INSTALL_TARGETS variable contains a list of all install target
    947 # categories. Each category defines a list of files and executables, and an
    948 # install destination,
    949 #
    950 # FOO_FILES := foo bar
    951 # FOO_EXECUTABLES := baz
    952 # FOO_DEST := target_path
    953 # INSTALL_TARGETS += FOO
    954 #
    955 # Additionally, a FOO_TARGET variable may be added to indicate the target for
    956 # which the files and executables are installed. Default is "libs".
    957 #
    958 # Finally, a FOO_KEEP_PATH variable may be set to 1 to indicate the paths given
    959 # in FOO_FILES/FOO_EXECUTABLES are to be kept at the destination. That is,
    960 # if FOO_FILES is bar/baz/qux.h, and FOO_DEST is $(DIST)/include, the installed
    961 # file would be $(DIST)/include/bar/baz/qux.h instead of $(DIST)/include/qux.h
    962 
    963 # If we're using binary nsinstall and it's not built yet, fallback to python nsinstall.
    964 ifneq (,$(filter $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX),$(install_cmd)))
    965 ifeq (,$(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)))
    966 nsinstall_is_usable = $(if $(wildcard $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)),yes)
    967 
    968 define install_cmd_override
    969 $(1): install_cmd = $$(if $$(nsinstall_is_usable),$$(INSTALL),$$(NSINSTALL_PY) -t) $$(1)
    970 endef
    971 endif
    972 endif
    973 
    974 install_target_tier = $(or $($(1)_TARGET),libs)
    975 INSTALL_TARGETS_TIERS := $(sort $(foreach category,$(INSTALL_TARGETS),$(call install_target_tier,$(category))))
    976 
    977 install_target_result = $($(1)_DEST:%/=%)/$(if $($(1)_KEEP_PATH),$(2),$(notdir $(2)))
    978 install_target_files = $(foreach file,$($(1)_FILES),$(call install_target_result,$(category),$(file)))
    979 install_target_executables = $(foreach file,$($(1)_EXECUTABLES),$(call install_target_result,$(category),$(file)))
    980 
    981 # Work around a GNU make 3.81 bug where it gives $< the wrong value.
    982 # See details in bug 934864.
    983 define create_dependency
    984 $(1): $(2)
    985 $(1): $(2)
    986 endef
    987 
    988 define install_target_template
    989 $(call install_cmd_override,$(2))
    990 $(call create_dependency,$(2),$(1))
    991 endef
    992 
    993 $(foreach category,$(INSTALL_TARGETS),\
    994  $(if $($(category)_DEST),,$(error Missing $(category)_DEST)) \
    995  $(foreach tier,$(call install_target_tier,$(category)),\
    996    $(eval INSTALL_TARGETS_FILES_$(tier) += $(call install_target_files,$(category))) \
    997    $(eval INSTALL_TARGETS_EXECUTABLES_$(tier) += $(call install_target_executables,$(category))) \
    998  ) \
    999  $(foreach file,$($(category)_FILES) $($(category)_EXECUTABLES), \
   1000    $(eval $(call install_target_template,$(file),$(call install_target_result,$(category),$(file)))) \
   1001  ) \
   1002 )
   1003 
   1004 $(foreach tier,$(INSTALL_TARGETS_TIERS), \
   1005  $(eval $(if $(filter .,$(DEPTH)),recurse_$(tier):,$(tier)::) $(INSTALL_TARGETS_FILES_$(tier)) $(INSTALL_TARGETS_EXECUTABLES_$(tier))) \
   1006 )
   1007 
   1008 install_targets_sanity = $(if $(filter-out $(notdir $@),$(notdir $(<))),$(error Looks like $@ has an unexpected dependency on $< which breaks INSTALL_TARGETS))
   1009 
   1010 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_FILES_$(tier)))):
   1011 $(install_targets_sanity)
   1012 $(call BUILDSTATUS,START_Install $@)
   1013 $(call install_cmd,$(IFLAGS1) '$<' '$(@D)')
   1014 $(call BUILDSTATUS,END_Install $@)
   1015 
   1016 $(sort $(foreach tier,$(INSTALL_TARGETS_TIERS),$(INSTALL_TARGETS_EXECUTABLES_$(tier)))):
   1017 $(install_targets_sanity)
   1018 $(call BUILDSTATUS,START_Install $@)
   1019 $(call install_cmd,$(IFLAGS2) '$<' '$(@D)')
   1020 $(call BUILDSTATUS,END_Install $@)
   1021 
   1022 ################################################################################
   1023 # Preprocessing rules
   1024 #
   1025 # The PP_TARGETS variable contains a list of all preprocessing target
   1026 # categories. Each category has associated variables listing input files, the
   1027 # output directory, extra preprocessor flags, and so on. For example:
   1028 #
   1029 #   FOO := input-file
   1030 #   FOO_PATH := target-directory
   1031 #   FOO_FLAGS := -Dsome_flag
   1032 #   PP_TARGETS += FOO
   1033 #
   1034 # If PP_TARGETS lists a category name <C> (like FOO, above), then we consult the
   1035 # following make variables to see what to do:
   1036 #
   1037 # - <C> lists input files to be preprocessed with mozbuild.action.preprocessor.
   1038 #   We search VPATH for the names given here. If an input file name ends in
   1039 #   '.in', that suffix is omitted from the output file name.
   1040 #
   1041 # - <C>_PATH names the directory in which to place the preprocessed output
   1042 #   files. We create this directory if it does not already exist. Setting
   1043 #   this variable is optional; if unset, we install the files in $(CURDIR).
   1044 #
   1045 # - <C>_FLAGS lists flags to pass to mozbuild.action.preprocessor, in addition
   1046 #   to the usual bunch. Setting this variable is optional.
   1047 #
   1048 # - <C>_TARGET names the 'make' target that should depend on creating the output
   1049 #   files. Setting this variable is optional; if unset, we preprocess the
   1050 #   files for the 'libs' target.
   1051 #
   1052 # - <C>_KEEP_PATH may be set to 1 to indicate the paths given in <C> are to be
   1053 #   kept under <C>_PATH. That is, if <C> is bar/baz/qux.h.in and <C>_PATH is
   1054 #   $(DIST)/include, the preprocessed file would be $(DIST)/include/bar/baz/qux.h
   1055 #   instead of $(DIST)/include/qux.h.
   1056 
   1057 pp_target_tier = $(or $($(1)_TARGET),libs)
   1058 PP_TARGETS_TIERS := $(sort $(foreach category,$(PP_TARGETS),$(call pp_target_tier,$(category))))
   1059 
   1060 pp_target_result = $(or $($(1)_PATH:%/=%),$(CURDIR))/$(if $($(1)_KEEP_PATH),$(2:.in=),$(notdir $(2:.in=)))
   1061 pp_target_results = $(foreach file,$($(1)),$(call pp_target_result,$(category),$(file)))
   1062 
   1063 $(foreach category,$(PP_TARGETS), \
   1064  $(foreach tier,$(call pp_target_tier,$(category)), \
   1065    $(eval PP_TARGETS_RESULTS_$(tier) += $(call pp_target_results,$(category))) \
   1066  ) \
   1067  $(foreach file,$($(category)), \
   1068    $(eval $(call create_dependency,$(call pp_target_result,$(category),$(file)), \
   1069                                    $(file) $(GLOBAL_DEPS))) \
   1070  ) \
   1071  $(eval $(call pp_target_results,$(category)): PP_TARGET_FLAGS=$($(category)_FLAGS)) \
   1072 )
   1073 
   1074 $(foreach tier,$(PP_TARGETS_TIERS), \
   1075  $(eval $(if $(filter .,$(DEPTH)),recurse_$(tier):,$(tier)::) $(PP_TARGETS_RESULTS_$(tier))) \
   1076 )
   1077 
   1078 PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
   1079 $(PP_TARGETS_ALL_RESULTS):
   1080 $(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
   1081 $(RM) '$@'
   1082 $(call py_action,preprocessor $(@F),--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
   1083 
   1084 $(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
   1085 
   1086 # The depfile is based on the filename, and we don't want conflicts. So check
   1087 # there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
   1088 PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
   1089 $(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
   1090  $(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
   1091    $(error Multiple preprocessing rules are creating a $(file) file) \
   1092  ) \
   1093 )
   1094 
   1095 ifneq (,$(filter $(PP_TARGETS_TIERS) $(PP_TARGETS_ALL_RESULTS),$(MAKECMDGOALS)))
   1096 # If the depfile for a preprocessed file doesn't exist, add a dep to force
   1097 # re-preprocessing.
   1098 $(foreach file,$(PP_TARGETS_ALL_RESULTS), \
   1099  $(if $(wildcard $(MDDEPDIR)/$(notdir $(file)).pp), \
   1100    , \
   1101    $(eval $(file): FORCE) \
   1102  ) \
   1103 )
   1104 
   1105 MDDEPEND_FILES := $(strip $(wildcard $(addprefix $(MDDEPDIR)/,$(addsuffix .pp,$(notdir $(PP_TARGETS_ALL_RESULTS))))))
   1106 
   1107 ifneq (,$(MDDEPEND_FILES))
   1108 -include $(MDDEPEND_FILES)
   1109 endif
   1110 
   1111 endif
   1112 
   1113 # Pull in non-recursive targets if this is a partial tree build.
   1114 ifndef TOPLEVEL_BUILD
   1115 include $(MOZILLA_DIR)/config/makefiles/nonrecursive.mk
   1116 endif
   1117 
   1118 ################################################################################
   1119 # Special gmake rules.
   1120 ################################################################################
   1121 
   1122 
   1123 #
   1124 # Re-define the list of default suffixes, so gmake won't have to churn through
   1125 # hundreds of built-in suffix rules for stuff we don't need.
   1126 #
   1127 .SUFFIXES:
   1128 
   1129 #
   1130 # Fake targets.  Always run these rules, even if a file/directory with that
   1131 # name already exists.
   1132 #
   1133 .PHONY: all alltags boot chrome realchrome export install libs makefiles run_apprunner tools $(DIRS) FORCE
   1134 
   1135 # Used as a dependency to force targets to rebuild
   1136 FORCE:
   1137 
   1138 # Delete target if error occurs when building target
   1139 .DELETE_ON_ERROR:
   1140 
   1141 tags: TAGS
   1142 
   1143 TAGS: $(CSRCS) $(CPPSRCS) $(wildcard *.h)
   1144 -etags $(CSRCS) $(CPPSRCS) $(wildcard *.h)
   1145 $(LOOP_OVER_DIRS)
   1146 
   1147 ifndef INCLUDED_DEBUGMAKE_MK #{
   1148  ## Only parse when an echo* or show* target is requested
   1149  ifneq (,$(call isTargetStem,echo,show))
   1150    include $(MOZILLA_DIR)/config/makefiles/debugmake.mk
   1151  endif #}
   1152 endif #}
   1153 
   1154 FREEZE_VARIABLES = \
   1155  CSRCS \
   1156  CPPSRCS \
   1157  EXPORTS \
   1158  DIRS \
   1159  LIBRARY \
   1160  MODULE \
   1161  $(NULL)
   1162 
   1163 $(foreach var,$(FREEZE_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
   1164 
   1165 CHECK_FROZEN_VARIABLES = $(foreach var,$(FREEZE_VARIABLES), \
   1166  $(if $(subst $($(var)_FROZEN),,'$($(var))'),$(error Makefile variable '$(var)' changed value after including rules.mk. Was $($(var)_FROZEN), now $($(var)).)))
   1167 
   1168 libs export::
   1169 $(CHECK_FROZEN_VARIABLES)
   1170 
   1171 .DEFAULT_GOAL := $(or $(OVERRIDE_DEFAULT_GOAL),default)
   1172 
   1173 #############################################################################
   1174 # Derived targets and dependencies
   1175 
   1176 include $(MOZILLA_DIR)/config/makefiles/autotargets.mk
   1177 ifneq ($(NULL),$(AUTO_DEPS))
   1178  default all libs tools export:: $(AUTO_DEPS)
   1179 endif