]> mj.ucw.cz Git - home-hw.git/blob - test-opencm3/Makefile
11acf15ddda38a83158b82742824f264ef08bea0
[home-hw.git] / test-opencm3 / Makefile
1 BINARY=test
2 OBJS=test.o
3
4 OPENCM3_DIR=/home/mj/stm/libopencm3
5 DEVICE=stm32f103x8
6
7 all: $(BINARY).elf $(BINARY).bin
8
9 flash: all
10         ../bin/st-flash write $(BINARY).bin 0x8000000
11
12 ifneq ($(V),1)
13 Q               := @
14 NULL            := 2>/dev/null
15 endif
16
17 include $(OPENCM3_DIR)/mk/genlink-config.mk
18
19 PREFIX          ?= arm-none-eabi
20
21 CC              := $(PREFIX)-gcc
22 CXX             := $(PREFIX)-g++
23 LD              := $(PREFIX)-gcc
24 AR              := $(PREFIX)-ar
25 AS              := $(PREFIX)-as
26 OBJCOPY         := $(PREFIX)-objcopy
27 OBJDUMP         := $(PREFIX)-objdump
28 GDB             := $(PREFIX)-gdb
29 OPT             := -Os
30 DEBUG           := -ggdb3
31 CSTD            ?= -std=c99
32
33 TGT_CFLAGS      += $(OPT) $(CSTD) $(DEBUG)
34 TGT_CFLAGS      += $(ARCH_FLAGS)
35 TGT_CFLAGS      += -Wall -Wextra -Wshadow -Wimplicit-function-declaration
36 TGT_CFLAGS      += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
37 TGT_CFLAGS      += -fno-common -ffunction-sections -fdata-sections
38
39 TGT_CPPFLAGS    += -MD
40
41 TGT_LDFLAGS     += --static -nostartfiles
42 TGT_LDFLAGS     += -T$(LDSCRIPT)
43 TGT_LDFLAGS     += $(ARCH_FLAGS) $(DEBUG)
44 TGT_LDFLAGS     += -Wl,-Map=$(*).map -Wl,--cref
45 TGT_LDFLAGS     += -Wl,--gc-sections
46 ifeq ($(V),99)
47 TGT_LDFLAGS     += -Wl,--print-gc-sections
48 endif
49
50 LDLIBS          += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
51
52 include $(OPENCM3_DIR)/mk/genlink-rules.mk
53
54 %.bin: %.elf
55         @printf "  OBJCOPY $(*).bin\n"
56         $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
57
58 %.elf: $(OBJS) $(LDSCRIPT)
59         @printf "  LD      $(*).elf\n"
60         $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $*.elf
61
62 %.o: %.c
63         @printf "  CC      $(*).c\n"
64         $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $*.o -c $*.c
65
66 .PHONY: clean
67 clean:
68         @printf "  CLEAN\n"
69         $(Q)rm -f *.elf *.bin *.o *.d *.map $(LDSCRIPT)
70
71 %.stlink-flash: %.bin
72         @printf "  FLASH  $<\n"
73         $(STFLASH) write $(*).bin 0x8000000
74
75 .SECONDEXPANSION:
76 .SECONDARY:
77
78 -include $(OBJS:.o=.d)