forked from Offworld-Robotics/bandicoot_embedded
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (149 loc) · 6.29 KB
/
Makefile
File metadata and controls
201 lines (149 loc) · 6.29 KB
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
# Makefile for feedback_io project
#
# Author: Aaron Lucas
# Date Created: 2020/07/27
#
# Written for the Off-World Robotics Team
# ==============================================================================
# Directory Definitions
# ==============================================================================
# Executable output files
OUT_DIR=bin
# Library archives
LIB_DIR=lib
# Source code
SRC_DIR=src
# Source code for testing programs and other testing files
TEST_DIR=test
# Object files
OBJ_DIR=obj
# ==============================================================================
# Project Definitions
# ==============================================================================
ELFS=blink pwmTest simulateMotor qeiTest system
TIVAWARE=$(SRC_DIR)/tivaware
DRIVERLIB=$(TIVAWARE)/driverlib
INC_DIRS=$(TIVAWARE) src
INC_FLAGS=$(patsubst %,-I%,$(INC_DIRS))
LINKER_SCRIPT=linker.ld
STARTUP_SCRIPT=$(SRC_DIR)/startup.c
STARTUP_OBJ=$(OBJ_DIR)/startup.o
# _DEPS=pwmControl.c qeiControl.c
# DEPS=$(patsubst %,$(SRC_DIR)/%,$(_DEPS))
# ==============================================================================
# Chip-Specific Configuration
# ==============================================================================
PART=TM4C123GH6PM
CPU=-mcpu=cortex-m4
FPU=-mfpu=fpv4-sp-d16 -mfloat-abi=hard
# ==============================================================================
# Toolchain Binaries
# ==============================================================================
PREFIX=arm-none-eabi
CC=$(PREFIX)-gcc
LD=$(PREFIX)-ld
AS=$(PREFIX)-as
AR=$(PREFIX)-ar
# ==============================================================================
# Toolchain Flags
# ==============================================================================
# Flag explanations
# ------------------
# -mthumb: 16-bit thumb instructions for smaller code size
# $(CPU), $(FPU): Tell compiler which CPU is on the chip and configure FPU
# -ffunction-sections: Put each function in its own section
# -fdata-sections: Put each data item in its own section
# -MD: Auto-generate dependency files
# -std: Set C language standard for compilation
# -W Show all warnings and make them errors
# -DPART_: Define part number for tivaware library
# -c: Compile and assemble into object files
# $(INC_FLAGS): Search for header files in non-standard directories
# -O2 Level 2 compiler optimisations
# -Dgcc Define compiler (used by some tivaware utils)
CFLAGS=-mthumb $(CPU) $(FPU) -ffunction-sections -fdata-sections -MD -std=c99 \
-Wall -Wpedantic -DPART_$(PART) -c $(INC_FLAGS) -O2 -Dgcc
LDFLAGS=--gc-sections
ASFLAGS=-mthumb $(CPU) $(FPU) -MD $(INC_FLAGS)
# ==============================================================================
# Libraries
# ==============================================================================
# GCC low-level runtime library
LIBGCC=$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
# Standard C library
LIBC=$(shell $(CC) $(CFLAGS) -print-file-name=libc.a)
# Math library
LIBM=$(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
# Tivaware driver library
LIBDRIVER=$(LIB_DIR)/libdriver.a
# All libraries
LIBS=$(LIBGCC) $(LIBC) $(LIBM) $(LIBDRIVER)
# ==============================================================================
# Make Rules
# ==============================================================================
COMMON_DEPS=$(LIBDRIVER) $(STARTUP_OBJ) $(OBJ_DIR)/common.o
.PHONY: all debug clean tags
all: $(patsubst %,$(OUT_DIR)/%.elf,$(ELFS))
# In debug mode, disable compiler optimisations, generate debugging symbols and
# activate extra debugging code.
debug: CFLAGS+=-g3 -DDEBUG -O0
debug: all
# Rule to create startup object file
# Uses different set of flags
$(OBJ_DIR)/startup.o: $(SRC_DIR)/startup.c | $(OBJ_DIR)
$(CC) $(ASFLAGS) -c -o $@ $<
# Rule to create object files from C files in source directory
# $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/%.h | $(OBJ_DIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -o $@ $<
# Rule to create object files from C files in test directory
$(OBJ_DIR)/%.o: $(TEST_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -o $@ $<
# Rule to create tivaware driver library object files
$(OBJ_DIR)/%.o: $(DRIVERLIB)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -o $@ $<
# Rule to create driver library archive
# Object files are created in tivaware folder so the library only needs to be
# built once.
DRIVERLIB_SRC=$(wildcard $(DRIVERLIB)/*.c)
$(LIBDRIVER): $(patsubst $(DRIVERLIB)/%.c,$(DRIVERLIB)/%.o,$(DRIVERLIB_SRC)) | $(LIB_DIR)
$(AR) -cr $@ $^
# Rules to create executable ELF files
# Generic
$(OUT_DIR)/%.elf: $(OBJ_DIR)/%.o $(COMMON_DEPS) | $(OUT_DIR)
$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $@ $^ $(LIBS)
# Specialised
_PWM_TEST_DEPS=pwmTest PWMControl
_PWM_TEST_H_DEPS=ControllerParameters units
PWM_TEST_DEPS=$(patsubst %,$(OBJ_DIR)/%.o,$(_PWM_TEST_DEPS)) $(COMMON_DEPS)
PWM_TEST_H_DEPS=$(patsubst %,$(SRC_DIR)/%.h,$(_PWM_TEST_H_DEPS))
$(OUT_DIR)/pwmTest.elf: $(PWM_TEST_DEPS) $(PWM_TEST_H_DEPS) | $(OUT_DIR)
$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $@ $(PWM_TEST_DEPS) $(LIBS)
_SIM_MOTOR_DEPS=simulateMotor Motor PIDController PWMControl
_SIM_MOTOR_H_DEPS=ControllerParameters MotorParameters units
SIM_MOTOR_DEPS=$(patsubst %,$(OBJ_DIR)/%.o,$(_SIM_MOTOR_DEPS)) $(COMMON_DEPS)
SIM_MOTOR_H_DEPS=$(patsubst %,$(SRC_DIR)/%.h,$(_SIM_MOTOR_H_DEPS))
$(OUT_DIR)/simulateMotor.elf: $(SIM_MOTOR_DEPS) $(SIM_MOTOR_H_DEPS) | $(OUT_DIR)
$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $@ $(SIM_MOTOR_DEPS) $(LIBS)
_QEI_TEST_DEPS=qeiTest QEIControl
_QEI_TEST_H_DEPS=units
QEI_TEST_DEPS=$(patsubst %,$(OBJ_DIR)/%.o,$(_QEI_TEST_DEPS)) $(COMMON_DEPS)
QEI_TEST_H_DEPS=$(patsubst %,$(SRC_DIR)/%.h,$(_QEI_TEST_H_DEPS))
$(OUT_DIR)/qeiTest.elf: $(QEI_TEST_DEPS) $(QEI_TEST_H_DEPS) | $(OUT_DIR)
$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $@ $(QEI_TEST_DEPS) $(LIBS)
_SYSTEM_DEPS=system PWMControl QEIControl PIDController
_SYSTEM_H_DEPS=ControllerParameters units
SYSTEM_DEPS=$(patsubst %,$(OBJ_DIR)/%.o,$(_SYSTEM_DEPS)) $(COMMON_DEPS)
SYSTEM_H_DEPS=$(patsubst %,$(SRC_DIR)/%.h,$(_SYSTEM_H_DEPS))
$(OUT_DIR)/system.elf: $(SYSTEM_DEPS) $(SYSTEM_H_DEPS) | $(OUT_DIR)
$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $@ $(SYSTEM_DEPS) $(LIBS)
$(OBJ_DIR):
mkdir -p $@
$(OUT_DIR):
mkdir -p $@
$(LIB_DIR):
mkdir -p $@
tags:
ctags -R src test
clean:
rm -rf $(OBJ_DIR)/* $(OUT_DIR)/* $(LIB_DIR)/* $(DRIVERLIB)/*.o