-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile.include
More file actions
262 lines (206 loc) · 7.15 KB
/
Makefile.include
File metadata and controls
262 lines (206 loc) · 7.15 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# -*- 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)
MCUFLAGS = -mmcu=$(MCU)
SIMAVR = ~/Projekte/simavr/simavr/run_avr
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 -Wnrvo
endif
#CXXFLAGS += $(OPTFLAGS) -std=c++17 #-pedantic
CXXFLAGS += $(OPTFLAGS) -std=c++23 # -pedantic
#CXXFLAGS += -O3 -std=c++17 # -pedantic
#CXXFLAGS += -nostdlib -fno-exceptions -fno-unwind-tables -fno-rtti -fno-threadsafe-statics
#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 += -DF_OSC=$(F_OSC) -DF_CPU=$(F_OSC)
#CXXFLAGS += -I/usr/local/avr/avr/include
#CXXFLAGS += -I. -I../../include -I../include -I../../../include
#CXXFLAGS += -I. -I../../include/std -I../include/std -I../../../include/std
#CXXFLAGS += -I/usr/include/simavr
#CXXFLAGS += -I/usr/avr/include
#CXXFLAGS += $(MCUFLAGS)
#CXXFLAGS += -Wa,-mgcc-isr # only for target atmega324pb - was missing in specs-atmega24pb
#CXXFLAGS += -fno-tree-switch-conversion
CFLAGS += $(OPTFLAGS) -std=gnu11 # wegen __flash
#CFLAGS += -Os -std=c11 -pedantic
CFLAGS += -funsigned-char -funsigned-bitfields -fshort-enums
CFLAGS += -Wall -Wextra
CFLAGS += -fstrict-aliasing -Wstrict-aliasing=1
#CFLAGS += -DF_OSC=$(F_OSC) -DF_CPU=$(F_OSC)
#CFLAGS += -I/usr/local/avr/avr/include
#CFLAGS += -I. -I../../include
#CFLAGS += -I../include
#CFLAGS += -I/usr/include/simavr
#CFLAGS += -I/usr/avr/include
#CFLAGS += $(MCUFLAGS)
#CFLAGS += -Wa,-mgcc-isr # only for target atmega324pb - was missing in specs-atmega24pb
ASMFLAGS += -fverbose-asm
ASMFLAGS += -Wa,-adhln
#ASMFLAGS += -Wa,-mgcc-isr
#LDFLAGS = $(MCUFLAGS) -Wl,-Map=main.map,--cref # -Wl,--gc-sections # remove unused function (s.a. byte.h)
#LDFLAGS += "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000" # simavrconsole.c
#LDFLAGS += "-Wl,--section-start=.mmcu=0x910000"
AVRDUDE_PROGRAMMER = avrisp2
AVRDUDE_PORT = usb
AVRDUDE_NO_VERIFY = -V
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
AVRDUDE_FLAGS += -C+/home/lmeier/Projekte/wmucpp/avrdude.conf
#CC = /usr/local/bin/avr-gcc
#CXX = /usr/local/bin/avr-g++
#CC = /usr/bin/avr-gcc
#CXX = /usr/bin/avr-g++
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
%.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]" > $@
%.s: %.s.save
cp $< $@
%.size: %.elf
avr-size $< > $@
# Program the device.
%.pgr: %.hex %.eep
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$< $(AVRDUDE_WRITE_EEPROM)
%.btl: %.hex
$(AVRDUDE) -p $(MCU) -P /dev/ttyUSB0 -c arduino -b 57600 -U flash:w:$<
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
%.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex $< $@
# 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 $< > $@
%: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(shell pwd)/$< --output $@ $(LDFLAGS) $(LOADLIBES)
%.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)/$< $@
%.d: %.cc
$(CXX) -MM -MG $(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 $@
%.out: %
./$< $(PARGS) > $@
%.aout: %
echo -n ".{output-caption} {counter:output}. Ausgabe des Programms: \`" > $@
echo -n $< >> $@
echo "\`" >> $@
echo "[role=\"output\"]" >> $@
echo "...." >> $@
-SIMPLETEST=${SIMPLETEST} ./$< $(PARGS) >> $@ 2>&1
echo "...." >> $@
%.aout2: %
echo -n ".{output-caption} {counter:output}. Ausgabe des Programms: \`" > $@
echo -n $< >> $@
echo "\`" >> $@
echo "[role=\"output\"]" >> $@
echo "...." >> $@
-SIMPLETEST=${SIMPLETEST} ./$< $(PARGS) >> $@ 2>/dev/null
echo "...." >> $@
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
$(RM) *.S
-include $(DEP)