Bug 1537549 [wpt PR 15932] - Fix splitting of git ls-tree output, a=testonly
[gecko.git] / config / config.mk
blob79bfc3a35fb9a9d701c0b81847d99a46001d2eb6
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/.
7 # config.mk
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!)
17 endif
18 INCLUDED_CONFIG_MK = 1
20 EXIT_ON_ERROR = set -e; # Shell loops continue past errors without this.
22 ifndef topsrcdir
23 topsrcdir = $(DEPTH)
24 endif
26 ifndef INCLUDED_AUTOCONF_MK
27 include $(DEPTH)/config/autoconf.mk
28 endif
30 -include $(DEPTH)/.mozconfig.mk
32 # MDDEPDIR is the subdirectory where dependency files are stored
33 MDDEPDIR := .deps
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
41 include backend.mk
42 endif
44 endif
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))
55 ifeq (.,$(__depth))
56 __depth :=
57 endif
58 $(foreach __d,$(__depth) .,$(eval __depth = $(wordlist 2,$(words $(__depth)),$(__depth))$(eval -include $(subst $(space),/,$(strip $(srcdir) $(__depth) defs.mk)))))
60 COMMA = ,
62 # Sanity check some variables
63 CHECK_VARS := \
64 XPI_NAME \
65 LIBRARY_NAME \
66 MODULE \
67 DEPTH \
68 XPI_PKGNAME \
69 INSTALL_EXTENSION_ID \
70 SHARED_LIBRARY_NAME \
71 SONAME \
72 STATIC_LIBRARY_NAME \
73 $(NULL)
75 # checks for internal spaces or trailing spaces in the variable
76 # named by $x
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
83 endif
85 RM = rm -f
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
89 # a moz.build file.
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)'
99 ifdef XPI_NAME
100 ACDEFINES += -DXPI_NAME=$(XPI_NAME)
101 endif
103 # The VERSION_NUMBER is suffixed onto the end of the DLLs we ship.
104 VERSION_NUMBER = 50
106 CONFIG_TOOLS = $(MOZ_BUILD_ROOT)/config
107 AUTOCONF_TOOLS = $(MOZILLA_DIR)/build/autoconf
109 CC := $(CC_WRAPPER) $(CC)
110 CXX := $(CXX_WRAPPER) $(CXX)
111 MKDIR ?= mkdir
112 SLEEP ?= sleep
113 TOUCH ?= touch
115 PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
118 # Build using PIC by default
120 _ENABLE_PIC=1
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
126 endif
128 # No sense in profiling unit tests
129 ifdef CPP_UNIT_TESTS
130 NO_PROFILE_GUIDED_OPTIMIZE = 1
131 endif
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))
139 AR_FLAGS += -LTCG
140 endif
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))
147 AR_FLAGS += -LTCG
148 endif
149 endif # MOZ_PROFILE_USE
150 endif # NO_PROFILE_GUIDED_OPTIMIZE
152 LOCALE_TOPDIR ?= $(topsrcdir)
153 MAKE_JARS_FLAGS = \
154 -t $(LOCALE_TOPDIR) \
155 -f $(MOZ_JAR_MAKER_FILE_FORMAT) \
156 $(NULL)
158 ifdef USE_EXTENSION_MANIFEST
159 MAKE_JARS_FLAGS += -e
160 endif
162 TAR_CREATE_FLAGS = -chf
165 # Default command macros; can be overridden in <arch>.mk.
167 CCC = $(CXX)
169 INCLUDES = \
170 -I$(srcdir) \
171 -I$(CURDIR) \
172 $(LOCAL_INCLUDES) \
173 -I$(ABS_DIST)/include \
174 $(NULL)
176 include $(MOZILLA_DIR)/config/static-checking-config.mk
178 ifndef MOZ_LTO
179 MOZ_LTO_CFLAGS :=
180 MOZ_LTO_LDFLAGS :=
181 endif
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)
197 ifdef MOZ_LTO
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
201 # dsymutil tool.
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
212 # linked binary.
213 LDFLAGS += -Wl,-object_path_lto,$(@F).lto.o/
214 endif
215 endif
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)
223 endif
224 endef
226 color_flags_vars := \
227 COMPILE_CFLAGS \
228 COMPILE_CXXFLAGS \
229 COMPILE_CMFLAGS \
230 COMPILE_CMMFLAGS \
231 LDFLAGS \
232 $(NULL)
234 ifdef MACH_STDOUT_ISATTY
235 ifdef COLOR_CFLAGS
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))))
241 endif
242 endif
243 endif
246 # Name of the binary code directories
248 # Override defaults
250 DEPENDENCIES = .md
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.
258 ifdef INCLUDE
259 export INCLUDE
260 endif
262 # Export to propagate to link.exe and submake for third-party code.
263 # Eventually, we'll want to just use -LIBPATH.
264 ifdef LIB
265 export LIB
266 endif
268 ifdef MOZ_USING_CCACHE
269 ifdef CLANG_CXX
270 export CCACHE_CPP2=1
271 endif
272 endif
274 ifdef CCACHE_PREFIX
275 export CCACHE_PREFIX
276 endif
278 # Set link flags according to whether we want a console.
279 ifeq ($(OS_ARCH),WINNT)
280 ifdef MOZ_WINCONSOLE
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)
285 endif
286 else
287 # For setting subsystem version
288 WIN32_EXE_LDFLAGS += $(WIN32_CONSOLE_EXE_LDFLAGS)
289 endif
290 endif # WINNT
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.
300 # (Bug 256180)
301 WIN32_EXE_LDFLAGS += -STACK:8388608
302 else
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
310 endif
311 endif
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)
320 ifndef NSDISTMODE
321 NSDISTMODE=absolute_symlink
322 endif
323 PWD := $(CURDIR)
324 endif
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)
329 else
330 NSINSTALL = $(DEPTH)/config/nsinstall$(HOST_BIN_SUFFIX)
331 endif # WINNT
334 ifeq (,$(CROSS_COMPILE)$(filter-out WINNT, $(OS_ARCH)))
335 INSTALL = $(NSINSTALL) -t
337 else
339 # This isn't laid out as conditional directives so that NSDISTMODE can be
340 # target-specific.
341 INSTALL = $(if $(filter absolute_symlink, $(NSDISTMODE)), $(NSINSTALL) -L $(PWD), $(NSINSTALL) -R)
343 endif # WINNT
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)))
369 ifdef relativesrcdir
370 LOCALE_RELATIVEDIR ?= $(relativesrcdir)
371 endif
373 ifdef LOCALE_RELATIVEDIR
374 LOCALE_SRCDIR ?= $(call EXPAND_LOCALE_SRCDIR,$(LOCALE_RELATIVEDIR))
375 endif
377 ifdef relativesrcdir
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)
382 endif
383 ifdef IS_LANGUAGE_REPACK
384 MAKE_JARS_FLAGS += --l10n-base=$(L10NBASEDIR)/$(AB_CD)
385 endif
386 else
387 MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
388 endif # en-US
389 else
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) )
409 else
410 MERGE_FILE = $(LOCALE_SRCDIR)/$(1)
411 MERGE_RELATIVE_FILE = $(call EXPAND_LOCALE_SRCDIR,$(2))/$(1)
412 endif
414 ifneq (WINNT,$(OS_ARCH))
415 RUN_TEST_PROGRAM = $(DIST)/bin/run-mozilla.sh
416 endif # ! WINNT
418 # autoconf.mk sets OBJ_SUFFIX to an error to avoid use before including
419 # this file
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
434 OBJ_SUFFIX := i_o
435 endif
436 endif
437 endif
439 PLY_INCLUDE = -I$(MOZILLA_DIR)/other-licenses/ply