-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (50 loc) · 1.7 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
# MCU type
MCU = MK20DX256
MCU_LD = teensy32/mk20dx256.ld
# The name of your project (used to name the compiled .hex file)
TARGET = main
# Paths to Teensyduino tools
TOOLSPATH = $(TEENSY_TOOLS_PATH)
COMPILERPATH = $(TOOLSPATH)/arm/bin
# compiler options for C only
CFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -MMD $(OPTIONS) -I.
# linker options
LDFLAGS = -Os -Wl,--gc-sections,--defsym=__rtc_localtime=0 --specs=nano.specs -mcpu=cortex-m4 -mthumb -T$(MCU_LD)
# additional libraries to link
LIBS = -lm
# names for the compiler programs
CC = $(COMPILERPATH)/arm-none-eabi-gcc
OBJCOPY = $(COMPILERPATH)/arm-none-eabi-objcopy
SIZE = $(COMPILERPATH)/arm-none-eabi-size
# automatically create lists of the sources and objects
TEENSY_FILES := teensy32/mk20dx256.c teensy32/rtc.c
C_FILES := $(wildcard *.c) $(TEENSY_FILES)
OBJS := $(C_FILES:%.c=build/%.o)
# the actual makefile rules (all .o files built by GNU make's default implicit rules)
all: directories build/$(TARGET).hex
build/$(TARGET).elf: $(OBJS) $(MCU_LD)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
build/%.hex: build/%.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
ifneq (,$(wildcard $(TOOLSPATH)))
$(TOOLSPATH)/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(TOOLSPATH)
-$(TOOLSPATH)/teensy_reboot
endif
build/%.o: %.c
ifndef TEENSY_TOOLS_PATH
$(error TEENSY_TOOLS_PATH is not set)
endif
$(CC) $(CFLAGS) -o $@ -c $<
directories:
mkdir -p build
mkdir -p build/teensy32
# compiler generated dependency info
-include $(OBJS:.o=.d)
clean:
rm -rf build/*
flash: build/$(TARGET).hex
ifneq (,$(wildcard $(TOOLSPATH)))
$(TOOLSPATH)/teensy_post_compile -file=$(TARGET) -path=$(shell pwd) -tools=$(TOOLSPATH)
-$(TOOLSPATH)/teensy_reboot
endif