Bump for 3.6-28
[LibreOffice.git] / solenv / gbuild / Zip.mk
blobf6d84f5d0d7e76b569adb7376cfd1982651a60f2
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 #
6 # Copyright 2000, 2011 Oracle and/or its affiliates.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # This file is part of OpenOffice.org.
12 # OpenOffice.org is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License version 3
14 # only, as published by the Free Software Foundation.
16 # OpenOffice.org is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Lesser General Public License version 3 for more details
20 # (a copy is included in the LICENSE file that accompanied this code).
22 # You should have received a copy of the GNU Lesser General Public License
23 # version 3 along with OpenOffice.org. If not, see
24 # <http://www.openoffice.org/license.html>
25 # for a copy of the LGPLv3 License.
27 #*************************************************************************
29 # Zip class
31 gb_Zip__get_preparation_target = $(WORKDIR)/Zip/$(1).prepare
33 gb_Zip_ZIPCOMMAND := zip $(if $(findstring s,$(MAKEFLAGS)),-q)
35 # remove zip file in workdir and outdir
36 $(call gb_Zip_get_clean_target,%) :
37 $(call gb_Output_announce,$*,$(false),ZIP,3)
38 $(call gb_Helper_abbreviate_dirs,\
39 rm -f $(call gb_Zip_get_target,$*) && \
40 rm -f $(call gb_Zip__get_preparation_target,$*) && \
41 rm -f $(call gb_Zip_get_final_target,$*) && \
42 $(if $(CLEAR_LOCATION),rm -rf $(gb_Package_Location_$*) &&) \
43 rm -f $(call gb_Zip_get_outdir_target,$*))
45 # rule to create zip package in workdir
46 # --filesync makes sure that all files in the zip package will be removed that no longer are in $(FILES)
47 $(call gb_Zip_get_target,%) :
48 $(call gb_Output_announce,$*,$(true),ZIP,3)
49 $(call gb_Helper_abbreviate_dirs,\
50 mkdir -p $(dir $(call gb_Zip_get_target,$*)) && \
51 cd $(LOCATION) && $(gb_Zip_ZIPCOMMAND) -rX --filesync $(call gb_Zip_get_target,$*) $(FILES) )
53 # the final target is a touch target; we use it as registered targets should be in workdir, not in outdir
54 # the outdir target depends on the workdir target and is built by delivering the latter
55 # the workdir target is created by cd'ing to the target directory and adding/updating the files
56 $(call gb_Zip_get_final_target,%) : $(call gb_Zip_get_outdir_target,%)
57 touch $@
59 # the preparation target is here to ensure proper ordering of actions in cases
60 # when we want to, e.g., create a zip from files created by a custom target
61 $(call gb_Zip__get_preparation_target,%) :
62 $(call gb_Helper_abbreviate_dirs,\
63 mkdir -p $(dir $@) && 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
73 $(call gb_Zip_get_target,$(1)) : FILES :=
74 $(call gb_Zip_get_target,$(1)) : LOCATION := $(2)
75 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION :=
76 gb_Package_Location_$(1) := $(2)
77 $(eval $(call gb_Module_register_target,$(call gb_Zip_get_final_target,$(1)),$(call gb_Zip_get_clean_target,$(1))))
78 $(call gb_Deliver_add_deliverable,$(call gb_Zip_get_outdir_target,$(1)),$(call gb_Zip_get_target,$(1)),$(1))
79 $(call gb_Zip_get_outdir_target,$(1)) : $(call gb_Zip_get_target,$(1)) \
80 | $(dir $(call gb_Zip_get_outdir_target,$(1))).dir
82 endef
84 # adding a file creates a dependency to it
85 # the full path name of the file needs access to the package location
86 # as scoped variables only exist in rules, we use a postfixed name to refer to the location
88 # if package location is in $(WORKDIR) we can specify third parameter and copy file from different place
89 # then we need also remove the location on make clean
90 define gb_Zip_add_file
91 $(call gb_Zip_get_target,$(1)) : FILES += $(2)
92 $(call gb_Zip_get_target,$(1)) : $(gb_Package_Location_$(1))/$(2)
93 $(gb_Package_Location_$(1))/$(2) :| $(call gb_Zip__get_preparation_target,$(1))
94 ifneq ($(3),)
95 $(call gb_Zip_get_clean_target,$(1)) : CLEAR_LOCATION := TRUE
96 $(gb_Package_Location_$(1))/$(2) : $(3)
97 mkdir -p $$(dir $$@)
98 cp -f $$< $$@
100 endif
102 endef
104 # add additional dependency that must exist before the archive can be created
105 define gb_Zip_add_dependency
106 $(call gb_Zip__get_preparation_target,$(1)) :| $(2)
108 endef
110 define gb_Zip_add_files
111 $(foreach file,$(2),$(call gb_Zip_add_file,$(1),$(file)))
112 endef
114 define gb_Zip_add_dependencies
115 $(foreach dependency,$(2),$(call gb_Zip_add_dependency,$(1),$(dependency)))
117 endef
119 define gb_Zip_add_commandoptions
120 $(call gb_Zip_get_target,$(1)) : gb_Zip_ZIPCOMMAND += $(2)
122 endef
124 # vim: set noet sw=4 ts=4: