espressif_tinyusb/examples/make.mk

141 lines
3.2 KiB
Makefile
Raw Normal View History

# ---------------------------------------
# Common make definition for all examples
# ---------------------------------------
2021-01-13 06:56:33 +01:00
# Build directory
BUILD := _build/$(BOARD)
2021-06-10 12:24:36 +02:00
PROJECT := $(notdir $(CURDIR))
BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
2021-01-13 06:56:33 +01:00
# Handy check parameter function
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))
2021-01-25 17:40:52 +01:00
2020-11-27 18:16:28 +01:00
#-------------- Select the board to build for. ------------
2021-01-13 06:56:33 +01:00
# Board without family
ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),)
BOARD_PATH := hw/bsp/$(BOARD)
2021-01-13 06:56:33 +01:00
FAMILY :=
endif
2021-01-13 06:56:33 +01:00
# Board within family
2020-11-27 18:16:28 +01:00
ifeq ($(BOARD_PATH),)
2021-01-13 06:56:33 +01:00
BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD)))
FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH)))
FAMILY_PATH = hw/bsp/$(FAMILY)
2020-11-27 18:16:28 +01:00
endif
2021-01-13 06:56:33 +01:00
ifeq ($(BOARD_PATH),)
$(info You must provide a BOARD parameter with 'BOARD=')
2021-01-13 06:56:33 +01:00
$(error Invalid BOARD specified)
endif
2020-11-27 18:16:28 +01:00
2021-01-13 06:56:33 +01:00
ifeq ($(FAMILY),)
include $(TOP)/hw/bsp/$(BOARD)/board.mk
else
# Include Family and Board specific defs
include $(TOP)/$(FAMILY_PATH)/family.mk
2021-01-13 06:56:33 +01:00
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
endif
#-------------- Cross Compiler ------------
# Can be set by board, default to ARM GCC
CROSS_COMPILE ?= arm-none-eabi-
# Allow for -Os to be changed by board makefiles in case -Os is not allowed
CFLAGS_OPTIMIZED ?= -Os
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
GDB = $(CROSS_COMPILE)gdb
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
MKDIR = mkdir
ifeq ($(CMDEXE),1)
CP = copy
RM = del
PYTHON = python
else
SED = sed
CP = cp
RM = rm
PYTHON = python3
endif
#-------------- Source files and compiler flags --------------
2020-11-27 18:16:28 +01:00
# Include all source C in family & board folder
SRC_C += hw/bsp/board.c
2020-11-27 18:16:28 +01:00
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
2019-05-14 08:59:45 +02:00
INC += $(TOP)/$(FAMILY_PATH)
# Compiler Flags
CFLAGS += \
-ggdb \
-fdata-sections \
-ffunction-sections \
-fsingle-precision-constant \
-fno-strict-aliasing \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
-Wdouble-promotion \
-Wstrict-prototypes \
-Wstrict-overflow \
-Werror-implicit-function-declaration \
-Wfloat-equal \
-Wundef \
-Wshadow \
-Wwrite-strings \
-Wsign-compare \
-Wmissing-format-attribute \
-Wunreachable-code \
-Wcast-align \
2021-10-17 11:26:27 +02:00
-Wcast-function-type \
2021-10-17 19:13:40 +02:00
-Wcast-qual \
-Wnull-dereference \
-Wuninitialized \
-Wunused \
-Wredundant-decls
2022-06-27 15:30:47 +02:00
# conversion is too strict for most mcu driver, may be disable sign/int/arith-conversion
# -Wconversion
# Debugging/Optimization
ifeq ($(DEBUG), 1)
2022-11-21 05:12:10 +01:00
CFLAGS += -O0
NO_LTO = 1
else
CFLAGS += $(CFLAGS_OPTIMIZED)
2019-10-03 14:22:43 +02:00
endif
2019-11-03 07:18:02 +01:00
# Log level is mapped to TUSB DEBUG option
2019-11-03 07:18:02 +01:00
ifneq ($(LOG),)
CMAKE_DEFSYM += -DLOG=$(LOG)
2019-11-03 07:18:02 +01:00
CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
endif
# Logger: default is uart, can be set to rtt or swo
ifneq ($(LOGGER),)
CMAKE_DEFSYM += -DLOGGER=$(LOGGER)
endif
ifeq ($(LOGGER),rtt)
CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
RTT_SRC = lib/SEGGER_RTT
INC += $(TOP)/$(RTT_SRC)/RTT
SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
else ifeq ($(LOGGER),swo)
CFLAGS += -DLOGGER_SWO
endif