-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile.arm
189 lines (148 loc) · 5 KB
/
Makefile.arm
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
# regbits: C++ templates for type-safe bit manipulation
# Copyright (C) 2019,2020 Mark R. Rubin
#
# This file is part of regbits.
#
# The regbits 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.
#
# The regbits 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 (LICENSE.txt) along with the regbits program. If not, see
# <https://www.gnu.org/licenses/gpl.html>
ifndef GCC_ARM_ROOT
$(error set GCC_ARM_ROOT environment variable)
endif
.SUFFIXES:
CXX_STANDARD ?= c++17
# OPTIMIZE ?= -O1
DEBUG ?= -g3
GCC_ARM_BUG ?= -DGCC_ARM_BUG
EXTRA_CC ?=
EXTRA_CXX ?=
THUMB_ARM ?= -mthumb
MCU ?=
ACPU ?= cortex-m0plus
TUNE ?=
ARCH ?=
TPCS ?=
# aapcs aapcs-linux apcs-gnu atpcs iwmmxt
ABI ?= apcs-gnu
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
OBJDUMP = arm-none-eabi-objdump
READELF = arm-none-eabi-readelf
export PATH := $(GCC_ARM_ROOT)/bin:$(PATH)
C_ELFS = $(subst ../../../../,,$(wildcard ../../../../*.c))
CXX_ELFS = $(subst ../../../../,,$(wildcard ../../../../*.cxx))
ELFS = $(subst .c,.elf,$(C_ELFS)) $(subst .cxx,.elf,$(CXX_ELFS))
DMPS = $(subst .elf,.elf.dmp,$(ELFS)) $(subst .elf,.o.dmp,$(ELFS))
RLFS = $(subst .elf,.elf.rdelf,$(ELFS))
OUTS = $(subst .elf,.out,$(ELFS))
INL_FILE = ../../../../do_tests.inl
o_all: o1 o2 o3
# gdb: $(OUTS) main.o $(INL_FILE) $(INIT_FILE).o $(ELFS) $(DMPS) $(RLFS)
# @ if [ -z $$GDB_OPENOCD ] ; then \
# echo Set 'GDB_OPENOCD' environment variable and attach hardware \
# to make '"gdb"' target. ; \
# else \
# ../../../../unittest.py arm '$(MCU) $(ACPU) $(ABI) $(TUNE) $(ARCH) $(TPCS) $(OPTIMIZE) $(DEBUG) $(GCC_ARM_BUG) $(EXTRA_CXX) $(CXX_STANDARD)' ../../../../do_tests.inl *.o.dmp *.out ; \
# fi
#
# o_gdb:
# @ rm -f $(OPT_LEVEL)/*
# @ make --no-print-directory clean
# @ make OPTIMIZE=-$(OPT_LEVEL) --no-print-directory gdb | tee $(OPT_LEVEL)/make.out
o1: O1/results.txt
o2: O2/results.txt
o3: O3/results.txt
.PHONY: clean cleanbin
clean: cleanbin
@ rm -f O?/*.dmp O?/*.map O?/*.out O?/*.rdelf O?/*.dmp O?/make.out O?/results.txt
cleanbin:
@ rm -f O?/*.o O?/*.elf O?/*.map
.PRECIOUS: O1/%.o O1/%.elf O2/%.o O2/%.elf O3/%.o O3/%.elf
INCLUDES = -I. -I../../../.. -I../../../../.. -Iinclude
vpath %c ../../../.. ../../..
vpath %cxx ../../../..
ARM_OPTS = $(THUMB_ARM)
ifdef ACPU
ARM_OPTS += -mcpu=$(ACPU)
endif
ifdef TUNE
ARM_OPTS += -mtune=$(TUNE)
endif
ifdef ARCH
ARM_OPTS += -march=$(ARCH)
endif
ifdef TPCS
ARM_OPTS += -m$(TPCS)
endif
ifdef ABI
ARM_OPTS += -mabi=$(ABI)
endif
# otherwise won't link without non-existent "unwind" library
ARM_OPTS += -fno-exceptions -fno-unwind-tables
CCOPTS = -Wall \
$(OPTIMIZE) \
$(DEBUG) \
$(INCLUDES) \
-D__VTOR_PRESENT \
$(ARM_OPTS) \
$(EXTRA_CC) \
-DREGBITS_PERIPH_BASE=$(PERIPH_BASE)
CXXOPTS = -Wall \
-std=$(CXX_STANDARD) \
$(OPTIMIZE) \
$(DEBUG) \
$(INCLUDES) \
-fno-threadsafe-statics \
$(ARM_OPTS) \
$(GCC_ARM_BUG) \
$(EXTRA_CXX) \
-DREGBITS_PERIPH_BASE=$(PERIPH_BASE)
LDOPTS = -marmelf -static -M --print-memory-usage # -nostdlib
# $(OPT_LEVEL)/%.out: %.elf
# @ if [ -z $$GDB_OPENOCD ] ; then \
# if [ -x $< ] ; then \
# echo Set 'GDB_OPENOCD' environment variable and attach hardware \
# to make '"gdb"' target. ; \
# else \
# rm -f $@ ; \
# $$GDB_OPENOCD $< -q -x ../../../../$(subst .elf,.gdb,$^) -x ../../../unittest.gdb > /dev/null ; \
# sleep 2 ; \
# fi ; \
# fi
# $$GDB_OPENOCD $< -x ../../../../$(subst .elf,.gdb,$^) -x ../../../unittest.gdb ; \
define OPTIMIZE_DIR_RULES
$(1)/%.o: %.c
@- $(CC) -c -$(1) $(CCOPTS) $$< -o $$@
$(1)/%.o: %.cxx
@- $(CXX) -c -$(1) $(CXXOPTS) $$< -o $$@
$(1)/results.txt: $(addprefix $(1)/,$(DMPS))
@ tail --lines=3 $(1)/*.map > $(1)/results.txt
@ ../../../../unittest.py arm '$(MCU) $(ACPU) $(ABI) $(TUNE) $(ARCH) $(TPCS) $(OPTIMIZE) $(DEBUG) $(GCC_ARM_BUG) $(EXTRA_CXX) $(CXX_STANDARD) -$(1)' ../../../../do_tests.inl $(1)/*.o.dmp >> $(1)/results.txt
$(1)/%.elf.rdelf: $(1)/%.elf
@- $(READELF) -a $$< > $$@
$(1)/%.o.dmp: $(1)/%.o
@- $(OBJDUMP) -dC -j.text -j.rodata -j.data -j.bss $$< > $$@
$(1)/%.elf.dmp: $(1)/%.elf
@- if [ -f $$< ] ; then \
$(OBJDUMP) -dC -j.text -j.rodata -j.data -j.bss $$< > $$@ ; \
fi
$(1)/%.elf: $(1)/%.o $(1)/main.o $(1)/$(INIT_FILE).o
@- $(LD) -o $$@ \
$$^ \
$(LDOPTS) \
$(GNU_ARM_LIBDIRS) \
$(LDLIBS) \
-T $(LD_SCRIPT) \
endef
$(foreach dir,O1 O2 O3,$(eval $(call OPTIMIZE_DIR_RULES,$(dir))))