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_AFLAGS
:= $(AFLAGS
)
47 -DBOOST_ERROR_CODE_HEADER_ONLY \
48 -DBOOST_SYSTEM_NO_DEPRECATED \
49 -DCPPU_ENV
=$(CPPU_ENV
) \
50 $(if
$(filter EMSCRIPTEN
,$(OS
)),-U_FORTIFY_SOURCE
) \
53 ifeq ($(gb_ENABLE_DBGUTIL
),$(true
))
54 ifneq ($(HAVE_LIBSTDCPP
),)
55 gb_COMPILERDEFS_STDLIB_DEBUG
= -D_GLIBCXX_DEBUG
57 ifneq ($(LIBCPP_DEBUG
),)
58 gb_COMPILERDEFS_STDLIB_DEBUG
= $(LIBCPP_DEBUG
)
61 gb_COMPILERDEFS
+= $(gb_COMPILERDEFS_STDLIB_DEBUG
)
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 \
78 $(if
$(filter EMSCRIPTEN
,$(OS
)),-fno-stack-protector
,-fstack-protector-strong
) \
80 gb_CXXFLAGS_COMMON
:= \
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 \
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
100 gb_CXXFLAGS_DISABLE_WARNINGS
= -w
102 ifeq ($(HAVE_BROKEN_GCC_WMAYBE_UNINITIALIZED
),TRUE
)
103 gb_CXXFLAGS_COMMON
+= -Wno-maybe-uninitialized
106 ifeq ($(HAVE_BROKEN_GCC_WSTRINGOP_OVERFLOW
),TRUE
)
107 gb_CXXFLAGS_COMMON
+= -Wno-stringop-overflow
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
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
129 ifeq ($(COM_IS_CLANG
),TRUE
)
130 gb_CXXFLAGS_COMMON
+= \
131 -Wimplicit-fallthrough \
132 -Wunused-exception-parameter \
133 -Wrange-loop-analysis
135 gb_CFLAGS_COMMON
+= \
139 gb_CXXFLAGS_COMMON
+= \
143 -Wunused-const-variable
=1
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
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
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
172 gb_CFLAGS_COMMON
+= -fpch-preprocess
-Winvalid-pch
173 gb_CXXFLAGS_COMMON
+= -fpch-preprocess
-Winvalid-pch
174 gb_NO_PCH_TIMESTAMP
:=
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
185 gb_CXX03FLAGS
:= -std
=gnu
++98 -Wno-long-long \
186 -Wno-variadic-macros
-Wno-deprecated-declarations
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
)
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
207 gb_LinkTarget_EXCEPTIONFLAGS
:= \
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
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
227 gb_COMPILERNOOPTFLAGS
:= -O0
-fstrict-aliasing
-fstrict-overflow
228 gb_COMPILERDEBUGOPTFLAGS
:= -Og
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
236 gb_DEBUGINFO_FLAGS
=-g2
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
248 ifeq ($(HAVE_CLANG_DEBUG_INFO_KIND_CONSTRUCTOR
),TRUE
)
249 gb_DEBUGINFO_FLAGS
+=-Xclang
-debug-info-kind
=constructor
252 ifeq ($(ENABLE_GDB_INDEX
),TRUE
)
253 gb_LINKER_DEBUGINFO_FLAGS
+= -Wl
,--gdb-index
254 gb_DEBUGINFO_FLAGS
+= -ggnu-pubnames
257 gb_LinkTarget_INCLUDE
:=\
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)'
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
)
275 ifeq ($(COMPILER_PLUGINS_DEBUG
),TRUE
)
276 gb_COMPILER_PLUGINS
+= -Xclang
-plugin-arg-loplugin
-Xclang
--debug
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
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
297 gb_COMPILER_TEST_FLAGS
:=
298 gb_COMPILER_PLUGINS
:=
299 gb_COMPILER_PLUGINS_SETUP
:=
300 gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS
:=
305 gb_Executable_EXT_for_build
:=
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
318 gb_Helper_LIBRARY_PATH_VAR
:= LD_LIBRARY_PATH
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)
328 # Convert path to file URL.
329 define gb_Helper_make_url
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
340 # vim: set noet sw=4: