Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gbuild / Dictionary.mk
blob8b8c8c56f8f9bd8e7c0e7c9147255eea0f869783
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 # ThesaurusIndexTarget class
12 gb_ThesaurusIndexTarget_CHECK_TARGET := $(SRCDIR)/dictionaries/util/th_check.pl
13 gb_ThesaurusIndexTarget_CHECK_COMMAND := PERL_UNICODE=0 $(PERL) -w $(gb_ThesaurusIndexTarget_CHECK_TARGET)
14 gb_ThesaurusIndexTarget_INDEX_DEPS := $(call gb_Executable_get_runtime_dependencies,idxdict)
15 gb_ThesaurusIndexTarget_INDEX_COMMAND := $(call gb_Executable_get_command,idxdict)
17 define gb_ThesaurusIndexTarget__command
18 $(call gb_Output_announce,$(2),$(true),THI,1)
19 $(call gb_Helper_abbreviate_dirs,\
20 $(gb_ThesaurusIndexTarget_INDEX_COMMAND) -o $(1) < $(THESAURUS_FILE) \
22 endef
23 #$(gb_ThesaurusIndexTarget_CHECK_COMMAND) $(THESAURUS_FILE) && \
25 $(dir $(call gb_ThesaurusIndexTarget_get_target,%)).dir :
26 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
28 $(dir $(call gb_ThesaurusIndexTarget_get_target,%))%/.dir :
29 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
31 $(call gb_ThesaurusIndexTarget_get_target,%) : $(gb_ThesaurusIndexTarget_INDEX_DEPS) | $(gb_ThesaurusIndexTarget_CHECK_TARGET)
32 $(call gb_ThesaurusIndexTarget__command,$@,$*)
34 .PHONY : $(call gb_ThesaurusIndexTarget_get_clean_target,%)
35 $(call gb_ThesaurusIndexTarget_get_clean_target,%) :
36 $(call gb_Output_announce,$*,$(false),THI,1)
37 $(call gb_Helper_abbreviate_dirs,\
38 rm -f $(call gb_ThesaurusIndexTarget_get_target,$*) \
41 # Creates an index for a given thesaurus
43 # The thesaurus' file path is relative to $(SRCDIR).
45 # gb_ThesaurusIndexTarget_ThesaurusIndexTarget thesaurus
46 define gb_ThesaurusIndexTarget_ThesaurusIndexTarget
47 $(call gb_ThesaurusIndexTarget_get_target,$(1)) : THESAURUS_FILE := $(SRCDIR)/$(1)
48 $(call gb_ThesaurusIndexTarget_get_target,$(1)) : $(SRCDIR)/$(1)
49 $(call gb_ThesaurusIndexTarget_get_target,$(1)) :| $(dir $(call gb_ThesaurusIndexTarget_get_target,$(1))).dir
51 endef
53 # PropertiesTranslateTarget class
55 # Handles translation of .properties files in dictionaries.
57 gb_PropertiesTranslateTarget_COMMAND := $(call gb_Executable_get_command,propex)
58 gb_PropertiesTranslateTarget_DEPS := $(call gb_Executable_get_runtime_dependencies,propex)
60 define gb_PropertiesTranslateTarget__command
61 $(call gb_Output_announce,$(2),$(true),PRP,1)
62 $(call gb_Helper_abbreviate_dirs, \
63 $(if $(filter-out qtz,$(LANG)), \
64 MERGEINPUT=$(call var2file,$(shell $(gb_MKTEMP)),100,$(POFILE)) && \
65 $(gb_PropertiesTranslateTarget_COMMAND) \
66 -i $(PROPERTIES_FILE) \
67 -l $(LANG) \
68 -m $${MERGEINPUT} \
69 -o $(1) && \
70 rm -f $${MERGEINPUT} \
71 , \
72 $(gb_PropertiesTranslateTarget_COMMAND) \
73 -i $(PROPERTIES_FILE) \
74 -l $(LANG) \
75 -m \
76 -o $(1) \
77 ) \
79 endef
81 $(dir $(call gb_PropertiesTranslateTarget_get_target,%)).dir :
82 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
84 $(dir $(call gb_PropertiesTranslateTarget_get_target,%))%/.dir :
85 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
87 $(call gb_PropertiesTranslateTarget_get_target,%) : $(gb_PropertiesTranslateTarget_DEPS)
88 $(call gb_PropertiesTranslateTarget__command,$@,$*)
90 .PHONY : $(call gb_PropertiesTranslateTarget_get_clean_target,%)
91 $(call gb_PropertiesTranslateTarget_get_clean_target,%) :
92 $(call gb_Output_announce,$*,$(false),PRP,1)
93 rm -f $(call gb_PropertiesTranslateTarget_get_target,$*)
95 # gb_PropertiesTranslateTarget_PropertiesTranslateTarget target source lang
96 define gb_PropertiesTranslateTarget_PropertiesTranslateTarget
97 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : LANG := $(3)
98 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : POFILE := $(gb_POLOCATION)/$(3)/$(patsubst %/,%,$(dir $(2))).po
99 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : PROPERTIES_FILE := $(SRCDIR)/$(2)
101 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : $(SRCDIR)/$(2)
102 $(call gb_PropertiesTranslateTarget_get_target,$(1)) :| $(dir $(call gb_PropertiesTranslateTarget_get_target,$(1))).dir
104 $(if $(filter-out qtz,$(3)),\
105 $(call gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang,$(1),$(gb_POLOCATION)/$(3)/$(patsubst %/,%,$(dir $(2))).po) \
108 endef
110 # gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang target pofile
111 define gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang
112 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : $(2)
113 $(2) :
115 endef
117 # DescriptionTranslateTarget class
119 # Handles translation of description.xml files in dictionaries.
121 gb_DescriptionTranslateTarget_COMMAND := $(call gb_Executable_get_command,xrmex)
122 gb_DescriptionTranslateTarget_DEPS := $(call gb_Executable_get_runtime_dependencies,xrmex)
124 define gb_DescriptionTranslateTarget__command
125 $(call gb_Output_announce,$(2),$(true),XRM,1)
126 $(call gb_Helper_abbreviate_dirs,\
127 MERGEINPUT=$(call var2file,$(shell $(gb_MKTEMP)),100,$(POFILES)) && \
128 $(gb_DescriptionTranslateTarget_COMMAND) \
129 -i $(DESCRIPTION_XML) \
130 -l all \
131 -m $${MERGEINPUT} \
132 -o $(1) && \
133 rm -f $${MERGEINPUT} \
135 endef
137 $(dir $(call gb_DescriptionTranslateTarget_get_target,%)).dir :
138 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
140 $(dir $(call gb_DescriptionTranslateTarget_get_target,%))%/.dir :
141 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
143 $(call gb_DescriptionTranslateTarget_get_target,%) : $(gb_DescriptionTranslateTarget_DEPS)
144 $(call gb_DescriptionTranslateTarget__command,$@,$*)
146 .PHONY : $(call gb_DescriptionTranslateTarget_get_clean_target,%)
147 $(call gb_DescriptionTranslateTarget_get_clean_target,%) :
148 $(call gb_Output_announce,$*,$(false),XRM,1)
149 rm -f $(call gb_DescriptionTranslateTarget_get_target,$*)
151 # gb_DescriptionTranslateTarget_DescriptionTranslateTarget target source langs
152 define gb_DescriptionTranslateTarget_DescriptionTranslateTarget
153 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : DESCRIPTION_XML := $(SRCDIR)/$(2)
154 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : POFILES :=
156 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : $(SRCDIR)/$(2)
157 $(call gb_DescriptionTranslateTarget_get_target,$(1)) :| $(dir $(call gb_DescriptionTranslateTarget_get_target,$(1))).dir
159 $(foreach lang,$(3),\
160 $(call gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang,$(1),$(patsubst %/,%,$(dir $(2))),$(lang)) \
163 endef
165 # gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang target pobase lang
166 define gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang
167 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : POFILES += $(if $(filter-out qtz,$(3)),$(gb_POLOCATION)/$(3)/$(2).po)
168 $(if $(filter-out qtz,$(3)),\
169 $(call gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps,$(1),$(gb_POLOCATION)/$(3)/$(2).po))
171 endef
173 # gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps target pofile
174 define gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps
175 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : $(2)
176 $(2) :
178 endef
180 # Dictionary class
182 # Handles creation and delivery of dictionary extensions.
184 # This class provides a filelist called Dictionary/<name> that contains
185 # all installed files of the dictionary.
187 gb_Dictionary_ALL_LANGS := $(filter-out en-US,$(gb_WITH_LANG))
188 gb_Dictionary_INSTDIR := $(LIBO_SHARE_FOLDER)/extensions
190 $(dir $(call gb_Dictionary_get_target,%)).dir :
191 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
193 $(dir $(call gb_Dictionary_get_target,%))%/.dir :
194 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
196 $(call gb_Dictionary_get_target,%) :
197 $(call gb_Output_announce,$*,$(true),DIC,3)
198 touch $@
200 .PHONY : $(call gb_Dictionary_get_clean_target,%)
201 $(call gb_Dictionary_get_clean_target,%) :
202 $(call gb_Output_announce,$*,$(false),DIC,3)
203 rm -f $(call gb_Dictionary_get_target,$*)
205 gb_Dictionary_get_packagename = Dictionary/$(1)
206 gb_Dictionary_get_packagesetname = Dictionary/$(1)
208 # Creates a dictionary extension
210 # gb_Dictionary_Dictionary dictionary srcdir
211 define gb_Dictionary_Dictionary
212 $(call gb_Package_Package_internal,$(call gb_Dictionary_get_packagename,$(1)),$(SRCDIR))
213 $(call gb_Package_Package_internal,$(call gb_Dictionary_get_packagename,$(1)_generated),$(WORKDIR))
214 $(call gb_PackageSet_PackageSet_internal,$(call gb_Dictionary_get_packagesetname,$(1)))
216 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)))
218 ifeq (,$(gb_Dictionary_ALL_LANGS))
219 $(call gb_Dictionary_add_root_file,$(1),$(2)/description.xml)
220 else
221 $(call gb_Dictionary__add_description_translations,$(1),$(2)/description.xml)
222 endif
223 $(call gb_Dictionary_add_root_file,$(1),$(2)/dictionaries.xcu)
224 $(call gb_Dictionary_add_file,$(1),META-INF/manifest.xml,$(2)/META-INF/manifest.xml)
226 $(call gb_Dictionary_get_target,$(1)) : $(call gb_PackageSet_get_target,$(call gb_Dictionary_get_packagesetname,$(1)))
227 $(call gb_Dictionary_get_target,$(1)) :| $(dir $(call gb_Dictionary_get_target,$(1))).dir
228 $(call gb_Dictionary_get_clean_target,$(1)) : $(call gb_PackageSet_get_clean_target,$(call gb_Dictionary_get_packagesetname,$(1)))
230 $$(eval $$(call gb_Module_register_target,$(call gb_Dictionary_get_target,$(1)),$(call gb_Dictionary_get_clean_target,$(1))))
231 $(call gb_Helper_make_userfriendly_targets,$(1),Dictionary)
233 endef
235 # gb_Dictionary__add_description_translation_impl dictionary desctarget descxml
236 define gb_Dictionary__add_description_translation_impl
237 $(call gb_DescriptionTranslateTarget_DescriptionTranslateTarget,$(2),$(3),$(gb_Dictionary_ALL_LANGS))
238 $(call gb_Dictionary_add_generated_file,$(1),description.xml,$(call gb_DescriptionTranslateTarget_get_target,$(2)))
240 $(call gb_Dictionary_get_target,$(1)) : $(call gb_DescriptionTranslateTarget_get_target,$(2))
241 $(call gb_Dictionary_get_clean_target,$(1)) : $(call gb_DescriptionTranslateTarget_get_clean_target,$(2))
243 endef
245 # gb_Dictionary__add_description_translations dictionary descxml
246 define gb_Dictionary__add_description_translations
247 $(call gb_Dictionary__add_description_translation_impl,$(1),$(basename $(2)),$(2))
249 endef
251 # gb_Dictionary__add_file dictionary package-base destfile sourcefile
252 define gb_Dictionary__add_file
253 $(call gb_Package_add_file,$(call gb_Dictionary_get_packagename,$(2)),$(gb_Dictionary_INSTDIR)/$(1)/$(3),$(4))
255 endef
257 # Adds a file from $(SRCDIR) to the dictionary under chosen name
259 # gb_Dictionary_add_file dictionary destfile sourcefile
260 define gb_Dictionary_add_file
261 $(call gb_Dictionary__add_file,$(1),$(1),$(2),$(3))
263 endef
265 # Adds several files from $(SRCDIR) to the dictionary at once
267 # The files are put into the chosen directory.
269 # gb_Dictionary_add_files dictionary destdir file(s)
270 define gb_Dictionary_add_files
271 $(foreach file,$(3),$(call gb_Dictionary_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
273 endef
275 # Adds an arbitrary file to the dictionary under chosen name
277 # gb_Dictionary_add_file dictionary destfile sourcefile
278 define gb_Dictionary_add_generated_file
279 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(2),$(subst $(WORKDIR)/,,$(3)))
280 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
282 endef
284 # Adds several arbitrary files to the dictionary at once
286 # The files are put into the chosen directory.
288 # gb_Dictionary_add_files dictionary destdir file(s)
289 define gb_Dictionary_add_generated_files
290 $(foreach file,$(3),$(call gb_Dictionary_add_generated_file,$(1),$(2)/$(notdir $(file)),$(file)))
292 endef
294 # Adds a localized xcu file, which needs special handling because it may be
295 # in $(WORKDIR) or $(SRCDIR) depending on whether translations are built.
297 # gb_Dictionary_add_localized_xcu_file dictionary destdir file
298 define gb_Dictionary_add_localized_xcu_file
299 ifeq ($(gb_WITH_LANG),)
300 $(call gb_Dictionary__add_file,$(1),$(1),$(2)/$(notdir $(3)),$(strip $(3)))
301 else
302 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(2)/$(notdir $(3)),$(subst $(WORKDIR)/,,$(call gb_XcuFile_for_extension,$(strip $(3)))))
303 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
304 endif
306 endef
308 # Adds a file to the root dir of the dictionary
310 # gb_Dictionary_add_root_file dictionary file
311 define gb_Dictionary_add_root_file
312 $(call gb_Dictionary_add_file,$(1),$(notdir $(2)),$(2))
314 endef
316 # Adds several files to the root dir of the dictionary
318 # gb_Dictionary_add_root_files dictionary file(s)
319 define gb_Dictionary_add_root_files
320 $(foreach file,$(2),$(call gb_Dictionary_add_root_file,$(1),$(file)))
322 endef
324 define gb_Dictionary__add_thesaurus
325 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(notdir $(3)),$(subst $(WORKDIR)/,,$(3)))
326 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
328 endef
330 # Adds a thesaurus to the dictionary
332 # An index for the thesaurus is generated and added to the dictionary as
333 # well.
335 # gb_Dictionary_add_thesaurus dictionary thesaurus
336 define gb_Dictionary_add_thesaurus
337 $(call gb_ThesaurusIndexTarget_ThesaurusIndexTarget,$(2))
338 $(call gb_Dictionary_add_root_file,$(1),$(2))
339 $(call gb_Dictionary__add_thesaurus,$(1),$(2),$(call gb_ThesaurusIndexTarget_get_target,$(2)))
341 endef
343 # Adds several thesauri to the dictionary at once
345 # Indexes for the thesauri are generated and added to the dictionary as
346 # well.
348 # gb_Dictionary_add_thesauri dictionary thesauri
349 define gb_Dictionary_add_thesauri
350 $(foreach thesaurus,$(2),$(call gb_Dictionary_add_thesaurus,$(1),$(thesaurus)))
352 endef
354 # gb_Dictionary__translate_propertyfile_impl dictionary destfile propertyfile propertyname lang
355 define gb_Dictionary__translate_propertyfile_impl
356 $(call gb_PropertiesTranslateTarget_PropertiesTranslateTarget,$(4),$(3),$(5))
357 $(call gb_Dictionary_add_generated_file,$(1),$(2),$(call gb_PropertiesTranslateTarget_get_target,$(4)))
359 endef
361 # gb_Dictionary__translate_propertyfile dictionary destdir propertyfile propertyname lang
362 define gb_Dictionary__translate_propertyfile
363 $(call gb_Dictionary__translate_propertyfile_impl,$(1),$(2)$(notdir $(4)).properties,$(3),$(4),$(5))
365 endef
367 # gb_Dictionary__add_propertyfile_translations dictionary destfile propertyfile
368 define gb_Dictionary__add_propertyfile_translations
369 $(foreach lang,$(gb_Dictionary_ALL_LANGS),$(call gb_Dictionary__translate_propertyfile,$(1),$(dir $(2)),$(3),$(subst en_US,$(subst -,_,$(lang)),$(basename $(3))),$(lang)))
371 endef
373 # Adds a .property file to the dictionary under chosen name
375 # The file is localized automatically.
377 # gb_Dictionary_add_propertyfile dictionary destfile propertyfile
378 define gb_Dictionary_add_propertyfile
379 $(call gb_Dictionary__add_file,$(1),$(1),$(2),$(3))
380 $(call gb_Dictionary__add_propertyfile_translations,$(1),$(2),$(3))
382 endef
384 # Adds several .property files to the dictionary at once
386 # The files are put into chosen directory. They are localized automatically.
388 # gb_Dictionary_add_propertyfiles dictionary destdir propertyfile(s)
389 define gb_Dictionary_add_propertyfiles
390 $(foreach propertyfile,$(3),$(call gb_Dictionary_add_propertyfile,$(1),$(2)/$(notdir $(propertyfile)),$(propertyfile)))
392 endef
394 # vim: set noet sw=4 ts=4: