-
Notifications
You must be signed in to change notification settings - Fork 22
/
common.mk
112 lines (87 loc) · 2.46 KB
/
common.mk
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
##
# Common settings for Makefiles
#
# Stefan Wendler, [email protected]
##
#
# compiler prefix
ifeq ($(TARCH),MSP430)
PREFIX ?= msp430-
else
PREFIX ?= arm-none-eabi-
endif
CC = $(PREFIX)gcc
LD = $(PREFIX)gcc
OBJCOPY = $(PREFIX)objcopy
OBJDUMP = $(PREFIX)objdump
ifeq ($(TARCH),MSP430)
INCDIR += -I./include
CFLAGS += -Os -g -mmcu=msp430g2553 -Wall -Wextra $(INCDIR)
LDFLAGS += -mmcu=msp430g2553 $(LIBDIR) $(LIBS)
else
INCDIR += -I./include -I$(HOME)/sat/arm-none-eabi/include
CFLAGS += -Os -g -Wall -Wextra -fno-common -mcpu=cortex-m3 -mthumb -msoft-float -MD $(INCDIR) -DSTM32F1
LDSCRIPT ?= $(BINARY).ld
LIBDIR += -L$(HOME)/sat/arm-none-eabi/lib -L$(HOME)/sat/arm-none-eabi/lib/stm32/f1
LIBS += -lopencm3_stm32f1
LDFLAGS += $(LIBDIR) $(LIBS) -T$(LDSCRIPT) -nostartfiles -Wall -mthumb -march=armv7 -mfix-cortex-m3-ldrd -msoft-float
endif
# where to put generated binaries to
BINDIR ?= ../bin
# doxygen executable
DOXYGEN = doxygen
# doxygen flags
DOXYGENFLAGS = ../doxygen.conf
# styler to use
STYLER = astyle
# which c-style to use
# - see man astyle
STYLERFLAGS = --style=stroustrup
# cpp checker
CHECKER = cppcheck
# flags for checker
# CHECKERFLAGS = --error-exitcode=1 --enable=all
CHECKERFLAGS = --enable=all --error-exitcode=1
.SUFFIXES: .elf .bin .hex .srec .list .images
.SECONDEXPANSION:
.SECONDARY:
all: images
images: $(BINARY).images
%.images: %.bin %.hex %.srec %.list
@#echo "*** $* images generated ***"
%.bin: %.elf
@#printf " OBJCOPY $(*).bin\n"
$(OBJCOPY) -Obinary $(*).elf $(*).bin && cp $(*).bin $(BINDIR)/.
%.hex: %.elf
@#printf " OBJCOPY $(*).hex\n"
$(OBJCOPY) -Oihex $(*).elf $(*).hex && cp $(*).hex $(BINDIR)/.
%.srec: %.elf
@#printf " OBJCOPY $(*).srec\n"
$(OBJCOPY) -Osrec $(*).elf $(*).srec && cp $(*).srec $(BINDIR)/.
%.list: %.elf
@#printf " OBJDUMP $(*).list\n"
$(OBJDUMP) -S $(*).elf > $(*).list && cp $(*).list $(BINDIR)/.
%.elf: $(OBJS) $(LDSCRIPT)
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
$(LD) $(OBJS) $(LDFLAGS) -o $(*).elf && cp $(*).elf $(BINDIR)/.
%.o: %.c Makefile
@#printf " CC $(subst $(shell pwd)/,,$(@))\n"
$(CC) $(CFLAGS) -o $@ -c $<
%.o: %.cpp Makefile
@#printf " CC $(subst $(shell pwd)/,,$(@))\n"
$(CC) $(CFLAGS) -o $@ -c $<
SRC = $(wildcard *.c)
HDR = $(wildcard include/*.h)
style:
$(STYLER) $(STYLERFLAGS) $(SRC)
$(STYLER) $(STYLERFLAGS) $(HDR)
clean:
rm -f *.o
rm -f *.d
rm -f *.elf
rm -f *.bin
rm -f *.hex
rm -f *.srec
rm -f *.list
rm -f *.orig
.PHONY: images clean