-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile_example
More file actions
168 lines (133 loc) · 5.74 KB
/
Copy pathMakefile_example
File metadata and controls
168 lines (133 loc) · 5.74 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
# The name of your project (used to name the compiled .hex file)
TARGET = $(notdir $(CURDIR))
# The Teensy board you're targeting (30,31,32,35,36, or LC)
TEENSY = ??
OPTIMIZE_LEVEL = -O
OPTIONS = -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE -DARDUINO=10800 -DTEENSYDUINO=134
# directory to build in
BUILDDIR = $(abspath $(CURDIR)/build)
# path location for Teensy 3 core
COREPATH = cores/teensy3
# path location for Arduino libraries
LIBRARYPATH = libraries
LIBRARIES = $(LIBRARYPATH)/Wire $(LIBRARYPATH)/Encoder $(LIBRARYPATH)/SPI $(LIBRARYPATH)/Servo $(LIBRARYPATH)/Adafruit_TCS34725 $(LIBRARYPATH)/vl53l0x-arduino
#************************************************************************
# 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.
#************************************************************************
#
ifeq ($(OS),Windows_NT)
# Windows machine
$(error Using the Makefile on Windows is not supported. Simply open src/src.ino in Arduino with teensyduino and supporting libraries installed)
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
# OS X Machine
ARDUINOPATH = /Applications/Arduino.app/Contents/Java
else
# Other UNIX Machine
# This should probably be changed to where you extracted the Arduino app after downloading
ARDUINOPATH = ${HOME}/arduino-1.8.0
endif
endif
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
TOOLSPATH = $(ARDUINOPATH)/hardware/tools
# path location for the arm-none-eabi compiler
COMPILERPATH = $(TOOLSPATH)/arm/bin
POSTCOMPILEPATH = $(TOOLSPATH)/teensy_post_compile
REBOOTPATH = $(TOOLSPATH)/teensy_reboot
#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************
# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g $(OPTIMIZE_LEVEL) -ffunction-sections -fdata-sections -nostdlib -mthumb -MMD $(OPTIONS) -I$(COREPATH)
# compiler options for C++ only
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti
# compiler options for C only
CFLAGS =
LDFLAGS = $(OPTIMIZE_LEVEL) -Wl,--gc-sections,--defsym=__rtc_localtime=0 -mthumb
# additional libraries to link
LIBS = -lm
# compiler options specific to teensy version
ifeq ($(TEENSY), 30)
CPPFLAGS += -D__MK20DX128__ -mcpu=cortex-m4 -DF_CPU=96000000
LDSCRIPT = $(COREPATH)/mk20dx128.ld
LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT)
else ifeq ($(TEENSY), 31)
CPPFLAGS += -D__MK20DX256__ -mcpu=cortex-m4 -DF_CPU=96000000
LDSCRIPT = $(COREPATH)/mk20dx256.ld
LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT)
else ifeq ($(TEENSY), 32)
CPPFLAGS += -D__MK20DX256__ -mcpu=cortex-m4 -DF_CPU=96000000
LDSCRIPT = $(COREPATH)/mk20dx256.ld
LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT)
else ifeq ($(TEENSY), LC)
CPPFLAGS += -D__MKL26Z64__ -mcpu=cortex-m0plus -DF_CPU=48000000
LDSCRIPT = $(COREPATH)/mkl26z64.ld
LDFLAGS += -mcpu=cortex-m0plus -T$(LDSCRIPT)
LIBS += -larm_cortexM0l_math
else ifeq ($(TEENSY), 35)
CPPFLAGS += -D__MK64FX512__ -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DF_CPU=120000000
LDSCRIPT = $(COREPATH)/mk64fx512.ld
LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T$(LDSCRIPT)
LIBS += -larm_cortexM4lf_math
else ifeq ($(TEENSY), 36)
CPPFLAGS += -D__MK66FX1M0__ -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DF_CPU=180000000
LDSCRIPT = $(COREPATH)/mk66fx1m0.ld
LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T$(LDSCRIPT)
LIBS += -larm_cortexM4lf_math
else
$(error Choose a valid target Teensy board (Makefile line 5))
endif
# 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
SIZE = $(abspath $(COMPILERPATH))/arm-none-eabi-size
# automatically create lists of the sources and objects
LC_FILES := $(foreach library, $(LIBRARIES), $(wildcard $(library)/*.c))
LCPP_FILES := $(foreach library, $(LIBRARIES), $(wildcard $(library)/*.cpp))
TC_FILES := $(wildcard $(COREPATH)/*.c)
TCPP_FILES := $(wildcard $(COREPATH)/*.cpp)
TCPP_FILES := $(filter-out $(COREPATH)/main.cpp, $(TCPP_FILES))
C_FILES := $(wildcard src/*.c)
CPP_FILES := $(wildcard src/*.cpp)
INO_FILES := $(wildcard src/*.ino)
# include paths for libraries
L_INC := $(foreach lib,$(filter %/, $(wildcard $(LIBRARYPATH)/*/)), -I$(lib))
SOURCES := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o) $(INO_FILES:.ino=.o) $(TC_FILES:.c=.o) $(TCPP_FILES:.cpp=.o) $(LC_FILES:.c=.o) $(LCPP_FILES:.cpp=.o)
OBJS := $(foreach src,$(SOURCES), $(BUILDDIR)/$(src))
all: hex
build: $(TARGET).elf
hex: $(TARGET).hex
post_compile: $(TARGET).hex
@$(abspath $(POSTCOMPILEPATH)) -file="$(basename $<)" -path=$(CURDIR) -tools="$(abspath $(TOOLSPATH))"
reboot:
@-$(abspath $(REBOOTPATH))
upload: post_compile reboot
$(BUILDDIR)/%.o: %.c
@echo "[CC]\t$<"
@mkdir -p "$(dir $@)"
@$(CC) $(CPPFLAGS) $(CFLAGS) $(L_INC) -o "$@" -c "$<"
$(BUILDDIR)/%.o: %.cpp
@echo "[CXX]\t$<"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -c "$<"
$(BUILDDIR)/%.o: %.ino
@echo "[CXX]\t$<"
@mkdir -p "$(dir $@)"
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(L_INC) -o "$@" -x c++ -include Arduino.h -c "$<"
$(TARGET).elf: $(OBJS) $(LDSCRIPT)
@echo "[LD]\t$@"
@$(CC) $(LDFLAGS) -o "$@" $(OBJS) $(LIBS)
%.hex: %.elf
@echo "[HEX]\t$@"
@$(SIZE) "$<"
@$(OBJCOPY) -O ihex -R .eeprom "$<" "$@"
# compiler generated dependency info
-include $(OBJS:.o=.d)
clean:
@echo Cleaning...
@rm -rf "$(BUILDDIR)"
@rm -f "$(TARGET).elf" "$(TARGET).hex"