nss: upgrade to release 3.73
[LibreOffice.git] / solenv / gbuild / platform / com_GCC_defs.mk
blobc369235275bcb197275fcc536f2cf09eb203adb5
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 gb_AWK := awk
12 gb_CLASSPATHSEP := :
13 gb_LICENSE := LICENSE
14 gb_README = README_$(1)
16 # use CC/CXX if they are nondefaults
17 ifneq ($(origin CC),default)
18 gb_CC := $(CC)
19 gb_GCCP := $(CC)
20 else
21 gb_CC := gcc
22 gb_GCCP := gcc
23 endif
25 ifneq ($(origin CXX),default)
26 gb_CXX := $(CXX)
27 else
28 gb_CXX := g++
29 endif
31 ifneq ($(origin AR),default)
32 gb_AR := $(AR)
33 else
34 gb_AR := $(shell $(CC) -print-prog-name=ar)
35 endif
37 # shell setup (env.vars) for the compiler
38 gb_COMPILER_SETUP :=
40 ifeq ($(strip $(gb_COMPILEROPTFLAGS)),)
41 gb_COMPILEROPTFLAGS := -O2
42 endif
44 gb_CPPU_ENV := gcc3
46 gb_AFLAGS := $(AFLAGS)
48 gb_COMPILERDEFS := \
49 -DBOOST_ERROR_CODE_HEADER_ONLY \
50 -DBOOST_SYSTEM_NO_DEPRECATED \
51 -DCPPU_ENV=$(gb_CPPU_ENV) \
53 gb_CFLAGS_COMMON := \
54 -Wall \
55 -Wendif-labels \
56 -Wextra \
57 -Wstrict-prototypes \
58 -Wundef \
59 -Wunreachable-code \
60 $(if $(or $(and $(COM_IS_CLANG),$(or $(findstring icecc,$(CC)),$(findstring icecc,$(CCACHE_PREFIX)))),$(findstring sccache,$(CC))),,-Wunused-macros) \
61 $(if $(COM_IS_CLANG),-Wembedded-directive) \
62 -finput-charset=UTF-8 \
63 -fmessage-length=0 \
64 -fno-common \
65 -pipe \
66 -fstack-protector-strong \
67 $(if $(gb_COLOR),-fdiagnostics-color=always) \
69 gb_CXXFLAGS_COMMON := \
70 -Wall \
71 -Wno-missing-braces \
72 -Wnon-virtual-dtor \
73 -Wendif-labels \
74 -Wextra \
75 -Wundef \
76 -Wunreachable-code \
77 $(if $(or $(and $(COM_IS_CLANG),$(or $(findstring icecc,$(CXX)),$(findstring icecc,$(CCACHE_PREFIX)))),$(findstring sccache,$(CXX))),,-Wunused-macros) \
78 $(if $(COM_IS_CLANG),-Wembedded-directive) \
79 -finput-charset=UTF-8 \
80 -fmessage-length=0 \
81 -fno-common \
82 -pipe \
83 -fstack-protector-strong \
84 $(if $(gb_COLOR),-fdiagnostics-color=always) \
86 ifeq ($(HAVE_WDEPRECATED_COPY_DTOR),TRUE)
87 gb_CXXFLAGS_COMMON += -Wdeprecated-copy-dtor
88 endif
90 gb_CXXFLAGS_DISABLE_WARNINGS = -w
92 ifeq ($(HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED),TRUE)
93 gb_CXXFLAGS_COMMON += -Wno-maybe-uninitialized
94 endif
96 gb_CXXFLAGS_Wundef = -Wno-undef
98 ifeq ($(strip $(gb_GCOV)),YES)
99 gb_CFLAGS_COMMON += -fprofile-arcs -ftest-coverage
100 gb_CXXFLAGS_COMMON += -fprofile-arcs -ftest-coverage
101 gb_LinkTarget_LDFLAGS += -fprofile-arcs -lgcov
102 gb_COMPILEROPTFLAGS := -O0
103 endif
105 ifeq ($(DISABLE_DYNLOADING),TRUE)
106 gb_CFLAGS_COMMON += -ffunction-sections -fdata-sections
107 gb_CXXFLAGS_COMMON += -ffunction-sections -fdata-sections
108 gb_LinkTarget_LDFLAGS += -Wl,--gc-sections
109 endif
111 ifeq ($(COM_IS_CLANG),TRUE)
112 gb_CXXFLAGS_COMMON += \
113 -Wimplicit-fallthrough \
114 -Wunused-exception-parameter \
115 -Wrange-loop-analysis
116 else
117 gb_CFLAGS_COMMON += \
118 -Wduplicated-cond \
119 -Wlogical-op \
120 -Wshift-overflow=2
121 gb_CXXFLAGS_COMMON += \
122 -Wduplicated-cond \
123 -Wlogical-op \
124 -Wshift-overflow=2 \
125 -Wunused-const-variable=1
126 endif
128 # GCC 8 -Wcast-function-type (included in -Wextra) unhelpfully even warns on reinterpret_cast
129 # between incompatible function types:
130 ifeq ($(shell expr '$(GCC_VERSION)' '>=' 800),1)
131 gb_CXXFLAGS_COMMON += \
132 -Wno-cast-function-type
133 endif
135 # If CC or CXX already include -fvisibility=hidden, don't duplicate it
136 ifeq (,$(filter -fvisibility=hidden,$(CC)))
137 gb_VISIBILITY_FLAGS := -fvisibility=hidden
138 endif
139 gb_VISIBILITY_FLAGS_CXX := -fvisibility-inlines-hidden
140 gb_CXXFLAGS_COMMON += $(gb_VISIBILITY_FLAGS_CXX)
142 gb_LinkTarget_LDFLAGS += -fstack-protector-strong
144 ifneq ($(gb_ENABLE_PCH),)
145 ifeq ($(COM_IS_CLANG),TRUE)
146 # Clang by default includes in the PCH timestamps of the files it was
147 # generated from, which would make the PCH be a "new" file for ccache
148 # even if the file has not actually changed. Disabling the timestamp
149 # prevents this at the cost of risking using an outdated PCH (which
150 # should be unlikely, given that gbuild has dependencies set up
151 # for our includes and system includes are unlikely to change).
152 gb_NO_PCH_TIMESTAMP := -Xclang -fno-pch-timestamp
153 else
154 gb_CFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
155 gb_CXXFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
156 gb_NO_PCH_TIMESTAMP :=
157 endif
158 endif
160 gb_CFLAGS_WERROR = $(if $(ENABLE_WERROR),-Werror)
161 ifeq ($(ENABLE_OPTIMIZED)-$(COM_IS_CLANG),TRUE-)
162 gb_CFLAGS_WERROR += -Wno-stringop-overflow
163 endif
165 # This is the default in non-C++11 mode
166 ifeq ($(COM_IS_CLANG),TRUE)
167 gb_CXX03FLAGS := -std=gnu++98 -Werror=c++11-extensions -Wno-c++11-long-long \
168 -Wno-deprecated-declarations
169 else
170 gb_CXX03FLAGS := -std=gnu++98 -Wno-long-long \
171 -Wno-variadic-macros -Wno-non-virtual-dtor -Wno-deprecated-declarations
172 endif
174 # On Windows MSVC only supports C90 so force gnu89 (especially in clang) to
175 # to catch potential gnu89/C90 incompatibilities locally.
176 gb_CFLAGS_COMMON += -std=gnu89
178 ifeq ($(ENABLE_LTO),TRUE)
179 ifeq ($(COM_IS_CLANG),TRUE)
180 ifneq (,$(index,iOS MACOSX,$(OS)))
181 gb_LTOFLAGS := -flto=thin
182 else
183 gb_LTOFLAGS := -flto
184 gb_LTOPLUGINFLAGS := --plugin LLVMgold.so
185 endif
186 else
187 gb_LTOFLAGS := -flto$(if $(filter-out 0,$(PARALLELISM)),=$(PARALLELISM)) -fuse-linker-plugin -O2
188 endif
189 endif
191 gb_LinkTarget_EXCEPTIONFLAGS := \
192 -DEXCEPTIONS_ON \
193 -fexceptions
195 ifeq ($(gb_ENABLE_DBGUTIL),$(false))
196 # Clang doesn't have this option
197 ifeq ($(HAVE_GCC_FNO_ENFORCE_EH_SPECS),TRUE)
198 gb_LinkTarget_EXCEPTIONFLAGS += \
199 -fno-enforce-eh-specs
200 gb_FilterOutClangCFLAGS += -fno-enforce-eh-specs
201 endif
202 endif
204 gb_PrecompiledHeader_EXCEPTIONFLAGS := $(gb_LinkTarget_EXCEPTIONFLAGS)
206 # optimization level
207 gb_COMPILERNOOPTFLAGS := -O0 -fstrict-aliasing -fstrict-overflow
208 gb_COMPILERDEBUGOPTFLAGS := -Og
210 ifeq ($(OS),ANDROID)
211 gb_DEBUGINFO_FLAGS=-glldb
212 # Clang does not know -ggdb2 or some other options
213 else ifeq ($(HAVE_GCC_GGDB2),TRUE)
214 gb_DEBUGINFO_FLAGS=-ggdb2
215 else
216 gb_DEBUGINFO_FLAGS=-g2
217 endif
218 gb_LINKER_DEBUGINFO_FLAGS=
220 # GCC 11 defaults to -gdwarf-5, which GDB 10 doesn't support in split debug info
221 ifeq ($(HAVE_GCC_SPLIT_DWARF),TRUE)
222 gb_DEBUGINFO_FLAGS+=-gsplit-dwarf
223 ifeq ($(COM_IS_CLANG),)
224 gb_DEBUGINFO_FLAGS+=-gdwarf-4
225 endif
226 endif
228 ifeq ($(HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR),TRUE)
229 gb_DEBUGINFO_FLAGS+=-Xclang -debug-info-kind=constructor
230 endif
232 ifeq ($(ENABLE_GDB_INDEX),TRUE)
233 gb_LINKER_DEBUGINFO_FLAGS += -Wl,--gdb-index
234 gb_DEBUGINFO_FLAGS += -ggnu-pubnames
235 endif
237 gb_LinkTarget_INCLUDE :=\
238 $(SOLARINC) \
239 -I$(BUILDDIR)/config_$(gb_Side) \
241 ifeq ($(COM_IS_CLANG),TRUE)
242 gb_COMPILER_TEST_FLAGS := -Xclang -plugin-arg-loplugin -Xclang --unit-test-mode
243 ifeq ($(COMPILER_PLUGIN_TOOL),)
244 gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/clang/plugin.so -Xclang -add-plugin -Xclang loplugin
245 ifneq ($(COMPILER_PLUGIN_WARNINGS_ONLY),)
246 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang \
247 --warnings-only='$(COMPILER_PLUGIN_WARNINGS_ONLY)'
248 endif
249 else
250 gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/clang/plugin.so -Xclang -plugin -Xclang loplugin $(foreach plugin,$(COMPILER_PLUGIN_TOOL), -Xclang -plugin-arg-loplugin -Xclang $(plugin))
251 ifneq ($(UPDATE_FILES),)
252 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang --scope=$(UPDATE_FILES)
253 endif
254 endif
255 ifeq ($(COMPILER_PLUGINS_DEBUG),TRUE)
256 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang --debug
257 endif
258 # set CCACHE_CPP2=1 to prevent clang generating spurious warnings
259 gb_COMPILER_SETUP += CCACHE_CPP2=1
260 gb_COMPILER_PLUGINS_SETUP := ICECC_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.dox CCACHE_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.dox
261 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS := \
262 -Xclang -plugin-arg-loplugin -Xclang --warnings-as-errors
263 else
264 # Set CCACHE_CPP2 to prevent GCC -Werror=implicit-fallthrough= when ccache strips comments from C
265 # code (which still needs /*fallthrough*/-style comments to silence that warning):
266 ifeq ($(ENABLE_WERROR),TRUE)
267 gb_COMPILER_SETUP += CCACHE_CPP2=1
268 endif
269 gb_COMPILER_TEST_FLAGS :=
270 gb_COMPILER_PLUGINS :=
271 gb_COMPILER_PLUGINS_SETUP :=
272 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS :=
273 endif
275 # Executable class
277 gb_Executable_EXT_for_build :=
279 # Helper class
281 ifeq ($(OS_FOR_BUILD),MACOSX)
282 gb_Helper_LIBRARY_PATH_VAR := DYLD_LIBRARY_PATH
283 else ifeq ($(OS_FOR_BUILD),AIX)
284 gb_Helper_LIBRARY_PATH_VAR := LIBPATH
285 else ifeq ($(OS_FOR_BUILD),WNT)
286 # In theory possible if cross-compiling to some Unix from Windows,
287 # in practice strongly discouraged to even try that
288 gb_Helper_LIBRARY_PATH_VAR := PATH
289 else ifeq ($(OS_FOR_BUILD),HAIKU)
290 gb_Helper_LIBRARY_PATH_VAR := LIBRARY_PATH
291 else
292 gb_Helper_LIBRARY_PATH_VAR := LD_LIBRARY_PATH
293 endif
295 gb_Helper_set_ld_path := $(gb_Helper_LIBRARY_PATH_VAR)=$${$(gb_Helper_LIBRARY_PATH_VAR):+$$$(gb_Helper_LIBRARY_PATH_VAR):}"$(INSTROOT_FOR_BUILD)/$(LIBO_URE_LIB_FOLDER_FOR_BUILD):$(INSTROOT_FOR_BUILD)/$(LIBO_LIB_FOLDER_FOR_BUILD)"
297 # $(1): list of : separated directory pathnames to append to the ld path
298 define gb_Helper_extend_ld_path
299 $(gb_Helper_set_ld_path):$(1)
300 endef
302 # Convert path to file URL.
303 define gb_Helper_make_url
304 file://$(strip $(1))
305 endef
307 gb_Helper_get_rcfile = $(1)rc
309 ifneq ($(gb_ENABLE_PCH),)
310 # Enable use of .sum files for PCHs.
311 gb_COMPILER_SETUP += CCACHE_PCH_EXTSUM=1
312 # CCACHE_SLOPPINESS should contain pch_defines,time_macros for PCHs.
313 gb_CCACHE_SLOPPINESS :=
314 ifeq ($(shell test -z "$$CCACHE_SLOPPINESS" && echo 1),1)
315 gb_CCACHE_SLOPPINESS := CCACHE_SLOPPINESS=pch_defines,time_macros
316 else
317 ifeq ($(shell echo "$$CCACHE_SLOPPINESS" | grep -q pch_defines | grep -q time_macros && echo 1),1)
318 gb_CCACHE_SLOPPINESS := CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS:pch_defines,time_macros
319 endif
320 endif
321 gb_COMPILER_SETUP += $(gb_CCACHE_SLOPPINESS)
322 endif
324 ifneq ($(CCACHE_DEPEND_MODE),)
325 gb_COMPILER_SETUP += CCACHE_DEPEND=1
326 endif
328 # vim: set noet sw=4: