Makefle - GaloisInc/betaflight GitHub Wiki
These are the basic changes that need to be done in the root directory Makefile and leaf Makefiles for building your project.
It is expected some familiarity with GNU Makefiles. If not this is a good place to start GNU Makefiles
ifneq ($(TARGET),$(filter $(TARGET),$(MAIXBIT)))
RISCV64_SDK_PREFIX = /opt/kendryte-toolchain/bin/riscv64-unknown-elf-
CROSS_CC := $(RISCV64_SDK_PREFIX)gcc #$(CCACHE) $(ARM_SDK_PREFIX)gcc
CROSS_CXX := $(RISCV64_SDK_PREFIX)g++ #$(CCACHE) $(ARM_SDK_PREFIX)g++
CROSS_GDB := $(RISCV64_SDK_PREFIX)-gdb #$(ARM_SDK_PREFIX)gdb
OBJCOPY := $(RISCV64_SDK_PREFIX)objcopy #$(ARM_SDK_PREFIX)objcopy
OBJDUMP := $(RISCV64_SDK_PREFIX)objdump #$(ARM_SDK_PREFIX)objdump
SIZE := $(RISCV64_SDK_PREFIX)size #$(ARM_SDK_PREFIX)size
DFUSE-PACK := src/utils/dfuse-pack.py
endif
Create a directory in src/main/target/<TARGET_NAME>
. The board has to be in the list of valid targets, which resides in make/targets_list.mk
Note: Line 1: ALT_TARGET_PATHS = $(filter-out %/target,$(basename $(wildcard $(ROOT)/src/main/target/*/*.mk)
, this is why we created the directory above
In the line below insert your target board :
ifeq ($(filter $(TARGET),$(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS) $(H7_TARGETS) $(SITL_TARGETS) $(RISCV_K210_TARGETS)),) $(error Target '$(TARGET)' has not specified a valid STM group, must be one of F1, F3, F405, F411, F446, F7X2RE, F7X5XE, F7X5XG, F7X5XI, F7X6XG or H7X3XI. Have you prepared a valid target.mk?) endif
- Add an
ifeq
statment like below to add the board as TARGET_MCU
else ifeq ($(TARGET),$(filter $(TARGET), $(RISCV_K210_TARGETS)))
TARGET_MCU := RISCV_K210
RISCV_K210 = yes
The name for the file is the MCU that is on the board. In our example was Kendryte 210 or K210, e.g RISCV_K210.mk ( we included the name of the architecture as well). Later, the file will contain specific compile and linker flags as well source files.
The 3 files are target.c, target.h, target.mk. In target.mk
we need only line on the top of target.mk <TARGET_MCU>_TARGETS += $(TARGET)
. In our example we named it RISCV_K210_TARGETS += $(TARGET)
. This will add the board's mcu in the list of targets.
In our case we had RISCV_K210 as TARGET_MCU. Later, we will revisit that folder and add the SDK files.
That way we can toggle what files are compiled and linked, starting with only main.c as a common source and the board specific drivers included in the lib/main/<TARGET_MCU>
directory, and sourced from TARGET_MCU.mk (or potentially in target.mk as well).
# ---------------------------------------------- +
#### RISCV |
#### --------------------------------------------+
ifneq ($(TARGET),$(filter $(TARGET),$(MAIXBIT)))
COMMON_SRC = \
build/build_config.c \
build/version.c \
capstone_print.c \
fc/init.c \
pg/pg.c\
sensors/initialisation.c \
sensors/gyro.c \
drivers/flash.c \
config/config_eeprom.c \
config/config_streamer.c\
config/config.c \
common/crc.c \
config/feature.c \
fc/board_info.c \
pg/board.c\
drivers/bus_spi.c \
drivers/bus_spi_pinconfig.c \
drivers/bus_spi_config.c \
pg/flash.c\
rx/rx.c \
drivers/io.c \
pg/flash_riscv_k210.c
ifneq ($(TEST),yes)
MCU_COMMON_SRC := main.c
endif
endif
SRC := $(MCU_COMMON_SRC) $(STARTUP_SRC) $(TARGET_SRC) $(COMMON_SRC)
#--------------------------------------------------+