Added CMake build system (to facilitate Win64 builds)
[tinycc.git] / tests / Makefile
blob9c8a43346bbd689f5ad8c1221130db6ee82392f3
2 # Tiny C Compiler Makefile - tests
5 TOP = ..
6 include $(TOP)/Makefile
7 SRCDIR = $(top_srcdir)/tests
8 VPATH = $(SRCDIR)
10 # what tests to run
11 TESTS = \
12 hello-exe \
13 hello-run \
14 libtest \
15 test3 \
16 abitest \
17 moretests
19 # test4 -- problem with -static
20 # asmtest -- minor differences with gcc
21 # btest -- works on i386 (including win32)
22 # test3 -- win32 does not know how to printf long doubles
24 # bounds-checking is supported only on i386
25 ifneq ($(ARCH),i386)
26 TESTS := $(filter-out btest,$(TESTS))
27 endif
28 ifdef CONFIG_WIN32
29 TESTS := $(filter-out test3,$(TESTS))
30 endif
31 ifeq ($(TARGETOS),Darwin)
32 TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
33 endif
35 ifdef DISABLE_STATIC
36 export LD_LIBRARY_PATH:=$(CURDIR)/..
37 endif
39 ifeq ($(TARGETOS),Darwin)
40 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
41 export MACOSX_DEPLOYMENT_TARGET:=10.2
42 NATIVE_DEFINES+=-D_ANSI_SOURCE
43 endif
45 # run local version of tcc with local libraries and includes
46 TCCFLAGS = -B$(TOP) -I$(TOP)
47 ifdef CONFIG_WIN32
48 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -I$(TOP) -L$(TOP)
49 endif
51 TCC = $(TOP)/tcc $(TCCFLAGS)
52 RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS)
54 DISAS = objdump -d
56 # libtcc test
57 ifdef LIBTCC1
58 LIBTCC1:=$(TOP)/$(LIBTCC1)
59 endif
61 all test : $(TESTS)
63 hello-exe: ../examples/ex1.c
64 @echo ------------ $@ ------------
65 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
67 hello-run: ../examples/ex1.c
68 @echo ------------ $@ ------------
69 $(TCC) -run $<
71 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
72 @echo ------------ $@ ------------
73 ./libtcc_test$(EXESUF) lib_path=..
75 libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
76 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
78 moretests:
79 @echo ------------ $@ ------------
80 $(MAKE) -C tests2
82 # test.ref - generate using gcc
83 # copy only tcclib.h so GCC's stddef and stdarg will be used
84 test.ref: tcctest.c
85 cp $(top_srcdir)/include/tcclib.h .
86 gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
87 ./tcctest.gcc > $@
89 # auto test
90 test1: test.ref
91 @echo ------------ $@ ------------
92 $(TCC) -run $(SRCDIR)/tcctest.c > test.out1
93 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
95 # iterated test2 (compile tcc then compile tcctest.c !)
96 test2: test.ref
97 @echo ------------ $@ ------------
98 $(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2
99 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
101 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
102 test3: test.ref
103 @echo ------------ $@ ------------
104 $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3
105 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
107 # binary output test
108 test4: test.ref
109 @echo ------------ $@ ------------
110 # object + link output
111 $(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c
112 $(TCC) -o tcctest3 tcctest3.o
113 ./tcctest3 > test3.out
114 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
115 # dynamic output
116 $(TCC) -o tcctest1 $(SRCDIR)/tcctest.c
117 ./tcctest1 > test1.out
118 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
119 # dynamic output + bound check
120 $(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c
121 ./tcctest4 > test4.out
122 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
123 # static output
124 $(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c
125 ./tcctest2 > test2.out
126 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
128 # memory and bound check auto test
129 BOUNDS_OK = 1 4 8 10 14
130 BOUNDS_FAIL= 2 5 7 9 11 12 13 15
132 btest: boundtest.c
133 @echo ------------ $@ ------------
134 @for i in $(BOUNDS_OK); do \
135 echo ; echo --- boundtest $$i ---; \
136 if $(TCC) -b -run boundtest.c $$i ; then \
137 echo succeded as expected; \
138 else\
139 echo Failed positive test $$i ; exit 1 ; \
140 fi ;\
141 done ;\
142 for i in $(BOUNDS_FAIL); do \
143 echo ; echo --- boundtest $$i ---; \
144 if $(TCC) -b -run boundtest.c $$i ; then \
145 echo Failed negative test $$i ; exit 1 ;\
146 else\
147 echo failed as expected; \
148 fi ;\
149 done ;\
150 echo; echo Bound test OK
152 # speed test
153 speedtest: ex2 ex3
154 @echo ------------ $@ ------------
155 time ./ex2 1238 2 3 4 10 13 4
156 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
157 time ./ex3 35
158 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
160 weaktest: test.ref
161 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
162 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
163 objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
164 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
165 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
167 ex%: $(top_srcdir)/examples/ex%.c
168 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
170 # tiny assembler testing
171 asmtest.ref: asmtest.S
172 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
173 objdump -D asmtest.ref.o > asmtest.ref
175 asmtest: asmtest.ref
176 @echo ------------ $@ ------------
177 $(TCC) -c asmtest.S
178 objdump -D asmtest.o > asmtest.out
179 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
181 # Check that code generated by libtcc is binary compatible with
182 # that generated by CC
183 abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
184 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
186 abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
187 $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
189 abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
190 @echo ------------ $@ ------------
191 ./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
192 ./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
194 # targets for development
195 %.bin: %.c tcc
196 $(TCC) -g -o $@ $<
197 $(DISAS) $@
199 instr: instr.o
200 objdump -d instr.o
202 instr.o: instr.S
203 $(CC) -o $@ -c $< -O2 -Wall -g
205 cache: tcc_g
206 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
207 vg_annotate tcc.c > /tmp/linpack.cache.log
209 # clean
210 clean:
211 $(MAKE) -C tests2 $@
212 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
213 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
215 Makefile: $(SRCDIR)/Makefile
216 cp $< $@