1#
2# Copyright (C) 2018 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
17##### Input Variables:
18# LOCAL_MODULE: required. Module name for the build system.
19# LOCAL_MODULE_CLASS: optional. Default is ETC.
20# LOCAL_MODULE_PATH: optional. Path of output file. Default is $(TARGET_OUT)/etc/vintf.
21# LOCAL_MODULE_STEM: optional. Name of output file. Default is $(LOCAL_MODULE).
22# LOCAL_SRC_FILES: required. Local source files provided to assemble_vintf
23#       (command line argument -i).
24# LOCAL_GENERATED_SOURCES: optional. Global source files provided to assemble_vintf
25#       (command line argument -i).
26#
27# LOCAL_ADD_VBMETA_VERSION: Use AVBTOOL to add avb version to the output matrix
28#       (corresponds to <avb><vbmeta-version> tag)
29# LOCAL_ASSEMBLE_VINTF_ENV_VARS: Add a list of environment variable names from global variables in
30#       the build system that is lazily evaluated (e.g. PRODUCT_ENFORCE_VINTF_MANIFEST).
31# LOCAL_ASSEMBLE_VINTF_ENV_VARS_OVERRIDE: Add a list of environment variables that is local to
32#       assemble_vintf invocation. Format is "VINTF_ENFORCE_NO_UNUSED_HALS=true".
33# LOCAL_ASSEMBLE_VINTF_FLAGS: Add additional command line arguments to assemble_vintf invocation.
34# LOCAL_KERNEL_CONFIG_DATA_PATHS: Paths to search for kernel config requirements. Format for each is
35#       <kernel version x.y.z>:<path that contains android-base*.cfg>.
36# LOCAL_GEN_FILE_DEPENDENCIES: A list of additional dependencies for the generated file.
37
38ifndef LOCAL_MODULE
39$(error LOCAL_MODULE must be defined.)
40endif
41
42ifndef LOCAL_MODULE_STEM
43LOCAL_MODULE_STEM := $(LOCAL_MODULE)
44endif
45
46ifndef LOCAL_MODULE_CLASS
47LOCAL_MODULE_CLASS := ETC
48endif
49
50ifndef LOCAL_MODULE_PATH
51LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/vintf
52endif
53
54GEN := $(local-generated-sources-dir)/$(LOCAL_MODULE_STEM)
55
56$(GEN): PRIVATE_ENV_VARS := $(LOCAL_ASSEMBLE_VINTF_ENV_VARS)
57$(GEN): PRIVATE_FLAGS := $(LOCAL_ASSEMBLE_VINTF_FLAGS)
58
59$(GEN): $(LOCAL_GEN_FILE_DEPENDENCIES)
60
61ifeq (true,$(strip $(LOCAL_ADD_VBMETA_VERSION)))
62ifeq (true,$(BOARD_AVB_ENABLE))
63$(GEN): $(AVBTOOL)
64# INTERNAL_AVB_SYSTEM_SIGNING_ARGS consists of BOARD_AVB_SYSTEM_KEY_PATH and
65# BOARD_AVB_SYSTEM_ALGORITHM. We should add the dependency of key path, which
66# is a file, here.
67$(GEN): $(BOARD_AVB_SYSTEM_KEY_PATH)
68# Use deferred assignment (=) instead of immediate assignment (:=).
69# Otherwise, cannot get INTERNAL_AVB_SYSTEM_SIGNING_ARGS.
70$(GEN): FRAMEWORK_VBMETA_VERSION = $$("$(AVBTOOL)" add_hashtree_footer \
71                           --print_required_libavb_version \
72                           $(INTERNAL_AVB_SYSTEM_SIGNING_ARGS) \
73                           $(BOARD_AVB_SYSTEM_ADD_HASHTREE_FOOTER_ARGS))
74else
75$(GEN): FRAMEWORK_VBMETA_VERSION := 0.0
76endif # BOARD_AVB_ENABLE
77$(GEN): PRIVATE_ENV_VARS += FRAMEWORK_VBMETA_VERSION
78endif # LOCAL_ADD_VBMETA_VERSION
79
80ifneq (,$(strip $(LOCAL_KERNEL_CONFIG_DATA_PATHS)))
81$(GEN): PRIVATE_KERNEL_CONFIG_DATA_PATHS := $(LOCAL_KERNEL_CONFIG_DATA_PATHS)
82$(GEN): $(foreach pair,$(PRIVATE_KERNEL_CONFIG_DATA_PATHS),\
83    $(wildcard $(call word-colon,2,$(pair))/android-base*.cfg))
84$(GEN): PRIVATE_FLAGS += $(foreach pair,$(PRIVATE_KERNEL_CONFIG_DATA_PATHS),\
85	--kernel=$(call word-colon,1,$(pair)):$(call normalize-path-list,\
86		$(wildcard $(call word-colon,2,$(pair))/android-base*.cfg)))
87endif
88
89my_matrix_src_files := \
90	$(addprefix $(LOCAL_PATH)/,$(LOCAL_SRC_FILES)) \
91	$(LOCAL_GENERATED_SOURCES)
92
93$(GEN): PRIVATE_ADDITIONAL_ENV_VARS := $(LOCAL_ASSEMBLE_VINTF_ENV_VARS_OVERRIDE)
94
95ifneq (,$(strip $(LOCAL_ASSEMBLE_VINTF_ERROR_MESSAGE)))
96$(GEN): PRIVATE_COMMAND_TAIL := || (echo $(strip $(LOCAL_ASSEMBLE_VINTF_ERROR_MESSAGE)) && false)
97endif
98
99$(GEN): PRIVATE_SRC_FILES := $(my_matrix_src_files)
100$(GEN): $(my_matrix_src_files) $(HOST_OUT_EXECUTABLES)/assemble_vintf
101	$(foreach varname,$(PRIVATE_ENV_VARS),\
102		$(if $(findstring $(varname),$(PRIVATE_ADDITIONAL_ENV_VARS)),\
103			$(error $(varname) should not be overridden by LOCAL_ASSEMBLE_VINTF_ENV_VARS_OVERRIDE.)))
104	$(foreach varname,$(PRIVATE_ENV_VARS),$(varname)="$($(varname))") \
105		$(PRIVATE_ADDITIONAL_ENV_VARS) \
106		$(HOST_OUT_EXECUTABLES)/assemble_vintf \
107		-i $(call normalize-path-list,$(PRIVATE_SRC_FILES)) \
108		-o $@ \
109		$(PRIVATE_FLAGS) $(PRIVATE_COMMAND_TAIL)
110
111LOCAL_PREBUILT_MODULE_FILE := $(GEN)
112LOCAL_SRC_FILES :=
113LOCAL_GENERATED_SOURCES :=
114
115include $(LOCAL_PATH)/clear_vars.mk
116my_matrix_src_files :=
117
118include $(BUILD_PREBUILT)
119