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
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
24 $(if
$(filter zip
,$(suffix $(1))),\
25 $(gb_UnpackedTarget_STRIP_COMPONENTS_ZIP_DEFAULT
),\
26 $(gb_UnpackedTarget_STRIP_COMPONENTS_TAR_DEFAULT
) \
31 define gb_UnpackedTarget__command_untar
36 $(STRIP_COMPONENTS
)=$(UNPACKED_STRIP_COMPONENTS
) \
37 -f
$(UNPACKED_TARBALL
)
40 define gb_UnpackedTarget__command_unzip
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 \
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)) && \
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
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
115 && cp
$(firstword $(1)) $(firstword $(2)) \
116 $(call gb_UnpackedTarball__copy_files_impl
,$(wordlist
2,$(words $(1)),$(1)),$(wordlist
2,$(words $(2)),$(2))) \
121 define gb_UnpackedTarball__copy_files_fix
122 $(wordlist
2,$(words $(1)),$(1))
125 define gb_UnpackedTarball__copy_files
126 $(call gb_UnpackedTarball__copy_files_fix
,$(call gb_UnpackedTarball__copy_files_impl
,$(1),$(2)))
129 define gb_UnpackedTarball__command
130 $(call gb_Output_announce
,$(2),$(true
),PAT
,2)
131 $(call gb_Helper_abbreviate_dirs
,\
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
;\
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)) && \
161 touch
$(call gb_UnpackedTarball_get_preparation_target
,$(2)) && \
167 $(dir $(call gb_UnpackedTarball_get_target
,%)).
dir :
168 $(if
$(wildcard $(dir $@
)),,mkdir
-p
$(dir $@
))
170 $(call gb_UnpackedTarball_get_preparation_target
,%) :
173 $(call gb_UnpackedTarball_get_target
,%) :
174 $(call gb_UnpackedTarball__command
,$@
,$*,$(call gb_UnpackedTarball_get_dir
,$*))
176 $(call gb_UnpackedTarball_get_final_target
,%) :
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
,\
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) :=
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)))
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))
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))
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)
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)
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)
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
)))
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)
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
)))
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))
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
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))
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
))
340 $(eval gb_UnpackedTarball_PATTERN_RULES_
$(1) += $(2))
344 define gb_UnpackedTarbal__ensure_pattern_rule
345 $(if
$(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_
$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule
,$(1),$(2)))
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
))
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)) \
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
)))
383 # force the rebuild of an external target
384 # this only works when running as partial build.
387 if
[ -f
$(call gb_UnpackedTarball_get_target
,$*) ] ; then \
388 touch
$(call gb_UnpackedTarball_get_target
,$*) ; \
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" ; \
401 echo
"Error: No pristine tarball avaialable for $*" 1>&2 ; \
405 # vim: set noet sw=4 ts=4: