2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 SRCDIR
= $(top_srcdir
)/tests
20 # test4 -- problem with -static
21 # asmtest -- minor differences with gcc
22 # btest -- works on i386 (including win32)
23 # test3 -- win32 does not know how to printf long doubles
25 # bounds-checking is supported only on i386
27 TESTS
:= $(filter-out btest
,$(TESTS
))
30 TESTS
:= $(filter-out test3
,$(TESTS
))
32 ifeq ($(TARGETOS
),Darwin
)
33 TESTS
:= $(filter-out hello-exe test3 btest
,$(TESTS
))
36 else ifneq ($(ARCH
),x86-64
)
37 TESTS
:= $(filter-out vla_test-run
,$(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 TCCFLAGS
= -B
$(TOP
) -I
$(TOP
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
53 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
) -I
$(top_srcdir
)/include -I
$(TOP
) -L
$(TOP
)
56 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
57 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(top_srcdir
)/tcc.c
$(TCCFLAGS
)
63 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
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
) $(LIBTCC1
)
77 @echo
------------ $@
------------
78 .
/libtcc_test
$(EXESUF
) lib_path
=..
80 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
81 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
84 @echo
------------ $@
------------
87 # test.ref - generate using gcc
88 # copy only tcclib.h so GCC's stddef and stdarg will be used
90 gcc
-o tcctest.gcc
$< -I
$(top_srcdir
) $(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
95 @echo
------------ $@
------------
96 $(TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out1
97 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
99 # iterated test2 (compile tcc then compile tcctest.c !)
101 @echo
------------ $@
------------
102 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out2
103 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
105 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
107 @echo
------------ $@
------------
108 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out3
109 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
113 @echo
------------ $@
------------
114 # object + link output
115 $(TCC
) -c
-o tcctest3.o
$(SRCDIR
)/tcctest.c
116 $(TCC
) -o tcctest3 tcctest3.o
117 .
/tcctest3
> test3.out
118 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
120 $(TCC
) -o tcctest1
$(SRCDIR
)/tcctest.c
121 .
/tcctest1
> test1.out
122 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
123 # dynamic output + bound check
124 $(TCC
) -b
-o tcctest4
$(SRCDIR
)/tcctest.c
125 .
/tcctest4
> test4.out
126 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
128 $(TCC
) -static
-o tcctest2
$(SRCDIR
)/tcctest.c
129 .
/tcctest2
> test2.out
130 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
132 # memory and bound check auto test
133 BOUNDS_OK
= 1 4 8 10 14
134 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
137 @echo
------------ $@
------------
138 @for i in
$(BOUNDS_OK
); do \
139 echo
; echo
--- boundtest
$$i ---; \
140 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
141 echo succeded
as expected
; \
143 echo Failed positive
test $$i ; exit
1 ; \
146 for i in
$(BOUNDS_FAIL
); do \
147 echo
; echo
--- boundtest
$$i ---; \
148 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
149 echo Failed negative
test $$i ; exit
1 ;\
151 echo failed
as expected
; \
154 echo
; echo Bound
test OK
158 @echo
------------ $@
------------
159 time .
/ex2
1238 2 3 4 10 13 4
160 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
162 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
165 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
166 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
167 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
168 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
169 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
171 ex
%: $(top_srcdir
)/examples
/ex
%.c
172 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
174 # tiny assembler testing
175 asmtest.ref
: asmtest.S
176 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
177 objdump
-D asmtest.ref.o
> asmtest.ref
180 @echo
------------ $@
------------
182 objdump
-D asmtest.o
> asmtest.out
183 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
185 # Check that code generated by libtcc is binary compatible with
186 # that generated by CC
187 abitest-cc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
188 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
190 abitest-tcc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
191 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
193 abitest
: abitest-cc
$(EXESUF
) abitest-tcc
$(EXESUF
)
194 @echo
------------ $@
------------
195 .
/abitest-cc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
196 .
/abitest-tcc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
198 vla_test
$(EXESUF
): vla_test.c
199 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
)
200 vla_test-run
: vla_test
$(EXESUF
)
201 @echo
------------ $@
------------
204 # targets for development
213 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
216 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
217 vg_annotate tcc.c
> /tmp
/linpack.cache.log
222 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.gcc
*.exe \
223 hello libtcc_test tcctest
[1234] ex? tcc_g tcclib.h
225 Makefile
: $(SRCDIR
)/Makefile