-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
92 lines (67 loc) · 2.16 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
PROGRAM = stm32-freqmeter
CROSS = arm-none-eabi
LDSCRIPT = libopencm3/lib/stm32/f1/stm32f103x8.ld
SERIAL = /dev/ttyUSB0
OBJS = freqmeter.o \
usbcdc.o \
DOCS = README.html \
addons/README.html \
addons/femtocom/README.html \
addons/henrymeter/README.html \
###############################################################################
CC = $(CROSS)-gcc
LD = $(CROSS)-ld
OBJCOPY = $(CROSS)-objcopy
OBJDUMP = $(CROSS)-objdump
SIZE = $(CROSS)-size
ELF = $(PROGRAM).elf
BIN = $(PROGRAM).bin
HEX = $(PROGRAM).hex
MAP = $(PROGRAM).map
DMP = $(PROGRAM).out
DEFS = -DSTM32F1
INCS = -Ilibopencm3/include/
FP_FLAGS = -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
CFLAGS += -Os -Wall -g
#CFLAGS += -Wextra
CFLAGS += -fno-common -ffunction-sections -fdata-sections
CFLAGS += $(ARCH_FLAGS) $(DEFS) $(INCS)
LDPATH = libopencm3/lib/
LIBM = $(shell $(CC) $(CFLAGS) --print-file-name=libm.a)
LIBC = $(shell $(CC) $(CFLAGS) --print-file-name=libc.a)
LIBNOSYS = $(shell $(CC) $(CFLAGS) --print-file-name=libnosys.a)
LIBGCC = $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)
LIBOPENCM3 = $(LDPATH)/libopencm3_stm32f1.a
LDFLAGS += -L$(LDPATH) -T$(LDSCRIPT) -Map $(MAP) --gc-sections
LDLIBS += $(LIBOPENCM3) $(LIBC) $(LIBNOSYS) $(LIBGCC)
all: $(LDPATH)$(LIBOPENCM3) $(BIN) $(HEX) $(DMP) size
$(ELF): $(LDSCRIPT) $(OBJS)
$(LD) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS)
$(DMP): $(ELF)
$(OBJDUMP) -d $< > $@
%.hex: %.elf
$(OBJCOPY) -S -O ihex $< $@
%.bin: %.elf
$(OBJCOPY) -S -O binary $< $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.html: %.md
markdown $< > $@
$(LDPATH)$(LIBOPENCM3):
git submodule init
git submodule update --remote
make -C libopencm3 lib/stm32/f1
.PHONY: clean distclean flash size
clean:
rm -f $(OBJS) $(DOCS) $(ELF) $(HEX) $(BIN) $(MAP)
distclean: clean
make -C libopencm3 clean
rm -f *~ *.swp
flash: $(HEX)
stm32flash -w $< -v $(SERIAL)
size: $(PROGRAM).elf
@echo ""
@$(SIZE) $(PROGRAM).elf
@echo ""
docs: $(DOCS)