-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
183 lines (137 loc) · 6.17 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
# The name of your project (used to name the compiled .hex file)
TARGET = $(notdir $(CURDIR))
# Path to the Arduino build
ARDUINOPATH ?= /home/rday/Development/Teensyduino/arduino-1.6.5-r5
# The teensy version to use, 30, 31, or LC
TEENSY = LC
# Set to 24000000, 48000000, or 96000000 to set CPU core speed
TEENSY_CORE_SPEED = 48000000
# Defines
DEFINES = -D__MKL26Z64__ -DTEENSYDUINO=125 -DARDUINO=10605 -DF_CPU=48000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH
# Chip specific
OPTIONS = $(DEFINES) -mthumb -mcpu=cortex-m0plus -fsingle-precision-constant -Wall
# directory to build in
BUILDDIR = $(abspath $(CURDIR)/build)
#************************************************************************
# Location of Teensyduino utilities, Toolchain, and Arduino Libraries.
# To use this makefile without Arduino, copy the resources from these
# locations and edit the pathnames. The rest of Arduino is not needed.
#************************************************************************
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
TOOLSPATH = $(ARDUINOPATH)/hardware/tools
# path location for Teensy 3 core
COREPATH = $(abspath $(CURDIR)/teensy3)
# Linker script
LDSCRIPT=$(COREPATH)/mkl26z64.ld
# path location for Arduino libraries
LIBRARYPATH = $(abspath $(CURDIR)/libraries)
# path location for the arm-none-eabi compiler
COMPILERPATH = $(TOOLSPATH)/arm/bin
TESTDIR = /home/rday/Development/Teensyduino/Robot/gtest/googletest/googletest
#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************
# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -Os -ffunction-sections -fdata-sections -nostdlib -MMD $(OPTIONS) -Isrc -I$(COREPATH)
# compiler options for C++ only
CXXFLAGS = -std=gnu++11 -felide-constructors -fno-exceptions -fno-rtti
# compiler options for C only
CFLAGS =
# linker options
LDFLAGS = -Os -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=0 -T$(LDSCRIPT) --specs=nano.specs -fsingle-precision-constant -mthumb -mcpu=cortex-m0plus
# names for the compiler programs
CC = $(abspath $(COMPILERPATH))/arm-none-eabi-gcc
CXX = $(abspath $(COMPILERPATH))/arm-none-eabi-g++
OBJCOPY = $(abspath $(COMPILERPATH))/arm-none-eabi-objcopy
OBJDUMP = $(abspath $(COMPILERPATH))/arm-none-eabi-objdump
SIZE = $(abspath $(COMPILERPATH))/arm-none-eabi-size
STRIP = $(abspath $(COMPILERPATH))/arm-none-eabi-strip
AR = $(abspath $(COMPILERPATH))/arm-none-eabi-ar
# Include all the files from the user libraries
LC_FILES := $(wildcard $(LIBRARYPATH)/*/*.c)
LCPP_FILES := $(wildcard $(LIBRARYPATH)/*/*.cpp)
# Include all the files from the Teensy Core
TC_FILES := $(wildcard $(COREPATH)/*.c)
TCPP_FILES := $(wildcard $(COREPATH)/*.cpp)
# Include all the user project files
C_FILES := $(wildcard src/**/*.c) $(wildcard src/*.c)
CPP_FILES := $(wildcard src/**/*.cpp) $(wildcard src/*.cpp)
INO_FILES := $(wildcard src/**/*.ino)
TEST_FILES := $(wildcard tests/*.cpp)
# include paths for libraries
L_INC := -I$(LIBRARYPATH) -Iteensy3/
TEENSY_SOURCES := $(TCPP_FILES:.cpp=.o) $(TC_FILES:.c=.o)
LIB_SOURCES := $(LC_FILES:.c=.o) $(LCPP_FILES:.cpp=.o)
PROJECT_SOURCES := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o) $(INO_FILES:.ino=.o)
TEST_SOURCES := $(TEST_FILES:.cpp=.o)
TEENSY_OBJS := $(foreach src,$(TEENSY_SOURCES), $(BUILDDIR)/$(src))
LIB_OBJS := $(foreach src,$(LIB_SOURCES), $(BUILDDIR)/$(src))
PROJECT_OBJS := $(foreach src,$(PROJECT_SOURCES), $(BUILDDIR)/$(src))
TEST_OBJS := $(foreach src,$(TEST_SOURCES), $(BUILDDIR)/$(src))
all: hex
@echo "Building all"
@echo "COREPATH\t$(COREPATH)"
@echo "BUILDDIR\t$(BUILDDIR)"
build: $(TARGET).elf
hex: $(TARGET).hex
post_compile: $(TARGET).hex
@$(abspath $(TOOLSPATH))/teensy_post_compile -file="$(basename $<)" -path=$(CURDIR) -tools="$(abspath $(TOOLSPATH))" -board=TEENSYLC
reboot:
@-$(abspath $(TOOLSPATH))/teensy_reboot
upload: post_compile reboot
$(BUILDDIR)/$(COREPATH)/%.o: $(COREPATH)/%.c
@echo "[TEENSY CC]\t$<"
@mkdir -p "$(dir $@)"
@$(CC) $(CPPFLAGS) $(CFLAGS) $(L_INC) -o "$@" -c "$<"
@$(AR) rcs $(BUILDDIR)/core.a "$@"
$(BUILDDIR)/$(COREPATH)/%.o: $(COREPATH)/%.cpp
@echo "[TEENSY CXX]\t$<"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c "$<"
@$(AR) rcs $(BUILDDIR)/core.a "$@"
$(BUILDDIR)/$(LIBRARYPATH)/%.o: $(LIBRARYPATH)/%.c
@echo "[LIBS CC]\t$<"
@mkdir -p "$(dir $@)"
@$(CC) $(CPPFLAGS) $(CFLAGS) $(L_INC) -o "$@" -c "$<"
@$(AR) rcs $(BUILDDIR)/libs.a "$@"
$(BUILDDIR)/$(LIBRARYPATH)/%.o: $(LIBRARYPATH)/%.cpp
@echo "[LIBS CXX]\t$<"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c "$<"
@$(AR) rcs $(BUILDDIR)/libs.a "$@"
$(BUILDDIR)/src/%.o: src/%.c
@echo "[CC]\t$<"
@mkdir -p "$(dir $@)"
@$(CC) $(CPPFLAGS) $(CFLAGS) $(L_INC) -o "$@" -c "$<"
$(BUILDDIR)/src/%.o: src/%.cpp
@echo "[CXX]\t$@"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c "$<"
$(TARGET).elf: $(TEENSY_OBJS) $(LIB_OBJS) $(PROJECT_OBJS)
%.hex: %.elf
@echo "[LD]\t$@"
$(CC) $(LDFLAGS) -o $(TARGET).elf $(BUILDDIR)/src/*.o $(BUILDDIR)/libs.a $(BUILDDIR)/core.a -L$(BUILDDIR)
@echo "[HEX]\t$@"
$(SIZE) "$<"
$(OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "$<" "$@"
$(OBJCOPY) -O ihex -R .eeprom "$<" "$@"
$(OBJDUMP) -D $(TARGET).elf > $(TARGET).list
# compiler generated dependency info
-include $(OBJS:.o=.d)
clean:
@echo Cleaning...
@rm -rf "$(BUILDDIR)"
@rm -f "$(TARGET).elf" "$(TARGET).hex"
@rm -f tests/*.o
$(BUILDDIR)/tests/%.o: tests/%.cpp
@echo "[BUILDING TEST]\t$<"
@mkdir -p "$(dir $@)"
@g++ $(L_INC) $(DEFINES) -fsingle-precision-constant -Itests/ -c "$<" -o "$@"
$(BUILDDIR)/tests/Message.o:
@g++ $(L_INC) $(DEFINES) -std=gnu++11 -Itests/ -c libraries/CuriousRobot/Message.cpp -o $(BUILDDIR)/tests/Message.o
$(BUILDDIR)/tests/ServoController.o:
@g++ $(L_INC) $(DEFINES) -std=gnu++11 -Itests/ -c libraries/CuriousRobot/ServoController.cpp -o $(BUILDDIR)/tests/ServoController.o
test: $(TEST_OBJS) $(BUILDDIR)/tests/Message.o $(BUILDDIR)/tests/ServoController.o
@echo [RUNNING TESTS]
@g++ $(BUILDDIR)/tests/*.o -o tests/run_tests
@tests/run_tests