Clear CFLAGS & LDFLAGS in tests
[tinycc.git] / tests / Makefile
blobe6c5660d66d89af7a4f1fc773570f845a8f0ef88
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 SRCDIR = $(top_srcdir)/tests
8 VPATH = $(SRCDIR) $(top_srcdir)
10 # clear CFLAGS and LDFLAGS
11 CFLAGS :=
12 LDFLAGS :=
14 # what tests to run
15 TESTS = \
16 hello-exe \
17 hello-run \
18 libtest \
19 test3 \
20 $(BTESTS) \
21 abitest \
22 vla_test-run \
23 moretests
25 BTESTS = test1b test3b btest
27 ifdef CONFIG_CROSS
28 TESTS += hello-cross
29 endif
31 # test4 -- problem with -static
32 # asmtest -- minor differences with gcc
33 # btest -- works on i386 (including win32)
35 # bounds-checking is supported only on i386
36 ifneq ($(ARCH),i386)
37 TESTS := $(filter-out $(BTESTS),$(TESTS))
38 endif
39 ifdef CONFIG_WIN32
40 TESTS := w32-prep $(filter-out $(BTESTS),$(TESTS))
41 endif
42 ifeq ($(TARGETOS),Darwin)
43 TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS))
44 endif
45 ifeq ($(ARCH),i386)
46 else ifneq ($(ARCH),x86-64)
47 TESTS := $(filter-out vla_test-run,$(TESTS))
48 endif
50 ifdef DISABLE_STATIC
51 export LD_LIBRARY_PATH:=$(CURDIR)/..
52 endif
54 ifeq ($(TARGETOS),Darwin)
55 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
56 export MACOSX_DEPLOYMENT_TARGET:=10.2
57 NATIVE_DEFINES+=-D_ANSI_SOURCE
58 endif
60 # run local version of tcc with local libraries and includes
61 TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
62 ifdef CONFIG_WIN32
63 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
64 endif
65 XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include
67 TCC = $(TOP)/tcc $(TCCFLAGS)
68 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
70 DISAS = objdump -d
72 # libtcc test
73 ifdef LIBTCC1
74 LIBTCC1:=$(TOP)/$(LIBTCC1)
75 endif
77 all test : $(TESTS)
79 hello-exe: ../examples/ex1.c
80 @echo ------------ $@ ------------
81 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
83 hello-cross: ../examples/ex1.c
84 @echo ------------ $@ ------------
85 for XTCC in $(PROGS_CROSS) ; \
86 do echo -n "Test of $$XTCC... "; \
87 out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \
88 test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \
89 echo "Success"; \
90 done
92 hello-run: ../examples/ex1.c
93 @echo ------------ $@ ------------
94 $(TCC) -run $<
96 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
97 @echo ------------ $@ ------------
98 ./libtcc_test$(EXESUF) lib_path=..
100 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
101 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
103 moretests:
104 @echo ------------ $@ ------------
105 $(MAKE) -C tests2
107 w32-prep:
108 cp ../libtcc1.a ../lib
110 # test.ref - generate using cc
111 test.ref: tcctest.c
112 $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
113 ./tcctest.cc > $@
115 # auto test
116 test1 test1b: tcctest.c test.ref
117 @echo ------------ $@ ------------
118 $(TCC) -run $< > test.out1
119 @diff -u test.ref test.out1 && echo "Auto Test OK"
121 # iterated test2 (compile tcc then compile tcctest.c !)
122 test2 test2b: tcctest.c test.ref
123 @echo ------------ $@ ------------
124 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
125 @diff -u test.ref test.out2 && echo "Auto Test2 OK"
127 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
128 test3 test3b: tcctest.c test.ref
129 @echo ------------ $@ ------------
130 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
131 @diff -u test.ref test.out3 && echo "Auto Test3 OK"
133 test%b : TCCFLAGS += -b
135 # binary output test
136 test4: tcctest.c test.ref
137 @echo ------------ $@ ------------
138 # object + link output
139 $(TCC) -c -o tcctest3.o $<
140 $(TCC) -o tcctest3 tcctest3.o
141 ./tcctest3 > test3.out
142 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
143 # dynamic output
144 $(TCC) -o tcctest1 $<
145 ./tcctest1 > test1.out
146 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
147 # dynamic output + bound check
148 $(TCC) -b -o tcctest4 $<
149 ./tcctest4 > test4.out
150 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
151 # static output
152 $(TCC) -static -o tcctest2 $<
153 ./tcctest2 > test2.out
154 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
156 # memory and bound check auto test
157 BOUNDS_OK = 1 4 8 10 14
158 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
160 btest: boundtest.c
161 @echo ------------ $@ ------------
162 @for i in $(BOUNDS_OK); do \
163 echo ; echo --- boundtest $$i ---; \
164 if $(TCC) -b -run $< $$i ; then \
165 echo succeeded as expected; \
166 else\
167 echo Failed positive test $$i ; exit 1 ; \
168 fi ;\
169 done ;\
170 for i in $(BOUNDS_FAIL); do \
171 echo ; echo --- boundtest $$i ---; \
172 if $(TCC) -b -run $< $$i ; then \
173 echo Failed negative test $$i ; exit 1 ;\
174 else\
175 echo failed as expected; \
176 fi ;\
177 done ;\
178 echo; echo Bound test OK
180 # speed test
181 speedtest: ex2 ex3
182 @echo ------------ $@ ------------
183 time ./ex2 1238 2 3 4 10 13 4
184 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
185 time ./ex3 35
186 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
188 weaktest: tcctest.c test.ref
189 $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
190 $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS)
191 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
192 objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt
193 diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
195 ex%: $(top_srcdir)/examples/ex%.c
196 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
198 # tiny assembler testing
199 asmtest.ref: asmtest.S
200 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
201 objdump -D asmtest.ref.o > asmtest.ref
203 asmtest: asmtest.ref
204 @echo ------------ $@ ------------
205 $(TCC) -c asmtest.S
206 objdump -D asmtest.o > asmtest.out
207 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
209 # Check that code generated by libtcc is binary compatible with
210 # that generated by CC
211 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
212 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
214 abitest-tcc$(EXESUF): abitest.c libtcc.c
215 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir)
217 abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
218 @echo ------------ $@ ------------
219 ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
220 ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
222 vla_test$(EXESUF): vla_test.c
223 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS)
224 vla_test-run: vla_test$(EXESUF)
225 @echo ------------ $@ ------------
226 ./vla_test$(EXESUF)
228 # targets for development
229 %.bin: %.c tcc
230 $(TCC) -g -o $@ $<
231 $(DISAS) $@
233 instr: instr.o
234 objdump -d instr.o
236 instr.o: instr.S
237 $(CC) -o $@ -c $< -O2 -Wall -g
239 cache: tcc_g
240 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
241 vg_annotate tcc.c > /tmp/linpack.cache.log
243 # clean
244 clean:
245 $(MAKE) -C tests2 $@
246 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
247 *-cc *-tcc *.exe \
248 hello libtcc_test vla_test tcctest[1234] ex? tcc_g tcclib.h \
249 ../lib/libtcc1.a