-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile.arm.include
More file actions
193 lines (147 loc) · 4.76 KB
/
Makefile.arm.include
File metadata and controls
193 lines (147 loc) · 4.76 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- mode: makefile-gmake; -*-
#
# WMuCpp - Bare Metal C++
# Copyright (C) 2019 - 2026 Wilhelm Meier <wilhelm.wm.meier@googlemail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
export LC_ALL=C
.PHONY: all clean subclean subdirs ${subdirs}
all: $(targets) subdirs
subdirs: ${subdirs}
${subdirs}:
@if [ -d $@ ]; then ${MAKE} -C $@ all; fi
CCSRC = $(wildcard *.cc)
CCOBJ = $(patsubst %.cc, %.o, $(CCSRC))
CCDEP = $(patsubst %.cc, %.d, $(CCSRC))
CCASM = $(patsubst %.cc, %.s, $(CCSRC))
CSRC = $(wildcard *.c)
COBJ = $(patsubst %.c, %.o, $(CSRC))
CDEP = $(patsubst %.c, %.d, $(CSRC))
CASM = $(patsubst %.c, %.s, $(CSRC))
HSRC = $(wildcard *.h)
SRC += $(CCSRC)
SRC += $(CSRC)
OBJ += $(CCOBJ)
OBJ += $(COBJ)
ASM += $(CCASM)
ASM += $(CASM)
DEP += $(CCDEP)
DEP += $(CDEP)
ifndef CPU
CPU = cortex-m0
endif
MCUFLAGS = -mthumb -mcpu=$(CPU) $(FPU) $(FLOAT-ABI)
AXTRACTOR = $(HOME)/Projekte/wmgit/extract/axtractor
EXTRACTOR = $(HOME)/Projekte/wmgit/extract/extractor
EXTRACTDIR = .extractor
EXTRACTDIRNC = .extractornc
SRCHI = source-highlight
cchtml = $(patsubst %.cc, %.cc.html, $(CCSRC))
chtml = $(patsubst %.cc, %.cc.html, $(CSRC))
hhtml = $(patsubst %.h, %.h.html, $(HSRC))
ahtml = $(patsubst %.s, %.s.html, $(ASM))
shtml: $(cchtml) $(chtml) $(hhtml) $(ahtml)
#CPPFLAGS += -DNDEBUG
ifndef OPTFLAGS
OPTFLAGS += -O2
endif
CXXFLAGS += $(OPTFLAGS) -std=c++26 # -pedantic
CXXFLAGS += -fno-exceptions -fno-unwind-tables -fno-rtti -fno-threadsafe-statics #-Wgnu-string-literal-operator-template
CXXFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums
CXXFLAGS += -ffunction-sections -fdata-sections # seperate sections -> see --gc-sections
CXXFLAGS += -fconcepts
CXXFLAGS += -ftemplate-depth=2048
CXXFLAGS += -fstrict-aliasing -Wstrict-aliasing=1
CXXFLAGS += -Wall -Wextra
CXXFLAGS += -I.
CXXFLAGS += $(MCUFLAGS)
CFLAGS += $(OPTFLAGS) -std=c11 # wegen __flash
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums
CFLAGS += -Wall -Wextra
CFLAGS += -fstrict-aliasing -Wstrict-aliasing=1
CFLAGS += -I.
CFLAGS += $(MCUFLAGS)
ASMFLAGS += -fverbose-asm
ASMFLAGS += -Wa,-adhln
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--no-warn-rwx-segments
LDFLAGS += -specs=nano.specs
LDFLAGS += $(MCUFLAGS) -T$(LDSCRIPT)
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
AS = arm-none-eabi-as
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
SIZE = arm-none-eabi-size
NM = arm-none-eabi-nm
%.s: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(ASMFLAGS) -S -o $@ $(shell pwd)/$<
%.s: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(ASMFLAGS) -S -o $@ $(shell pwd)/$<
#%.S: %.s
# cat $< | c++filt | grep -v "^[ \t]*;" | grep -v "^[ \t]*\/\*.*\*\/$$" | grep -v "^[ \t]*__[Stz]" | grep -v "^\.L__" | grep -v "^.L[FV]" | grep -v "^\s*\.[fgi]" | grep -v "^[ \t]*$$" > $@
# #cat $< | grep -v "^#" | grep -v "^[ \t]*$$" | grep -v "[ \t]*\.cfi_" | grep -v "^\.L[A-Z][A-Z]" > $@
# Create extended listing file from ELF output file.
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
$(NM) -n $< > $@
%.elf: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(shell pwd)/$< --output $@ $(LDFLAGS) $(LOADLIBES)
%.elf: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(shell pwd)/$< --output $@ $(LDFLAGS) $(LOADLIBES)
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom $(shell pwd)/$< $@
%.bin: %.elf
$(OBJCOPY) -O binary -S $< $@
%.d: %.cc
$(CXX) -MM -MG $(CPPFLAGS) $(CXXFLAGS) $< | sed 's/$*\.o/& $@ $*.elf $<.extract/g' > $@
%.cc.extract: %.cc
$(EXTRACTOR) -lcpp -aA2 -aN -o$@ -d$(EXTRACTDIR) $<
%.h.extract: %.h
$(EXTRACTOR) -lcpp -aA2 -aN -o$@ -d$(EXTRACTDIR) $<
%.s.axtract: %.s
$(AXTRACTOR) -o$@ $<
%.cc.extractnc: %.cc
$(EXTRACTOR) -lcpp -aA2 -aN --sc -d$(EXTRACTDIRNC) -o$@ $<
%.h.extractnc: %.h
$(EXTRACTOR) -lcpp -aA2 -aN --sc -d$(EXTRACTDIRNC) -o$@ $<
%.cc.html: %.cc
$(EXTRACTOR) -x --eb --io $< | $(SRCHI) -scpp > $@
%.h.html: %.h
$(EXTRACTOR) -x --eb --io $< | $(SRCHI) -scpp > $@
%.s.html: %.s
$(SRCHI) -sasm -i $< -o $@
subclean:
@for d in ${subdirs}; do \
if [ -d $$d ]; then \
${MAKE} -C $$d clean; \
fi \
done
clean: subclean
$(RM) $(targets)
$(RM) $(OBJ)
$(RM) $(DEP)
$(RM) $(ASM)
$(RM) *.hex
$(RM) *.elf
$(RM) *.map
$(RM) *.lss
$(RM) *.eep
$(RM) *.size
$(RM) *.html
$(RM) *.S
-include $(DEP)