Futher changes to casts
[tinycc/k1w1.git] / Makefile
blob1e6adad8d498485972d4cb7076d0f05ae14d2324
2 # Tiny C Compiler Makefile
4 include config.mak
6 CFLAGS+=-g -Wall
7 ifndef CONFIG_WIN32
8 LIBS=-lm
9 ifndef CONFIG_NOLDL
10 LIBS+=-ldl
11 endif
12 BCHECK_O=bcheck.o
13 endif
14 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
15 LIBS_P=
17 CFLAGS+=-mpreferred-stack-boundary=2
18 ifeq ($(GCC_MAJOR),2)
19 CFLAGS+=-m386 -malign-functions=0
20 else
21 CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing
22 ifneq ($(GCC_MAJOR),3)
23 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
24 endif
25 endif
27 DISAS=objdump -d
28 INSTALL=install
30 ifdef CONFIG_WIN32
31 PROGS=tcc$(EXESUF)
32 ifdef CONFIG_CROSS
33 PROGS+=c67-tcc$(EXESUF) arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
34 endif
35 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
36 else
37 ifeq ($(ARCH),i386)
38 PROGS=tcc$(EXESUF)
39 ifdef CONFIG_CROSS
40 PROGS+=arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
41 endif
42 endif
43 ifeq ($(ARCH),arm)
44 PROGS=tcc$(EXESUF)
45 ifdef CONFIG_CROSS
46 PROGS+=i386-tcc$(EXESUF)
47 endif
48 endif
49 ifdef CONFIG_CROSS
50 PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
51 endif
52 endif
54 ifdef CONFIG_USE_LIBGCC
55 LIBTCC1=
56 else
57 LIBTCC1=libtcc1.a
58 endif
60 # run local version of tcc with local libraries and includes
61 TCC=./tcc -B. -I.
63 all: $(PROGS) \
64 $(LIBTCC1) $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
65 libtcc_test$(EXESUF)
67 Makefile: config.mak
69 # auto test
71 test: test.ref test.out
72 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
74 tcctest.ref: tcctest.c
75 $(CC) $(CFLAGS) -w -I. -o $@ $<
77 test.ref: tcctest.ref
78 ./tcctest.ref > $@
80 test.out: tcc tcctest.c
81 $(TCC) -run tcctest.c > $@
83 run: tcc tcctest.c
84 $(TCC) -run tcctest.c
86 # iterated test2 (compile tcc then compile tcctest.c !)
87 test2: tcc tcc.c tcctest.c test.ref
88 $(TCC) -run tcc.c -B. -I. -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 !)
92 test3: tcc tcc.c tcctest.c test.ref
93 $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3
94 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
96 # binary output test
97 test4: tcc test.ref
98 # dynamic output
99 $(TCC) -o tcctest1 tcctest.c
100 ./tcctest1 > test1.out
101 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
102 # static output
103 $(TCC) -static -o tcctest2 tcctest.c
104 ./tcctest2 > test2.out
105 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
106 # object + link output
107 $(TCC) -c -o tcctest3.o tcctest.c
108 $(TCC) -o tcctest3 tcctest3.o
109 ./tcctest3 > test3.out
110 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
111 # dynamic output + bound check
112 $(TCC) -b -o tcctest4 tcctest.c
113 ./tcctest4 > test4.out
114 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
116 # memory and bound check auto test
117 BOUNDS_OK = 1 4 8 10
118 BOUNDS_FAIL= 2 5 7 9 11 12 13
120 btest: boundtest.c tcc
121 @for i in $(BOUNDS_OK); do \
122 if $(TCC) -b -run boundtest.c $$i ; then \
123 /bin/true ; \
124 else\
125 echo Failed positive test $$i ; exit 1 ; \
126 fi ;\
127 done ;\
128 for i in $(BOUNDS_FAIL); do \
129 if $(TCC) -b -run boundtest.c $$i ; then \
130 echo Failed negative test $$i ; exit 1 ;\
131 else\
132 /bin/true ; \
134 done ;\
135 echo Bound test OK
137 # speed test
138 speed: tcc ex2 ex3
139 time ./ex2 1238 2 3 4 10 13 4
140 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
141 time ./ex3 35
142 time ./tcc -I. ./ex3.c 35
144 ex2: ex2.c
145 $(CC) $(CFLAGS) -o $@ $<
147 ex3: ex3.c
148 $(CC) $(CFLAGS) -o $@ $<
150 # Host Tiny C Compiler
151 ifdef CONFIG_WIN32
152 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
153 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
154 else
155 ifeq ($(ARCH),i386)
156 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
157 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
158 endif
159 ifeq ($(ARCH),arm)
160 ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
161 ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
163 tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
164 $(CC) $(CFLAGS) -DTCC_TARGET_ARM $(ARMFLAGS) -o $@ $< $(LIBS)
165 endif
166 endif
168 # Cross Tiny C Compilers
169 i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
170 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
172 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
173 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
175 arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
176 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
178 arm-tcc-fpa-ld$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
179 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -o $@ $< $(LIBS)
181 arm-tcc-vfp$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
182 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_VFP -o $@ $< $(LIBS)
184 arm-tcc-vfp-eabi$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
185 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
187 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
188 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
190 # windows utilities
191 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
192 $(CC) $(CFLAGS) -o $@ $< -lkernel32
193 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
194 $(CC) $(CFLAGS) -o $@ $< -lkernel32
196 # TinyCC runtime libraries
197 ifdef CONFIG_WIN32
198 # for windows, we must use TCC because we generate ELF objects
199 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
200 LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
201 else
202 LIBTCC1_OBJS=libtcc1.o
203 LIBTCC1_CC=$(CC)
204 endif
205 ifeq ($(ARCH),i386)
206 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
207 endif
209 %.o: %.c
210 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
212 %.o: %.S
213 $(LIBTCC1_CC) -c -o $@ $<
215 libtcc1.a: $(LIBTCC1_OBJS)
216 $(AR) rcs $@ $^
218 bcheck.o: bcheck.c
219 $(CC) -O2 -Wall -c -o $@ $<
221 install: tcc_install libinstall
223 tcc_install: $(PROGS) tcc.1 $(LIBTCC1) $(BCHECK_O) tcc-doc.html
224 mkdir -p "$(DESTDIR)$(bindir)"
225 $(INSTALL) -s -m755 $(PROGS) "$(DESTDIR)$(bindir)"
226 ifndef CONFIG_WIN32
227 mkdir -p "$(DESTDIR)$(mandir)/man1"
228 $(INSTALL) tcc.1 "$(DESTDIR)$(mandir)/man1"
229 endif
230 mkdir -p "$(DESTDIR)$(tccdir)"
231 mkdir -p "$(DESTDIR)$(tccdir)/include"
232 ifdef CONFIG_WIN32
233 mkdir -p "$(DESTDIR)$(tccdir)/lib"
234 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(DESTDIR)$(tccdir)/lib"
235 cp -r win32/include/. "$(DESTDIR)$(tccdir)/include"
236 cp -r win32/examples/. "$(DESTDIR)$(tccdir)/examples"
237 else
238 ifndef CONFIG_USE_LIBGCC
239 $(INSTALL) -m644 libtcc1.a "$(DESTDIR)$(tccdir)"
240 endif
241 $(INSTALL) -m644 $(BCHECK_O) "$(DESTDIR)$(tccdir)"
242 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
243 tcclib.h "$(DESTDIR)$(tccdir)/include"
244 endif
245 mkdir -p "$(DESTDIR)$(docdir)"
246 $(INSTALL) -m644 tcc-doc.html "$(DESTDIR)$(docdir)"
247 ifdef CONFIG_WIN32
248 $(INSTALL) -m644 win32/readme.txt "$(DESTDIR)$(docdir)"
249 endif
251 clean:
252 rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
253 core gmon.out test.out test.ref a.out tcc_p \
254 *.exe *.lib tcc.pod libtcc_test \
255 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
257 distclean: clean
258 rm -f config.h config.mak config.texi
260 # profiling version
261 tcc_p: tcc.c Makefile
262 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
264 # libtcc generation and example
265 libinstall: libtcc.a
266 mkdir -p "$(DESTDIR)$(libdir)"
267 $(INSTALL) -m644 libtcc.a "$(DESTDIR)$(libdir)"
268 mkdir -p "$(DESTDIR)$(includedir)"
269 $(INSTALL) -m644 libtcc.h "$(DESTDIR)$(includedir)"
271 libtcc.o: tcc.c i386-gen.c Makefile
272 ifdef CONFIG_WIN32
273 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
274 else
275 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
276 endif
278 libtcc.a: libtcc.o
279 $(AR) rcs $@ $^
281 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
282 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
284 libtest: libtcc_test
285 ./libtcc_test
287 # targets for development
289 %.bin: %.c tcc
290 $(TCC) -g -o $@ $<
291 $(DISAS) $@
293 instr: instr.o
294 objdump -d instr.o
296 # tiny assembler testing
298 asmtest.ref: asmtest.S
299 $(CC) -c -o asmtest.ref.o asmtest.S
300 objdump -D asmtest.ref.o > $@
302 # XXX: we compute tcc.c to go faster during development !
303 asmtest.out: asmtest.S tcc
304 # ./tcc tcc.c -c asmtest.S
305 #asmtest.out: asmtest.S tcc
306 ./tcc -c asmtest.S
307 objdump -D asmtest.o > $@
309 asmtest: asmtest.out asmtest.ref
310 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
312 instr.o: instr.S
313 $(CC) -O2 -Wall -g -c -o $@ $<
315 cache: tcc_g
316 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
317 vg_annotate tcc.c > /tmp/linpack.cache.log
319 # documentation and man page
320 tcc-doc.html: tcc-doc.texi
321 -texi2html -monolithic -number $<
323 tcc.1: tcc-doc.texi
324 -./texi2pod.pl $< tcc.pod
325 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
327 FILE=tcc-$(shell cat VERSION)
329 # tar release (use 'make -k tar' on a checkouted tree)
330 tar:
331 rm -rf /tmp/$(FILE)
332 cp -r . /tmp/$(FILE)
333 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
334 rm -rf /tmp/$(FILE)