Avoid potential negative array index access to cached text.
[LibreOffice.git] / solenv / gbuild / Package.mk
blob6f054a54987563eda92511f7d76bb3c0a9025379
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 .
21 # PackagePart class
23 # a pattern rule with multiple targets is actually executed only once for each
24 # match, so define only pattern rules with one target here
25 # the .dir is for make 3.81, which ignores trailing /
26 define gb_PackagePart__rule
27 $(1)/.dir :
28 $$(if $$(wildcard $$(dir $$@)),,mkdir -p $$(dir $$@))
29 $(1)/%/.dir :
30 $$(if $$(wildcard $$(dir $$@)),,mkdir -p $$(dir $$@))
31 $(1)/% :
32 $$(call gb_Deliver_deliver,$$<,$$@)
33 endef
35 $(foreach destination,$(call gb_PackagePart_get_destinations),$(eval \
36 $(call gb_PackagePart__rule,$(destination))))
38 # Deliver one file to the output dir.
40 # gb_PackagePart_PackagePart destfile source prep-target outdir
41 define gb_PackagePart_PackagePart
42 $(4)/$(1) : $(2) | $(dir $(4)/$(1)).dir
43 $(2) :| $(3)
45 $(if $(gb_Package_PRESTAGEDIR),\
46 $(if $(wildcard $(gb_Package_PRESTAGEDIR)/$(1)),\
47 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(gb_Package_PRESTAGEDIR)/$(1),$(3)),\
48 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(2),$(3)) \
49 ),\
50 $(call gb_Deliver_add_deliverable,$(4)/$(1),$(2),$(3)) \
53 endef
56 # Package class
58 $(dir $(call gb_Package_get_target,%)).dir :
59 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
61 $(dir $(call gb_Package_get_target,%))%/.dir :
62 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
64 .PHONY : $(call gb_Package_get_clean_target,%)
65 $(call gb_Package_get_clean_target,%) :
66 $(call gb_Output_announce,$*,$(false),PKG,2)
67 RESPONSEFILE=$(call gb_var2file,$(shell $(gb_MKTEMP)),$(FILES)) \
68 && cat $${RESPONSEFILE} | $(if $(filter WNT,$(OS)),env -i PATH="$$PATH") xargs $(if $(filter MACOSX,$(OS_FOR_BUILD)),-n 1000) rm -fr \
69 && rm -f $${RESPONSEFILE}
71 $(call gb_Package_get_preparation_target,%) :
72 mkdir -p $(dir $@) && touch $@
74 # NOTE: It is possible that a file has been added to the package more
75 # than once, so we must drop the duplicates, or Windows installer will
76 # be unhappy.
77 # TODO: this is only for convenience for impl. of gbuild classes. There
78 # should be check that it does not happen in "normal" use, i.e., in
79 # Package_foo makefiles.
80 $(call gb_Package_get_target,%) :
81 $(call gb_Output_announce,$*,$(true),PKG,2)
82 $(call gb_Trace_StartRange,$*,PKG)
83 $(if $(PACKAGE_DEFINED),,$(call gb_Output_error,$(RDEPENDS) depend(s) on package $* which does not exist.))
84 $(file >$@,$(sort $(FILES)))
85 $(call gb_Trace_EndRange,$*,PKG)
87 # for other targets that want to create Packages, does not register at Module
88 define gb_Package_Package_internal
89 gb_Package_SOURCEDIR_$(1) := $(2)
90 gb_Package_OUTDIR_$(1) := $(INSTROOT)
91 $(call gb_Package_get_target,$(1)) : PACKAGE_DEFINED := $(true)
92 $(call gb_Package_get_target,$(1)) : FILES :=
93 $(call gb_Package_get_clean_target,$(1)) : FILES := $(call gb_Package_get_target,$(1)) $(call gb_Package_get_preparation_target,$(1))
94 $(call gb_Package_get_target,$(1)) : $(call gb_Package_get_preparation_target,$(1))
95 $(call gb_Package_get_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
96 $(call gb_Package_get_target,$(1)) :| $(dir $(call gb_Package_get_target,$(1))).dir
98 endef
100 define gb_Package_Package
101 $$(if $$(gb_Package_SOURCEDIR_$(1)),$$(call gb_Output_error,gb_Package__check: Package $(1) has already been defined))
102 $(if $(filter postprocess% instsetoo_native%,$(1)),,\
103 $(call gb_Postprocess_register_target,AllPackages,Package,$(1)))
104 ifeq (,$$(filter $(1),$$(gb_Package_REGISTERED)))
105 $$(eval $$(call gb_Output_info,Currently known packages are: $(sort $(gb_Package_REGISTERED)),ALL))
106 $$(eval $$(call gb_Output_error,Package $(1) must be registered in Repository.mk or RepositoryExternal.mk))
107 endif
108 $(call gb_Package_Package_internal,$(1),$(2))
109 $$(eval $$(call gb_Module_register_target,$(call gb_Package_get_target,$(1)),$(call gb_Package_get_clean_target,$(1))))
110 $(call gb_Helper_make_userfriendly_targets,$(1),Package)
112 endef
114 # Ensure that the package is defined.
116 # gb_Package__check package
117 define gb_Package__check
118 $$(if $$(gb_Package_SOURCEDIR_$(1)),,$$(call gb_Output_error,gb_Package__check: Package $(1) has not been defined))
120 endef
122 # Set output dir for the package files.
124 # Default is $(INSTROOT).
126 # gb_Package_set_outdir package outdir
127 define gb_Package_set_outdir
128 $(call gb_Package__check,$(1))
129 gb_Package_OUTDIR_$(1) := $(2)
131 endef
133 # Add empty directory (if it's non-empty, don't use this, use
134 # gb_Package_add_file for the files in it instead!)
135 define gb_Package_add_empty_directory
136 $(call gb_Package__check,$(1))
137 $(if $(strip $(2)),,$(call gb_Output_error,gb_Package_add_directory requires 2 arguments))
138 $(call gb_Package_get_target,$(1)) :| $$(gb_Package_OUTDIR_$(1))/$(2)/.dir
139 $(call gb_Package_get_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
140 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
142 endef
144 # Example:
145 # $(eval $(call gb_Package_add_empty_directories,foo_inc,inc/foo))
146 # # -> inc/foo
147 define gb_Package_add_empty_directories
148 $(call gb_Package__check,$(1))
149 $(foreach file,$(2),$(call gb_Package_add_empty_directory,$(1),$(file)))
151 endef
153 define gb_Package_add_symbolic_link
154 $(call gb_Package__check,$(1))
155 $(if $(strip $(3)),,$(call gb_Output_error,gb_Package_add_symbolic_link requires 3 arguments))
156 $(call gb_Package_get_target,$(1)) : $$(gb_Package_OUTDIR_$(1))/$(2)
157 $$(gb_Package_OUTDIR_$(1))/$(2) :| $$(dir $$(gb_Package_OUTDIR_$(1))/$(2)).dir
158 rm -f $$@ && ln -s $(3) $$@
160 $(call gb_Package_get_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
161 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
163 endef
165 define gb_Package_add_file
166 $(call gb_Package__check,$(1))
167 $(if $(strip $(3)),,$(call gb_Output_error,gb_Package_add_file requires 3 arguments))
168 $(call gb_Package_get_target,$(1)) : $$(gb_Package_OUTDIR_$(1))/$(2)
169 $(call gb_Package_get_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
170 $(call gb_Package_get_clean_target,$(1)) : FILES += $$(gb_Package_OUTDIR_$(1))/$(2)
171 $(call gb_PackagePart_PackagePart,$(2),$$(gb_Package_SOURCEDIR_$(1))/$(3),$(call gb_Package_get_preparation_target,$(1)),$$(gb_Package_OUTDIR_$(1)))
173 endef
175 # Adds several files at once.
177 # Files are copied directly into the specified directory.
179 # Example:
180 # $(eval $(call gb_Package_Package,foo_inc,$(SRCDIR)/foo/inc))
181 # $(eval $(call gb_Package_add_files,foo_inc,inc/foo,foo/bar/foo.hxx))
182 # # -> inc/foo/foo.hxx
183 define gb_Package_add_files
184 $(call gb_Package__check,$(1))
185 $(if $(strip $(3)),,$(if $(filter 1,$(words $(2))),,$(call gb_Output_error,gb_Package_add_files: it looks like either pkg name or dest. dir is missing)))
186 $(foreach file,$(3),$(call gb_Package_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
188 endef
190 # Adds several files at once.
192 # Files are copied including subdirectories.
194 # Example:
195 # $(eval $(call gb_Package_Package,foo_inc,$(SRCDIR)/foo/inc))
196 # $(eval $(call gb_Package_add_files,foo_inc,inc,foo/bar/foo.hxx))
197 # # -> inc/foo/bar/foo.hxx
198 define gb_Package_add_files_with_dir
199 $(call gb_Package__check,$(1))
200 $(if $(strip $(3)),,$(if $(filter 1,$(words $(2))),,$(call gb_Output_error,gb_Package_add_files: it looks like either pkg name or dest. dir is missing)))
201 $(foreach file,$(3),$(call gb_Package_add_file,$(1),$(2)/$(file),$(file)))
203 endef
205 # Package files from custom target
206 define gb_Package_use_custom_target
207 $(call gb_Package__check,$(1))
208 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_CustomTarget_get_target,$(2))
210 endef
212 # Package files from unpacked tarball of an external project
213 define gb_Package_use_unpacked
214 $(call gb_Package__check,$(1))
215 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_UnpackedTarball_get_target,$(2))
217 endef
219 # Package files from build of an external project
220 define gb_Package_use_external_project
221 $(call gb_Package__check,$(1))
222 $(call gb_Package_get_preparation_target,$(1)) :| $(call gb_ExternalProject_get_target,$(2))
224 endef
226 # vim: set noet sw=4: