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