_Bool type fix
[tinycc.git] / Makefile
blob5dbc68da9ec4e8d173d04b20390ae4a5004e12b6
2 # Tiny C Compiler Makefile
4 include config.mak
6 CFLAGS=-O2 -g -Wall
7 ifndef CONFIG_WIN32
8 LIBS=-ldl
9 BCHECK_O=bcheck.o
10 endif
11 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
12 LIBS_P=
14 CFLAGS+=-mpreferred-stack-boundary=2
15 ifeq ($(GCC_MAJOR),2)
16 CFLAGS+=-m386 -malign-functions=0
17 else
18 CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing
19 endif
21 DISAS=objdump -d
22 INSTALL=install
24 ifdef CONFIG_WIN32
25 PROGS=tcc$(EXESUF)
26 ifdef CONFIG_CROSS
27 PROGS+=c67-tcc$(EXESUF) arm-tcc$(EXESUF)
28 endif
29 PROGS+=tiny_impdef$(EXESUF)
30 else
31 ifeq ($(ARCH),i386)
32 PROGS=tcc$(EXESUF)
33 ifdef CONFIG_CROSS
34 PROGS+=arm-tcc$(EXESUF)
35 endif
36 endif
37 ifeq ($(ARCH),arm)
38 PROGS=tcc$(EXESUF)
39 ifdef CONFIG_CROSS
40 PROGS+=i386-tcc$(EXESUF)
41 endif
42 endif
43 ifdef CONFIG_CROSS
44 PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
45 endif
46 endif
48 # run local version of tcc with local libraries and includes
49 TCC=./tcc -B. -I.
51 all: $(PROGS) \
52 libtcc1$(LIBSUF) $(BCHECK_O) tcc-doc.html tcc.1 libtcc$(LIBSUF) \
53 libtcc_test$(EXESUF)
55 Makefile: config.mak
57 # auto test
59 test: test.ref test.out
60 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
62 tcctest.ref: tcctest.c
63 $(CC) $(CFLAGS) -I. -o $@ $<
65 test.ref: tcctest.ref
66 ./tcctest.ref > $@
68 test.out: tcc tcctest.c
69 $(TCC) -run tcctest.c > $@
71 run: tcc tcctest.c
72 $(TCC) -run tcctest.c
74 # iterated test2 (compile tcc then compile tcctest.c !)
75 test2: tcc tcc.c tcctest.c test.ref
76 $(TCC) -run tcc.c -B. -I. -run tcctest.c > test.out2
77 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
79 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
80 test3: tcc tcc.c tcctest.c test.ref
81 $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3
82 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
84 # binary output test
85 test4: tcc test.ref
86 # dynamic output
87 $(TCC) -o tcctest1 tcctest.c
88 ./tcctest1 > test1.out
89 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
90 # static output
91 $(TCC) -static -o tcctest2 tcctest.c
92 ./tcctest2 > test2.out
93 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
94 # object + link output
95 $(TCC) -c -o tcctest3.o tcctest.c
96 $(TCC) -o tcctest3 tcctest3.o
97 ./tcctest3 > test3.out
98 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
99 # dynamic output + bound check
100 $(TCC) -b -o tcctest4 tcctest.c
101 ./tcctest4 > test4.out
102 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
104 # memory and bound check auto test
105 BOUNDS_OK = 1 4 8 10
106 BOUNDS_FAIL= 2 5 7 9 11 12 13
108 btest: boundtest.c tcc
109 @for i in $(BOUNDS_OK); do \
110 if $(TCC) -b -run boundtest.c $$i ; then \
111 /bin/true ; \
112 else\
113 echo Failed positive test $$i ; exit 1 ; \
114 fi ;\
115 done ;\
116 for i in $(BOUNDS_FAIL); do \
117 if $(TCC) -b -run boundtest.c $$i ; then \
118 echo Failed negative test $$i ; exit 1 ;\
119 else\
120 /bin/true ; \
122 done ;\
123 echo Bound test OK
125 # speed test
126 speed: tcc ex2 ex3
127 time ./ex2 1238 2 3 4 10 13 4
128 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
129 time ./ex3 35
130 time ./tcc -I. ./ex3.c 35
132 ex2: ex2.c
133 $(CC) $(CFLAGS) -o $@ $<
135 ex3: ex3.c
136 $(CC) $(CFLAGS) -o $@ $<
138 # Host Tiny C Compiler
139 ifdef CONFIG_WIN32
140 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
141 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
142 else
143 ifeq ($(ARCH),i386)
144 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
145 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
146 endif
147 ifeq ($(ARCH),arm)
148 tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
149 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
150 endif
151 endif
153 # Cross Tiny C Compilers
154 i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
155 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
157 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
158 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
160 arm-tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
161 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
163 i386-win32-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
164 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
166 # windows utilities
167 tiny_impdef$(EXESUF): tiny_impdef.c
168 $(CC) $(CFLAGS) -o $@ $< -lkernel32
170 # TinyCC runtime libraries
171 ifdef CONFIG_WIN32
172 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
173 else
174 LIBTCC1_OBJS=libtcc1.o
175 endif
177 %.o: %.c
178 $(CC) -O2 -Wall -c -o $@ $<
180 %.o: %.S
181 $(CC) -c -o $@ $<
183 libtcc1$(LIBSUF): $(LIBTCC1_OBJS)
184 $(AR) rcs $@ $^
186 bcheck.o: bcheck.c
187 $(CC) -O2 -Wall -c -o $@ $<
189 install: tcc_install libinstall
191 tcc_install: $(PROGS) tcc.1 libtcc1$(LIBSUF) $(BCHECK_O) tcc-doc.html tcc.1
192 mkdir -p "$(bindir)"
193 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
194 ifndef CONFIG_WIN32
195 mkdir -p "$(mandir)/man1"
196 $(INSTALL) tcc.1 "$(mandir)/man1"
197 endif
198 mkdir -p "$(tccdir)"
199 mkdir -p "$(tccdir)/include"
200 ifdef CONFIG_WIN32
201 mkdir -p "$(tccdir)/lib"
202 $(INSTALL) -m644 libtcc1$(LIBSUF) win32/lib/*.def "$(tccdir)/lib"
203 cp -r win32/include "$(tccdir)/include"
204 cp -r win32/examples "$(tccdir)/examples"
205 else
206 $(INSTALL) -m644 libtcc1$(LIBSUF) $(BCHECK_O) "$(tccdir)"
207 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
208 tcclib.h "$(tccdir)/include"
209 endif
210 mkdir -p "$(docdir)"
211 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
212 ifdef CONFIG_WIN32
213 $(INSTALL) -m644 win32/readme.txt "$(docdir)"
214 endif
216 clean:
217 rm -f *~ *.o *.a tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
218 core gmon.out test.out test.ref a.out tcc_p \
219 *.exe *.lib tcc.pod libtcc$(LIBSUF) libtcc_test \
220 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
222 distclean: clean
223 rm -f config.h config.mak config.texi
225 # profiling version
226 tcc_p: tcc.c Makefile
227 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
229 # libtcc generation and example
230 libinstall: libtcc$(LIBSUF)
231 mkdir -p "$(libdir)"
232 $(INSTALL) -m644 libtcc$(LIBSUF) "$(libdir)"
233 mkdir -p "$(includedir)"
234 $(INSTALL) -m644 libtcc.h "$(includedir)"
236 libtcc.o: tcc.c i386-gen.c Makefile
237 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
239 libtcc$(LIBSUF): libtcc.o
240 $(AR) rcs $@ $^
242 libtcc_test$(EXESUF): libtcc_test.c libtcc$(LIBSUF)
243 $(CC) $(CFLAGS) -o $@ $< libtcc$(LIBSUF) $(LIBS)
245 libtest: libtcc_test
246 ./libtcc_test
248 # targets for development
250 %.bin: %.c tcc
251 $(TCC) -g -o $@ $<
252 $(DISAS) $@
254 instr: instr.o
255 objdump -d instr.o
257 # tiny assembler testing
259 asmtest.ref: asmtest.S
260 $(CC) -c -o asmtest.ref.o asmtest.S
261 objdump -D asmtest.ref.o > $@
263 # XXX: we compute tcc.c to go faster during development !
264 asmtest.out: asmtest.S tcc
265 # ./tcc tcc.c -c asmtest.S
266 #asmtest.out: asmtest.S tcc
267 ./tcc -c asmtest.S
268 objdump -D asmtest.o > $@
270 asmtest: asmtest.out asmtest.ref
271 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
273 instr.o: instr.S
274 $(CC) -O2 -Wall -g -c -o $@ $<
276 cache: tcc_g
277 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
278 vg_annotate tcc.c > /tmp/linpack.cache.log
280 # documentation and man page
281 tcc-doc.html: tcc-doc.texi
282 texi2html -monolithic -number $<
284 tcc.1: tcc-doc.texi
285 ./texi2pod.pl $< tcc.pod
286 pod2man --section=1 --center=" " --release=" " tcc.pod > $@
288 FILE=tcc-$(shell cat VERSION)
290 # tar release (use 'make -k tar' on a checkouted tree)
291 tar:
292 rm -rf /tmp/$(FILE)
293 cp -r . /tmp/$(FILE)
294 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
295 rm -rf /tmp/$(FILE)