update
[tinycc/miki.git] / Makefile
blob0abaa6389649b26a8ec7f0ec05c99d7268e1ba91
2 # Tiny C Compiler Makefile
4 prefix=/usr/local
6 CFLAGS=-O2 -g -Wall
7 LIBS=-ldl
8 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
9 LIBS_P=
11 CFLAGS+=-m386 -malign-functions=0
12 CFLAGS+=-DCONFIG_TCC_PREFIX=\"$(prefix)\"
13 DISAS=objdump -d
14 INSTALL=install
15 VERSION=0.9.11
17 # run local version of tcc with local libraries and includes
18 TCC=./tcc -B. -I.
20 all: tcc libtcc1.o bcheck.o tcc-doc.html
22 # auto test
24 test: test.ref test.out
25 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
27 tcctest.ref: tcctest.c
28 gcc $(CFLAGS) -I. -o $@ $<
30 test.ref: tcctest.ref
31 ./tcctest.ref > $@
33 test.out: tcc tcctest.c
34 $(TCC) tcctest.c > $@
36 run: tcc tcctest.c
37 $(TCC) tcctest.c
39 # iterated test2 (compile tcc then compile tcctest.c !)
40 test2: tcc tcc.c tcctest.c test.ref
41 $(TCC) tcc.c -B. -I. tcctest.c > test.out2
42 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
44 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
45 test3: tcc tcc.c tcctest.c test.ref
46 $(TCC) tcc.c -B. -I. tcc.c -B. -I. tcctest.c > test.out3
47 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
49 # binary output test
50 test4: tcc test.ref
51 # dynamic output
52 $(TCC) -o tcctest1 tcctest.c
53 ./tcctest1 > test1.out
54 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
55 # static output
56 $(TCC) -static -o tcctest2 tcctest.c
57 ./tcctest2 > test2.out
58 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
59 # object + link output
60 $(TCC) -c -o tcctest3.o tcctest.c
61 $(TCC) -o tcctest3 tcctest3.o
62 ./tcctest3 > test3.out
63 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
64 # dynamic output + bound check
65 $(TCC) -b -o tcctest4 tcctest.c
66 ./tcctest4 > test4.out
67 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
69 # memory and bound check auto test
70 BOUNDS_OK = 1 4 8 10
71 BOUNDS_FAIL= 2 5 7 9 11 12 13
73 btest: boundtest.c tcc
74 @for i in $(BOUNDS_OK); do \
75 if $(TCC) -b boundtest.c $$i ; then \
76 /bin/true ; \
77 else\
78 echo Failed positive test $$i ; exit 1 ; \
79 fi ;\
80 done ;\
81 for i in $(BOUNDS_FAIL); do \
82 if $(TCC) -b boundtest.c $$i ; then \
83 echo Failed negative test $$i ; exit 1 ;\
84 else\
85 /bin/true ; \
86 fi\
87 done ;\
88 echo Bound test OK
90 # speed test
91 speed: tcc ex2 ex3
92 time ./ex2 1238 2 3 4 10 13 4
93 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
94 time ./ex3 35
95 time ./tcc -I. ./ex3.c 35
97 ex2: ex2.c
98 gcc $(CFLAGS) -o $@ $<
100 ex3: ex3.c
101 gcc $(CFLAGS) -o $@ $<
103 # Native Tiny C Compiler
105 tcc_g: tcc.c i386-gen.c tccelf.c tcctok.h libtcc.h Makefile
106 gcc $(CFLAGS) -o $@ $< $(LIBS)
108 tcc: tcc_g
109 strip -s -R .comment -R .note -o $@ $<
111 # TinyCC runtime libraries
112 libtcc1.o: libtcc1.c
113 gcc -O2 -Wall -c -o $@ $<
115 bcheck.o: bcheck.c
116 gcc -O2 -Wall -c -o $@ $<
118 install: tcc libtcc1.o bcheck.o
119 $(INSTALL) -m755 tcc $(prefix)/bin
120 $(INSTALL) tcc.1 $(prefix)/man/man1
121 mkdir -p $(prefix)/lib/tcc
122 mkdir -p $(prefix)/lib/tcc/include
123 $(INSTALL) -m644 libtcc1.o bcheck.o $(prefix)/lib/tcc
124 $(INSTALL) -m644 stdarg.h stddef.h float.h stdbool.h \
125 tcclib.h $(prefix)/lib/tcc/include
127 clean:
128 rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
129 core gmon.out test.out test.ref a.out tcc_p \
130 *.exe iltcc iltcc_g tcc-doc.html \
131 tcctest[1234] test[1234].out
133 # IL TCC
135 iltcc_g: tcc.c il-gen.c bcheck.c Makefile
136 gcc $(CFLAGS) -DTCC_TARGET_IL -o $@ $< $(LIBS)
138 iltcc: iltcc_g
139 strip -s -R .comment -R .note -o $@ $<
141 # win32 TCC
142 tcc_g.exe: tcc.c i386-gen.c bcheck.c Makefile
143 i386-mingw32msvc-gcc $(CFLAGS) -DCONFIG_TCC_STATIC -o $@ $<
145 tcc.exe: tcc_g.exe
146 i386-mingw32msvc-strip -o $@ $<
148 # profiling version
149 tcc_p: tcc.c Makefile
150 gcc $(CFLAGS_P) -o $@ $< $(LIBS_P)
152 # libtcc generation and example
153 libinstall: libtcc.a
154 $(INSTALL) -m644 libtcc.a $(prefix)/lib
155 $(INSTALL) -m644 libtcc.h $(prefix)/include
157 libtcc.o: tcc.c i386-gen.c bcheck.c Makefile
158 gcc $(CFLAGS) -DLIBTCC -c -o $@ $<
160 libtcc.a: libtcc.o
161 ar rcs $@ $^
163 libtcc_test: libtcc_test.c libtcc.a
164 gcc $(CFLAGS) -I. -o $@ $< -L. -ltcc -ldl
166 # targets for development
168 %.bin: %.c tcc
169 $(TCC) -g -o $@ $<
170 $(DISAS) $@
172 instr: instr.o
173 objdump -d instr.o
175 instr.o: instr.S
176 gcc -O2 -Wall -g -c -o $@ $<
178 # documentation
179 tcc-doc.html: tcc-doc.texi
180 texi2html -monolithic -number $<
182 FILES= Makefile Makefile.uClibc \
183 README TODO COPYING \
184 Changelog tcc-doc.texi tcc-doc.html \
185 tcc.1 \
186 tcc.c i386-gen.c tccelf.c tcctok.h \
187 bcheck.c libtcc1.c \
188 il-opcodes.h il-gen.c \
189 elf.h stab.h stab.def \
190 stddef.h stdarg.h stdbool.h float.h \
191 tcclib.h libtcc.h libtcc_test.c \
192 ex1.c ex2.c ex3.c ex4.c ex5.c \
193 tcctest.c boundtest.c
195 FILE=tcc-$(VERSION)
197 tar:
198 rm -rf /tmp/$(FILE)
199 mkdir -p /tmp/$(FILE)
200 cp -P $(FILES) /tmp/$(FILE)
201 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) )
202 rm -rf /tmp/$(FILE)