Home | History | Annotate | Download | only in tasks
      1 # Copyright (C) 2009 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 
     16 # If they didn't define PRODUCT_SDK_ADDON_NAME, then we won't define
     17 # any of these rules.
     18 addon_name := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_NAME))
     19 ifneq ($(addon_name),)
     20 
     21 addon_dir_leaf  := $(addon_name)-$(FILE_NAME_TAG)-$(INTERNAL_SDK_HOST_OS_NAME)
     22 addon_dir_img   := $(addon_dir_leaf)-img
     23 intermediates   := $(HOST_OUT_INTERMEDIATES)/SDK_ADDON/$(addon_name)_intermediates
     24 full_target     := $(HOST_OUT_SDK_ADDON)/$(addon_dir_leaf).zip
     25 full_target_img := $(HOST_OUT_SDK_ADDON)/$(addon_dir_img).zip
     26 staging         := $(intermediates)
     27 
     28 sdk_addon_deps :=
     29 files_to_copy :=
     30 
     31 define stub-addon-jar-file
     32 $(subst .jar,_stub-addon.jar,$(1))
     33 endef
     34 
     35 define stub-addon-jar
     36 $(call stub-addon-jar-file,$(1)): $(1) | mkstubs
     37 	$(info Stubbing addon jar using $(PRODUCT_SDK_ADDON_STUB_DEFS))
     38 	$(hide) $(JAVA) -jar $(call module-installed-files,mkstubs) $(if $(hide),,--v) \
     39 		"$$<" "$$@" @$(PRODUCT_SDK_ADDON_STUB_DEFS)
     40 endef
     41 
     42 # Files that are built and then copied into the sdk-addon
     43 ifneq ($(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_MODULES)),)
     44 $(foreach cf,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_MODULES), \
     45   $(eval _src := $(call module-stubs-files,$(call word-colon,1,$(cf)))) \
     46   $(eval $(call stub-addon-jar,$(_src))) \
     47   $(eval _src := $(call stub-addon-jar-file,$(_src))) \
     48   $(if $(_src),,$(eval $(error Unknown or unlinkable module: $(call word-colon,1,$(cf)). Requested by $(INTERNAL_PRODUCT)))) \
     49   $(eval _dest := $(call word-colon,2,$(cf))) \
     50   $(eval files_to_copy += $(addon_dir_leaf):$(_src):$(_dest)) \
     51  )
     52 endif
     53 
     54 # Files that are copied directly into the sdk-addon
     55 ifneq ($(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_FILES)),)
     56 $(foreach cf,$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_COPY_FILES), \
     57   $(eval _src  := $(call word-colon,1,$(cf))) \
     58   $(eval _dest := $(call word-colon,2,$(cf))) \
     59   $(if $(findstring images/,$(_dest)), $(eval _root := $(addon_dir_img)), $(eval _root := $(addon_dir_leaf))) \
     60   $(eval files_to_copy += $(_root):$(_src):$(_dest)) \
     61  )
     62 endif
     63 
     64 # Files copied in the system-image directory
     65 files_to_copy += \
     66 	$(addon_dir_img):$(INSTALLED_QEMU_SYSTEMIMAGE):images/$(TARGET_CPU_ABI)/system.img \
     67 	$(addon_dir_img):$(INSTALLED_QEMU_VENDORIMAGE):images/$(TARGET_CPU_ABI)/vendor.img \
     68 	$(addon_dir_img):$(BUILT_RAMDISK_TARGET):images/$(TARGET_CPU_ABI)/ramdisk.img \
     69 	$(addon_dir_img):$(PRODUCT_OUT)/system/build.prop:images/$(TARGET_CPU_ABI)/build.prop \
     70 	$(addon_dir_img):$(target_notice_file_txt):images/$(TARGET_CPU_ABI)/NOTICE.txt \
     71 	$(addon_dir_img):$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP):images/source.properties
     72 
     73 # Generate rules to copy the requested files
     74 $(foreach cf,$(files_to_copy), \
     75   $(eval _root := $(call word-colon,1,$(cf))) \
     76   $(eval _src  := $(call word-colon,2,$(cf))) \
     77   $(eval _dest := $(call append-path,$(call append-path,$(staging),$(_root)),$(call word-colon,3,$(cf)))) \
     78   $(eval $(call copy-one-file,$(_src),$(_dest))) \
     79   $(eval sdk_addon_deps += $(_dest)) \
     80  )
     81 
     82 # The system-image source.properties is a template that we directly expand in-place
     83 addon_img_source_prop := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)/source.properties
     84 sdk_addon_deps += $(addon_img_source_prop)
     85 
     86 $(addon_img_source_prop): $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_SYS_IMG_SOURCE_PROP)
     87 	@echo Generate $@
     88 	$(hide) mkdir -p $(dir $@)
     89 	$(hide) sed \
     90 		-e 's/$${PLATFORM_VERSION}/$(PLATFORM_VERSION)/' \
     91 		-e 's/$${PLATFORM_SDK_VERSION}/$(PLATFORM_SDK_VERSION)/' \
     92 		-e 's/$${PLATFORM_VERSION_CODENAME}/$(subst REL,,$(PLATFORM_VERSION_CODENAME))/' \
     93 		-e 's/$${TARGET_ARCH}/$(TARGET_ARCH)/' \
     94 		-e 's/$${TARGET_CPU_ABI}/$(TARGET_CPU_ABI)/' \
     95 		$< > $@ && sed -i -e '/^AndroidVersion.CodeName=\s*$$/d' $@
     96 
     97 
     98 # We don't know about all of the docs files, so depend on the timestamps for
     99 # them, and record the directories, and the packaging rule will just copy the
    100 # whole thing.
    101 doc_modules := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SDK_ADDON_DOC_MODULES))
    102 sdk_addon_deps += $(foreach dm, $(doc_modules), $(call doc-timestamp-for, $(dm)))
    103 $(full_target): PRIVATE_DOCS_DIRS := $(addprefix $(OUT_DOCS)/, $(doc_modules))
    104 
    105 $(full_target): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_leaf))
    106 
    107 $(full_target): $(sdk_addon_deps) | $(ACP) $(SOONG_ZIP)
    108 	@echo Packaging SDK Addon: $@
    109 	$(hide) mkdir -p $(PRIVATE_STAGING_DIR)/docs
    110 	$(hide) for d in $(PRIVATE_DOCS_DIRS); do \
    111 	    $(ACP) -r $$d $(PRIVATE_STAGING_DIR)/docs ;\
    112 	  done
    113 	$(hide) mkdir -p $(dir $@)
    114 	$(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR)
    115 
    116 $(full_target_img): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI)
    117 $(full_target_img): $(full_target) $(addon_img_source_prop) | $(ACP) $(SOONG_ZIP)
    118 	@echo Packaging SDK Addon System-Image: $@
    119 	$(hide) mkdir -p $(dir $@)
    120 	$(ACP) -r $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR)/data
    121 	$(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR)
    122 
    123 
    124 .PHONY: sdk_addon
    125 sdk_addon: $(full_target) $(full_target_img)
    126 
    127 ifneq ($(sdk_repo_goal),)
    128 # If we're building the sdk_repo, keep the name of the addon zip
    129 # around so that development/build/tools/sdk_repo.mk can dist it
    130 # at the appropriate location.
    131 ADDON_SDK_ZIP        := $(full_target)
    132 ADDON_SDK_IMG_ZIP    := $(full_target_img)
    133 else
    134 # When not building an sdk_repo, just dist the addon zip file
    135 # as-is.
    136 $(call dist-for-goals, sdk_addon, $(full_target))
    137 endif
    138 
    139 else # addon_name
    140 ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
    141 $(error Trying to build sdk_addon, but product '$(INTERNAL_PRODUCT)' does not define one)
    142 endif
    143 endif # addon_name
    144