Debian Codegraph @

solenv/gbuild/UnpackedTarball.mk

raw symbols SCIP
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
2 #
3 # This file is part of the LibreOffice project.
4 #
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/.
8 #
9
10 # UnpackedTarget class
11
12 # Handles unpacking of a tarball
13
14 # platform
15 # gb_UnpackedTarget_TARFILE_LOCATION
16 # NOTE: only for commands; targets should use TARFILE_LOCATION directly
17
18 # Location of internal copies of config.{guess,sub}.
19 gb_UnpackedTarball_CONFIGDIR := $(GBUILDDIR)
20
21 define gb_UnpackedTarget__command_untar
22 $(GNUTAR) \
23 -x \
24 $(3) \
25 -C $(UNPACKED_DIR) \
26 $(STRIP_COMPONENTS)=$(UNPACKED_STRIP_COMPONENTS) \
27 --no-same-owner \
28 -f $(call gb_Helper_cyg_path,$(UNPACKED_TARBALL))
29 endef
30
31 define gb_UnpackedTarget__command_unzip
32 unzip \
33 -qq \
34 -d $(UNPACKED_DIR) $(UNPACKED_TARBALL) \
35 $(if $(filter-out 0,$(UNPACKED_STRIP_COMPONENTS)),\
36 && UNZIP_DIR=`ls $(UNPACKED_DIR)` \
37 && mv $(UNPACKED_DIR)/$$UNZIP_DIR/* $(UNPACKED_DIR) \
38 && rm -rf $(UNPACKED_DIR)/$$UNZIP_DIR \
39 )
40 endef
41
42 define gb_UnpackedTarget__command
43 $(call gb_Output_announce,$(notdir $(2)),$(true),UPK,1)
44 $(call gb_Trace_StartRange,$(notdir $(2)),UPK)
45 $(call gb_Helper_abbreviate_dirs,\
46 $(if $(wildcard $(UNPACKED_DIR)),rm -rf $(UNPACKED_DIR) &&) \
47 mkdir -p $(UNPACKED_DIR) && \
48 $(call gb_UnpackedTarget__command_$(1),$(2),$(3),$(4)) && \
49 touch $(2) \
50 )
51 $(call gb_Trace_EndRange,$(notdir $(2)),UPK)
52 endef
53
54 $(dir $(call gb_UnpackedTarget_get_target,%)).dir :
55 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
56
57 $(call gb_UnpackedTarget_get_target,%).tar.bz2 :
58 $(call gb_UnpackedTarget__command,untar,$@,$*,-j)
59
60 $(call gb_UnpackedTarget_get_target,%).tar.xz :
61 $(call gb_UnpackedTarget__command,untar,$@,$*,-J)
62
63 $(call gb_UnpackedTarget_get_target,%).tar.gz :
64 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
65
66 $(call gb_UnpackedTarget_get_target,%).tgz :
67 $(call gb_UnpackedTarget__command,untar,$@,$*,-z)
68
69 $(call gb_UnpackedTarget_get_target,%).zip :
70 $(call gb_UnpackedTarget__command,unzip,$@,$*)
71
72 $(call gb_UnpackedTarget_get_target,%).oxt :
73 $(call gb_UnpackedTarget__command,unzip,$@,$*)
74
75 .PHONY : $(call gb_UnpackedTarget_get_clean_target,%)
76 $(call gb_UnpackedTarget_get_clean_target,%) :
77 $(call gb_Output_announce,$*,$(false),UPK,1)
78 $(call gb_Helper_abbreviate_dirs,\
79 rm -f $(call gb_UnpackedTarget_get_target,$*) \
80 )
81
82 # gb_UnpackedTarget_UnpackedTarget target outdir strip-components?
83 define gb_UnpackedTarget_UnpackedTarget
84 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_DIR := $(2)
85 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_TARBALL := $(gb_UnpackedTarget_TARFILE_LOCATION)/$(1)
86 $(call gb_UnpackedTarget_get_target,$(1)) : UNPACKED_STRIP_COMPONENTS := $(if $(strip $(3)),$(strip $(3)),1)
87
88 $(call gb_UnpackedTarget_get_target,$(1)) : $(TARFILE_LOCATION)/$(1)
89 $(call gb_UnpackedTarget_get_target,$(1)) :| $(dir $(call gb_UnpackedTarget_get_target,$(1))).dir
90
91 endef
92
93 # UnpackedTarball class
94
95 # Handles unpacking and patching of an external project
96 #
97 # The unpacked dir is recreated every time one of the patches, copied
98 # files or the makefile changes.
99
100 gb_UnpackedTarball_PATCHLEVEL_DEFAULT := 1
101
102 gb_UnpackedTarball_CONVERTTODOS = \
103 $(gb_AWK) 'sub("$$","\r")' $(1) > $(1).TEMP && mv $(1).TEMP $(1)
104 gb_UnpackedTarball_CONVERTTOUNIX = \
105 tr -d '\r' < $(1) > $(1).TEMP && mv $(1).TEMP $(1)
106
107 define gb_UnpackedTarball__copy_files_impl
108 $(if $(1),\
109 && cp $(firstword $(1)) $(firstword $(2)) \
110 $(call gb_UnpackedTarball__copy_files_impl,$(wordlist 2,$(words $(1)),$(1)),$(wordlist 2,$(words $(2)),$(2))) \
111 )
112 endef
113
114 # Drop leading &&
115 define gb_UnpackedTarball__copy_files_fix
116 $(wordlist 2,$(words $(1)),$(1))
117 endef
118
119 define gb_UnpackedTarball__copy_files
120 $(call gb_UnpackedTarball__copy_files_fix,$(call gb_UnpackedTarball__copy_files_impl,$(1),$(2)))
121 endef
122
123 define gb_UnpackedTarball__command
124 $(call gb_Helper_abbreviate_dirs,\
125 ( \
126 cd $(3) \
127 $(if $(UNPACKED_IS_BIN_TARBALL),,&& \
128 $(if $(UNPACKED_PRE_ACTION),\
129 $(UNPACKED_PRE_ACTION) && \
130 ) \
131 $(if $(UNPACKED_FILES),\
132 mkdir -p $(sort $(dir $(UNPACKED_DESTFILES))) && \
133 $(call gb_UnpackedTarball__copy_files,$(UNPACKED_FILES),$(UNPACKED_DESTFILES)) && \
134 ) \
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 && \
143 ) \
144 $(foreach file,$(UNPACKED_FIX_EOL),$(call gb_UnpackedTarball_CONVERTTODOS,$(file)) && ) \
145 $(foreach confdir,$(UNPACKED_CONFIG_DIRS),\
146 cp -f $(SRCDIR)/config.guess $(SRCDIR)/config.sub $(confdir) && \
147 ) \
148 $(if $(UNPACKED_POST_ACTION),\
149 $(UNPACKED_POST_ACTION) && \
150 ) \
151 $(if $(gb_KEEP_PRISTINE), \
152 rm -fr $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
153 cp -r -P $(gb_UnpackedTarball_workdir)/$(2) $(call gb_UnpackedTarball_get_pristine_dir,$(2)) && \
154 ) \
155 touch $(1) \
156 )\
157 ) || \
158 ( \
159 touch $(call gb_UnpackedTarball_get_preparation_target,$(2)) && \
160 exit 1 \
161 )
162 )
163 endef
164
165 $(dir $(call gb_UnpackedTarball_get_target,%)).dir :
166 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
167
168 $(call gb_UnpackedTarball_get_preparation_target,%) :
169 touch $@
170
171 $(call gb_UnpackedTarball_get_target,%) :
172 $(call gb_Output_announce,$*,$(true),PAT,2)
173 $(call gb_Trace_StartRange,$*,PAT)
174 $(call gb_UnpackedTarball__command,$@,$*,$(gb_UnpackedTarball_workdir)/$*)
175 $(call gb_Trace_EndRange,$*,PAT)
176
177 $(call gb_UnpackedTarball_get_final_target,%) :
178 touch $@
179
180 .PHONY : $(call gb_UnpackedTarball_get_clean_target,%)
181 $(call gb_UnpackedTarball_get_clean_target,%) :
182 $(call gb_Output_announce,$*,$(false),PAT,2)
183 $(call gb_Helper_abbreviate_dirs,\
184 rm -rf \
185 $(call gb_UnpackedTarball_get_final_target,$*) \
186 $(call gb_UnpackedTarball_get_target,$*) \
187 $(call gb_UnpackedTarball_get_preparation_target,$*) \
188 $(gb_UnpackedTarball_workdir)/$* \
189 $(call gb_UnpackedTarball_get_pristine_dir,$*) \
190 )
191
192 # Initialize unpacked tarball
193 define gb_UnpackedTarball_UnpackedTarball_internal
194 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES :=
195 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES :=
196 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FIX_EOL :=
197 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES :=
198 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(gb_UnpackedTarball_PATCHLEVEL_DEFAULT)
199 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS :=
200 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION :=
201 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION :=
202 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_CONFIG_DIRS :=
203
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))
209
210 private gb_UnpackedTarball_PATTERN_RULES_$(1) :=
211
212 endef
213
214 # Define a new unpacked tarball
215 define gb_UnpackedTarball_UnpackedTarball
216 $(call gb_UnpackedTarball_UnpackedTarball_internal,$(1))
217
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)))
220
221 endef
222
223 # Convert line ending from dos to unix style for selected files
224 #
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.
228 #
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 $(gb_UnpackedTarball_workdir)/$(1)/,$(2))
232
233 endef
234
235
236 # Internal version of set_tarball, mostly to avoid repeated invocation of $(shell
237 define gb_UnpackedTarball_set_tarball_internal
238 $(call gb_UnpackedTarget_UnpackedTarget,$(2),$(gb_UnpackedTarball_workdir)/$(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)) : $(TARFILE_LOCATION)/$(6)
246 $(TARFILE_LOCATION)/$(6) : $(call gb_Module_get_nonl10n_target,$(4))
247 $$(call gb_Output_announce,$(6),$(true),PKB,3)
248 $$(call gb_Trace_StartRange,$(6),PKB)
249 if test ! -f "$$@" ; then cd $(gb_UnpackedTarball_workdir)/ && $(GNUTAR) -czf "$$@" $(1)/ || $(GNUTAR) -czf "$$@" $(1)/ ; else touch "$$@" ; fi
250 $$(call gb_Trace_EndRange,$(6),PKB)
251 )
252
253 endef
254
255 # Set tarball name
256 #
257 # gb_UnpackedTarball_set_tarball unpacked tarball-name
258 define gb_UnpackedTarball_set_tarball
259 $(if $(USE_LIBRARY_BIN_TAR),
260 $(if $(4),
261 $(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)"),
262 $(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),\
263 $(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)")))
264 ,
265 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
266 )
267 ,
268 $(call gb_UnpackedTarball_set_tarball_internal,$(1),$(2),$(3),$(4),)
269 )
270
271 endef
272
273 # Set patch level to be used for all patches
274 #
275 # gb_UnpackedTarball_set_patchlevel unpacked level
276 define gb_UnpackedTarball_set_patchlevel
277 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHLEVEL := $(2)
278
279 endef
280
281 # Add patch flags to be passed to patch for all patches cf. fdo#66826
282 #
283 # gb_UnpackedTarball_set_patchlevel unpacked level
284 define gb_UnpackedTarball_set_patchflags
285 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHFLAGS := $(2)
286
287 endef
288
289 # Add a patch to be applied on the unpacked files
290 #
291 # gb_UnpackedTarball_add_patch unpacked patch
292 define gb_UnpackedTarball_add_patch
293 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PATCHES += $(SRCDIR)/$(2)
294 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(2)
295
296 endef
297
298 # Add several patches at once
299 #
300 # gb_UnpackedTarball_add_patches unpacked patch(es)
301 define gb_UnpackedTarball_add_patches
302 $(foreach patch,$(2),$(call gb_UnpackedTarball_add_patch,$(1),$(patch)))
303
304 endef
305
306 # Add a file from source dir to the unpacked dir
307 #
308 # This function should not be used for overwriting existing files--use a
309 # patch for that purpose.
310 #
311 # gb_UnpackedTarball_add_file unpacked destfile file
312 define gb_UnpackedTarball_add_file
313 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_FILES += $(SRCDIR)/$(3)
314 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_DESTFILES += $(gb_UnpackedTarball_workdir)/$(1)/$(2)
315 $(call gb_UnpackedTarball_get_preparation_target,$(1)) : $(SRCDIR)/$(3)
316
317 endef
318
319 # Add several files(s) from source dir to the unpacked dir
320 #
321 # The files are added into the specified subdir.
322 #
323 # gb_UnpackedTarball_add_files unpacked subdir file(s)
324 define gb_UnpackedTarball_add_files
325 $(foreach file,$(3),$(call gb_UnpackedTarball_add_file,$(1),$(2)/$(notdir $(file)),$(file)))
326
327 endef
328
329 # Set arbitrary shell command to be run during unpack
330 #
331 # The command is run at the very beginning, in freshly unpacked tarball.
332 # The command is run in the unpacked directory. If more than one command
333 # is used, care should be taken that the whole command fails if either
334 # of the sub-commands fails.
335 #
336 # gb_UnpackedTarball_set_pre_action unpacked shell-command
337 define gb_UnpackedTarball_set_pre_action
338 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_PRE_ACTION := $(strip $(2))
339
340 endef
341
342 # Set arbitrary shell command to be run during unpack
343 #
344 # The command is run at the very end: after patching, C++ extension
345 # mangling and copying additional files in. The command is run in the
346 # unpacked directory. If more than one command is used, care should be
347 # taken that the whole command fails if either of the sub-commands
348 # fails.
349 #
350 # NOTE: This is a bit hackish, but it is the easiest way to move files
351 # around or delete files (typically because the file causes build
352 # problems in the original location, c.f. clucene). This is doable by
353 # using -E with patch (we use GNU patch anyway), but it would mean an
354 # additional patch to maintain...
355 #
356 # gb_UnpackedTarball_set_post_action unpacked shell-command
357 define gb_UnpackedTarball_set_post_action
358 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_POST_ACTION := $(strip $(2))
359
360 endef
361
362 define gb_UnpackedTarbal__make_pattern_rule
363 $(gb_UnpackedTarball_workdir)/$(1)/%$(2) :
364 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
365 $$(if $$(UNPACKED_MODE),chmod $$(UNPACKED_MODE) $$@ &&) \
366 touch $$@
367
368 $(eval gb_UnpackedTarball_PATTERN_RULES_$(1) += $(2))
369
370 endef
371
372 define gb_UnpackedTarbal__ensure_pattern_rule
373 $(if $(filter $(2),$(gb_UnpackedTarball_PATTERN_RULES_$(1))),,$(call gb_UnpackedTarbal__make_pattern_rule,$(1),$(2)))
374
375 endef
376
377 define gb_UnpackedTarbal__make_file_rule
378 $(gb_UnpackedTarball_workdir)/$(1)/$(2) :
379 $$(if $$(wildcard $$@),,$$(call gb_Output_error,file $$@ does not exist in the tarball))
380 $$(if $$(UNPACKED_MODE),chmod $$(UNPACKED_MODE) $$@ &&) \
381 touch $$@
382
383 endef
384
385 # Mark a source file to be used outside of this module
386 #
387 # This results in the timestamp of the file being updated, so a possible
388 # change is recognized properly by other files depending on it. The
389 # update is run after possible post action.
390 #
391 # See description of class ExternalPackage for more information.
392 #
393 # gb_UnpackedTarball_mark_output_file unpacked file
394 define gb_UnpackedTarball_mark_output_file
395 $(call gb_UnpackedTarball_get_final_target,$(1)) : $(gb_UnpackedTarball_workdir)/$(1)/$(2)
396 $(gb_UnpackedTarball_workdir)/$(1)/$(2) : $(call gb_UnpackedTarball_get_target,$(1))
397 $(gb_UnpackedTarball_workdir)/$(1)/$(2) : UNPACKED_MODE := 644
398 $(if $(suffix $(2)),\
399 $(call gb_UnpackedTarbal__ensure_pattern_rule,$(1),$(suffix $(2))),\
400 $(call gb_UnpackedTarbal__make_file_rule,$(1),$(2)) \
401 )
402
403 endef
404
405 # Mark several source files to be used outside of this module
406 #
407 # gb_UnpackedTarball_mark_output_files unpacked file(s)
408 define gb_UnpackedTarball_mark_output_files
409 $(foreach file,$(2),$(call gb_UnpackedTarball_mark_output_file,$(1),$(file)))
410
411 endef
412
413 # Replace project's config.{guess,sub} files by internal copies
414 #
415 # This is useful if the project's config files are outdated and don't
416 # allow build on some new arch. The internal copies are located at
417 # gb_UnpackedTarball_CONFIGDIR.
418 #
419 # If the configs are placed somewhere else than in the top-level dir of
420 # the project, pass the (relative) dir as second argument. (It can even
421 # be a list of dirs, if the project contains multiple subprojects, each
422 # with its own configure.)
423 #
424 # gb_UnpackedTarball_update_autoconf_configs unpacked dirs(s)?
425 define gb_UnpackedTarball_update_autoconf_configs
426 $(call gb_UnpackedTarball_get_target,$(1)) : UNPACKED_CONFIG_DIRS += $(if $(strip $(2)),$(2),.)
427
428 endef
429
430 # force the rebuild of an external target
431 # this only works when running as partial build.
432 #
433 %.rebuild :
434 if [ -f $(call gb_UnpackedTarball_get_target,$*) ] ; then \
435 touch $(call gb_UnpackedTarball_get_target,$*) ; \
436 $(MAKE) ;\
437 fi
438
439 %.genpatch :
440 if [ -d $(gb_UnpackedTarball_workdir)/$* -a -d $(call gb_UnpackedTarball_get_pristine_dir,$*) ] ; then \
441 ( \
442 patch_file=$$(pwd)/$*.new.patch.1; \
443 cd $(gb_UnpackedTarball_workdir)/ ; \
444 diff -ur $*.org $* > $$patch_file; \
445 echo "Patch $$patch_file generated" ; \
446 ); \
447 else \
448 echo "Error: No pristine tarball available for $*" 1>&2 ; \
449 fi
450
451
452 # vim: set noet sw=4 ts=4: