forked from LedgerHQ/ledger-secure-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.rules
More file actions
132 lines (113 loc) · 5.6 KB
/
Makefile.rules
File metadata and controls
132 lines (113 loc) · 5.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#*******************************************************************************
# Ledger SDK
# (c) 2017 Ledger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************
# temporary redef, to ensure wider compliance of the SDK with pre-1.6 apps
ifeq ($(USE_NBGL),0)
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_ux_nbgl
NBGL_SOURCES := $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_layout*.[csS]')
NBGL_SOURCES += $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_page*.[csS]')
NBGL_SOURCES += $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_step*.[csS]')
NBGL_SOURCES += $(shell find $(BOLOS_SDK)/lib_nbgl/src -name 'nbgl_use_case*.[csS]')
NBGL_INCLUDE_PATH := lib_nbgl
endif
# include dynamic memory allocator, if asked (temporary flag)
ifeq ($(ENABLE_DYNAMIC_ALLOC), 1)
SDK_SOURCE_PATH += lib_alloc
endif
ifneq ($(IS_STANDARD_APP),1)
ifneq ($(DISABLE_OS_IO_STACK_USE), 1)
ifeq (,$(filter $(DEFINES),HAVE_LEGACY_PID))
DEFINES += USE_OS_IO_STACK
endif
endif
endif
define uniq =
$(eval seen :=)
$(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))
${seen}
endef
define check_duplicate =
$(eval LIST := $(sort $(foreach file_h, $(notdir $1), $(notdir $(shell find $2 -name $(file_h))))))
$(if $(LIST), $(info [WARNING] Found duplicate files in SDK and APP: ${LIST}))
endef
SDK_SOURCE_PATH += io io_legacy protocol lib_u2f_legacy
# adding the correct target header to sources
SDK_SOURCE_PATH += target/$(TARGET)/include
# Expose all SDK header files with their full relative path to the SDK root folder
INCLUDES_PATH += ${BOLOS_SDK}
#include the lib_cxng definition by default if not asked otherwise
ifeq ($(NO_CXNG),)
INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/include
endif
# Get absolute App root directory to ensure correct stem replacement
APP_DIR := $(shell git rev-parse --show-toplevel)
ifeq ($(APP_DIR),)
MSG := "[ERROR] You should be inside a git repo (you can use 'git init')"
ifneq ($(ENABLE_SDK_WERROR),0)
$(error $(MSG))
else
$(warning $(MSG))
endif
endif
# Extract BOLOS_SDK source files added by the App Makefile
APP_SRC_FROM_SDK = $(filter $(BOLOS_SDK)/%, $(APP_SOURCE_FILES))
# Extract generated and glyphs source files added by the App Makefile
APP_SRC_GEN = $(filter $(GEN_SRC_DIR)/%, $(APP_SOURCE_FILES))
# Extract proto source files added by the App Makefile
APP_SRC_PROTOC = $(filter %.pb.c, $(APP_SOURCE_FILES) $(SOURCE_FILES)) $(shell find $(APP_SOURCE_PATH) -name '*.pb.c')
# Filter remaining real source files from App (proto filtered globally hereafter)
APP_SRC_FILTER = $(filter-out $(APP_SRC_FROM_SDK) $(APP_SRC_GEN), $(APP_SOURCE_FILES))
# Separate SDK and APP and GEN sources
SOURCES_SDK += $(foreach libdir, src $(SDK_SOURCE_PATH), $(shell find $(BOLOS_SDK)/$(libdir) -name '*.[csS]')) $(APP_SRC_FROM_SDK) $(NBGL_SOURCES)
SOURCES_APP += $(filter-out %.pb.c, $(abspath $(SOURCE_FILES) $(foreach libdir, $(SOURCE_PATH) $(APP_SOURCE_PATH), $(shell find $(libdir) -name '*.[csS]')) $(APP_SRC_FILTER)))
SOURCES_GEN += $(GLYPH_DESTC) $(APP_SRC_GEN)
VPATH += $(call uniq, $(dir $(SOURCES_SDK) $(SOURCES_APP) $(GLYPH_DESTC)))
# Retrieve APP header filenames
INCLUDES_APP += $(shell find $(APP_SOURCE_PATH) -name '*.h')
# Warn if a same header filename is found in both APP and SDK
$(call check_duplicate, $(INCLUDES_APP), $(BOLOS_SDK))
# Compute header directories list
INCLUDES_PATH += $(call uniq, $(dir $(foreach libdir, $(SDK_SOURCE_PATH) $(NBGL_INCLUDE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.h')))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(INCLUDES_APP)) $(GLYPH_SRC_DIR))
# Separate object files from SDK and APP to avoid name conflicts
OBJECTS_SDK += $(sort $(subst $(BOLOS_SDK), $(OBJ_DIR)/sdk, $(addsuffix .o, $(basename $(SOURCES_SDK)))))
OBJECTS_APP += $(sort $(addprefix $(OBJ_DIR)/app, $(addsuffix .o, $(basename $(foreach f, $(SOURCES_APP), $(shell echo $(f) | sed "s|$(APP_DIR)||" 2>/dev/null))))))
OBJECTS_GEN += $(sort $(SOURCES_GEN:%c=%o))
OBJECTS_PROTOC += $(sort $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(APP_SRC_PROTOC)))))
OBJECT_FILES = $(OBJECTS_GEN) $(OBJECTS_PROTOC) $(OBJECTS_APP) $(OBJECTS_SDK)
OBJECTS_DIR += $(sort $(dir $(OBJECT_FILES)))
# Separate dependency files from SDK and APP to avoid name conflicts
DEPEND_FILES = $(subst $(OBJ_DIR), $(DEP_DIR), $(addsuffix .d, $(basename $(OBJECT_FILES))))
DEPEND_DIR += $(sort $(dir $(DEPEND_FILES)))
# Path to the TOML file
APP_MANIFEST_FILE := $(APP_DIR)/ledger_app.toml
# If the TOML file exists, retrieve the use-cases
ifneq ($(wildcard $(APP_MANIFEST_FILE)),)
# Retrieve the use-cases from the TOML file
APP_USE_CASES := $(shell ledger-manifest "$(APP_MANIFEST_FILE)" -ouc -j | jq -r 'keys | join(" ")')
# Function to extract flags for a specific use case
define get_flags_for_use_case
$(shell ledger-manifest "$(APP_MANIFEST_FILE)" -ouc $1)
endef
endif
include $(BOLOS_SDK)/Makefile.rules_generic
list-defines:
# As of now APPNAME is added as a CFLAG and not a DEFINE
# We force print it.
@echo "DEFINITIONS LIST"
@echo "APPNAME=\"$(APPNAME)\""
@for d in $(DEFINES); do echo "$$d"; done