Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gbuild / UIConfig.mk
blob7746a5de7b657359aa23c273827c4ed4ac5f6aff
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/.
10 # class UILocalizeTarget
12 # Produces translations for one .ui file.
14 gb_UILocalizeTarget_WORKDIR := $(WORKDIR)/UILocalizeTarget
16 gb_UILocalizeTarget_DEPS := $(call gb_Executable_get_runtime_dependencies,uiex)
17 gb_UILocalizeTarget_COMMAND := $(call gb_Executable_get_command,uiex)
19 # If translatable strings from a .ui file are not merged into the
20 # respective .po file yet, the produced translated files are empty,
21 # which breaks delivery. This hack avoids the problem by creating a
22 # dummy translation file.
23 $(call gb_UILocalizeTarget_get_workdir,%).ui :
24 $(if $(wildcard $@) \
25 ,touch $@ \
26 ,echo '<?xml version="1.0"?><t></t>' > $@ \
29 define gb_UILocalizeTarget__command
30 $(call gb_Output_announce,$(2),$(true),UIX,1)
31 MERGEINPUT=$(call var2file,$(shell $(gb_MKTEMP)),100,$(POFILES)) && \
32 $(call gb_Helper_abbreviate_dirs,\
33 $(gb_UILocalizeTarget_COMMAND) \
34 -i $(UIConfig_FILE) \
35 -o $(call gb_UILocalizeTarget_get_workdir,$(2)) \
36 -l all \
37 -m $${MERGEINPUT} \
38 && touch $(1) \
39 ) && \
40 rm -rf $${MERGEINPUT}
41 endef
43 $(dir $(call gb_UILocalizeTarget_get_target,%)).dir :
44 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
46 $(dir $(call gb_UILocalizeTarget_get_target,%))%/.dir :
47 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
49 $(call gb_UILocalizeTarget_get_target,%) : $(gb_UILocalizeTarget_DEPS)
50 $(call gb_UILocalizeTarget__command,$@,$*)
52 .PHONY : $(call gb_UILocalizeTarget_get_clean_target,%)
53 $(call gb_UILocalizeTarget_get_clean_target,%) :
54 $(call gb_Output_announce,$*,$(false),UIX,1)
55 $(call gb_Helper_abbreviate_dirs,\
56 rm -rf $(call gb_UILocalizeTarget_get_target,$*) $(call gb_UILocalizeTarget_get_workdir,$*) \
59 # Produce translations for one .ui file
61 # gb_UILocalizeTarget_UILocalizeTarget target
62 define gb_UILocalizeTarget_UILocalizeTarget
63 $(call gb_UILocalizeTarget__UILocalizeTarget_impl,$(1),$(2),$(wildcard $(foreach lang,$(gb_TRANS_LANGS),$(gb_POLOCATION)/$(lang)/$(patsubst %/,%,$(dir $(2))).po)))
65 endef
67 # gb_UILocalizeTarget__UILocalizeTarget_impl target pofiles
68 define gb_UILocalizeTarget__UILocalizeTarget_impl
69 $(call gb_UILocalizeTarget_get_target,$(1)) : POFILES := $(3)
70 $(call gb_UILocalizeTarget_get_target,$(1)) : UIConfig_FILE := $(SRCDIR)/$(2).ui
72 $(call gb_UILocalizeTarget_get_target,$(1)) : $(3)
73 $(call gb_UILocalizeTarget_get_target,$(1)) : $(SRCDIR)/$(2).ui
74 $(call gb_UILocalizeTarget_get_target,$(1)) :| \
75 $(dir $(call gb_UILocalizeTarget_get_target,$(1))).dir \
76 $(call gb_UILocalizeTarget_get_workdir,$(1))/.dir
78 endef
80 # class UIMenubarTarget
82 # Handles platform-specific processing of menubar config files.
84 # defined by platform:
85 # gb_UIMenubarTarget_UIMenubarTarget_platform
86 # gb_UIMenubarTarget__command
88 $(dir $(call gb_UIMenubarTarget_get_target,%)).dir :
89 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
91 $(dir $(call gb_UIMenubarTarget_get_target,%))%/.dir :
92 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
94 $(call gb_UIMenubarTarget_get_target,%) :
95 $(call gb_UIMenubarTarget__command,$@,$*,$<)
97 .PHONY : $(call gb_UIMenubarTarget_get_clean_target,%)
98 $(call gb_UIMenubarTarget_get_clean_target,%) :
99 $(call gb_Output_announce,$(2),$(false),UIM,1)
100 rm -f $(call gb_UIMenubarTarget_get_target,$*)
102 # Process a menubar configuration file.
104 # gb_UIMenubarTarget_UIMenubarTarget target source
105 define gb_UIMenubarTarget_UIMenubarTarget
106 $(call gb_UIMenubarTarget_get_target,$(1)) : $(2)
107 $(call gb_UIMenubarTarget_get_target,$(1)) :| $(dir $(call gb_UIMenubarTarget_get_target,$(1))).dir
109 $(call gb_UIMenubarTarget_UIMenubarTarget_platform,$(1),$(2))
111 endef
113 # class UIImageListTarget
115 # Handles creation of image lists for .ui files.
117 gb_UIImageListTarget_COMMAND = $(call gb_ExternalExecutable_get_command,xsltproc)
118 gb_UIImageListTarget_DEPS = $(call gb_ExternalExecutable_get_dependencies,xsltproc)
119 gb_UIImageListTarget_XSLTFILE := $(SRCDIR)/solenv/bin/uiimagelist.xsl
121 # NOTE: for some reason xsltproc does not produce any file if there is
122 # no output, so we touch the target to make sure it exists.
123 define gb_UIImageListTarget__command
124 $(call gb_Output_announce,$(2),$(true),UIL,1)
125 $(call gb_Helper_abbreviate_dirs,\
126 $(gb_UIImageListTarget_COMMAND) -o $@ $(gb_UIImageListTarget_XSLTFILE) $(UIFILE) && \
127 touch $@ \
129 endef
131 $(dir $(call gb_UIImageListTarget_get_target,%)).dir :
132 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
134 $(dir $(call gb_UIImageListTarget_get_target,%))%/.dir :
135 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
137 $(call gb_UIImageListTarget_get_target,%) : $(gb_UIImageListTarget_DEPS) $(gb_UIImageListTarget_XSLTFILE)
138 $(call gb_UIImageListTarget__command,$@,$*)
140 .PHONY : $(call gb_UIImageListTarget_get_clean_target,%)
141 $(call gb_UIImageListTarget_get_clean_target,%) :
142 $(call gb_Output_announce,$*,$(false),UIL,1)
143 rm -f $(call gb_UIImageListTarget_get_target,$*)
145 # Extract list of images referenced in a .ui file.
147 # gb_UIImageListTarget_UIImageListTarget uifile
148 define gb_UIImageListTarget_UIImageListTarget
149 $(call gb_UIImageListTarget_get_target,$(1)) : UIFILE := $(SRCDIR)/$(1).ui
151 $(call gb_UIImageListTarget_get_target,$(1)) : $(SRCDIR)/$(1).ui
152 $(call gb_UIImageListTarget_get_target,$(1)) :| $(dir $(call gb_UIImageListTarget_get_target,$(1))).dir
154 endef
156 # class UIConfig
158 # Handles UI configuration files.
160 # This mostly means UI description files (suffix .ui) for the new layouting
161 # mechanism.
163 # This class provides the following filelists:
164 # * UIConfig/<name> containing all nontranslatable files
165 # * UIConfig/<name>_<lang> for each active lang, containing translations
166 # of .ui files. This filelist only exists if the UIConfig contains any
167 # .ui files.
169 gb_UIConfig_INSTDIR := $(LIBO_SHARE_FOLDER)/config/soffice.cfg
170 # en-US is the default, so there is no translation for it
171 gb_UIConfig_LANGS := $(filter-out en-US,$(gb_WITH_LANG))
173 $(dir $(call gb_UIConfig_get_target,%)).dir :
174 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
176 $(dir $(call gb_UIConfig_get_target,%))%/.dir :
177 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
179 $(call gb_UIConfig_get_target,%) : $(call gb_UIConfig_get_imagelist_target,%)
180 $(call gb_Output_announce,$*,$(true),UIC,2)
181 $(call gb_Helper_abbreviate_dirs,\
182 touch $@ \
185 $(call gb_UIConfig_get_imagelist_target,%) :
186 $(call gb_UIConfig__command)
188 .PHONY : $(call gb_UIConfig_get_clean_target,%)
189 $(call gb_UIConfig_get_clean_target,%) :
190 $(call gb_Output_announce,$*,$(false),UIC,2)
191 $(call gb_Helper_abbreviate_dirs,\
192 rm -f $(call gb_UIConfig_get_target,$*) \
195 gb_UIConfig_get_packagename = UIConfig/$(1)
196 gb_UIConfig_get_packagesetname = UIConfig/$(1)
197 gb_UIConfig_get_zipname_for_lang = UIConfig/$(1)/$(2)
199 # Processes and delivers a set of UI configuration files.
201 # gb_UIConfig_UIConfig modulename
202 define gb_UIConfig_UIConfig
203 $(call gb_UIConfig_get_imagelist_target,$(1)) : UI_IMAGELISTS :=
205 $(call gb_PackageSet_PackageSet_internal,$(call gb_UIConfig_get_packagesetname,$(1)))
206 $(call gb_Package_Package_internal,$(call gb_UIConfig_get_packagename,$(1)),$(SRCDIR))
207 $(call gb_Package_Package_internal,$(call gb_UIConfig_get_packagename,$(1)_generated),$(WORKDIR))
209 $(call gb_PackageSet_add_package,$(call gb_UIConfig_get_packagesetname,$(1)),$(call gb_UIConfig_get_packagename,$(1)))
211 $(call gb_UIConfig_get_target,$(1)) :| $(dir $(call gb_UIConfig_get_target,$(1))).dir
212 $(call gb_UIConfig_get_imagelist_target,$(1)) :| $(dir $(call gb_UIConfig_get_imagelist_target,$(1))).dir
213 $(call gb_UIConfig_get_target,$(1)) : $(call gb_PackageSet_get_target,$(call gb_UIConfig_get_packagesetname,$(1)))
214 $(call gb_UIConfig_get_clean_target,$(1)) : $(call gb_PackageSet_get_clean_target,$(call gb_UIConfig_get_packagesetname,$(1)))
216 ifneq ($(gb_UIConfig_LANGS),)
217 $(foreach lang,$(gb_UIConfig_LANGS),$(call gb_UIConfig__UIConfig_for_lang,$(1),$(lang)))
218 endif
220 $$(eval $$(call gb_Module_register_target,$(call gb_UIConfig_get_target,$(1)),$(call gb_UIConfig_get_clean_target,$(1))))
221 $(call gb_Helper_make_userfriendly_targets,$(1),UIConfig)
222 $(call gb_Postprocess_register_target,AllUIConfigs,UIConfig,$(1))
224 endef
226 define gb_UIConfig__UIConfig_for_lang
227 $(call gb_UIConfig_get_target,$(1)) : $(call gb_Zip_get_target,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2)))
228 $(call gb_UIConfig_get_clean_target,$(1)) : $(call gb_Zip_get_clean_target,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2)))
229 $(call gb_Zip_Zip_internal,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2)),$(gb_UILocalizeTarget_WORKDIR)/$(1))
230 $(call gb_Zip_add_commandoptions,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2)),--suffixes .ui)
231 $(call gb_Zip_get_target,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2))) : $(SRCDIR)/solenv/gbuild/UIConfig.mk
232 $(call gb_Zip_set_install_name,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(2)),$(INSTROOT)/$(gb_UIConfig_INSTDIR)/$(1)/ui/res/$(2).zip)
234 endef
236 # gb_UIConfig__package_file target package type destfile srcfile
237 define gb_UIConfig__package_file
238 $(call gb_Package_add_file,$(2),$(gb_UIConfig_INSTDIR)/$(1)/$(3)/$(4),$(5))
240 endef
242 # gb_UIConfig__package_uifile target package destfile srcfile
243 define gb_UIConfig__package_uifile
244 $(call gb_UIConfig__package_file,$(1),$(2),ui,$(3),$(4))
246 endef
248 # gb_UIConfig__add_uifile target file
249 define gb_UIConfig__add_uifile
250 $(call gb_UIConfig__package_uifile,$(1),$(call gb_UIConfig_get_packagename,$(1)),$(notdir $(2)).ui,$(2).ui)
251 $(call gb_UIImageListTarget_UIImageListTarget,$(2))
253 $(call gb_UIConfig_get_imagelist_target,$(1)) : UI_IMAGELISTS += $(call gb_UIImageListTarget_get_target,$(2))
254 $(call gb_UIConfig_get_imagelist_target,$(1)) : $(call gb_UIImageListTarget_get_target,$(2))
255 $(call gb_UIConfig_get_clean_target,$(1)) : $(call gb_UIImageListTarget_get_clean_target,$(2))
257 endef
259 # Add a l10n for an .ui file to respective lang package.
261 # gb_UIConfig__add_uifile_for_lang target file lang
262 define gb_UIConfig__add_uifile_for_lang
263 $(call gb_Zip_add_file,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(3)),$(notdir $(2))/$(3).ui)
264 $(call gb_Zip_add_dependency,$(call gb_UIConfig_get_zipname_for_lang,$(1),$(3)),$(call gb_UILocalizeTarget_get_target,$(1)/$(notdir $(2))))
266 endef
268 # Add a l10n for an .ui file to respective lang package.
270 # This is only for "real" languages, i.e., everything except qtz.
272 # gb_UIConfig__add_uifile_for_real_lang target file lang
273 define gb_UIConfig__add_uifile_for_real_lang
274 $(if $(filter qtz,$(3)),$(call gb_Output_error,gb_UIConfig__add_uifile_for_real_lang called with qtz))
275 $(call gb_UIConfig__add_uifile_for_lang,$(1),$(2),$(3))
277 endef
279 # gb_UIConfig__add_translations_impl target uifile langs
280 define gb_UIConfig__add_translations_impl
281 $(call gb_UILocalizeTarget_UILocalizeTarget,$(1)/$(notdir $(2)),$(2))
282 $(call gb_UIConfig_get_target,$(1)) : $(call gb_UILocalizeTarget_get_target,$(1)/$(notdir $(2)))
283 $(call gb_UIConfig_get_clean_target,$(1)) : $(call gb_UILocalizeTarget_get_clean_target,$(1)/$(notdir $(2)))
284 $(foreach lang,$(3),$(call gb_UIConfig__add_uifile_for_real_lang,$(1),$(2),$(lang)))
286 endef
288 # gb_UIConfig__add_translations target uifile langs qtz
289 define gb_UIConfig__add_translations
290 $(if $(strip $(3) $(4)),$(call gb_UIConfig__add_translations_impl,$(1),$(2),$(3)))
291 $(if $(strip $(4)),$(call gb_UIConfig__add_uifile_for_lang,$(1),$(2),$(strip $(4))))
293 endef
295 # Adds translations for languages that have corresponding .po file
297 # gb_UIConfig__add_uifile_translations target uifile
298 define gb_UIConfig__add_uifile_translations
299 $(call gb_UIConfig__add_translations,$(1),$(2),\
300 $(foreach lang,$(gb_UIConfig_LANGS),\
301 $(if $(wildcard $(gb_POLOCATION)/$(lang)/$(patsubst %/,%,$(dir $(2))).po),$(lang)) \
303 $(filter qtz,$(gb_UIConfig_LANGS)) \
306 endef
309 gb_UIConfig_ALLFILES:=
310 # Adds .ui file to the package
312 # The file is relative to $(SRCDIR) and without extension.
314 # gb_UIConfig_add_uifile target uifile
315 define gb_UIConfig_add_uifile
316 gb_UIConfig_ALLFILES+=$(1):$(notdir $(2))
317 $(call gb_UIConfig__add_uifile,$(1),$(2))
319 ifneq ($(gb_UIConfig_LANGS),)
320 $(call gb_UIConfig__add_uifile_translations,$(1),$(2))
321 endif
323 endef
325 # Adds multiple .ui files to the package
327 # gb_UIConfig_add_uifiles target uifile(s)
328 define gb_UIConfig_add_uifiles
329 $(foreach uifile,$(2),$(call gb_UIConfig_add_uifile,$(1),$(uifile)))
331 endef
333 # gb_UIConfig__add_xmlfile target package-target type xmlfile
334 define gb_UIConfig__add_xmlfile
335 $(call gb_UIConfig__package_file,$(1),$(call gb_UIConfig_get_packagename,$(2)),$(3),$(notdir $(4)).xml,$(4).xml)
337 endef
339 define gb_UIConfig__add_menubarfile
340 $(call gb_UIMenubarTarget_UIMenubarTarget,$(2),$(3))
341 $(call gb_Package_add_file,$(call gb_UIConfig_get_packagename,$(1)_generated),$(gb_UIConfig_INSTDIR)/$(1)/menubar/$(notdir $(2)).xml,$(subst $(WORKDIR)/,,$(call gb_UIMenubarTarget_get_target,$(2))))
342 $(call gb_PackageSet_add_package,$(call gb_UIConfig_get_packagesetname,$(1)),$(call gb_UIConfig_get_packagename,$(1)_generated))
344 $(call gb_Package_get_target,$(call gb_UIConfig_get_packagename,$(1)_generated)) : $(call gb_UIMenubarTarget_get_target,$(2))
345 $(call gb_Package_get_clean_target,$(call gb_UIConfig_get_packagename,$(1)_generated)) : $(call gb_UIMenubarTarget_get_clean_target,$(2))
347 endef
349 # Add menubar config file to the package.
351 # The file is relative to $(SRCDIR) and without extension.
353 # gb_UIConfig_add_menubarfile target file
354 define gb_UIConfig_add_menubarfile
355 $(call gb_UIConfig__add_menubarfile,$(1),$(gb_UIConfig_INSTDIR)/$(1)/menubar/$(notdir $(2)),$(SRCDIR)/$(2).xml)
357 endef
359 # Adds multiple menubar config files to the package.
361 # gb_UIConfig_add_menubarfiles target file(s)
362 define gb_UIConfig_add_menubarfiles
363 $(foreach menubarfile,$(2),$(call gb_UIConfig_add_menubarfile,$(1),$(menubarfile)))
365 endef
367 # Add a generated menubar config file to the package.
369 # The file is relative to $(WORKDIR) and without extension.
371 # gb_UIConfig_add_generated_menubarfile target file
372 define gb_UIConfig_add_generated_menubarfile
373 $(call gb_UIConfig__add_menubarfile,$(1),$(gb_UIConfig_INSTDIR)/$(1)/menubar/$(notdir $(2)),$(WORKDIR)/$(2).xml)
375 endef
377 # Adds multiple menubar config files to the package.
379 # gb_UIConfig_add_generated_menubarfiles target file(s)
380 define gb_UIConfig_add_generated_menubarfiles
381 $(foreach menubarfile,$(2),$(call gb_UIConfig_add_generated_menubarfile,$(1),$(menubarfile)))
383 endef
385 # Add statusbar config file to the package.
387 # The file is relative to $(SRCDIR) and without extension.
389 # gb_UIConfig_add_statusbarfile target file
390 define gb_UIConfig_add_statusbarfile
391 $(call gb_UIConfig__add_xmlfile,$(1),$(1),statusbar,$(2))
393 endef
395 # Adds multiple statusbar config files to the package.
397 # gb_UIConfig_add_statusbarfiles target file(s)
398 define gb_UIConfig_add_statusbarfiles
399 $(foreach statusbarfile,$(2),$(call gb_UIConfig_add_statusbarfile,$(1),$(statusbarfile)))
401 endef
403 # Add toolbar config file to the package.
405 # The file is relative to $(SRCDIR) and without extension.
407 # gb_UIConfig_add_toolbarfile target file
408 define gb_UIConfig_add_toolbarfile
409 $(call gb_UIConfig__add_xmlfile,$(1),$(1),toolbar,$(2))
411 endef
413 # Adds multiple toolbar config files to the package.
415 # gb_UIConfig_add_toolbarfiles target file(s)
416 define gb_UIConfig_add_toolbarfiles
417 $(foreach toolbarfile,$(2),$(call gb_UIConfig_add_toolbarfile,$(1),$(toolbarfile)))
419 endef
421 # vim: set noet sw=4 ts=4: