bump product version to 7.2.5.1
[LibreOffice.git] / solenv / gbuild / Zip.mk
blob673a02df137040ba965df6110bfb238d595e1042
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 $(if $(CLEAR_LOCATION),rm -rf $(gb_Package_Location_$*) &&) \
31 $(if $(INSTALL_NAME),rm -f $(INSTALL_NAME) &&) \
32 rm -f $(call gb_Zip_get_target,$*) && \
33 rm -f $(call gb_Zip__get_preparation_target,$*))
35 $(dir $(call gb_Zip_get_target,%)).dir :
36 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
38 $(dir $(call gb_Zip_get_target,%))%/.dir :
39 $(if $(wildcard $(dir $@)),,mkdir -p $(dir $@))
41 # rule to create zip package in workdir
42 # --filesync makes sure that all files in the zip package will be removed that no longer are in $(FILES)
43 # if there are no files, zip fails; copy empty zip file to target in that case
44 $(call gb_Zip_get_target,%) :
45 $(call gb_Output_announce,$*,$(true),ZIP,3)
46 $(call gb_Trace_StartRange,$*,ZIP)
47 $(call gb_Helper_abbreviate_dirs,\
48 $(if $(FILES),\
49 RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),500,\
50 $(FILES)) && \
51 cd $(LOCATION) && \
52 cat $${RESPONSEFILE} | tr "[:space:]" "\n" | \
53 $(gb_Zip_ZIPCOMMAND) -@rX --filesync --must-match \
54 $(call gb_Zip_get_target,$*) && \
55 rm -f $${RESPONSEFILE} && \
56 touch $@\
57 , cp $(SRCDIR)/solenv/gbuild/empty.zip $@)\
58 $(if $(INSTALL_NAME),&& cp $(call gb_Zip_get_target,$*) $(INSTALL_NAME)) \
60 $(call gb_Trace_EndRange,$*,ZIP)
62 # the preparation target is here to ensure proper ordering of actions in cases
63 # when we want to, e.g., create a zip from files created by a custom target
64 $(call gb_Zip__get_preparation_target,%) :
65 touch $@
67 # clear file list, set location (zipping uses relative paths)
68 # register target and clean target
69 # add deliverable
70 # add dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
71 # the zip package target requires that all added files have a common root directory (package location)
72 # names of added files are relative to it; the zip will store them with their complete relative path name
73 # the location can't be stored in a scoped variable as it is needed in the add_file macro (see rule above)
74 define gb_Zip_Zip_internal_nodeliver
75 $(call gb_Zip_get_target,$(1)) : FILES :=
76 $(call gb_Zip_get_target,$(1)) : INSTALL_NAME :=
77 $(call gb_Zip_get_target,$(1)) : LOCATION := $(2)
78 $(call gb_Zip_get_target,$(1)) :| $(dir $(call gb_Zip_get_target,$(1))).dir
79 $(call gb_Zip__get_preparation_target,$(1)) :| $(dir $(call gb_Zip__get_preparation_target,$(1))).dir
80 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION :=
81 $(call gb_Zip_get_clean_target,$(1)) : INSTALL_NAME :=
82 $(eval gb_Package_Location_$(1) := $(2))
84 endef
86 define gb_Zip_Zip_internal
87 $(call gb_Zip_Zip_internal_nodeliver,$(1),$(2))
89 endef
91 # depend on makefile to enforce a rebuild if files are removed from the zip
92 define gb_Zip_Zip
93 $(call gb_Zip_Zip_internal,$(1),$(2))
94 $(call gb_Zip_get_target,$(1)) : $(gb_Module_CURRENTMAKEFILE)
96 $(eval $(call gb_Module_register_target,$(call gb_Zip_get_target,$(1)),$(call gb_Zip_get_clean_target,$(1))))
97 $(call gb_Helper_make_userfriendly_targets,$(1),Zip,$(call gb_Zip_get_target,$(1)))
99 endef
101 # adding a file creates a dependency to it
102 # the full path name of the file needs access to the package location
103 # as scoped variables only exist in rules, we use a postfixed name to refer to the location
105 # if package location is in $(WORKDIR) we can specify third parameter and copy file from different place
106 # then we need also remove the location on make clean
107 define gb_Zip_add_file
108 $(call gb_Zip_get_target,$(1)) : FILES += $(2)
109 $(call gb_Zip_get_target,$(1)) : $(gb_Package_Location_$(1))/$(2)
110 $(gb_Package_Location_$(1))/$(2) :| $(call gb_Zip__get_preparation_target,$(1))
111 ifneq ($(3),)
112 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION := TRUE
113 $(gb_Package_Location_$(1))/$(2) : $(3)
114 mkdir -p $$(dir $$@)
115 cp -f $$< $$@
117 endif
119 endef
121 # add additional dependency that must exist before the archive can be created
122 define gb_Zip_add_dependency
123 $(call gb_Zip__get_preparation_target,$(1)) :| $(2)
125 endef
127 define gb_Zip_add_files
128 $(foreach file,$(2),$(call gb_Zip_add_file,$(1),$(file)))
129 endef
131 define gb_Zip_add_dependencies
132 $(foreach dependency,$(2),$(call gb_Zip_add_dependency,$(1),$(dependency)))
134 endef
136 define gb_Zip_add_commandoptions
137 $(call gb_Zip_get_target,$(1)) : gb_Zip_ZIPCOMMAND += $(2)
139 endef
141 define gb_Zip_set_install_name
142 $(call gb_Zip_get_target,$(1)) : INSTALL_NAME := $(2)
143 $(call gb_Zip_get_target,$(1)) :| $(dir $(2)).dir
144 $(call gb_Zip_get_clean_target,$(1)) : INSTALL_NAME := $(2)
146 endef
148 define gb_Zip_use_unpacked
149 $(call gb_Zip__get_preparation_target,$(1)) \
150 :| $(call gb_UnpackedTarball_get_final_target,$(2))
152 endef
154 # vim: set noet sw=4 ts=4: