-
Notifications
You must be signed in to change notification settings - Fork 30
/
Makefile
80 lines (61 loc) · 1.52 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
ENABLE_DEBUG ?=
ifneq ($(V), 1)
MAKEFLAGS += --no-print-dir
Q := @
endif
OPT_FLAGS ?= -O2
CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\
$(OPT_FLAGS) -std=gnu99 -g3 -MD \
-I.
LDFLAGS += $(OPT_FLAGS)
ifeq ($(ENABLE_DEBUG), 1)
CFLAGS += -DENABLE_DEBUG
endif
SRC = \
main.c \
platform.c \
cdcacm.c \
usbuart.c \
CROSS_COMPILE ?= arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
OPT_FLAGS = -Os
CFLAGS += -mcpu=cortex-m3 -mthumb \
-DSTM32F1 -DDISCOVERY_STLINK -I../libopencm3/include \
-I .
LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs \
-lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
-Wl,-T,bluepill.ld -nostartfiles -lc \
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
-L../libopencm3/lib
LDFLAGS = $(LDFLAGS_BOOT)
ifeq ($(ENABLE_DEBUG), 1)
LDFLAGS += --specs=rdimon.specs
else
LDFLAGS += --specs=nosys.specs
endif
all: blackmagic.bin
host_clean:
-$(Q)$(RM) blackmagic.bin
OBJ = $(SRC:.c=.o)
blackmagic.elf: version.h $(OBJ)
@echo " LD $@"
$(Q)$(CC) -o $@ $(OBJ) $(LDFLAGS)
%.o: %.c
@echo " CC $<"
$(Q)$(CC) $(CFLAGS) -c $< -o $@
%.bin: %.elf
@echo " OBJCOPY $@"
$(Q)$(OBJCOPY) -O binary $^ $@
%.hex: %
@echo " OBJCOPY $@"
$(Q)$(OBJCOPY) -O ihex $^ $@
.PHONY: clean host_clean FORCE
clean: host_clean
$(Q)echo " CLEAN"
-$(Q)$(RM) -f *.o *.d *~ blackmagic.elf $(HOSTFILES)
-$(Q)$(RM) -f mapfile version.h
version.h: FORCE
$(Q)echo " GIT version.h"
$(Q)echo "#define FIRMWARE_VERSION \"`git describe --always --dirty`\"" > $@
-include *.d