Makefile 9.11 KB
Newer Older
grischka's avatar
grischka committed
1
2
3
4
#
# Tiny C Compiler Makefile - tests
#

5
TOP = ..
6
include $(TOP)/Makefile
grischka's avatar
grischka committed
7
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
grischka's avatar
grischka committed
8
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
9

grischka's avatar
grischka committed
10
# what tests to run
grischka's avatar
grischka committed
11
TESTS = \
12
13
 hello-exe \
 hello-run \
grischka's avatar
grischka committed
14
15
 libtest \
 test3 \
grischka's avatar
grischka committed
16
 memtest \
grischka's avatar
grischka committed
17
 dlltest \
18
 abitest \
19
 asm-c-connect-test \
20
 vla_test-run \
21
 cross-test \
22
23
 tests2-dir \
 pp-dir
24
25
26

BTESTS = test1b test3b btest

grischka's avatar
grischka committed
27
# test4 -- problem with -static
28
# asmtest / asmtest2 -- minor differences with gcc
grischka's avatar
grischka committed
29
# btest -- works on i386 (including win32)
grischka's avatar
grischka committed
30

31
32
# bounds-checking is supported only on i386
ifneq ($(ARCH),i386)
33
 TESTS := $(filter-out $(BTESTS),$(TESTS))
34
endif
grischka's avatar
grischka committed
35
ifdef CONFIG_WIN32
grischka's avatar
grischka committed
36
 TESTS := $(filter-out $(BTESTS),$(TESTS))
37
endif
grischka's avatar
grischka committed
38
39
ifdef CONFIG_OSX # -run only
 TESTS := hello-run libtest tests2-dir pp-dir
40
endif
41
ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
42
43
 TESTS := $(filter-out vla_test-run,$(TESTS))
endif
44
45
46
ifeq ($(CONFIG_arm_eabi),yes)
 TESTS := $(filter-out test3,$(TESTS))
endif
47
ifeq (,$(filter i386 x86_64,$(ARCH)))
48
 TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
grischka's avatar
grischka committed
49
endif
50
ifndef CONFIG_cross
51
52
 TESTS := $(filter-out cross-%,$(TESTS))
endif
grischka's avatar
grischka committed
53

grischka's avatar
grischka committed
54
55
ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
 PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
56
57
endif

58
RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
59
DISAS = objdump -d
grischka's avatar
grischka committed
60
DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
61
62

all test : clean-s $(TESTS)
grischka's avatar
grischka committed
63

64
65
hello-exe: ../examples/ex1.c
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
66
	$(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
67
68

hello-run: ../examples/ex1.c
grischka's avatar
grischka committed
69
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
70
	$(TCC) -run $< || $(DUMPTCC)
grischka's avatar
grischka committed
71

72
libtest: libtcc_test$(EXESUF)
grischka's avatar
grischka committed
73
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
74
	./libtcc_test$(EXESUF) $(TCCFLAGS)
grischka's avatar
grischka committed
75

76
77
libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
grischka's avatar
grischka committed
78

grischka's avatar
grischka committed
79
%-dir:
grischka's avatar
grischka committed
80
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
81
	$(MAKE) -k -C $*
grischka's avatar
grischka committed
82

83
# test.ref - generate using cc
grischka's avatar
grischka committed
84
test.ref: tcctest.c
85
86
	$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
	./tcctest.gcc > $@
grischka's avatar
grischka committed
87
88

# auto test
89
test1 test1b: tcctest.c test.ref
grischka's avatar
grischka committed
90
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
91
	$(TCC) -run $< > test.out1
92
	@diff -u test.ref test.out1 && echo "Auto Test OK"
grischka's avatar
grischka committed
93
94

# iterated test2 (compile tcc then compile tcctest.c !)
95
test2 test2b: tcctest.c test.ref
grischka's avatar
grischka committed
96
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
97
	$(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
98
	@diff -u test.ref test.out2 && echo "Auto Test2 OK"
grischka's avatar
grischka committed
99
100

# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
101
test3 test3b: tcctest.c test.ref
grischka's avatar
grischka committed
102
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
103
	$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
104
105
106
	@diff -u test.ref test.out3 && echo "Auto Test3 OK"

test%b : TCCFLAGS += -b
grischka's avatar
grischka committed
107
108

# binary output test
grischka's avatar
grischka committed
109
test4: tcctest.c test.ref
grischka's avatar
grischka committed
110
111
	@echo ------------ $@ ------------
# object + link output
grischka's avatar
grischka committed
112
	$(TCC) -c -o tcctest3.o $<
grischka's avatar
grischka committed
113
114
115
	$(TCC) -o tcctest3 tcctest3.o
	./tcctest3 > test3.out
	@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
grischka's avatar
grischka committed
116
# dynamic output
grischka's avatar
grischka committed
117
	$(TCC) -o tcctest1 $<
grischka's avatar
grischka committed
118
119
	./tcctest1 > test1.out
	@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
grischka's avatar
grischka committed
120
# dynamic output + bound check
grischka's avatar
grischka committed
121
	$(TCC) -b -o tcctest4 $<
grischka's avatar
grischka committed
122
123
	./tcctest4 > test4.out
	@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
grischka's avatar
grischka committed
124
# static output
grischka's avatar
grischka committed
125
	$(TCC) -static -o tcctest2 $<
grischka's avatar
grischka committed
126
127
	./tcctest2 > test2.out
	@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
grischka's avatar
grischka committed
128

grischka's avatar
grischka committed
129
130
131
# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
dlltest:
	@echo ------------ $@ ------------
132
133
	$(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
grischka's avatar
grischka committed
134
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
135
136
ifndef CONFIG_WIN32
	@echo ------------ $@ with PIC ------------
137
	$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
grischka's avatar
grischka committed
138
	$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
139
	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
grischka's avatar
grischka committed
140
	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
grischka's avatar
grischka committed
141
142
143
endif
	@rm tcc2$(EXESUF) libtcc2$(DLLSUF)

grischka's avatar
grischka committed
144
145
memtest:
	@echo ------------ $@ ------------
146
147
148
	$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
grischka's avatar
grischka committed
149

grischka's avatar
grischka committed
150

grischka's avatar
grischka committed
151
# memory and bound check auto test
grischka's avatar
grischka committed
152
153
BOUNDS_OK  = 1 4 8 10 14
BOUNDS_FAIL= 2 5 7 9 11 12 13 15
grischka's avatar
grischka committed
154

grischka's avatar
grischka committed
155
btest: boundtest.c
grischka's avatar
grischka committed
156
157
	@echo ------------ $@ ------------
	@for i in $(BOUNDS_OK); do \
158
	   echo ; echo --- boundtest $$i ---; \
159
	   if $(TCC) -b -run $< $$i ; then \
160
	       echo succeeded as expected; \
grischka's avatar
grischka committed
161
162
163
164
165
	   else\
	       echo Failed positive test $$i ; exit 1 ; \
	   fi ;\
	done ;\
	for i in $(BOUNDS_FAIL); do \
166
	   echo ; echo --- boundtest $$i ---; \
167
	   if $(TCC) -b -run $< $$i ; then \
grischka's avatar
grischka committed
168
169
	       echo Failed negative test $$i ; exit 1 ;\
	   else\
170
	       echo failed as expected; \
grischka's avatar
grischka committed
171
172
	   fi ;\
	done ;\
173
	echo; echo Bound test OK
grischka's avatar
grischka committed
174
175

# speed test
176
speedtest: ex2 ex3
grischka's avatar
grischka committed
177
178
	@echo ------------ $@ ------------
	time ./ex2 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
179
	time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
grischka's avatar
grischka committed
180
	time ./ex3 35
grischka's avatar
grischka committed
181
	time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
grischka's avatar
grischka committed
182

grischka's avatar
grischka committed
183
weaktest: tcctest.c test.ref
184
	$(TCC) -c $< -o weaktest.tcc.o
185
	$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
186
	objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
187
188
	objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
	diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
189

grischka's avatar
grischka committed
190
ex%: $(TOPSRC)/examples/ex%.c
191
	$(CC) -o $@ $< $(CFLAGS)
grischka's avatar
grischka committed
192
193
194

# tiny assembler testing
asmtest.ref: asmtest.S
195
	$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
196
	objdump -D asmtest.ref.o > asmtest.ref
grischka's avatar
grischka committed
197

198
asmtest asmtest2: asmtest.ref
grischka's avatar
grischka committed
199
	@echo ------------ $@ ------------
200
	$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
201
	objdump -D asmtest.o > asmtest.out
grischka's avatar
grischka committed
202
203
	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi

204
205
206
# test assembler with tcc compiled by itself
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)

207
208
# Check that code generated by libtcc is binary compatible with
# that generated by CC
209
210
abitest-cc$(EXESUF): abitest.c $(LIBTCC)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
211

212
abitest-tcc$(EXESUF): abitest.c libtcc.c
213
	$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
214

215
216
ABITESTS := abitest-cc$(EXESUF)
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
217
 ABITESTS += abitest-tcc$(EXESUF)
218
219
220
endif

abitest: $(ABITESTS)
221
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
222
	./abitest-cc$(EXESUF) $(TCCFLAGS)
223
224
225
ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
	./abitest-tcc$(EXESUF) $(TCCFLAGS)
endif
226

227
vla_test$(EXESUF): vla_test.c
228
229
	$(TCC) -o $@ $^

230
231
232
233
vla_test-run: vla_test$(EXESUF)
	@echo ------------ $@ ------------
	./vla_test$(EXESUF)

234
235
236
asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
	$(TCC) -o $@ $^

237
238
239
240
241
242
243
asm-c-connect-%.o: asm-c-connect-%.c
	$(TCC) -c -o $@ $<

asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
	$(TCC) -o $@ $^

asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
244
	@echo ------------ $@ ------------
grischka's avatar
grischka committed
245
246
247
	./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
	./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
	@diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
248

249
250
251
cross-test :
	@echo ------------ $@ ------------
	$(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
252
	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
253
	$(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
254
	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
255
	$(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
grischka's avatar
grischka committed
256
257
	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
	$(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
258
259
260
261
262
	$(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"

grischka's avatar
grischka committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# targets for development
%.bin: %.c tcc
	$(TCC) -g -o $@ $<
	$(DISAS) $@

instr: instr.o
	objdump -d instr.o

instr.o: instr.S
	$(CC) -o $@ -c $< -O2 -Wall -g

cache: tcc_g
	cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
	vg_annotate tcc.c > /tmp/linpack.cache.log

# clean
clean:
grischka's avatar
grischka committed
280
281
	rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
	rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
282
	rm -f asm-c-connect$(EXESUF)
grischka's avatar
grischka committed
283
284
285
	rm -f ex? tcc_g weaktest.*.txt *.def
	@$(MAKE) -C tests2 $@
	@$(MAKE) -C pp $@
286
287
288
289

# silent clean, used before running tests
clean-s:
	@$(MAKE) -s --no-print-directory clean