-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·76 lines (54 loc) · 1.94 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
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
# Minimal makefile for STM32F3 Neucleo board.
TARGET := arm-none-eabi
# devtools
CC := $(TARGET)-gcc
LD := $(TARGET)-gcc
AS := $(TARGET)-as
OBJCOPY := $(TARGET)-objcopy
STFLASH := st-flash
STUTIL := st-util
PORT := /dev/ttyACM0
CFLAGS = -g3 -mcpu=cortex-m4 -mtune=cortex-m4 -march=armv7e-m -mthumb -nostdlib -O0 -ffunction-sections -fdata-sections -Wl,--gc-sections -std=c99 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -D__FPU_PRESENT
INCLUDE = -I./include
#INCPATHS = ./include
INCLUDES = $(addprefix -I ,$(INCPATHS))
LDFLAGS = -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mtune=cortex-m4
OBJDIR = obj
SOURCES = $(shell find * -name "*.c")
SRCDIR = $(dir $(SOURCES))
BINDIR = $(addprefix $(OBJDIR)/, $(SRCDIR))
ASMS = $(shell find * -name "*.s")
ASMDIR = $(dir $(ASMS))
ASMBIN = $(addprefix $(OBJDIR)/, $(ASMDIR))
OBJECTS = $(addprefix $(OBJDIR)/, $(patsubst %.c, %.o, $(SOURCES))) $(addprefix $(OBJDIR)/, $(patsubst %.s, %.o, $(ASMS)))
DEPENDS = $(OBJECTS:.o=.d)
ifeq "$(strip $(OBJDIR))" ""
OBJDIR = .
endif
MEMORYMAP = STM32F446XE.ld
OBJECTNAME = STM
default :
@[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR)
@[ -d "$(BINDIR)" ] || mkdir -p $(BINDIR)
@[ -d "$(ASMBIN)" ] || mkdir -p $(ASMBIN)
@make all --no-print-directory
all: $(OBJECTS) $(OBJECTNAME).bin $(OBJECTNAME).elf
$(OBJECTNAME).elf: $(OBJECTNAME).bin
$(OBJCOPY) -I binary -O elf32-little $(OBJECTNAME).bin $(OBJECTNAME).elf
$(OBJECTNAME).bin: $(OBJECTNAME).out
$(OBJCOPY) $(OBJECTNAME).out -I ihex -O binary $(OBJECTNAME).bin
$(OBJECTNAME).out: $(OBJECTS)
$(LD) -T $(MEMORYMAP) $(OBJECTS) $(CFLAGS) $(LDFLAGS) -o $(OBJECTNAME).out
$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
$(OBJDIR)/%.o: %.s
$(AS) -g $< -o $@
.PHONY: clean flash
st-flash: $(OBJECTNAME).bin
$(STFLASH) write $(OBJECTNAME).bin 0x8000000
st-util: $(OBJECTNAME).bin
$(STUTIL) $(OBJECTNAME).bin
clean:
rm -rf $(OBJDIR) *.out *.bin *.elf