2 # Tiny C Compiler Makefile - tests
6 include $(TOP
)/Makefile
7 VPATH
= $(top_srcdir
)/tests
16 # test4 -- problem with -static
17 # asmtest -- minor differences with gcc
18 # btest -- works on i386 (including win32)
19 # test3 -- win32 does not know how to printf long doubles
21 # bounds-checking is supported only on i386
23 TESTS
:= $(filter-out btest
,$(TESTS
))
26 TESTS
:= $(filter-out test3
,$(TESTS
))
28 ifeq ($(TARGETOS
),Darwin
)
29 TESTS
:= $(filter-out hello test3 btest
,$(TESTS
))
33 export LD_LIBRARY_PATH
:=$(CURDIR
)/..
36 ifeq ($(TARGETOS
),Darwin
)
37 CFLAGS
+=-Wl
,-flat_namespace
,-undefined
,warning
38 export MACOSX_DEPLOYMENT_TARGET
:=10.2
39 NATIVE_DEFINES
+=-D_ANSI_SOURCE
42 # run local version of tcc with local libraries and includes
45 TCCFLAGS
= -B
$(top_srcdir
)/win32
-I
$(top_srcdir
)/include -L
$(TOP
)
48 TCC
= $(TOP
)/tcc
$(TCCFLAGS
)
49 RUN_TCC
= $(NATIVE_DEFINES
) -DONE_SOURCE
-run
$(TOP
)/tcc.c
$(TCCFLAGS
)
55 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
60 hello
: ..
/examples
/ex1.c
61 @echo
------------ $@
------------
62 $(TCC
) $< -o
$@
$(EXESUF
) && .
/$@
$(EXESUF
)
65 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
66 @echo
------------ $@
------------
67 .
/libtcc_test
$(EXESUF
) lib_path
=..
69 libtcc_test
$(EXESUF
): libtcc_test.c
$(top_builddir
)/$(LIBTCC
)
70 $(CC
) -o
$@
$^
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
)
73 @echo
------------ $@
------------
76 # test.ref - generate using gcc
77 # copy only tcclib.h so GCC's stddef and stdarg will be used
79 cp ..
/include/tcclib.h .
80 gcc
-o tcctest.gcc
$< -I.
$(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
85 @echo
------------ $@
------------
86 $(TCC
) -run tcctest.c
> test.out1
87 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
89 # iterated test2 (compile tcc then compile tcctest.c !)
91 @echo
------------ $@
------------
92 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
93 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
95 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
97 @echo
------------ $@
------------
98 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
99 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
103 @echo
------------ $@
------------
104 # object + link output
105 $(TCC
) -c
-o tcctest3.o tcctest.c
106 $(TCC
) -o tcctest3 tcctest3.o
107 .
/tcctest3
> test3.out
108 @if diff
-u
test.ref test3.out
; then echo
"Object Auto Test OK"; fi
110 $(TCC
) -o tcctest1 tcctest.c
111 .
/tcctest1
> test1.out
112 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
113 # dynamic output + bound check
114 $(TCC
) -b
-o tcctest4 tcctest.c
115 .
/tcctest4
> test4.out
116 @if diff
-u
test.ref test4.out
; then echo
"BCheck Auto Test OK"; fi
118 $(TCC
) -static
-o tcctest2 tcctest.c
119 .
/tcctest2
> test2.out
120 @if diff
-u
test.ref test2.out
; then echo
"Static Auto Test OK"; fi
122 # memory and bound check auto test
123 BOUNDS_OK
= 1 4 8 10 14
124 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
127 @echo
------------ $@
------------
128 @for i in
$(BOUNDS_OK
); do \
129 echo
; echo
--- boundtest
$$i ---; \
130 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
131 echo succeded
as expected
; \
133 echo Failed positive
test $$i ; exit
1 ; \
136 for i in
$(BOUNDS_FAIL
); do \
137 echo
; echo
--- boundtest
$$i ---; \
138 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
139 echo Failed negative
test $$i ; exit
1 ;\
141 echo failed
as expected
; \
144 echo
; echo Bound
test OK
148 @echo
------------ $@
------------
149 time .
/ex2
1238 2 3 4 10 13 4
150 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex2.c
1238 2 3 4 10 13 4
152 time
$(TCC
) -run
$(top_srcdir
)/examples
/ex3.c
35
155 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
156 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
157 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
158 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
159 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
161 ex
%: $(top_srcdir
)/examples
/ex
%.c
162 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
164 # tiny assembler testing
165 asmtest.ref
: asmtest.S
166 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
167 objdump
-D asmtest.ref.o
> asmtest.ref
170 @echo
------------ $@
------------
172 objdump
-D asmtest.o
> asmtest.out
173 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
175 # targets for development
184 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
187 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
188 vg_annotate tcc.c
> /tmp
/linpack.cache.log
193 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.out?b
*.gcc
*.exe \
194 hello libtcc_test tcctest
[1234] ex? tcc_g tcclib.h