# t4make00 Makefile # adapted from apmorton's teensy-template https://github.com/apmorton/teensy-template # and based on Makefile examples as part of teensy's cores https://github.com/PaulStoffregen/cores # gauthiier - d@gauthiier.info # name of your project (used to name the compiled .hex file) TARGET = $(notdir $(CURDIR)) # directory to build in BUILDDIR = $(abspath $(CURDIR)/build) # (local) libraries LIBRARYPATH = $(abspath $(CURDIR)/libs) #***************************************************** # Location of utilites, toolchains, etc... # note: $T4MAKE00PATH must be part of your PATH #***************************************************** # generale tools path TOOLSPATH = $(T4MAKE00PATH)/tools # general libs path LIBSPATH = $(T4MAKE00PATH)/libs # path location for the arm-none-eabi compiler COMPILERPATH = $(TOOLSPATH)/gcc-arm-none-eabi/bin # path location for teensy-tools ifeq ($(OS), Windows_NT) $(error NT not supported) else UNAME_M := $(shell uname -m) ifneq ($(UNAME_M),x86_64) $(error only support for x86_64... sorry) endif UNAME_S := $(shell uname -s) #note: (ver.00) only packs t4make00 with Darwin-x86_64... ifneq ($(UNAME_S),Darwin) $(error only support for Darwin-x86_64... sorry) endif TEENSY_TOOLSPATH = $(TOOLSPATH)/teensy-tools/$(UNAME_S)-$(UNAME_M) endif #***************************************************** # Teensy specificities: version, cores, etc. #***************************************************** # teensy version to use, 41, 40, 30, 31, or LC TEENSY = # teensy core to use, teensy3, teensy4 TEENSYCORE = # teensyduino version to use TEENSYDUINO = # path location for teensy core to use, teensy3, teensy4 COREPATH = $(LIBSPATH)/$(TEENSYCORE) #***************************************************** # Compiler, linker options #***************************************************** # compiler options specific to teensy core ifeq ($(TEENSYCORE), teensy3) # Set to 24000000, 48000000, or 96000000 to set CPU core speed TEENSY_CORE_SPEED = 48000000 # configurable options OPTIONS = -DF_CPU=$(TEENSY_CORE_SPEED) -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE # cpu options CPUOPTIONS = -mthumb # CPPFLAGS = compiler options for C and C++ CPPFLAGS = -Wall -g -Os $(CPUOPTIONS) -ffunction-sections -fdata-sections -MMD $(OPTIONS) -I$(COREPATH) -I$(LIBRARYPATH) -I. -DTEENSYDUINO=$(TEENSYDUINO) # compiler options for C++ only CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti # compiler options for C only CFLAGS = # linker options LDFLAGS = -Os -Wl,--gc-sections $(CPUOPTIONS) # additional libraries to link LIBS = -lm else ifeq ($(TEENSYCORE), teensy4) # Set to 600000000 to set CPU core speed (can we clock it higher?) TEENSY_CORE_SPEED = 600000000 # configurable options OPTIONS = -DF_CPU=$(TEENSY_CORE_SPEED) -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE # cpu options with single & double precision FPU CPUOPTIONS = -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 # CPPFLAGS = compiler options for C and C++ CPPFLAGS = -Wall -g -O2 $(CPUOPTIONS) -ffunction-sections -fdata-sections -MMD $(OPTIONS) -I$(COREPATH) -I$(LIBRARYPATH) -I. -DTEENSYDUINO=$(TEENSYDUINO) # compiler options for C++ only CXXFLAGS = -std=gnu++14 -felide-constructors -fno-exceptions -fno-rtti -fpermissive -Wno-error=narrowing # compiler options for C only CFLAGS = # linker options LDFLAGS = -Os -Wl,--gc-sections $(CPUOPTIONS) # additional libraries to link LIBS = -lm -larm_cortexM7lfsp_math -lstdc++ else $(error Invalid setting for TEENSYCORE) endif # compiler options specific to teensy version ifeq ($(TEENSY), 40) CPPFLAGS += -D__IMXRT1062__ -mcpu=cortex-m7 -DARDUINO_TEENSY40 LDSCRIPT = $(COREPATH)/imxrt1062.ld LDFLAGS += -mcpu=cortex-m7 -T$(LDSCRIPT) else ifeq ($(TEENSY), 41) CPPFLAGS += -D__IMXRT1062__ -mcpu=cortex-m7 -DARDUINO_TEENSY41 LDSCRIPT = $(COREPATH)/imxrt1062_t41.ld LDFLAGS += -mcpu=cortex-m7 -T$(LDSCRIPT) else ifeq ($(TEENSY), 30) CPPFLAGS += -D__MK20DX128__ -mcpu=cortex-m4 LDSCRIPT = $(COREPATH)/mk20dx128.ld LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT) else ifeq ($(TEENSY), 31) CPPFLAGS += -D__MK20DX256__ -mcpu=cortex-m4 LDSCRIPT = $(COREPATH)/mk20dx256.ld LDFLAGS += -mcpu=cortex-m4 -T$(LDSCRIPT) else ifeq ($(TEENSY), LC) CPPFLAGS += -D__MKL26Z64__ -mcpu=cortex-m0plus LDSCRIPT = $(COREPATH)/mkl26z64.ld LDFLAGS += -mcpu=cortex-m0plus -T$(LDSCRIPT) LIBS += -larm_cortexM0l_math else $(error Invalid setting for TEENSY) endif # set arduino define if given ifdef ARDUINO CPPFLAGS += -DARDUINO=$(ARDUINO) else CPPFLAGS += -DUSING_MAKEFILE 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 # library sources LC_FILES := $(shell find $(LIBRARYPATH) \( -name examples -o -name extras -o -path name \) -prune -false -o -name "*.c") LCPP_FILES := $(shell find $(LIBRARYPATH) \( -name examples -o -name extras -o -path name \) -prune -false -o -name "*.cpp") # core sources CC_FILES := $(wildcard $(COREPATH)/*.c) CCPP_FILES := $(wildcard $(COREPATH)/*.cpp) # project sources C_FILES := $(wildcard *.c) CPP_FILES := $(wildcard *.cpp) INO_FILES := $(wildcard *.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) $(CC_FILES:.c=.o) $(CCPP_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 $(TEENSY_TOOLSPATH))/teensy_post_compile -file="$(basename $<)" -path=$(CURDIR) -tools="$(abspath $(TEENSY_TOOLSPATH))" reboot: @-$(abspath $(TEENSY_TOOLSPATH))/teensy_reboot 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"