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