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 # these should work too
21 # TESTS += test1 test2 speedtest btest weaktest
23 # some tests do not pass on all platforms, remove them for now
24 ifeq ($(TARGETOS
),Linux
)
25 TESTS
:= $(filter-out btest
,$(TESTS
))
26 TESTS
:= $(filter-out weaktest
,$(TESTS
))
28 ifeq ($(TARGETOS
),Darwin
)
29 TESTS
:= $(filter-out test1
,$(TESTS
))
30 TESTS
:= $(filter-out test2
,$(TESTS
))
31 TESTS
:= $(filter-out test3
,$(TESTS
))
32 TESTS
:= $(filter-out btest
,$(TESTS
))
33 TESTS
:= $(filter-out weaktest
,$(TESTS
))
37 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
40 ifeq ($(TARGETOS
),Darwin
)
41 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
42 export MACOSX_DEPLOYMENT_TARGET
:=10.2
43 NATIVE_DEFINES
+=-D_ANSI_SOURCE
46 # run local version of tcc with local libraries and includes
47 TCC
= ..
/tcc
-B..
$(NATIVE_DEFINES
)
49 TCC
:= $(TCC
) -I
$(TOP
)/win32
/include -L
$(TOP
)
51 RUN_TCC
= $(NATIVE_DEFINES
) -run
-DONE_SOURCE ..
/tcc.c
-B..
56 # make sure that tcc exists
57 test1 test2 test3 test4 btest speedtest asmtest weaktest
: ..
/tcc
63 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
66 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
67 @echo
------------ $@
------------
68 .
/libtcc_test
$(EXESUF
) lib_path
=..
70 libtcc_test
$(EXESUF
): libtcc_test.c ..
/$(LIBTCC
)
71 $(CC
) -o
$@
$^
-I..
$(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
)
73 # test.ref - generate using gcc
74 # copy only tcclib.h so GCC's stddef and stdarg will be used
76 cp ..
/include/tcclib.h .
77 $(CC
) -o tcctest.gcc
$< -I.
-w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
82 @echo
------------ $@
------------
83 $(TCC
) -run tcctest.c
> test.out1
84 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
86 # iterated test2 (compile tcc then compile tcctest.c !)
88 @echo
------------ $@
------------
89 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
90 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
92 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
94 @echo
------------ $@
------------
95 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
96 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
100 @echo
------------ $@
------------
102 $(TCC
) -o tcctest1 tcctest.c
103 .
/tcctest1
> test1.out
104 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
105 # object + link output
106 $(TCC
) -c
-o tcctest3.o tcctest.c
107 $(TCC
) -o tcctest3 tcctest3.o
108 .
/tcctest3
> test3.out
109 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
111 $(TCC
) -static
-o tcctest2 tcctest.c
112 .
/tcctest2
> test2.out
113 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
114 # dynamic output + bound check
115 $(TCC
) -b
-o tcctest4 tcctest.c
116 .
/tcctest4
> test4.out
117 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
119 # memory and bound check auto test
120 BOUNDS_OK
= 1 4 8 10 14
121 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
123 btest
: boundtest.c ..
/bcheck.o
124 @echo
------------ $@
------------
125 @for i in
$(BOUNDS_OK
); do \
126 echo
; echo
--- boundtest
$$i ---; \
127 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
128 echo succeded
as expected
; \
130 echo Failed positive
test $$i ; exit
1 ; \
133 for i in
$(BOUNDS_FAIL
); do \
134 echo
; echo
--- boundtest
$$i ---; \
135 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
136 echo Failed negative
test $$i ; exit
1 ;\
138 echo failed
as expected
; \
141 echo
; echo Bound
test OK
145 @echo
------------ $@
------------
146 time .
/ex2
1238 2 3 4 10 13 4
147 time
$(TCC
) -run ..
/examples
/ex2.c
1238 2 3 4 10 13 4
149 time
$(TCC
) -run ..
/examples
/ex3.c
35
152 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
153 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
-w
$(CFLAGS
)
154 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
155 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
156 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
158 ex
%: ..
/examples
/ex
%.c
159 $(CC
) -o
$@
$< $(CFLAGS
)
161 # tiny assembler testing
162 asmtest.ref
: asmtest.S
163 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
164 objdump
-D asmtest.ref.o
> asmtest.ref
167 @echo
------------ $@
------------
169 objdump
-D asmtest.o
> asmtest.out
170 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
172 # targets for development
181 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
184 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
185 vg_annotate tcc.c
> /tmp
/linpack.cache.log
189 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.gcc \
190 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h