Backed out 35 changesets (bug 941158, bug 972518, bug 959520, bug 986063, bug 948895...
[gecko.git] / config / config.mk
blob445b45f58acb1e8b5e0f075d62efb03befce0a4a
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 # Integrate with mozbuild-generated make files. We first verify that no
33 # variables provided by the automatically generated .mk files are
34 # present. If they are, this is a violation of the separation of
35 # responsibility between Makefile.in and mozbuild files.
36 _MOZBUILD_EXTERNAL_VARIABLES := \
37 ANDROID_GENERATED_RESFILES \
38 ANDROID_RES_DIRS \
39 CMSRCS \
40 CMMSRCS \
41 CPP_UNIT_TESTS \
42 DIRS \
43 EXTRA_PP_COMPONENTS \
44 EXTRA_PP_JS_MODULES \
45 FORCE_SHARED_LIB \
46 FORCE_STATIC_LIB \
47 FINAL_LIBRARY \
48 HOST_CSRCS \
49 HOST_CMMSRCS \
50 HOST_LIBRARY_NAME \
51 HOST_PROGRAM \
52 HOST_SIMPLE_PROGRAMS \
53 IS_COMPONENT \
54 JAVA_JAR_TARGETS \
55 JS_MODULES_PATH \
56 LIBRARY_NAME \
57 LIBXUL_LIBRARY \
58 MODULE \
59 MSVC_ENABLE_PGO \
60 NO_DIST_INSTALL \
61 PARALLEL_DIRS \
62 PROGRAM \
63 SDK_HEADERS \
64 SIMPLE_PROGRAMS \
65 TEST_DIRS \
66 TIERS \
67 TOOL_DIRS \
68 XPCSHELL_TESTS \
69 XPIDL_MODULE \
70 $(NULL)
72 _DEPRECATED_VARIABLES := \
73 ANDROID_RESFILES \
74 MOCHITEST_FILES_PARTS \
75 MOCHITEST_BROWSER_FILES_PARTS \
76 SHORT_LIBNAME \
77 $(NULL)
79 ifndef EXTERNALLY_MANAGED_MAKE_FILE
80 # Using $(firstword) may not be perfect. But it should be good enough for most
81 # scenarios.
82 _current_makefile = $(CURDIR)/$(firstword $(MAKEFILE_LIST))
84 $(foreach var,$(_MOZBUILD_EXTERNAL_VARIABLES),$(if $(filter file override,$(subst $(NULL) ,_,$(origin $(var)))),\
85 $(error Variable $(var) is defined in $(_current_makefile). It should only be defined in moz.build files),\
88 $(foreach var,$(_DEPRECATED_VARIABLES),$(if $(filter file override,$(subst $(NULL) ,_,$(origin $(var)))),\
89 $(error Variable $(var) is defined in $(_current_makefile). This variable has been deprecated. It does nothing. It must be removed in order to build)\
92 # Import the automatically generated backend file. If this file doesn't exist,
93 # the backend hasn't been properly configured. We want this to be a fatal
94 # error, hence not using "-include".
95 ifndef STANDALONE_MAKEFILE
96 GLOBAL_DEPS += backend.mk
97 include backend.mk
98 endif
100 # Freeze the values specified by moz.build to catch them if they fail.
102 $(foreach var,$(_MOZBUILD_EXTERNAL_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
103 $(foreach var,$(_DEPRECATED_VARIABLES),$(eval $(var)_FROZEN := '$($(var))'))
105 CHECK_MOZBUILD_VARIABLES = $(foreach var,$(_MOZBUILD_EXTERNAL_VARIABLES), \
106 $(if $(subst $($(var)_FROZEN),,'$($(var))'), \
107 $(error Variable $(var) is defined in $(_current_makefile). It should only be defined in moz.build files),\
108 )) $(foreach var,$(_DEPRECATED_VARIABLES), \
109 $(if $(subst $($(var)_FROZEN),,'$($(var))'), \
110 $(error Variable $(var) is defined in $(_current_makefile). This variable has been deprecated. It does nothing. It must be removed in order to build),\
113 endif
115 space = $(NULL) $(NULL)
117 # Include defs.mk files that can be found in $(srcdir)/$(DEPTH),
118 # $(srcdir)/$(DEPTH-1), $(srcdir)/$(DEPTH-2), etc., and $(srcdir)
119 # where $(DEPTH-1) is one level less of depth, $(DEPTH-2), two, etc.
120 # i.e. for DEPTH=../../.., DEPTH-1 is ../.. and DEPTH-2 is ..
121 # These defs.mk files are used to define variables in a directory
122 # and all its subdirectories, recursively.
123 __depth := $(subst /, ,$(DEPTH))
124 ifeq (.,$(__depth))
125 __depth :=
126 endif
127 $(foreach __d,$(__depth) .,$(eval __depth = $(wordlist 2,$(words $(__depth)),$(__depth))$(eval -include $(subst $(space),/,$(strip $(srcdir) $(__depth) defs.mk)))))
129 COMMA = ,
131 # Sanity check some variables
132 CHECK_VARS := \
133 XPI_NAME \
134 LIBRARY_NAME \
135 MODULE \
136 DEPTH \
137 XPI_PKGNAME \
138 INSTALL_EXTENSION_ID \
139 SHARED_LIBRARY_NAME \
140 STATIC_LIBRARY_NAME \
141 $(NULL)
143 # checks for internal spaces or trailing spaces in the variable
144 # named by $x
145 check-variable = $(if $(filter-out 0 1,$(words $($(x))z)),$(error Spaces are not allowed in $(x)))
147 $(foreach x,$(CHECK_VARS),$(check-variable))
149 ifndef INCLUDED_FUNCTIONS_MK
150 include $(topsrcdir)/config/makefiles/functions.mk
151 endif
153 RM = rm -f
155 # LIBXUL_DIST is not defined under js/src, thus we make it mean DIST there.
156 LIBXUL_DIST ?= $(DIST)
158 # FINAL_TARGET specifies the location into which we copy end-user-shipped
159 # build products (typelibs, components, chrome). It may already be specified by
160 # a moz.build file.
162 # If XPI_NAME is set, the files will be shipped to $(DIST)/xpi-stage/$(XPI_NAME)
163 # instead of $(DIST)/bin. In both cases, if DIST_SUBDIR is set, the files will be
164 # shipped to a $(DIST_SUBDIR) subdirectory.
165 FINAL_TARGET ?= $(if $(XPI_NAME),$(DIST)/xpi-stage/$(XPI_NAME),$(DIST)/bin)$(DIST_SUBDIR:%=/%)
166 # Override the stored value for the check to make sure that the variable is not
167 # redefined in the Makefile.in value.
168 FINAL_TARGET_FROZEN := '$(FINAL_TARGET)'
170 ifdef XPI_NAME
171 DEFINES += -DXPI_NAME=$(XPI_NAME)
172 endif
174 # The VERSION_NUMBER is suffixed onto the end of the DLLs we ship.
175 VERSION_NUMBER = 50
177 ifeq ($(HOST_OS_ARCH),WINNT)
178 win_srcdir := $(subst $(topsrcdir),$(WIN_TOP_SRC),$(srcdir))
179 BUILD_TOOLS = $(WIN_TOP_SRC)/build/unix
180 else
181 win_srcdir := $(srcdir)
182 BUILD_TOOLS = $(topsrcdir)/build/unix
183 endif
185 CONFIG_TOOLS = $(MOZ_BUILD_ROOT)/config
186 AUTOCONF_TOOLS = $(topsrcdir)/build/autoconf
188 # Disable MOZ_PSEUDO_DERECURSE when it contains no-pymake and we're running
189 # pymake. This can be removed when no-pymake is removed from the default in
190 # build/autoconf/compiler-opts.m4.
191 ifdef .PYMAKE
192 comma = ,
193 ifneq (,$(filter no-pymake,$(subst $(comma), ,$(MOZ_PSEUDO_DERECURSE))))
194 MOZ_PSEUDO_DERECURSE :=
195 endif
196 endif
198 # Disable MOZ_PSEUDO_DERECURSE on PGO builds until it's fixed.
199 ifneq (,$(MOZ_PROFILE_USE)$(MOZ_PROFILE_GENERATE))
200 MOZ_PSEUDO_DERECURSE :=
201 endif
204 # Strip off the excessively long version numbers on these platforms,
205 # but save the version to allow multiple versions of the same base
206 # platform to be built in the same tree.
208 ifneq (,$(filter FreeBSD HP-UX Linux NetBSD OpenBSD SunOS,$(OS_ARCH)))
209 OS_RELEASE := $(basename $(OS_RELEASE))
211 # Allow the user to ignore the OS_VERSION, which is usually irrelevant.
212 ifdef WANT_MOZILLA_CONFIG_OS_VERSION
213 OS_VERS := $(suffix $(OS_RELEASE))
214 OS_VERSION := $(shell echo $(OS_VERS) | sed 's/-.*//')
215 endif
217 endif
219 OS_CONFIG := $(OS_ARCH)$(OS_RELEASE)
221 ifdef _MSC_VER
222 CC_WRAPPER ?= $(call py_action,cl)
223 CXX_WRAPPER ?= $(call py_action,cl)
224 endif # _MSC_VER
226 CC := $(CC_WRAPPER) $(CC)
227 CXX := $(CXX_WRAPPER) $(CXX)
228 MKDIR ?= mkdir
229 SLEEP ?= sleep
230 TOUCH ?= touch
232 ifdef .PYMAKE
233 PYCOMMANDPATH += $(PYTHON_SITE_PACKAGES)
234 endif
236 PYTHON_PATH = $(PYTHON) $(topsrcdir)/config/pythonpath.py
238 # determine debug-related options
239 _DEBUG_ASFLAGS :=
240 _DEBUG_CFLAGS :=
241 _DEBUG_LDFLAGS :=
243 ifdef MOZ_DEBUG
244 _DEBUG_CFLAGS += $(MOZ_DEBUG_ENABLE_DEFS)
245 XULPPFLAGS += $(MOZ_DEBUG_ENABLE_DEFS)
246 else
247 _DEBUG_CFLAGS += $(MOZ_DEBUG_DISABLE_DEFS)
248 XULPPFLAGS += $(MOZ_DEBUG_DISABLE_DEFS)
249 endif
251 ifneq (,$(MOZ_DEBUG)$(MOZ_DEBUG_SYMBOLS))
252 ifeq ($(AS),yasm)
253 ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
254 _DEBUG_ASFLAGS += -g cv8
255 else
256 ifneq ($(OS_ARCH),Darwin)
257 _DEBUG_ASFLAGS += -g dwarf2
258 endif
259 endif
260 else
261 _DEBUG_ASFLAGS += $(MOZ_DEBUG_FLAGS)
262 endif
263 _DEBUG_CFLAGS += $(MOZ_DEBUG_FLAGS)
264 _DEBUG_LDFLAGS += $(MOZ_DEBUG_LDFLAGS)
265 endif
267 MOZALLOC_LIB = $(call EXPAND_LIBNAME_PATH,mozalloc,$(DIST)/lib)
269 ASFLAGS += $(_DEBUG_ASFLAGS)
270 OS_CFLAGS += $(_DEBUG_CFLAGS)
271 OS_CXXFLAGS += $(_DEBUG_CFLAGS)
272 OS_LDFLAGS += $(_DEBUG_LDFLAGS)
274 # XXX: What does this? Bug 482434 filed for better explanation.
275 ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
276 ifdef MOZ_DEBUG
277 ifneq (,$(MOZ_BROWSE_INFO)$(MOZ_BSCFILE))
278 OS_CFLAGS += -FR
279 OS_CXXFLAGS += -FR
280 endif
281 else # ! MOZ_DEBUG
283 # MOZ_DEBUG_SYMBOLS generates debug symbols in separate PDB files.
284 # Used for generating an optimized build with debugging symbols.
285 # Used in the Windows nightlies to generate symbols for crash reporting.
286 ifdef MOZ_DEBUG_SYMBOLS
287 OS_CXXFLAGS += -UDEBUG -DNDEBUG
288 OS_CFLAGS += -UDEBUG -DNDEBUG
289 ifdef HAVE_64BIT_OS
290 OS_LDFLAGS += -DEBUG -OPT:REF,ICF
291 else
292 OS_LDFLAGS += -DEBUG -OPT:REF
293 endif
294 endif
297 # Handle trace-malloc and DMD in optimized builds.
298 # No opt to give sane callstacks.
300 ifneq (,$(NS_TRACE_MALLOC)$(MOZ_DMD))
301 MOZ_OPTIMIZE_FLAGS=-Zi -Od -UDEBUG -DNDEBUG
302 ifdef HAVE_64BIT_OS
303 OS_LDFLAGS = -DEBUG -OPT:REF,ICF
304 else
305 OS_LDFLAGS = -DEBUG -OPT:REF
306 endif
307 endif # NS_TRACE_MALLOC || MOZ_DMD
309 endif # MOZ_DEBUG
311 # We don't build a static CRT when building a custom CRT,
312 # it appears to be broken. So don't link to jemalloc if
313 # the Makefile wants static CRT linking.
314 ifeq ($(MOZ_MEMORY)_$(USE_STATIC_LIBS),1_1)
315 # Disable default CRT libs and add the right lib path for the linker
316 MOZ_GLUE_LDFLAGS=
317 endif
319 endif # WINNT && !GNU_CC
321 ifdef MOZ_GLUE_PROGRAM_LDFLAGS
322 DEFINES += -DMOZ_GLUE_IN_PROGRAM
323 else
324 MOZ_GLUE_PROGRAM_LDFLAGS=$(MOZ_GLUE_LDFLAGS)
325 endif
328 # Build using PIC by default
330 _ENABLE_PIC=1
332 # Determine if module being compiled is destined
333 # to be merged into libxul
335 ifeq ($(FINAL_LIBRARY),xul)
336 ifdef LIBXUL_LIBRARY
337 $(error FINAL_LIBRARY is "xul", LIBXUL_LIBRARY is implied)
338 endif
339 LIBXUL_LIBRARY := 1
340 endif
342 ifdef LIBXUL_LIBRARY
343 ifdef IS_COMPONENT
344 $(error IS_COMPONENT is set, but is not compatible with LIBXUL_LIBRARY)
345 endif
346 FORCE_STATIC_LIB=1
347 endif
349 # If we are building this component into an extension/xulapp, it cannot be
350 # statically linked. In the future we may want to add a xulapp meta-component
351 # build option.
353 ifdef XPI_NAME
354 ifdef IS_COMPONENT
355 EXPORT_LIBRARY=
356 FORCE_STATIC_LIB=
357 FORCE_SHARED_LIB=1
358 endif
359 endif
361 ifndef SHARED_LIBRARY_NAME
362 ifdef LIBRARY_NAME
363 SHARED_LIBRARY_NAME=$(LIBRARY_NAME)
364 endif
365 endif
367 ifndef STATIC_LIBRARY_NAME
368 ifdef LIBRARY_NAME
369 STATIC_LIBRARY_NAME=$(LIBRARY_NAME)
370 endif
371 endif
373 # PGO on MSVC is opt-in
374 ifdef _MSC_VER
375 ifndef MSVC_ENABLE_PGO
376 NO_PROFILE_GUIDED_OPTIMIZE = 1
377 endif
378 endif
380 # No sense in profiling tools
381 ifdef INTERNAL_TOOLS
382 NO_PROFILE_GUIDED_OPTIMIZE = 1
383 endif
385 # Don't build SIMPLE_PROGRAMS with PGO, since they don't need it anyway,
386 # and we don't have the same build logic to re-link them in the second pass.
387 ifdef SIMPLE_PROGRAMS
388 NO_PROFILE_GUIDED_OPTIMIZE = 1
389 endif
391 # No sense in profiling unit tests
392 ifdef CPP_UNIT_TESTS
393 NO_PROFILE_GUIDED_OPTIMIZE = 1
394 endif
396 # Enable profile-based feedback
397 ifneq (1,$(NO_PROFILE_GUIDED_OPTIMIZE))
398 ifdef MOZ_PROFILE_GENERATE
399 OS_CFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_GEN_CFLAGS))
400 OS_CXXFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_GEN_CFLAGS))
401 OS_LDFLAGS += $(PROFILE_GEN_LDFLAGS)
402 ifeq (WINNT,$(OS_ARCH))
403 AR_FLAGS += -LTCG
404 endif
405 endif # MOZ_PROFILE_GENERATE
407 ifdef MOZ_PROFILE_USE
408 OS_CFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_USE_CFLAGS))
409 OS_CXXFLAGS += $(if $(filter $(notdir $<),$(notdir $(NO_PROFILE_GUIDED_OPTIMIZE))),,$(PROFILE_USE_CFLAGS))
410 OS_LDFLAGS += $(PROFILE_USE_LDFLAGS)
411 ifeq (WINNT,$(OS_ARCH))
412 AR_FLAGS += -LTCG
413 endif
414 endif # MOZ_PROFILE_USE
415 endif # NO_PROFILE_GUIDED_OPTIMIZE
418 # Does the makefile specifies the internal XPCOM API linkage?
419 ifneq (,$(MOZILLA_INTERNAL_API)$(LIBXUL_LIBRARY))
420 DEFINES += -DMOZILLA_INTERNAL_API
421 endif
423 # Force XPCOM/widget/gfx methods to be _declspec(dllexport) when we're
424 # building libxul libraries
425 ifdef LIBXUL_LIBRARY
426 DEFINES += \
427 -DIMPL_LIBXUL \
428 $(NULL)
430 ifndef JS_SHARED_LIBRARY
431 DEFINES += -DSTATIC_EXPORTABLE_JS_API
432 endif
433 endif
435 MAKE_JARS_FLAGS = \
436 -t $(topsrcdir) \
437 -f $(MOZ_CHROME_FILE_FORMAT) \
438 $(NULL)
440 ifdef USE_EXTENSION_MANIFEST
441 MAKE_JARS_FLAGS += -e
442 endif
444 ifdef BOTH_MANIFESTS
445 MAKE_JARS_FLAGS += --both-manifests
446 endif
448 TAR_CREATE_FLAGS = -chf
450 ifeq ($(OS_ARCH),OS2)
451 TAR_CREATE_FLAGS = -cf
452 endif
455 # Personal makefile customizations go in these optional make include files.
457 MY_CONFIG := $(DEPTH)/config/myconfig.mk
458 MY_RULES := $(DEPTH)/config/myrules.mk
461 # Default command macros; can be overridden in <arch>.mk.
463 CCC = $(CXX)
465 # Java macros
466 JAVA_GEN_DIR = _javagen
467 JAVA_DIST_DIR = $(DEPTH)/$(JAVA_GEN_DIR)
468 JAVA_IFACES_PKG_NAME = org/mozilla/interfaces
470 OS_INCLUDES += $(MOZ_JPEG_CFLAGS) $(MOZ_PNG_CFLAGS) $(MOZ_ZLIB_CFLAGS)
472 # NSPR_CFLAGS and NSS_CFLAGS must appear ahead of OS_INCLUDES to avoid Linux
473 # builds wrongly picking up system NSPR/NSS header files.
474 INCLUDES = \
475 -I$(srcdir) \
476 -I. \
477 $(LOCAL_INCLUDES) \
478 -I$(DIST)/include \
479 $(if $(LIBXUL_SDK),-I$(LIBXUL_SDK)/include) \
480 $(NSPR_CFLAGS) $(NSS_CFLAGS) \
481 $(OS_INCLUDES) \
482 $(NULL)
484 include $(topsrcdir)/config/static-checking-config.mk
486 CFLAGS = $(OS_CPPFLAGS) $(OS_CFLAGS)
487 CXXFLAGS = $(OS_CPPFLAGS) $(OS_CXXFLAGS)
488 LDFLAGS = $(OS_LDFLAGS) $(MOZ_FIX_LINK_PATHS)
490 # Allow each module to override the *default* optimization settings
491 # by setting MODULE_OPTIMIZE_FLAGS if the developer has not given
492 # arguments to --enable-optimize
493 ifdef MOZ_OPTIMIZE
494 ifeq (1,$(MOZ_OPTIMIZE))
495 ifdef MODULE_OPTIMIZE_FLAGS
496 CFLAGS += $(MODULE_OPTIMIZE_FLAGS)
497 CXXFLAGS += $(MODULE_OPTIMIZE_FLAGS)
498 else
499 ifneq (,$(if $(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE),$(MOZ_PGO_OPTIMIZE_FLAGS)))
500 CFLAGS += $(MOZ_PGO_OPTIMIZE_FLAGS)
501 CXXFLAGS += $(MOZ_PGO_OPTIMIZE_FLAGS)
502 else
503 CFLAGS += $(MOZ_OPTIMIZE_FLAGS)
504 CXXFLAGS += $(MOZ_OPTIMIZE_FLAGS)
505 endif # neq (,$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
506 endif # MODULE_OPTIMIZE_FLAGS
507 else
508 CFLAGS += $(MOZ_OPTIMIZE_FLAGS)
509 CXXFLAGS += $(MOZ_OPTIMIZE_FLAGS)
510 endif # MOZ_OPTIMIZE == 1
511 LDFLAGS += $(MOZ_OPTIMIZE_LDFLAGS)
512 endif # MOZ_OPTIMIZE
514 ifdef CROSS_COMPILE
515 HOST_CFLAGS += $(HOST_OPTIMIZE_FLAGS)
516 else
517 ifdef MOZ_OPTIMIZE
518 ifeq (1,$(MOZ_OPTIMIZE))
519 ifdef MODULE_OPTIMIZE_FLAGS
520 HOST_CFLAGS += $(MODULE_OPTIMIZE_FLAGS)
521 else
522 HOST_CFLAGS += $(MOZ_OPTIMIZE_FLAGS)
523 endif # MODULE_OPTIMIZE_FLAGS
524 else
525 HOST_CFLAGS += $(MOZ_OPTIMIZE_FLAGS)
526 endif # MOZ_OPTIMIZE == 1
527 endif # MOZ_OPTIMIZE
528 endif # CROSS_COMPILE
530 CFLAGS += $(MOZ_FRAMEPTR_FLAGS)
531 CXXFLAGS += $(MOZ_FRAMEPTR_FLAGS)
533 # Check for FAIL_ON_WARNINGS & FAIL_ON_WARNINGS_DEBUG (Shorthand for Makefiles
534 # to request that we use the 'warnings as errors' compile flags)
536 # NOTE: First, we clear FAIL_ON_WARNINGS[_DEBUG] if we're doing a Windows PGO
537 # build, since WARNINGS_AS_ERRORS has been suspected of causing isuses in that
538 # situation. (See bug 437002.)
539 ifeq (WINNT_1,$(OS_ARCH)_$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
540 FAIL_ON_WARNINGS_DEBUG=
541 FAIL_ON_WARNINGS=
542 endif # WINNT && (MOS_PROFILE_GENERATE ^ MOZ_PROFILE_USE)
544 # Now, check for debug version of flag; it turns on normal flag in debug builds.
545 ifdef FAIL_ON_WARNINGS_DEBUG
546 ifdef MOZ_DEBUG
547 FAIL_ON_WARNINGS = 1
548 endif # MOZ_DEBUG
549 endif # FAIL_ON_WARNINGS_DEBUG
551 # Check for normal version of flag, and add WARNINGS_AS_ERRORS if it's set to 1.
552 ifdef FAIL_ON_WARNINGS
553 CXXFLAGS += $(WARNINGS_AS_ERRORS)
554 CFLAGS += $(WARNINGS_AS_ERRORS)
555 endif # FAIL_ON_WARNINGS
557 ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_)
558 #// Currently, unless USE_STATIC_LIBS is defined, the multithreaded
559 #// DLL version of the RTL is used...
561 #//------------------------------------------------------------------------
562 ifdef USE_STATIC_LIBS
563 RTL_FLAGS=-MT # Statically linked multithreaded RTL
564 ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC)$(MOZ_DMD))
565 ifndef MOZ_NO_DEBUG_RTL
566 RTL_FLAGS=-MTd # Statically linked multithreaded MSVC4.0 debug RTL
567 endif
568 endif # MOZ_DEBUG || NS_TRACE_MALLOC || MOZ_DMD
570 else # !USE_STATIC_LIBS
572 RTL_FLAGS=-MD # Dynamically linked, multithreaded RTL
573 ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC)$(MOZ_DMD))
574 ifndef MOZ_NO_DEBUG_RTL
575 RTL_FLAGS=-MDd # Dynamically linked, multithreaded MSVC4.0 debug RTL
576 endif
577 endif # MOZ_DEBUG || NS_TRACE_MALLOC || MOZ_DMD
578 endif # USE_STATIC_LIBS
579 endif # WINNT && !GNU_CC
581 ifeq ($(OS_ARCH),Darwin)
582 # Compiling ObjC requires an Apple compiler anyway, so it's ok to set
583 # host CMFLAGS here.
584 HOST_CMFLAGS += -fobjc-exceptions
585 HOST_CMMFLAGS += -fobjc-exceptions
586 OS_COMPILE_CMFLAGS += -fobjc-exceptions
587 OS_COMPILE_CMMFLAGS += -fobjc-exceptions
588 ifeq ($(MOZ_WIDGET_TOOLKIT),uikit)
589 OS_COMPILE_CMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
590 OS_COMPILE_CMMFLAGS += -fobjc-abi-version=2 -fobjc-legacy-dispatch
591 endif
592 endif
594 COMPILE_CFLAGS = $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_CPPFLAGS) $(OS_COMPILE_CFLAGS) $(CFLAGS)
595 COMPILE_CXXFLAGS = $(STL_FLAGS) $(VISIBILITY_FLAGS) $(DEFINES) $(INCLUDES) $(DSO_CFLAGS) $(DSO_PIC_CFLAGS) $(RTL_FLAGS) $(OS_CPPFLAGS) $(OS_COMPILE_CXXFLAGS) $(CXXFLAGS)
596 COMPILE_CMFLAGS = $(OS_COMPILE_CMFLAGS)
597 COMPILE_CMMFLAGS = $(OS_COMPILE_CMMFLAGS)
599 ifndef CROSS_COMPILE
600 HOST_CFLAGS += $(RTL_FLAGS)
601 endif
604 # Name of the binary code directories
606 # Override defaults
608 # We need to know where to find the libraries we
609 # put on the link line for binaries, and should
610 # we link statically or dynamic? Assuming dynamic for now.
612 ifneq (WINNT_,$(OS_ARCH)_$(GNU_CC))
613 LIBS_DIR = -L$(DIST)/bin -L$(DIST)/lib
614 ifdef LIBXUL_SDK
615 LIBS_DIR += -L$(LIBXUL_SDK)/bin -L$(LIBXUL_SDK)/lib
616 endif
617 endif
619 # Default location of include files
620 ifndef LIBXUL_SDK
621 IDL_PARSER_DIR = $(topsrcdir)/xpcom/idl-parser
622 IDL_PARSER_CACHE_DIR = $(DEPTH)/xpcom/idl-parser
623 else
624 IDL_PARSER_DIR = $(LIBXUL_SDK)/sdk/bin
625 IDL_PARSER_CACHE_DIR = $(LIBXUL_SDK)/sdk/bin
626 endif
628 SDK_LIB_DIR = $(DIST)/sdk/lib
629 SDK_BIN_DIR = $(DIST)/sdk/bin
631 DEPENDENCIES = .md
633 MOZ_COMPONENT_LIBS=$(XPCOM_LIBS) $(MOZ_COMPONENT_NSPR_LIBS)
635 ifdef MACOSX_DEPLOYMENT_TARGET
636 export MACOSX_DEPLOYMENT_TARGET
637 endif # MACOSX_DEPLOYMENT_TARGET
639 ifdef MOZ_USING_CCACHE
640 ifdef CLANG_CXX
641 export CCACHE_CPP2=1
642 endif
643 endif
645 # Set link flags according to whether we want a console.
646 ifdef MOZ_WINCONSOLE
647 ifeq ($(MOZ_WINCONSOLE),1)
648 ifeq ($(OS_ARCH),OS2)
649 BIN_FLAGS += -Zlinker -PM:VIO
650 endif
651 ifeq ($(OS_ARCH),WINNT)
652 ifdef GNU_CC
653 WIN32_EXE_LDFLAGS += -mconsole
654 else
655 WIN32_EXE_LDFLAGS += -SUBSYSTEM:CONSOLE
656 endif
657 endif
658 else # MOZ_WINCONSOLE
659 ifeq ($(OS_ARCH),OS2)
660 BIN_FLAGS += -Zlinker -PM:PM
661 endif
662 ifeq ($(OS_ARCH),WINNT)
663 ifdef GNU_CC
664 WIN32_EXE_LDFLAGS += -mwindows
665 else
666 WIN32_EXE_LDFLAGS += -SUBSYSTEM:WINDOWS
667 endif
668 endif
669 endif
670 endif
672 ifdef _MSC_VER
673 ifeq ($(CPU_ARCH),x86_64)
674 # set stack to 2MB on x64 build. See bug 582910
675 WIN32_EXE_LDFLAGS += -STACK:2097152
676 endif
677 endif
679 # If we're building a component on MSVC, we don't want to generate an
680 # import lib, because that import lib will collide with the name of a
681 # static version of the same library.
682 ifeq ($(GNU_LD)$(OS_ARCH),WINNT)
683 ifdef IS_COMPONENT
684 LDFLAGS += -IMPLIB:fake.lib
685 DELETE_AFTER_LINK = fake.lib fake.exp
686 endif
687 endif
690 # Include any personal overrides the user might think are needed.
692 -include $(topsrcdir)/$(MOZ_BUILD_APP)/app-config.mk
693 -include $(MY_CONFIG)
695 ######################################################################
697 GARBAGE += $(DEPENDENCIES) core $(wildcard core.[0-9]*) $(wildcard *.err) $(wildcard *.pure) $(wildcard *_pure_*.o) Templates.DB
699 ifeq ($(OS_ARCH),Darwin)
700 ifndef NSDISTMODE
701 NSDISTMODE=absolute_symlink
702 endif
703 PWD := $(CURDIR)
704 endif
706 NSINSTALL_PY := $(PYTHON) $(abspath $(topsrcdir)/config/nsinstall.py)
707 # For Pymake, wherever we use nsinstall.py we're also going to try to make it
708 # a native command where possible. Since native commands can't be used outside
709 # of single-line commands, we continue to provide INSTALL for general use.
710 # Single-line commands should be switched over to install_cmd.
711 NSINSTALL_NATIVECMD := %nsinstall nsinstall
713 ifdef NSINSTALL_BIN
714 NSINSTALL = $(NSINSTALL_BIN)
715 else
716 ifeq (OS2,$(CROSS_COMPILE)$(OS_ARCH))
717 NSINSTALL = $(MOZ_TOOLS_DIR)/nsinstall
718 else
719 ifeq ($(HOST_OS_ARCH),WINNT)
720 NSINSTALL = $(NSINSTALL_PY)
721 else
722 NSINSTALL = $(CONFIG_TOOLS)/nsinstall$(HOST_BIN_SUFFIX)
723 endif # WINNT
724 endif # OS2
725 endif # NSINSTALL_BIN
728 ifeq (,$(CROSS_COMPILE)$(filter-out WINNT OS2, $(OS_ARCH)))
729 INSTALL = $(NSINSTALL) -t
730 ifdef .PYMAKE
731 install_cmd = $(NSINSTALL_NATIVECMD) -t $(1)
732 endif # .PYMAKE
734 else
736 # This isn't laid out as conditional directives so that NSDISTMODE can be
737 # target-specific.
738 INSTALL = $(if $(filter copy, $(NSDISTMODE)), $(NSINSTALL) -t, $(if $(filter absolute_symlink, $(NSDISTMODE)), $(NSINSTALL) -L $(PWD), $(NSINSTALL) -R))
740 endif # WINNT/OS2
742 # The default for install_cmd is simply INSTALL
743 install_cmd ?= $(INSTALL) $(1)
745 # Use nsinstall in copy mode to install files on the system
746 SYSINSTALL = $(NSINSTALL) -t
747 # This isn't necessarily true, just here
748 sysinstall_cmd = install_cmd
751 # Localization build automation
754 # Because you might wish to "make locales AB_CD=ab-CD", we don't hardcode
755 # MOZ_UI_LOCALE directly, but use an intermediate variable that can be
756 # overridden by the command line. (Besides, AB_CD is prettier).
757 AB_CD = $(MOZ_UI_LOCALE)
759 ifndef L10NBASEDIR
760 L10NBASEDIR = $(error L10NBASEDIR not defined by configure)
761 else
762 IS_LANGUAGE_REPACK = 1
763 endif
765 EXPAND_LOCALE_SRCDIR = $(if $(filter en-US,$(AB_CD)),$(topsrcdir)/$(1)/en-US,$(or $(realpath $(L10NBASEDIR)),$(abspath $(L10NBASEDIR)))/$(AB_CD)/$(subst /locales,,$(1)))
767 ifdef relativesrcdir
768 LOCALE_SRCDIR ?= $(call EXPAND_LOCALE_SRCDIR,$(relativesrcdir))
769 endif
771 ifdef relativesrcdir
772 MAKE_JARS_FLAGS += --relativesrcdir=$(relativesrcdir)
773 ifneq (en-US,$(AB_CD))
774 ifdef LOCALE_MERGEDIR
775 MAKE_JARS_FLAGS += --locale-mergedir=$(LOCALE_MERGEDIR)
776 endif
777 ifdef IS_LANGUAGE_REPACK
778 MAKE_JARS_FLAGS += --l10n-base=$(L10NBASEDIR)/$(AB_CD)
779 endif
780 else
781 MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
782 endif # en-US
783 else
784 MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
785 endif # ! relativesrcdir
787 ifdef LOCALE_MERGEDIR
788 MERGE_FILE = $(firstword \
789 $(wildcard $(LOCALE_MERGEDIR)/$(subst /locales,,$(relativesrcdir))/$(1)) \
790 $(wildcard $(LOCALE_SRCDIR)/$(1)) \
791 $(srcdir)/en-US/$(1) )
792 else
793 MERGE_FILE = $(LOCALE_SRCDIR)/$(1)
794 endif
795 MERGE_FILES = $(foreach f,$(1),$(call MERGE_FILE,$(f)))
797 ifeq (OS2,$(OS_ARCH))
798 RUN_TEST_PROGRAM = $(topsrcdir)/build/os2/test_os2.cmd '$(LIBXUL_DIST)'
799 else
800 ifneq (WINNT,$(OS_ARCH))
801 RUN_TEST_PROGRAM = $(LIBXUL_DIST)/bin/run-mozilla.sh
802 endif # ! WINNT
803 endif # ! OS2
806 # Java macros
809 # Make sure any compiled classes work with at least JVM 1.4
810 JAVAC_FLAGS += -source 1.4
812 ifdef MOZ_DEBUG
813 JAVAC_FLAGS += -g
814 endif
816 CREATE_PRECOMPLETE_CMD = $(PYTHON) $(abspath $(topsrcdir)/config/createprecomplete.py)
818 # MDDEPDIR is the subdirectory where dependency files are stored
819 MDDEPDIR := .deps
821 EXPAND_LIBS_EXEC = $(PYTHON) $(topsrcdir)/config/expandlibs_exec.py $(if $@,--depend $(MDDEPDIR)/$@.pp --target $@)
822 EXPAND_LIBS_GEN = $(PYTHON) $(topsrcdir)/config/expandlibs_gen.py $(if $@,--depend $(MDDEPDIR)/$@.pp)
823 EXPAND_AR = $(EXPAND_LIBS_EXEC) --extract -- $(AR)
824 EXPAND_CC = $(EXPAND_LIBS_EXEC) --uselist -- $(CC)
825 EXPAND_CCC = $(EXPAND_LIBS_EXEC) --uselist -- $(CCC)
826 EXPAND_LD = $(EXPAND_LIBS_EXEC) --uselist -- $(LD)
827 EXPAND_MKSHLIB_ARGS = --uselist
828 ifdef SYMBOL_ORDER
829 EXPAND_MKSHLIB_ARGS += --symbol-order $(SYMBOL_ORDER)
830 endif
831 EXPAND_MKSHLIB = $(EXPAND_LIBS_EXEC) $(EXPAND_MKSHLIB_ARGS) -- $(MKSHLIB)
833 ifneq (,$(MOZ_LIBSTDCXX_TARGET_VERSION)$(MOZ_LIBSTDCXX_HOST_VERSION))
834 ifneq ($(OS_ARCH),Darwin)
835 CHECK_STDCXX = @$(TOOLCHAIN_PREFIX)objdump -p $(1) | grep -e 'GLIBCXX_3\.4\.\(9\|[1-9][0-9]\)' > /dev/null && echo 'TEST-UNEXPECTED-FAIL | check_stdcxx | We do not want these libstdc++ symbols to be used:' && $(TOOLCHAIN_PREFIX)objdump -T $(1) | grep -e 'GLIBCXX_3\.4\.\(9\|[1-9][0-9]\)' && false || true
836 endif
838 ifdef MOZ_LIBSTDCXX_TARGET_VERSION
839 EXTRA_LIBS += $(call EXPAND_LIBNAME_PATH,stdc++compat,$(DEPTH)/build/unix/stdc++compat)
840 endif
841 ifdef MOZ_LIBSTDCXX_HOST_VERSION
842 HOST_EXTRA_LIBS += $(call EXPAND_LIBNAME_PATH,host_stdc++compat,$(DEPTH)/build/unix/stdc++compat)
843 endif
844 endif
846 ifeq (,$(filter $(OS_TARGET),WINNT Darwin OS2))
847 CHECK_TEXTREL = @$(TOOLCHAIN_PREFIX)readelf -d $(1) | grep TEXTREL > /dev/null && echo 'TEST-UNEXPECTED-FAIL | check_textrel | We do not want text relocations in libraries and programs' || true
848 endif
850 define CHECK_BINARY
851 $(call CHECK_STDCXX,$(1))
852 $(call CHECK_TEXTREL,$(1))
853 endef
855 # autoconf.mk sets OBJ_SUFFIX to an error to avoid use before including
856 # this file
857 OBJ_SUFFIX := $(_OBJ_SUFFIX)
859 # PGO builds with GCC build objects with instrumentation in a first pass,
860 # then objects optimized, without instrumentation, in a second pass. If
861 # we overwrite the ojects from the first pass with those from the second,
862 # we end up not getting instrumentation data for better optimization on
863 # incremental builds. As a consequence, we use a different object suffix
864 # for the first pass.
865 ifndef NO_PROFILE_GUIDED_OPTIMIZE
866 ifdef MOZ_PROFILE_GENERATE
867 ifdef GNU_CC
868 OBJ_SUFFIX := i_o
869 endif
870 endif
871 endif
873 # EXPAND_LIBNAME - $(call EXPAND_LIBNAME,foo)
874 # expands to $(LIB_PREFIX)foo.$(LIB_SUFFIX) or -lfoo, depending on linker
875 # arguments syntax. Should only be used for system libraries
877 # EXPAND_LIBNAME_PATH - $(call EXPAND_LIBNAME_PATH,foo,dir)
878 # expands to dir/$(LIB_PREFIX)foo.$(LIB_SUFFIX)
880 # EXPAND_MOZLIBNAME - $(call EXPAND_MOZLIBNAME,foo)
881 # expands to $(DIST)/lib/$(LIB_PREFIX)foo.$(LIB_SUFFIX)
883 ifdef GNU_CC
884 EXPAND_LIBNAME = $(addprefix -l,$(1))
885 else
886 EXPAND_LIBNAME = $(foreach lib,$(1),$(LIB_PREFIX)$(lib).$(LIB_SUFFIX))
887 endif
888 EXPAND_LIBNAME_PATH = $(foreach lib,$(1),$(2)/$(LIB_PREFIX)$(lib).$(LIB_SUFFIX))
889 EXPAND_MOZLIBNAME = $(foreach lib,$(1),$(DIST)/lib/$(LIB_PREFIX)$(lib).$(LIB_SUFFIX))
891 PLY_INCLUDE = -I$(topsrcdir)/other-licenses/ply
893 export CL_INCLUDES_PREFIX
895 ifdef MOZ_GTK2_CFLAGS
896 MOZ_GTK2_CFLAGS := -I$(topsrcdir)/widget/gtk/compat $(MOZ_GTK2_CFLAGS)
897 endif
899 DEFINES += -DNO_NSPR_10_SUPPORT