blob: 890d26abf2b4e2055b092dce7bedbc3a162bd2f8 [file] [log] [blame]
Ying Wang3b81aab2014-05-05 16:46:52 -07001# Package up modules to a zip file.
2# It preserves the install path of the modules' installed files.
3#
4# Input variables:
5# my_modules: a list of module names
6# my_package_name: the name of the output zip file.
7# Output variables:
8# my_package_zip: the path to the output zip file.
9#
10#
11
12my_staging_dir := $(call intermediates-dir-for,PACKAGING,$(my_package_name))
13my_built_modules :=
14my_copy_pairs :=
15my_pickup_files :=
16
17# Search for modules' built files and installed files;
18# Calculate the dest files in the output zip file.
Ying Wang571fee82014-05-07 16:39:21 -070019# If for 1 module name we found multiple installed files,
20# we use suffix matching to find the corresponding built file.
Ying Wang3b81aab2014-05-05 16:46:52 -070021$(foreach m,$(my_modules),\
22 $(if $(ALL_MODULES.$(m).INSTALLED),,\
Ying Wang571fee82014-05-07 16:39:21 -070023 $(warning Unknown installed file for module '$(m)'))\
Ying Wang3b81aab2014-05-05 16:46:52 -070024 $(eval my_pickup_files += $(ALL_MODULES.$(m).PICKUP_FILES))\
25 $(foreach i,$(filter $(TARGET_OUT_ROOT)/%,$(ALL_MODULES.$(m).INSTALLED)),\
Ying Wang571fee82014-05-07 16:39:21 -070026 $(eval my_suffix := $(suffix $(i))) \
27 $(if $(my_suffix),\
28 $(eval my_patt := $(TARGET_OUT_ROOT)/%$(my_suffix)),\
29 $(eval my_patt := $(TARGET_OUT_ROOT)/%$(notdir $(i))))\
30 $(eval b := $(filter $(my_patt),$(ALL_MODULES.$(m).BUILT)))\
Ying Wang3b81aab2014-05-05 16:46:52 -070031 $(if $(filter 1,$(words $(b))),\
32 $(eval my_built_modules += $(b))\
Ying Wang571fee82014-05-07 16:39:21 -070033 $(eval my_copy_dest := $(patsubst data/%,DATA/%,\
Ying Wang92213a82014-05-15 20:45:39 -070034 $(patsubst system/%,DATA/%,\
Ying Wang571fee82014-05-07 16:39:21 -070035 $(patsubst $(PRODUCT_OUT)/%,%,$(i)))))\
36 $(eval my_copy_pairs += $(b):$(my_staging_dir)/$(my_copy_dest)),\
Ying Wang3b81aab2014-05-05 16:46:52 -070037 $(warning Unexpected module built file '$(b)' for module '$(m)'))\
38 ))
39
40my_package_zip := $(my_staging_dir)/$(my_package_name).zip
41$(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
42$(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files)
43$(my_package_zip) : $(my_built_modules)
44 @echo "Package $@"
45 @rm -rf $(dir $@) && mkdir -p $(dir $@)
46 $(hide) $(foreach p, $(PRIVATE_COPY_PAIRS), \
47 $(eval pair := $(subst :,$(space),$(p)))\
48 mkdir -p $(dir $(word 2,$(pair))); \
49 cp -rf $(word 1,$(pair)) $(word 2,$(pair));)
50 $(hide) $(foreach f, $(PRIVATE_PICKUP_FILES), \
51 cp -rf $(f) $(dir $@);)
52 $(hide) cd $(dir $@) && zip -rq $(notdir $@) *