-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
48 lines (36 loc) · 1.3 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
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
SIZE = arm-none-eabi-size
LOADER = teensy_loader_cli
OUTFILE = firmware
BUILD_DIR = ./build
SRC_DIRS ?= ./src ./teensy ./include
SRCS := $(shell find $(SRC_DIRS) -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS = -O3 -Wall -Werror -mcpu=cortex-m7 -mthumb $(INC_FLAGS)
LDFLAGS = -Wl,--gc-sections,--print-gc-sections,--print-memory-usage -nostdlib -nostartfiles -Tteensy/imxrt1062.ld
$(BUILD_DIR)/$(OUTFILE).hex: $(BUILD_DIR)/$(OUTFILE).elf
@$(OBJCOPY) -O ihex -R .eeprom build/$(OUTFILE).elf build/$(OUTFILE).hex
@$(OBJDUMP) -d -x build/$(OUTFILE).elf > build/$(OUTFILE).dis
@$(OBJDUMP) -d -S -C build/$(OUTFILE).elf > build/$(OUTFILE).lst
@$(SIZE) build/$(OUTFILE).elf
$(BUILD_DIR)/$(OUTFILE).elf: $(OBJS)
@$(CC) $(CFLAGS) -Xlinker -Map=build/$(OUTFILE).map $(LDFLAGS) -o $@ $^
$(BUILD_DIR)/%.s.o: %.s
@$(MKDIR_P) $(dir $@)
@$(AS) $(ASFLAGS) -c $< -o $@
$(BUILD_DIR)/%.c.o: %.c
@$(MKDIR_P) $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: flash
flash: $(BUILD_DIR)/$(OUTFILE).hex
$(LOADER) --mcu=TEENSY40 -w -v $<
.PHONY: clean
clean:
@$(RM) -r $(BUILD_DIR)
MKDIR_P ?= mkdir -p