Disable singnedness warnings with newer gcc.
[tinycc.git] / Makefile
blobeda0889a9b2886bdc3354d2625fe4cd1ba0a96f5
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 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
20 endif
22 DISAS=objdump -d
23 INSTALL=install
25 ifdef CONFIG_WIN32
26 PROGS=tcc$(EXESUF)
27 ifdef CONFIG_CROSS
28 PROGS+=c67-tcc$(EXESUF) arm-tcc$(EXESUF)
29 endif
30 PROGS+=tiny_impdef$(EXESUF)
31 else
32 ifeq ($(ARCH),i386)
33 PROGS=tcc$(EXESUF)
34 ifdef CONFIG_CROSS
35 PROGS+=arm-tcc$(EXESUF)
36 endif
37 endif
38 ifeq ($(ARCH),arm)
39 PROGS=tcc$(EXESUF)
40 ifdef CONFIG_CROSS
41 PROGS+=i386-tcc$(EXESUF)
42 endif
43 endif
44 ifdef CONFIG_CROSS
45 PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
46 endif
47 endif
49 # run local version of tcc with local libraries and includes
50 TCC=./tcc -B. -I.
52 all: $(PROGS) \
53 libtcc1.a $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
54 libtcc_test$(EXESUF)
56 Makefile: config.mak
58 # auto test
60 test: test.ref test.out
61 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
63 tcctest.ref: tcctest.c
64 $(CC) $(CFLAGS) -I. -o $@ $<
66 test.ref: tcctest.ref
67 ./tcctest.ref > $@
69 test.out: tcc tcctest.c
70 $(TCC) -run tcctest.c > $@
72 run: tcc tcctest.c
73 $(TCC) -run tcctest.c
75 # iterated test2 (compile tcc then compile tcctest.c !)
76 test2: tcc tcc.c tcctest.c test.ref
77 $(TCC) -run tcc.c -B. -I. -run tcctest.c > test.out2
78 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
80 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
81 test3: tcc tcc.c tcctest.c test.ref
82 $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3
83 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
85 # binary output test
86 test4: tcc test.ref
87 # dynamic output
88 $(TCC) -o tcctest1 tcctest.c
89 ./tcctest1 > test1.out
90 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
91 # static output
92 $(TCC) -static -o tcctest2 tcctest.c
93 ./tcctest2 > test2.out
94 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
95 # object + link output
96 $(TCC) -c -o tcctest3.o tcctest.c
97 $(TCC) -o tcctest3 tcctest3.o
98 ./tcctest3 > test3.out
99 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
100 # dynamic output + bound check
101 $(TCC) -b -o tcctest4 tcctest.c
102 ./tcctest4 > test4.out
103 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
105 # memory and bound check auto test
106 BOUNDS_OK = 1 4 8 10
107 BOUNDS_FAIL= 2 5 7 9 11 12 13
109 btest: boundtest.c tcc
110 @for i in $(BOUNDS_OK); do \
111 if $(TCC) -b -run boundtest.c $$i ; then \
112 /bin/true ; \
113 else\
114 echo Failed positive test $$i ; exit 1 ; \
115 fi ;\
116 done ;\
117 for i in $(BOUNDS_FAIL); do \
118 if $(TCC) -b -run boundtest.c $$i ; then \
119 echo Failed negative test $$i ; exit 1 ;\
120 else\
121 /bin/true ; \
123 done ;\
124 echo Bound test OK
126 # speed test
127 speed: tcc ex2 ex3
128 time ./ex2 1238 2 3 4 10 13 4
129 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
130 time ./ex3 35
131 time ./tcc -I. ./ex3.c 35
133 ex2: ex2.c
134 $(CC) $(CFLAGS) -o $@ $<
136 ex3: ex3.c
137 $(CC) $(CFLAGS) -o $@ $<
139 # Host Tiny C Compiler
140 ifdef CONFIG_WIN32
141 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
142 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
143 else
144 ifeq ($(ARCH),i386)
145 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
146 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
147 endif
148 ifeq ($(ARCH),arm)
149 tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
150 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
151 endif
152 endif
154 # Cross Tiny C Compilers
155 i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
156 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
158 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
159 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
161 arm-tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
162 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
164 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
165 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
167 # windows utilities
168 tiny_impdef$(EXESUF): tiny_impdef.c
169 $(CC) $(CFLAGS) -o $@ $< -lkernel32
171 # TinyCC runtime libraries
172 ifdef CONFIG_WIN32
173 # for windows, we must use TCC because we generate ELF objects
174 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
175 LIBTCC1_CC=./tcc.exe -Bwin32
176 else
177 LIBTCC1_OBJS=libtcc1.o
178 LIBTCC1_CC=$(CC)
179 endif
180 ifeq ($(ARCH),i386)
181 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
182 endif
184 %.o: %.c
185 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
187 %.o: %.S
188 $(LIBTCC1_CC) -c -o $@ $<
190 libtcc1.a: $(LIBTCC1_OBJS)
191 $(AR) rcs $@ $^
193 bcheck.o: bcheck.c
194 $(CC) -O2 -Wall -c -o $@ $<
196 install: tcc_install libinstall
198 tcc_install: $(PROGS) tcc.1 libtcc1.a $(BCHECK_O) tcc-doc.html
199 mkdir -p "$(bindir)"
200 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
201 ifndef CONFIG_WIN32
202 mkdir -p "$(mandir)/man1"
203 $(INSTALL) tcc.1 "$(mandir)/man1"
204 endif
205 mkdir -p "$(tccdir)"
206 mkdir -p "$(tccdir)/include"
207 ifdef CONFIG_WIN32
208 mkdir -p "$(tccdir)/lib"
209 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(tccdir)/lib"
210 cp -r win32/include/. "$(tccdir)/include"
211 cp -r win32/examples/. "$(tccdir)/examples"
212 else
213 $(INSTALL) -m644 libtcc1.a $(BCHECK_O) "$(tccdir)"
214 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
215 tcclib.h "$(tccdir)/include"
216 endif
217 mkdir -p "$(docdir)"
218 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
219 ifdef CONFIG_WIN32
220 $(INSTALL) -m644 win32/readme.txt "$(docdir)"
221 endif
223 clean:
224 rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
225 core gmon.out test.out test.ref a.out tcc_p \
226 *.exe *.lib tcc.pod libtcc_test \
227 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
229 distclean: clean
230 rm -f config.h config.mak config.texi
232 # profiling version
233 tcc_p: tcc.c Makefile
234 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
236 # libtcc generation and example
237 libinstall: libtcc.a
238 mkdir -p "$(libdir)"
239 $(INSTALL) -m644 libtcc.a "$(libdir)"
240 mkdir -p "$(includedir)"
241 $(INSTALL) -m644 libtcc.h "$(includedir)"
243 libtcc.o: tcc.c i386-gen.c Makefile
244 ifdef CONFIG_WIN32
245 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
246 else
247 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
248 endif
250 libtcc.a: libtcc.o
251 $(AR) rcs $@ $^
253 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
254 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
256 libtest: libtcc_test
257 ./libtcc_test
259 # targets for development
261 %.bin: %.c tcc
262 $(TCC) -g -o $@ $<
263 $(DISAS) $@
265 instr: instr.o
266 objdump -d instr.o
268 # tiny assembler testing
270 asmtest.ref: asmtest.S
271 $(CC) -c -o asmtest.ref.o asmtest.S
272 objdump -D asmtest.ref.o > $@
274 # XXX: we compute tcc.c to go faster during development !
275 asmtest.out: asmtest.S tcc
276 # ./tcc tcc.c -c asmtest.S
277 #asmtest.out: asmtest.S tcc
278 ./tcc -c asmtest.S
279 objdump -D asmtest.o > $@
281 asmtest: asmtest.out asmtest.ref
282 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
284 instr.o: instr.S
285 $(CC) -O2 -Wall -g -c -o $@ $<
287 cache: tcc_g
288 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
289 vg_annotate tcc.c > /tmp/linpack.cache.log
291 # documentation and man page
292 tcc-doc.html: tcc-doc.texi
293 -texi2html -monolithic -number $<
295 tcc.1: tcc-doc.texi
296 -./texi2pod.pl $< tcc.pod
297 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
299 FILE=tcc-$(shell cat VERSION)
301 # tar release (use 'make -k tar' on a checkouted tree)
302 tar:
303 rm -rf /tmp/$(FILE)
304 cp -r . /tmp/$(FILE)
305 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
306 rm -rf /tmp/$(FILE)