summaryrefslogtreecommitdiffstats
path: root/solenv/gbuild/platform/com_GCC_class.mk
blob: d19f0d3686adb038da7ce8ae9ae51cf99cc527de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

ifeq ($(gb_FULLDEPS),$(true))
ifneq (,$(CCACHE_HARDLINK))
# cannot move hardlink over itself, so create dep file directly, even if that
# might leave a broken file behind in case the build is interrupted forcefully
define gb_cxx_dep_generation_options
-MMD -MT $(1) -MP -MF $(2)
endef
define gb_cxx_dep_copy
endef
else
define gb_cxx_dep_generation_options
-MMD -MT $(1) -MP -MF $(2)_
endef
define gb_cxx_dep_copy
&& mv $(1)_ $(1)
endef
endif
else
define gb_cxx_dep_generation_options
endef
define gb_cxx_dep_copy
endef
endif

# AsmObject class

gb_AsmObject_get_source = $(1)/$(2).s

# $(call gb_AsmObject__command,object,relative-source,source,dep-file)
define gb_AsmObject__command
$(call gb_Output_announce,$(2),$(true),ASM,3)
$(call gb_Helper_abbreviate_dirs,\
	mkdir -p $(dir $(1)) $(dir $(4)) && cd $(SRCDIR) && \
	$(gb_CC) \
		-x assembler-with-cpp \
		$(gb_LTOFLAGS) \
		$(gb_AFLAGS) \
		-c $(3) \
		-o $(1)) \
		$(INCLUDE) && \
	echo "$(1) : $(3)" > $(4)
endef

# CObject class

# $(call gb_CObject__compiler,source,compiler)
define gb_CObject__compiler
	$(if $(filter %.c %.m,$(1)), \
		$(if $(2), $(2), $(gb_CC)), \
		$(if $(2), $(2), $(gb_CXX)))
endef

# When gb_LinkTarget_use_clang is used, filter out GCC flags that Clang doesn't know.
# $(call gb_CObject__filter_out_clang_cflags,cflags)
define gb_CObject__filter_out_clang_cflags
    $(filter-out $(gb_FilterOutClangCFLAGS),$(1))
endef

# $(call gb_CObject__command_pattern,object,flags,source,dep-file,compiler-plugins,symbols,compiler)
define gb_CObject__command_pattern
$(call gb_Helper_abbreviate_dirs,\
	mkdir -p $(dir $(1)) $(dir $(4)) && cd $(SRCDIR) && \
	$(gb_COMPILER_SETUP) \
	$(if $(5),$(gb_COMPILER_PLUGINS_SETUP)) \
	$(call gb_CObject__compiler,$(3),$(7)) \
		$(DEFS) \
		$(gb_LTOFLAGS) \
		$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
		$(if $(WARNINGS_NOT_ERRORS),$(if $(ENABLE_WERROR),$(if $(PLUGIN_WARNINGS_AS_ERRORS),$(gb_COMPILER_PLUGINS_WARNINGS_AS_ERRORS))),$(gb_CFLAGS_WERROR)) \
		$(if $(5),$(gb_COMPILER_PLUGINS)) \
		$(if $(COMPILER_TEST),-fsyntax-only -ferror-limit=0 -Xclang -verify) \
		$(if $(7), $(call gb_CObject__filter_out_clang_cflags,$(2)),$(2)) \
		$(if $(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS)) \
		$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
		-c $(3) \
		-o $(1) \
		$(if $(COMPILER_TEST),,$(call gb_cxx_dep_generation_options,$(1),$(4))) \
		$(INCLUDE) \
		$(PCHFLAGS) \
		$(if $(COMPILER_TEST),,$(call gb_cxx_dep_copy,$(4))) \
		)
endef

# PrecompiledHeader class

ifeq ($(COM_IS_CLANG),TRUE)
gb_PrecompiledHeader_get_enableflags = -include-pch $(call gb_PrecompiledHeader_get_target,$(1),$(2))
gb_PrecompiledHeader_EXT := .pch
else
gb_PrecompiledHeader_get_enableflags = \
-include $(dir $(call gb_PrecompiledHeader_get_target,$(1),$(2)))$(notdir $(subst .gch,,$(call gb_PrecompiledHeader_get_target,$(1),$(2))))
gb_PrecompiledHeader_EXT := .gch
endif

# Clang supports building extra object file where it puts code that would be shared by all users of the PCH.
# Unlike with MSVC it is built as a separate step. The relevant options are used only when generating the PCH
# and when creating the PCH's object file, normal compilations using the PCH do not need extra options.
gb_PrecompiledHeader_pch_with_obj = $(BUILDING_PCH_WITH_OBJ)
ifneq ($(BUILDING_PCH_WITH_OBJ),)
# If using Clang's PCH extra object, we may need to strip unused sections, otherwise inline and template functions
# emitted in that object may in some cases cause unresolved references to private symbols in other libraries.
gb_LinkTarget_LDFLAGS += $(LD_GC_SECTIONS)
gb_PrecompiledHeader_pch_with_obj += -ffunction-sections -fdata-sections
# Enable generating more shared code and debuginfo in the PCH object file.
gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_DEBUGINFO)
ifeq ($(ENABLE_OPTIMIZED),)
# -fmodules-codegen appears to be worth it only if not optimizing, otherwise optimizing all the functions emitted
# in the PCH object file may take way too long, especially given that many of those may get thrown away
gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_CODEGEN)
endif
endif

# This is for MSVC's object file built directly as a side-effect of building the PCH.
gb_PrecompiledHeader_get_objectfile =

define gb_PrecompiledHeader__command
$(call gb_Output_announce,$(2),$(true),PCH,1)
	$(call gb_Trace_StartRange,$(2),PCH)
$(call gb_Helper_abbreviate_dirs,\
	mkdir -p $(dir $(1)) $(dir $(call gb_PrecompiledHeader_get_dep_target,$(2),$(7))) && \
	cd $(BUILDDIR)/ && \
	CCACHE_DISABLE=1 $(gb_COMPILER_SETUP) \
	$(if $(8),$(8),$(gb_CXX)) \
		-x c++-header \
		$(4) \
		$(if $(7), $(call gb_CObject__filter_out_clang_cflags,$(5)),$(5)) \
		$(if $(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS)) \
		$(gb_COMPILERDEPFLAGS) \
		$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
		$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
		$(gb_NO_PCH_TIMESTAMP) \
		$(gb_PrecompiledHeader_pch_with_obj) \
		$(6) \
		$(call gb_cxx_dep_generation_options,$(1),$(call gb_PrecompiledHeader_get_dep_target_tmp,$(2),$(7))) \
		-c $(patsubst %.cxx,%.hxx,$(3)) \
		-o$(1) \
		$(call gb_cxx_dep_copy,$(call gb_PrecompiledHeader_get_dep_target_tmp,$(2),$(7))) \
		)
	$(call gb_Trace_EndRange,$(2),PCH)
endef

ifeq ($(COM_IS_CLANG),TRUE)
# Clang has -fno-pch-timestamp, just checksum the file for CCACHE_PCH_EXTSUM
define gb_PrecompiledHeader__sum_command
	$(SHA256SUM) $(1) >$(1).sum
endef
else
# GCC does not generate the same .gch for the same input, so checksum the (preprocessed) input
define gb_PrecompiledHeader__sum_command
$(call gb_Helper_abbreviate_dirs,\
	CCACHE_DISABLE=1 $(gb_COMPILER_SETUP) \
	$(gb_CXX) \
		-x c++-header \
		$(4) $(5) \
		$(if $(WARNINGS_DISABLED),$(gb_CXXFLAGS_DISABLE_WARNINGS)) \
		$(gb_COMPILERDEPFLAGS) \
		$(if $(VISIBILITY),,$(gb_VISIBILITY_FLAGS)) \
		$(if $(EXTERNAL_CODE),$(gb_CXXFLAGS_Wundef),$(gb_DEFS_INTERNAL)) \
		$(gb_NO_PCH_TIMESTAMP) \
		$(6) \
		-E $(patsubst %.cxx,%.hxx,$(3)) \
		-o- \
		| $(SHA256SUM) >$(1).sum \
		)
endef
endif

# not needed
gb_PrecompiledHeader__create_reuse_files =
gb_PrecompiledHeader__copy_reuse_files =

# YaccTarget class

define gb_YaccTarget__command
$(call gb_Output_announce,$(2),$(true),YAC,3)
$(call gb_Helper_abbreviate_dirs,\
	mkdir -p $(dir $(3)) && \
	$(BISON) $(T_YACCFLAGS) -v --defines=$(4) -o $(5) $(1) && touch $(3) )

endef

# CppunitTest class

ifeq ($(strip $(DEBUGCPPUNIT)),TRUE)
gb_CppunitTest_GDBTRACE := gdb -nx -ex "add-auto-load-safe-path $(INSTDIR)" -ex "set environment $(subst =, ,$(gb_CppunitTest_CPPTESTPRECOMMAND))" --batch --command=$(SRCDIR)/solenv/bin/gdbtrycatchtrace-stdout -return-child-result --args
endif

# ExternalProject class

gb_ExternalProject_use_autoconf :=
gb_ExternalProject_use_nmake :=

# StaticLibrary class

gb_StaticLibrary_get_filename = lib$(1).a
gb_StaticLibrary_PLAINEXT := .a
gb_StaticLibrary_StaticLibrary_platform :=

gb_LinkTarget_get_linksearchpath_for_layer = \
	-L$(WORKDIR)/LinkTarget/StaticLibrary \
	-L$(call gb_Library_get_sdk_link_dir) \
	$(foreach layer,\
		$(subst +, ,$(patsubst $(1):%.,%,\
			$(filter $(1):%.,$(gb_LinkTarget_LAYER_LINKPATHS)))),\
		$(patsubst $(layer):%,-L%,\
			$(filter $(layer):%,$(gb_Library_LAYER_DIRS))))


gb_ICU_PRECOMMAND := $(call gb_Helper_extend_ld_path,$(WORKDIR_FOR_BUILD)/UnpackedTarball/icu/source/lib)

# UIConfig class

# macOS sort(1) cannot read a response file
define gb_UIConfig__command
$(call gb_Helper_abbreviate_dirs,\
	$(SORT) -u $(UI_IMAGELISTS) /dev/null > $@ \
)

endef

define gb_UIConfig__gla11y_command
$(call gb_Helper_abbreviate_dirs,\
	$(gb_UIConfig_LXML_PATH) $(if $(SYSTEM_LIBXML)$(SYSTEM_LIBXSLT),,$(gb_Helper_set_ld_path)) \
	$(call gb_ExternalExecutable_get_command,python) \
	$(gb_UIConfig_gla11y_SCRIPT) $(gb_UIConfig_gla11y_PARAMETERS) -o $@ $(UIFILES)
)

endef

# vim: set noet sw=4 ts=4: