-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (49 loc) · 1.22 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
Q?=@
QQ=@
RM?=rm
PREFIX_ARCH?=arm-none-eabi
AS=$(PREFIX_ARCH)-as
CC=$(PREFIX_ARCH)-gcc
LD=$(PREFIX_ARCH)-ld
OBJDUMP=$(PREFIX_ARCH)-objdump
OBJCOPY=$(PREFIX_ARCH)-objcopy
ASFLAGS:=--warn
ASFLAGS+=--fatal-warnings
ASFLAGS+=-mcpu=cortex-m3
CFLAGS:=-Wall
CFLAGS+=-O0
CFLAGS+=-nostdlib
CFLAGS+=-nostartfiles
CFLAGS+=-ffreestanding
CFLAGS+=-mcpu=cortex-m3
CFLAGS+=-mthumb
SRC=src
BUILD=build
SOURCES:=$(wildcard $(SRC)/*.c)
SOURCES+=$(wildcard $(SRC)/*.s)
OBJECTS:=$(patsubst $(SRC)/%,$(BUILD)/%.o,$(SOURCES))
TARGET=notmain
all: $(TARGET).elf $(TARGET).bin
$(OBJECTS): | $(BUILD)
$(BUILD):
$(Q) mkdir -p $(BUILD)
$(BUILD)/%.c.o: $(SRC)/%.c
$(QQ) echo " CC $@"
$(Q) $(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/%.s.o: $(SRC)/%.s
$(QQ) echo " AS $@"
$(Q) $(AS) $(ASFLAGS) $< -o $@
$(TARGET).elf: $(OBJECTS)
$(QQ) echo " LD $@"
$(Q) $(LD) -o $@ -T flash.ld $^
$(QQ) echo " OBJDUMP $@"
$(Q) $(OBJDUMP) -D $@ >[email protected]
$(TARGET).bin: $(TARGET).elf
$(QQ) echo " OBJCOPY $@"
$(Q) $(OBJCOPY) $< $@ -O binary
clean:
$(QQ) echo " RM $(OBJECTS)"
$(Q) $(RM) -r $(OBJECTS)
$(QQ) echo " RM $(TARGET).elf $(TARGET).bin $(TARGET).elf.list"
$(Q) $(RM) -r $(TARGET).elf $(TARGET).bin $(TARGET).elf.list
.PHONY: clean all