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
) -I
$(top_srcdir
) -I
$(top_srcdir
)/include
48 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
) -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 gcc
-o tcctest.gcc
$< -I
$(top_srcdir
) $(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
90 @echo
------------ $@
------------
91 $(TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out1
92 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
94 # iterated test2 (compile tcc then compile tcctest.c !)
96 @echo
------------ $@
------------
97 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out2
98 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
100 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
102 @echo
------------ $@
------------
103 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run
$(SRCDIR
)/tcctest.c
> test.out3
104 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
108 @echo
------------ $@
------------
109 # object + link output
110 $(TCC
) -c
-o tcctest3.o
$(SRCDIR
)/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
) -o tcctest1
$(SRCDIR
)/tcctest.c
116 .
/tcctest1
> test1.out
117 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
118 # dynamic output + bound check
119 $(TCC
) -b
-o tcctest4
$(SRCDIR
)/tcctest.c
120 .
/tcctest4
> test4.out
121 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
123 $(TCC
) -static
-o tcctest2
$(SRCDIR
)/tcctest.c
124 .
/tcctest2
> test2.out
125 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
127 # memory and bound check auto test
128 BOUNDS_OK
= 1 4 8 10 14
129 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
132 @echo
------------ $@
------------
133 @for i in
$(BOUNDS_OK
); do \
134 echo
; echo
--- boundtest
$$i ---; \
135 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
136 echo succeded
as expected
; \
138 echo Failed positive
test $$i ; exit
1 ; \
141 for i in
$(BOUNDS_FAIL
); do \
142 echo
; echo
--- boundtest
$$i ---; \
143 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
144 echo Failed negative
test $$i ; exit
1 ;\
146 echo failed
as expected
; \
149 echo
; echo Bound
test OK
153 @echo
------------ $@
------------
154 time .
/ex2
1238 2 3 4 10 13 4
155 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
157 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
160 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
161 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
162 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
163 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
164 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
166 ex
%: $(top_srcdir
)/examples
/ex
%.c
167 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
169 # tiny assembler testing
170 asmtest.ref
: asmtest.S
171 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
172 objdump
-D asmtest.ref.o
> asmtest.ref
175 @echo
------------ $@
------------
177 objdump
-D asmtest.o
> asmtest.out
178 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
180 # Check that code generated by libtcc is binary compatible with
181 # that generated by CC
182 abitest-cc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
183 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
185 abitest-tcc
$(EXESUF
): abitest.c
$(top_builddir
)/$(LIBTCC
)
186 $(TCC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
) -I
$(top_srcdir
)
188 abitest
: abitest-cc
$(EXESUF
) abitest-tcc
$(EXESUF
)
189 @echo
------------ $@
------------
190 .
/abitest-cc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
191 .
/abitest-tcc
$(EXESUF
) lib_path
=..
include="$(top_srcdir)/include"
193 # targets for development
202 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
205 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
206 vg_annotate tcc.c
> /tmp
/linpack.cache.log
211 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.gcc
*.exe \
212 hello libtcc_test tcctest
[1234] ex? tcc_g tcclib.h
214 Makefile
: $(SRCDIR
)/Makefile