forked from jkovacic/FreeRTOS-GCC-ARM926ejs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
215 lines (154 loc) · 6.57 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
# Copyright 2013, 2017, Jernej Kovacic
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software. If you wish to use our Amazon
# FreeRTOS name, please do so in a fair use way that does not cause confusion.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Type "make help" for more details.
#
# Version "6-2017-q2-update" of the "GNU Arm Embedded Toolchain" is used
# as a build tool. See comments in "setenv.sh" for more details about
# downloading it and setting the appropriate environment variables.
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CXX = $(TOOLCHAIN)g++
AS = $(TOOLCHAIN)as
LD = $(TOOLCHAIN)ld
OBJCOPY = $(TOOLCHAIN)objcopy
AR = $(TOOLCHAIN)ar
# GCC flags
CFLAG = -c
OFLAG = -o
INCLUDEFLAG = -I
CPUFLAG = -mcpu=arm926ej-s
WFLAG = -Wall -Wextra -Werror
CFLAGS = $(CPUFLAG) $(WFLAG)
# Additional C compiler flags to produce debugging symbols
DEB_FLAG = -g -DDEBUG
# Compiler/target path in FreeRTOS/Source/portable
PORT_COMP_TARG = GCC/ARM926EJ-S/
# Intermediate directory for all *.o and other files:
OBJDIR = obj/
# FreeRTOS source base directory
FREERTOS_SRC = FreeRTOS/Source/
# Directory with memory management source files
FREERTOS_MEMMANG_SRC = $(FREERTOS_SRC)portable/MemMang/
# Directory with platform specific source files
FREERTOS_PORT_SRC = $(FREERTOS_SRC)portable/$(PORT_COMP_TARG)
# Directory with HW drivers' source files
DRIVERS_SRC = drivers/
# Directory with demo specific source (and header) files
APP_SRC = Demo/
# Object files to be linked into an application
# Due to a large number, the .o files are arranged into logical groups:
FREERTOS_OBJS = queue.o list.o tasks.o
# The following o. files are only necessary if
# certain options are enabled in FreeRTOSConfig.h
#FREERTOS_OBJS += timers.o
#FREERTOS_OBJS += croutine.o
#FREERTOS_OBJS += event_groups.o
#FREERTOS_OBJS += stream_buffer.o
# Only one memory management .o file must be uncommented!
FREERTOS_MEMMANG_OBJS = heap_1.o
#FREERTOS_MEMMANG_OBJS = heap_2.o
#FREERTOS_MEMMANG_OBJS = heap_3.o
#FREERTOS_MEMMANG_OBJS = heap_4.o
#FREERTOS_MEMMANG_OBJS = heap_5.o
FREERTOS_PORT_OBJS = port.o portISR.o
STARTUP_OBJ = startup.o
DRIVERS_OBJS = timer.o interrupt.o uart.o
APP_OBJS = init.o main.o print.o receive.o
# nostdlib.o must be commented out if standard lib is going to be linked!
APP_OBJS += nostdlib.o
# All object files specified above are prefixed the intermediate directory
OBJS = $(addprefix $(OBJDIR), $(STARTUP_OBJ) $(FREERTOS_OBJS) $(FREERTOS_MEMMANG_OBJS) $(FREERTOS_PORT_OBJS) $(DRIVERS_OBJS) $(APP_OBJS))
# Definition of the linker script and final targets
LINKER_SCRIPT = $(addprefix $(APP_SRC), qemu.ld)
ELF_IMAGE = image.elf
TARGET = image.bin
# Include paths to be passed to $(CC) where necessary
INC_FREERTOS = $(FREERTOS_SRC)include/
INC_DRIVERS = $(DRIVERS_SRC)include/
# Complete include flags to be passed to $(CC) where necessary
INC_FLAGS = $(INCLUDEFLAG)$(INC_FREERTOS) $(INCLUDEFLAG)$(APP_SRC) $(INCLUDEFLAG)$(FREERTOS_PORT_SRC)
INC_FLAG_DRIVERS = $(INCLUDEFLAG)$(INC_DRIVERS)
# Dependency on HW specific settings
DEP_BSP = $(INC_DRIVERS)bsp.h
#
# Make rules:
#
all : $(TARGET)
rebuild : clean all
$(TARGET) : $(OBJDIR) $(ELF_IMAGE)
$(OBJCOPY) -O binary $(word 2,$^) $@
$(OBJDIR) :
mkdir -p $@
$(ELF_IMAGE) : $(OBJS) $(LINKER_SCRIPT)
$(LD) -nostdlib -L $(OBJDIR) -T $(LINKER_SCRIPT) $(OBJS) $(OFLAG) $@
debug : _debug_flags all
debug_rebuild : _debug_flags rebuild
_debug_flags :
$(eval CFLAGS += $(DEB_FLAG))
# Startup code, implemented in assembler
$(OBJDIR)startup.o : $(APP_SRC)startup.s
$(AS) $(CPUFLAG) $< $(OFLAG) $@
# FreeRTOS core
$(OBJDIR)%.o : $(FREERTOS_SRC)%.c
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
# HW specific part, in FreeRTOS/Source/portable/$(PORT_COMP_TARGET)
$(OBJDIR)%.o : $(FREERTOS_PORT_SRC)%.c
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $(INC_FLAG_DRIVERS) $< $(OFLAG) $@
# Rules for all MemMang implementations are provided
# Only one of these object files must be linked to the final target
$(OBJDIR)%.o : $(FREERTOS_MEMMANG_SRC)%.c
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
# Drivers
$(OBJDIR)%.o : $(DRIVERS_SRC)%.c $(DEP_BSP)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAG_DRIVERS) $< $(OFLAG) $@
# Demo application
$(OBJDIR)main.o : $(APP_SRC)main.c
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
$(OBJDIR)init.o : $(APP_SRC)init.c $(DEP_BSP)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAG_DRIVERS) $< $(OFLAG) $@
$(OBJDIR)print.o : $(APP_SRC)print.c
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $(INC_FLAG_DRIVERS) $< $(OFLAG) $@
$(OBJDIR)receive.o : $(APP_SRC)receive.c $(DEP_BSP)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $(INC_FLAG_DRIVERS) $< $(OFLAG) $@
$(OBJDIR)nostdlib.o : $(APP_SRC)nostdlib.c
$(CC) $(CFLAG) $(CFLAGS) $< $(OFLAG) $@
# Cleanup directives:
clean_obj :
$(RM) -r $(OBJDIR)
clean_intermediate : clean_obj
$(RM) *.elf
$(RM) *.img
clean : clean_intermediate
$(RM) *.bin
# Short help instructions:
help :
@echo
@echo Valid targets:
@echo - all: builds missing dependencies and creates the target image \'$(TARGET)\'.
@echo - rebuild: rebuilds all dependencies and creates the target image \'$(TARGET)\'.
@echo - debug: same as \'all\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
@echo - debug_rebuild: same as \'rebuild\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
@echo - clean_obj: deletes all object files, only keeps \'$(ELF_IMAGE)\' and \'$(TARGET)\'.
@echo - clean_intermediate: deletes all intermediate binaries, only keeps the target image \'$(TARGET)\'.
@echo - clean: deletes all intermediate binaries, incl. the target image \'$(TARGET)\'.
@echo - help: displays these help instructions.
@echo
.PHONY : all rebuild clean clean_obj clean_intermediate debug debug_rebuild _debug_flags help