-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
208 lines (172 loc) · 4.99 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#******************************************************************************
#
#
TARGET := freertos
ODIR ?= build
OBJODIR := $(ODIR)/obj
# A simple variant is to prefix commands with $(Q) - that's useful
# for commands that shall be hidden in non-verbose mode.
#
# $(Q)ln $@ :<
#
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
else
BUILD_VERBOSE = 0
endif
ifeq ($(BUILD_VERBOSE),1)
Q =
else
Q = @
endif
# Do not print "Entering directory ...",
# but we want to display it when entering to the output directory
# so that IDEs/editors are able to understand relative filenames.
MAKEFLAGS += --no-print-directory
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is arm-none-eabi-
CROSS_COMPILE ?=
# Make variables (CC, etc...)
AS = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)gcc
CXX = $(CC)
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
SIZE = $(CROSS_COMPILE)size
# File System Utilities
MKDIR = mkdir -p
RM = rm -f
MV = mv -f
LDFILES :=
LIBS := -lpthread
BIN2OBJ := -I binary -O elf32-littlearm -B arm --rename-section .data=.rodata
CPUFLAGS :=
COMMONFLAGS := \
-g3 -O2 \
-fmessage-length=0 \
-ffunction-sections \
-fdata-sections \
-fsigned-char \
-fsingle-precision-constant \
-Wfloat-equal \
-Wuninitialized \
-Wextra \
-Wall
CCFLAGS := \
-std=gnu11
CPPFLAGS := \
-std=c++1y \
-fno-rtti \
-fno-exceptions
LDFLAGS := \
-Wl,-Map="$(ODIR)/$(TARGET).map" \
-Wl,--gc-sections \
-Wl,--print-memory-usage
COMPONENT_PATH=FreeRTOS
include $(COMPONENT_PATH)/component.mk
INCLUDES += $(COMPONENT_INCLUDES)
#******************************************************************************
# Header File
INCLUDES += -I ./
#******************************************************************************
# C File
CSRCS += main.c
#******************************************************************************
# CPP File
CPPSRCS +=
#******************************************************************************
# ASM File (*.S)
ASRCS +=
#******************************************************************************
# ASM File (*.s)
ASRCs +=
#******************************************************************************
# Binary resource (*)
BSRC +=
COMPONENT_OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
$(CPPSRCS:%.cpp=$(OBJODIR)/%.o) \
$(ASRCs:%.s=$(OBJODIR)/%.o) \
$(ASRCS:%.S=$(OBJODIR)/%.o) \
$(BSRC:%=$(OBJODIR)/%)
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
$(CPPSRCS:%.cpp=$(OBJODIR)/%.d) \
$(ASRCs:%.s=$(OBJODIR)/%.d) \
$(ASRCS:%.S=$(OBJODIR)/%.d)
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
$(CPPSRCS:%.cpp=$(OBJODIR)/%.o) \
$(ASRCs:%.s=$(OBJODIR)/%.o) \
$(ASRCS:%.S=$(OBJODIR)/%.o) \
$(BSRC:%=$(OBJODIR)/%)
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
$(CPPSRCS:%.cpp=$(OBJODIR)/%.d) \
$(ASRCs:%.s=$(OBJODIR)/%.d) \
$(ASRCS:%.S=$(OBJODIR)/%.d)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),disasm)
ifdef DEPS
sinclude $(DEPS)
endif
endif
endif
$(OBJODIR)/%.o: %.c
@echo [CC] $<
$(Q)$(MKDIR) $(dir $@)
$(Q)$(CC) -MT $@ -MMD -MP -MF $(OBJODIR)/$*.Td $(CPUFLAGS) $(COMMONFLAGS) $(CCFLAGS) $(INCLUDES) -c -o $@ $<
$(Q)$(MV) $(OBJODIR)/$*.Td $(OBJODIR)/$*.d && touch $@
$(OBJODIR)/%.o: %.cpp
@echo [CXX] $<
$(Q)$(MKDIR) $(dir $@)
$(Q)$(CXX) -MT $@ -MMD -MP -MF $(OBJODIR)/$*.Td $(CPUFLAGS) $(COMMONFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o $@ $<
$(Q)$(MV) $(OBJODIR)/$*.Td $(OBJODIR)/$*.d && touch $@
$(OBJODIR)/%.o: %.s
@echo [AS] $<
$(Q)$(MKDIR) $(dir $@)
$(Q)$(AS) $(CFLAGS) -M -o $(OBJODIR)/$*.d $<
$(Q)$(AS) $(CFLAGS) -MMD -MP -MF $(OBJODIR)/$*.d -MT$@ -c -o $@ $<
$(OBJODIR)/%.o: %.S
@echo [AS] $<
$(Q)$(MKDIR) $(dir $@)
$(Q)$(AS) $(CFLAGS) -M -o $(OBJODIR)/$*.d $<
$(Q)$(AS) $(CFLAGS) -MMD -MP -MF $(OBJODIR)/$*.d -MT$@ -c -o $@ $<
$(OBJODIR)/%: %
@echo [OBJCOPY] $<
$(Q)$(MKDIR) $(dir $@)
$(Q)$(OBJCOPY) $(BIN2OBJ) $< $@
#******************************************************************************
# Targets
#
PHONY += all
all: $(OBJS)
$(Q)$(LD) $(CPUFLAGS) $(LDFLAGS) $(LDFILES) $(OBJS) $(LIBS) -o $(ODIR)/$(TARGET).elf
@echo $(CSRCS)
@echo ' '
@echo $(OBJS)
@echo ' '
@echo $(INCLUDES)
@echo 'all finish'
PHONY += clean
clean:
$(Q)$(RM) -r $(ODIR)
@echo 'clean finish'
PHONY += listc
listc:
@echo $(CSRCS) $(CPPSRCS) $(CASRCS)
# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
# Set default target
.DEFAULT_GOAL:= all