Bump version to 6.4.7.2.M8
[LibreOffice.git] / solenv / gbuild / UnpackedTarball.mk
blob5ba30d9fa977a9ebb1cd2666839d5b5d6c4fb219
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
16 # NOTE: only for commands; targets should use TARFILE_LOCATION directly
18 # Location of internal copies of config.{guess,sub}.
19 gb_UnpackedTarball_CONFIGDIR := $(GBUILDDIR)
21 define gb_UnpackedTarget__command_untar
22 $(GNUTAR) \
23 -x \
24 $(3) \
25 -C $(UNPACKED_DIR) \
26 $(STRIP_COMPONENTS)=$(UNPACKED_STRIP_COMPONENTS) \
27 -f $(UNPACKED_TARBALL)
28 endef
30 define gb_UnpackedTarget__command_unzip
31 unzip \
32 -qq \
33 -d $(UNPACKED_DIR) $(UNPACKED_TARBALL) \
34 $(if $(filter-out 0,$(UNPACKED_STRIP_COMPONENTS)),\
35 && UNZIP_DIR=`ls $(UNPACKED_DIR)` \
36 && mv $(UNPACKED_DIR)/$$UNZIP_DIR/* $(UNPACKED_DIR) \
37 && rm -rf $(UNPACKED_DIR)/$$UNZIP_DIR \
39 endef
41 define gb_UnpackedTarget__command
42 $(call gb_Output_announce,$(notdir $(2)),$(true),UPK,1)
43 $(call gb_Helper_abbreviate_dirs,\
44 $(if $(wildcard $(UNPACKED_DIR)),rm -rf $(UNPACKED_DIR) &&) \
45 mkdir -p $(UNPACKED_DIR) && \
46 $(call gb_UnpackedTarget__command_$(1),$(2),$(3),$(4)) && \
47 touch $(2) \
49 endef
51 $(dir $(call gb_UnpackedTarget_get_target,%)).dir :
52 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
54 $(call gb_UnpackedTarget_get_target,%).tar.bz2 :
55 $(call gb_UnpackedTarget__command,untar,$@,$*,-j)
57 $(call gb_UnpackedTarget_get_target,%).tar.xz :
58 $(call gb_UnpackedTarget__command,untar,$@,$*,-J)
60 $(call gb_UnpackedTarget_get_target,%).tar.gz :
61 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
63 $(call gb_UnpackedTarget_get_target,%).tgz :
64 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
66 $(call gb_UnpackedTarget_get_target,%).zip :
67 $(call gb_UnpackedTarget__command,unzip,$@,$*)
69 $(call gb_UnpackedTarget_get_target,%).oxt :
70 $(call gb_UnpackedTarget__command,unzip,$@,$*)
72 .PHONY : $(call gb_UnpackedTarget_get_clean_target,%)
73 $(call gb_UnpackedTarget_get_clean_target,%) :
74 $(call gb_Output_announce,$*,$(false),UPK,1)
75 $(call gb_Helper_abbreviate_dirs,\
76 rm -f $(call gb_UnpackedTarget_get_target,$*) \
79 # gb_UnpackedTarget_UnpackedTarget target outdir strip-components?
80 define gb_UnpackedTarget_UnpackedTarget
81 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_DIR := $(2)
82 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_TARBALL := $(gb_UnpackedTarget_TARFILE_LOCATION)/$(1)
83 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_STRIP_COMPONENTS := $(if $(strip $(3)),$(strip $(3)),1)
85 $(call gb_UnpackedTarget_get_target,$(1)) : $(TARFILE_LOCATION)/$(1)
86 $(call gb_UnpackedTarget_get_target,$(1)) :| $(dir $(call gb_UnpackedTarget_get_target,$(1))).dir
88 endef
90 # UnpackedTarball class
92 # Handles unpacking and patching of an external project
94 # The unpacked dir is recreated every time one of the patches, copied
95 # files or the makefile changes.
97 # This is what dmake patches use. Once all external modules are
98 # converted, it is better to be changed to 1.
99 gb_UnpackedTarball_PATCHLEVEL_DEFAULT := 2
101 gb_UnpackedTarball_CONVERTTODOS = \
102 $(gb_AWK) 'sub("$$","\r")' $(1) > $(1).TEMP && mv $(1).TEMP $(1)
103 gb_UnpackedTarball_CONVERTTOUNIX = \
104 tr -d '\r' < $(1) > $(1).TEMP && mv $(1).TEMP $(1)
106 define gb_UnpackedTarball__copy_files_impl
107 $(if $(1),\
108 && cp $(firstword $(1)) $(firstword $(2)) \
109 $(call gb_UnpackedTarball__copy_files_impl,$(wordlist 2,$(words $(1)),$(1)),$(wordlist 2,$(words $(2)),$(2))) \
111 endef
113 # Drop leading &&
114 define gb_UnpackedTarball__copy_files_fix
115 $(wordlist 2,$(words $(1)),$(1))
116 endef
118 define gb_UnpackedTarball__copy_files
119 $(call gb_UnpackedTarball__copy_files_fix,$(call gb_UnpackedTarball__copy_files_impl,$(1),$(2)))
120 endef
122 define gb_UnpackedTarball__command
123 $(call gb_Output_announce,$(2),$(true),PAT,2)
124 $(call gb_Helper_abbreviate_dirs,\
126 cd $(3) \
127 $(if $(UNPACKED_IS_BIN_TARBALL),,&& \
128 $(if $(UNPACKED_PRE_ACTION),\
129 $(UNPACKED_PRE_ACTION) && \
131 $(if $(UNPACKED_FILES),\
132 mkdir -p $(sort $(dir $(UNPACKED_DESTFILES))) && \
133 $(call gb_UnpackedTarball__copy_files,$(UNPACKED_FILES),$(UNPACKED_DESTFILES)) && \
135 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTOUNIX,$(file)) && ) \
136 $(if $(UNPACKED_PATCHES),\
137 for p in $(UNPACKED_PATCHES); do \
138 pl=$(UNPACKED_PATCHLEVEL); \
139 s=$${p##*.}; case "$$s" in [0-9]$(CLOSE_PAREN) pl="$$s"; ;; esac ; \
140 $(GNUPATCH) $(UNPACKED_PATCHFLAGS) -f -s "-p$$pl" --fuzz=0 < "$$p"; \
141 if test "$$?" -ne 0; then echo "Patch FAILED: $$p"; exit 1; fi;\
142 done && \
144 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTODOS,$(file)) && ) \
145 $(foreach confdir,$(UNPACKED_CONFIG_DIRS),\
146 cp -f $(gb_UnpackedTarball_CONFIGDIR)/config.guess $(gb_UnpackedTarball_CONFIGDIR)/config.sub $(confdir) && \
148 $(if $(UNPACKED_POST_ACTION),\
149 $(UNPACKED_POST_ACTION) && \
151 $(if $(gb_KEEP_PRISTINE), \
152 rm -fr $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
153 cp -r $(call gb_UnpackedTarball_get_dir,$(2)) $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
155 touch $(1) \
157 ) || \
159 touch $(call gb_UnpackedTarball_get_preparation_target,$(2)) && \
160 exit 1 \
163 endef
165 $(dir $(call gb_UnpackedTarball_get_target,%)).dir :
166 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
168 $(call gb_UnpackedTarball_get_preparation_target,%) :
169 touch $@
171 $(call gb_UnpackedTarball_get_target,%) :
172 $(call gb_UnpackedTarball__command,$@,$*,$(call gb_UnpackedTarball_get_dir,$*))
174 $(call gb_UnpackedTarball_get_final_target,%) :
175 touch $@
177 .PHONY : $(call gb_UnpackedTarball_get_clean_target,%)
178 $(call gb_UnpackedTarball_get_clean_target,%) :
179 $(call gb_Output_announce,$*,$(false),PAT,2)
180 $(call gb_Helper_abbreviate_dirs,\
181 rm -rf \
182 $(call gb_UnpackedTarball_get_final_target,$*) \
183 $(call gb_UnpackedTarball_get_target,$*) \
184 $(call gb_UnpackedTarball_get_preparation_target,$*) \
185 $(call gb_UnpackedTarball_get_dir,$*) \
186 $(call gb_UnpackedTarball_get_pristine_dir,$*) \
189 # Initialize unpacked tarball
190 define gb_UnpackedTarball_UnpackedTarball_internal
191 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES :=
192 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES :=
193 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL :=
194 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES :=
195 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(gb_UnpackedTarball_PATCHLEVEL_DEFAULT)
196 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS :=
197 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION :=
198 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION :=
199 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_CONFIG_DIRS :=
201 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
202 $(call gb_UnpackedTarball_get_preparation_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
203 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
204 $(call gb_UnpackedTarball_get_target,$(1)) :| $(dir $(call gb_UnpackedTarball_get_target,$(1))).dir
205 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_target,$(1))
207 private gb_UnpackedTarball_PATTERN_RULES_$(1) :=
209 endef
211 # Define a new unpacked tarball
212 define gb_UnpackedTarball_UnpackedTarball
213 $(call gb_UnpackedTarball_UnpackedTarball_internal,$(1))
215 $$(eval $$(call gb_Module_register_target,UnpackedTarball_$(1),$(call gb_UnpackedTarball_get_final_target,$(1)),$(call gb_UnpackedTarball_get_clean_target,$(1))))
216 $(call gb_Helper_make_userfriendly_targets,$(1),UnpackedTarball,$(call gb_UnpackedTarball_get_final_target,$(1)))
218 endef
220 # Convert line ending from dos to unix style for selected files
222 # This is done before applying patches, because patches expect unix
223 # style line ending, and the files are converted back after that. The
224 # files are relative to the unpacked path.
226 # gb_UnpackedTarball_fix_end_of_line unpacked file(s)
227 define gb_UnpackedTarball_fix_end_of_line
228 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL += $(addprefix $(call gb_UnpackedTarball_get_dir,$(1))/,$(2))
230 endef
233 # Internal version of set_tarball, mostly to avoid repeated invocation of $(shell
234 define gb_UnpackedTarball_set_tarball_internal
235 $(call gb_UnpackedTarget_UnpackedTarget,$(2),$(call gb_UnpackedTarball_get_dir,$(1)),$(3),$(4))
236 $(call gb_UnpackedTarball_get_target,$(1)) : $(call gb_UnpackedTarget_get_target,$(2))
237 $(call gb_UnpackedTarball_get_clean_target,$(1)) : $(call gb_UnpackedTarget_get_clean_target,$(2))
238 $(call gb_UnpackedTarget_get_target,$(2)) : $(call gb_UnpackedTarball_get_preparation_target,$(1))
239 $(if $(findstring in,$(5)),
240 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_IS_BIN_TARBALL := YES
241 $(call gb_ExternalProject_get_state_target,$(1),%) : UNPACKED_IS_BIN_TARBALL := YES)
242 $(if $(findstring out,$(5)),$(call gb_Module_get_target,$(4)) : $(TARFILE_LOCATION)/$(6)
243 $(TARFILE_LOCATION)/$(6) : $(call gb_Module_get_nonl10n_target,$(4))
244 $$(call gb_Output_announce,$(6),$(true),PKB,3)
245 if test ! -f "$$@" ; then cd $(call gb_UnpackedTarball_get_dir,) && $(GNUTAR) -czf "$$@" $(1)/ || $(GNUTAR) -czf "$$@" $(1)/ ; else touch "$$@" ; fi)
247 endef
249 # Set tarball name
251 # gb_UnpackedTarball_set_tarball unpacked tarball-name
252 define gb_UnpackedTarball_set_tarball
253 $(if $(USE_LIBRARY_BIN_TAR),
254 $(if $(4),
255 $(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)"),
256 $(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),\
257 $(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)")))
259 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
262 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
265 endef
267 # Set patch level to be used for all patches
269 # The default value is 3 to be able to work with current dmake patches.
271 # gb_UnpackedTarball_set_patchlevel unpacked level
272 define gb_UnpackedTarball_set_patchlevel
273 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(2)
275 endef
277 # Add patch flags to be passed to patch for all patches cf. fdo#66826
279 # gb_UnpackedTarball_set_patchlevel unpacked level
280 define gb_UnpackedTarball_set_patchflags
281 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS := $(2)
283 endef
285 # Add a patch to be applied on the unpacked files
287 # gb_UnpackedTarball_add_patch unpacked patch
288 define gb_UnpackedTarball_add_patch
289 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES += $(SRCDIR)/$(2)
290 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(2)
292 endef
294 # Add several patches at once
296 # gb_UnpackedTarball_add_patches unpacked patch(es)
297 define gb_UnpackedTarball_add_patches
298 $(foreach patch,$(2),$(call gb_UnpackedTarball_add_patch,$(1),$(patch)))
300 endef
302 # Add a file from source dir to the unpacked dir
304 # This function should not be used for overwriting existing files--use a
305 # patch for that purpose.
307 # gb_UnpackedTarball_add_file unpacked destfile file
308 define gb_UnpackedTarball_add_file
309 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES += $(SRCDIR)/$(3)
310 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES += $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
311 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(3)
313 endef
315 # Add several files(s) from source dir to the unpacked dir
317 # The files are added into the specified subdir.
319 # gb_UnpackedTarball_add_files unpacked subdir file(s)
320 define gb_UnpackedTarball_add_files
321 $(foreach file,$(3),$(call gb_UnpackedTarball_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
323 endef
325 # Set arbitrary shell command to be run during unpack
327 # The command is run at the very beginning, in freshly unpacked tarball.
328 # The command is run in the unpacked directory. If more than one command
329 # is used, care should be taken that the whole command fails if either
330 # of the sub-commands fails.
332 # gb_UnpackedTarball_set_pre_action unpacked shell-command
333 define gb_UnpackedTarball_set_pre_action
334 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION := $(strip $(2))
336 endef
338 # Set arbitrary shell command to be run during unpack
340 # The command is run at the very end: after patching, C++ extension
341 # mangling and copying additional files in. The command is run in the
342 # unpacked directory. If more than one command is used, care should be
343 # taken that the whole command fails if either of the sub-commands
344 # fails.
346 # NOTE: This is a bit hackish, but it is the easiest way to move files
347 # around or delete files (typically because the file causes build
348 # problems in the original location, c.f. clucene). This is doable by
349 # using -E with patch (we use GNU patch anyway), but it would mean an
350 # additional patch to maintain...
352 # gb_UnpackedTarball_set_post_action unpacked shell-command
353 define gb_UnpackedTarball_set_post_action
354 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION := $(strip $(2))
356 endef
358 define gb_UnpackedTarbal__make_pattern_rule
359 $(call gb_UnpackedTarball_get_dir,$(1))/%$(2) :
360 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
361 $$(if $$(UNPACKED_MODE),chmod $$(UNPACKED_MODE) $$@ &&) \
362 touch $$@
364 $(eval gb_UnpackedTarball_PATTERN_RULES_$(1) += $(2))
366 endef
368 define gb_UnpackedTarbal__ensure_pattern_rule
369 $(if $(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule,$(1),$(2)))
371 endef
373 define gb_UnpackedTarbal__make_file_rule
374 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) :
375 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
376 $$(if $$(UNPACKED_MODE),chmod $$(UNPACKED_MODE) $$@ &&) \
377 touch $$@
379 endef
381 # Mark a source file to be used outside of this module
383 # This results in the timestamp of the file being updated, so a possible
384 # change is recognized properly by other files depending on it. The
385 # update is run after possible post action.
387 # See description of class ExternalPackage for more information.
389 # gb_UnpackedTarball_mark_output_file unpacked file
390 define gb_UnpackedTarball_mark_output_file
391 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(call gb_UnpackedTarball_get_dir,$(1))/$(2)
392 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) : $(call gb_UnpackedTarball_get_target,$(1))
393 $(call gb_UnpackedTarball_get_dir,$(1))/$(2) : UNPACKED_MODE := 644
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 # Replace project's config.{guess,sub} files by internal copies
411 # This is useful if the project's config files are outdated and don't
412 # allow build on some new arch. The internal copies are located at
413 # gb_UnpackedTarball_CONFIGDIR.
415 # If the configs are placed somewhere else than in the top-level dir of
416 # the project, pass the (relative) dir as second argument. (It can even
417 # be a list of dirs, if the project contains multiple subprojects, each
418 # with its own configure.)
420 # gb_UnpackedTarball_update_autoconf_configs unpacked dirs(s)?
421 define gb_UnpackedTarball_update_autoconf_configs
422 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_CONFIG_DIRS += $(if $(strip $(2)),$(2),.)
424 endef
426 # force the rebuild of an external target
427 # this only works when running as partial build.
429 %.rebuild :
430 if [ -f $(call gb_UnpackedTarball_get_target,$*) ] ; then \
431 touch $(call gb_UnpackedTarball_get_target,$*) ; \
432 $(MAKE) ;\
435 %.genpatch :
436 if [ -d $(call gb_UnpackedTarball_get_dir,$*) -a -d $(call gb_UnpackedTarball_get_pristine_dir,$*) ] ; then \
438 patch_file=$$(pwd)/$*.new.patch.1; \
439 cd $(call gb_UnpackedTarball_get_dir,) ; \
440 diff -ur $*.org $* > $$patch_file; \
441 echo "Patch $$patch_file generated" ; \
442 ); \
443 else \
444 echo "Error: No pristine tarball available for $*" 1>&2 ; \
448 # vim: set noet sw=4 ts=4: