Skip to content

Instantly share code, notes, and snippets.

Last active Dec 26, 2015
What would you like to do?
Makefile for teensy 3.0 hello world in C
TARGET = main
OPTIONS += -D__MK20DX128__ -DARDUIO=104
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
ARDUINO_PATH= $(HOME)/work/arduino
TOOLSPATH= $(ARDUINO_PATH)/hardware/tools
MCU_LINKER_SCRIPT = $(ARDUINO_PATH)/hardware/teensy/cores/teensy3/mk20dx128.ld
# path location for Arduino libraries (currently not used)
# path location for the arm-none-eabi compiler
COMPILERPATH = $(TOOLSPATH)/arm-none-eabi/bin
# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD $(OPTIONS) -I. -I$(ARDUINO_PATH)/hardware/teensy/cores/teensy3/
# compiler options for C++ only
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti
# compiler options for C only
# linker options
LDFLAGS = -Os -Wl,--gc-sections -mcpu=cortex-m4 -mthumb -T$(MCU_LINKER_SCRIPT)
# additional libraries to link
LIBS = -lm
# 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
# TODO: this does not handle Arduino libraries yet...
C_FILES := $(wildcard *.c)
CPP_FILES := $(wildcard *.cpp)
OBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o) $(wildcard $(ARDUINO_PATH)/hardware/teensy/cores/teensy3/*.o)
# the actual makefile rules (all .o files built by GNU make's default implicit rules)
all: $(TARGET).hex
$(CC) $(LDFLAGS) -o $@ $(OBJS)
%.hex: %.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(abspath $(TOOLSPATH))/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(abspath $(TOOLSPATH))
-$(abspath $(TOOLSPATH))/teensy_reboot
# compiler generated dependency info
-include $(OBJS:.o=.d)
rm -f *.o *.d $(TARGET).elf $(TARGET).hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment