-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
103 lines (71 loc) · 2.29 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
#########################################################################################
#
# Main Makefile
#
# Desc:
# Builds the whole system, provides commands for uploading the resulting elf.
#
#########################################################################################
#####################################################################
# Files
# Directories
BUILD_DIR = build
SRC_DIR = src/
TEENSY_SRC_DIR = teensy_src/
# Sources
SRC = main.cpp
INC = -I. -Iinc/
SRC_FILES = $(addprefix src/, $(SRC))
# Object files
OBJECTS = $(addprefix $(BUILD_DIR)/, $(SRC:.cpp=.o))
# Target Output
TARGET = payload
OBJECT_FILE = $(BUILD_DIR)/objects.tmp
TEENSY_OBJECTS = $(BUILD_DIR)/teensy_objects.tmp
#####################################################################
# Compile Tools
CPU=cortex-m4
MCU=mk20dx256 # For teensy_loader_cli
CFLAGS= -Wall -g -fno-common -mthumb -mcpu=$(CPU) -std=c99
CXXFLAGS = -Wall -g -fno-common -mthumb -mcpu=$(CPU) -fno-exceptions -fno-rtti -mfloat-abi=soft -nostdlib
LDSCRIPT= $(TEENSY_SRC_DIR)Teensy31_flash.ld
LDFLAGS= -nostartfiles -T$(LDSCRIPT) -mthumb -mcpu=$(CPU) -nostdlib
# Tools
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
SIZE = arm-none-eabi-size
UPLOAD = teensy_loader_cli
MKDIR_P = mkdir -p
#####################################################################
# Build Rules
.PHONY: clean flash dump teensy $(TARGET) stats
all: $(TARGET) stats
teensy:
$(MAKE) -C $(TEENSY_SRC_DIR) BUILD_LOC=../build OBJECT_LOC=./build
$(TARGET): $(BUILD_DIR) | $(OBJECTS) teensy
rm -f $(OBJECT_FILE)
echo -n " " $(OBJECTS) >> $(OBJECT_FILE)
$(CXX) $(LDFLAGS) @$(TEENSY_OBJECTS) @$(OBJECT_FILE) -o $@.elf
$(OBJCOPY) -R .stack -O ihex $@.elf $@.hex
$(BUILD_DIR)/%.o:$(SRC_DIR)/%.cpp
@echo Compiling $@
$(CXX) -c $(CXXFLAGS) $(INC) -o $@ $<
$(BUILD_DIR)/%.o: %.c
@echo Compiling $@
@$(CXX) -c $(CXXFLAGS) $(INC) -o $@ $<
$(BUILD_DIR):
$(MKDIR_P) $(BUILD_DIR)
#####################################################################
# Tool Rules
dump:
$(OBJDUMP) -S -D $(BUILD_DIR)/$(TARGET).elf > $(BUILD_DIR)/$(TARGET).S
stats:$(TARGET).elf
$(SIZE) $(TARGET).elf
flash:$(TARGET).hex
$(UPLOAD) -v -w --mcu=${MCU} $<
clean:
rm -f -r build
rm -f $(TARGET).hex $(TARGET).elf