-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
142 lines (142 loc) · 5.81 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
NAME = app
#------------------------------------------------------------------------------
# Directories
#------------------------------------------------------------------------------
SRCDIR = src
OBJDIR = obj
RESDIR = res
BINDIR = bin
#------------------------------------------------------------------------------
# Files
#------------------------------------------------------------------------------
SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
#------------------------------------------------------------------------------
# Toolchain
#------------------------------------------------------------------------------
TRIPLE = arm-none-eabi-
CC = $(TRIPLE)gcc
AS = $(TRIPLE)as
LD = $(TRIPLE)ld
SZ = $(TRIPLE)size
OC = $(TRIPLE)objcopy
OD = $(TRIPLE)objdump
NM = $(TRIPLE)nm
#------------------------------------------------------------------------------
# Objcopy flags
#------------------------------------------------------------------------------
OCFLAGS += -g
OCFLAGS += -O
OCFLAGS += srec
#------------------------------------------------------------------------------
# Objdump flags
#------------------------------------------------------------------------------
ODFLAGS += -d
ODFLAGS += -S
#------------------------------------------------------------------------------
# Nm flags
#------------------------------------------------------------------------------
NMFLAGS += -n
#------------------------------------------------------------------------------
# Linker flags
#------------------------------------------------------------------------------
LDFLAGS += -T linkerscript.ld
LDFLAGS += --print-memory-usage
LDFLAGS += -Map $(RESDIR)/$(NAME).map
LDFLAGS += --gc-sections
#------------------------------------------------------------------------------
# Assembler flags
#------------------------------------------------------------------------------
ASFLAGS += -mthumb
ASFLAGS += -march=armv7e-m+fp
ASFLAGS += -mcpu=cortex-m4
ASFLAGS += -mfpu=fpv4-sp-d16
ASFLAGS += -mfloat-abi=hard
#------------------------------------------------------------------------------
# Compiler architecture flags
#------------------------------------------------------------------------------
CCFLAGS_ARCH += -mthumb
CCFLAGS_ARCH += -march=armv7e-m+fp
CCFLAGS_ARCH += -mtune=cortex-m4
CCFLAGS_ARCH += -mfpu=fpv4-sp-d16
CCFLAGS_ARCH += -mfloat-abi=hard
#------------------------------------------------------------------------------
# Compiler debugging flags
#------------------------------------------------------------------------------
CCFLAGS_DBG += -ggdb
#------------------------------------------------------------------------------
# Compiler optimization flags
#------------------------------------------------------------------------------
CCFLAGS_OPT += -Og
CCFLAGS_OPT += -ffunction-sections
CCFLAGS_OPT += -fdata-sections
#------------------------------------------------------------------------------
# Compiler warning flags
#------------------------------------------------------------------------------
CCLFAGS_WARN += -Wall
CCLFAGS_WARN += -Wextra
#------------------------------------------------------------------------------
# Compiler linking flags
#------------------------------------------------------------------------------
CCFLAGS_LINK += -nostartfiles
CCFLAGS_LINK += -nodefaultlibs
CCFLAGS_LINK += -nolibc
CCFLAGS_LINK += -nostdlib
#------------------------------------------------------------------------------
# Compiler directories flags
#------------------------------------------------------------------------------
CCFLAGS_DIR += -nostdinc
#------------------------------------------------------------------------------
# Compiler dialect flags
#------------------------------------------------------------------------------
CCFLAGS_DIAL += -std=c11
#------------------------------------------------------------------------------
# Compiler flags
#------------------------------------------------------------------------------
CCFLAGS += -ffreestanding
CCFLAGS += $(CCFLAGS_ARCH)
CCFLAGS += $(CCFLAGS_DBG)
CCFLAGS += $(CCFLAGS_OPT)
CCFLAGS += $(CCLFAGS_WARN)
CCFLAGS += $(CCFLAGS_LINK)
CCFLAGS += $(CCFLAGS_DIR)
CCFLAGS += $(CCFLAGS_DIAL)
#------------------------------------------------------------------------------
# Primary app target
#------------------------------------------------------------------------------
$(BINDIR)/$(NAME).elf: $(OBJDIR)/startup.o $(OBJECTS)
$(LD) $(LDFLAGS) $^ -o $@
$(OD) $(ODFLAGS) $@ > $(RESDIR)/$(NAME).lst
$(OC) $(OCFLAGS) $@ $(RESDIR)/$(NAME).srec
$(NM) $(NMFLAGS) $@ > $(RESDIR)/$(NAME).sym
#------------------------------------------------------------------------------
# Secondary startup target
#------------------------------------------------------------------------------
$(OBJDIR)/startup.o: startup.S
$(AS) $(ASFLAGS) $< -o $@
#------------------------------------------------------------------------------
# Secondary sources target
#------------------------------------------------------------------------------
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c $(SRCDIR)/%.h
$(CC) $(CCFLAGS) -c $< -o $@
#------------------------------------------------------------------------------
# Directories target
#------------------------------------------------------------------------------
directories:
mkdir -p $(OBJDIR)
mkdir -p $(RESDIR)
mkdir -p $(BINDIR)
#------------------------------------------------------------------------------
# Size target
#------------------------------------------------------------------------------
size:
$(SZ) $(OBJDIR)/*.o $(BINDIR)/$(NAME).elf
#------------------------------------------------------------------------------
# Clean target
#------------------------------------------------------------------------------
clean:
rm $(BINDIR)/*
rm $(OBJDIR)/*
rm $(RESDIR)/*
#------------------------------------------------------------------------------