forked from embedded2014/rtenv-plus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
78 lines (60 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
77
78
TARGET = main
.DEFAULT_GOAL = all
# Compiler configurations
CROSS_COMPILE ?= arm-none-eabi-
CC := $(CROSS_COMPILE)gcc
# Hardware setup
CPU = cortex-m4
CFLAGS = -mcpu=$(CPU) -march=armv7e-m -mtune=cortex-m4
CFLAGS += -mlittle-endian -mthumb
CFLAGS += -fno-common -ffreestanding -O0 \
-gdwarf-2 -g3 -Wall -Werror \
-Wl,-Tmain.ld -nostartfiles \
-DUSER_NAME=\"$(USER)\"
CMSIS_LIB=Libraries/CMSIS
CMSIS_LIB_DEVICE=$(CMSIS_LIB)/Device/ST/STM32F4xx
STM32_LIB=Libraries/STM32F4xx_StdPeriph_Driver
OUTDIR = build
SRCDIR = src \
$(STM32_LIB)/src
INCDIR = include \
$(CMSIS_LIB)/Include \
$(CMSIS_LIB_DEVICE)/Include \
$(STM32_LIB)/inc
INCLUDES = $(addprefix -I,$(INCDIR))
DATDIR = data
TOOLDIR = tool
SRC = $(wildcard $(addsuffix /*.c,$(SRCDIR))) \
$(wildcard $(addsuffix /*.s,$(SRCDIR))) \
$(CMSIS_LIB_DEVICE)/Source/Templates/gcc_ride7/startup_stm32f429_439xx.s \
$(CMSIS_LIB_DEVICE)/Source/Templates/system_stm32f4xx.c
OBJ := $(addprefix $(OUTDIR)/,$(patsubst %.s,%.o,$(SRC:.c=.o)))
DEP = $(OBJ:.o=.o.d)
DAT =
MAKDIR = mk
MAK = $(wildcard $(MAKDIR)/*.mk)
include $(MAK)
all: $(OUTDIR)/$(TARGET).bin $(OUTDIR)/$(TARGET).lst
$(OUTDIR)/$(TARGET).bin: $(OUTDIR)/$(TARGET).elf
@echo " OBJCOPY "$@
@$(CROSS_COMPILE)objcopy -Obinary $< $@
$(OUTDIR)/$(TARGET).lst: $(OUTDIR)/$(TARGET).elf
@echo " LIST "$@
@$(CROSS_COMPILE)objdump -S $< > $@
$(OUTDIR)/$(TARGET).elf: $(OBJ) $(DAT)
@echo " LD "$@
@echo " MAP "$(OUTDIR)/$(TARGET).map
@$(CROSS_COMPILE)gcc $(CFLAGS) -Wl,-Map=$(OUTDIR)/$(TARGET).map -o $@ $^
$(OUTDIR)/%.o: %.c
@mkdir -p $(dir $@)
@echo " CC "$@
@$(CROSS_COMPILE)gcc $(CFLAGS) -MMD -MF [email protected] -o $@ -c $(INCLUDES) $<
$(OUTDIR)/%.o: %.s
@mkdir -p $(dir $@)
@echo " CC "$@
@$(CROSS_COMPILE)gcc $(CFLAGS) -MMD -MF [email protected] -o $@ -c $(INCLUDES) $<
clean:
rm -rf $(OUTDIR)
flash:
st-flash write $(OUTDIR)/$(TARGET).bin 0x8000000
-include $(DEP)