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