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
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
26 $(STRIP_COMPONENTS
)=$(UNPACKED_STRIP_COMPONENTS
) \
27 -f
$(UNPACKED_TARBALL
)
30 define gb_UnpackedTarget__command_unzip
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 \
41 define gb_UnpackedTarget__command
42 $(call gb_Output_announce
,$(notdir $(2)),$(true
),UPK
,1)
43 $(call gb_Trace_StartRange
,$(notdir $(2)),UPK
)
44 $(call gb_Helper_abbreviate_dirs
,\
45 $(if
$(wildcard $(UNPACKED_DIR
)),rm -rf
$(UNPACKED_DIR
) &&) \
46 mkdir
-p
$(UNPACKED_DIR
) && \
47 $(call gb_UnpackedTarget__command_
$(1),$(2),$(3),$(4)) && \
50 $(call gb_Trace_EndRange
,$(notdir $(2)),UPK
)
53 $(dir $(call gb_UnpackedTarget_get_target
,%)).
dir :
54 $(if
$(wildcard $(dir $@
)),,mkdir
-p
$(dir $@
))
56 $(call gb_UnpackedTarget_get_target
,%).
tar.bz2
:
57 $(call gb_UnpackedTarget__command
,untar
,$@
,$*,-j
)
59 $(call gb_UnpackedTarget_get_target
,%).
tar.xz
:
60 $(call gb_UnpackedTarget__command
,untar
,$@
,$*,-J
)
62 $(call gb_UnpackedTarget_get_target
,%).
tar.gz
:
63 $(call gb_UnpackedTarget__command
,untar
,$@
,$*,-z
)
65 $(call gb_UnpackedTarget_get_target
,%).tgz
:
66 $(call gb_UnpackedTarget__command
,untar
,$@
,$*,-z
)
68 $(call gb_UnpackedTarget_get_target
,%).zip
:
69 $(call gb_UnpackedTarget__command
,unzip
,$@
,$*)
71 $(call gb_UnpackedTarget_get_target
,%).oxt
:
72 $(call gb_UnpackedTarget__command
,unzip
,$@
,$*)
74 .PHONY
: $(call gb_UnpackedTarget_get_clean_target
,%)
75 $(call gb_UnpackedTarget_get_clean_target
,%) :
76 $(call gb_Output_announce
,$*,$(false
),UPK
,1)
77 $(call gb_Helper_abbreviate_dirs
,\
78 rm -f
$(call gb_UnpackedTarget_get_target
,$*) \
81 # gb_UnpackedTarget_UnpackedTarget target outdir strip-components?
82 define gb_UnpackedTarget_UnpackedTarget
83 $(call gb_UnpackedTarget_get_target
,$(1)) : UNPACKED_DIR
:= $(2)
84 $(call gb_UnpackedTarget_get_target
,$(1)) : UNPACKED_TARBALL
:= $(gb_UnpackedTarget_TARFILE_LOCATION
)/$(1)
85 $(call gb_UnpackedTarget_get_target
,$(1)) : UNPACKED_STRIP_COMPONENTS
:= $(if
$(strip $(3)),$(strip $(3)),1)
87 $(call gb_UnpackedTarget_get_target
,$(1)) : $(TARFILE_LOCATION
)/$(1)
88 $(call gb_UnpackedTarget_get_target
,$(1)) :|
$(dir $(call gb_UnpackedTarget_get_target
,$(1))).
dir
92 # UnpackedTarball class
94 # Handles unpacking and patching of an external project
96 # The unpacked dir is recreated every time one of the patches, copied
97 # files or the makefile changes.
99 # This is what dmake patches use. Once all external modules are
100 # converted, it is better to be changed to 1.
101 gb_UnpackedTarball_PATCHLEVEL_DEFAULT
:= 2
103 gb_UnpackedTarball_CONVERTTODOS
= \
104 $(gb_AWK
) 'sub("$$","\r")' $(1) > $(1).TEMP
&& mv
$(1).TEMP
$(1)
105 gb_UnpackedTarball_CONVERTTOUNIX
= \
106 tr
-d
'\r' < $(1) > $(1).TEMP
&& mv
$(1).TEMP
$(1)
108 define gb_UnpackedTarball__copy_files_impl
110 && cp
$(firstword $(1)) $(firstword $(2)) \
111 $(call gb_UnpackedTarball__copy_files_impl
,$(wordlist
2,$(words $(1)),$(1)),$(wordlist
2,$(words $(2)),$(2))) \
116 define gb_UnpackedTarball__copy_files_fix
117 $(wordlist
2,$(words $(1)),$(1))
120 define gb_UnpackedTarball__copy_files
121 $(call gb_UnpackedTarball__copy_files_fix
,$(call gb_UnpackedTarball__copy_files_impl
,$(1),$(2)))
124 define gb_UnpackedTarball__command
125 $(call gb_Helper_abbreviate_dirs
,\
128 $(if
$(UNPACKED_IS_BIN_TARBALL
),,&& \
129 $(if
$(UNPACKED_PRE_ACTION
),\
130 $(UNPACKED_PRE_ACTION
) && \
132 $(if
$(UNPACKED_FILES
),\
133 mkdir
-p
$(sort $(dir $(UNPACKED_DESTFILES
))) && \
134 $(call gb_UnpackedTarball__copy_files
,$(UNPACKED_FILES
),$(UNPACKED_DESTFILES
)) && \
136 $(foreach file
,$(UNPACKED_FIX_EOL
),$(call gb_UnpackedTarball_CONVERTTOUNIX
,$(file
)) && ) \
137 $(if
$(UNPACKED_PATCHES
),\
138 for p in
$(UNPACKED_PATCHES
); do \
139 pl
=$(UNPACKED_PATCHLEVEL
); \
140 s
=$${p
##*.}; case "$$s" in [0-9]$(CLOSE_PAREN) pl="$$s"; ;; esac ; \
141 $(GNUPATCH
) $(UNPACKED_PATCHFLAGS
) -f
-s
"-p$$pl" --fuzz
=0 < "$$p"; \
142 if
test "$$?" -ne
0; then echo
"Patch FAILED: $$p"; exit
1; fi
;\
145 $(foreach file
,$(UNPACKED_FIX_EOL
),$(call gb_UnpackedTarball_CONVERTTODOS
,$(file
)) && ) \
146 $(foreach confdir
,$(UNPACKED_CONFIG_DIRS
),\
147 cp
-f
$(SRCDIR
)/config.guess
$(SRCDIR
)/config.sub
$(confdir
) && \
149 $(if
$(UNPACKED_POST_ACTION
),\
150 $(UNPACKED_POST_ACTION
) && \
152 $(if
$(gb_KEEP_PRISTINE
), \
153 rm -fr
$(call gb_UnpackedTarball_get_pristine_dir
,$(2)) && \
154 cp
-r
$(call gb_UnpackedTarball_get_dir
,$(2)) $(call gb_UnpackedTarball_get_pristine_dir
,$(2)) && \
160 touch
$(call gb_UnpackedTarball_get_preparation_target
,$(2)) && \
166 $(dir $(call gb_UnpackedTarball_get_target
,%)).
dir :
167 $(if
$(wildcard $(dir $@
)),,mkdir
-p
$(dir $@
))
169 $(call gb_UnpackedTarball_get_preparation_target
,%) :
172 $(call gb_UnpackedTarball_get_target
,%) :
173 $(call gb_Output_announce
,$*,$(true
),PAT
,2)
174 $(call gb_Trace_StartRange
,$*,PAT
)
175 $(call gb_UnpackedTarball__command
,$@
,$*,$(call gb_UnpackedTarball_get_dir
,$*))
176 $(call gb_Trace_EndRange
,$*,PAT
)
178 $(call gb_UnpackedTarball_get_final_target
,%) :
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
,\
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
:=
203 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_CONFIG_DIRS
:=
205 $(call gb_UnpackedTarball_get_preparation_target
,$(1)) : $(gb_Module_CURRENTMAKEFILE
)
206 $(call gb_UnpackedTarball_get_preparation_target
,$(1)) :|
$(dir $(call gb_UnpackedTarball_get_target
,$(1))).
dir
207 $(call gb_UnpackedTarball_get_target
,$(1)) : $(call gb_UnpackedTarball_get_preparation_target
,$(1))
208 $(call gb_UnpackedTarball_get_target
,$(1)) :|
$(dir $(call gb_UnpackedTarball_get_target
,$(1))).
dir
209 $(call gb_UnpackedTarball_get_final_target
,$(1)) : $(call gb_UnpackedTarball_get_target
,$(1))
211 private gb_UnpackedTarball_PATTERN_RULES_
$(1) :=
215 # Define a new unpacked tarball
216 define gb_UnpackedTarball_UnpackedTarball
217 $(call gb_UnpackedTarball_UnpackedTarball_internal
,$(1))
219 $$(eval
$$(call gb_Module_register_target
,$(call gb_UnpackedTarball_get_final_target
,$(1)),$(call gb_UnpackedTarball_get_clean_target
,$(1))))
220 $(call gb_Helper_make_userfriendly_targets
,$(1),UnpackedTarball
,$(call gb_UnpackedTarball_get_final_target
,$(1)))
224 # Convert line ending from dos to unix style for selected files
226 # This is done before applying patches, because patches expect unix
227 # style line ending, and the files are converted back after that. The
228 # files are relative to the unpacked path.
230 # gb_UnpackedTarball_fix_end_of_line unpacked file(s)
231 define gb_UnpackedTarball_fix_end_of_line
232 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_FIX_EOL
+= $(addprefix $(call gb_UnpackedTarball_get_dir
,$(1))/,$(2))
237 # Internal version of set_tarball, mostly to avoid repeated invocation of $(shell
238 define gb_UnpackedTarball_set_tarball_internal
239 $(call gb_UnpackedTarget_UnpackedTarget
,$(2),$(call gb_UnpackedTarball_get_dir
,$(1)),$(3),$(4))
240 $(call gb_UnpackedTarball_get_target
,$(1)) : $(call gb_UnpackedTarget_get_target
,$(2))
241 $(call gb_UnpackedTarball_get_clean_target
,$(1)) : $(call gb_UnpackedTarget_get_clean_target
,$(2))
242 $(call gb_UnpackedTarget_get_target
,$(2)) : $(call gb_UnpackedTarball_get_preparation_target
,$(1))
243 $(if
$(findstring in
,$(5)),
244 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_IS_BIN_TARBALL
:= YES
245 $(call gb_ExternalProject_get_state_target
,$(1),%) : UNPACKED_IS_BIN_TARBALL
:= YES
)
246 $(if
$(findstring out
,$(5)),$(call gb_Module_get_target
,$(4)) : $(TARFILE_LOCATION
)/$(6)
247 $(TARFILE_LOCATION
)/$(6) : $(call gb_Module_get_nonl10n_target
,$(4))
248 $$(call gb_Output_announce
,$(6),$(true
),PKB
,3)
249 $$(call gb_Trace_StartRange
,$(6),PKB
)
250 if
test ! -f
"$$@" ; then cd
$(call gb_UnpackedTarball_get_dir
,) && $(GNUTAR
) -czf
"$$@" $(1)/ ||
$(GNUTAR
) -czf
"$$@" $(1)/ ; else touch
"$$@" ; fi
251 $$(call gb_Trace_EndRange
,$(6),PKB
)
258 # gb_UnpackedTarball_set_tarball unpacked tarball-name
259 define gb_UnpackedTarball_set_tarball
260 $(if
$(USE_LIBRARY_BIN_TAR
),
262 $(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)"),
263 $(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
),\
264 $(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)")))
266 $(call gb_UnpackedTarball_set_tarball_internal
,$(1),$(2),$(3),$(4),)
269 $(call gb_UnpackedTarball_set_tarball_internal
,$(1),$(2),$(3),$(4),)
274 # Set patch level to be used for all patches
276 # The default value is 3 to be able to work with current dmake patches.
278 # gb_UnpackedTarball_set_patchlevel unpacked level
279 define gb_UnpackedTarball_set_patchlevel
280 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_PATCHLEVEL
:= $(2)
284 # Add patch flags to be passed to patch for all patches cf. fdo#66826
286 # gb_UnpackedTarball_set_patchlevel unpacked level
287 define gb_UnpackedTarball_set_patchflags
288 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_PATCHFLAGS
:= $(2)
292 # Add a patch to be applied on the unpacked files
294 # gb_UnpackedTarball_add_patch unpacked patch
295 define gb_UnpackedTarball_add_patch
296 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_PATCHES
+= $(SRCDIR
)/$(2)
297 $(call gb_UnpackedTarball_get_preparation_target
,$(1)) : $(SRCDIR
)/$(2)
301 # Add several patches at once
303 # gb_UnpackedTarball_add_patches unpacked patch(es)
304 define gb_UnpackedTarball_add_patches
305 $(foreach patch
,$(2),$(call gb_UnpackedTarball_add_patch
,$(1),$(patch
)))
309 # Add a file from source dir to the unpacked dir
311 # This function should not be used for overwriting existing files--use a
312 # patch for that purpose.
314 # gb_UnpackedTarball_add_file unpacked destfile file
315 define gb_UnpackedTarball_add_file
316 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_FILES
+= $(SRCDIR
)/$(3)
317 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_DESTFILES
+= $(call gb_UnpackedTarball_get_dir
,$(1))/$(2)
318 $(call gb_UnpackedTarball_get_preparation_target
,$(1)) : $(SRCDIR
)/$(3)
322 # Add several files(s) from source dir to the unpacked dir
324 # The files are added into the specified subdir.
326 # gb_UnpackedTarball_add_files unpacked subdir file(s)
327 define gb_UnpackedTarball_add_files
328 $(foreach file
,$(3),$(call gb_UnpackedTarball_add_file
,$(1),$(2)/$(notdir $(file
)),$(file
)))
332 # Set arbitrary shell command to be run during unpack
334 # The command is run at the very beginning, in freshly unpacked tarball.
335 # The command is run in the unpacked directory. If more than one command
336 # is used, care should be taken that the whole command fails if either
337 # of the sub-commands fails.
339 # gb_UnpackedTarball_set_pre_action unpacked shell-command
340 define gb_UnpackedTarball_set_pre_action
341 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_PRE_ACTION
:= $(strip $(2))
345 # Set arbitrary shell command to be run during unpack
347 # The command is run at the very end: after patching, C++ extension
348 # mangling and copying additional files in. The command is run in the
349 # unpacked directory. If more than one command is used, care should be
350 # taken that the whole command fails if either of the sub-commands
353 # NOTE: This is a bit hackish, but it is the easiest way to move files
354 # around or delete files (typically because the file causes build
355 # problems in the original location, c.f. clucene). This is doable by
356 # using -E with patch (we use GNU patch anyway), but it would mean an
357 # additional patch to maintain...
359 # gb_UnpackedTarball_set_post_action unpacked shell-command
360 define gb_UnpackedTarball_set_post_action
361 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_POST_ACTION
:= $(strip $(2))
365 define gb_UnpackedTarbal__make_pattern_rule
366 $(call gb_UnpackedTarball_get_dir
,$(1))/%$(2) :
367 $$(if
$$(wildcard $$@
),,$$(call gb_Output_error
,file
$$@ does not exist in the tarball
))
368 $$(if
$$(UNPACKED_MODE
),chmod
$$(UNPACKED_MODE
) $$@
&&) \
371 $(eval gb_UnpackedTarball_PATTERN_RULES_
$(1) += $(2))
375 define gb_UnpackedTarbal__ensure_pattern_rule
376 $(if
$(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_
$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule
,$(1),$(2)))
380 define gb_UnpackedTarbal__make_file_rule
381 $(call gb_UnpackedTarball_get_dir
,$(1))/$(2) :
382 $$(if
$$(wildcard $$@
),,$$(call gb_Output_error
,file
$$@ does not exist in the tarball
))
383 $$(if
$$(UNPACKED_MODE
),chmod
$$(UNPACKED_MODE
) $$@
&&) \
388 # Mark a source file to be used outside of this module
390 # This results in the timestamp of the file being updated, so a possible
391 # change is recognized properly by other files depending on it. The
392 # update is run after possible post action.
394 # See description of class ExternalPackage for more information.
396 # gb_UnpackedTarball_mark_output_file unpacked file
397 define gb_UnpackedTarball_mark_output_file
398 $(call gb_UnpackedTarball_get_final_target
,$(1)) : $(call gb_UnpackedTarball_get_dir
,$(1))/$(2)
399 $(call gb_UnpackedTarball_get_dir
,$(1))/$(2) : $(call gb_UnpackedTarball_get_target
,$(1))
400 $(call gb_UnpackedTarball_get_dir
,$(1))/$(2) : UNPACKED_MODE
:= 644
401 $(if
$(suffix $(2)),\
402 $(call gb_UnpackedTarbal__ensure_pattern_rule
,$(1),$(suffix $(2))),\
403 $(call gb_UnpackedTarbal__make_file_rule
,$(1),$(2)) \
408 # Mark several source files to be used outside of this module
410 # gb_UnpackedTarball_mark_output_files unpacked file(s)
411 define gb_UnpackedTarball_mark_output_files
412 $(foreach file
,$(2),$(call gb_UnpackedTarball_mark_output_file
,$(1),$(file
)))
416 # Replace project's config.{guess,sub} files by internal copies
418 # This is useful if the project's config files are outdated and don't
419 # allow build on some new arch. The internal copies are located at
420 # gb_UnpackedTarball_CONFIGDIR.
422 # If the configs are placed somewhere else than in the top-level dir of
423 # the project, pass the (relative) dir as second argument. (It can even
424 # be a list of dirs, if the project contains multiple subprojects, each
425 # with its own configure.)
427 # gb_UnpackedTarball_update_autoconf_configs unpacked dirs(s)?
428 define gb_UnpackedTarball_update_autoconf_configs
429 $(call gb_UnpackedTarball_get_target
,$(1)) : UNPACKED_CONFIG_DIRS
+= $(if
$(strip $(2)),$(2),.
)
433 # force the rebuild of an external target
434 # this only works when running as partial build.
437 if
[ -f
$(call gb_UnpackedTarball_get_target
,$*) ] ; then \
438 touch
$(call gb_UnpackedTarball_get_target
,$*) ; \
443 if
[ -d
$(call gb_UnpackedTarball_get_dir
,$*) -a
-d
$(call gb_UnpackedTarball_get_pristine_dir
,$*) ] ; then \
445 patch_file
=$$(pwd
)/$*.new.patch
.1; \
446 cd
$(call gb_UnpackedTarball_get_dir
,) ; \
447 diff
-ur
$*.org
$* > $$patch_file; \
448 echo
"Patch $$patch_file generated" ; \
451 echo
"Error: No pristine tarball available for $*" 1>&2 ; \
455 # vim: set noet sw=4 ts=4: