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/.
14 gb_README
= README_
$(1)
16 # use CC/CXX if they are nondefaults
17 ifneq ($(origin CC
),default
)
25 ifneq ($(origin CXX
),default
)
31 ifneq ($(origin AR
),default
)
34 gb_AR
:= $(shell $(CC
) -print-prog-name
=ar)
37 # shell setup (env.vars) for the compiler
40 ifeq ($(strip $(gb_COMPILEROPTFLAGS
)),)
41 gb_COMPILEROPTFLAGS
:= -O2
44 gb_COMPILEROPTFLAGS
+= $(if
$(ENABLE_HARDENING_FLAGS
),$(HARDENING_OPT_CFLAGS
))
46 gb_AFLAGS
:= $(AFLAGS
)
49 -DBOOST_SYSTEM_NO_DEPRECATED \
50 -DCPPU_ENV
=$(CPPU_ENV
) \
51 $(if
$(filter EMSCRIPTEN
,$(OS
)),-U_FORTIFY_SOURCE
) \
54 ifeq ($(ENABLE_DBGUTIL
),TRUE
)
55 ifneq ($(HAVE_LIBSTDCPP
),)
56 gb_COMPILERDEFS_STDLIB_DEBUG
= -D_GLIBCXX_DEBUG
58 ifneq ($(LIBCPP_DEBUG
),)
59 gb_COMPILERDEFS_STDLIB_DEBUG
= $(LIBCPP_DEBUG
)
62 gb_COMPILERDEFS
+= $(gb_COMPILERDEFS_STDLIB_DEBUG
)
72 $(if
$(or
$(and
$(COM_IS_CLANG
),$(or
$(findstring icecc
,$(CC
)),$(findstring icecc
,$(CCACHE_PREFIX
)))),$(findstring sccache
,$(CC
))),,-Wunused-macros
) \
73 $(if
$(COM_IS_CLANG
),-Wembedded-directive
) \
74 $(if
$(COM_IS_CLANG
),-Wshadow-all
) \
75 -finput-charset
=UTF-8 \
79 $(if
$(ENABLE_HARDENING_FLAGS
),$(HARDENING_CFLAGS
)) \
80 $(if
$(filter EMSCRIPTEN
,$(OS
)),-fno-stack-protector
,-fstack-protector-strong
) \
82 gb_CXXFLAGS_COMMON
:= \
90 $(if
$(or
$(and
$(COM_IS_CLANG
),$(or
$(findstring icecc
,$(CXX
)),$(findstring icecc
,$(CCACHE_PREFIX
)))),$(findstring sccache
,$(CXX
))),,-Wunused-macros
) \
91 $(if
$(COM_IS_CLANG
),-Wembedded-directive
) \
92 -finput-charset
=UTF-8 \
96 $(if
$(ENABLE_HARDENING_FLAGS
),$(HARDENING_CFLAGS
)) \
97 $(if
$(filter EMSCRIPTEN
,$(OS
)),-fno-stack-protector
,-fstack-protector-strong
) \
99 ifeq ($(HAVE_WDEPRECATED_COPY_DTOR
),TRUE
)
100 gb_CXXFLAGS_COMMON
+= -Wdeprecated-copy-dtor
103 gb_CXXFLAGS_DISABLE_WARNINGS
= -w
105 ifeq ($(HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED
),TRUE
)
106 gb_CXXFLAGS_COMMON
+= -Wno-maybe-uninitialized
109 ifeq ($(HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW
),TRUE
)
110 gb_CXXFLAGS_COMMON
+= -Wno-stringop-overflow
113 gb_CXXFLAGS_Wundef
= -Wno-undef
115 gb_CXXFLAGS_include
:= -include$(gb_SPACE
)
117 ifeq ($(strip $(gb_GCOV
)),YES
)
118 gb_CFLAGS_COMMON
+= -fprofile-arcs
-ftest-coverage
119 gb_CXXFLAGS_COMMON
+= -fprofile-arcs
-ftest-coverage
120 gb_LinkTarget_LDFLAGS
+= -fprofile-arcs
-lgcov
121 gb_COMPILEROPTFLAGS
:= -O0
124 ifeq ($(DISABLE_DYNLOADING
),TRUE
)
125 gb_CFLAGS_COMMON
+= -ffunction-sections
-fdata-sections
126 gb_CXXFLAGS_COMMON
+= -ffunction-sections
-fdata-sections
127 ifneq ($(OS
),EMSCRIPTEN
)
128 gb_LinkTarget_LDFLAGS
+= -Wl
,--gc-sections
132 ifeq ($(COM_IS_CLANG
),TRUE
)
133 gb_CXXFLAGS_COMMON
+= \
134 -Wimplicit-fallthrough \
135 -Wunused-exception-parameter \
136 -Wrange-loop-analysis
138 gb_CFLAGS_COMMON
+= \
142 gb_CXXFLAGS_COMMON
+= \
146 -Wunused-const-variable
=1
149 # If CC or CXX already include -fvisibility=hidden, don't duplicate it
150 ifeq (,$(filter -fvisibility
=hidden
,$(CC
)))
151 gb_VISIBILITY_FLAGS
:= -fvisibility
=hidden
153 gb_VISIBILITY_FLAGS_CXX
:= -fvisibility-inlines-hidden
154 gb_CXXFLAGS_COMMON
+= $(gb_VISIBILITY_FLAGS_CXX
)
156 gb_LinkTarget_LDFLAGS
+= $(if
$(filter EMSCRIPTEN
,$(OS
)),-fno-stack-protector
,-fstack-protector-strong
)
158 ifneq ($(gb_ENABLE_PCH
),)
159 ifeq ($(COM_IS_CLANG
),TRUE
)
160 # Clang by default includes in the PCH timestamps of the files it was
161 # generated from, which would make the PCH be a "new" file for ccache
162 # even if the file has not actually changed. Disabling the timestamp
163 # prevents this at the cost of risking using an outdated PCH (which
164 # should be unlikely, given that gbuild has dependencies set up
165 # for our includes and system includes are unlikely to change).
166 gb_NO_PCH_TIMESTAMP
:= -Xclang
-fno-pch-timestamp
168 gb_CFLAGS_COMMON
+= -fpch-preprocess
-Winvalid-pch
169 gb_CXXFLAGS_COMMON
+= -fpch-preprocess
-Winvalid-pch
170 gb_NO_PCH_TIMESTAMP
:=
174 gb_CFLAGS_WERROR
= $(if
$(ENABLE_WERROR
),-Werror
)
176 # This is the default in non-C++11 mode
177 ifeq ($(COM_IS_CLANG
),TRUE
)
178 gb_CXX03FLAGS
:= -std
=gnu
++98 -Werror
=c
++11-extensions
-Wno-c
++11-long-long \
179 -Wno-deprecated-declarations
181 gb_CXX03FLAGS
:= -std
=gnu
++98 -Wno-long-long \
182 -Wno-variadic-macros
-Wno-deprecated-declarations
185 ifeq ($(ENABLE_LTO
),TRUE
)
186 ifeq ($(COM_IS_CLANG
),TRUE
)
187 gb_LTOFLAGS
:= -flto
=thin
188 ifeq (,$(index
,iOS MACOSX
,$(OS
)))
189 gb_LTOPLUGINFLAGS
:= --plugin
$(if
$(LD_PLUGIN
),$(LD_PLUGIN
),LLVMgold.so
)
192 # use parallelism based on make's job handling
193 gb_LTOFLAGS
:= -flto
=jobserver
-fuse-linker-plugin
-O2
194 # clang does not support -flto=<number>
195 gb_CLANG_LTOFLAGS
:= -flto
=thin
199 gb_LinkTarget_EXCEPTIONFLAGS
:= \
202 ifeq ($(ENABLE_DBGUTIL
),)
203 # Clang doesn't have this option
204 ifeq ($(HAVE_GCC_FNO_ENFORCE_EH_SPECS
),TRUE
)
205 gb_LinkTarget_EXCEPTIONFLAGS
+= \
206 -fno-enforce-eh-specs
207 gb_FilterOutClangCFLAGS
+= -fno-enforce-eh-specs
211 gb_PrecompiledHeader_EXCEPTIONFLAGS
:= $(gb_LinkTarget_EXCEPTIONFLAGS
)
213 # We turn on and off this one depending on whether icecream and/or ccache are used,
214 # and changing cxxflags cause PCH rebuilds, so e.g. a plain temporary 'CCACHE_DISABLE=1'
215 # would cause a rebuild. Ignore the flag there, it's irrelevant for PCH use anyway.
216 gb_PrecompiledHeader_ignore_flags_for_flags_file
:= -Wunused-macros
219 gb_COMPILERNOOPTFLAGS
:= -O0
-Wp
,-U_FORTIFY_SOURCE
-fstrict-aliasing
-fstrict-overflow
220 gb_COMPILERDEBUGOPTFLAGS
:= -Og
223 gb_DEBUGINFO_FLAGS
=-glldb
224 # Clang does not know -ggdb2 or some other options
225 else ifeq ($(HAVE_GCC_GGDB2
),TRUE
)
226 gb_DEBUGINFO_FLAGS
=-ggdb2
228 gb_DEBUGINFO_FLAGS
=-g2
230 gb_LINKER_DEBUGINFO_FLAGS
=
232 ifeq ($(HAVE_EXTERNAL_DWARF
),TRUE
)
233 gb_DEBUGINFO_FLAGS
+=-gsplit-dwarf
234 # GCC 11 defaults to -gdwarf-5, which GDB 10 doesn't support in split debug info
235 ifeq ($(COM_IS_CLANG
),)
236 gb_DEBUGINFO_FLAGS
+=-gdwarf-4
240 ifeq ($(HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR
),TRUE
)
241 gb_DEBUGINFO_FLAGS
+=-Xclang
-debug-info-kind
=constructor
244 ifeq ($(ENABLE_GDB_INDEX
),TRUE
)
245 gb_LINKER_DEBUGINFO_FLAGS
+= -Wl
,--gdb-index
246 gb_DEBUGINFO_FLAGS
+= -ggnu-pubnames
249 gb_LinkTarget_INCLUDE
:=\
251 -I
$(BUILDDIR
)/config_
$(gb_Side
) \
253 ifeq ($(COM_IS_CLANG
),TRUE
)
254 gb_COMPILER_TEST_FLAGS
:= -Xclang
-plugin-arg-loplugin
-Xclang
--unit-test-mode
255 gb_COMPILER_PLUGINS
:= -Xclang
-load
-Xclang
$(BUILDDIR
)/compilerplugins
/clang
/plugin.so
-Xclang
-add-plugin
-Xclang loplugin
256 ifneq ($(COMPILER_PLUGIN_WARNINGS_ONLY
),)
257 gb_COMPILER_PLUGINS
+= -Xclang
-plugin-arg-loplugin
-Xclang \
258 --warnings-only
='$(COMPILER_PLUGIN_WARNINGS_ONLY)'
260 ifeq ($(COMPILER_PLUGINS_DEBUG
),TRUE
)
261 gb_COMPILER_PLUGINS
+= -Xclang
-plugin-arg-loplugin
-Xclang
--debug
263 gb_COMPILER_PLUGINS_TOOL
:= -Xclang
-load
-Xclang
$(BUILDDIR
)/compilerplugins
/clang
/plugin.so
-Xclang
-plugin
-Xclang loplugin
$(foreach plugin
,$(COMPILER_PLUGIN_TOOL
), -Xclang
-plugin-arg-loplugin
-Xclang
$(plugin
))
264 ifneq ($(UPDATE_FILES
),)
265 gb_COMPILER_PLUGINS_TOOL
+= -Xclang
-plugin-arg-loplugin
-Xclang
--scope
=$(UPDATE_FILES
)
267 ifeq ($(COMPILER_PLUGINS_DEBUG
),TRUE
)
268 gb_COMPILER_PLUGINS_TOOL
+= -Xclang
-plugin-arg-loplugin
-Xclang
--debug
271 # Set CCACHE_CPP2=1 to prevent Clang generating spurious warnings.
273 # For Emscripten, the emcc command is a Python script that outputs annoying warnings like
274 # .../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'>
275 # into stderr, which makes a configure script think that there is a problem in
276 # compiling even a microscopic test program with an option like -Werror which
277 # surely *is* supported. Avoid this by setting PYTHONWARNINGS=ignore.
279 gb_COMPILER_SETUP
+= CCACHE_CPP2
=1 $(if
$(filter EMSCRIPTEN
,$(OS
)),PYTHONWARNINGS
=ignore
)
280 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
281 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS
:= \
282 -Xclang
-plugin-arg-loplugin
-Xclang
--warnings-as-errors
284 # Set CCACHE_CPP2 to prevent GCC -Werror=implicit-fallthrough= when ccache strips comments from C
285 # code (which still needs /*fallthrough*/-style comments to silence that warning):
286 ifeq ($(ENABLE_WERROR
),TRUE
)
287 gb_COMPILER_SETUP
+= CCACHE_CPP2
=1
289 gb_COMPILER_TEST_FLAGS
:=
290 gb_COMPILER_PLUGINS
:=
291 gb_COMPILER_PLUGINS_TOOL
:=
292 gb_COMPILER_PLUGINS_SETUP
:=
293 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS
:=
298 gb_Executable_EXT_for_build
:=
302 ifeq ($(OS_FOR_BUILD
),MACOSX
)
303 gb_Helper_LIBRARY_PATH_VAR
:= DYLD_LIBRARY_PATH
304 else ifeq ($(OS_FOR_BUILD
),WNT
)
305 # In theory possible if cross-compiling to some Unix from Windows,
306 # in practice strongly discouraged to even try that
307 gb_Helper_LIBRARY_PATH_VAR
:= PATH
308 else ifeq ($(OS_FOR_BUILD
),HAIKU
)
309 gb_Helper_LIBRARY_PATH_VAR
:= LIBRARY_PATH
311 gb_Helper_LIBRARY_PATH_VAR
:= LD_LIBRARY_PATH
314 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)"
316 # $(1): list of : separated directory pathnames to append to the ld path
317 define gb_Helper_extend_ld_path
318 $(gb_Helper_set_ld_path
):$(1)
321 # Convert path to file URL.
322 define gb_Helper_make_url
326 gb_Helper_get_rcfile
= $(1)rc
328 ifneq ($(gb_ENABLE_PCH
),)
329 # Enable use of .sum files for PCHs.
330 gb_COMPILER_SETUP
+= CCACHE_PCH_EXTSUM
=1
333 # vim: set noet sw=4: