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