-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
247 lines (194 loc) · 7.11 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
##
# @file Makefile
# @author cy023@MVMC-Lab (cyyang023@gmail.com)
# @date 2022.09.17
# @brief Makefile for rtox project.
################################################################################
# User Settings
################################################################################
## Target
TARGET = main
# Upload Info.
COMPORT ?=
UPLOAD_HEX ?= main
## MCU Info.
CPU = -mcpu=cortex-m4
MCU =
FPU = -mfpu=fpv4-sp-d16
FLOAT-ABI = -mfloat-abi=hard
## Warning Options
WARNINGS = -Wall -Werror -Wtype-limits -Wno-unused-function
## Debugging Options
DEBUG = -gdwarf-2
## Optimize Options
OPTIMIZE = -O0
## Libraries Path
LIBS =
LIBDIRS =
## Include Path
C_INCLUDES = -I.
C_INCLUDES += -ICore
C_INCLUDES += -IConfig
C_INCLUDES += -IDevice_Startup
C_INCLUDES += -IDrivers/CMSIS
C_INCLUDES += -IDrivers/HAL
C_INCLUDES += -IDrivers/w25q128jv
C_INCLUDES += -IDrivers/Library/Device/Nuvoton_M480/Include
C_INCLUDES += -IDrivers/Library/StdDriver/inc
C_INCLUDES += -IMiddleware/LittleFS
C_INCLUDES += -IMiddleware/FreeRTOS/Source/include
C_INCLUDES += -IMiddleware/FreeRTOS/Source/portable/GCC/ARM_CM4F
C_INCLUDES += -IMiddleware/SEGGER/Config
C_INCLUDES += -IMiddleware/SEGGER/OS
C_INCLUDES += -IMiddleware/SEGGER/SEGGER
C_INCLUDES += -IMiddleware/uLog
## Source Path
C_SOURCES += $(wildcard Device_Startup/*.c)
C_SOURCES += $(wildcard Drivers/HAL/*.c)
C_SOURCES += $(wildcard Drivers/w25q128jv/*.c)
C_SOURCES += $(wildcard Drivers/Library/Device/Nuvoton_M480/Source/*.c)
# C_SOURCES += $(wildcard Drivers/Library/StdDriver/src/*.c)
C_SOURCES += Drivers/Library/StdDriver/src/sys.c
C_SOURCES += Drivers/Library/StdDriver/src/uart.c
C_SOURCES += Drivers/Library/StdDriver/src/retarget.c
C_SOURCES += Drivers/Library/StdDriver/src/clk.c
C_SOURCES += Drivers/Library/StdDriver/src/gpio.c
C_SOURCES += Drivers/Library/StdDriver/src/spi.c
C_SOURCES += $(wildcard Middleware/LittleFS/*.c)
C_SOURCES += $(wildcard Middleware/FreeRTOS/Source/*.c)
C_SOURCES += Middleware/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
C_SOURCES += Middleware/FreeRTOS/Source/portable/MemMang/heap_4.c
C_SOURCES += $(wildcard Middleware/SEGGER/Config/*.c)
C_SOURCES += $(wildcard Middleware/SEGGER/OS/*.c)
C_SOURCES += $(wildcard Middleware/SEGGER/SEGGER/*.c)
C_SOURCES += $(wildcard Middleware/SEGGER/SEGGER/Syscalls/*.c)
C_SOURCES += Middleware/SEGGER/Rec/segger_uart_m480.c
C_SOURCES += $(wildcard Middleware/uLog/*.c)
ASM_SOURCES += $(wildcard Device_Startup/*.S)
ASM_SOURCES += $(wildcard Middleware/SEGGER/SEGGER/*.S)
################################################################################
# Project Architecture
################################################################################
## Root Path
IPATH = .
## Build Output Path
BUILD_DIR = build
## Build Reference Path
VPATH = $(sort $(dir $(C_SOURCES)))
VPATH += $(sort $(dir $(C_APPSRCS)))
VPATH += $(sort $(dir $(C_TESTSRC)))
## User App Path
C_APPSRCS = $(wildcard Core/*.c)
## Unit Test Path
C_TESTSRC = $(wildcard UnitTest/*.c)
## Object Files
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.S=.o)))
APPOBJS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_APPSRCS:.c=.o)))
TESTOBJ = $(addprefix $(BUILD_DIR)/,$(notdir $(C_TESTSRC:.c=.o)))
## Target and UnitTest HEX Files
TARGET_FILE = $(BUILD_DIR)/$(TARGET).hex
TEST_TARGET = $(TESTOBJ:.o=.hex)
### Linker script
LDSCRIPT = Device_Startup/gcc_arm.ld
################################################################################
# Toolchain
################################################################################
COMPILER_PATH ?=
CROSS := $(COMPILER_PATH)arm-none-eabi
CC := $(CROSS)-gcc
AR := $(CROSS)-ar
SIZE := $(CROSS)-size
OBJDUMP := $(CROSS)-objdump
OBJCOPY := $(CROSS)-objcopy
NM := $(CROSS)-nm
## Common Options for assemble, compile and link.
MCUFLAGS = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
## Compile Options
CFLAGS = $(MCUFLAGS)
CFLAGS += -std=gnu99 $(WARNINGS) $(DEBUG) $(OPTIMIZE)
CFLAGS += -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections
CFLAGS += -Wa,-a,-ad,-alms=$(@:%.o=%.lst)
CFLAGS += -Wp,-MM,-MP,-MT,$(BUILD_DIR)/$(*F).o,-MF,$(BUILD_DIR)/$(*F).d
CFLAGS += $(C_INCLUDES)
## Assembler Options
ASMFLAGS = $(MCUFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-g$(DEBUG)
## Link Options
LDFLAGS = $(MCUFLAGS)
LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$*.map,--cref -Wl,--gc-sections
LDFLAGS += -T$(LDSCRIPT)
LDFLAGS += -specs=nosys.specs -specs=nano.specs -flto
LDFLAGS += -u _printf_float
LDFLAGS += $(LIBDIRS) $(LIBS)
## Archiver Options
# ARFLAGS = rcs
## Intel Hex file production Options
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom=alloc,load
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
################################################################################
# User Command
################################################################################
all: $(OBJECTS) $(APPOBJS) $(TARGET_FILE)
@echo "========== SIZE =========="
$(SIZE) $^
test: $(OBJECTS) $(TESTOBJ) $(TEST_TARGET)
@echo "========== SIZE =========="
$(SIZE) $^
macro: $(OBJECTS:.o=.i) $(APPOBJS:.o=.i) $(TESTOBJ:.o=.i)
dump: $(BUILD_DIR)/$(TARGET).lss $(TESTOBJ:.o=.lss) $(BUILD_DIR)/$(TARGET).sym $(TESTOBJ:.o=.sym)
size: $(TARGET_FILE)
$(SIZE) $(TARGET_FILE)
clean:
-rm -rf $(BUILD_DIR)
upload:
serprog prog -p $(COMPORT) -f build/$(UPLOAD_HEX).hex
terminal:
putty -serial $(COMPORT) -sercfg 38400,1,N,N
systeminfo:
@uname -a
@$(CC) --version
.PHONY: all test macro dump size systeminfo clean upload terminal
################################################################################
# Build The Project
################################################################################
## Preprocess
$(BUILD_DIR)/%.i: %.c Makefile | $(BUILD_DIR)
$(CC) -E $(C_INCLUDES) $< -o $@
## Compile
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR)
$(CC) -c $(ASMFLAGS) $< -o $@
## Link
$(TARGET_FILE:.hex=.elf): $(OBJECTS) $(APPOBJS) Makefile
$(CC) $(LDFLAGS) $(OBJECTS) $(APPOBJS) -o $@
$(TEST_TARGET:.hex=.elf): $(OBJECTS) $(TESTOBJ) Makefile
$(CC) $(LDFLAGS) $(OBJECTS) $(@:%.elf=%.o) -o $@
## Intel HEX format
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@
## Binary format
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(OBJCOPY) -O binary $< $@
## Archive
# $(BUILD_DIR)/libc4mrtos.a: $(OBJECTS)
# $(AR) rcs $@ $(OBJECTS)
## Eeprom format
$(BUILD_DIR)/%.eep: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(OBJCOPY) $(HEX_EEPROM_FLAGS) -O binary $< $@ || exit 0
## Disassemble
$(BUILD_DIR)/%.lss: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(OBJDUMP) -h -S $< > $@
## Symbol Table
$(BUILD_DIR)/%.sym: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(NM) -n $< > $@
## Make Directory
$(BUILD_DIR):
mkdir $@
################################################################################
# dependencies
################################################################################
-include $(wildcard $(BUILD_DIR)/*.d)