aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 95ff3403e5fd2d61596c91bd61480e5b77e1d64e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Tiny C Compiler Makefile
#
prefix=/usr/local

CFLAGS=-O2 -g -Wall
LIBS=-ldl
CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
LIBS_P=

CFLAGS+=-m386 -malign-functions=0
DISAS=objdump -d
INSTALL=install
VERSION=0.9.4

all: tcc

# auto test

test: test.ref test.out
	@if diff -u test.ref test.out ; then echo "Auto Test OK"; fi

tcctest.ref: tcctest.c 
	gcc $(CFLAGS) -I. -o $@ $<

test.ref: tcctest.ref
	./tcctest.ref > $@

test.out: tcc tcctest.c
	./tcc -I. tcctest.c > $@

run: tcc tcctest.c
	./tcc -I. tcctest.c

# iterated test2 (compile tcc then compile tcctest.c !)
test2: tcc tcc.c tcctest.c test.ref
	./tcc -I. tcc.c -I. tcctest.c > test.out2
	@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi

# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
test3: tcc tcc.c tcctest.c test.ref
	./tcc -I. tcc.c -I. tcc.c -I. tcctest.c > test.out3
	@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi

# memory and bound check auto test
BOUNDS_OK  = 1 4 8 10
BOUNDS_FAIL= 2 5 7 9 11 12

btest: boundtest.c tcc
	@for i in $(BOUNDS_OK); do \
           if ./tcc -b boundtest.c $$i ; then \
               /bin/true ; \
           else\
	       echo Failed positive test $$i ; exit 1 ; \
           fi ;\
        done ;\
        for i in $(BOUNDS_FAIL); do \
           if ./tcc -b boundtest.c $$i ; then \
	       echo Failed negative test $$i ; exit 1 ;\
           else\
               /bin/true ; \
           fi\
        done ;\
        echo Bound test OK

# speed test
speed: tcc ex2 ex3
	time ./ex2 1238 2 3 4 10 13 4
	time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
	time ./ex3 35
	time ./tcc -I. ./ex3.c 35

ex2: ex2.c
	gcc $(CFLAGS) -o $@ $<

ex3: ex3.c
	gcc $(CFLAGS) -o $@ $<

# Tiny C Compiler

tcc_g: tcc.c i386-gen.c bcheck.c Makefile
	gcc $(CFLAGS) -o $@ $< $(LIBS)

tcc: tcc_g
	strip -s -R .comment -R .note -o $@ $<

install: tcc 
	$(INSTALL) -m755 tcc $(prefix)/bin
	mkdir -p $(prefix)/lib/tcc
	$(INSTALL) -m644 stdarg.h stddef.h float.h stdbool.h \
                   tcclib.h $(prefix)/lib/tcc

clean:
	rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
           core gmon.out test.out test.ref a.out tcc_p

# win32 version
tcc_g.exe: tcc.c i386-gen.c bcheck.c Makefile
	i386-mingw32msvc-gcc $(CFLAGS) -DCONFIG_TCC_STATIC -o $@ $<

tcc.exe: tcc_g.exe
	i386-mingw32msvc-strip -o $@ $<

# profiling version
tcc_p: tcc.c Makefile
	gcc $(CFLAGS_P) -o $@ $< $(LIBS_P)

# targets for development

%.bin: %.c tcc
	./tcc -g -o $@ -I. $<
	$(DISAS) $@

instr: instr.o
	objdump -d instr.o

instr.o: instr.S
	gcc -O2 -Wall -g -c -o $@ $<

FILE=tcc-$(VERSION)

tar:
	rm -rf /tmp/$(FILE)
	cp -r ../tcc /tmp/$(FILE)
	( cd /tmp ; tar zcvf ~/$(FILE).tar.gz \
          $(FILE)/Makefile $(FILE)/README $(FILE)/TODO $(FILE)/COPYING \
	  $(FILE)/Changelog $(FILE)/tcc-doc.html \
          $(FILE)/tcc.c $(FILE)/i386-gen.c $(FILE)/bcheck.c \
          $(FILE)/stddef.h $(FILE)/stdarg.h $(FILE)/stdbool.h $(FILE)/float.h \
          $(FILE)/tcclib.h \
          $(FILE)/ex*.c $(FILE)/tcctest.c $(FILE)/boundtest.c )
	rm -rf /tmp/$(FILE)