2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 SRCDIR
= $(top_srcdir
)/tests
19 # test4 -- problem with -static
20 # asmtest -- minor differences with gcc
21 # btest -- works on i386 (including win32)
22 # test3 -- win32 does not know how to printf long doubles
24 # bounds-checking is supported only on i386
26 TESTS
:= $(filter-out btest
,$(TESTS
))
29 TESTS
:= $(filter-out test3
,$(TESTS
))
31 ifeq ($(TARGETOS
),Darwin
)
32 TESTS
:= $(filter-out hello-exe test3 btest
,$(TESTS
))
36 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
39 ifeq ($(TARGETOS
),Darwin
)
40 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
41 export MACOSX_DEPLOYMENT_TARGET
:=10.2
42 NATIVE_DEFINES
+=-D_ANSI_SOURCE
45 # run local version of tcc with local libraries and includes
46 TCCFLAGS
= -B
$(TOP
) -I
$(TOP
)
48 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
)/include -I
$(TOP
) -L
$(TOP
)
51 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
52 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(top_srcdir
)/tcc.c
$(TCCFLAGS
)
58 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
63 hello-exe
: ..
/examples
/ex1.c
64 @echo
------------ $@
------------
65 $(TCC
) $< -o hello
$(EXESUF
) ||
($(TOP
)/tcc
-vv
; exit
1) && .
/hello
$(EXESUF
)
67 hello-run
: ..
/examples
/ex1.c
68 @echo
------------ $@
------------
71 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
72 @echo
------------ $@
------------
73 .
/libtcc_test
$(EXESUF
) lib_path
=..
75 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
76 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
79 @echo
------------ $@
------------
82 # test.ref - generate using gcc
83 # copy only tcclib.h so GCC's stddef and stdarg will be used
85 cp
$(top_srcdir
)/include/tcclib.h .
86 gcc
-o tcctest.gcc
$< -I.
$(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
91 @echo
------------ $@
------------
92 $(TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out1
93 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
95 # iterated test2 (compile tcc then compile tcctest.c !)
97 @echo
------------ $@
------------
98 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out2
99 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
101 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
103 @echo
------------ $@
------------
104 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out3
105 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
109 @echo
------------ $@
------------
110 # object + link output
111 $(TCC
) -c
-o tcctest3.o tcctest.c
112 $(TCC
) -o tcctest3 tcctest3.o
113 .
/tcctest3
> test3.out
114 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
116 $(TCC
) -o tcctest1 tcctest.c
117 .
/tcctest1
> test1.out
118 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
119 # dynamic output + bound check
120 $(TCC
) -b
-o tcctest4 tcctest.c
121 .
/tcctest4
> test4.out
122 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
124 $(TCC
) -static
-o tcctest2 tcctest.c
125 .
/tcctest2
> test2.out
126 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
128 # memory and bound check auto test
129 BOUNDS_OK
= 1 4 8 10 14
130 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
133 @echo
------------ $@
------------
134 @for i in
$(BOUNDS_OK
); do \
135 echo
; echo
--- boundtest
$$i ---; \
136 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
137 echo succeded
as expected
; \
139 echo Failed positive
test $$i ; exit
1 ; \
142 for i in
$(BOUNDS_FAIL
); do \
143 echo
; echo
--- boundtest
$$i ---; \
144 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
145 echo Failed negative
test $$i ; exit
1 ;\
147 echo failed
as expected
; \
150 echo
; echo Bound
test OK
154 @echo
------------ $@
------------
155 time .
/ex2
1238 2 3 4 10 13 4
156 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
158 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
161 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
162 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
163 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
164 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
165 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
167 ex
%: $(top_srcdir
)/examples
/ex
%.c
168 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
170 # tiny assembler testing
171 asmtest.ref
: asmtest.S
172 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
173 objdump
-D asmtest.ref.o
> asmtest.ref
176 @echo
------------ $@
------------
178 objdump
-D asmtest.o
> asmtest.out
179 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
181 # Check that code generated by libtcc is binary compatible with
182 # that generated by CC
183 abitest-cc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
184 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
186 abitest-tcc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
187 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
189 abitest
: abitest-cc
$(EXESUF
) abitest-tcc
$(EXESUF
)
190 @echo
------------ $@
------------
191 .
/abitest-cc
$(EXESUF
) lib_path
=..
192 .
/abitest-tcc
$(EXESUF
) lib_path
=..
194 # targets for development
203 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
206 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
207 vg_annotate tcc.c
> /tmp
/linpack.cache.log
212 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.gcc
*.exe \
213 hello libtcc_test tcctest
[1234] ex? tcc_g tcclib.h
215 Makefile
: $(SRCDIR
)/Makefile