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
24 BTESTS
= test1b test3b btest
30 # test4 -- problem with -static
31 # asmtest -- minor differences with gcc
32 # btest -- works on i386 (including win32)
34 # bounds-checking is supported only on i386
36 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
39 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
41 ifeq ($(TARGETOS
),Darwin
)
42 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
44 ifeq (,$(filter arm64 i386 x86-64
,$(ARCH
)))
45 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
47 ifeq ($(CONFIG_arm_eabi
),yes
)
48 TESTS
:= $(filter-out test3
,$(TESTS
))
52 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
55 ifeq ($(TARGETOS
),Darwin
)
56 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
57 export MACOSX_DEPLOYMENT_TARGET
:=10.2
58 NATIVE_DEFINES
+=-D_ANSI_SOURCE
61 # run local version of tcc with local libraries and includes
62 TCCFLAGS
= -B
$(TOP
) -I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include -L
$(TOP
)
64 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
) -I
$(top_srcdir
)/include -L
$(TOP
)
66 XTCCFLAGS
= -B
$(TOP
) -B
$(top_srcdir
)/win32
-I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
68 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
69 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(top_srcdir
)/tcc.c
$(TCCFLAGS
)
76 LIBTCC1
:=$(TOP
)/win32
/libtcc
/libtcc.a
78 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
84 hello-exe
: ..
/examples
/ex1.c
85 @echo
------------ $@
------------
86 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
88 hello-cross
: ..
/examples
/ex1.c
89 @echo
------------ $@
------------
90 for XTCC in
$(PROGS_CROSS
) ; \
91 do echo
-n
"Test of $$XTCC... "; \
92 out
=$$($(TOP
)/$$XTCC $(XTCCFLAGS
) -c
$< 2>&1); \
93 test $$?
-ne
0 && { echo
"Failed\n$$out\n" ; $(TOP
)/$$XTCC -vv
; exit
1; } ; \
97 hello-run
: ..
/examples
/ex1.c
98 @echo
------------ $@
------------
101 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
102 @echo
------------ $@
------------
103 .
/libtcc_test
$(EXESUF
) $(TCCFLAGS
)
105 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
106 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
109 @echo
------------ $@
------------
112 # test.ref - generate using cc
114 $(CC
) -o tcctest.
cc $< -I
$(top_srcdir
) $(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
118 test1 test1b
: tcctest.c
test.ref
119 @echo
------------ $@
------------
120 $(TCC
) -run
$< > test.out1
121 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
123 # iterated test2 (compile tcc then compile tcctest.c !)
124 test2 test2b
: tcctest.c
test.ref
125 @echo
------------ $@
------------
126 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
127 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
129 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
130 test3 test3b
: tcctest.c
test.ref
131 @echo
------------ $@
------------
132 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
133 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
135 test%b
: TCCFLAGS
+= -b
138 test4
: tcctest.c
test.ref
139 @echo
------------ $@
------------
140 # object + link output
141 $(TCC
) -c
-o tcctest3.o
$<
142 $(TCC
) -o tcctest3 tcctest3.o
143 .
/tcctest3
> test3.out
144 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
146 $(TCC
) -o tcctest1
$<
147 .
/tcctest1
> test1.out
148 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
149 # dynamic output + bound check
150 $(TCC
) -b
-o tcctest4
$<
151 .
/tcctest4
> test4.out
152 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
154 $(TCC
) -static
-o tcctest2
$<
155 .
/tcctest2
> test2.out
156 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
158 # memory and bound check auto test
159 BOUNDS_OK
= 1 4 8 10 14
160 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
163 @echo
------------ $@
------------
164 @for i in
$(BOUNDS_OK
); do \
165 echo
; echo
--- boundtest
$$i ---; \
166 if
$(TCC
) -b
-run
$< $$i ; then \
167 echo succeeded
as expected
; \
169 echo Failed positive
test $$i ; exit
1 ; \
172 for i in
$(BOUNDS_FAIL
); do \
173 echo
; echo
--- boundtest
$$i ---; \
174 if
$(TCC
) -b
-run
$< $$i ; then \
175 echo Failed negative
test $$i ; exit
1 ;\
177 echo failed
as expected
; \
180 echo
; echo Bound
test OK
184 @echo
------------ $@
------------
185 time .
/ex2
1238 2 3 4 10 13 4
186 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
188 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
190 weaktest
: tcctest.c
test.ref
191 $(TCC
) -c
$< -o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
192 $(CC
) -c
$< -o weaktest.
cc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
193 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
194 objdump
-t weaktest.
cc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.
cc.o.txt
195 diff weaktest.
cc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
197 ex
%: $(top_srcdir
)/examples
/ex
%.c
198 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
200 # tiny assembler testing
201 asmtest.ref
: asmtest.S
202 $(CC
) -m32
-Wa
,-W
-o asmtest.ref.o
-c asmtest.S
203 objdump
-D asmtest.ref.o
> asmtest.ref
206 @echo
------------ $@
------------
208 objdump
-D asmtest.o
> asmtest.out
209 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
211 # Check that code generated by libtcc is binary compatible with
212 # that generated by CC
213 abitest-cc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
214 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
216 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
217 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) -DONE_SOURCE
$(LIBS
) $(LDFLAGS
) -I
$(top_srcdir
)
219 ABITESTS
:= abitest-cc
$(EXESUF
)
220 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
221 ABITESTS
+= abitest-tcc
$(EXESUF
)
225 @echo
------------ $@
------------
226 .
/abitest-cc
$(EXESUF
) $(TCCFLAGS
)
227 if
[ "$(CONFIG_arm_eabi)" != "yes" ]; then .
/abitest-tcc
$(EXESUF
) $(TCCFLAGS
); fi
229 vla_test
$(EXESUF
): vla_test.c
230 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
)
231 vla_test-run
: vla_test
$(EXESUF
)
232 @echo
------------ $@
------------
235 # targets for development
244 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
247 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
248 vg_annotate tcc.c
> /tmp
/linpack.cache.log
254 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc \
256 hello libtcc_test vla_test tcctest
[1234] ex? tcc_g