factory_ramdisk.mk revision 9d5e83d331a3bb39da65e7e376ed779a0fc28d21
1#
2# Copyright (C) 2011 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17ifneq (,$(ONE_SHOT_MAKEFILE))
18
19# PRODUCT_FACTORY_RAMDISK_MODULES consists of "<module_name>:<install_path>[:<install_path>...]" tuples.
20# <install_path> is relative to TARGET_FACTORY_RAMDISK_OUT.
21# We can have multiple <install_path>s because multiple modules may have the same name.
22# For example:
23# PRODUCT_FACTORY_RAMDISK_MODULES := \
24#     toolbox:system/bin/toolbox adbd:sbin/adbd adb:system/bin/adb
25factory_ramdisk_modules := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_FACTORY_RAMDISK_MODULES))
26ifneq (,$(factory_ramdisk_modules))
27
28# A module name may end up in multiple modules (so multiple built files)
29# with the same name.
30# This function selects the module built file based on the install path.
31# $(1): the dest install path
32# $(2): the module built files
33define install-one-factory-ramdisk-module
34$(eval _iofrm_suffix := $(suffix $(1))) \
35$(if $(_iofrm_suffix), \
36    $(eval _iofrm_pattern := %$(_iofrm_suffix)), \
37    $(eval _iofrm_pattern := %$(notdir $(1)))) \
38$(eval _iofrm_src := $(filter $(_iofrm_pattern),$(2))) \
39$(if $(filter 1,$(words $(_iofrm_src))), \
40    $(eval _fulldest := $(TARGET_FACTORY_RAMDISK_OUT)/$(1)) \
41    $(eval $(call copy-one-file,$(_iofrm_src),$(_fulldest))) \
42    $(eval INTERNAL_FACTORY_RAMDISK_EXTRA_MODULES_FILES += $(_fulldest)), \
43    $(error Error: Can not find match in "$(2)" for "$(1)") \
44    )
45endef
46
47INTERNAL_FACTORY_RAMDISK_EXTRA_MODULES_FILES :=
48$(foreach m, $(factory_ramdisk_modules), \
49    $(eval _fr_m_tuple := $(subst :, ,$(m))) \
50    $(eval _fr_m_name := $(word 1,$(_fr_m_tuple))) \
51    $(eval _fr_dests := $(wordlist 2,999,$(_fr_m_tuple))) \
52    $(eval _fr_m_built := $(filter $(PRODUCT_OUT)/%, $(ALL_MODULES.$(_fr_m_name).BUILT))) \
53    $(foreach d,$(_fr_dests),$(call install-one-factory-ramdisk-module,$(d),$(_fr_m_built))) \
54    )
55endif
56
57# Files may also be installed via PRODUCT_COPY_FILES, PRODUCT_PACKAGES etc.
58INTERNAL_FACTORY_RAMDISK_FILES := $(filter $(TARGET_FACTORY_RAMDISK_OUT)/%, \
59    $(ALL_DEFAULT_INSTALLED_MODULES))
60
61ifneq (,$(INTERNAL_FACTORY_RAMDISK_EXTRA_MODULES_FILES)$(INTERNAL_FACTORY_RAMDISK_FILES))
62
63BUILT_FACTORY_RAMDISK_TARGET := $(PRODUCT_OUT)/factory_ramdisk.img
64
65INSTALLED_FACTORY_RAMDISK_TARGET := $(BUILT_FACTORY_RAMDISK_TARGET)
66$(INSTALLED_FACTORY_RAMDISK_TARGET) : $(MKBOOTFS) \
67    $(INTERNAL_FACTORY_RAMDISK_EXTRA_MODULES_FILES) $(INTERNAL_FACTORY_RAMDISK_FILES) | $(MINIGZIP)
68	$(call pretty,"Target factory ram disk: $@")
69	$(hide) $(MKBOOTFS) $(TARGET_FACTORY_RAMDISK_OUT) | $(MINIGZIP) > $@
70
71endif
72
73endif # ONE_SHOT_MAKEFILE
74