package-modules.mk revision 03270b97ca8fac50641c6fad7b603652cbb323c9
1# 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.
19# If for 1 module name we found multiple installed files,
20# we use suffix matching to find the corresponding built file.
21$(foreach m,$(my_modules),\
22  $(if $(ALL_MODULES.$(m).INSTALLED),,\
23    $(warning Unknown installed file for module '$(m)'))\
24  $(eval my_pickup_files += $(ALL_MODULES.$(m).PICKUP_FILES))\
25  $(foreach i,$(filter $(TARGET_OUT_ROOT)/%,$(ALL_MODULES.$(m).INSTALLED)),\
26    $(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)))\
31    $(if $(filter 1,$(words $(b))),\
32      $(eval my_built_modules += $(b))\
33      $(eval my_copy_dest := $(patsubst data/%,DATA/%,\
34                               $(patsubst system/%,DATA/%,\
35                                 $(patsubst $(PRODUCT_OUT)/%,%,$(i)))))\
36      $(eval my_copy_pairs += $(b):$(my_staging_dir)/$(my_copy_dest)),\
37      $(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 $@) *
53