Skip to content

Commit

Permalink
ports/psoc6/mtb-libs/makefile_mtb.mk: Variable clean-up.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx committed Feb 6, 2024
1 parent 3a95068 commit 7be59c5
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions ports/psoc6/mtb-libs/makefile_mtb.mk
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@

# get path to this file
MPY_PATH_TO_MTB_ADAPTER_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
MPY_DIR_OF_MTB_ADAPTER_MAKEFILE := $(dir $(MPY_PATH_TO_MTB_ADAPTER_MAKEFILE))

MTB_LIBS_DIR = mtb-libs
MTB_LIBS_BUILD_DIR = mtb-libs/build

# get variable definitions from main makefile
MTB_BASE_EXAMPLE_MAKEFILE_DIR := $(MPY_DIR_OF_MTB_ADAPTER_MAKEFILE)
MPY_MTB_MAIN_MAKEFILE := $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/Makefile
MPY_MTB_TARGET := $(shell egrep '^ *TARGET' $(MPY_MTB_MAIN_MAKEFILE) | sed 's/^.*= *//g')
MPY_MTB_CONFIG ?= $(shell egrep '^ *CONFIG' $(MPY_MTB_MAIN_MAKEFILE) | sed 's/^.*= *//g')

MPY_MTB_BOARD_BUILD_DIR := $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/$(BUILD)
MPY_MTB_BOARD_BUILD_OUTPUT_DIR := $(MPY_MTB_BOARD_BUILD_DIR)/$(MPY_MTB_TARGET)/$(MPY_MTB_CONFIG)
MTB_LIBS_DIR = mtb-libs
MTB_MAIN_MAKEFILE := $(MTB_LIBS_DIR)/Makefile
MTB_TARGET := $(shell egrep '^ *TARGET' $(MTB_MAIN_MAKEFILE) | sed 's/^.*= *//g')
MTB_CONFIG ?= $(shell egrep '^ *CONFIG' $(MTB_MAIN_MAKEFILE) | sed 's/^.*= *//g')

MPY_MTB_LIB_NAME = $(file < $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/artifact.rsp)
MTB_LIBS_BUILD_DIR := $(MTB_LIBS_DIR)/$(BUILD)
MTB_LIBS_BOARD_BUILD_DIR := $(MTB_LIBS_BUILD_DIR)/$(MTB_TARGET)/$(MPY_MTB_CONFIG)

# $(info MPY_DIR_OF_MTB_ADAPTER_MAKEFILE : $(MPY_DIR_OF_MTB_ADAPTER_MAKEFILE))
MPY_MTB_LIB_NAME = $(file < $(MTB_LIBS_BOARD_BUILD_DIR)/artifact.rsp)

# $(info MPY_MTB_MAIN_MAKEFILE : $(MPY_MTB_MAIN_MAKEFILE))
# $(info MPY_MTB_TARGET : $(MPY_MTB_TARGET))
# $(info MPY_MTB_CONFIG : $(MPY_MTB_CONFIG))
# $(info MTB_LIB_NAME : $(MPY_MTB_LIB_NAME))
$(info MTB_MAIN_MAKEFILE : $(MTB_MAIN_MAKEFILE))
$(info MTB_TARGET : $(MTB_TARGET))
$(info MTB_CONFIG : $(MTB_CONFIG))
$(info MTB_LIB_NAME : $(MPY_MTB_LIB_NAME))

# $(info MPY_MTB_BOARD_BUILD_DIR : $(MPY_MTB_BOARD_BUILD_DIR))
# $(info MPY_MTB_BOARD_BUILD_OUTPUT_DIR : $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR))
$(info MTB_LIBS_BUILD_DIR : $(MTB_LIBS_BUILD_DIR))
$(info MTB_LIBS_BOARD_BUILD_DIR : $(MTB_LIBS_BOARD_BUILD_DIR))

mtb_init: mtb_deinit mtb_add_bsp mtb_set_bsp mtb_get_libs
$(info )
Expand Down Expand Up @@ -58,32 +48,32 @@ mtb_config_deps:
@:
$(info )
$(info Configuring ModusToolbox dependencies ...)
$(info mtb_deps_dir : $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)deps/$(MTB_DEPS_DIRS)/)
$(Q) $(foreach DIR, $(MTB_DEPS_DIRS), $(shell cp -r $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)deps/$(DIR)/. $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)deps))
$(info mtb_deps_dir : $(MTB_LIBS_DIR)/deps/$(MTB_DEPS_DIRS)/)
$(Q) $(foreach DIR, $(MTB_DEPS_DIRS), $(shell cp -r $(MTB_LIBS_DIR)/deps/$(DIR)/. $(MTB_LIBS_DIR)/deps))

mtb_get_libs: mtb_config_deps
$(info )
$(info Retrieving ModusToolbox dependencies ...)
$(Q) $(MAKE) -C $(MTB_BASE_EXAMPLE_MAKEFILE_DIR) getlibs
$(Q) $(MAKE) -C $(MTB_LIBS_DIR) getlibs

mtb_add_bsp:
$(info )
$(info Adding board $(BOARD) dependencies ...)
$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); library-manager-cli --project . --add-bsp-name $(BOARD) --add-bsp-version $(BOARD_VERSION)
$(Q) cd $(MTB_LIBS_DIR); library-manager-cli --project . --add-bsp-name $(BOARD) --add-bsp-version $(BOARD_VERSION)

mtb_set_bsp:
$(info )
$(info Setting board $(BOARD) as active ...)
$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); library-manager-cli --project . --set-active-bsp APP_$(BOARD)
$(Q) cd $(MTB_LIBS_DIR); library-manager-cli --project . --set-active-bsp APP_$(BOARD)

# Remove MTB retrieved lib and dependencies
mtb_deinit: clean
$(info )
$(info Removing mtb_shared and libs folder ...)
-$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); rm -rf libs
-$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); rm -rf bsps
-$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); rm -rf ../mtb_shared
-$(Q) cd $(MTB_BASE_EXAMPLE_MAKEFILE_DIR); find deps/ -maxdepth 1 -type f -delete
-$(Q) cd $(MTB_LIBS_DIR); rm -rf libs
-$(Q) cd $(MTB_LIBS_DIR); rm -rf bsps
-$(Q) cd $(MTB_LIBS_DIR); rm -rf ../mtb_shared
-$(Q) cd $(MTB_LIBS_DIR); find deps/ -maxdepth 1 -type f -delete

# Some of the configuration variables are passed to the ModusToolbox
# Makefile to include/exclude certain middleware libraries and components
Expand All @@ -93,7 +83,7 @@ MPY_MTB_MAKE_VARS = MICROPY_PY_NETWORK=$(MICROPY_PY_NETWORK) MICROPY_PY_SSL=$(MI
mtb_build:
$(info )
$(info Building $(BOARD) in $(CONFIG) mode using MTB ...)
$(Q) $(MAKE) -C $(MTB_BASE_EXAMPLE_MAKEFILE_DIR) CONFIG=$(MPY_MTB_CONFIG) $(MPY_MTB_MAKE_VARS) build
$(Q) $(MAKE) -C $(MTB_LIBS_DIR) CONFIG=$(MPY_MTB_CONFIG) $(MPY_MTB_MAKE_VARS) build


mtb_clean:
Expand All @@ -102,14 +92,14 @@ mtb_clean:
# get variables set for includes, objects, etc. and add to mpy makefile variables
mtb_get_build_flags: mtb_build
@:
$(eval MPY_MTB_INCLUDE_DIRS = $(file < $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/inclist.rsp))
$(eval INC += $(subst -I,-I$(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/,$(MPY_MTB_INCLUDE_DIRS)))
$(eval MPY_MTB_INCLUDE_DIRS = $(file < $(MTB_LIBS_BOARD_BUILD_DIR)/inclist.rsp))
$(eval INC += $(subst -I,-I$(MTB_LIBS_DIR)/,$(MPY_MTB_INCLUDE_DIRS)))
$(eval INC += -I$(BOARD_DIR))
$(eval MPY_MTB_LIBRARIES = $(file < $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/liblist.rsp))
$(eval LIBS += $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/$(MPY_MTB_LIB_NAME))
$(eval CFLAGS += $(shell $(PYTHON) $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/mtb_build_info.py ccxxflags $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/.cycompiler ))
$(eval MPY_MTB_LIBRARIES = $(file < $(MTB_LIBS_BOARD_BUILD_DIR)/liblist.rsp))
$(eval LIBS += $(MTB_LIBS_BOARD_BUILD_DIR)/$(MPY_MTB_LIB_NAME))
$(eval CFLAGS += $(shell $(PYTHON) $(MTB_LIBS_DIR)/mtb_build_info.py ccxxflags $(MTB_LIBS_BOARD_BUILD_DIR)/.cycompiler ))
$(eval CXXFLAGS += $(CFLAGS))
$(eval LDFLAGS += $(shell $(PYTHON) $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/mtb_build_info.py ldflags $(MPY_MTB_BOARD_BUILD_OUTPUT_DIR)/.cylinker $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)))
$(eval LDFLAGS += $(shell $(PYTHON) $(MTB_LIBS_DIR)/mtb_build_info.py ldflags $(MTB_LIBS_BOARD_BUILD_DIR)/.cylinker $(MTB_LIBS_DIR)))
$(eval QSTR_GEN_CFLAGS += $(INC) $(CFLAGS))

# When multiple types of boards are connected, a devs file needs to be provided.
Expand Down Expand Up @@ -143,7 +133,7 @@ MTB_HOME ?= $(HOME)/ModusToolbox
OPENOCD_HOME ?= $(MTB_HOME)/tools_3.0/openocd

# Selection of openocd cfg files based on board
OPENOCD_CFG_SEARCH = $(MTB_BASE_EXAMPLE_MAKEFILE_DIR)/bsps/TARGET_APP_$(BOARD)/config/GeneratedSource
OPENOCD_CFG_SEARCH = $(MTB_LIBS_DIR)/bsps/TARGET_APP_$(BOARD)/config/GeneratedSource

ifeq ($(BOARD),CY8CPROTO-062-4343W)
OPENOCD_TARGET_CFG=psoc6_2m.cfg
Expand Down

0 comments on commit 7be59c5

Please sign in to comment.