forked from dirtyjtag/DirtyJTAG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
69 lines (50 loc) · 1.82 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
SUPPORTED_PLATFORMS = baite bluepill olimexstm32h103 stlinkv2 stlinkv2white
PLATFORM ?= bluepill
OBJS := src/dirtyjtag.$(PLATFORM).o src/jtag.$(PLATFORM).o src/usb.$(PLATFORM).o src/delay.$(PLATFORM).o src/cmd.$(PLATFORM).o
PREFIX ?= arm-none-eabi
TARGETS := stm32/f1
DEFS += -DSTM32F1
ARCH_FLAGS := -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd
LD_SCRIPT := ld/$(PLATFORM).ld
UCMX_DIR := $(realpath unicore-mx)
UCMX_INCLUDE_DIR := $(UCMX_DIR)/include
UCMX_LIB_DIR := $(UCMX_DIR)/lib
CFLAGS = -g -O2
CFLAGS += -Wall -Wextra -Werror
CFLAGS += -fno-common -ffunction-sections -fdata-sections
CFLAGS += -std=gnu11
CFLAGS += -DPLATFORM='HW_$(PLATFORM)'
CPPFLAGS = -MD -g
CPPFLAGS += -Wall -Wundef
CPPFLAGS += -I$(UCMX_INCLUDE_DIR) $(DEFS)
LDFLAGS += --static -nostartfiles
LDFLAGS += -L"$(UCMX_LIB_DIR)"
LDFLAGS += -T$(LD_SCRIPT)
LDFLAGS += -Wl,-Map=$(*).map
LDFLAGS += -Wl,--gc-sections # Remove deadcode
LDLIBS += -lucmx_stm32f1
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
CC := $(PREFIX)-gcc
LD := $(PREFIX)-ld
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
SIZE := $(PREFIX)-size
OBJCOPY := $(PREFIX)-objcopy
all: dirtyjtag
clean: dirtyjtag-clean ucmx-clean
dirtyjtag: src/dirtyjtag.$(PLATFORM).elf src/dirtyjtag.$(PLATFORM).bin
dirtyjtag-release: $(patsubst %, src/dirtyjtag.%.bin, $(SUPPORTED_PLATFORMS))
dirtyjtag-clean:
$(Q)$(RM) src/*.d src/*.o src/*.map src/*.bin src/*.elf *.bin *.elf
ucmx:
$(Q)$(MAKE) -C $(UCMX_DIR) lib/stm32/f1
ucmx-clean:
$(Q)$(MAKE) -C $(UCMX_DIR) clean
%.bin: %.elf
$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.elf %.map: $(OBJS) $(LD_SCRIPT)
$(Q)$(CC) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(*).elf
$(Q)$(SIZE) $(*).elf
%.$(PLATFORM).o: %.c | ucmx
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $<
.PHONY: clean dirtyjtag dirtyjtag-release dirtyjtag-clean ucmx ucmx-clean