Skip to content

Commit

Permalink
Makefiles: Extract Makefile.target from Makefile.defines
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Apr 29, 2024
1 parent 9a19a02 commit a01dea2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 41 deletions.
46 changes: 5 additions & 41 deletions Makefile.defines
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#*******************************************************************************
# Ledger SDK
# (c) 2017 Ledger
# (c) 2024 Ledger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,10 @@
# limitations under the License.
#*******************************************************************************

# TARGET should be set as an environment variable otherwise it will be read from a `.target`
# file in the SDK root repository
TARGETS := nanos nanox nanos2 stax flex
ifeq ($(TARGET),)
ifeq ("$(wildcard $(BOLOS_SDK)/.target)","")
$(error No TARGET specified and no .target file in SDK repository $(BOLOS_SDK))
else
TARGET := $(shell cat $(BOLOS_SDK)/.target)
endif
endif

ifeq ($(filter $(TARGET),$(TARGETS)),)
$(error TARGET not set to a valid value (possible values: $(TARGETS)))
endif
ifeq ($(__MAKEFILE_DEFINES__),)
__MAKEFILE_DEFINES__ := 1

API_LEVEL := 0
TARGET_PATH := $(BOLOS_SDK)/target/$(TARGET)
TARGET_ID := $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
TARGET_NAME := $(sort $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ | grep -v TARGET_ID | cut -f2 -d' '))
SDK_NAME := "ledger-secure-sdk"
SDK_VERSION := $(shell git -C $(BOLOS_SDK) describe --tags --exact-match --match "v[0-9]*" --dirty)
SDK_HASH := $(shell git -C $(BOLOS_SDK) describe --always --dirty --exclude '*' --abbrev=40)
ifeq ($(SDK_VERSION),)
SDK_VERSION := "None"
endif
ifeq ($(SDK_HASH),)
SDK_HASH := "None"
endif
include $(BOLOS_SDK)/Makefile.target

# APPNAME exposed to the app as a CFLAG because it might contain spaces
CFLAGS += -DAPPNAME=\"$(APPNAME)\"
Expand All @@ -56,23 +32,12 @@ APP_METADATA_LIST := TARGET TARGET_NAME APPVERSION SDK_NAME SDK_VERSION SDK_HASH
DEFINES += $(foreach item,$(APP_METADATA_LIST), $(item)=\"$($(item))\")


BUILD_DIR := build
TARGET_BUILD_DIR := $(BUILD_DIR)/$(TARGET)
BIN_DIR := $(TARGET_BUILD_DIR)/bin
OBJ_DIR := $(TARGET_BUILD_DIR)/obj
DBG_DIR := $(TARGET_BUILD_DIR)/dbg
DEP_DIR := $(TARGET_BUILD_DIR)/dep
GEN_SRC_DIR := $(TARGET_BUILD_DIR)/gen_src

### platform definitions
DEFINES += gcc __IO=volatile

# no assert by default
DEFINES += NDEBUG

# Debug mode disabled by default
DEBUG:=0

# default is not to display make commands
log = $(if $(strip $(VERBOSE)),$1,@$1) # kept for retrocompat
L = $(if $(strip $(VERBOSE)),,@)
Expand Down Expand Up @@ -243,5 +208,4 @@ endif
# include builtin CX libs options
-include $(BOLOS_SDK)/Makefile.conf.cx

# define the default makefile target (high in include to avoid glyph.h or what not specific target to be the default one when no target passed on the make command line)
all: default
endif
4 changes: 4 additions & 0 deletions Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#*******************************************************************************

include $(BOLOS_SDK)/Makefile.target

#####################################################################
# BLUETOOTH #
#####################################################################
Expand Down Expand Up @@ -212,6 +214,8 @@ ifeq ($(TARGET_NAME), TARGET_FLEX)
ICONNAME ?= $(ICON_FLEX)
endif

include $(BOLOS_SDK)/Makefile.defines

include $(BOLOS_SDK)/Makefile.glyphs

load: all
Expand Down
64 changes: 64 additions & 0 deletions Makefile.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#*******************************************************************************
# Ledger SDK
# (c) 2024 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.
#*******************************************************************************

ifeq ($(__MAKEFILE_TARGET__),)
__MAKEFILE_TARGET__ := 1

# TARGET should be set as an environment variable otherwise it will be read from a `.target`
# file in the SDK root repository
TARGETS := nanos nanox nanos2 stax flex
ifeq ($(TARGET),)
ifeq ("$(wildcard $(BOLOS_SDK)/.target)","")
$(error No TARGET specified and no .target file in SDK repository $(BOLOS_SDK))
else
TARGET := $(shell cat $(BOLOS_SDK)/.target)
endif
endif

ifeq ($(filter $(TARGET),$(TARGETS)),)
$(error TARGET not set to a valid value (possible values: $(TARGETS)))
endif

API_LEVEL := 0
TARGET_PATH := $(BOLOS_SDK)/target/$(TARGET)
TARGET_ID := $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
TARGET_NAME := $(sort $(shell cat $(TARGET_PATH)/include/bolos_target.h | grep TARGET_ | grep -v TARGET_ID | cut -f2 -d' '))
SDK_NAME := "ledger-secure-sdk"
SDK_VERSION := $(shell git -C $(BOLOS_SDK) describe --tags --exact-match --match "v[0-9]*" --dirty)
SDK_HASH := $(shell git -C $(BOLOS_SDK) describe --always --dirty --exclude '*' --abbrev=40)
ifeq ($(SDK_VERSION),)
SDK_VERSION := "None"
endif
ifeq ($(SDK_HASH),)
SDK_HASH := "None"
endif

BUILD_DIR := build
TARGET_BUILD_DIR := $(BUILD_DIR)/$(TARGET)
BIN_DIR := $(TARGET_BUILD_DIR)/bin
OBJ_DIR := $(TARGET_BUILD_DIR)/obj
DBG_DIR := $(TARGET_BUILD_DIR)/dbg
DEP_DIR := $(TARGET_BUILD_DIR)/dep
GEN_SRC_DIR := $(TARGET_BUILD_DIR)/gen_src

# Debug mode disabled by default
DEBUG:=0

# define the default makefile target (high in include to avoid glyph.h or what not specific target to be the default one when no target passed on the make command line)
all: default

endif

0 comments on commit a01dea2

Please sign in to comment.