summaryrefslogtreecommitdiffstats
path: root/core/tasks/tools/package-modules.mk
blob: 83d59849e7bb4f78ccf5c2860f223224c2029041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Package up modules to a zip file.
# It preserves the install path of the modules' installed files.
#
# Input variables:
#   my_modules: a list of module names
#   my_package_name: the name of the output zip file.
# Output variables:
#   my_package_zip: the path to the output zip file.
#
#

my_staging_dir := $(call intermediates-dir-for,PACKAGING,$(my_package_name))
my_built_modules :=
my_copy_pairs :=
my_pickup_files :=

# Iterate over modules' built files and installed files;
# Calculate the dest files in the output zip file.

$(foreach m,$(my_modules),\
  $(if $(ALL_MODULES.$(m).BUILT_INSTALLED),,\
    $(warning Unknown installed file for module '$(m)'))\
  $(eval my_pickup_files += $(ALL_MODULES.$(m).PICKUP_FILES))\
  $(foreach i, $(ALL_MODULES.$(m).BUILT_INSTALLED),\
    $(eval bui_ins := $(subst :,$(space),$(i)))\
    $(eval ins := $(word 2,$(bui_ins)))\
    $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\
      $(eval bui := $(word 1,$(bui_ins)))\
      $(eval my_built_modules += $(bui))\
      $(eval my_copy_dest := $(patsubst data/%,DATA/%,\
                               $(patsubst system/%,DATA/%,\
                                 $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))))\
      $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\
  ))

my_package_zip := $(my_staging_dir)/$(my_package_name).zip
$(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
$(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files)
$(my_package_zip) : $(my_built_modules)
	@echo "Package $@"
	@rm -rf $(dir $@) && mkdir -p $(dir $@)
	$(hide) $(foreach p, $(PRIVATE_COPY_PAIRS), \
	  $(eval pair := $(subst :,$(space),$(p)))\
	  mkdir -p $(dir $(word 2,$(pair))); \
	  cp -rf $(word 1,$(pair)) $(word 2,$(pair));)
	$(hide) $(foreach f, $(PRIVATE_PICKUP_FILES), \
	  cp -rf $(f) $(dir $@);)
	$(hide) cd $(dir $@) && zip -rq $(notdir $@) *