Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / solenv / gbuild / UI.mk
blob62f7870e9a6bf31dc13105d19bc971444e9b9bc0
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_TARGET := $(call gb_Executable_get_target_for_build,uiex)
17 gb_UILocalizeTarget_COMMAND := $(gb_Helper_set_ld_path) $(gb_UILocalizeTarget_TARGET)
18 gb_UILocalizeTarget_LANGS := $(filter-out qtz,$(filter-out en-US,$(gb_WITH_LANG)))
20 # If translatable strings from a .ui file are not merged into the
21 # respective .po file yet, the produced translated files are empty (that
22 # is, they only contain the root element), but qtz is not created at all
23 # which breaks delivery. This hack avoids the problem by creating a
24 # dummy translation file.
25 define gb_UILocalizeTarget__fix_missing_qtz
26 $(if $(filter qtz,$(gb_WITH_LANG)),\
27 && if [ ! -f $(1)/qtz.ui ]; then \
28 echo '<?xml version="1.0"?><t></t>' > $(1)/qtz.ui; \
29 fi \
31 endef
33 define gb_UILocalizeTarget__command
34 $(call gb_Output_announce,$(2),$(true),UIX,1)
35 MERGEINPUT=`$(gb_MKTEMP)` && \
36 echo $(POFILES) > $${MERGEINPUT} && \
37 $(call gb_Helper_abbreviate_dirs,\
38 $(gb_UILocalizeTarget_COMMAND) \
39 -i $(UI_FILE) \
40 -o $(call gb_UILocalizeTarget_get_workdir,$(2)) \
41 -l all \
42 -m $${MERGEINPUT} \
43 $(call gb_UILocalizeTarget__fix_missing_qtz,$(call gb_UILocalizeTarget_get_workdir,$(2))) \
44 && touch $(1) \
45 ) && \
46 rm -rf $${MERGEINPUT}
47 endef
49 $(dir $(call gb_UILocalizeTarget_get_target,%)).dir :
50 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
52 $(dir $(call gb_UILocalizeTarget_get_target,%))%/.dir :
53 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
55 $(call gb_UILocalizeTarget_get_target,%) : $(gb_UILocalizeTarget_TARGET)
56 $(call gb_UILocalizeTarget__command,$@,$*)
58 .PHONY : $(call gb_UILocalizeTarget_get_clean_target,%)
59 $(call gb_UILocalizeTarget_get_clean_target,%) :
60 $(call gb_Output_announce,$*,$(false),UIX,1)
61 $(call gb_Helper_abbreviate_dirs,\
62 rm -f $(call gb_UILocalizeTarget_get_target,$*) \
65 # Produce translations for one .ui file
67 # gb_UILocalizeTarget_UILocalizeTarget target
68 define gb_UILocalizeTarget_UILocalizeTarget
69 $(call gb_UILocalizeTarget__UILocalizeTarget_impl,$(1),$(foreach lang,$(gb_UILocalizeTarget_LANGS),$(gb_POLOCATION)/$(lang)/$(patsubst %/,%,$(dir $(1))).po))
71 endef
73 # gb_UILocalizeTarget__UILocalizeTarget_impl target pofiles
74 define gb_UILocalizeTarget__UILocalizeTarget_impl
75 $(call gb_UILocalizeTarget_get_target,$(1)) : POFILES := $(2)
76 $(call gb_UILocalizeTarget_get_target,$(1)) : UI_FILE := $(SRCDIR)/$(1).ui
78 $(call gb_UILocalizeTarget_get_target,$(1)) : $(2)
79 $(call gb_UILocalizeTarget_get_target,$(1)) : $(SRCDIR)/$(1).ui
80 $(call gb_UILocalizeTarget_get_target,$(1)) :| \
81 $(dir $(call gb_UILocalizeTarget_get_target,$(1))).dir \
82 $(call gb_UILocalizeTarget_get_workdir,$(1))/.dir
84 $(2) :
86 endef
88 # class UI
90 # Handles UI description files (suffix .ui) for the new layouting mechanism.
92 # en-US is the default, so there is no translation for it
93 gb_UI_LANGS := $(filter-out en-US,$(gb_WITH_LANG))
95 $(dir $(call gb_UI_get_target,%)).dir :
96 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
98 $(dir $(call gb_UI_get_target,%))%/.dir :
99 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
101 $(call gb_UI_get_target,%) :
102 $(call gb_Output_announce,$*,$(true),UI ,2)
103 $(call gb_Helper_abbreviate_dirs,\
104 touch $@ \
107 .PHONY : $(call gb_UI_get_clean_target,%)
108 $(call gb_UI_get_clean_target,%) :
109 $(call gb_Output_announce,$*,$(false),UI ,2)
110 $(call gb_Helper_abbreviate_dirs,\
111 rm -f $(call gb_UI_get_target,$*) \
114 # Translates and delivers a set of .ui files
116 # gb_UI_UI modulename
117 define gb_UI_UI
118 $(call gb_Package_Package_internal,$(1)_ui,$(SRCDIR))
119 $(call gb_UI_get_target,$(1)) :| $(dir $(call gb_UI_get_target,$(1))).dir
120 $(call gb_UI_get_target,$(1)) :| $(call gb_Package_get_target,$(1)_ui)
121 $(call gb_UI_get_clean_target,$(1)) : $(call gb_Package_get_clean_target,$(1)_ui)
123 ifneq ($(gb_UI_LANGS),)
124 $(call gb_Package_Package_internal,$(1)_ui_localized,$(gb_UILocalizeTarget_WORKDIR))
125 $(call gb_UI_get_target,$(1)) :| $(call gb_Package_get_target,$(1)_ui_localized)
126 $(call gb_UI_get_clean_target,$(1)) : $(call gb_Package_get_clean_target,$(1)_ui_localized)
127 endif
129 $$(eval $$(call gb_Module_register_target,$(call gb_UI_get_target,$(1)),$(call gb_UI_get_clean_target,$(1))))
130 endef
132 # gb_UI__package_uifile target package destfile srcfile
133 define gb_UI__package_uifile
134 $(call gb_Package_add_file,$(2),xml/uiconfig/$(1)/ui/$(3),$(4))
136 endef
138 # gb_UI__add_uifile target file
139 define gb_UI__add_uifile
140 $(call gb_UI__package_uifile,$(1),$(1)_ui,$(notdir $(2)).ui,$(2).ui)
142 endef
144 # gb_UI__add_uifile_for_lang target file lang
145 define gb_UI__add_uifile_for_lang
146 $(call gb_UI__package_uifile,$(1),$(1)_ui_localized,res/$(3)/$(notdir $(2)),$(2)/$(3).ui)
148 endef
150 # gb_UI__add_translations_impl target uifile langs
151 define gb_UI__add_translations_impl
152 $(call gb_UILocalizeTarget_UILocalizeTarget,$(2))
153 $(call gb_UI_get_target,$(1)) : $(call gb_UILocalizeTarget_get_target,$(2))
154 $(call gb_UI_get_clean_target,$(1)) : $(call gb_UILocalizeTarget_get_clean_target,$(2))
155 $(call gb_Package_get_preparation_target,$(1)_ui_localized) : $(call gb_UILocalizeTarget_get_target,$(2))
156 $(foreach lang,$(3),$(call gb_UI__add_uifile_for_lang,$(1),$(2),$(lang)))
158 endef
160 # gb_UI__add_translations target uifile langs qtz
161 define gb_UI__add_translations
162 $(if $(strip $(3) $(4)),$(call gb_UI__add_translations_impl,$(1),$(2),$(3)))
163 $(if $(strip $(4)),$(call gb_UI__add_uifile_for_lang,$(1),$(2),$(strip $(4))))
165 endef
167 # Adds translations for languages that have corresponding .po file
169 # gb_UI__add_uifile_translations target uifile
170 define gb_UI__add_uifile_translations
171 $(call gb_UI__add_translations,$(1),$(2),\
172 $(foreach lang,$(gb_UI_LANGS),\
173 $(if $(wildcard $(gb_POLOCATION)/$(lang)/$(patsubst %/,%,$(dir $(2))).po),$(lang)) \
175 $(filter qtz,$(gb_UI_LANGS)) \
178 endef
180 # Adds .ui file to the package
182 # The file is relative to $(SRCDIR) and without extension.
184 # gb_UI_add_uifile target uifile
185 define gb_UI_add_uifile
186 $(call gb_UI__add_uifile,$(1),$(2))
188 ifneq ($(gb_UI_LANGS),)
189 $(call gb_UI__add_uifile_translations,$(1),$(2))
190 endif
192 endef
194 # Adds multiple .ui files to the package
196 # gb_UI_add_uifiles target uifile(s)
197 define gb_UI_add_uifiles
198 $(foreach uifile,$(2),$(call gb_UI_add_uifile,$(1),$(uifile)))
200 endef
202 # vim: set noet sw=4 ts=4: