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 weaktest
,$(TESTS
))
27 ifeq ($(TARGETOS
),Darwin
)
28 TESTS
:= $(filter-out test1
,$(TESTS
))
29 TESTS
:= $(filter-out test2
,$(TESTS
))
30 TESTS
:= $(filter-out test3
,$(TESTS
))
31 TESTS
:= $(filter-out btest
,$(TESTS
))
32 TESTS
:= $(filter-out weaktest
,$(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 TCC
= ..
/tcc
-B..
$(NATIVE_DEFINES
)
48 TCC
:= $(TCC
) -I
$(TOP
)/win32
/include -L
$(TOP
)
50 RUN_TCC
= $(NATIVE_DEFINES
) -run
-DONE_SOURCE ..
/tcc.c
-B..
55 # make sure that tcc exists
56 test1 test2 test3 test4 btest speedtest asmtest weaktest
: ..
/tcc
62 LIBTCC1
:=$(TOP
)/$(LIBTCC1
)
65 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
66 @echo
------------ $@
------------
67 .
/libtcc_test
$(EXESUF
) lib_path
=..
69 libtcc_test
$(EXESUF
): libtcc_test.c ..
/$(LIBTCC
)
70 $(CC
) -o
$@
$^
-I..
$(CPPFLAGS
) $(CFLAGS
) $(NATIVE_DEFINES
) $(LIBS
) $(LINK_LIBTCC
) $(LDFLAGS
)
72 # test.ref - generate using gcc
73 # copy only tcclib.h so GCC's stddef and stdarg will be used
75 cp ..
/include/tcclib.h .
76 $(CC
) -o tcctest.gcc
$< -I.
$(CPPFLAGS
) -w
$(CFLAGS
) $(NATIVE_DEFINES
) -std
=gnu99
-O0
-fno-omit-frame-pointer
$(LDFLAGS
)
81 @echo
------------ $@
------------
82 $(TCC
) -run tcctest.c
> test.out1
83 @if diff
-u
test.ref
test.out1
; then echo
"Auto Test OK"; fi
85 # iterated test2 (compile tcc then compile tcctest.c !)
87 @echo
------------ $@
------------
88 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out2
89 @if diff
-u
test.ref
test.out2
; then echo
"Auto Test2 OK"; fi
91 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
93 @echo
------------ $@
------------
94 $(TCC
) $(RUN_TCC
) $(RUN_TCC
) $(RUN_TCC
) -run tcctest.c
> test.out3
95 @if diff
-u
test.ref
test.out3
; then echo
"Auto Test3 OK"; fi
99 @echo
------------ $@
------------
101 $(TCC
) -o tcctest1 tcctest.c
102 .
/tcctest1
> test1.out
103 @if diff
-u
test.ref test1.out
; then echo
"Dynamic Auto Test OK"; fi
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
) -static
-o tcctest2 tcctest.c
111 .
/tcctest2
> test2.out
112 @if diff
-u
test.ref test2.out
; then echo
"Static 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 # memory and bound check auto test
119 BOUNDS_OK
= 1 4 8 10 14
120 BOUNDS_FAIL
= 2 5 7 9 11 12 13 15
122 btest
: boundtest.c ..
/bcheck.o
123 @echo
------------ $@
------------
124 @for i in
$(BOUNDS_OK
); do \
125 echo
; echo
--- boundtest
$$i ---; \
126 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
127 echo succeded
as expected
; \
129 echo Failed positive
test $$i ; exit
1 ; \
132 for i in
$(BOUNDS_FAIL
); do \
133 echo
; echo
--- boundtest
$$i ---; \
134 if
$(TCC
) -b
-run boundtest.c
$$i ; then \
135 echo Failed negative
test $$i ; exit
1 ;\
137 echo failed
as expected
; \
140 echo
; echo Bound
test OK
144 @echo
------------ $@
------------
145 time .
/ex2
1238 2 3 4 10 13 4
146 time
$(TCC
) -run ..
/examples
/ex2.c
1238 2 3 4 10 13 4
148 time
$(TCC
) -run ..
/examples
/ex3.c
35
151 $(TCC
) -c tcctest.c
-o weaktest.tcc.o
$(CPPFLAGS
) $(CFLAGS
)
152 $(CC
) -c tcctest.c
-o weaktest.gcc.o
-I.
$(CPPFLAGS
) -w
$(CFLAGS
)
153 objdump
-t weaktest.tcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.tcc.o.txt
154 objdump
-t weaktest.gcc.o | grep
' w ' | sed
-e
's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL
=C
sort > weaktest.gcc.o.txt
155 diff weaktest.gcc.o.txt weaktest.tcc.o.txt
&& echo
"Weak Auto Test OK"
157 ex
%: ..
/examples
/ex
%.c
158 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
160 # tiny assembler testing
161 asmtest.ref
: asmtest.S
162 $(CC
) -Wa
,-W
-o asmtest.ref.o
-c asmtest.S
163 objdump
-D asmtest.ref.o
> asmtest.ref
166 @echo
------------ $@
------------
168 objdump
-D asmtest.o
> asmtest.out
169 @if diff
-u
--ignore-matching-lines
="file format" asmtest.ref asmtest.out
; then echo
"ASM Auto Test OK"; fi
171 # targets for development
180 $(CC
) -o
$@
-c
$< -O2
-Wall
-g
183 cachegrind .
/tcc_g
-o
/tmp
/linpack
-lm bench
/linpack.c
184 vg_annotate tcc.c
> /tmp
/linpack.cache.log
188 rm -vf
*~
*.o
*.a
*.bin
*.i
*.ref
*.out
*.out?
*.gcc \
189 tcctest
[1234] ex? libtcc_test
$(EXESUF
) tcc_g tcclib.h