2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(TOPSRC
)/tests
$(TOPSRC
) $(TOP
)
8 CFLAGS
:= $(filter-out -W
% -g
% -O
%,$(CFLAGS
)) -I
$(TOPSRC
) $(LDFLAGS
)
25 BTESTS
= test1b test3b btest
27 # test4 -- problem with -static
28 # asmtest / asmtest2 -- 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
:= $(filter-out $(BTESTS
),$(TESTS
))
38 ifdef CONFIG_OSX
# -run only
39 TESTS
:= hello-run libtest tests2-dir pp-dir
41 ifeq (,$(filter arm64 i386 x86_64
,$(ARCH
)))
42 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
44 ifeq ($(CONFIG_arm_eabi
),yes
)
45 TESTS
:= $(filter-out test3
,$(TESTS
))
47 ifeq (,$(filter i386 x86_64
,$(ARCH
)))
48 TESTS
:= $(filter-out dlltest asm-c-connect-test
,$(TESTS
))
51 TESTS
:= $(filter-out cross-
%,$(TESTS
))
54 ifeq ($(OS
),Windows_NT
) # for libtcc_test to find libtcc.dll
55 PATH
:= $(CURDIR
)/$(TOP
)$(if
$(findstring :\
,$(PATH
)),;,:)$(PATH
)
58 RUN_TCC
= $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
60 DUMPTCC
= (set
-x
; $(TOP
)/tcc
-vv
; ldd
$(TOP
)/tcc
; exit
1)
66 hello-exe
: ..
/examples
/ex1.c
67 @echo
------------ $@
------------
68 $(TCC
) $< -o hello
$(EXESUF
) && .
/hello
$(EXESUF
) ||
$(DUMPTCC
)
70 hello-run
: ..
/examples
/ex1.c
71 @echo
------------ $@
------------
72 $(TCC
) -run
$< ||
$(DUMPTCC
)
74 libtest
: libtcc_test
$(EXESUF
)
75 @echo
------------ $@
------------
76 .
/libtcc_test
$(EXESUF
) $(TCCFLAGS
)
78 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
79 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
82 @echo
------------ $@
------------
85 # test.ref - generate using cc
87 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
91 test1 test1b
: tcctest.c
test.ref
92 @echo
------------ $@
------------
93 $(TCC
) -run
$< > test.out1
94 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
96 # iterated test2 (compile tcc then compile tcctest.c !)
97 test2 test2b
: tcctest.c
test.ref
98 @echo
------------ $@
------------
99 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
100 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
102 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
103 test3 test3b
: tcctest.c
test.ref
104 @echo
------------ $@
------------
105 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
106 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
108 test%b
: TCCFLAGS
+= -b
111 test4
: tcctest.c
test.ref
112 @echo
------------ $@
------------
113 # object + link output
114 $(TCC
) -c
-o tcctest3.o
$<
115 $(TCC
) -o tcctest3 tcctest3.o
116 .
/tcctest3
> test3.out
117 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
119 $(TCC
) -o tcctest1
$<
120 .
/tcctest1
> test1.out
121 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
122 # dynamic output + bound check
123 $(TCC
) -b
-o tcctest4
$<
124 .
/tcctest4
> test4.out
125 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
127 $(TCC
) -static
-o tcctest2
$<
128 .
/tcctest2
> test2.out
129 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
131 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
133 @echo
------------ $@
------------
134 $(TCC
) $(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
$(TOPSRC
)/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
135 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
136 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
138 @echo
------------ $@ with PIC
------------
139 $(CC
) $(CFLAGS
) -fPIC
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c
$(TOPSRC
)/libtcc.c
140 $(TCC
) libtcc.o
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
141 $(TCC
) $(NATIVE_DEFINES
) -DONE_SOURCE
=0 $(TOPSRC
)/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
142 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run
$(TOPSRC
)/examples
/ex1.c
144 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
147 @echo
------------ $@
------------
148 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DMEM_DEBUG
=2 $(TOPSRC
)/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
149 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) $(TOPSRC
)/tcc.c
$(LIBS
)
150 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
) $(TOPSRC
)/tests
/tcctest.c
153 # memory and bound check auto test
154 BOUNDS_OK
= 1 4 8 10 14
155 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
158 @echo
------------ $@
------------
159 @for i in
$(BOUNDS_OK
); do \
160 echo
; echo
--- boundtest
$$i ---; \
161 if
$(TCC
) -b
-run
$< $$i ; then \
162 echo succeeded
as expected
; \
164 echo Failed positive
test $$i ; exit
1 ; \
167 for i in
$(BOUNDS_FAIL
); do \
168 echo
; echo
--- boundtest
$$i ---; \
169 if
$(TCC
) -b
-run
$< $$i ; then \
170 echo Failed negative
test $$i ; exit
1 ;\
172 echo failed
as expected
; \
175 echo
; echo Bound
test OK
179 @echo
------------ $@
------------
180 time .
/ex2
1238 2 3 4 10 13 4
181 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
183 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
185 weaktest
: tcctest.c
test.ref
186 $(TCC
) -c
$< -o weaktest.tcc.o
187 $(CC
) -c
$< -o weaktest.gcc.o
$(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
188 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
189 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
190 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
192 ex
%: $(TOPSRC
)/examples
/ex
%.c
193 $(CC
) -o
$@
$< $(CFLAGS
)
195 # tiny assembler testing
196 asmtest.ref
: asmtest.S
197 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
198 objdump
-D asmtest.ref.o
> asmtest.ref
200 asmtest asmtest2
: asmtest.ref
201 @echo
------------ $@
------------
202 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
203 objdump
-D asmtest.o
> asmtest.out
204 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
206 # test assembler with tcc compiled by itself
207 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
209 # Check that code generated by libtcc is binary compatible with
210 # that generated by CC
211 abitest-cc
$(EXESUF
): abitest.c
$(LIBTCC
)
212 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
214 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
215 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) $(LIBS
)
217 ABITESTS
:= abitest-cc
$(EXESUF
)
218 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
219 ABITESTS
+= abitest-tcc
$(EXESUF
)
223 @echo
------------ $@
------------
224 .
/abitest-cc
$(EXESUF
) $(TCCFLAGS
)
225 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
226 .
/abitest-tcc
$(EXESUF
) $(TCCFLAGS
)
229 vla_test
$(EXESUF
): vla_test.c
232 vla_test-run
: vla_test
$(EXESUF
)
233 @echo
------------ $@
------------
236 asm-c-connect
$(EXESUF
): asm-c-connect-1.c asm-c-connect-2.c
239 asm-c-connect-
%.o
: asm-c-connect-
%.c
242 asm-c-connect-sep
$(EXESUF
): asm-c-connect-1.o asm-c-connect-2.o
245 asm-c-connect-test
: asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
246 @echo
------------ $@
------------
247 .
/asm-c-connect
$(EXESUF
) > asm-c-connect.out1
&& cat asm-c-connect.out1
248 .
/asm-c-connect-sep
$(EXESUF
) > asm-c-connect.out2
&& cat asm-c-connect.out2
249 @diff
-u asm-c-connect.out1 asm-c-connect.out2
&& echo
"ok"
252 @echo
------------ $@
------------
253 $(TOP
)/i386-tcc
$(EXESUF
) $(TCCFLAGS-unx
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
254 $(TOP
)/i386-win32-tcc
$(EXESUF
) $(TCCFLAGS-win
) $(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
255 $(TOP
)/x86_64-tcc
$(EXESUF
) $(TCCFLAGS-unx
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
256 $(TOP
)/x86_64-win32-tcc
$(EXESUF
) $(TCCFLAGS-win
) $(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
257 $(TOP
)/arm-tcc
$(EXESUF
) $(TCCFLAGS-unx
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
258 $(TOP
)/arm-wince-tcc
$(EXESUF
) $(TCCFLAGS-win
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
259 $(TOP
)/arm64-tcc
$(EXESUF
) $(TCCFLAGS-unx
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
260 $(TOP
)/c67-tcc
$(EXESUF
) $(TCCFLAGS-unx
) -c
$(TOPSRC
)/examples
/ex3.c
&& echo
"ok"
261 $(TOP
)/i386-win32-tcc
$(EXESUF
) $(TCCFLAGS-win
) $(TOPSRC
)/win32
/examples
/hello_win.c
&& echo
"ok"
262 $(TOP
)/x86_64-win32-tcc
$(EXESUF
) $(TCCFLAGS-win
) $(TOPSRC
)/win32
/examples
/hello_win.c
&& echo
"ok"
263 $(TOP
)/arm-wince-tcc
$(EXESUF
) $(TCCFLAGS-win
) -c
$(TOPSRC
)/win32
/examples
/hello_win.c
&& echo
"ok"
265 # targets for development
274 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
277 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
278 vg_annotate tcc.c
> /tmp
/linpack.cache.log
282 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc
283 rm -f
*-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234]
284 rm -f asm-c-connect
$(EXESUF
) asm-c-connect-sep
$(EXESUF
)
285 rm -f ex? tcc_g weaktest.
*.txt
*.def
286 @
$(MAKE
) -C tests2
$@
289 # silent clean, used before running tests
291 @
$(MAKE
) -s
--no-print-directory
clean