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
)
23 BTESTS
= test1b test3b btest
25 # test4 -- problem with -static
26 # asmtest / asmtest2 -- minor differences with gcc
27 # btest -- works on i386 (including win32)
29 # bounds-checking is supported only on i386
31 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
34 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
36 ifeq ($(TARGETOS
),Darwin
)
37 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
39 ifeq (,$(filter arm64 i386 x86-64
,$(ARCH
)))
40 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
42 ifeq ($(CONFIG_arm_eabi
),yes
)
43 TESTS
:= $(filter-out test3
,$(TESTS
))
45 ifeq (,$(filter i386 x86-64
,$(ARCH
)))
46 TESTS
:= $(filter-out dlltest
,$(TESTS
))
49 # run local version of tcc with local libraries and includes
50 TCCFLAGS
= -B
$(TOP
) -I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
)
52 TCCFLAGS
= -B
$(TOPSRC
)/win32
-I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
) -L
$(TOP
)
53 PATH
:= $(CURDIR
)/$(TOP
):$(PATH
) # for libtcc_test to find libtcc.dll
56 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
57 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
59 ifeq ($(TARGETOS
),Darwin
)
60 CFLAGS
+= -Wl
,-flat_namespace
,-undefined
,warning
61 TCCFLAGS
+= -D_ANSI_SOURCE
62 export MACOSX_DEPLOYMENT_TARGET
:=10.2
67 all test : clean-s
$(TESTS
)
69 hello-exe
: ..
/examples
/ex1.c
70 @echo
------------ $@
------------
71 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
73 hello-run
: ..
/examples
/ex1.c
74 @echo
------------ $@
------------
77 libtest
: libtcc_test
$(EXESUF
)
78 @echo
------------ $@
------------
79 .
/libtcc_test
$(EXESUF
) $(TCCFLAGS
)
81 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
82 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
85 @echo
------------ $@
------------
88 # test.ref - generate using cc
90 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
94 test1 test1b
: tcctest.c
test.ref
95 @echo
------------ $@
------------
96 $(TCC
) -run
$< > test.out1
97 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
99 # iterated test2 (compile tcc then compile tcctest.c !)
100 test2 test2b
: tcctest.c
test.ref
101 @echo
------------ $@
------------
102 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
103 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
105 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
106 test3 test3b
: tcctest.c
test.ref
107 @echo
------------ $@
------------
108 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
109 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
111 test%b
: TCCFLAGS
+= -b
114 test4
: tcctest.c
test.ref
115 @echo
------------ $@
------------
116 # object + link output
117 $(TCC
) -c
-o tcctest3.o
$<
118 $(TCC
) -o tcctest3 tcctest3.o
119 .
/tcctest3
> test3.out
120 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
122 $(TCC
) -o tcctest1
$<
123 .
/tcctest1
> test1.out
124 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
125 # dynamic output + bound check
126 $(TCC
) -b
-o tcctest4
$<
127 .
/tcctest4
> test4.out
128 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
130 $(TCC
) -static
-o tcctest2
$<
131 .
/tcctest2
> test2.out
132 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
134 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
136 @echo
------------ $@
------------
137 $(TCC
) -DONE_SOURCE
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL ..
/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
138 $(TCC
) $(NATIVE_DEFINES
) ..
/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
139 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run ..
/examples
/ex1.c
141 @echo
------------ $@ with PIC
------------
142 $(CC
) $(CFLAGS
) -fPIC
-DONE_SOURCE
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c ..
/libtcc.c
143 $(TCC
) libtcc.o
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
144 $(TCC
) $(NATIVE_DEFINES
) ..
/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
145 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run ..
/examples
/ex1.c
147 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
150 @echo
------------ $@
------------
151 $(CC
) $(CFLAGS
) $(NATIVE_DEFINES
) -DONE_SOURCE
-DMEM_DEBUG
=2 ..
/tcc.c
$(LIBS
) -o memtest-tcc
$(EXESUF
)
152 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -DONE_SOURCE ..
/tcc.c
$(LIBS
)
153 .
/memtest-tcc
$(EXESUF
) $(TCCFLAGS
) $(NATIVE_DEFINES
) -DONE_SOURCE
-run ..
/tcc.c
$(TCCFLAGS
) tcctest.c
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
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
186 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
188 weaktest
: tcctest.c
test.ref
189 $(TCC
) -c
$< -o weaktest.tcc.o
190 $(CC
) -c
$< -o weaktest.gcc.o
-I.
$(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.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
193 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
195 ex
%: $(TOPSRC
)/examples
/ex
%.c
196 $(CC
) -o
$@
$< $(CFLAGS
)
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
203 asmtest asmtest2
: asmtest.ref
204 @echo
------------ $@
------------
205 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
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 # test assembler with tcc compiled by itself
210 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
212 # Check that code generated by libtcc is binary compatible with
213 # that generated by CC
214 abitest-cc
$(EXESUF
): abitest.c
$(LIBTCC
)
215 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
217 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
218 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) -DONE_SOURCE
$(LIBS
)
220 ABITESTS
:= abitest-cc
$(EXESUF
)
221 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
222 ABITESTS
+= abitest-tcc
$(EXESUF
)
226 @echo
------------ $@
------------
227 .
/abitest-cc
$(EXESUF
) $(TCCFLAGS
)
228 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
229 .
/abitest-tcc
$(EXESUF
) $(TCCFLAGS
)
232 vla_test
$(EXESUF
): vla_test.c
235 vla_test-run
: vla_test
$(EXESUF
)
236 @echo
------------ $@
------------
239 # targets for development
248 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
251 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
252 vg_annotate tcc.c
> /tmp
/linpack.cache.log
256 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc \
257 *-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234] ex? tcc_g
261 # silent clean, used before running tests
263 @
$(MAKE
) -s
--no-print-directory
clean