2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
17 # test4 # this test does not seem to work on any platform
18 # asmtest # this test does not seem to work on any platform
20 # bounds-checking is supported only on i386
22 TESTS
:= $(filter-out btest
,$(TESTS
))
25 # these should work too
26 # TESTS += test1 test2 speedtest btest weaktest
28 # some tests do not pass on all platforms, remove them for now
29 ifeq ($(TARGETOS
),Linux
)
30 TESTS
:= $(filter-out weaktest
,$(TESTS
))
32 ifeq ($(TARGETOS
),Darwin
)
33 TESTS
:= $(filter-out test1
,$(TESTS
))
34 TESTS
:= $(filter-out test2
,$(TESTS
))
35 TESTS
:= $(filter-out test3
,$(TESTS
))
36 TESTS
:= $(filter-out btest
,$(TESTS
))
37 TESTS
:= $(filter-out weaktest
,$(TESTS
))
41 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
44 ifeq ($(TARGETOS
),Darwin
)
45 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
46 export MACOSX_DEPLOYMENT_TARGET
:=10.2
47 NATIVE_DEFINES
+=-D_ANSI_SOURCE
50 # run local version of tcc with local libraries and includes
51 TCC
= ..
/tcc
-B..
$(NATIVE_DEFINES
)
53 TCC
:= $(TCC
) -I
$(TOP
)/win32
/include -L
$(TOP
)
55 RUN_TCC
= $(NATIVE_DEFINES
) -run
-DONE_SOURCE ..
/tcc.c
-B..
60 # make sure that tcc exists
61 test1 test2 test3 test4 btest speedtest asmtest weaktest
: ..
/tcc
67 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
70 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
71 @echo
------------ $@
------------
72 .
/libtcc_test
$(EXESUF
) lib_path
=..
74 libtcc_test
$(EXESUF
): libtcc_test.c ..
/$(LIBTCC
)
75 $(CC
) -o
$@
$^
-I..
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
)
77 # test.ref - generate using gcc
78 # copy only tcclib.h so GCC's stddef and stdarg will be used
80 cp ..
/include/tcclib.h .
81 $(CC
) -o tcctest.gcc
$< -I.
$(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
86 @echo
------------ $@
------------
87 $(TCC
) -run tcctest.c
> test.out1
88 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
90 # iterated test2 (compile tcc then compile tcctest.c !)
92 @echo
------------ $@
------------
93 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
94 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
96 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
98 @echo
------------ $@
------------
99 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
100 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
104 @echo
------------ $@
------------
106 $(TCC
) -o tcctest1 tcctest.c
107 .
/tcctest1
> test1.out
108 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
109 # object + link output
110 $(TCC
) -c
-o tcctest3.o tcctest.c
111 $(TCC
) -o tcctest3 tcctest3.o
112 .
/tcctest3
> test3.out
113 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
115 $(TCC
) -static
-o tcctest2 tcctest.c
116 .
/tcctest2
> test2.out
117 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
118 # dynamic output + bound check
119 $(TCC
) -b
-o tcctest4 tcctest.c
120 .
/tcctest4
> test4.out
121 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
123 # memory and bound check auto test
124 BOUNDS_OK
= 1 4 8 10 14
125 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
127 btest
: boundtest.c ..
/bcheck.o
128 @echo
------------ $@
------------
129 @for i in
$(BOUNDS_OK
); do \
130 echo
; echo
--- boundtest
$$i ---; \
131 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
132 echo succeded
as expected
; \
134 echo Failed positive
test $$i ; exit
1 ; \
137 for i in
$(BOUNDS_FAIL
); do \
138 echo
; echo
--- boundtest
$$i ---; \
139 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
140 echo Failed negative
test $$i ; exit
1 ;\
142 echo failed
as expected
; \
145 echo
; echo Bound
test OK
149 @echo
------------ $@
------------
150 time .
/ex2
1238 2 3 4 10 13 4
151 time
$(TCC
) -run ..
/examples
/ex2.c
1238 2 3 4 10 13 4
153 time
$(TCC
) -run ..
/examples
/ex3.c
35
156 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
157 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
158 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
159 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
160 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
162 ex
%: ..
/examples
/ex
%.c
163 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
165 # tiny assembler testing
166 asmtest.ref
: asmtest.S
167 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
168 objdump
-D asmtest.ref.o
> asmtest.ref
171 @echo
------------ $@
------------
173 objdump
-D asmtest.o
> asmtest.out
174 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
176 # targets for development
185 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
188 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
189 vg_annotate tcc.c
> /tmp
/linpack.cache.log
193 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.gcc \
194 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h