2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 SRCDIR
= $(top_srcdir
)/tests
8 VPATH
= $(SRCDIR
) $(top_srcdir
)
21 BTESTS
= test1b test3b btest
27 # test4 -- problem with -static
28 # asmtest -- minor differences with gcc
29 # btest -- works on i386 (including win32)
31 # bounds-checking is supported only on i386
33 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
36 TESTS
:= w32-prep
$(filter-out $(BTESTS
),$(TESTS
))
38 ifeq ($(TARGETOS
),Darwin
)
39 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
42 else ifneq ($(ARCH
),x86-64
)
43 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
47 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
50 ifeq ($(TARGETOS
),Darwin
)
51 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
52 export MACOSX_DEPLOYMENT_TARGET
:=10.2
53 NATIVE_DEFINES
+=-D_ANSI_SOURCE
56 # run local version of tcc with local libraries and includes
57 TCCFLAGS
= -B
$(TOP
) -I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
59 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
) -I
$(top_srcdir
)/include -I
$(TOP
) -L
$(TOP
)
61 XTCCFLAGS
= -B
$(TOP
) -B
$(top_srcdir
)/win32
-I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
63 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
64 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(top_srcdir
)/tcc.c
$(TCCFLAGS
)
70 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
75 hello-exe
: ..
/examples
/ex1.c
76 @echo
------------ $@
------------
77 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
79 hello-cross
: ..
/examples
/ex1.c
80 @echo
------------ $@
------------
81 for XTCC in
$(PROGS_CROSS
) ; \
82 do echo
-n
"Test of $$XTCC... "; \
83 out
=$$($(TOP
)/$$XTCC $(XTCCFLAGS
) -c
$< 2>&1); \
84 test $$?
-ne
0 && { echo
"Failed\n$$out\n" ; $(TOP
)/$$XTCC -vv
; exit
1; } ; \
88 hello-run
: ..
/examples
/ex1.c
89 @echo
------------ $@
------------
92 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
93 @echo
------------ $@
------------
94 .
/libtcc_test
$(EXESUF
) lib_path
=..
96 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
97 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
100 @echo
------------ $@
------------
104 cp ..
/libtcc1.a ..
/lib
106 # test.ref - generate using cc
108 $(CC
) -o tcctest.
cc $< -I
$(top_srcdir
) $(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
112 test1 test1b
: tcctest.c
test.ref
113 @echo
------------ $@
------------
114 $(TCC
) -run
$< > test.out1
115 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
117 # iterated test2 (compile tcc then compile tcctest.c !)
118 test2 test2b
: tcctest.c
test.ref
119 @echo
------------ $@
------------
120 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
121 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
123 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
124 test3 test3b
: tcctest.c
test.ref
125 @echo
------------ $@
------------
126 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
127 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
129 test%b
: TCCFLAGS
+= -b
132 test4
: tcctest.c
test.ref
133 @echo
------------ $@
------------
134 # object + link output
135 $(TCC
) -c
-o tcctest3.o
$<
136 $(TCC
) -o tcctest3 tcctest3.o
137 .
/tcctest3
> test3.out
138 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
140 $(TCC
) -o tcctest1
$<
141 .
/tcctest1
> test1.out
142 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
143 # dynamic output + bound check
144 $(TCC
) -b
-o tcctest4
$<
145 .
/tcctest4
> test4.out
146 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
148 $(TCC
) -static
-o tcctest2
$<
149 .
/tcctest2
> test2.out
150 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
152 # memory and bound check auto test
153 BOUNDS_OK
= 1 4 8 10 14
154 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
157 @echo
------------ $@
------------
158 @for i in
$(BOUNDS_OK
); do \
159 echo
; echo
--- boundtest
$$i ---; \
160 if
$(TCC
) -b
-run
$< $$i ; then \
161 echo succeeded
as expected
; \
163 echo Failed positive
test $$i ; exit
1 ; \
166 for i in
$(BOUNDS_FAIL
); do \
167 echo
; echo
--- boundtest
$$i ---; \
168 if
$(TCC
) -b
-run
$< $$i ; then \
169 echo Failed negative
test $$i ; exit
1 ;\
171 echo failed
as expected
; \
174 echo
; echo Bound
test OK
178 @echo
------------ $@
------------
179 time .
/ex2
1238 2 3 4 10 13 4
180 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
182 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
184 weaktest
: tcctest.c
test.ref
185 $(TCC
) -c
$< -o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
186 $(CC
) -c
$< -o weaktest.
cc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
187 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
188 objdump
-t weaktest.
cc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.
cc.o.txt
189 diff weaktest.
cc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
191 ex
%: $(top_srcdir
)/examples
/ex
%.c
192 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
194 # tiny assembler testing
195 asmtest.ref
: asmtest.S
196 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
197 objdump
-D asmtest.ref.o
> asmtest.ref
200 @echo
------------ $@
------------
202 objdump
-D asmtest.o
> asmtest.out
203 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
205 # Check that code generated by libtcc is binary compatible with
206 # that generated by CC
207 abitest-cc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
208 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
210 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
211 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) -DONE_SOURCE
$(LIBS
) $(LDFLAGS
) -I
$(top_srcdir
)
213 abitest
: abitest-cc
$(EXESUF
) abitest-tcc
$(EXESUF
)
214 @echo
------------ $@
------------
215 .
/abitest-cc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
216 .
/abitest-tcc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
218 vla_test
$(EXESUF
): vla_test.c
219 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
)
220 vla_test-run
: vla_test
$(EXESUF
)
221 @echo
------------ $@
------------
224 # targets for development
233 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
236 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
237 vg_annotate tcc.c
> /tmp
/linpack.cache.log
242 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc \
244 hello libtcc_test vla_test tcctest
[1234] ex? tcc_g tcclib.h \