2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(top_srcdir
)/tests
21 # test4 # this test does not seem to work on any platform
22 # asmtest # this test does not seem to work on any platform
24 # bounds-checking is supported only on i386
26 TESTS
:= $(filter-out btest
,$(TESTS
))
27 TESTS
:= $(filter-out test1b
,$(TESTS
))
28 TESTS
:= $(filter-out test2b
,$(TESTS
))
29 TESTS
:= $(filter-out test3b
,$(TESTS
))
32 # these should work too
33 # TESTS += test1 test2 speedtest btest weaktest
35 # some tests do not pass on all platforms, remove them for now
36 ifeq ($(TARGETOS
),Linux
)
37 TESTS
:= $(filter-out weaktest
,$(TESTS
))
39 ifeq ($(TARGETOS
),Darwin
)
40 TESTS
:= $(filter-out test1
,$(TESTS
))
41 TESTS
:= $(filter-out test2
,$(TESTS
))
42 TESTS
:= $(filter-out test3
,$(TESTS
))
43 TESTS
:= $(filter-out btest
,$(TESTS
))
44 TESTS
:= $(filter-out weaktest
,$(TESTS
))
48 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
51 ifeq ($(TARGETOS
),Darwin
)
52 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
53 export MACOSX_DEPLOYMENT_TARGET
:=10.2
54 NATIVE_DEFINES
+=-D_ANSI_SOURCE
57 # run local version of tcc with local libraries and includes
58 TCC
= ..
/tcc
-B..
$(NATIVE_DEFINES
)
60 TCC
:= $(TCC
) -I
$(top_srcdir
)/win32
/include -L
$(top_build
)
62 RUN_TCC
= $(NATIVE_DEFINES
) -run
-DONE_SOURCE ..
/tcc.c
-B..
67 # make sure that tcc exists
68 test1 test2 test3 test4 btest speedtest asmtest weaktest
: ..
/tcc
74 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
77 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
78 @echo
------------ $@
------------
79 .
/libtcc_test
$(EXESUF
) lib_path
=..
81 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
82 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
)
84 # test.ref - generate using gcc
85 # copy only tcclib.h so GCC's stddef and stdarg will be used
87 cp ..
/include/tcclib.h .
88 $(CC
) -o tcctest.gcc
$< -I.
$(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
93 @echo
------------ $@
------------
94 $(TCC
) -run tcctest.c
> test.out1
95 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
98 @echo
------------ $@
------------
99 $(TCC
) -b
-run tcctest.c
> test.out1b
100 @if diff
-u
test.ref
test.out1b
; then echo
"Auto Test OK"; fi
102 # iterated test2 (compile tcc then compile tcctest.c !)
104 @echo
------------ $@
------------
105 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
106 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
108 test2b
: test.ref ..
/bcheck.o
109 @echo
------------ $@
------------
110 $(TCC
) -b
$(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2b
111 @if diff
-u
test.ref
test.out2b
; then echo
"Auto Test2b OK"; fi
113 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
115 @echo
------------ $@
------------
116 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
117 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
120 @echo
------------ $@
------------
121 $(TCC
) -b
$(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3b
122 @if diff
-u
test.ref
test.out3b
; then echo
"Auto Test3 OK"; fi
126 @echo
------------ $@
------------
128 $(TCC
) -o tcctest1 tcctest.c
129 .
/tcctest1
> test1.out
130 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
131 # object + link output
132 $(TCC
) -c
-o tcctest3.o tcctest.c
133 $(TCC
) -o tcctest3 tcctest3.o
134 .
/tcctest3
> test3.out
135 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
137 $(TCC
) -static
-o tcctest2 tcctest.c
138 .
/tcctest2
> test2.out
139 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
140 # dynamic output + bound check
141 $(TCC
) -b
-o tcctest4 tcctest.c
142 .
/tcctest4
> test4.out
143 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
145 # memory and bound check auto test
146 BOUNDS_OK
= 1 4 8 10 14
147 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
149 btest
: boundtest.c ..
/bcheck.o
150 @echo
------------ $@
------------
151 @for i in
$(BOUNDS_OK
); do \
152 echo
; echo
--- boundtest
$$i ---; \
153 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
154 echo succeded
as expected
; \
156 echo Failed positive
test $$i ; exit
1 ; \
159 for i in
$(BOUNDS_FAIL
); do \
160 echo
; echo
--- boundtest
$$i ---; \
161 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
162 echo Failed negative
test $$i ; exit
1 ;\
164 echo failed
as expected
; \
167 echo
; echo Bound
test OK
171 @echo
------------ $@
------------
172 time .
/ex2
1238 2 3 4 10 13 4
173 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
175 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
178 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
179 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
180 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
181 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
182 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
184 ex
%: $(top_srcdir
)/examples
/ex
%.c
185 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
187 # tiny assembler testing
188 asmtest.ref
: asmtest.S
189 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
190 objdump
-D asmtest.ref.o
> asmtest.ref
193 @echo
------------ $@
------------
195 objdump
-D asmtest.o
> asmtest.out
196 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
198 # targets for development
207 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
210 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
211 vg_annotate tcc.c
> /tmp
/linpack.cache.log
215 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.gcc \
216 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h