2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(TOPSRC
)/tests
$(TOPSRC
) $(TOP
)
8 CFLAGS
= -I
$(TOPSRC
) -I
$(TOP
)
21 BTESTS
= test1b test3b btest
23 # test4 -- problem with -static
24 # asmtest / asmtest2 -- minor differences with gcc
25 # btest -- works on i386 (including win32)
27 # bounds-checking is supported only on i386
29 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
32 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
34 ifeq ($(TARGETOS
),Darwin
)
35 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
37 ifeq (,$(filter arm64 i386 x86-64
,$(ARCH
)))
38 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
40 ifeq ($(CONFIG_arm_eabi
),yes
)
41 TESTS
:= $(filter-out test3
,$(TESTS
))
44 # run local version of tcc with local libraries and includes
45 TCCFLAGS
= -B
$(TOP
) -I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
)
47 TCCFLAGS
= -B
$(TOPSRC
)/win32
-I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
) -L
$(TOP
)
48 PATH
:= $(CURDIR
)/$(TOP
):$(PATH
) # for libtcc_test to find libtcc.dll
51 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
52 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
54 ifeq ($(TARGETOS
),Darwin
)
55 CFLAGS
+= -Wl
,-flat_namespace
,-undefined
,warning
56 TCCFLAGS
+= -D_ANSI_SOURCE
57 export MACOSX_DEPLOYMENT_TARGET
:=10.2
62 all test : clean-s
$(TESTS
)
64 hello-exe
: ..
/examples
/ex1.c
65 @echo
------------ $@
------------
66 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
68 hello-run
: ..
/examples
/ex1.c
69 @echo
------------ $@
------------
72 libtest
: libtcc_test
$(EXESUF
)
73 @echo
------------ $@
------------
74 .
/libtcc_test
$(EXESUF
) $(TCCFLAGS
)
76 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
77 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
80 @echo
------------ $@
------------
83 # test.ref - generate using cc
85 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
89 test1 test1b
: tcctest.c
test.ref
90 @echo
------------ $@
------------
91 $(TCC
) -run
$< > test.out1
92 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
94 # iterated test2 (compile tcc then compile tcctest.c !)
95 test2 test2b
: tcctest.c
test.ref
96 @echo
------------ $@
------------
97 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
98 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
100 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
101 test3 test3b
: tcctest.c
test.ref
102 @echo
------------ $@
------------
103 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
104 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
106 test%b
: TCCFLAGS
+= -b
109 test4
: tcctest.c
test.ref
110 @echo
------------ $@
------------
111 # object + link output
112 $(TCC
) -c
-o tcctest3.o
$<
113 $(TCC
) -o tcctest3 tcctest3.o
114 .
/tcctest3
> test3.out
115 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
117 $(TCC
) -o tcctest1
$<
118 .
/tcctest1
> test1.out
119 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
120 # dynamic output + bound check
121 $(TCC
) -b
-o tcctest4
$<
122 .
/tcctest4
> test4.out
123 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
125 $(TCC
) -static
-o tcctest2
$<
126 .
/tcctest2
> test2.out
127 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
129 # memory and bound check auto test
130 BOUNDS_OK
= 1 4 8 10 14
131 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
134 @echo
------------ $@
------------
135 @for i in
$(BOUNDS_OK
); do \
136 echo
; echo
--- boundtest
$$i ---; \
137 if
$(TCC
) -b
-run
$< $$i ; then \
138 echo succeeded
as expected
; \
140 echo Failed positive
test $$i ; exit
1 ; \
143 for i in
$(BOUNDS_FAIL
); do \
144 echo
; echo
--- boundtest
$$i ---; \
145 if
$(TCC
) -b
-run
$< $$i ; then \
146 echo Failed negative
test $$i ; exit
1 ;\
148 echo failed
as expected
; \
151 echo
; echo Bound
test OK
155 @echo
------------ $@
------------
156 time .
/ex2
1238 2 3 4 10 13 4
157 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
159 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
161 weaktest
: tcctest.c
test.ref
162 $(TCC
) -c
$< -o weaktest.tcc.o
163 $(CC
) -c
$< -o weaktest.gcc.o
-I.
$(CFLAGS
)
164 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
165 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
166 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
168 ex
%: $(TOPSRC
)/examples
/ex
%.c
169 $(CC
) -o
$@
$< $(CFLAGS
)
171 # tiny assembler testing
172 asmtest.ref
: asmtest.S
173 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
174 objdump
-D asmtest.ref.o
> asmtest.ref
176 asmtest asmtest2
: asmtest.ref
177 @echo
------------ $@
------------
178 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
179 objdump
-D asmtest.o
> asmtest.out
180 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
182 # test assembler with tcc compiled by itself
183 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
185 # Check that code generated by libtcc is binary compatible with
186 # that generated by CC
187 abitest-cc
$(EXESUF
): abitest.c
$(LIBTCC
)
188 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
190 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
191 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) -DONE_SOURCE
$(LIBS
)
193 ABITESTS
:= abitest-cc
$(EXESUF
)
194 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
195 ABITESTS
+= abitest-tcc
$(EXESUF
)
199 @echo
------------ $@
------------
200 .
/abitest-cc
$(EXESUF
) $(TCCFLAGS
)
201 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
202 .
/abitest-tcc
$(EXESUF
) $(TCCFLAGS
)
205 vla_test
$(EXESUF
): vla_test.c
208 vla_test-run
: vla_test
$(EXESUF
)
209 @echo
------------ $@
------------
212 # targets for development
221 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
224 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
225 vg_annotate tcc.c
> /tmp
/linpack.cache.log
229 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc \
230 *-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234] ex? tcc_g
234 # silent clean, used before running tests
236 @
$(MAKE
) -s
--no-print-directory
clean