• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (c) 2020, Google, Inc. All rights reserved
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# Generate and add constant headers, if necessary
18#
19# args:
20# MODULE : module name (required)
21# PY3 : Path of the Python 3 interpreter to use to run the manifest compiler
22#       script.
23# MODULE_CONSTANTS : JSON files with constants used for both the manifest and C
24# 		headers (optional) (CONSTANTS is a deprecated equivalent to
25# 		MODULE_CONSTANTS)
26# MANIFEST : manifest for the application (optional)
27# MANIFEST_OVERLAY : additional overlay manifests for the application (optional)
28#
29# outputs:
30# TRUSTY_APP_MANIFEST_BIN : manifest binary name, if MANIFEST
31#
32# If neither MODULE_CONSTANTS nor MANIFEST are set, this file does nothing.
33
34ifneq ($(strip $(MODULE_CONSTANTS)),)
35MODULE_INCLUDES += \
36	$(BUILDDIR)/constants/include
37endif
38
39ifneq ($(strip $(MODULE_CONSTANTS)$(MANIFEST)),)
40
41CONSTANTS_HEADER_DIR := $(BUILDDIR)/constants/include
42
43ifeq ($(strip $(MANIFEST_COMPILER)),)
44MANIFEST_COMPILER := trusty/user/base/tools/manifest_compiler.py
45endif
46
47# build manifest objects if we are building an app, otherwise generate shared
48# constants headers if constants provided
49ifeq ($(call TOBOOL,$(TRUSTY_APP)),true)
50
51TRUSTY_APP_MANIFEST_BIN := $(BUILDDIR)/$(TRUSTY_APP_NAME).manifest
52
53# Save the manifest path for use in user-tasks.mk
54_MODULES_$(MODULE)_TRUSTY_APP_MANIFEST_BIN := $(TRUSTY_APP_MANIFEST_BIN)
55$(INFO_DONE $(MODULE),generating manifest,$(TRUSTY_APP_MANIFEST_BIN))
56
57# TODO Until the SDK supports library variants, this flag will only work as
58# intended for applications that have no library dependencies.
59$(TRUSTY_APP_MANIFEST_BIN): TRUSTY_APP_ENABLE_SCS :=
60ifeq (false,$(call TOBOOL,$(TRUSTY_APP_DISABLE_SCS)))
61ifeq (true,$(call TOBOOL,$(SCS_ENABLED)))
62$(TRUSTY_APP_MANIFEST_BIN): TRUSTY_APP_ENABLE_SCS := --enable-shadow-call-stack
63endif
64endif
65ifdef ARCH_$(ARCH)_DEFAULT_USER_SHADOW_STACK_SIZE
66$(TRUSTY_APP_MANIFEST_BIN): DEFAULT_USER_SHADOW_STACK_SIZE := \
67--default-shadow-call-stack-size $(ARCH_$(ARCH)_DEFAULT_USER_SHADOW_STACK_SIZE)
68else
69$(TRUSTY_APP_MANIFEST_BIN): DEFAULT_USER_SHADOW_STACK_SIZE :=
70endif
71$(TRUSTY_APP_MANIFEST_BIN): MANIFEST_COMPILER := $(MANIFEST_COMPILER)
72$(TRUSTY_APP_MANIFEST_BIN): PY3 := $(PY3)
73$(TRUSTY_APP_MANIFEST_BIN): CONFIG_CONSTANTS := $(MODULE_CONSTANTS)
74$(TRUSTY_APP_MANIFEST_BIN): MODULE := $(MODULE)
75$(TRUSTY_APP_MANIFEST_BIN): MANIFEST := $(MANIFEST)
76$(TRUSTY_APP_MANIFEST_BIN): MANIFEST_OVERLAY := $(MANIFEST_OVERLAY)
77$(TRUSTY_APP_MANIFEST_BIN): HEADER_DIR := $(CONSTANTS_HEADER_DIR)
78$(TRUSTY_APP_MANIFEST_BIN): $(MANIFEST) $(MANIFEST_OVERLAY) $(MANIFEST_COMPILER) $(MODULE_CONSTANTS)
79	@$(MKDIR)
80	@$(call ECHO,$(MODULE),compiling,$< to $@)
81	$(NOECHO)$(PY3) $(MANIFEST_COMPILER) $(addprefix -i,$(MANIFEST) $(MANIFEST_OVERLAY)) -o $@ $(addprefix -c,$(CONFIG_CONSTANTS)) --header-dir $(HEADER_DIR) \
82	$(TRUSTY_APP_ENABLE_SCS) $(DEFAULT_USER_SHADOW_STACK_SIZE)
83	@$(call ECHO_DONE_SILENT,$(MODULE),compiling,$< to $@)
84
85# We need the constants headers to be generated before the sources are compiled
86MODULE_SRCDEPS += $(TRUSTY_APP_MANIFEST_BIN)
87
88else # we are not building an app
89
90ifneq ($(strip $(MODULE_CONSTANTS)),)
91
92# generate shared constants headers if only constants and no manifest provided
93# generate also a hidden generated for each module that will
94# say that constants are already generated for this module
95$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): MANIFEST_COMPILER := $(MANIFEST_COMPILER)
96$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): PY3 := $(PY3)
97$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): MODULE := $(MODULE)
98$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): CONFIG_CONSTANTS := $(MODULE_CONSTANTS)
99$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): HEADER_DIR := $(CONSTANTS_HEADER_DIR)
100$(CONSTANTS_HEADER_DIR)/.generated/$(MODULE): $(MANIFEST_COMPILER) $(MODULE_CONSTANTS)
101	@$(MKDIR)
102	@$(call ECHO,$(MODULE),compiling constants,for $(MODULE))
103	$(NOECHO)$(PY3) $(MANIFEST_COMPILER) $(addprefix -c,$(CONFIG_CONSTANTS)) --header-dir $(HEADER_DIR)
104	@touch $(HEADER_DIR)/.generated/$(MODULE)
105	@$(call ECHO_DONE_SILENT,$(MODULE),compiling constants,for $(MODULE))
106
107MODULE_SRCDEPS += $(CONSTANTS_HEADER_DIR)/.generated/$(MODULE)
108
109endif # MODULE_CONSTANTS is non-empty
110
111endif # TRUSTY_APP = false
112
113endif # MODULE_CONSTANTS and/or MANIFEST is non-empty
114
115CONSTANTS :=
116CONSTANTS_HEADER_DIR :=
117MODULE_CONSTANTS :=
118MANIFEST :=
119MANIFEST_OVERLAY :=
120