2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 SRCDIR
= $(top_srcdir
)/tests
8 VPATH
= $(SRCDIR
) $(top_srcdir
)
10 # clear CFLAGS and LDFLAGS
25 BTESTS
= test1b test3b btest
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
37 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
40 TESTS
:= w32-prep
$(filter-out $(BTESTS
),$(TESTS
))
42 ifeq ($(TARGETOS
),Darwin
)
43 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
46 else ifneq ($(ARCH
),x86-64
)
47 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
51 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
54 ifeq ($(TARGETOS
),Darwin
)
55 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
56 export MACOSX_DEPLOYMENT_TARGET
:=10.2
57 NATIVE_DEFINES
+=-D_ANSI_SOURCE
60 # run local version of tcc with local libraries and includes
61 TCCFLAGS
= -B
$(TOP
) -I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
63 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
) -I
$(top_srcdir
)/include -I
$(TOP
) -L
$(TOP
)
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
)
74 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
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; } ; \
92 hello-run
: ..
/examples
/ex1.c
93 @echo
------------ $@
------------
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
)
104 @echo
------------ $@
------------
108 cp ..
/libtcc1.a ..
/lib
110 # test.ref - generate using cc
112 $(CC
) -o tcctest.
cc $< -I
$(top_srcdir
) $(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
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
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
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
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
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
; \
167 echo Failed positive
test $$i ; exit
1 ; \
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 ;\
175 echo failed
as expected
; \
178 echo
; echo Bound
test OK
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
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
204 @echo
------------ $@
------------
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
------------ $@
------------
228 # targets for development
237 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
240 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
241 vg_annotate tcc.c
> /tmp
/linpack.cache.log
246 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc \
248 hello libtcc_test vla_test tcctest
[1234] ex? tcc_g tcclib.h \