bump product version to 7.6.3.2-android
[LibreOffice.git] / solenv / gbuild / platform / com_GCC_defs.mk
blob8f99e91f5f9b9f9c2b646c0e1e94aa71cf196170
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_AFLAGS := $(AFLAGS)
46 gb_COMPILERDEFS := \
47 -DBOOST_ERROR_CODE_HEADER_ONLY \
48 -DBOOST_SYSTEM_NO_DEPRECATED \
49 -DCPPU_ENV=$(CPPU_ENV) \
50 $(if $(filter EMSCRIPTEN,$(OS)),-U_FORTIFY_SOURCE) \
52 # enable debug STL
53 ifeq ($(gb_ENABLE_DBGUTIL),$(true))
54 ifneq ($(HAVE_LIBSTDCPP),)
55 gb_COMPILERDEFS_STDLIB_DEBUG = -D_GLIBCXX_DEBUG
56 else
57 ifneq ($(LIBCPP_DEBUG),)
58 gb_COMPILERDEFS_STDLIB_DEBUG = $(LIBCPP_DEBUG)
59 endif
60 endif
61 gb_COMPILERDEFS += $(gb_COMPILERDEFS_STDLIB_DEBUG)
62 endif
64 gb_CFLAGS_COMMON := \
65 -Wall \
66 -Wendif-labels \
67 -Wextra \
68 -Wstrict-prototypes \
69 -Wundef \
70 -Wunreachable-code \
71 $(if $(or $(and $(COM_IS_CLANG),$(or $(findstring icecc,$(CC)),$(findstring icecc,$(CCACHE_PREFIX)))),$(findstring sccache,$(CC))),,-Wunused-macros) \
72 $(if $(COM_IS_CLANG),-Wembedded-directive) \
73 $(if $(COM_IS_CLANG),-Wshadow-all) \
74 -finput-charset=UTF-8 \
75 -fmessage-length=0 \
76 -fno-common \
77 -pipe \
78 $(if $(filter EMSCRIPTEN,$(OS)),-fno-stack-protector,-fstack-protector-strong) \
80 gb_CXXFLAGS_COMMON := \
81 -Wall \
82 -Wno-missing-braces \
83 -Wendif-labels \
84 -Wextra \
85 -Wundef \
86 -Wunreachable-code \
87 -Wshadow \
88 $(if $(or $(and $(COM_IS_CLANG),$(or $(findstring icecc,$(CXX)),$(findstring icecc,$(CCACHE_PREFIX)))),$(findstring sccache,$(CXX))),,-Wunused-macros) \
89 $(if $(COM_IS_CLANG),-Wembedded-directive) \
90 -finput-charset=UTF-8 \
91 -fmessage-length=0 \
92 -fno-common \
93 -pipe \
94 $(if $(filter EMSCRIPTEN,$(OS)),-fno-stack-protector,-fstack-protector-strong) \
96 ifeq ($(HAVE_WDEPRECATED_COPY_DTOR),TRUE)
97 gb_CXXFLAGS_COMMON += -Wdeprecated-copy-dtor
98 endif
100 gb_CXXFLAGS_DISABLE_WARNINGS = -w
102 ifeq ($(HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED),TRUE)
103 gb_CXXFLAGS_COMMON += -Wno-maybe-uninitialized
104 endif
106 ifeq ($(HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW),TRUE)
107 gb_CXXFLAGS_COMMON += -Wno-stringop-overflow
108 endif
110 gb_CXXFLAGS_Wundef = -Wno-undef
112 gb_CXXFLAGS_include := -include$(gb_SPACE)
114 ifeq ($(strip $(gb_GCOV)),YES)
115 gb_CFLAGS_COMMON += -fprofile-arcs -ftest-coverage
116 gb_CXXFLAGS_COMMON += -fprofile-arcs -ftest-coverage
117 gb_LinkTarget_LDFLAGS += -fprofile-arcs -lgcov
118 gb_COMPILEROPTFLAGS := -O0
119 endif
121 ifeq ($(DISABLE_DYNLOADING),TRUE)
122 gb_CFLAGS_COMMON += -ffunction-sections -fdata-sections
123 gb_CXXFLAGS_COMMON += -ffunction-sections -fdata-sections
124 ifneq ($(OS),EMSCRIPTEN)
125 gb_LinkTarget_LDFLAGS += -Wl,--gc-sections
126 endif
127 endif
129 ifeq ($(COM_IS_CLANG),TRUE)
130 gb_CXXFLAGS_COMMON += \
131 -Wimplicit-fallthrough \
132 -Wunused-exception-parameter \
133 -Wrange-loop-analysis
134 else
135 gb_CFLAGS_COMMON += \
136 -Wduplicated-cond \
137 -Wlogical-op \
138 -Wshift-overflow=2
139 gb_CXXFLAGS_COMMON += \
140 -Wduplicated-cond \
141 -Wlogical-op \
142 -Wshift-overflow=2 \
143 -Wunused-const-variable=1
144 endif
146 # GCC 8 -Wcast-function-type (included in -Wextra) unhelpfully even warns on reinterpret_cast
147 # between incompatible function types:
148 ifeq ($(shell expr '$(GCC_VERSION)' '>=' 800),1)
149 gb_CXXFLAGS_COMMON += \
150 -Wno-cast-function-type
151 endif
153 # If CC or CXX already include -fvisibility=hidden, don't duplicate it
154 ifeq (,$(filter -fvisibility=hidden,$(CC)))
155 gb_VISIBILITY_FLAGS := -fvisibility=hidden
156 endif
157 gb_VISIBILITY_FLAGS_CXX := -fvisibility-inlines-hidden
158 gb_CXXFLAGS_COMMON += $(gb_VISIBILITY_FLAGS_CXX)
160 gb_LinkTarget_LDFLAGS += $(if $(filter EMSCRIPTEN,$(OS)),-fno-stack-protector,-fstack-protector-strong)
162 ifneq ($(gb_ENABLE_PCH),)
163 ifeq ($(COM_IS_CLANG),TRUE)
164 # Clang by default includes in the PCH timestamps of the files it was
165 # generated from, which would make the PCH be a "new" file for ccache
166 # even if the file has not actually changed. Disabling the timestamp
167 # prevents this at the cost of risking using an outdated PCH (which
168 # should be unlikely, given that gbuild has dependencies set up
169 # for our includes and system includes are unlikely to change).
170 gb_NO_PCH_TIMESTAMP := -Xclang -fno-pch-timestamp
171 else
172 gb_CFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
173 gb_CXXFLAGS_COMMON += -fpch-preprocess -Winvalid-pch
174 gb_NO_PCH_TIMESTAMP :=
175 endif
176 endif
178 gb_CFLAGS_WERROR = $(if $(ENABLE_WERROR),-Werror)
180 # This is the default in non-C++11 mode
181 ifeq ($(COM_IS_CLANG),TRUE)
182 gb_CXX03FLAGS := -std=gnu++98 -Werror=c++11-extensions -Wno-c++11-long-long \
183 -Wno-deprecated-declarations
184 else
185 gb_CXX03FLAGS := -std=gnu++98 -Wno-long-long \
186 -Wno-variadic-macros -Wno-deprecated-declarations
187 endif
189 # On Windows MSVC only supports C90 so force gnu89 (especially in clang) to
190 # to catch potential gnu89/C90 incompatibilities locally.
191 gb_CFLAGS_COMMON += -std=gnu89
193 ifeq ($(ENABLE_LTO),TRUE)
194 ifeq ($(COM_IS_CLANG),TRUE)
195 gb_LTOFLAGS := -flto=thin
196 ifeq (,$(index,iOS MACOSX,$(OS)))
197 gb_LTOPLUGINFLAGS := --plugin $(if $(LD_PLUGIN),$(LD_PLUGIN),LLVMgold.so)
198 endif
199 else
200 # use parallelism based on make's job handling
201 gb_LTOFLAGS := -flto=jobserver -fuse-linker-plugin -O2
202 # clang does not support -flto=<number>
203 gb_CLANG_LTOFLAGS := -flto=thin
204 endif
205 endif
207 gb_LinkTarget_EXCEPTIONFLAGS := \
208 -fexceptions
210 ifeq ($(gb_ENABLE_DBGUTIL),$(false))
211 # Clang doesn't have this option
212 ifeq ($(HAVE_GCC_FNO_ENFORCE_EH_SPECS),TRUE)
213 gb_LinkTarget_EXCEPTIONFLAGS += \
214 -fno-enforce-eh-specs
215 gb_FilterOutClangCFLAGS += -fno-enforce-eh-specs
216 endif
217 endif
219 gb_PrecompiledHeader_EXCEPTIONFLAGS := $(gb_LinkTarget_EXCEPTIONFLAGS)
221 # We turn on and off this one depending on whether icecream and/or ccache are used,
222 # and changing cxxflags cause PCH rebuilds, so e.g. a plain temporary 'CCACHE_DISABLE=1'
223 # would cause a rebuild. Ignore the flag there, it's irrelevant for PCH use anyway.
224 gb_PrecompiledHeader_ignore_flags_for_flags_file := -Wunused-macros
226 # optimization level
227 gb_COMPILERNOOPTFLAGS := -O0 -fstrict-aliasing -fstrict-overflow
228 gb_COMPILERDEBUGOPTFLAGS := -Og
230 ifeq ($(OS),ANDROID)
231 gb_DEBUGINFO_FLAGS=-glldb
232 # Clang does not know -ggdb2 or some other options
233 else ifeq ($(HAVE_GCC_GGDB2),TRUE)
234 gb_DEBUGINFO_FLAGS=-ggdb2
235 else
236 gb_DEBUGINFO_FLAGS=-g2
237 endif
238 gb_LINKER_DEBUGINFO_FLAGS=
240 ifeq ($(HAVE_EXTERNAL_DWARF),TRUE)
241 gb_DEBUGINFO_FLAGS+=-gsplit-dwarf
242 # GCC 11 defaults to -gdwarf-5, which GDB 10 doesn't support in split debug info
243 ifeq ($(COM_IS_CLANG),)
244 gb_DEBUGINFO_FLAGS+=-gdwarf-4
245 endif
246 endif
248 ifeq ($(HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR),TRUE)
249 gb_DEBUGINFO_FLAGS+=-Xclang -debug-info-kind=constructor
250 endif
252 ifeq ($(ENABLE_GDB_INDEX),TRUE)
253 gb_LINKER_DEBUGINFO_FLAGS += -Wl,--gdb-index
254 gb_DEBUGINFO_FLAGS += -ggnu-pubnames
255 endif
257 gb_LinkTarget_INCLUDE :=\
258 $(SOLARINC) \
259 -I$(BUILDDIR)/config_$(gb_Side) \
261 ifeq ($(COM_IS_CLANG),TRUE)
262 gb_COMPILER_TEST_FLAGS := -Xclang -plugin-arg-loplugin -Xclang --unit-test-mode
263 ifeq ($(COMPILER_PLUGIN_TOOL),)
264 gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/clang/plugin.so -Xclang -add-plugin -Xclang loplugin
265 ifneq ($(COMPILER_PLUGIN_WARNINGS_ONLY),)
266 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang \
267 --warnings-only='$(COMPILER_PLUGIN_WARNINGS_ONLY)'
268 endif
269 else
270 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))
271 ifneq ($(UPDATE_FILES),)
272 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang --scope=$(UPDATE_FILES)
273 endif
274 endif
275 ifeq ($(COMPILER_PLUGINS_DEBUG),TRUE)
276 gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang --debug
277 endif
279 # Set CCACHE_CPP2=1 to prevent Clang generating spurious warnings.
281 # For Emscripten, the emcc command is a Python script that outputs annoying warnings like
282 # .../emscripten/tools/building.py:638: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/emscripten_temp_0fvvg__1/conftest.js.jso.js' mode='w' encoding='utf-8'>
283 # into stderr, which makes a configure script think that there is a problem in
284 # compiling even a microscopic test program with an option like -Werror which
285 # surely *is* supported. Avoid this by setting PYTHONWARNINGS=ignore.
287 gb_COMPILER_SETUP += CCACHE_CPP2=1 $(if $(filter EMSCRIPTEN,$(OS)),PYTHONWARNINGS=ignore)
288 gb_COMPILER_PLUGINS_SETUP := ICECC_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.dox CCACHE_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.dox SCCACHE_EXTRAFILES=$(SRCDIR)/include/sal/log-areas.dox
289 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS := \
290 -Xclang -plugin-arg-loplugin -Xclang --warnings-as-errors
291 else
292 # Set CCACHE_CPP2 to prevent GCC -Werror=implicit-fallthrough= when ccache strips comments from C
293 # code (which still needs /*fallthrough*/-style comments to silence that warning):
294 ifeq ($(ENABLE_WERROR),TRUE)
295 gb_COMPILER_SETUP += CCACHE_CPP2=1
296 endif
297 gb_COMPILER_TEST_FLAGS :=
298 gb_COMPILER_PLUGINS :=
299 gb_COMPILER_PLUGINS_SETUP :=
300 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS :=
301 endif
303 # Executable class
305 gb_Executable_EXT_for_build :=
307 # Helper class
309 ifeq ($(OS_FOR_BUILD),MACOSX)
310 gb_Helper_LIBRARY_PATH_VAR := DYLD_LIBRARY_PATH
311 else ifeq ($(OS_FOR_BUILD),WNT)
312 # In theory possible if cross-compiling to some Unix from Windows,
313 # in practice strongly discouraged to even try that
314 gb_Helper_LIBRARY_PATH_VAR := PATH
315 else ifeq ($(OS_FOR_BUILD),HAIKU)
316 gb_Helper_LIBRARY_PATH_VAR := LIBRARY_PATH
317 else
318 gb_Helper_LIBRARY_PATH_VAR := LD_LIBRARY_PATH
319 endif
321 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)"
323 # $(1): list of : separated directory pathnames to append to the ld path
324 define gb_Helper_extend_ld_path
325 $(gb_Helper_set_ld_path):$(1)
326 endef
328 # Convert path to file URL.
329 define gb_Helper_make_url
330 file://$(strip $(1))
331 endef
333 gb_Helper_get_rcfile = $(1)rc
335 ifneq ($(gb_ENABLE_PCH),)
336 # Enable use of .sum files for PCHs.
337 gb_COMPILER_SETUP += CCACHE_PCH_EXTSUM=1
338 endif
340 # vim: set noet sw=4: