-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakefile
310 lines (261 loc) · 8.41 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#
# Makefile for GCC ARM.
#
# Based on Aktiv JCS makefile from Guardant Code example application.
#
# Kovalenko Igor / 2017
#
# On command line:
#
# "make all" - Make software.
# "make clean" - Clean out built project files.
# "make filename" - Just compile filename into the assembler code only.
#
# To rebuild project do "make clean" then "make all".
#
# Path of include files:
CFG_INCLUDE_DIR = /gccarm/arm-none-eabi/include
# Path of library:
CFG_LIB_DIR = /gccarm/arm-none-eabi/lib/thumb/v6-m
# Path of service utils:
CFG_GCC_DIR = /gccarm/bin/
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level!)
#OPT = 0
#OPT = 1
OPT = 2
#OPT = s
#
# !!!!!
# Íà óðîâíå îïòèìèçàöèè -Os, åñòü ïðîáëåìû ñ âûðàâíèâàíèåì ñòðóêòóð â ïàìÿòè.
# !!!!!
#
# List C source files here:
SRC = bcomp.c
SRC += adc.c
SRC += analog.c
SRC += bconfig.c
SRC += beep.c
SRC += buttons.c
SRC += can.c
SRC += config.c
SRC += crc8.c
#SRC += drive.c
SRC += eeprom.c
#SRC += elog.c
SRC += errors.c
SRC += event.c
#SRC += graph.c
SRC += i2c.c
SRC += leds.c
#SRC += lzss.c
#SRC += menu.c
#SRC += nmea.c
SRC += obd.c
#SRC += oled128.c
#SRC += oled128_sh1106.c
#SRC += oled128_ssd1306.c
SRC += printf.c
SRC += sounds.c
SRC += system_LPC11xx.c
SRC += timer.c
SRC += virtuino.c
SRC += uart0.c
#SRC += warning.c
#SRC += wheels.c
#SRC += ./fonts/font12x16.c
#SRC += ./fonts/font6x8.c
#SRC += ./icons/icons11.c
# List C++ source files here:
# Use file-extension cpp for C++-files!
#CPPSRC = module1.cpp
#CPPSRC += module2.cpp
#CPPSRC += module3.cpp
#CPPSRC += module4.cpp
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
#ASRC = asm1.s
#ASRC += asm2.s
#ASRC += asm3.s
# MCU name:
MCU = cortex-m0
# Output format (can be srec, ihex, binary):
FORMAT = ihex
# Target file name (without extension):
TARGET = SAMPLE
# Linker Script Name:
LDSCRIPT = rom
# Startup File Name:
ASTARTUP = startup_LPC11xx_gcc
# ARM Toolchain Prefix
ARM_TOOLS_PREFIX = arm-none-eabi
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS = ./ ./arm $(CFG_INCLUDE_DIR)
# Startup file into ASM sources:
ASRC = $(ASTARTUP).s
# Full List of sources:
ALLSRC = $(SRC) $(CPPSRC) $(ASRC)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options for C here:
CDEFS = -D__GCC__ -D__ARM__ -DCORTEX -D_LPC1100_ -DCFG_GCC
# Place -I options here:
CINCS =
# Place -D or -U options for ASM here:
ADEFS =
# Compiler flags.
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums -fpack-struct
CFLAGS += -Wall -Wcast-align -Wcast-qual -Wimplicit
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += -Wpointer-arith -Wswitch
CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
CFLAGS += -Wno-pragmas -Wno-main
CFLAGS += -fdata-sections -ffunction-sections
# flags only for C
# Turn on any warnings:
CONLYFLAGS = -Wnested-externs -Wstrict-prototypes
#CONLYFLAGS += -Wmissing-prototypes -Wnested-externs -Wmissing-declarations
# no listings
#CONLYFLAGS += -Wa,-adhmlns=.lst/$(<:.c=.lst)
CONLYFLAGS += $(CSTANDARD)
# flags only for C++ (g++)
#CPPFLAGS = -Wa,-adhmlns=.lst/$(<:.cpp=.lst)
CPPFLAGS = -lg -lm -lstdc++
CPPFLAGS += -fno-rtti -fno-exceptions -fno-use-cxa-atexit
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# no listings
#ASFLAGS = $(ADEFS) -Wa,-adhlns=.lst/$(<:.s=.lst),-gstabs
# Linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -nostartfiles -Wl,-Map=.out_gcc/$(TARGET).map,--cref
LDFLAGS += -lc -lm -lgcc -L./ -L$(CFG_LIB_DIR) -mthumb-interwork
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -T$(LDSCRIPT).ld
# Define programs and commands.
CC = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-gcc
CPP = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-g++
AS = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-as
OBJCOPY = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-objcopy
OBJDUMP = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-objdump
SIZE = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-size
NM = $(CFG_GCC_DIR)$(ARM_TOOLS_PREFIX)-nm
REMOVE = rm -f
COPY = cp
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE = Size:
MSG_FLASH = Creating hex file:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.s=.o) $(CPPSRC:.cpp=.o)
# Define all listing files.
LST = $(ASRC:.s=.lst) $(SRC:.c=.lst) $(SRCT:.c=.lst) $(CPPSRC:.cpp=.lst)
# Compiler flags to generate dependency files.
FTEMP = $(@F)
GENDEPFLAGS = -MD -MP -MF .dep/$(FTEMP:.o=.o.d)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mcpu=$(MCU) -mthumb -mthumb-interwork -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mcpu=$(MCU) -mthumb -mthumb-interwork -I. $(ASFLAGS)
# Default target.
all: begin prebuild build postbuild sizeafter finished end
# Build target.
build: elf hex
# Link: create ELF output file from object files.
elf: $(OBJ)
$(CC) -c $(ALL_ASFLAGS) $(ASRC) -o .obj/$(ASRC:.s=.o)
@echo $(MSG_LINKING) .out_gcc/$(TARGET).elf
$(CC) $(ALL_CFLAGS) $(addprefix .obj/,$(OBJ)) --output .out_gcc/$(TARGET).elf $(LDFLAGS)
hex:
@echo
@echo $(MSG_FLASH) hex
$(OBJCOPY) -O $(FORMAT) .out_gcc/$(TARGET).elf .out_gcc/$(TARGET).hex
# Eye candy.
begin:
@echo $(MSG_BEGIN)
# Files check.
prebuild:
@if [ ! -e .dep ]; then mkdir .dep; fi;
@if [ ! -e .obj ]; then mkdir .obj; fi;
@if [ ! -e .obj/fonts ]; then mkdir .obj/fonts; fi;
@if [ ! -e .obj/icons ]; then mkdir .obj/icons; fi;
@if [ ! -e .lst ]; then mkdir .lst; fi;
@if [ ! -e .out_gcc ]; then mkdir .out_gcc; fi;
postbuild:
$(OBJDUMP) -xD .out_gcc/$(TARGET).ELF --disassembler-options=force-thumb > .out_gcc/$(TARGET).asm
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) .out_gcc/$(TARGET).hex
ELFSIZE = $(SIZE) -A .out_gcc/$(TARGET).elf
sizeafter:
@if [ -f .out_gcc/$(TARGET).elf ]; then echo; echo $(MSG_SIZE); $(ELFSIZE); fi;
# Compile: create object files from C source files.
%.o : %.c
@echo $(MSG_COMPILING) $@ $<
$(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o .obj/$(@:.o=.o)
# Compile: create object files from C++ source files.
%.o : %.cpp
@echo $(MSG_COMPILINGCPP) $<
$(CPP) -c $(ALL_CFLAGS) $(CPPFLAGS) $< -o .obj/$(@:.o=.o)
# Assemble: create object files from assembler source files.
%.o : %.s
@echo
@echo $(MSG_ASSEMBLING) $<
@if [ -e ".obj" ]; then $(CC) -c $(ALL_ASFLAGS) $< -o .obj/$(@:.o=.o) ; fi;
# Target: clean project.
clean: begin clean_list finished end
clean_list:
@echo
@echo $(MSG_CLEANING)
$(REMOVE) -r .out_gcc
$(REMOVE) -r .lst
$(REMOVE) -r .obj
$(REMOVE) -r .dep
mkdir .out_gcc
mkdir .obj
mkdir .obj/fonts
mkdir .obj/icons
mkdir .lst
mkdir .dep
# Listing of phony targets.
.PHONY: all begin finish end sizeafter gccversion \
prebuild build elf hex lss sym clean clean_list finished end