xref: /aoo42x/main/solenv/gbuild/Zip.mk (revision b63233d8)
1###############################################################
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20###############################################################
21
22
23
24# Zip class
25
26gb_Zip_ZIPCOMMAND := zip
27
28# remove zip file in workdir and outdir
29$(call gb_Zip_get_clean_target,%) :
30	$(call gb_Output_announce,$*,$(false),ZIP,3)
31	$(call gb_Helper_abbreviate_dirs,\
32		rm -f $(call gb_Zip_get_target,$*) && \
33		rm -f $(call gb_Zip_get_final_target,$*) && \
34		rm -f $(call gb_Zip_get_outdir_target,$*))
35
36# rule to create zip package in workdir
37# -FS 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_Helper_abbreviate_dirs_native,\
40	mkdir -p $(dir $(call gb_Zip_get_target,$*)) && \
41	cd $(LOCATION) && $(gb_Zip_ZIPCOMMAND) -rX -FS $(call gb_Zip_get_target,$*) $(FILES) )
42
43# the final target is a touch target; we use it as registered targets should be in workdir, not in outdir
44# the outdir target depends on the workdir target and is built by delivering the latter
45# the workdir target is created by cd'ing to the target directory and adding/updating the files
46$(call gb_Zip_get_final_target,%) : $(call gb_Zip_get_outdir_target,%)
47	touch $@
48
49# clear file list, set location (zipping uses relative paths)
50# register target and clean target
51# add deliverable
52# add dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
53# the zip package target requires that all added files have a common root directory (package location)
54# names of added files are relative to it; the zip will store them with their complete relative path name
55# the location can't be stored in a scoped variable as it is needed in the add_file macro (see rule above)
56define gb_Zip_Zip
57$(call gb_Zip_get_target,$(1)) : FILES :=
58$(call gb_Zip_get_target,$(1)) : LOCATION := $(2)
59gb_Package_Location_$(1) := $(2)
60$(eval $(call gb_Module_register_target,$(call gb_Zip_get_final_target,$(1)),$(call gb_Zip_get_clean_target,$(1))))
61$(call gb_Deliver_add_deliverable,$(call gb_Zip_get_outdir_target,$(1)),$(call gb_Zip_get_target,$(1)),$(1))
62$(call gb_Zip_get_outdir_target,$(1)) : $(call gb_Zip_get_target,$(1))
63
64endef
65
66# adding a file creates a dependency to it
67# the full path name of the file needs access to the package location
68# as scoped variables only exist in rules, we use a postfixed name to refer to the location
69define gb_Zip_add_file
70$(call gb_Zip_get_target,$(1)) : FILES += $(2)
71$(call gb_Zip_get_target,$(1)) : $(gb_Package_Location_$(1))/$(2)
72
73endef
74
75define gb_Zip_add_files
76$(foreach file,$(2),$(call gb_Zip_add_file,$(1),$(file)))
77endef
78
79# vim: set noet sw=4 ts=4:
80