Avoid potential negative array index access to cached text.
[LibreOffice.git] / solenv / gbuild / CustomTarget.mk
blob1237640fb13e7e3ed4b71ba5c43247962d9a6956
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 # the .dir is for make 3.81, which ignores trailing /
21 $(call gb_CustomTarget_get_workdir,%)/.dir :
22 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
24 $(call gb_CustomTarget_get_target,%) :
25 $(call gb_Output_announce,$*,$(true),CUS,3)
26 $(call gb_Trace_MakeMark,$*,CUS)
27 touch $@
29 .PHONY: $(call gb_CustomTarget_get_clean_target,%)
30 $(call gb_CustomTarget_get_clean_target,%) :
31 $(call gb_Output_announce,$*,$(false),CUS,3)
32 $(call gb_Helper_abbreviate_dirs,\
33 rm -rf $(call gb_CustomTarget_get_workdir,$*) && \
34 rm -f $(call gb_CustomTarget_get_target,$*))
36 define gb_CustomTarget_CustomTarget
37 $(eval $(call gb_Module_register_target,$(call gb_CustomTarget_get_target,$(1)),$(call gb_CustomTarget_get_clean_target,$(1))))
38 $(call gb_Helper_make_userfriendly_targets,$(1),CustomTarget)
39 $(call gb_CustomTarget_get_target,$(1)) :| $(dir $(call gb_CustomTarget_get_target,$(1))).dir
41 endef
43 define gb_CustomTarget_register_target
44 $(call gb_CustomTarget_get_target,$(1)) : $(call gb_CustomTarget_get_workdir,$(1))/$(2)
45 $(call gb_CustomTarget_get_workdir,$(1))/$(2) :| $(dir $(call gb_CustomTarget_get_workdir,$(1))/$(2)).dir
47 endef
49 define gb_CustomTarget_register_targets
50 $(foreach target,$(2),$(call gb_CustomTarget_register_target,$(1),$(target)))
52 endef
54 ifneq ($(WITH_LANG),)
56 # $(call gb_CustomTarget_ulfex__command,ulftarget,ulfsource,pofiles)
57 define gb_CustomTarget_ulfex__command
58 $(call gb_Output_announce,$(1),$(true),ULF,1)
59 $(call gb_Trace_StartRange,$(1),ULF)
60 MERGEINPUT=$(call gb_var2file,$(shell $(gb_MKTEMP)),$(3)) && \
61 $(call gb_Helper_abbreviate_dirs,\
62 $(call gb_Executable_get_command,ulfex) -i $(2) -o $(1) -m $${MERGEINPUT} -l all) && \
63 rm -rf $${MERGEINPUT}
64 $(call gb_Trace_EndRange,$(1),ULF)
65 endef
67 else
69 define gb_CustomTarget_ulfex__command
70 cp $(2) $(1)
71 endef
73 endif
75 # $(call gb_CustomTarget_ulfex_rule,ulftargetpattern,ulfsource,pofiles)
76 define gb_CustomTarget_ulfex_rule
77 $(1) : $(2) $(if $(WITH_LANG),$(call gb_Executable_get_runtime_dependencies,ulfex)) | $(dir $(1)).dir
78 $$(call gb_CustomTarget_ulfex__command,$$@,$(subst %,$$*,$(strip $(2))),$(strip $(3)))
80 endef
82 #$(call gb_CustomTarget_token_hash,oox/generated,tokenhash.inc,tokenhash.gperf)
83 define gb_CustomTarget_token_hash
84 $(call gb_CustomTarget_get_target,$(1)) : $(call gb_CustomTarget_get_workdir,$(1))/$(2)
85 $(call gb_CustomTarget_get_workdir,$(1))/$(2) : $(call gb_CustomTarget_get_workdir,$(1))/misc/$(3)
86 $$(call gb_Output_announce,$$(subst $(WORKDIR)/,,$$@),build,GPF,1)
87 $(GPERF) --compare-strncmp --switch=2 --readonly-tables $$< \
88 | sed -e 's/char\*)0/(char\*)0, 0/g' | grep -v '^#line' > $$@
90 endef
92 #$(call gb_CustomTarget_generate_tokens,oox/generated,oox,oox/source/token,
93 #namespaces,namespace,namespaces.txt,namespaces-strict,namespaces.pl)
94 define gb_CustomTarget_generate_tokens
95 $(call gb_CustomTarget_get_workdir,$(1))/misc/$(5)ids.inc \
96 $(call gb_CustomTarget_get_workdir,$(1))/$(5)names.inc \
97 $(if $(6),$(call gb_CustomTarget_get_workdir,$(1))/misc/$(6)) \
98 $(if $(7),$(call gb_CustomTarget_get_workdir,$(1))/$(7)names.inc) : \
99 $(call gb_CustomTarget_get_workdir,$(1))/$(2)/token/$(4).hxx
100 touch $$@
102 $(call gb_CustomTarget_get_workdir,$(1))/$(2)/token/$(4).hxx : \
103 $(call gb_ExternalExecutable_get_dependencies,python) \
104 $(if $(7),$(SRCDIR)/$(3)/$(7).txt) \
105 $(if $(8),$(SRCDIR)/$(3)/$(8),$(SRCDIR)/solenv/bin/generate-tokens.py) \
106 $(SRCDIR)/$(3)/$(4).txt \
107 $(SRCDIR)/$(3)/$(4).hxx.head \
108 $(SRCDIR)/$(3)/$(4).hxx.tail
109 $$(call gb_Output_announce,$$(subst $(WORKDIR)/,,$$@),build,PRL,1)
110 $$(call gb_Trace_StartRange,$$(subst $(WORKDIR)/,,$$@),PRL)
111 mkdir -p $(call gb_CustomTarget_get_workdir,$(1))/misc \
112 $(call gb_CustomTarget_get_workdir,$(1)) \
113 $(call gb_CustomTarget_get_workdir,$(1))/$(2)/token
114 $(call gb_ExternalExecutable_get_command,python) $(if $(8),$(SRCDIR)/$(3)/$(8),$(SRCDIR)/solenv/bin/generate-tokens.py) \
115 $(SRCDIR)/$(3)/$(4).txt \
116 $(call gb_CustomTarget_get_workdir,$(1))/misc/$(5)ids.inc \
117 $(call gb_CustomTarget_get_workdir,$(1))/$(5)names.inc \
118 $(if $(6), $(call gb_CustomTarget_get_workdir,$(1))/misc/$(6)) \
119 $(if $(7), $(SRCDIR)/$(3)/$(7).txt \
120 $(call gb_CustomTarget_get_workdir,$(1))/$(7)names.inc) \
121 && cat $(SRCDIR)/$(3)/$(4).hxx.head \
122 $(call gb_CustomTarget_get_workdir,$(1))/misc/$(5)ids.inc \
123 $(SRCDIR)/$(3)/$(4).hxx.tail \
124 > $(call gb_CustomTarget_get_workdir,$(1))/$(2)/token/$(4).hxx \
125 && touch $$@
126 $$(call gb_Trace_EndRange,$$(subst $(WORKDIR)/,,$$@),PRL)
128 $(call gb_CustomTarget_get_target,$(1)) : \
129 $(call gb_CustomTarget_get_workdir,$(1))/$(5)names.inc \
130 $(if $(7),$(call gb_CustomTarget_get_workdir,$(1))/$(7)names.inc) \
131 $(call gb_CustomTarget_get_workdir,$(1))/$(2)/token/$(4).hxx \
132 $(if $(6),$(call gb_CustomTarget_get_workdir,$(1))/misc/$(6)) \
134 endef
136 # vim: set noet sw=4: