blob: bed46d02b12368a570e3cddc8d466c8c66d45412 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001# ---------------------------------------
2# Common make definition for all examples
3# ---------------------------------------
4
5# Build directory
6BUILD := _build/$(BOARD)
7
8PROJECT := $(notdir $(CURDIR))
9BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
10
11# Handy check parameter function
12check_defined = \
13 $(strip $(foreach 1,$1, \
14 $(call __check_defined,$1,$(strip $(value 2)))))
15__check_defined = \
16 $(if $(value $1),, \
17 $(error Undefined make flag: $1$(if $2, ($2))))
18
19#-------------- Select the board to build for. ------------
20
21# Board without family
22ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),)
23BOARD_PATH := hw/bsp/$(BOARD)
24FAMILY :=
25endif
26
27# Board within family
28ifeq ($(BOARD_PATH),)
29 BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD)))
30 FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH)))
31 FAMILY_PATH = hw/bsp/$(FAMILY)
32endif
33
34ifeq ($(BOARD_PATH),)
35 $(info You must provide a BOARD parameter with 'BOARD=')
36 $(error Invalid BOARD specified)
37endif
38
39ifeq ($(FAMILY),)
40 include $(TOP)/hw/bsp/$(BOARD)/board.mk
41else
42 # Include Family and Board specific defs
43 include $(TOP)/$(FAMILY_PATH)/family.mk
44
45 SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
46endif
47
48# Fetch submodules depended by family
49fetch_submodule_if_empty = $(if $(wildcard $(TOP)/$1/*),,$(info $(shell git -C $(TOP) submodule update --init $1)))
50ifdef DEPS_SUBMODULES
51 $(foreach s,$(DEPS_SUBMODULES),$(call fetch_submodule_if_empty,$(s)))
52endif
53
54#-------------- Cross Compiler ------------
55# Can be set by board, default to ARM GCC
56CROSS_COMPILE ?= arm-none-eabi-
57# Allow for -Os to be changed by board makefiles in case -Os is not allowed
58CFLAGS_OPTIMIZED ?= -Os
59
60CC = $(CROSS_COMPILE)gcc
61CXX = $(CROSS_COMPILE)g++
62GDB = $(CROSS_COMPILE)gdb
63OBJCOPY = $(CROSS_COMPILE)objcopy
64SIZE = $(CROSS_COMPILE)size
65MKDIR = mkdir
66
67ifeq ($(CMDEXE),1)
68 CP = copy
69 RM = del
70 PYTHON = python
71else
72 SED = sed
73 CP = cp
74 RM = rm
75 PYTHON = python3
76endif
77
78#-------------- Source files and compiler flags --------------
79
80# Include all source C in family & board folder
81SRC_C += hw/bsp/board.c
82SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
83
84INC += $(TOP)/$(FAMILY_PATH)
85
86# Compiler Flags
87CFLAGS += \
88 -ggdb \
89 -fdata-sections \
90 -ffunction-sections \
91 -fsingle-precision-constant \
92 -fno-strict-aliasing \
93 -Wdouble-promotion \
94 -Wstrict-prototypes \
95 -Wstrict-overflow \
96 -Wall \
97 -Wextra \
98 -Werror \
99 -Wfatal-errors \
100 -Werror-implicit-function-declaration \
101 -Wfloat-equal \
102 -Wundef \
103 -Wshadow \
104 -Wwrite-strings \
105 -Wsign-compare \
106 -Wmissing-format-attribute \
107 -Wunreachable-code \
108 -Wcast-align \
109 -Wcast-function-type \
110 -Wcast-qual \
111 -Wnull-dereference
112
113# Debugging/Optimization
114ifeq ($(DEBUG), 1)
115 CFLAGS += -Og
116else
117 CFLAGS += $(CFLAGS_OPTIMIZED)
118endif
119
120# Log level is mapped to TUSB DEBUG option
121ifneq ($(LOG),)
122 CMAKE_DEFSYM += -DLOG=$(LOG)
123 CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
124endif
125
126# Logger: default is uart, can be set to rtt or swo
127ifneq ($(LOGGER),)
128 CMAKE_DEFSYM += -DLOGGER=$(LOGGER)
129endif
130
131ifeq ($(LOGGER),rtt)
132 CFLAGS += -DLOGGER_RTT -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
133 RTT_SRC = lib/SEGGER_RTT
134 INC += $(TOP)/$(RTT_SRC)/RTT
135 SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c
136else ifeq ($(LOGGER),swo)
137 CFLAGS += -DLOGGER_SWO
138endif