bump product version to 4.1.6.2
[LibreOffice.git] / solenv / gbuild / UnpackedTarball.mk
blob5f5af1fa6fbfe01951024d1b3abc8d317b163a3a
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 # UnpackedTarget class
12 # Handles unpacking of a tarball
14 # platform
15 # gb_UnpackedTarget_TARFILE_LOCATION
17 gb_UnpackedTarget_STRIP_COMPONENTS_TAR_DEFAULT := 1
18 gb_UnpackedTarget_STRIP_COMPONENTS_ZIP_DEFAULT := 0
20 # gb_UnpackedTarget__get_strip_components target strip-components?
21 define gb_UnpackedTarget__get_strip_components
22 $(strip $(if $(2),\
23 $(2),\
24 $(if $(filter zip,$(suffix $(1))),\
25 $(gb_UnpackedTarget_STRIP_COMPONENTS_ZIP_DEFAULT),\
26 $(gb_UnpackedTarget_STRIP_COMPONENTS_TAR_DEFAULT) \
27 ) \
29 endef
31 define gb_UnpackedTarget__command_untar
32 $(GNUTAR) \
33 -x \
34 $(3) \
35 -C $(UNPACKED_DIR) \
36 $(STRIP_COMPONENTS)=$(UNPACKED_STRIP_COMPONENTS) \
37 -f $(UNPACKED_TARBALL)
38 endef
40 define gb_UnpackedTarget__command_unzip
41 unzip \
42 -qq \
43 -d $(UNPACKED_DIR) $(UNPACKED_TARBALL) \
44 $(if $(filter-out 0,$(UNPACKED_STRIP_COMPONENTS)),\
45 && UNZIP_DIR=`ls $(UNPACKED_DIR)` \
46 && mv $(UNPACKED_DIR)/$$UNZIP_DIR/* $(UNPACKED_DIR) \
47 && rmdir $(UNPACKED_DIR)/$$UNZIP_DIR \
49 endef
51 define gb_UnpackedTarget__command
52 $(call gb_Output_announce,$(notdir $(2)),$(true),UPK,1)
53 $(call gb_Helper_abbreviate_dirs,\
54 $(if $(wildcard $(UNPACKED_DIR)),rm -rf $(UNPACKED_DIR) &&) \
55 mkdir -p $(UNPACKED_DIR) && \
56 $(call gb_UnpackedTarget__command_$(1),$(2),$(3),$(4)) && \
57 touch $(2) \
59 endef
61 $(dir $(call gb_UnpackedTarget_get_target,%)).dir :
62 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
64 $(call gb_UnpackedTarget_get_target,%).tar.bz2 :
65 $(call gb_UnpackedTarget__command,untar,$@,$*,-j)
67 $(call gb_UnpackedTarget_get_target,%).tar.gz :
68 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
70 $(call gb_UnpackedTarget_get_target,%).tgz :
71 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
73 $(call gb_UnpackedTarget_get_target,%).zip :
74 $(call gb_UnpackedTarget__command,unzip,$@,$*)
76 $(call gb_UnpackedTarget_get_target,%).oxt :
77 $(call gb_UnpackedTarget__command,unzip,$@,$*)
79 .PHONY : $(call gb_UnpackedTarget_get_clean_target,%)
80 $(call gb_UnpackedTarget_get_clean_target,%) :
81 $(call gb_Output_announce,$*,$(false),UPK,1)
82 $(call gb_Helper_abbreviate_dirs,\
83 rm -f $(call gb_UnpackedTarget_get_target,$*) \
86 # gb_UnpackedTarget_UnpackedTarget target outdir strip-components?
87 define gb_UnpackedTarget_UnpackedTarget
88 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_DIR := $(2)
89 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_TARBALL := $(gb_UnpackedTarget_TARFILE_LOCATION)/$(1)
90 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_STRIP_COMPONENTS := $(call gb_UnpackedTarget__get_strip_components,$(1),$(3))
92 $(call gb_UnpackedTarget_get_target,$(1)) : $(gb_UnpackedTarget_TARFILE_LOCATION)/$(1)
93 $(call gb_UnpackedTarget_get_target,$(1)) :| $(dir $(call gb_UnpackedTarget_get_target,$(1))).dir
95 endef
97 # UnpackedTarball class
99 # Handles unpacking and patching of an external project
101 # The unpacked dir is recreated every time one of the patches, copied
102 # files or the makefile changes.
104 # This is what dmake patches use. Once all external modules are
105 # converted, it is better to be changed to 1.
106 gb_UnpackedTarball_PATCHLEVEL_DEFAULT := 2
108 gb_UnpackedTarball_CONVERTTODOS = \
109 $(gb_AWK) 'sub("$$","\r")' $(1) > $(1).TEMP && mv $(1).TEMP $(1)
110 gb_UnpackedTarball_CONVERTTOUNIX = \
111 tr -d '\r' < $(1) > $(1).TEMP && mv $(1).TEMP $(1)
113 define gb_UnpackedTarball__copy_files_impl
114 $(if $(1),\
115 && cp $(firstword $(1)) $(firstword $(2)) \
116 $(call gb_UnpackedTarball__copy_files_impl,$(wordlist 2,$(words $(1)),$(1)),$(wordlist 2,$(words $(2)),$(2))) \
118 endef
120 # Drop leading &&
121 define gb_UnpackedTarball__copy_files_fix
122 $(wordlist 2,$(words $(1)),$(1))
123 endef
125 define gb_UnpackedTarball__copy_files
126 $(call gb_UnpackedTarball__copy_files_fix,$(call gb_UnpackedTarball__copy_files_impl,$(1),$(2)))
127 endef
129 define gb_UnpackedTarball__command
130 $(call gb_Output_announce,$(2),$(true),PAT,2)
131 $(call gb_Helper_abbreviate_dirs,\
133 cd $(3) && \
134 $(if $(UNPACKED_PRE_ACTION),\
135 $(UNPACKED_PRE_ACTION) && \
137 $(if $(UNPACKED_FILES),\
138 mkdir -p $(sort $(dir $(UNPACKED_DESTFILES))) && \
139 $(call gb_UnpackedTarball__copy_files,$(UNPACKED_FILES),$(UNPACKED_DESTFILES)) && \
141 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTOUNIX,$(file)) && ) \
142 $(if $(UNPACKED_PATCHES),\
143 for p in $(UNPACKED_PATCHES); do \
144 pl=$(UNPACKED_PATCHLEVEL); \
145 s=$${p##*.}; case "$$s" in [0-9]$(CLOSE_PAREN) pl="$$s"; ;; esac ; \
146 $(GNUPATCH) $(UNPACKED_PATCHFLAGS) -f -s "-p$$pl" < "$$p"; \
147 if test "$$?" -ne 0; then echo "Patch FAILED: $$p"; exit 1; fi;\
148 done && \
150 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTODOS,$(file)) && ) \
151 $(if $(UNPACKED_POST_ACTION),\
152 $(UNPACKED_POST_ACTION) && \
154 $(if $(gb_KEEP_PRISTINE), \
155 rm -fr $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
156 cp -r $(call gb_UnpackedTarball_get_dir,$(2)) $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
158 touch $(1) \
159 ) || \
161 touch $(call gb_UnpackedTarball_get_preparation_target,$(2)) && \
162 exit 1 \
165 endef
167 $(dir $(call gb_UnpackedTarball_get_target,%)).dir :
168 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
170 $(call gb_UnpackedTarball_get_preparation_target,%) :
171 touch $@
173 $(call gb_UnpackedTarball_get_target,%) :
174 $(call gb_UnpackedTarball__command,$@,$*,$(call gb_UnpackedTarball_get_dir,$*))
176 $(call gb_UnpackedTarball_get_final_target,%) :
177 touch $@
179 .PHONY : $(call gb_UnpackedTarball_get_clean_target,%)
180 $(call gb_UnpackedTarball_get_clean_target,%) :
181 $(call gb_Output_announce,$*,$(false),PAT,2)
182 $(call gb_Helper_abbreviate_dirs,\
183 rm -rf \
184 $(call gb_UnpackedTarball_get_final_target,$*) \
185 $(call gb_UnpackedTarball_get_target,$*) \
186 $(call gb_UnpackedTarball_get_preparation_target,$*) \
187 $(call gb_UnpackedTarball_get_dir,$*) \
188 $(call gb_UnpackedTarball_get_pristine_dir,$*) \
191 # Initialize unpacked tarball
192 define gb_UnpackedTarball_UnpackedTarball_internal
193 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES :=
194 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES :=
195 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL :=
196 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES :=
197 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(gb_UnpackedTarball_PATCHLEVEL_DEFAULT)
198 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS :=
199 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION :=
200 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION :=
202 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
203 $(call gb_UnpackedTarball_get_preparation_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
204 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
205 $(call gb_UnpackedTarball_get_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
206 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_target,$(1))
208 private gb_UnpackedTarball_PATTERN_RULES_$(1) :=
210 endef
212 # Define a new unpacked tarball
213 define gb_UnpackedTarball_UnpackedTarball
214 $(call gb_UnpackedTarball_UnpackedTarball_internal,$(1))
216 $$(eval $$(call gb_Module_register_target,$(call gb_UnpackedTarball_get_final_target,$(1)),$(call gb_UnpackedTarball_get_clean_target,$(1))))
217 $(call gb_Helper_make_userfriendly_targets,$(1),UnpackedTarball,$(call gb_UnpackedTarball_get_final_target,$(1)))
219 endef
221 # Convert line ending from dos to unix style for selected files
223 # This is done before applying patches, because patches expect unix
224 # style line ending, and the files are converted back after that. The
225 # files are relative to the unpacked path.
227 # gb_UnpackedTarball_fix_end_of_line unpacked file(s)
228 define gb_UnpackedTarball_fix_end_of_line
229 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL += $(addprefix $(call gb_UnpackedTarball_get_dir,$(1))/,$(2))
231 endef
233 # Set tarball name
235 # gb_UnpackedTarball_set_tarball unpacked tarball-name
236 define gb_UnpackedTarball_set_tarball
237 $(call gb_UnpackedTarget_UnpackedTarget,$(2),$(call gb_UnpackedTarball_get_dir,$(1)),$(3))
238 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarget_get_target,$(2))
239 $(call gb_UnpackedTarball_get_clean_target,$(1)) : $(call gb_UnpackedTarget_get_clean_target,$(2))
240 $(call gb_UnpackedTarget_get_target,$(2)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
242 endef
244 # Set patch level to be used for all patches
246 # The default value is 3 to be able to work with current dmake patches.
248 # gb_UnpackedTarball_set_patchlevel unpacked level
249 define gb_UnpackedTarball_set_patchlevel
250 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(2)
252 endef
254 # Add patch flags to be passed to patch for all patches cf. fdo#66826
256 # gb_UnpackedTarball_set_patchlevel unpacked level
257 define gb_UnpackedTarball_set_patchflags
258 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS := $(2)
260 endef
262 # Add a patch to be applied on the unpacked files
264 # gb_UnpackedTarball_add_patch unpacked patch
265 define gb_UnpackedTarball_add_patch
266 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES += $(SRCDIR)/$(2)
267 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(2)
269 endef
271 # Add several patches at once
273 # gb_UnpackedTarball_add_patches unpacked patch(es)
274 define gb_UnpackedTarball_add_patches
275 $(foreach patch,$(2),$(call gb_UnpackedTarball_add_patch,$(1),$(patch)))
277 endef
279 # Add a file from source dir to the unpacked dir
281 # This function should not be used for overwriting existing files--use a
282 # patch for that purpose.
284 # gb_UnpackedTarball_add_file unpacked destfile file
285 define gb_UnpackedTarball_add_file
286 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES += $(SRCDIR)/$(3)
287 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES += $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
288 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(3)
290 endef
292 # Add several files(s) from source dir to the unpacked dir
294 # The files are added into the specified subdir.
296 # gb_UnpackedTarball_add_files unpacked subdir file(s)
297 define gb_UnpackedTarball_add_files
298 $(foreach file,$(3),$(call gb_UnpackedTarball_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
300 endef
302 # Set arbitrary shell command to be run during unpack
304 # The command is run at the very beginning, in freshly unpacked tarball.
305 # The command is run in the unpacked directory. If more than one command
306 # is used, care should be taken that the whole command fails if either
307 # of the sub-commands fails.
309 # gb_UnpackedTarball_set_pre_action unpacked shell-command
310 define gb_UnpackedTarball_set_pre_action
311 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION := $(strip $(2))
313 endef
315 # Set arbitrary shell command to be run during unpack
317 # The command is run at the very end: after patching, C++ extension
318 # mangling and copying additional files in. The command is run in the
319 # unpacked directory. If more than one command is used, care should be
320 # taken that the whole command fails if either of the sub-commands
321 # fails.
323 # NOTE: This is a bit hackish, but it is the easiest way to move files
324 # around or delete files (typically because the file causes build
325 # problems in the original location, c.f. clucene). This is doable by
326 # using -E with patch (we use GNU patch anyway), but it would mean an
327 # additional patch to maintain....
329 # gb_UnpackedTarball_set_post_action unpacked shell-command
330 define gb_UnpackedTarball_set_post_action
331 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION := $(strip $(2))
333 endef
335 define gb_UnpackedTarbal__make_pattern_rule
336 $(call gb_UnpackedTarball_get_dir,$(1))/%$(2) :
337 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
338 touch $$@
340 $(eval gb_UnpackedTarball_PATTERN_RULES_$(1) += $(2))
342 endef
344 define gb_UnpackedTarbal__ensure_pattern_rule
345 $(if $(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule,$(1),$(2)))
347 endef
349 define gb_UnpackedTarbal__make_file_rule
350 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) :
351 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
352 touch $$@
354 endef
356 # Mark a source file to be used outside of this module
358 # This results in the timestamp of the file being updated, so a possible
359 # change is recognized properly by other files depending on it. The
360 # update is run after possible post action.
362 # See description of class ExternalPackage for more information.
364 # gb_UnpackedTarball_mark_output_file unpacked file
365 define gb_UnpackedTarball_mark_output_file
366 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
367 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) : $(call gb_UnpackedTarball_get_target,$(1))
368 $(if $(suffix $(2)),\
369 $(call gb_UnpackedTarbal__ensure_pattern_rule,$(1),$(suffix $(2))),\
370 $(call gb_UnpackedTarbal__make_file_rule,$(1),$(2)) \
373 endef
375 # Mark several source files to be used outside of this module
377 # gb_UnpackedTarball_mark_output_files unpacked file(s)
378 define gb_UnpackedTarball_mark_output_files
379 $(foreach file,$(2),$(call gb_UnpackedTarball_mark_output_file,$(1),$(file)))
381 endef
383 # force the rebuild of an external target
384 # this only works when running as partial build.
386 %.rebuild :
387 if [ -f $(call gb_UnpackedTarball_get_target,$*) ] ; then \
388 touch $(call gb_UnpackedTarball_get_target,$*) ; \
389 make ;\
392 %.genpatch :
393 if [ -d $(call gb_UnpackedTarball_get_dir,$*) -a -d $(call gb_UnpackedTarball_get_pristine_dir,$*) ] ; then \
395 patch_file=$$(pwd)/$*.new.patch.1; \
396 cd $(call gb_UnpackedTarball_get_dir,) ; \
397 diff -ur $*.org $* > $$patch_file; \
398 echo "Patch $$patch_file generated" ; \
399 ); \
400 else \
401 echo "Error: No pristine tarball avaialable for $*" 1>&2 ; \
405 # vim: set noet sw=4 ts=4: