forked from ve3wwg/stm32f103c8t6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.incl
144 lines (111 loc) · 3.9 KB
/
Makefile.incl
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
######################################################################
# Rules etc. adapted from libopencm3
######################################################################
PREFIX ?= arm-none-eabi
TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
OPENCM3_DIR := $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/libopencm3)
LIBNAME = opencm3_stm32f1
DEFS += -DSTM32F1
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
ASFLAGS = -mthumb -mcpu=cortex-m3
CC := $(PREFIX)-gcc
CXX := $(PREFIX)-g++
LD := $(PREFIX)-gcc
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
OBJCOPY := $(PREFIX)-objcopy
SIZE := $(PREFIX)-size
OBJDUMP := $(PREFIX)-objdump
GDB := $(PREFIX)-gdb
STFLASH = $(shell which st-flash)
STYLECHECK := /checkpatch.pl
STYLECHECKFLAGS := --no-tree -f --terse --mailback
STYLECHECKFILES := $(shell find . -name '*.[ch]')
OPT := -Os -g
CSTD ?= -std=c99
TEMP1 = $(patsubst %.c,%.o,$(SRCFILES))
TEMP2 = $(patsubst %.asm,%.o,$(TEMP1))
OBJS = $(patsubst %.cpp,%.o,$(TEMP2))
LDSCRIPT ?= $(TOP_DIR)/stm32f103c8t6.ld
TGT_CFLAGS += $(OPT) $(CSTD)
TGT_CFLAGS += $(ARCH_FLAGS)
TGT_CFLAGS += -Wextra -Wshadow -Wimplicit-function-declaration
TGT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
TGT_CFLAGS += -fno-common -ffunction-sections -fdata-sections
TGT_CFLAGS += -I$(OPENCM3_DIR)/include
TGT_CFLAGS += -I$(TOP_DIR)/rtos/libwwg/include
TGT_CXXFLAGS += $(OPT) $(CXXSTD)
TGT_CXXFLAGS += $(ARCH_FLAGS)
TGT_CXXFLAGS += -Wextra -Wshadow -Wredundant-decls -Weffc++
TGT_CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
TGT_CPPFLAGS += -MD
TGT_CPPFLAGS += -Wall -Wundef
TGT_CPPFLAGS += $(DEFS)
TGT_CPPFLAGS += -I$(OPENCM3_DIR)/include
TGT_CPPFLAGS += -I$(TOP_DIR)/rtos/libwwg/include
TGT_LDFLAGS += --static -nostartfiles
TGT_LDFLAGS += -T$(LDSCRIPT)
TGT_LDFLAGS += $(ARCH_FLAGS)
TGT_LDFLAGS += -Wl,-Map=$(*).map
TGT_LDFLAGS += -Wl,--gc-sections
LDLIBS += -specs=nosys.specs
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
LDLIBS += -L$(TOP_DIR)/rtos/libwwg -lwwg
LDLIBS += -L$(OPENCM3_DIR)/lib -lopencm3_stm32f1
.SUFFIXES: .elf .bin .hex .srec .list .map .images
.SECONDEXPANSION:
.SECONDARY:
elf: $(DEPS) $(BINARY).elf
bin: $(DEPS) $(BINARY).bin
hex: $(DEPS) $(BINARY).hex
srec: $(DEPS) $(BINARY).srec
list: $(DEPS) $(BINARY).list
# Define a helper macro for debugging make errors online
# you can type "make print-OPENCM3_DIR" and it will show you
# how that ended up being resolved by all of the included
# makefiles.
print-%:
@echo $*=$($*)
%.images: %.bin %.hex %.srec %.list %.map
@#printf "*** $* images generated ***\n"
%.bin: %.elf
@#printf " OBJCOPY $(*).bin\n"
$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.hex: %.elf
@#printf " OBJCOPY $(*).hex\n"
$(OBJCOPY) -Oihex $(*).elf $(*).hex
%.srec: %.elf
@#printf " OBJCOPY $(*).srec\n"
$(OBJCOPY) -Osrec $(*).elf $(*).srec
%.list: %.elf
@#printf " OBJDUMP $(*).list\n"
$(OBJDUMP) -S $(*).elf > $(*).list
%.elf %.map: $(OBJS) $(LDSCRIPT)
$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(*).elf
$(SIZE) $(BINARY).elf
%.o: %.c
@#printf " CC $(*).c\n"
$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).c
%.o: %.cxx
@#printf " CXX $(*).cxx\n"
$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cxx
%.o: %.cpp
@#printf " CXX $(*).cpp\n"
$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cpp
%.o: %.asm
$(AS) $(ASFLAGS) -o $*.o -c $<
clean:
@#printf " CLEAN\n"
$(RM) *.o *.d generated.* $(OBJS) $(patsubst %.o,%.d,$(OBJS))
clobber: clean
rm -f *.elf *.bin *.hex *.srec *.list *.map $(CLOBBER)
# Flash 64k Device
flash: $(BINARY).bin
$(STFLASH) $(FLASHSIZE) write $(BINARY).bin 0x8000000
# Flash 128k Device
bigflash: $(BINARY).bin
$(STFLASH) --flash=128k write $(BINARY).bin 0x8000000
.PHONY: images clean elf bin hex srec list all
-include $(OBJS:.o=.d)
# End