2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # Determines the platform and builds the macros needed to load the
10 # appropriate platform-specific .mk file, then defines all (most?)
11 # of the generic macros.
14 # Define an include-at-most-once flag
15 ifdef INCLUDED_CONFIG_MK
16 $(error Do not
include config.mk twice
!)
18 INCLUDED_CONFIG_MK
= 1
20 EXIT_ON_ERROR
= set
-e
; # Shell loops continue past errors without this.
26 ifndef INCLUDED_AUTOCONF_MK
27 include $(DEPTH
)/config
/autoconf.mk
30 -include $(DEPTH
)/.mozconfig.mk
32 # MDDEPDIR is the subdirectory where dependency files are stored
35 ifndef EXTERNALLY_MANAGED_MAKE_FILE
36 # Import the automatically generated backend file. If this file doesn't exist,
37 # the backend hasn't been properly configured. We want this to be a fatal
38 # error, hence not using "-include".
39 ifndef STANDALONE_MAKEFILE
40 GLOBAL_DEPS
+= backend.mk
46 space
= $(NULL
) $(NULL
)
48 # Include defs.mk files that can be found in $(srcdir)/$(DEPTH),
49 # $(srcdir)/$(DEPTH-1), $(srcdir)/$(DEPTH-2), etc., and $(srcdir)
50 # where $(DEPTH-1) is one level less of depth, $(DEPTH-2), two, etc.
51 # i.e. for DEPTH=../../.., DEPTH-1 is ../.. and DEPTH-2 is ..
52 # These defs.mk files are used to define variables in a directory
53 # and all its subdirectories, recursively.
54 __depth
:= $(subst /, ,$(DEPTH
))
58 $(foreach __d
,$(__depth
) .
,$(eval __depth
= $(wordlist
2,$(words $(__depth
)),$(__depth
))$(eval
-include $(subst $(space
),/,$(strip $(srcdir) $(__depth
) defs.mk
)))))
62 # Sanity check some variables
69 INSTALL_EXTENSION_ID \
75 # checks for internal spaces or trailing spaces in the variable
77 check-variable
= $(if
$(filter-out 0 1,$(words $($(x
))z
)),$(error Spaces are not allowed in
$(x
)))
79 $(foreach x
,$(CHECK_VARS
),$(check-variable
))
81 ifndef INCLUDED_FUNCTIONS_MK
82 include $(MOZILLA_DIR
)/config
/makefiles
/functions.mk
87 # FINAL_TARGET specifies the location into which we copy end-user-shipped
88 # build products (typelibs, components, chrome). It may already be specified by
91 # If XPI_NAME is set, the files will be shipped to $(DIST)/xpi-stage/$(XPI_NAME)
92 # instead of $(DIST)/bin. In both cases, if DIST_SUBDIR is set, the files will be
93 # shipped to a $(DIST_SUBDIR) subdirectory.
94 FINAL_TARGET ?
= $(if
$(XPI_NAME
),$(DIST
)/xpi-stage
/$(XPI_NAME
),$(DIST
)/bin
)$(DIST_SUBDIR
:%=/%)
95 # Override the stored value for the check to make sure that the variable is not
96 # redefined in the Makefile.in value.
97 FINAL_TARGET_FROZEN
:= '$(FINAL_TARGET)'
100 ACDEFINES
+= -DXPI_NAME
=$(XPI_NAME
)
103 # The VERSION_NUMBER is suffixed onto the end of the DLLs we ship.
106 CONFIG_TOOLS
= $(MOZ_BUILD_ROOT
)/config
107 AUTOCONF_TOOLS
= $(MOZILLA_DIR
)/build
/autoconf
109 CC
:= $(CC_WRAPPER
) $(CC
)
110 CXX
:= $(CXX_WRAPPER
) $(CXX
)
115 PYTHON_PATH
= $(PYTHON
) $(topsrcdir
)/config
/pythonpath.py
118 # Build using PIC by default
122 # Don't build SIMPLE_PROGRAMS with PGO, since they don't need it anyway,
123 # and we don't have the same build logic to re-link them in the second pass.
124 ifdef SIMPLE_PROGRAMS
125 NO_PROFILE_GUIDED_OPTIMIZE
= 1
128 # No sense in profiling unit tests
130 NO_PROFILE_GUIDED_OPTIMIZE
= 1
133 # Enable profile-based feedback
134 ifneq (1,$(NO_PROFILE_GUIDED_OPTIMIZE
))
135 ifdef MOZ_PROFILE_GENERATE
136 PGO_CFLAGS
+= $(if
$(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE
))),,$(PROFILE_GEN_CFLAGS
) $(COMPUTED_PROFILE_GEN_DYN_CFLAGS
))
137 PGO_LDFLAGS
+= $(PROFILE_GEN_LDFLAGS
)
138 ifeq (WINNT
,$(OS_ARCH
))
141 endif # MOZ_PROFILE_GENERATE
143 ifdef MOZ_PROFILE_USE
144 PGO_CFLAGS
+= $(if
$(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE
))),,$(PROFILE_USE_CFLAGS
))
145 PGO_LDFLAGS
+= $(PROFILE_USE_LDFLAGS
)
146 ifeq (WINNT
,$(OS_ARCH
))
149 endif # MOZ_PROFILE_USE
150 endif # NO_PROFILE_GUIDED_OPTIMIZE
152 LOCALE_TOPDIR ?
= $(topsrcdir
)
154 -t
$(LOCALE_TOPDIR
) \
155 -f
$(MOZ_JAR_MAKER_FILE_FORMAT
) \
158 ifdef USE_EXTENSION_MANIFEST
159 MAKE_JARS_FLAGS
+= -e
162 TAR_CREATE_FLAGS
= -chf
165 # Default command macros; can be overridden in <arch>.mk.
173 -I
$(ABS_DIST
)/include \
176 include $(MOZILLA_DIR
)/config
/static-checking-config.mk
183 LDFLAGS
= $(MOZ_LTO_LDFLAGS
) $(COMPUTED_LDFLAGS
) $(PGO_LDFLAGS
) $(MK_LDFLAGS
)
185 COMPILE_CFLAGS
= $(MOZ_LTO_CFLAGS
) $(COMPUTED_CFLAGS
) $(PGO_CFLAGS
) $(_DEPEND_CFLAGS
) $(MK_COMPILE_DEFINES
)
186 COMPILE_CXXFLAGS
= $(MOZ_LTO_CFLAGS
) $(COMPUTED_CXXFLAGS
) $(PGO_CFLAGS
) $(_DEPEND_CFLAGS
) $(MK_COMPILE_DEFINES
)
187 COMPILE_CMFLAGS
= $(MOZ_LTO_CFLAGS
) $(OS_COMPILE_CMFLAGS
) $(MOZBUILD_CMFLAGS
)
188 COMPILE_CMMFLAGS
= $(MOZ_LTO_CFLAGS
) $(OS_COMPILE_CMMFLAGS
) $(MOZBUILD_CMMFLAGS
)
189 ASFLAGS
= $(COMPUTED_ASFLAGS
)
190 SFLAGS
= $(COMPUTED_SFLAGS
)
192 HOST_CFLAGS
= $(COMPUTED_HOST_CFLAGS
) $(_DEPEND_CFLAGS
)
193 HOST_CXXFLAGS
= $(COMPUTED_HOST_CXXFLAGS
) $(_DEPEND_CFLAGS
)
194 HOST_C_LDFLAGS
= $(COMPUTED_HOST_C_LDFLAGS
)
195 HOST_CXX_LDFLAGS
= $(COMPUTED_HOST_CXX_LDFLAGS
)
198 ifeq (Darwin
,$(OS_TARGET
))
199 # When linking on macOS, debug info is not linked along with the final binary,
200 # and the dwarf data stays in object files until they are "linked" with the
202 # With LTO, object files are temporary, and are not kept around, which
203 # means there's no object file for dsymutil to do its job. Consequently,
204 # there is no debug info for LTOed compilation units.
205 # The macOS linker has however an option to explicitly keep those object
206 # files, which dsymutil will then find.
207 # The catch is that the linker uses sequential numbers for those object
208 # files, and doesn't avoid conflicts from multiple linkers running at
209 # the same time. So in directories with multiple binaries, object files
210 # from the first linked binaries would be overwritten by those of the
211 # last linked binary. So we use a subdirectory containing the name of the
213 LDFLAGS
+= -Wl
,-object_path_lto
,$(@F
).lto.o
/
217 # We only add color flags if neither the flag to disable color
218 # (e.g. "-fno-color-diagnostics" nor a flag to control color
219 # (e.g. "-fcolor-diagnostics=never") is present.
220 define colorize_flags
221 ifeq (,$(filter $(COLOR_CFLAGS
:-f
%=-fno-
%),$$(1))$(findstring $(COLOR_CFLAGS
),$$(1)))
222 $(1) += $(COLOR_CFLAGS
)
226 color_flags_vars
:= \
234 ifdef MACH_STDOUT_ISATTY
236 # TODO Bug 1319166 - iTerm2 interprets some bytes sequences as a
237 # request to show a print dialog. Don't enable color on iTerm2 until
238 # a workaround is in place.
239 ifneq ($(TERM_PROGRAM
),iTerm.app
)
240 $(foreach var
,$(color_flags_vars
),$(eval
$(call colorize_flags
,$(var
))))
246 # Name of the binary code directories
252 ifdef MACOSX_DEPLOYMENT_TARGET
253 export MACOSX_DEPLOYMENT_TARGET
254 endif # MACOSX_DEPLOYMENT_TARGET
256 # Export to propagate to cl and submake for third-party code.
257 # Eventually, we'll want to just use -I.
262 # Export to propagate to link.exe and submake for third-party code.
263 # Eventually, we'll want to just use -LIBPATH.
268 ifdef MOZ_USING_CCACHE
278 # Set link flags according to whether we want a console.
279 ifeq ($(OS_ARCH
),WINNT
)
281 ifeq ($(MOZ_WINCONSOLE
),1)
282 WIN32_EXE_LDFLAGS
+= $(WIN32_CONSOLE_EXE_LDFLAGS
)
283 else # MOZ_WINCONSOLE
284 WIN32_EXE_LDFLAGS
+= $(WIN32_GUI_EXE_LDFLAGS
)
287 # For setting subsystem version
288 WIN32_EXE_LDFLAGS
+= $(WIN32_CONSOLE_EXE_LDFLAGS
)
292 ifneq (,$(filter msvc clang-cl
,$(CC_TYPE
)))
293 ifneq ($(CPU_ARCH
),x86
)
294 # Normal operation on 64-bit Windows needs 2 MB of stack. (Bug 582910)
295 # ASAN requires 6 MB of stack.
296 # Setting the stack to 8 MB to match the capability of other systems
297 # to deal with frame construction for unreasonably deep DOM trees
298 # with worst-case styling. This uses address space unnecessarily for
299 # non-main threads, but that should be tolerable on 64-bit systems.
301 WIN32_EXE_LDFLAGS
+= -STACK
:8388608
303 # Since this setting affects the default stack size for non-main
304 # threads, too, to avoid burning the address space, increase only
305 # 512 KB over the default. Just enough to be able to deal with
306 # reasonable styling applied to DOM trees whose depth is near what
307 # Blink's HTML parser can output, esp.
308 # layout/base/crashtests/507119.html (Bug 256180)
309 WIN32_EXE_LDFLAGS
+= -STACK
:1572864
313 -include $(topsrcdir
)/$(MOZ_BUILD_APP
)/app-config.mk
315 ######################################################################
317 GARBAGE
+= $(DEPENDENCIES
) core
$(wildcard core.
[0-9]*) $(wildcard *.err
) $(wildcard *.pure
) $(wildcard *_pure_
*.o
) Templates.DB
319 ifeq ($(OS_ARCH
),Darwin
)
321 NSDISTMODE
=absolute_symlink
326 NSINSTALL_PY
:= $(PYTHON
) $(abspath
$(MOZILLA_DIR
)/config
/nsinstall.py
)
327 ifneq (,$(or
$(filter WINNT
,$(HOST_OS_ARCH
)),$(if
$(COMPILE_ENVIRONMENT
),,1)))
328 NSINSTALL
= $(NSINSTALL_PY
)
330 NSINSTALL
= $(DEPTH
)/config
/nsinstall
$(HOST_BIN_SUFFIX
)
334 ifeq (,$(CROSS_COMPILE
)$(filter-out WINNT
, $(OS_ARCH
)))
335 INSTALL
= $(NSINSTALL
) -t
339 # This isn't laid out as conditional directives so that NSDISTMODE can be
341 INSTALL
= $(if
$(filter absolute_symlink
, $(NSDISTMODE
)), $(NSINSTALL
) -L
$(PWD
), $(NSINSTALL
) -R
)
345 # The default for install_cmd is simply INSTALL
346 install_cmd ?
= $(INSTALL
) $(1)
348 # Use nsinstall in copy mode to install files on the system
349 SYSINSTALL
= $(NSINSTALL
) -t
350 # This isn't necessarily true, just here
351 sysinstall_cmd
= install_cmd
354 # Localization build automation
357 # Because you might wish to "make locales AB_CD=ab-CD", we don't hardcode
358 # MOZ_UI_LOCALE directly, but use an intermediate variable that can be
359 # overridden by the command line. (Besides, AB_CD is prettier).
360 AB_CD
= $(MOZ_UI_LOCALE
)
362 include $(MOZILLA_DIR
)/config
/AB_rCD.mk
364 # Many locales directories want this definition.
365 ACDEFINES
+= -DAB_CD
=$(AB_CD
)
367 EXPAND_LOCALE_SRCDIR
= $(if
$(filter en-US
,$(AB_CD
)),$(LOCALE_TOPDIR
)/$(1)/en-US
,$(or
$(realpath
$(L10NBASEDIR
)),$(abspath
$(L10NBASEDIR
)))/$(AB_CD
)/$(subst /locales
,,$(1)))
370 LOCALE_RELATIVEDIR ?
= $(relativesrcdir
)
373 ifdef LOCALE_RELATIVEDIR
374 LOCALE_SRCDIR ?
= $(call EXPAND_LOCALE_SRCDIR
,$(LOCALE_RELATIVEDIR
))
378 MAKE_JARS_FLAGS
+= --relativesrcdir
=$(LOCALE_RELATIVEDIR
)
379 ifneq (en-US
,$(AB_CD
))
380 ifdef IS_LANGUAGE_REPACK
381 MAKE_JARS_FLAGS
+= --locale-mergedir
=$(REAL_LOCALE_MERGEDIR
)
383 ifdef IS_LANGUAGE_REPACK
384 MAKE_JARS_FLAGS
+= --l10n-base
=$(L10NBASEDIR
)/$(AB_CD
)
387 MAKE_JARS_FLAGS
+= -c
$(LOCALE_SRCDIR
)
390 MAKE_JARS_FLAGS
+= -c
$(LOCALE_SRCDIR
)
391 endif # ! relativesrcdir
393 ifdef IS_LANGUAGE_REPACK
394 MERGE_FILE
= $(firstword \
395 $(wildcard $(REAL_LOCALE_MERGEDIR
)/$(subst /locales
,,$(LOCALE_RELATIVEDIR
))/$(1)) \
396 $(wildcard $(LOCALE_SRCDIR
)/$(1)) \
397 $(srcdir)/en-US
/$(1) )
398 # Like MERGE_FILE, but with the specified relative source directory
399 # $(2) replacing $(srcdir). It's expected that $(2) will include
400 # '/locales' but not '/locales/en-US'.
402 # MERGE_RELATIVE_FILE and MERGE_FILE could be -- ahem -- merged by
403 # making the second argument optional, but that expression makes for
404 # difficult to read Make.
405 MERGE_RELATIVE_FILE
= $(firstword \
406 $(wildcard $(REAL_LOCALE_MERGEDIR
)/$(subst /locales
,,$(2))/$(1)) \
407 $(wildcard $(call EXPAND_LOCALE_SRCDIR
,$(2))/$(1)) \
408 $(topsrcdir
)/$(2)/en-US
/$(1) )
410 MERGE_FILE
= $(LOCALE_SRCDIR
)/$(1)
411 MERGE_RELATIVE_FILE
= $(call EXPAND_LOCALE_SRCDIR
,$(2))/$(1)
414 ifneq (WINNT
,$(OS_ARCH
))
415 RUN_TEST_PROGRAM
= $(DIST
)/bin
/run-mozilla.sh
418 # autoconf.mk sets OBJ_SUFFIX to an error to avoid use before including
420 OBJ_SUFFIX
:= $(_OBJ_SUFFIX
)
422 OBJS_VAR_SUFFIX
:= OBJS
424 # PGO builds with GCC and clang-cl build objects with instrumentation in
425 # a first pass, then objects optimized, without instrumentation, in a
426 # second pass. If we overwrite the objects from the first pass with
427 # those from the second, we end up not getting instrumentation data for
428 # better optimization on incremental builds. As a consequence, we use a
429 # different object suffix for the first pass.
430 ifdef MOZ_PROFILE_GENERATE
431 ifneq (,$(GNU_CC
)$(CLANG_CL
))
432 OBJS_VAR_SUFFIX
:= PGO_OBJS
433 ifndef NO_PROFILE_GUIDED_OPTIMIZE
439 PLY_INCLUDE
= -I
$(MOZILLA_DIR
)/other-licenses
/ply