-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile-common.mk
141 lines (111 loc) · 3.28 KB
/
makefile-common.mk
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
LINKSCR ?= linkscript.ld
BUILDDIR ?= build
BINARYNAME ?= main
UIMAGENAME ?= $(BUILDDIR)/a7-main.uimg
SCRIPTDIR ?= .
OBJDIR = $(BUILDDIR)/obj/obj
LOADADDR ?= 0xC2000040
ENTRYPOINT ?= 0xC2000040
OBJECTS = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(SOURCES))))
DEPS = $(addprefix $(OBJDIR)/, $(addsuffix .d, $(basename $(SOURCES))))
MCU ?= -mcpu=cortex-a7 -march=armv7ve -mfpu=neon-vfpv4 -mlittle-endian -mfloat-abi=hard
EXTRA_ARCH_CFLAGS ?=
ARCH_CFLAGS ?= -DUSE_FULL_LL_DRIVER \
-DSTM32MP157Cxx \
-DSTM32MP1 \
-DCORE_CA7 \
$(EXTRA_ARCH_CFLAGS) \
OPTFLAG ?= -O0
AFLAGS = $(MCU)
CFLAGS = -g2 \
-fno-common \
$(ARCH_CFLAGS) \
$(MCU) \
$(INCLUDES) \
-fdata-sections -ffunction-sections \
-nostartfiles \
$(EXTRACFLAGS)\
CXXFLAGS = $(CFLAGS) \
-std=c++2a \
-fno-rtti \
-fno-exceptions \
-fno-unwind-tables \
-fno-threadsafe-statics \
-mno-unaligned-access \
-Werror=return-type \
-Wdouble-promotion \
-Wno-register \
-Wno-volatile \
$(EXTRACXXFLAGS) \
LINK_STDLIB ?= -nostdlib
LFLAGS = -Wl,--gc-sections \
-Wl,-Map,$(BUILDDIR)/$(BINARYNAME).map,--cref \
$(MCU) \
-T $(LINKSCR) \
$(LINK_STDLIB) \
-nostartfiles \
-ffreestanding \
-Wl,--no-warn-rwx-segments \
$(EXTRALDFLAGS) \
DEPFLAGS = -MMD -MP -MF $(OBJDIR)/$(basename $<).d
# By default, this uses the toolchain on your path
# Override by invoking make with TOOLCHAIN_DIR=/my/location/ (final slash is required)
TOOLCHAIN_DIR ?=
ARCH = arm-none-eabi
CC = ${TOOLCHAIN_DIR}$(ARCH)-gcc
CXX = ${TOOLCHAIN_DIR}$(ARCH)-g++
LD = ${TOOLCHAIN_DIR}$(ARCH)-g++
AS = ${TOOLCHAIN_DIR}$(ARCH)-as
OBJCPY = ${TOOLCHAIN_DIR}$(ARCH)-objcopy
OBJDMP = ${TOOLCHAIN_DIR}$(ARCH)-objdump
GDB = ${TOOLCHAIN_DIR}$(ARCH)-gdb
SZ = ${TOOLCHAIN_DIR}$(ARCH)-size
SZOPTS = -d
ELF = $(BUILDDIR)/$(BINARYNAME).elf
HEX = $(BUILDDIR)/$(BINARYNAME).hex
BIN = $(BUILDDIR)/$(BINARYNAME).bin
all: Makefile makefile-common.mk $(ELF) $(UIMAGENAME)
@:
elf: $(ELF)
install:
@if [ "$${SD_DISK_DEVPART}" = "" ]; then echo "Please specify the disk and partition like this: make install SD_DISK_DEVPART=/dev/diskXs3"; \
else \
echo "sudo dd if=${UIMAGENAME} of=$${SD_DISK_DEVPART}" && \
sudo dd if=${UIMAGENAME} of=$${SD_DISK_DEVPART}; fi
$(OBJDIR)/%.o: %.s
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(AS) $(AFLAGS) $< -o $@
$(OBJDIR)/%.o: %.c $(OBJDIR)/%.d
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(CC) -c $(DEPFLAGS) $(OPTFLAG) $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: %.c[cp]* $(OBJDIR)/%.d
@mkdir -p $(dir $@)
$(info Building $< at $(OPTFLAG))
@$(CXX) -c $(DEPFLAGS) $(OPTFLAG) $(CXXFLAGS) $< -o $@
$(ELF): $(OBJECTS) $(LINKSCR)
$(info Linking...)
@$(LD) $(LFLAGS) -o $@ $(OBJECTS)
$(BIN): $(ELF)
$(OBJCPY) -O binary $< $@
$(HEX): $(ELF)
@$(OBJCPY) --output-target=ihex $< $@
@$(SZ) $(SZOPTS) $(ELF)
$(UIMAGENAME): $(BIN)
$(info Creating uimg file)
python3 $(SCRIPTDIR)/uimg_header.py $< $@ $(LOADADDR) $(ENTRYPOINT)
%.d: ;
clean:
rm -rf build
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEPS)
endif
.PRECIOUS: $(DEPS) $(OBJECTS) $(ELF)
.PHONY: all clean install
.PHONY: compile_commands
compile_commands:
compiledb make
compdb -p ./ list > compile_commands.tmp 2>/dev/null
rm compile_commands.json
mv compile_commands.tmp compile_commands.json