Avoid potential negative array index access to cached text.
[LibreOffice.git] / solenv / gbuild / Dictionary.mk
blobe4fda64f64b427fbdcca80c96b3ab49f428095ef
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_Helper_abbreviate_dirs,\
19 $(gb_ThesaurusIndexTarget_INDEX_COMMAND) -o $(1) < $(THESAURUS_FILE) \
21 endef
22 #$(gb_ThesaurusIndexTarget_CHECK_COMMAND) $(THESAURUS_FILE) && \
24 $(dir $(call gb_ThesaurusIndexTarget_get_target,%)).dir :
25 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
27 $(dir $(call gb_ThesaurusIndexTarget_get_target,%))%/.dir :
28 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
30 $(call gb_ThesaurusIndexTarget_get_target,%) : $(gb_ThesaurusIndexTarget_INDEX_DEPS) | $(gb_ThesaurusIndexTarget_CHECK_TARGET)
31 $(call gb_Output_announce,$*,$(true),THI,1)
32 $(call gb_Trace_StartRange,$*,THI)
33 $(call gb_ThesaurusIndexTarget__command,$@,$*)
34 $(call gb_Trace_EndRange,$*,THI)
36 .PHONY : $(call gb_ThesaurusIndexTarget_get_clean_target,%)
37 $(call gb_ThesaurusIndexTarget_get_clean_target,%) :
38 $(call gb_Output_announce,$*,$(false),THI,1)
39 $(call gb_Helper_abbreviate_dirs,\
40 rm -f $(call gb_ThesaurusIndexTarget_get_target,$*) \
43 # Creates an index for a given thesaurus
45 # The thesaurus' file path is relative to $(SRCDIR).
47 # gb_ThesaurusIndexTarget_ThesaurusIndexTarget thesaurus
48 define gb_ThesaurusIndexTarget_ThesaurusIndexTarget
49 $(call gb_ThesaurusIndexTarget_get_target,$(1)) : THESAURUS_FILE := $(SRCDIR)/$(1)
50 $(call gb_ThesaurusIndexTarget_get_target,$(1)) : $(SRCDIR)/$(1)
51 $(call gb_ThesaurusIndexTarget_get_target,$(1)) :| $(dir $(call gb_ThesaurusIndexTarget_get_target,$(1))).dir
53 endef
55 # PropertiesTranslateTarget class
57 # Handles translation of .properties files in dictionaries.
59 gb_PropertiesTranslateTarget_COMMAND := $(call gb_Executable_get_command,propex)
60 gb_PropertiesTranslateTarget_DEPS := $(call gb_Executable_get_runtime_dependencies,propex)
62 define gb_PropertiesTranslateTarget__command
63 $(call gb_Helper_abbreviate_dirs, \
64 $(if $(filter-out qtz,$(LANGUAGE)), \
65 MERGEINPUT=$(call gb_var2file,$(shell $(gb_MKTEMP)),$(POFILE)) && \
66 $(gb_PropertiesTranslateTarget_COMMAND) \
67 -i $(PROPERTIES_FILE) \
68 -l $(LANGUAGE) \
69 -m $${MERGEINPUT} \
70 -o $(1) && \
71 rm -f $${MERGEINPUT} \
72 , \
73 $(gb_PropertiesTranslateTarget_COMMAND) \
74 -i $(PROPERTIES_FILE) \
75 -l $(LANGUAGE) \
76 -m \
77 -o $(1) \
78 ) \
80 endef
82 $(dir $(call gb_PropertiesTranslateTarget_get_target,%)).dir :
83 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
85 $(dir $(call gb_PropertiesTranslateTarget_get_target,%))%/.dir :
86 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
88 $(call gb_PropertiesTranslateTarget_get_target,%) : $(gb_PropertiesTranslateTarget_DEPS)
89 $(call gb_Output_announce,$*,$(true),PRP,1)
90 $(call gb_Trace_StartRange,$*,PRP)
91 $(call gb_PropertiesTranslateTarget__command,$@,$*)
92 $(call gb_Trace_EndRange,$*,PRP)
94 .PHONY : $(call gb_PropertiesTranslateTarget_get_clean_target,%)
95 $(call gb_PropertiesTranslateTarget_get_clean_target,%) :
96 $(call gb_Output_announce,$*,$(false),PRP,1)
97 rm -f $(call gb_PropertiesTranslateTarget_get_target,$*)
99 # gb_PropertiesTranslateTarget_PropertiesTranslateTarget target source lang
100 define gb_PropertiesTranslateTarget_PropertiesTranslateTarget
101 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : LANGUAGE := $(3)
102 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : POFILE := $(gb_POLOCATION)/$(3)/$(patsubst %/,%,$(dir $(2))).po
103 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : PROPERTIES_FILE := $(SRCDIR)/$(2)
105 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : $(SRCDIR)/$(2)
106 $(call gb_PropertiesTranslateTarget_get_target,$(1)) :| $(dir $(call gb_PropertiesTranslateTarget_get_target,$(1))).dir
108 $(if $(filter-out qtz,$(3)),\
109 $(call gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang,$(1),$(gb_POLOCATION)/$(3)/$(patsubst %/,%,$(dir $(2))).po) \
112 endef
114 # gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang target pofile
115 define gb_PropertiesTranslateTarget__PropertiesTranslateTarget_onelang
116 $(call gb_PropertiesTranslateTarget_get_target,$(1)) : $(2)
117 $(2) :
119 endef
121 # DescriptionTranslateTarget class
123 # Handles translation of description.xml files in dictionaries.
125 gb_DescriptionTranslateTarget_COMMAND := $(call gb_Executable_get_command,xrmex)
126 gb_DescriptionTranslateTarget_DEPS := $(call gb_Executable_get_runtime_dependencies,xrmex)
128 define gb_DescriptionTranslateTarget__command
129 $(call gb_Helper_abbreviate_dirs,\
130 MERGEINPUT=$(call gb_var2file,$(shell $(gb_MKTEMP)),$(POFILES)) && \
131 $(gb_DescriptionTranslateTarget_COMMAND) \
132 -i $(DESCRIPTION_XML) \
133 -l all \
134 -m $${MERGEINPUT} \
135 -o $(1) && \
136 rm -f $${MERGEINPUT} \
138 endef
140 $(dir $(call gb_DescriptionTranslateTarget_get_target,%)).dir :
141 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
143 $(dir $(call gb_DescriptionTranslateTarget_get_target,%))%/.dir :
144 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
146 $(call gb_DescriptionTranslateTarget_get_target,%) : $(gb_DescriptionTranslateTarget_DEPS)
147 $(call gb_Output_announce,$*,$(true),XRM,1)
148 $(call gb_Trace_StartRange,$*,XRM)
149 $(call gb_DescriptionTranslateTarget__command,$@,$*)
150 $(call gb_Trace_EndRange,$*,XRM)
152 .PHONY : $(call gb_DescriptionTranslateTarget_get_clean_target,%)
153 $(call gb_DescriptionTranslateTarget_get_clean_target,%) :
154 $(call gb_Output_announce,$*,$(false),XRM,1)
155 rm -f $(call gb_DescriptionTranslateTarget_get_target,$*)
157 # gb_DescriptionTranslateTarget_DescriptionTranslateTarget target source langs
158 define gb_DescriptionTranslateTarget_DescriptionTranslateTarget
159 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : DESCRIPTION_XML := $(SRCDIR)/$(2)
160 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : POFILES :=
162 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : $(SRCDIR)/$(2)
163 $(call gb_DescriptionTranslateTarget_get_target,$(1)) :| $(dir $(call gb_DescriptionTranslateTarget_get_target,$(1))).dir
165 $(foreach lang,$(3),\
166 $(call gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang,$(1),$(patsubst %/,%,$(dir $(2))),$(lang)) \
169 endef
171 # gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang target pobase lang
172 define gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang
173 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : POFILES += $(if $(filter-out qtz,$(3)),$(gb_POLOCATION)/$(3)/$(2).po)
174 $(if $(filter-out qtz,$(3)),\
175 $(call gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps,$(1),$(gb_POLOCATION)/$(3)/$(2).po))
177 endef
179 # gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps target pofile
180 define gb_DescriptionTranslateTarget__DescriptionTranslateTarget_onelang_podeps
181 $(call gb_DescriptionTranslateTarget_get_target,$(1)) : $(2)
182 $(2) :
184 endef
186 # Dictionary class
188 # Handles creation and delivery of dictionary extensions.
190 # This class provides a filelist called Dictionary/<name> that contains
191 # all installed files of the dictionary.
193 gb_Dictionary_ALL_LANGS := $(filter-out en-US,$(gb_WITH_LANG))
194 gb_Dictionary_INSTDIR := $(LIBO_SHARE_FOLDER)/extensions
196 $(dir $(call gb_Dictionary_get_target,%)).dir :
197 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
199 $(dir $(call gb_Dictionary_get_target,%))%/.dir :
200 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
202 $(call gb_Dictionary_get_target,%) :
203 $(call gb_Output_announce,$*,$(true),DIC,3)
204 $(call gb_Trace_MakeMark,$*,DIC)
205 touch $@
207 .PHONY : $(call gb_Dictionary_get_clean_target,%)
208 $(call gb_Dictionary_get_clean_target,%) :
209 $(call gb_Output_announce,$*,$(false),DIC,3)
210 rm -f $(call gb_Dictionary_get_target,$*)
212 gb_Dictionary_get_packagename = Dictionary/$(1)
213 gb_Dictionary_get_packagesetname = Dictionary/$(1)
215 # Creates a dictionary extension
217 # gb_Dictionary_Dictionary dictionary srcdir
218 define gb_Dictionary_Dictionary
219 $(call gb_Package_Package_internal,$(call gb_Dictionary_get_packagename,$(1)),$(SRCDIR))
220 $(call gb_Package_Package_internal,$(call gb_Dictionary_get_packagename,$(1)_generated),$(WORKDIR))
221 $(call gb_PackageSet_PackageSet_internal,$(call gb_Dictionary_get_packagesetname,$(1)))
223 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)))
225 ifeq (,$(gb_Dictionary_ALL_LANGS))
226 $(call gb_Dictionary_add_root_file,$(1),$(2)/description.xml)
227 else
228 $(call gb_Dictionary__add_description_translations,$(1),$(2)/description.xml)
229 endif
230 $(call gb_Dictionary_add_root_file,$(1),$(2)/dictionaries.xcu)
231 $(call gb_Dictionary_add_file,$(1),META-INF/manifest.xml,$(2)/META-INF/manifest.xml)
233 $(call gb_Dictionary_get_target,$(1)) : $(call gb_PackageSet_get_target,$(call gb_Dictionary_get_packagesetname,$(1)))
234 $(call gb_Dictionary_get_target,$(1)) :| $(dir $(call gb_Dictionary_get_target,$(1))).dir
235 $(call gb_Dictionary_get_clean_target,$(1)) : $(call gb_PackageSet_get_clean_target,$(call gb_Dictionary_get_packagesetname,$(1)))
237 $$(eval $$(call gb_Module_register_target,$(call gb_Dictionary_get_target,$(1)),$(call gb_Dictionary_get_clean_target,$(1))))
238 $(call gb_Helper_make_userfriendly_targets,$(1),Dictionary)
240 endef
242 # gb_Dictionary__add_description_translation_impl dictionary desctarget descxml
243 define gb_Dictionary__add_description_translation_impl
244 $(call gb_DescriptionTranslateTarget_DescriptionTranslateTarget,$(2),$(3),$(gb_Dictionary_ALL_LANGS))
245 $(call gb_Dictionary_add_generated_file,$(1),description.xml,$(call gb_DescriptionTranslateTarget_get_target,$(2)))
247 $(call gb_Dictionary_get_target,$(1)) : $(call gb_DescriptionTranslateTarget_get_target,$(2))
248 $(call gb_Dictionary_get_clean_target,$(1)) : $(call gb_DescriptionTranslateTarget_get_clean_target,$(2))
250 endef
252 # gb_Dictionary__add_description_translations dictionary descxml
253 define gb_Dictionary__add_description_translations
254 $(call gb_Dictionary__add_description_translation_impl,$(1),$(basename $(2)),$(2))
256 endef
258 # gb_Dictionary__add_file dictionary package-base destfile sourcefile
259 define gb_Dictionary__add_file
260 $(call gb_Package_add_file,$(call gb_Dictionary_get_packagename,$(2)),$(gb_Dictionary_INSTDIR)/$(1)/$(3),$(4))
262 endef
264 # Adds a file from $(SRCDIR) to the dictionary under chosen name
266 # gb_Dictionary_add_file dictionary destfile sourcefile
267 define gb_Dictionary_add_file
268 $(call gb_Dictionary__add_file,$(1),$(1),$(2),$(3))
270 endef
272 # Adds several files from $(SRCDIR) to the dictionary at once
274 # The files are put into the chosen directory.
276 # gb_Dictionary_add_files dictionary destdir file(s)
277 define gb_Dictionary_add_files
278 $(foreach file,$(3),$(call gb_Dictionary_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
280 endef
282 # Adds an arbitrary file to the dictionary under chosen name
284 # gb_Dictionary_add_file dictionary destfile sourcefile
285 define gb_Dictionary_add_generated_file
286 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(2),$(subst $(WORKDIR)/,,$(3)))
287 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
289 endef
291 # Adds several arbitrary files to the dictionary at once
293 # The files are put into the chosen directory.
295 # gb_Dictionary_add_files dictionary destdir file(s)
296 define gb_Dictionary_add_generated_files
297 $(foreach file,$(3),$(call gb_Dictionary_add_generated_file,$(1),$(2)/$(notdir $(file)),$(file)))
299 endef
301 # Adds a localized xcu file, which needs special handling because it may be
302 # in $(WORKDIR) or $(SRCDIR) depending on whether translations are built.
304 # gb_Dictionary_add_localized_xcu_file dictionary destdir file
305 define gb_Dictionary_add_localized_xcu_file
306 ifeq ($(gb_WITH_LANG),)
307 $(call gb_Dictionary__add_file,$(1),$(1),$(2)/$(notdir $(3)),$(strip $(3)))
308 else
309 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(2)/$(notdir $(3)),$(subst $(WORKDIR)/,,$(call gb_XcuFile_for_extension,$(strip $(3)))))
310 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
311 endif
313 endef
315 # Adds a file to the root dir of the dictionary
317 # gb_Dictionary_add_root_file dictionary file
318 define gb_Dictionary_add_root_file
319 $(call gb_Dictionary_add_file,$(1),$(notdir $(2)),$(2))
321 endef
323 # Adds several files to the root dir of the dictionary
325 # gb_Dictionary_add_root_files dictionary file(s)
326 define gb_Dictionary_add_root_files
327 $(foreach file,$(2),$(call gb_Dictionary_add_root_file,$(1),$(file)))
329 endef
331 define gb_Dictionary__add_thesaurus
332 $(call gb_Dictionary__add_file,$(1),$(1)_generated,$(notdir $(3)),$(subst $(WORKDIR)/,,$(3)))
333 $(call gb_PackageSet_add_package,$(call gb_Dictionary_get_packagesetname,$(1)),$(call gb_Dictionary_get_packagename,$(1)_generated))
335 endef
337 # Adds a thesaurus to the dictionary
339 # An index for the thesaurus is generated and added to the dictionary as
340 # well.
342 # gb_Dictionary_add_thesaurus dictionary thesaurus
343 define gb_Dictionary_add_thesaurus
344 $(call gb_ThesaurusIndexTarget_ThesaurusIndexTarget,$(2))
345 $(call gb_Dictionary_add_root_file,$(1),$(2))
346 $(call gb_Dictionary__add_thesaurus,$(1),$(2),$(call gb_ThesaurusIndexTarget_get_target,$(2)))
348 endef
350 # Adds several thesauri to the dictionary at once
352 # Indexes for the thesauri are generated and added to the dictionary as
353 # well.
355 # gb_Dictionary_add_thesauri dictionary thesauri
356 define gb_Dictionary_add_thesauri
357 $(foreach thesaurus,$(2),$(call gb_Dictionary_add_thesaurus,$(1),$(thesaurus)))
359 endef
361 # gb_Dictionary__translate_propertyfile_impl dictionary destfile propertyfile propertyname lang
362 define gb_Dictionary__translate_propertyfile_impl
363 $(call gb_PropertiesTranslateTarget_PropertiesTranslateTarget,$(4),$(3),$(5))
364 $(call gb_Dictionary_add_generated_file,$(1),$(2),$(call gb_PropertiesTranslateTarget_get_target,$(4)))
366 endef
368 # gb_Dictionary__translate_propertyfile dictionary destdir propertyfile propertyname lang
369 define gb_Dictionary__translate_propertyfile
370 $(call gb_Dictionary__translate_propertyfile_impl,$(1),$(2)$(notdir $(4)).properties,$(3),$(4),$(5))
372 endef
374 # gb_Dictionary__add_propertyfile_translations dictionary destfile propertyfile
375 define gb_Dictionary__add_propertyfile_translations
376 $(foreach lang,$(gb_Dictionary_ALL_LANGS),$(call gb_Dictionary__translate_propertyfile,$(1),$(dir $(2)),$(3),$(subst en_US,$(subst -,_,$(lang)),$(basename $(3))),$(lang)))
378 endef
380 # Adds a .property file to the dictionary under chosen name
382 # The file is localized automatically.
384 # gb_Dictionary_add_propertyfile dictionary destfile propertyfile
385 define gb_Dictionary_add_propertyfile
386 $(call gb_Dictionary__add_file,$(1),$(1),$(2),$(3))
387 $(call gb_Dictionary__add_propertyfile_translations,$(1),$(2),$(3))
389 endef
391 # Adds several .property files to the dictionary at once
393 # The files are put into chosen directory. They are localized automatically.
395 # gb_Dictionary_add_propertyfiles dictionary destdir propertyfile(s)
396 define gb_Dictionary_add_propertyfiles
397 $(foreach propertyfile,$(3),$(call gb_Dictionary_add_propertyfile,$(1),$(2)/$(notdir $(propertyfile)),$(propertyfile)))
399 endef
401 # vim: set noet sw=4 ts=4: