bump product version to 4.1.6.2
[LibreOffice.git] / solenv / gbuild / Zip.mk
blob8fd7706be43845d53ca9178c3fee335945414059
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/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 # Zip class
22 gb_Zip__get_preparation_target = $(WORKDIR)/Zip/$(1).prepare
24 gb_Zip_ZIPCOMMAND := zip $(if $(findstring s,$(MAKEFLAGS)),-q)
26 # remove zip file in workdir and outdir
27 $(call gb_Zip_get_clean_target,%) :
28 $(call gb_Output_announce,$*,$(false),ZIP,3)
29 $(call gb_Helper_abbreviate_dirs,\
30 rm -f $(call gb_Zip_get_target,$*) && \
31 rm -f $(call gb_Zip__get_preparation_target,$*) && \
32 rm -f $(call gb_Zip_get_final_target,$*) && \
33 $(if $(CLEAR_LOCATION),rm -rf $(gb_Package_Location_$*) &&) \
34 rm -f $(call gb_Zip_get_outdir_target,$*))
36 # rule to create zip package in workdir
37 # --filesync makes sure that all files in the zip package will be removed that no longer are in $(FILES)
38 $(call gb_Zip_get_target,%) :
39 $(call gb_Output_announce,$*,$(true),ZIP,3)
40 $(call gb_Helper_abbreviate_dirs,\
41 RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),500,\
42 $(FILES)) && \
43 mkdir -p $(dir $(call gb_Zip_get_target,$*)) && \
44 cd $(LOCATION) && cat $${RESPONSEFILE} | tr "[:space:]" "\n" | $(gb_Zip_ZIPCOMMAND) -@rX --filesync --must-match $(call gb_Zip_get_target,$*) && \
45 rm -f $${RESPONSEFILE} )
47 # the final target is a touch target; we use it as registered targets should be in workdir, not in outdir
48 # the outdir target depends on the workdir target and is built by delivering the latter
49 # the workdir target is created by cd'ing to the target directory and adding/updating the files
50 $(call gb_Zip_get_final_target,%) : $(call gb_Zip_get_outdir_target,%)
51 touch $@
53 # the preparation target is here to ensure proper ordering of actions in cases
54 # when we want to, e.g., create a zip from files created by a custom target
55 $(call gb_Zip__get_preparation_target,%) :
56 $(call gb_Helper_abbreviate_dirs,\
57 mkdir -p $(dir $@) && touch $@)
59 # clear file list, set location (zipping uses relative paths)
60 # register target and clean target
61 # add deliverable
62 # add dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
63 # the zip package target requires that all added files have a common root directory (package location)
64 # names of added files are relative to it; the zip will store them with their complete relative path name
65 # the location can't be stored in a scoped variable as it is needed in the add_file macro (see rule above)
66 define gb_Zip_Zip_internal_nodeliver
67 $(call gb_Zip_get_target,$(1)) : FILES :=
68 $(call gb_Zip_get_target,$(1)) : LOCATION := $(2)
69 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION :=
70 $(eval gb_Package_Location_$(1) := $(2))
72 endef
74 define gb_Zip_Zip_internal
75 $(call gb_Zip_Zip_internal_nodeliver,$(1),$(2))
77 $(call gb_Deliver_add_deliverable,$(call gb_Zip_get_outdir_target,$(1)),$(call gb_Zip_get_target,$(1)),$(1))
78 $(call gb_Zip_get_outdir_target,$(1)) : $(call gb_Zip_get_target,$(1)) \
79 | $(dir $(call gb_Zip_get_outdir_target,$(1))).dir
81 endef
83 # depend on makefile to enforce a rebuild if files are removed from the zip
84 define gb_Zip_Zip
85 $(call gb_Zip_Zip_internal,$(1),$(2))
86 $(call gb_Zip_get_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
88 $(eval $(call gb_Module_register_target,$(call gb_Zip_get_final_target,$(1)),$(call gb_Zip_get_clean_target,$(1))))
89 $(call gb_Helper_make_userfriendly_targets,$(1),Zip,$(call gb_Zip_get_final_target,$(1)))
91 endef
93 # adding a file creates a dependency to it
94 # the full path name of the file needs access to the package location
95 # as scoped variables only exist in rules, we use a postfixed name to refer to the location
97 # if package location is in $(WORKDIR) we can specify third parameter and copy file from different place
98 # then we need also remove the location on make clean
99 define gb_Zip_add_file
100 $(call gb_Zip_get_target,$(1)) : FILES += $(2)
101 $(call gb_Zip_get_target,$(1)) : $(gb_Package_Location_$(1))/$(2)
102 $(gb_Package_Location_$(1))/$(2) :| $(call gb_Zip__get_preparation_target,$(1))
103 ifneq ($(3),)
104 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION := TRUE
105 $(gb_Package_Location_$(1))/$(2) : $(3)
106 mkdir -p $$(dir $$@)
107 cp -f $$< $$@
109 endif
111 endef
113 # add additional dependency that must exist before the archive can be created
114 define gb_Zip_add_dependency
115 $(call gb_Zip__get_preparation_target,$(1)) :| $(2)
117 endef
119 define gb_Zip_add_files
120 $(foreach file,$(2),$(call gb_Zip_add_file,$(1),$(file)))
121 endef
123 define gb_Zip_add_dependencies
124 $(foreach dependency,$(2),$(call gb_Zip_add_dependency,$(1),$(dependency)))
126 endef
128 define gb_Zip_add_commandoptions
129 $(call gb_Zip_get_target,$(1)) : gb_Zip_ZIPCOMMAND += $(2)
131 endef
133 define gb_Zip_use_unpacked
134 $(call gb_Zip__get_preparation_target,$(1)) \
135 :| $(call gb_UnpackedTarball_get_final_target,$(2))
137 endef
139 # vim: set noet sw=4 ts=4: