avoid jumping into statement expression
[tinycc.git] / Makefile
blobf67f49a658d4d69ead7fbc1fdc4ac4a980040fed
2 # Tiny C Compiler Makefile
4 include config.mak
6 CFLAGS+=-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.a $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
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 # for windows, we must use TCC because we generate ELF objects
173 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
174 LIBTCC1_CC=./tcc.exe -Bwin32
175 else
176 LIBTCC1_OBJS=libtcc1.o
177 LIBTCC1_CC=$(CC)
178 endif
180 %.o: %.c
181 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
183 %.o: %.S
184 $(LIBTCC1_CC) -c -o $@ $<
186 libtcc1.a: $(LIBTCC1_OBJS)
187 $(AR) rcs $@ $^
189 bcheck.o: bcheck.c
190 $(CC) -O2 -Wall -c -o $@ $<
192 install: tcc_install libinstall
194 tcc_install: $(PROGS) tcc.1 libtcc1.a $(BCHECK_O) tcc-doc.html tcc.1
195 mkdir -p "$(bindir)"
196 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
197 ifndef CONFIG_WIN32
198 mkdir -p "$(mandir)/man1"
199 $(INSTALL) tcc.1 "$(mandir)/man1"
200 endif
201 mkdir -p "$(tccdir)"
202 mkdir -p "$(tccdir)/include"
203 ifdef CONFIG_WIN32
204 mkdir -p "$(tccdir)/lib"
205 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(tccdir)/lib"
206 cp -r win32/include/. "$(tccdir)/include"
207 cp -r win32/examples/. "$(tccdir)/examples"
208 else
209 $(INSTALL) -m644 libtcc1.a $(BCHECK_O) "$(tccdir)"
210 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
211 tcclib.h "$(tccdir)/include"
212 endif
213 mkdir -p "$(docdir)"
214 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
215 ifdef CONFIG_WIN32
216 $(INSTALL) -m644 win32/readme.txt "$(docdir)"
217 endif
219 clean:
220 rm -f *~ *.o *.a tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
221 core gmon.out test.out test.ref a.out tcc_p \
222 *.exe *.lib tcc.pod libtcc_test \
223 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
225 distclean: clean
226 rm -f config.h config.mak config.texi
228 # profiling version
229 tcc_p: tcc.c Makefile
230 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
232 # libtcc generation and example
233 libinstall: libtcc.a
234 mkdir -p "$(libdir)"
235 $(INSTALL) -m644 libtcc.a "$(libdir)"
236 mkdir -p "$(includedir)"
237 $(INSTALL) -m644 libtcc.h "$(includedir)"
239 libtcc.o: tcc.c i386-gen.c Makefile
240 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
242 libtcc.a: libtcc.o
243 $(AR) rcs $@ $^
245 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
246 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
248 libtest: libtcc_test
249 ./libtcc_test
251 # targets for development
253 %.bin: %.c tcc
254 $(TCC) -g -o $@ $<
255 $(DISAS) $@
257 instr: instr.o
258 objdump -d instr.o
260 # tiny assembler testing
262 asmtest.ref: asmtest.S
263 $(CC) -c -o asmtest.ref.o asmtest.S
264 objdump -D asmtest.ref.o > $@
266 # XXX: we compute tcc.c to go faster during development !
267 asmtest.out: asmtest.S tcc
268 # ./tcc tcc.c -c asmtest.S
269 #asmtest.out: asmtest.S tcc
270 ./tcc -c asmtest.S
271 objdump -D asmtest.o > $@
273 asmtest: asmtest.out asmtest.ref
274 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
276 instr.o: instr.S
277 $(CC) -O2 -Wall -g -c -o $@ $<
279 cache: tcc_g
280 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
281 vg_annotate tcc.c > /tmp/linpack.cache.log
283 # documentation and man page
284 tcc-doc.html: tcc-doc.texi
285 texi2html -monolithic -number $<
287 tcc.1: tcc-doc.texi
288 ./texi2pod.pl $< tcc.pod
289 pod2man --section=1 --center=" " --release=" " tcc.pod > $@
291 FILE=tcc-$(shell cat VERSION)
293 # tar release (use 'make -k tar' on a checkouted tree)
294 tar:
295 rm -rf /tmp/$(FILE)
296 cp -r . /tmp/$(FILE)
297 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
298 rm -rf /tmp/$(FILE)