2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(TOPSRC
)/tests
$(TOPSRC
) $(TOP
)
8 CFLAGS
= -I
$(TOPSRC
) -I
$(TOP
)
22 BTESTS
= test1b test3b btest
24 # test4 -- problem with -static
25 # asmtest / asmtest2 -- minor differences with gcc
26 # btest -- works on i386 (including win32)
28 # bounds-checking is supported only on i386
30 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
33 TESTS
:= $(filter-out $(BTESTS
),$(TESTS
))
35 ifeq ($(TARGETOS
),Darwin
)
36 TESTS
:= $(filter-out hello-exe test3
$(BTESTS
),$(TESTS
))
38 ifeq (,$(filter arm64 i386 x86-64
,$(ARCH
)))
39 TESTS
:= $(filter-out vla_test-run
,$(TESTS
))
41 ifeq ($(CONFIG_arm_eabi
),yes
)
42 TESTS
:= $(filter-out test3
,$(TESTS
))
44 ifeq (,$(filter i386 x86-64
,$(ARCH
)))
45 TESTS
:= $(filter-out dlltest
,$(TESTS
))
48 # run local version of tcc with local libraries and includes
49 TCCFLAGS
= -B
$(TOP
) -I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
)
51 TCCFLAGS
= -B
$(TOPSRC
)/win32
-I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
) -L
$(TOP
)
52 PATH
:= $(CURDIR
)/$(TOP
):$(PATH
) # for libtcc_test to find libtcc.dll
55 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
56 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(TOPSRC
)/tcc.c
$(TCCFLAGS
)
58 ifeq ($(TARGETOS
),Darwin
)
59 CFLAGS
+= -Wl
,-flat_namespace
,-undefined
,warning
60 TCCFLAGS
+= -D_ANSI_SOURCE
61 export MACOSX_DEPLOYMENT_TARGET
:=10.2
66 all test : clean-s
$(TESTS
)
68 hello-exe
: ..
/examples
/ex1.c
69 @echo
------------ $@
------------
70 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
72 hello-run
: ..
/examples
/ex1.c
73 @echo
------------ $@
------------
76 libtest
: libtcc_test
$(EXESUF
)
77 @echo
------------ $@
------------
78 .
/libtcc_test
$(EXESUF
) $(TCCFLAGS
)
80 libtcc_test
$(EXESUF
): libtcc_test.c
$(LIBTCC
)
81 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
)
84 @echo
------------ $@
------------
87 # test.ref - generate using cc
89 $(CC
) -o tcctest.gcc
$< $(NATIVE_DEFINES
) $(CFLAGS
) -w
-O0
-std
=gnu99
-fno-omit-frame-pointer
93 test1 test1b
: tcctest.c
test.ref
94 @echo
------------ $@
------------
95 $(TCC
) -run
$< > test.out1
96 @diff
-u
test.ref
test.out1
&& echo
"Auto Test OK"
98 # iterated test2 (compile tcc then compile tcctest.c !)
99 test2 test2b
: tcctest.c
test.ref
100 @echo
------------ $@
------------
101 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out2
102 @diff
-u
test.ref
test.out2
&& echo
"Auto Test2 OK"
104 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
105 test3 test3b
: tcctest.c
test.ref
106 @echo
------------ $@
------------
107 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$< > test.out3
108 @diff
-u
test.ref
test.out3
&& echo
"Auto Test3 OK"
110 test%b
: TCCFLAGS
+= -b
113 test4
: tcctest.c
test.ref
114 @echo
------------ $@
------------
115 # object + link output
116 $(TCC
) -c
-o tcctest3.o
$<
117 $(TCC
) -o tcctest3 tcctest3.o
118 .
/tcctest3
> test3.out
119 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
121 $(TCC
) -o tcctest1
$<
122 .
/tcctest1
> test1.out
123 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
124 # dynamic output + bound check
125 $(TCC
) -b
-o tcctest4
$<
126 .
/tcctest4
> test4.out
127 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
129 $(TCC
) -static
-o tcctest2
$<
130 .
/tcctest2
> test2.out
131 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
133 # use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
135 @echo
------------ $@
------------
136 $(TCC
) -DONE_SOURCE
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL ..
/libtcc.c
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
137 $(TCC
) $(NATIVE_DEFINES
) ..
/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
138 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run ..
/examples
/ex1.c
140 @echo
------------ $@ with PIC
------------
141 $(CC
) $(CFLAGS
) -fPIC
-DONE_SOURCE
$(NATIVE_DEFINES
) -DLIBTCC_AS_DLL
-c ..
/libtcc.c
142 $(TCC
) libtcc.o
$(LIBS
) -shared
-o libtcc2
$(DLLSUF
)
143 $(TCC
) $(NATIVE_DEFINES
) ..
/tcc.c libtcc2
$(DLLSUF
) $(LIBS
) -Wl
,-rpath
=.
-o tcc2
$(EXESUF
)
144 .
/tcc2
$(EXESUF
) $(TCCFLAGS
) $(RUN_TCC
) -run ..
/examples
/ex1.c
146 @
rm tcc2
$(EXESUF
) libtcc2
$(DLLSUF
)
149 # memory and bound check auto test
150 BOUNDS_OK
= 1 4 8 10 14
151 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
154 @echo
------------ $@
------------
155 @for i in
$(BOUNDS_OK
); do \
156 echo
; echo
--- boundtest
$$i ---; \
157 if
$(TCC
) -b
-run
$< $$i ; then \
158 echo succeeded
as expected
; \
160 echo Failed positive
test $$i ; exit
1 ; \
163 for i in
$(BOUNDS_FAIL
); do \
164 echo
; echo
--- boundtest
$$i ---; \
165 if
$(TCC
) -b
-run
$< $$i ; then \
166 echo Failed negative
test $$i ; exit
1 ;\
168 echo failed
as expected
; \
171 echo
; echo Bound
test OK
175 @echo
------------ $@
------------
176 time .
/ex2
1238 2 3 4 10 13 4
177 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex2.c
1238 2 3 4 10 13 4
179 time
$(TCC
) -run
$(TOPSRC
)/examples
/ex3.c
35
181 weaktest
: tcctest.c
test.ref
182 $(TCC
) -c
$< -o weaktest.tcc.o
183 $(CC
) -c
$< -o weaktest.gcc.o
-I.
$(CFLAGS
)
184 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
185 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
186 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
188 ex
%: $(TOPSRC
)/examples
/ex
%.c
189 $(CC
) -o
$@
$< $(CFLAGS
)
191 # tiny assembler testing
192 asmtest.ref
: asmtest.S
193 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
194 objdump
-D asmtest.ref.o
> asmtest.ref
196 asmtest asmtest2
: asmtest.ref
197 @echo
------------ $@
------------
198 $(TCC
) $(MAYBE_RUN_TCC
) -c asmtest.S
199 objdump
-D asmtest.o
> asmtest.out
200 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
202 # test assembler with tcc compiled by itself
203 asmtest2
: MAYBE_RUN_TCC
= $(RUN_TCC
)
205 # Check that code generated by libtcc is binary compatible with
206 # that generated by CC
207 abitest-cc
$(EXESUF
): abitest.c
$(LIBTCC
)
208 $(CC
) -o
$@
$^
$(CFLAGS
) $(LIBS
) -w
210 abitest-tcc
$(EXESUF
): abitest.c libtcc.c
211 $(TCC
) -o
$@
$^
$(NATIVE_DEFINES
) -DONE_SOURCE
$(LIBS
)
213 ABITESTS
:= abitest-cc
$(EXESUF
)
214 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
215 ABITESTS
+= abitest-tcc
$(EXESUF
)
219 @echo
------------ $@
------------
220 .
/abitest-cc
$(EXESUF
) $(TCCFLAGS
)
221 ifneq ($(CONFIG_arm_eabi
),yes
) # not ARM soft-float
222 .
/abitest-tcc
$(EXESUF
) $(TCCFLAGS
)
225 vla_test
$(EXESUF
): vla_test.c
228 vla_test-run
: vla_test
$(EXESUF
)
229 @echo
------------ $@
------------
232 # targets for development
241 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
244 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
245 vg_annotate tcc.c
> /tmp
/linpack.cache.log
249 rm -f
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.
cc *.gcc \
250 *-cc *-gcc
*-tcc
*.exe hello libtcc_test vla_test tcctest
[1234] ex? tcc_g
254 # silent clean, used before running tests
256 @
$(MAKE
) -s
--no-print-directory
clean