weld: Return unique_ptr in weld::Dialog::widget_for_response
[LibreOffice.git] / solenv / gbuild / Helper.mk
blob0f54a81d2cb59742f57329b98457c9d8500dab76
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/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 gb_Helper_MISC := $(WORKDIR)/Misc
22 # general purpose phony target
23 gb_Helper_PHONY := $(gb_Helper_MISC)/PHONY
25 # general purpose empty dummy target
26 gb_Helper_MISCDUMMY := $(gb_Helper_MISC)/DUMMY
28 # target for reacting to changes in the list of configured languages
29 gb_Helper_LANGSTARGET := $(BUILDDIR)/config_$(gb_Side)_lang.mk.stamp
31 .PHONY : $(WORKDIR)/Misc/PHONY
32 $(gb_Helper_MISCDUMMY) :
33 @mkdir -p $(dir $@) && touch $@
35 ifeq ($(SRCDIR),$(BUILDDIR))
36 define gb_Helper_abbreviate_dirs
37 S=$(SRCDIR) && \
38 $(subst $(SRCDIR)/,$$S/,I=$(INSTDIR)) && \
39 $(subst $(SRCDIR)/,$$S/,W=$(WORKDIR)) && \
40 $(subst $(SRCDIR)/,$$S/,$(subst $(INSTDIR)/,$$I/,$(subst $(WORKDIR)/,$$W/,$(1))))
41 endef
42 else
43 define gb_Helper_abbreviate_dirs
44 S=$(SRCDIR) && \
45 $(subst $(SRCDIR)/,$$S/,B=$(BUILDDIR)) && \
46 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,I=$(INSTDIR))) && \
47 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,W=$(WORKDIR))) && \
48 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,$(subst $(INSTDIR)/,$$I/,$(subst $(WORKDIR)/,$$W/,$(1)))))
49 endef
50 endif
52 define gb_Helper_abbreviate_dirs_native
53 $(call gb_Output_error,gb_Helper_abbreviate_dirs_native: use gb_Helper_abbreviate_dirs instead.)
54 endef
56 define gb_Helper_native_path
57 $(call gb_Output_error,gb_Helper_native_path: Do not use. Should not be necessary.)
58 endef
60 # cygwin seems to eat one backslash when executing command, thus replace with '\\'
61 define gb_Helper_windows_path
62 $(subst /,\\,$(1))
63 endef
66 ifeq ($(OS),WNT)
67 # path-replacement optimizations, instead of calling cygpath/wslpath all the time, just do it once
68 # and then do all other path-replacements without the need to spawn processes/shells for that
69 SRCDIR_CYG := $(shell cygpath -u $(SRCDIR))
70 BUILDDIR_CYG := $(shell cygpath -u $(BUILDDIR))
71 INSTDIR_CYG := $(shell cygpath -u $(INSTDIR))
72 WORKDIR_CYG := $(shell cygpath -u $(WORKDIR))
73 TARFILE_LOCATION_CYG := $(shell cygpath -u $(TARFILE_LOCATION))
75 define gb_Helper_cyg_path
76 $(subst $(TARFILE_LOCATION)/,$(TARFILE_LOCATION_CYG)/,$(subst $(SRCDIR)/,$(SRCDIR_CYG)/,$(subst $(BUILDDIR)/,$(BUILDDIR_CYG)/,$(subst $(INSTDIR)/,$(INSTDIR_CYG)/,$(subst $(WORKDIR)/,$(WORKDIR_CYG)/,$(1))))))
77 endef
79 ifneq ($(MSYSTEM),)
80 # paths to reach into windows realm from within wsl
81 SRCDIR_WSL := $(shell $(WSL) wslpath -u $(SRCDIR))
82 BUILDDIR_WSL := $(shell $(WSL) wslpath -u $(BUILDDIR))
83 INSTDIR_WSL := $(shell $(WSL) wslpath -u $(INSTDIR))
84 WORKDIR_WSL := $(shell $(WSL) wslpath -u $(WORKDIR))
85 TARFILE_LOCATION_WSL := $(shell $(WSL) wslpath -u $(TARFILE_LOCATION))
87 define gb_Helper_wsl_path
88 $(subst $(TARFILE_LOCATION)/,$(TARFILE_LOCATION_WSL)/,$(subst $(SRCDIR)/,$(SRCDIR_WSL)/,$(subst $(BUILDDIR)/,$(BUILDDIR_WSL)/,$(subst $(INSTDIR)/,$(INSTDIR_WSL)/,$(subst $(WORKDIR)/,$(WORKDIR_WSL)/,$(1))))))
89 endef
90 else
91 # not needed for cygwin
92 gb_Helper_wsl_path=$(1)
93 endif
95 else
96 # noop for non-Windows
97 gb_Helper_wsl_path=$(1)
98 gb_Helper_cyg_path=$(1)
99 endif
101 define gb_Helper_make_clean_target
102 gb_$(1)_get_clean_target = $(WORKDIR)/Clean/$(1)/$$(1)
104 endef
106 define gb_Helper_make_dep_target
107 gb_$(1)_get_dep_target = $(WORKDIR)/Dep/$(1)/$$(1).d
109 endef
111 define gb_Helper_make_clean_targets
112 $(foreach targettype,$(1),\
113 $(call gb_Helper_make_clean_target,$(targettype)))
115 endef
117 define gb_Helper_make_dep_targets
118 $(foreach targettype,$(1),\
119 $(call gb_Helper_make_dep_target,$(targettype)))
121 endef
123 # e.g. 'make CppunitTest_sw_macros_test'
125 # gb_Helper_make_userfriendly_targets target class build-target? clean-target?
126 define gb_Helper_make_userfriendly_targets
127 .PHONY: $(2) $(2)_$(1) $(2)_$(1).clean
128 $(2): $(2)_$(1)
129 $(2)_$(1) : $(if $(3),$(3),$(call gb_$(2)_get_target,$(1)))
130 $(2)_$(1).clean : $(if $(4),$(4),$(call gb_$(2)_get_clean_target,$(1)))
132 endef
134 define gb_Helper_init_registries
135 gb_Executable_VALIDGROUPS_INSTALLED := UREBIN SDK OOO
136 gb_Executable_VALIDGROUPS_NOTINSTALLED := NONE
137 gb_Executable_VALIDGROUPS := UREBIN SDK OOO NONE
138 gb_Library_VALIDGROUPS_INSTALLED := OOOLIBS PLAINLIBS_URE PLAINLIBS_OOO PRIVATELIBS_URE RTVERLIBS UNOVERLIBS PLAINLIBS_SHLXTHDL
139 gb_Library_VALIDGROUPS_NOTINSTALLED := PLAINLIBS_NONE PLAINLIBS_OXT EXTENSIONLIBS
140 gb_Library_VALIDGROUPS := OOOLIBS PLAINLIBS_URE PLAINLIBS_OOO PRIVATELIBS_URE RTVERLIBS UNOVERLIBS PLAINLIBS_SHLXTHDL PLAINLIBS_NONE PLAINLIBS_OXT EXTENSIONLIBS
141 gb_Jar_VALIDGROUPS_INSTALLED := URE OOO
142 gb_Jar_VALIDGROUPS_NOTINSTALLED := OXT NONE
143 gb_Jar_VALIDGROUPS := URE OOO OXT NONE
145 $$(foreach group,$$(gb_Executable_VALIDGROUPS),$$(eval gb_Executable_$$(group) :=))
146 $$(foreach group,$$(gb_Library_VALIDGROUPS),$$(eval gb_Library_$$(group) :=))
147 $$(foreach group,$$(gb_Jar_VALIDGROUPS),$$(eval gb_Jar_$$(group) :=))
149 endef
151 define gb_Helper_collect_knownlibs
152 gb_Library_KNOWNLIBS := $$(foreach group,$$(gb_Library_VALIDGROUPS),$$(gb_Library_$$(group)))
153 gb_Executable_KNOWN := $$(foreach group,$$(gb_Executable_VALIDGROUPS),$$(gb_Executable_$$(group)))
154 gb_Jar_KNOWN := $$(foreach group,$$(gb_Jar_VALIDGROUPS),$$(gb_Jar_$$(group)))
155 gb_Fuzzers_KNOWN := $$(filter %fuzzer,$$(foreach group,$$(gb_Executable_VALIDGROUPS),$$(gb_Executable_$$(group))))
157 endef
159 define gb_Helper_process_executable_registrations
160 $(foreach group,$(gb_Executable_VALIDGROUPS),\
161 $(foreach executable,$(gb_Executable_$(group)),\
162 $(if $(filter-out undefined,$(origin gb_Executable__register_$(executable))),\
163 $(call gb_Executable__register_$(executable)))))
165 endef
167 define gb_Helper__register_executables
168 $(foreach group,$(gb_Executable_VALIDGROUPS),\
169 $(foreach target,$(2),\
170 $(if $(filter $(target),$(gb_Executable_$(group))),\
171 $(call gb_Output_error,gb_Helper_register_executables: already registered: $(target)))))
172 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
173 $(call gb_Output_error,gb_Helper_register_executables: contains duplicates: $(2)))
175 gb_Executable_$(1) += $(2)
177 endef
179 # $(call gb_Helper_register_executables,layer,exes)
180 define gb_Helper_register_executables
181 ifeq ($$(filter $(1),$$(gb_Executable_VALIDGROUPS_NOTINSTALLED)),)
182 $$(eval $$(call gb_Output_error,$(1) is not a valid group for executables that are not installed. Valid groups are: $$(gb_Executable_VALIDGROUPS_NOTINSTALLED). Use gb_Helper_register_executables_for_install for installed executables.))
183 endif
184 $(call gb_Helper__register_executables,$(1),$(2))
186 endef
188 # $(call gb_Helper_register_executables_for_install,layer,installmodule,exes)
189 define gb_Helper_register_executables_for_install
190 $(if $(3),,$(call gb_Output_error,gb_Helper_register_executables_for_install: no executables - need 3 parameters))
191 ifeq ($$(filter $(1),$$(gb_Executable_VALIDGROUPS_INSTALLED)),)
192 $$(eval $$(call gb_Output_error,$(1) is not a valid group for installed executables. Valid groups are: $$(gb_Executable_VALIDGROUPS_INSTALLED). Use gb_Helper_register_executables for executables that are not installed.))
193 endif
194 $(call gb_Helper__register_executables,$(1),$(3))
196 gb_Executable_MODULE_$(2) += $(3)
198 endef
200 define gb_Helper__register_libraries
201 $(foreach group,$(gb_Library_VALIDGROUPS),\
202 $(foreach target,$(2),\
203 $(if $(filter $(target),$(gb_Library_$(group))),\
204 $(call gb_Output_error,gb_Helper_register_libraries: already registered: $(target)))))
205 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
206 $(call gb_Output_error,gb_Helper_register_libraries: contains duplicates: $(2)))
208 gb_Library_$(1) += $(2)
210 endef
212 # $(call gb_Helper_register_libraries,layer,libs)
213 define gb_Helper_register_libraries
214 ifeq ($$(filter $(1),$$(gb_Library_VALIDGROUPS_NOTINSTALLED)),)
215 $$(eval $$(call gb_Output_error,$(1) is not a valid group for libraries that are not installed. Valid groups are: $$(gb_Library_VALIDGROUPS_NOTINSTALLED). Use gb_Helper_register_libraries_for_install for installed libraries.))
216 endif
217 $(call gb_Helper__register_libraries,$(1),$(2))
219 endef
221 # the first argument is the group, which sets rpaths etc.
222 # the second argument is the install module, which describes in which distro package/msi a lib should show up
223 # UGLY: for versioned libraries "sdk" module is hard-coded for now
224 # $(call gb_Helper_register_libraries_for_install,layer,installmodule,libs)
225 define gb_Helper_register_libraries_for_install
226 $(if $(3),,$(call gb_Output_error,gb_Helper_register_libraries_for_install: no libraries - need 3 parameters))
227 ifeq ($$(filter $(1),$$(gb_Library_VALIDGROUPS_INSTALLED)),)
228 $$(eval $$(call gb_Output_error,$(1) is not a valid group for installed libraries. Valid groups are: $$(gb_Library_VALIDGROUPS_INSTALLED). Use gb_Helper_register_libraries for libraries that are not installed.))
229 endif
230 $(call gb_Helper__register_libraries,$(1),$(3))
232 gb_Library_MODULE_$(2) += $(filter-out $(gb_MERGEDLIBS),$(3))
234 $(if $(filter UNOVERLIBS RTVERLIBS,$(1)),\
235 gb_SdkLinkLibrary_MODULE_sdk += $(3))
237 endef
239 # a plugin is a library, why can't be dynamically linked and must be dlopen'd, but must be linked static
240 define gb_Helper_register_plugins_for_install
241 $(call gb_Helper_register_libraries_for_install,$(1),$(2),$(3))
242 gb_Library_KNOWNPLUGINS += $(3)
244 endef
246 define gb_Helper__register_jars
247 $(foreach group,$(gb_Jar_VALIDGROUPS),\
248 $(foreach target,$(2),\
249 $(if $(filter $(target),$(gb_Jar_$(group))),\
250 $(call gb_Output_error,gb_Helper_register_jars: already registered: $(target)))))
251 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
252 $(call gb_Output_error,gb_Helper_register_jars: contains duplicates: $(2)))
254 gb_Jar_$(1) += $(2)
256 endef
258 # $(call gb_Helper_register_jars,layer,jars)
259 define gb_Helper_register_jars
260 ifeq ($$(filter $(1),$$(gb_Jar_VALIDGROUPS_NOTINSTALLED)),)
261 $$(eval $$(call gb_Output_error,$(1) is not a valid group for jars that are not installed. Valid groups are: $$(gb_Jar_VALIDGROUPS_NOTINSTALLED). Use gb_Helper_register_jars_for_install for installed jars.))
262 endif
263 $(call gb_Helper__register_jars,$(1),$(2))
265 endef
267 # $(call gb_Helper_register_jars_for_install,layer,installmodule,jars)
268 define gb_Helper_register_jars_for_install
269 $(if $(3),,$(call gb_Output_error,gb_Helper_register_jars_for_install: no jars - need 3 parameters))
270 ifeq ($$(filter $(1),$$(gb_Jar_VALIDGROUPS_INSTALLED)),)
271 $$(eval $$(call gb_Output_error,$(1) is not a valid group for installed jars. Valid groups are: $$(gb_Jar_VALIDGROUPS_INSTALLED). Use gb_Helper_register_jars for jars that are not installed.))
272 endif
273 $(call gb_Helper__register_jars,$(1),$(3))
275 gb_Jar_MODULE_$(2) += $(3)
277 endef
279 define gb_Helper__register_packages
280 $(foreach target,$(1),\
281 $(if $(filter $(target),$(gb_Package_REGISTERED)),\
282 $(call gb_Output_error,gb_Helper_register_packages: already registered: $(target))))
283 $(if $(filter-out $(words $(1)),$(words $(sort $(1)))),\
284 $(call gb_Output_error,gb_Helper_register_packages: contains duplicates: $(1)))
286 gb_Package_REGISTERED += $(1)
288 endef
290 # $(call gb_Helper_register_packages,packages)
291 define gb_Helper_register_packages
292 $(call gb_Helper__register_packages,$(1))
294 endef
296 # $(call gb_Helper_register_packages_for_install,installmodule,packages)
297 define gb_Helper_register_packages_for_install
298 $(if $(2),,$(call gb_Output_error,gb_Helper_register_packages_for_install: no packages - need 2 parameters))
299 $(call gb_Helper__register_packages,$(2))
301 gb_Package_MODULE_$(1) += $(2)
303 endef
305 define gb_Helper_register_mos
306 gb_AllLangMoTarget_REGISTERED += $(1)
308 endef
310 # TODO: this should be extended to handle auto-installation.
311 define gb_Helper_register_uiconfigs
312 gb_UIConfig_REGISTERED += $(1)
314 endef
316 define gb_Helper_get_imagelists
317 $(foreach ui,$(gb_UIConfig_REGISTERED),$(call gb_UIConfig_get_imagelist_target,$(ui)))
318 endef
320 # call gb_Helper_replace_if_different_and_touch,source,target,optional-touch-reference-file
321 define gb_Helper_replace_if_different_and_touch
322 if cmp -s $(1) $(2); then rm $(1); \
323 else mv $(1) $(2) $(if $(3),&& touch -r $(3) $(2)); \
325 endef
327 # call gb_Helper_copy_if_different_and_touch,source,target,optional-touch-reference-file
328 define gb_Helper_copy_if_different_and_touch
329 if ! cmp -s $(1) $(2); then \
330 cp $(1) $(2) $(if $(3),&& touch -r $(3) $(2)); \
332 endef
334 define gb_Helper_define_if_set
335 $(foreach def,$(1),$(if $(filter TRUE YES,$($(def))),-D$(def)))
336 endef
338 define gb_Helper_execute
339 $(call gb_Executable_get_command,$(firstword $(1))) $(wordlist 2,$(words $(1)),$(1))
340 endef
342 # define gb_Helper_install registered-target target-to-install target-from-workdir
343 define gb_Helper_install
344 $(1) :| $(2)
345 $(2) : $(3) | $(dir $(2)).dir
346 $(call gb_Deliver_add_deliverable,$(2),$(3),$(2))
347 endef
349 # use if the installed target is the final target
350 define gb_Helper_install_final
351 $(1) : $(2) | $(dir $(1)).dir
352 $(call gb_Deliver_add_deliverable,$(1),$(2),$(1))
353 endef
355 # call gb_Helper_optional,build_type,if-true,if-false
356 define gb_Helper_optional
357 $(if $(filter $(1),$(BUILD_TYPE)),$(2),$(3))
358 endef
360 # call gb_Helper_optionals_or,build_types,if-true,if-false
361 define gb_Helper_optionals_or
362 $(call gb_Helper_optional,$(1),$(2),$(3))
363 endef
365 # call gb_Helper_optionals_and,build_types,if-true,if-false
366 define gb_Helper_optionals_and
367 $(if $(strip $(filter-out $(filter $(1),$(BUILD_TYPE)),$(1))),$(3),$(2))
368 endef
370 ifeq ($(WITH_LOCALES),)
371 define gb_Helper_optional_locale
372 $(2)
373 endef
374 else
375 define gb_Helper_optional_locale
376 $(if $(filter $(1) $(1)_%,$(WITH_LOCALES)),$(2))
377 endef
378 endif
380 define gb_Helper_print_on_error
381 $(if $(gb_QUIET_EXTERNAL), \
382 $(if $(2), \
383 ( ( $(1) ) > $(2) 2>&1 || ( cat $(2) && false ) ), \
384 ( TEMPFILE=$(shell $(gb_MKTEMP)) && ( $(1) ) > $$TEMPFILE 2>&1 \
385 && rm $$TEMPFILE \
386 || ( cat $$TEMPFILE && rm $$TEMPFILE && false ) )), \
387 ( $(1) ))
388 endef
390 # vim: set noet sw=4 ts=4: