-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
129 lines (104 loc) · 3.15 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
#BOARD := DISCOVERY
#BOARD := NUCLEO
FPU := ENABLED
PROJ := OS1F
ARM-PATH := /opt/arm/toolchain
#OOCD-PATH := /opt/openocd
# COMMANDS
CC := $(ARM-PATH)/bin/arm-none-eabi-gcc
GDB := $(ARM-PATH)/bin/arm-none-eabi-gdb-py
OBJDUMP := $(ARM-PATH)/bin/arm-none-eabi-objdump
SIZE := $(ARM-PATH)/bin/arm-none-eabi-size
OPENOCD := openocd #$(OOCD-PATH)/bin/openocd
OUT := BUILD
INC_DIRS :=
SRC_DIRS :=
SRCS :=
OBJS :=
DEPS :=
-include aux/make/sources_auto.mk
FINAL := $(OUT)/$(PROJ)
ELF := $(FINAL).elf
##==================================================
## DEFINES
##==================================================
# TODO: implement non-printf trace functions
DEFINES := -DUSE_HAL_DRIVER -DSTM32F746xx
#DEFINEs += -DOS_USE_TRACE_ITM
DEFINES += -DDEBUG -DTRACE
#DEFINES += -DOS_USE_SEMIHOSTING -DOS_USE_TRACE_SEMIHOSTING_DEBUG
DEFINES += -DOS_USE_VCP
DEFINES += -DOS_USE_LCD
#ifeq ($(BOARD),DISCOVERY)
#DEFINES += -DBOARD_DISCOVERY
#else
#DEFINES += -DBOARD_NUCLEO
#endif
ARCH := -mcpu=cortex-m7 -mthumb
ifeq ($(FPU),ENABLED)
ARCH += -mfloat-abi=hard -mfpu=fpv5-sp-d16
DEFINES += -DENABLE_FPU
else
ARCH += -mfloat-abi=soft
endif
##==================================================
## CFLAGS
##==================================================
CFLAGS := $(ARCH) -Og -g3 -gdwarf-2 -std=c11
CFLAGS += -Wall -Wextra -Wfatal-errors -pedantic -Wno-unused-parameter
CFLAGS += -fsigned-char -ffunction-sections -fdata-sections -ffreestanding
##CFLAGS += -flto
CFLAGS += -fno-inline -fno-omit-frame-pointer -funwind-tables -mpoke-function-name
##==================================================
## INCLUDES
##==================================================
INCLUDES := $(addprefix -I, $(INC_DIRS))
##==================================================
## PREPROC -- preprocessor flags
##==================================================
PREPROC = $(DEFINES) -MMD -MP -MF$(@:%.o=%.d) -MT$(@)
##==================================================
## LDFLAGS
##==================================================
## NOTE: use deferred assignment here
LDFLAGS = $(ARCH) -Wl,-Map,$(OUT)/$*.map -Wl,--gc-sections,--print-memory-usage
LDFLAGS += -Tconfig/STM32F746NG_FLASH.ld -nostartfiles --specs=nano.specs -lc -lg -lm
## for semihosting
#LDFLAGS += --specs=rdimon.specs -lrdimon
vpath %.c $(SRC_DIRS)
vpath %.S $(SRC_DIRS)
vpath %.h $(INC_DIRS)
all: $(FINAL).siz $(FINAL).disass;
analyze: CFLAGS += -fstack-usage
analyze: $(OBJS)
## disassembly
$(OUT)/%.disass: $(ELF)
$(OBJDUMP) -dS $< > $@
## Print Size
$(OUT)/%.siz: $(ELF)
$(SIZE) --format=berkeley $<
## Check for missing symbols
link-check: LDFLAGS := --specs=nosys.specs
link-check: $(OBJS)
$(CC) $(LDFLAGS) -o $(OUT)/link-check $(OBJS)
## Build ELF file
$(OUT)/%.elf: $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS)
## Build Object files from S files
$(OUT)/%.o: %.S
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(PREPROC) $(INCLUDES) -c -o $@ $<
## Build Object files from C files
$(OUT)/%.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(PREPROC) $(INCLUDES) -c -o $@ $<
JUNK := `find . | grep '\~'`
clean:
@rm -fr $(OUT)
@rm -f $(JUNK)
@rm -f src/*.lst
stuff:
@echo "$(OBJS)"
-include aux/make/openocd.mk
-include $(DEPS)
.SECONDARY: