Fix compile warning with cross compilers
[tinycc.git] / tests / Makefile
blob88c5879eba48f657e2e2ce46f1a2cd8806dfdf82
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
8 CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 memtest \
17 dlltest \
18 abitest \
19 asm-c-connect-test \
20 vla_test-run \
21 cross-test \
22 tests2-dir \
23 pp-dir
25 BTESTS = test1b test3b btest
27 # test4 -- problem with -static
28 # asmtest / asmtest2 -- minor differences with gcc
29 # btest -- works on i386 (including win32)
31 # bounds-checking is supported only on i386
32 ifneq ($(ARCH),i386)
33 TESTS := $(filter-out $(BTESTS),$(TESTS))
34 endif
35 ifdef CONFIG_WIN32
36 TESTS := $(filter-out $(BTESTS),$(TESTS))
37 endif
38 ifdef CONFIG_OSX # -run only
39 TESTS := hello-run libtest tests2-dir pp-dir
40 endif
41 ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
42 TESTS := $(filter-out vla_test-run,$(TESTS))
43 endif
44 ifeq ($(CONFIG_arm_eabi),yes)
45 TESTS := $(filter-out test3,$(TESTS))
46 endif
47 ifeq (,$(filter i386 x86_64,$(ARCH)))
48 TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
49 endif
50 ifndef CONFIG_cross
51 TESTS := $(filter-out cross-%,$(TESTS))
52 endif
54 ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
55 PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
56 endif
58 RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
59 DISAS = objdump -d
60 DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
62 all test :
63 $(MAKE) clean-s
64 $(MAKE) $(TESTS)
66 hello-exe: ../examples/ex1.c
67 @echo ------------ $@ ------------
68 $(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
70 hello-run: ../examples/ex1.c
71 @echo ------------ $@ ------------
72 $(TCC) -run $< || $(DUMPTCC)
74 libtest: libtcc_test$(EXESUF)
75 @echo ------------ $@ ------------
76 ./libtcc_test$(EXESUF) $(TCCFLAGS)
78 libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
79 $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
81 %-dir:
82 @echo ------------ $@ ------------
83 $(MAKE) -k -C $*
85 # test.ref - generate using cc
86 test.ref: tcctest.c
87 $(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
88 ./tcctest.gcc > $@
90 # auto test
91 test1 test1b: tcctest.c test.ref
92 @echo ------------ $@ ------------
93 $(TCC) -run $< > test.out1
94 @diff -u test.ref test.out1 && echo "Auto Test OK"
96 # iterated test2 (compile tcc then compile tcctest.c !)
97 test2 test2b: tcctest.c test.ref
98 @echo ------------ $@ ------------
99 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
100 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
102 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
103 test3 test3b: tcctest.c test.ref
104 @echo ------------ $@ ------------
105 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
106 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
108 test%b : TCCFLAGS += -b
110 # binary output test
111 test4: tcctest.c test.ref
112 @echo ------------ $@ ------------
113 # object + link output
114 $(TCC) -c -o tcctest3.o $<
115 $(TCC) -o tcctest3 tcctest3.o
116 ./tcctest3 > test3.out
117 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
118 # dynamic output
119 $(TCC) -o tcctest1 $<
120 ./tcctest1 > test1.out
121 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
122 # dynamic output + bound check
123 $(TCC) -b -o tcctest4 $<
124 ./tcctest4 > test4.out
125 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
126 # static output
127 $(TCC) -static -o tcctest2 $<
128 ./tcctest2 > test2.out
129 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
131 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
132 dlltest:
133 @echo ------------ $@ ------------
134 $(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
135 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
136 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
137 ifndef CONFIG_WIN32
138 @echo ------------ $@ with PIC ------------
139 $(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
140 $(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
141 $(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
142 ./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
143 endif
144 @rm tcc2$(EXESUF) libtcc2$(DLLSUF)
146 memtest:
147 @echo ------------ $@ ------------
148 $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
149 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
150 ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
153 # memory and bound check auto test
154 # 3 is profiling test
155 BOUNDS_OK = 1 4 8 10 14 16
156 BOUNDS_FAIL= 2 5 6 7 9 11 12 13 15 17
158 btest: boundtest.c
159 @echo ------------ $@ ------------
160 @for i in $(BOUNDS_OK); do \
161 echo ; echo --- boundtest $$i ---; \
162 if $(TCC) -b -run $< $$i ; then \
163 echo succeeded as expected; \
164 else\
165 echo Failed positive test $$i ; exit 1 ; \
166 fi ;\
167 done ;\
168 for i in $(BOUNDS_FAIL); do \
169 echo ; echo --- boundtest $$i ---; \
170 if $(TCC) -b -run $< $$i ; then \
171 echo Failed negative test $$i ; exit 1 ;\
172 else\
173 echo failed as expected; \
174 fi ;\
175 done ;\
176 echo; echo Bound test OK
178 # speed test
179 speedtest: ex2 ex3
180 @echo ------------ $@ ------------
181 time ./ex2 1238 2 3 4 10 13 4
182 time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
183 time ./ex3 35
184 time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
186 weaktest: tcctest.c test.ref
187 $(TCC) -c $< -o weaktest.tcc.o
188 $(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
189 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
190 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
191 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
193 ex%: $(TOPSRC)/examples/ex%.c
194 $(CC) -o $@ $< $(CFLAGS)
196 # tiny assembler testing
197 asmtest.ref: asmtest.S
198 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
199 objdump -D asmtest.ref.o > asmtest.ref
201 asmtest asmtest2: asmtest.ref
202 @echo ------------ $@ ------------
203 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
204 objdump -D asmtest.o > asmtest.out
205 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
207 # test assembler with tcc compiled by itself
208 asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
210 # Check that code generated by libtcc is binary compatible with
211 # that generated by CC
212 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
213 $(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
215 abitest-tcc$(EXESUF): abitest.c libtcc.c
216 $(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
218 ABITESTS := abitest-cc$(EXESUF)
219 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
220 ABITESTS += abitest-tcc$(EXESUF)
221 endif
223 abitest: $(ABITESTS)
224 @echo ------------ $@ ------------
225 ./abitest-cc$(EXESUF) $(TCCFLAGS)
226 ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
227 ./abitest-tcc$(EXESUF) $(TCCFLAGS)
228 endif
230 vla_test$(EXESUF): vla_test.c
231 $(TCC) -o $@ $^
233 vla_test-run: vla_test$(EXESUF)
234 @echo ------------ $@ ------------
235 ./vla_test$(EXESUF)
237 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
238 $(TCC) -o $@ $^
240 asm-c-connect-%.o: asm-c-connect-%.c
241 $(TCC) -c -o $@ $<
243 asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
244 $(TCC) -o $@ $^
246 asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
247 @echo ------------ $@ ------------
248 ./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
249 ./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
250 @diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
252 cross-test :
253 @echo ------------ $@ ------------
254 $(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
255 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
256 $(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
257 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
258 $(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
259 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
260 $(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
261 $(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
262 $(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
263 $(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
264 $(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
266 # targets for development
267 %.bin: %.c tcc
268 $(TCC) -g -o $@ $<
269 $(DISAS) $@
271 instr: instr.o
272 objdump -d instr.o
274 instr.o: instr.S
275 $(CC) -o $@ -c $< -O2 -Wall -g
277 cache: tcc_g
278 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
279 vg_annotate tcc.c > /tmp/linpack.cache.log
281 # clean
282 clean:
283 rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
284 rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
285 rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
286 rm -f ex? tcc_g weaktest.*.txt *.def
287 @$(MAKE) -C tests2 $@
288 @$(MAKE) -C pp $@
290 # silent clean, used before running tests
291 clean-s:
292 @$(MAKE) -s --no-print-directory clean