Makefile.rules
7.11 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
# common part for all tests
#build
#TOP="$(TOP)"
#BUILD="$(TOP)/$(basename $@)"
#PRJ="$(notdir $(basename $@))"
#APP="$(TOP)/$@"
#CFLAGS="$(CFLAGS)"
#FPUCFG=$(FPUCFG)
# the TOP directory as absolute path
ifndef TOP
$(error TOP is not set)
endif
# building directory (for specific project)
ifndef BUILD
$(error BUILD is not set)
endif
# project directory (where files with the source code are)
ifndef PRJ
$(error PRJ is not set)
endif
# ELF file for the project
ifndef APP
$(error APP is not set)
endif
# type of FPU (also subdirectory in building directory)
ifndef FPUCFG
$(error FPUCFG is not set)
endif
ifndef LIBSRCDIR
LIBSRCDIR=../libs
endif
#LNKSCRIPT=$(TOP)/scripts/linkleon
ifdef LDSCRIPT
LNKSCRIPT=$(TOP)/scripts/$(LDSCRIPT)
else
LNKSCRIPT=$(TOP)/scripts/linkram2
endif
#LASTTEXTSECTION=.bss
#LASTTEXTSECTION=.data
SIMCFG_SCRIPT=$(TOP)/scripts/makemgsimini.py
SIMCFG_TMP=$(TOP)/scripts/config-simple-uartlite.ini-template
LIBDIR=$(BUILD)lib
INCDIR=$(BUILD)include
# LLVM toolchain
ifeq ($(TOOL),llvm)
TOOLCHAIN=sparc-daiteq-elf
CC=clang
LC=llc
CFLAGS=$(CF) -mcpu=leon2 -DUSEDBSP=BSP_AT697
CFLAGS+=-ggdb -target $(TOOLCHAIN) -Xassembler -Aleon -Xassembler --has-swar -Xassembler --has-fhalf -Xassembler --has-fpack
#CFLAGS+=-Xlinker -debug-pass=Structure -Xlinker -debug -Xlinker --asm-verbose
#CFLAGS+=-Xlinker --print-after-all
#CFLAGS+=-Xlinker --view-legalize-types-dags
#CFLAGS+=-save-temps
endif
# GCC toolchain - BCC 2.0.2
ifeq ($(TOOL),gcc)
TOOLCHAIN=sparc-gaisler-elf
CC=$(TOOLCHAIN)-gcc
CFLAGS=$(CF) -mcpu=leon -qbsp=leon2 -mfix-at697f
CFLAGS+=-ggdb
endif
CFLAGS+=$(APPFLAGS)
INCLUDE+=-I. -I$(INCDIR)
# no libraries
LDFLAGS=-N -nostdlib -nostartfiles -T $(LNKSCRIPT) -e _hardreset
LDFLAGS+=--gc-sections
# --print-gc-sections
DATSECS=.text .data
APP_OBJS=$(SOURCES:%.c=$(BUILD)$(PRJ)$(VER)/%.o)
APP_DIS=$(APP:%.elf=%.dis)
APP_MGINI=$(APP:%.elf=%.ini)
APP_AST=$(APP:%.elf=%.ast)
APP_LL=$(APP:%.elf=%.ll)
APP_FPI=$(APP:%.elf=%-compile-fpu.log)
APP_CAL=$(APP:%.elf=%-compile-sfcalls.log)
APP_MCAL=$(APP:%.elf=%-compile-mcalls.log)
APP_DAT=$(APP:%.elf=%.dat)
STRIP_APP=$(APP:%.elf=%-strip.elf)
STRIP_APP_DAT=$(APP:%.elf=%-strip.dat)
BOOTOBJ=$(BUILD)bsplib/locore1.o
#The following include is workaround if clang option 'daiteq-fpu-type' does not work
#include $(TOP)/Makefile.fpu
$(info >>> APP <<< T=$(TOP) , B=$(BUILD) , P=$(PRJ) , A=$(APP) , VER=$(VER), CF=$(CFLAGS) , F=$(FPUCFG))
.SUFFIXES:
.PHONY: clean all withsim build sim
#all:
#@for t in $(LISTOFTESTS); \
#do \
#echo Build $$t ;\
#make -f Makefile build APPDIR=$$t; \
#done
#withsim:
#@for t in $(LISTOFTESTS); \
#do \
#echo Build $$t ;\
#make -f Makefile build APPDIR=$$t; \
#make -f Makefile sim APPDIR=$$t; \
#done
#$(APP_MGINI) $(APP_ASTS) $(APP_IRS) $(STRIP_APP) $(STRIP_APP_DAT)
build: $(LIBDIR) $(INCDIR) $(LIBS:%=$(LIBDIR)/lib%.a) $(BUILD)$(PRJ)$(VER) $(APP) $(APP_DIS) $(APP_DAT) $(APP_FPI) $(APP_CAL) $(APP_MCAL) $(APP_MGINI)
@echo "Compiled"
$(BLDDIR):
@mkdir -p $@
$(LIBDIR):
@mkdir -p $@
$(INCDIR):
@mkdir -p $@
$(BUILD)$(PRJ)$(VER):
@mkdir -p $@
#### Libraries ####
$(LIBDIR)/libbsp.a: $(TOP)/$(LIBSRCDIR)/bsp
@echo "BSP in $<"
@make -C $< -f Makefile export TOP="$(TOP)" TOOL=$(TOOL) DSTPATH="$(LIBDIR)" INCPATH="$(INCDIR)" BLDPATH="$(BUILD)bsplib" CFLAGS="$(CFLAGS)" FPUCFG=$(FPUCFG)
$(LIBDIR)/libm.a: $(TOP)/$(LIBSRCDIR)/openlibm
@echo "openlibm in $<"
@make -C $< -f Makefile export TOP="$(TOP)" TOOL=$(TOOL) DSTPATH="$(LIBDIR)" INCPATH="$(INCDIR)" BLDPATH="$(BUILD)openlibm" CF="$(CFLAGS)" FPUCFG=$(FPUCFG)
$(LIBDIR)/libins.a: $(TOP)/$(LIBSRCDIR)/builtins
@echo "builtins in $<"
@make -C $< -f Makefile export TOP="$(TOP)" TOOL=$(TOOL) DSTPATH="$(LIBDIR)" INCPATH="$(INCDIR)" BLDPATH="$(BUILD)inslib" APPCFLAGS="$(CFLAGS)" FPUCFG=$(FPUCFG)
# soft-float library is only one for all daifpu configurations
$(LIBDIR)/libsoftfloat.a: $(TOP)/$(LIBSRCDIR)/softfloat/build/DAITEQ-LEON-LLVM
@echo "softfloat in $<"
@make -C $< -f Makefile export TOP="$(TOP)" TOOL=$(TOOL) DSTPATH="$(LIBDIR)" INCPATH="$(INCDIR)" CFLAGS="$(CFLAGS)"
# test-float library
$(LIBDIR)/libtestfloat.a: $(TOP)/$(LIBSRCDIR)/testfloat
@echo "testfloat in $<"
@make -C $< -f Makefile export TOP="$(TOP)" TOOL=$(TOOL) DSTPATH="$(LIBDIR)" INCPATH="$(INCDIR)" BLDPATH="$(BUILD)testfloat" CFLAGS="$(CFLAGS)" FPUCFG=$(FPUCFG)
#### Apps ####
$(APP_DIS): $(APP)
$(TOOLCHAIN)-objdump -S --visualize-jumps $< > $@
$(STRIP_APP): $(APP)
cp $(APP) $(STRIP_APP)
$(TOOLCHAIN)-strip $(STRIP_APP)
$(STRIP_APP_DAT): $(STRIP_APP)
$(TOOLCHAIN)-objdump -s $(DATSECS:%=-j %) $< > $@
$(APP_DAT): $(APP)
$(TOOLCHAIN)-objdump -s $(DATSECS:%=-j %) $< > $@
$(APP_MGINI): $(APP)
$(TOOLCHAIN)-size -A -d -t $< > /tmp/sectable.txt; \
$(SIMCFG_SCRIPT) /tmp/sectable.txt $(SIMCFG_TMP) $@; \
rm -f /tmp/sectable.txt
$(BUILD)$(PRJ)$(VER)/%.o:$(TSTDIR)/$(PRJ)/%.c $(DEPFILES:%=$(TSTDIR)/$(PRJ)/%)
@echo " o Compile '$^' -> $@"
@echo " > $(CC) -daiteq-fpu-type=$(FPUCFG) -DTESTID=$(ID) $(CFLAGS) $(INCLUDE) -c $< -o $@ <"
@$(CC) -daiteq-fpu-type=$(FPUCFG) -DTESTID=$(ID) $(CFLAGS) $(INCLUDE) -c $< -o $@
# the first function in BSP library should be a _hardreset function or directly use some object file (bootmain.o)
$(APP): $(APP_OBJS) $(DEPFILES:%=$(TSTDIR)/$(PRJ)/%)
$(TOOLCHAIN)-ld $(LDFLAGS) -L $(LIBDIR) -o $@ $(BOOTOBJ) $(APP_OBJS) $(LIBS:%=-l%)
#$(BUILDDIR)/$(COMMONDIR)/bootmini.o:$(COMMONDIR)/boot_mini.S
# @$(CC) $(CFLAGS) -c $< -o $@
#
#$(BUILDDIR)/$(COMMONDIR)/my_printf.o:$(COMMONDIR)/my_printf.c
# @$(CC) $(CFLAGS) -c $< -o $@
#
#$(BUILDDIR)/$(COMMONDIR)/leon-myuart.o:$(COMMONDIR)/leon-myuart.c
# @$(CC) $(CFLAGS) -c $< -o $@
#
$(APP_AST):$(PRJ)/%.c
@$(CC) -Xclang -ast-dump -fno-color-diagnostics -S $(CFLAGS) $< >$@ 2>$@_err
$(APP_LL):$(PRJ)/%.c
@$(CC) -emit-llvm $(CFLAGS) $< -S -o $@ 2>$@_err
$(APP_FPI):$(APP_DIS)
@$(TOP)/scripts/inspectfp.py $< >$@
NOSFLIBS=$(filter-out softfloat,$(LIBS))
NOMLIBS=$(filter-out m,$(LIBS))
$(APP_CAL):$(APP_OBJS)
@echo " ~ Check linking $(APP) without softfloat library"
@( $(TOOLCHAIN)-ld $(LDFLAGS) -L $(LIBDIR) -o /tmp/$(notdir $@).toremove $^ $(NOSFLIBS:%=-l%) 2>&1 >/dev/null | grep -E "undefined reference to" | sed -e 's/undefined reference to/library call/g' | tee $@; (exit 0); )
$(APP_MCAL):$(APP_OBJS)
@echo " ~ Check linking $(APP) without m library"
@( $(TOOLCHAIN)-ld $(LDFLAGS) -L $(LIBDIR) -o /tmp/$(notdir $@).toremove $^ $(NOMLIBS:%=-l%) 2>&1 >/dev/null | grep -E "undefined reference to" | sed -e 's/undefined reference to/library call/g' | tee $@; (exit 0); )
# ------------------------------------------------------------------------------
# clean generated files
clean:
rm -f $(APP) $(APP_OBJS) $(APP) $(APP_MGINI)
# ------------------------------------------------------------------------------
# run simulation
ifeq ($(NOLOG),y)
SIM_LOGOUT=/dev/null
else
SIM_LOGFILE=$(notdir $(APP:%.elf=%-sim-stderr.log))
SIM_LOGOUT=$(SIM_LOGFILE:%=$(SIMDIR)/%)
endif
SIM_OUTFILE=$(notdir $(APP:%.elf=%-sim-stdout.log))
SIM_OUTPUT=$(SIM_OUTFILE:%=$(SIMDIR)/%)
sim: $(SIM_OUTPUT)
@echo "Simulation done"
$(SIM_OUTPUT): $(APP) $(APP_MGINI)
mgsim -c $(APP_MGINI) -t --no-edge-properties $(APP) 2>$(SIM_LOGOUT) | tee $(SIM_OUTPUT)
@echo '~EoS~'