bump product version to 4.2.0.1
[LibreOffice.git] / solenv / gbuild / UnpackedTarball.mk
blob066f8ff888277f2a2224243be0f022f5f202d704
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 && rm -rf $(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_IS_BIN_TARBALL),,&& \
135 $(if $(UNPACKED_PRE_ACTION),\
136 $(UNPACKED_PRE_ACTION) && \
138 $(if $(UNPACKED_FILES),\
139 mkdir -p $(sort $(dir $(UNPACKED_DESTFILES))) && \
140 $(call gb_UnpackedTarball__copy_files,$(UNPACKED_FILES),$(UNPACKED_DESTFILES)) && \
142 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTOUNIX,$(file)) && ) \
143 $(if $(UNPACKED_PATCHES),\
144 for p in $(UNPACKED_PATCHES); do \
145 pl=$(UNPACKED_PATCHLEVEL); \
146 s=$${p##*.}; case "$$s" in [0-9]$(CLOSE_PAREN) pl="$$s"; ;; esac ; \
147 $(GNUPATCH) $(UNPACKED_PATCHFLAGS) -f -s "-p$$pl" --fuzz=0 < "$$p"; \
148 if test "$$?" -ne 0; then echo "Patch FAILED: $$p"; exit 1; fi;\
149 done && \
151 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTODOS,$(file)) && ) \
152 $(if $(UNPACKED_POST_ACTION),\
153 $(UNPACKED_POST_ACTION) && \
155 $(if $(gb_KEEP_PRISTINE), \
156 rm -fr $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
157 cp -r $(call gb_UnpackedTarball_get_dir,$(2)) $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
159 touch $(1) \
161 ) || \
163 touch $(call gb_UnpackedTarball_get_preparation_target,$(2)) && \
164 exit 1 \
167 endef
169 $(dir $(call gb_UnpackedTarball_get_target,%)).dir :
170 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
172 $(call gb_UnpackedTarball_get_preparation_target,%) :
173 touch $@
175 $(call gb_UnpackedTarball_get_target,%) :
176 $(call gb_UnpackedTarball__command,$@,$*,$(call gb_UnpackedTarball_get_dir,$*))
178 $(call gb_UnpackedTarball_get_final_target,%) :
179 touch $@
181 .PHONY : $(call gb_UnpackedTarball_get_clean_target,%)
182 $(call gb_UnpackedTarball_get_clean_target,%) :
183 $(call gb_Output_announce,$*,$(false),PAT,2)
184 $(call gb_Helper_abbreviate_dirs,\
185 rm -rf \
186 $(call gb_UnpackedTarball_get_final_target,$*) \
187 $(call gb_UnpackedTarball_get_target,$*) \
188 $(call gb_UnpackedTarball_get_preparation_target,$*) \
189 $(call gb_UnpackedTarball_get_dir,$*) \
190 $(call gb_UnpackedTarball_get_pristine_dir,$*) \
193 # Initialize unpacked tarball
194 define gb_UnpackedTarball_UnpackedTarball_internal
195 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES :=
196 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES :=
197 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL :=
198 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES :=
199 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(gb_UnpackedTarball_PATCHLEVEL_DEFAULT)
200 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS :=
201 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION :=
202 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION :=
204 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
205 $(call gb_UnpackedTarball_get_preparation_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
206 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
207 $(call gb_UnpackedTarball_get_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
208 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_target,$(1))
210 private gb_UnpackedTarball_PATTERN_RULES_$(1) :=
212 endef
214 # Define a new unpacked tarball
215 define gb_UnpackedTarball_UnpackedTarball
216 $(call gb_UnpackedTarball_UnpackedTarball_internal,$(1))
218 $$(eval $$(call gb_Module_register_target,$(call gb_UnpackedTarball_get_final_target,$(1)),$(call gb_UnpackedTarball_get_clean_target,$(1))))
219 $(call gb_Helper_make_userfriendly_targets,$(1),UnpackedTarball,$(call gb_UnpackedTarball_get_final_target,$(1)))
221 endef
223 # Convert line ending from dos to unix style for selected files
225 # This is done before applying patches, because patches expect unix
226 # style line ending, and the files are converted back after that. The
227 # files are relative to the unpacked path.
229 # gb_UnpackedTarball_fix_end_of_line unpacked file(s)
230 define gb_UnpackedTarball_fix_end_of_line
231 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL += $(addprefix $(call gb_UnpackedTarball_get_dir,$(1))/,$(2))
233 endef
236 # Internal version of set_tarbal, mostly to avoid repeated invocation of $(shel
237 define gb_UnpackedTarball_set_tarball_internal
238 $(call gb_UnpackedTarget_UnpackedTarget,$(2),$(call gb_UnpackedTarball_get_dir,$(1)),$(3),$(4))
239 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarget_get_target,$(2))
240 $(call gb_UnpackedTarball_get_clean_target,$(1)) : $(call gb_UnpackedTarget_get_clean_target,$(2))
241 $(call gb_UnpackedTarget_get_target,$(2)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
242 $(if $(findstring in,$(5)),
243 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_IS_BIN_TARBALL := YES
244 $(call gb_ExternalProject_get_state_target,$(1),%) : UNPACKED_IS_BIN_TARBALL := YES)
245 $(if $(findstring out,$(5)),$(call gb_Module_get_target,$(4)) : $(gb_UnpackedTarget_TARFILE_LOCATION)/$(6)
246 $(gb_UnpackedTarget_TARFILE_LOCATION)/$(6) : $(call gb_Module_get_nonl10n_target,$(4))
247 $$(call gb_Output_announce,$(6),$(true),PKB,3)
248 if test ! -f "$$@" ; then cd $(call gb_UnpackedTarball_get_dir,) && $(GNUTAR) -czf "$$@" $(1)/ || $(GNUTAR) -czf "$$@" $(1)/ ; else touch "$$@" ; fi)
250 endef
252 # Set tarball name
254 # gb_UnpackedTarball_set_tarball unpacked tarball-name
255 define gb_UnpackedTarball_set_tarball
256 $(if $(findstring YES,$(USE_LIBRARY_BIN_TAR)),
257 $(if $(4),
258 $(if $(shell "$(SRCDIR)/solenv/bin/bin_library_info.sh" -l "$(gb_UnpackedTarget_TARFILE_LOCATION)" -o "$(4)" -b "$(BUILDDIR)" -s "$(SRCDIR)" -t "$(2)" -m verify -p "$(OS)_$(CPUNAME)"),
259 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(shell "$(SRCDIR)/solenv/bin/bin_library_info.sh" -l "$(gb_UnpackedTarget_TARFILE_LOCATION)" -o "$(4)" -b "$(BUILDDIR)" -s "$(SRCDIR)" -t "$(2)" -m verify -p "$(OS)_$(CPUNAME)"),$(3),$(4),in),\
260 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),out,$(shell "$(SRCDIR)/solenv/bin/bin_library_info.sh" -l "$(gb_UnpackedTarget_TARFILE_LOCATION)" -o "$(4)" -b "$(BUILDDIR)" -s "$(SRCDIR)" -t "$(2)" -m name -p "$(OS)_$(CPUNAME)")))
262 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
265 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
268 endef
270 # Set patch level to be used for all patches
272 # The default value is 3 to be able to work with current dmake patches.
274 # gb_UnpackedTarball_set_patchlevel unpacked level
275 define gb_UnpackedTarball_set_patchlevel
276 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(2)
278 endef
280 # Add patch flags to be passed to patch for all patches cf. fdo#66826
282 # gb_UnpackedTarball_set_patchlevel unpacked level
283 define gb_UnpackedTarball_set_patchflags
284 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS := $(2)
286 endef
288 # Add a patch to be applied on the unpacked files
290 # gb_UnpackedTarball_add_patch unpacked patch
291 define gb_UnpackedTarball_add_patch
292 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES += $(SRCDIR)/$(2)
293 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(2)
295 endef
297 # Add several patches at once
299 # gb_UnpackedTarball_add_patches unpacked patch(es)
300 define gb_UnpackedTarball_add_patches
301 $(foreach patch,$(2),$(call gb_UnpackedTarball_add_patch,$(1),$(patch)))
303 endef
305 # Add a file from source dir to the unpacked dir
307 # This function should not be used for overwriting existing files--use a
308 # patch for that purpose.
310 # gb_UnpackedTarball_add_file unpacked destfile file
311 define gb_UnpackedTarball_add_file
312 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES += $(SRCDIR)/$(3)
313 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES += $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
314 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(3)
316 endef
318 # Add several files(s) from source dir to the unpacked dir
320 # The files are added into the specified subdir.
322 # gb_UnpackedTarball_add_files unpacked subdir file(s)
323 define gb_UnpackedTarball_add_files
324 $(foreach file,$(3),$(call gb_UnpackedTarball_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
326 endef
328 # Set arbitrary shell command to be run during unpack
330 # The command is run at the very beginning, in freshly unpacked tarball.
331 # The command is run in the unpacked directory. If more than one command
332 # is used, care should be taken that the whole command fails if either
333 # of the sub-commands fails.
335 # gb_UnpackedTarball_set_pre_action unpacked shell-command
336 define gb_UnpackedTarball_set_pre_action
337 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION := $(strip $(2))
339 endef
341 # Set arbitrary shell command to be run during unpack
343 # The command is run at the very end: after patching, C++ extension
344 # mangling and copying additional files in. The command is run in the
345 # unpacked directory. If more than one command is used, care should be
346 # taken that the whole command fails if either of the sub-commands
347 # fails.
349 # NOTE: This is a bit hackish, but it is the easiest way to move files
350 # around or delete files (typically because the file causes build
351 # problems in the original location, c.f. clucene). This is doable by
352 # using -E with patch (we use GNU patch anyway), but it would mean an
353 # additional patch to maintain....
355 # gb_UnpackedTarball_set_post_action unpacked shell-command
356 define gb_UnpackedTarball_set_post_action
357 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION := $(strip $(2))
359 endef
361 define gb_UnpackedTarbal__make_pattern_rule
362 $(call gb_UnpackedTarball_get_dir,$(1))/%$(2) :
363 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
364 touch $$@
366 $(eval gb_UnpackedTarball_PATTERN_RULES_$(1) += $(2))
368 endef
370 define gb_UnpackedTarbal__ensure_pattern_rule
371 $(if $(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule,$(1),$(2)))
373 endef
375 define gb_UnpackedTarbal__make_file_rule
376 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) :
377 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
378 touch $$@
380 endef
382 # Mark a source file to be used outside of this module
384 # This results in the timestamp of the file being updated, so a possible
385 # change is recognized properly by other files depending on it. The
386 # update is run after possible post action.
388 # See description of class ExternalPackage for more information.
390 # gb_UnpackedTarball_mark_output_file unpacked file
391 define gb_UnpackedTarball_mark_output_file
392 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
393 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) : $(call gb_UnpackedTarball_get_target,$(1))
394 $(if $(suffix $(2)),\
395 $(call gb_UnpackedTarbal__ensure_pattern_rule,$(1),$(suffix $(2))),\
396 $(call gb_UnpackedTarbal__make_file_rule,$(1),$(2)) \
399 endef
401 # Mark several source files to be used outside of this module
403 # gb_UnpackedTarball_mark_output_files unpacked file(s)
404 define gb_UnpackedTarball_mark_output_files
405 $(foreach file,$(2),$(call gb_UnpackedTarball_mark_output_file,$(1),$(file)))
407 endef
409 # force the rebuild of an external target
410 # this only works when running as partial build.
412 %.rebuild :
413 if [ -f $(call gb_UnpackedTarball_get_target,$*) ] ; then \
414 touch $(call gb_UnpackedTarball_get_target,$*) ; \
415 make ;\
418 %.genpatch :
419 if [ -d $(call gb_UnpackedTarball_get_dir,$*) -a -d $(call gb_UnpackedTarball_get_pristine_dir,$*) ] ; then \
421 patch_file=$$(pwd)/$*.new.patch.1; \
422 cd $(call gb_UnpackedTarball_get_dir,) ; \
423 diff -ur $*.org $* > $$patch_file; \
424 echo "Patch $$patch_file generated" ; \
425 ); \
426 else \
427 echo "Error: No pristine tarball avaialable for $*" 1>&2 ; \
431 # vim: set noet sw=4 ts=4: