bump product version to 4.2.0.1
[LibreOffice.git] / solenv / gbuild / Helper.mk
bloba22f2f807d38b61b9329ff6cb25e1e0bc62886cc
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 .PHONY : $(WORKDIR)/Misc/PHONY
29 $(gb_Helper_MISCDUMMY) :
30 @mkdir -p $(dir $@) && touch $@
32 ifeq ($(SRCDIR),$(BUILDDIR))
33 define gb_Helper_abbreviate_dirs
34 S=$(SRCDIR) && \
35 $(subst $(SRCDIR)/,$$S/,I=$(INSTDIR)) && \
36 $(subst $(SRCDIR)/,$$S/,W=$(WORKDIR)) && \
37 $(subst $(SRCDIR)/,$$S/,$(subst $(INSTDIR)/,$$I/,$(subst $(WORKDIR)/,$$W/,$(1))))
38 endef
39 else
40 define gb_Helper_abbreviate_dirs
41 S=$(SRCDIR) && \
42 $(subst $(SRCDIR)/,$$S/,B=$(BUILDDIR)) && \
43 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,I=$(INSTDIR))) && \
44 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,W=$(WORKDIR))) && \
45 $(subst $(SRCDIR)/,$$S/,$(subst $(BUILDDIR)/,$$B/,$(subst $(INSTDIR)/,$$I/,$(subst $(WORKDIR)/,$$W/,$(1)))))
46 endef
47 endif
49 define gb_Helper_abbreviate_dirs_native
50 $(call gb_Output_error,gb_Helper_abbreviate_dirs_native: use gb_Helper_abbreviate_dirs instead.)
51 endef
53 define gb_Helper_native_path
54 $(call gb_Output_error,gb_Helper_native_path: Do not use. Should not be necessary.)
55 endef
57 # cygwin seems to eat one backslash when executing command, thus replace with '\\'
58 define gb_Helper_windows_path
59 $(subst /,\\,$(1))
60 endef
62 define gb_Helper_make_clean_target
63 gb_$(1)_get_clean_target = $(WORKDIR)/Clean/$(1)/$$(1)
65 endef
67 define gb_Helper_make_dep_target
68 gb_$(1)_get_dep_target = $(WORKDIR)/Dep/$(1)/$$(1).d
70 endef
72 define gb_Helper_make_clean_targets
73 $(foreach targettype,$(1),\
74 $(call gb_Helper_make_clean_target,$(targettype)))
76 endef
78 define gb_Helper_make_dep_targets
79 $(foreach targettype,$(1),\
80 $(call gb_Helper_make_dep_target,$(targettype)))
82 endef
84 # e.g. 'make CppunitTest_sw_macros_test'
86 # gb_Helper_make_userfriendly_targets target class build-target? clean-target?
87 define gb_Helper_make_userfriendly_targets
88 .PHONY: $(2)_$(1) $(2)_$(1).clean
89 $(2)_$(1) : $(if $(3),$(3),$(call gb_$(2)_get_target,$(1)))
90 $(2)_$(1).clean : $(if $(4),$(4),$(call gb_$(2)_get_clean_target,$(1)))
92 endef
94 define gb_Helper_init_registries
95 gb_Executable_VALIDGROUPS := UREBIN SDK OOO NONE
96 gb_Library_VALIDGROUPS := OOOLIBS PLAINLIBS_NONE PLAINLIBS_URE PLAINLIBS_OOO PRIVATELIBS_URE RTVERLIBS UNOVERLIBS EXTENSIONLIBS PLAINLIBS_SHLXTHDL
97 gb_Jar_VALIDGROUPS := URE OOO OXT NONE
99 $$(foreach group,$$(gb_Executable_VALIDGROUPS),$$(eval gb_Executable_$$(group) :=))
100 $$(foreach group,$$(gb_Library_VALIDGROUPS),$$(eval gb_Library_$$(group) :=))
101 $$(foreach group,$$(gb_Jar_VALIDGROUPS),$$(eval gb_Jar_$$(group) :=))
103 endef
105 define gb_Helper_collect_knownlibs
106 gb_Library_KNOWNLIBS := $$(foreach group,$$(gb_Library_VALIDGROUPS),$$(gb_Library_$$(group)))
107 gb_Executable_KNOWN := $$(foreach group,$$(gb_Executable_VALIDGROUPS),$$(gb_Executable_$$(group)))
108 gb_Jar_KNOWN := $$(foreach group,$$(gb_Jar_VALIDGROUPS),$$(gb_Jar_$$(group)))
110 endef
112 define gb_Helper_process_executable_registrations
113 $(foreach group,$(gb_Executable_VALIDGROUPS),\
114 $(foreach executable,$(gb_Executable_$(group)),\
115 $(if $(filter-out undefined,$(origin gb_Executable__register_$(executable))),\
116 $(call gb_Executable__register_$(executable)))))
118 endef
120 define gb_Helper_register_executables
121 ifeq ($$(filter $(1),$$(gb_Executable_VALIDGROUPS)),)
122 $$(eval $$(call gb_Output_error,$(1) is not a valid group for executables. Valid groups are: $$(gb_Executable_VALIDGROUPS)))
123 endif
124 $(foreach group,$(gb_Executable_VALIDGROUPS),\
125 $(foreach target,$(2),\
126 $(if $(filter $(target),$(gb_Executable_$(group))),\
127 $(call gb_Output_error,gb_Helper_register_executables: already registered: $(target)))))
128 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
129 $(call gb_Output_error,gb_Helper_register_executables: contains duplicates: $(2)))
131 gb_Executable_$(1) += $(2)
133 endef
135 define gb_Helper_register_executables_for_install
136 $(call gb_Helper_register_executables,$(1),$(3))
138 gb_Executable_MODULE_$(2) += $(3)
140 endef
142 define gb_Helper_register_libraries
143 ifeq ($$(filter $(1),$$(gb_Library_VALIDGROUPS)),)
144 $$(eval $$(call gb_Output_error,$(1) is not a valid group for libraries. Valid groups are: $$(gb_Library_VALIDGROUPS)))
145 endif
146 $(foreach group,$(gb_Library_VALIDGROUPS),\
147 $(foreach target,$(2),\
148 $(if $(filter $(target),$(gb_Library_$(group))),\
149 $(call gb_Output_error,gb_Helper_register_libraries: already registered: $(target)))))
150 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
151 $(call gb_Output_error,gb_Helper_register_libraries: contains duplicates: $(2)))
153 gb_Library_$(1) += $(2)
155 endef
157 # the first argument is the group, which sets rpaths etc.
158 # the second argument is the install module, which describes in which distro package/msi a lib should show up
159 define gb_Helper_register_libraries_for_install
160 $(call gb_Helper_register_libraries,$(1),$(3))
162 gb_Library_MODULE_$(2) += $(filter-out $(gb_MERGEDLIBS) $(gb_URELIBS),$(3))
164 endef
166 define gb_Helper_register_jars
167 ifeq ($$(filter $(1),$$(gb_Jar_VALIDGROUPS)),)
168 $$(eval $$(call gb_Output_error,$(1) is not a valid group for jars. Valid groups are: $$(gb_Jar_VALIDGROUPS)))
169 endif
170 $(foreach group,$(gb_Jar_VALIDGROUPS),\
171 $(foreach target,$(2),\
172 $(if $(filter $(target),$(gb_Jar_$(group))),\
173 $(call gb_Output_error,gb_Helper_register_jars: already registered: $(target)))))
174 $(if $(filter-out $(words $(2)),$(words $(sort $(2)))),\
175 $(call gb_Output_error,gb_Helper_register_jars: contains duplicates: $(2)))
177 gb_Jar_$(1) += $(2)
179 endef
181 define gb_Helper_define_if_set
182 $(foreach def,$(1),$(if $(filter TRUE YES,$($(def))),-D$(def)))
183 endef
185 define gb_Helper_execute
186 $(call gb_Executable_get_command,$(firstword $(1))) $(wordlist 2,$(words $(1)),$(1))
187 endef
189 # define gb_Helper_install registered-target target-to-install target-from-workdir
190 define gb_Helper_install
191 $(1) :| $(2)
192 $(2) : $(3) | $(dir $(2)).dir
193 $(call gb_Deliver_add_deliverable,$(2),$(3),$(2))
194 endef
196 # use if the installed target is the final target
197 define gb_Helper_install_final
198 $(1) : $(2) | $(dir $(1)).dir
199 $(call gb_Deliver_add_deliverable,$(1),$(2),$(1))
200 endef
202 define gb_Helper_optional
203 $(if $(filter $(1),$(BUILD_TYPE)),$(2))
204 endef
206 define gb_Helper_optional_for_host
207 $(if $(filter $(1),$(BUILD_TYPE_FOR_HOST)),$(2))
208 endef
210 define gb_Helper_print_on_error
211 $(if $(gb_QUIET_EXTERNAL),( $(1) ) > $(2) 2>&1 || ( cat $(2) && false ),$(1) )
212 endef
214 # vim: set noet sw=4 ts=4: