Import 409,410: ARM EABI by Daniel Glöckner
[tinycc.git] / Makefile
blob65f9fd942aebd7a902e4ccbf1aecdfdee25223b6
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 -DTCC_ARM_EABI -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
179 ifeq ($(ARCH),i386)
180 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
181 endif
183 %.o: %.c
184 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
186 %.o: %.S
187 $(LIBTCC1_CC) -c -o $@ $<
189 libtcc1.a: $(LIBTCC1_OBJS)
190 $(AR) rcs $@ $^
192 bcheck.o: bcheck.c
193 $(CC) -O2 -Wall -c -o $@ $<
195 install: tcc_install libinstall
197 tcc_install: $(PROGS) tcc.1 libtcc1.a $(BCHECK_O) tcc-doc.html
198 mkdir -p "$(bindir)"
199 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
200 ifndef CONFIG_WIN32
201 mkdir -p "$(mandir)/man1"
202 $(INSTALL) tcc.1 "$(mandir)/man1"
203 endif
204 mkdir -p "$(tccdir)"
205 mkdir -p "$(tccdir)/include"
206 ifdef CONFIG_WIN32
207 mkdir -p "$(tccdir)/lib"
208 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(tccdir)/lib"
209 cp -r win32/include/. "$(tccdir)/include"
210 cp -r win32/examples/. "$(tccdir)/examples"
211 else
212 $(INSTALL) -m644 libtcc1.a $(BCHECK_O) "$(tccdir)"
213 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
214 tcclib.h "$(tccdir)/include"
215 endif
216 mkdir -p "$(docdir)"
217 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
218 ifdef CONFIG_WIN32
219 $(INSTALL) -m644 win32/readme.txt "$(docdir)"
220 endif
222 clean:
223 rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
224 core gmon.out test.out test.ref a.out tcc_p \
225 *.exe *.lib tcc.pod libtcc_test \
226 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
228 distclean: clean
229 rm -f config.h config.mak config.texi
231 # profiling version
232 tcc_p: tcc.c Makefile
233 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
235 # libtcc generation and example
236 libinstall: libtcc.a
237 mkdir -p "$(libdir)"
238 $(INSTALL) -m644 libtcc.a "$(libdir)"
239 mkdir -p "$(includedir)"
240 $(INSTALL) -m644 libtcc.h "$(includedir)"
242 libtcc.o: tcc.c i386-gen.c Makefile
243 ifdef CONFIG_WIN32
244 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
245 else
246 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
247 endif
249 libtcc.a: libtcc.o
250 $(AR) rcs $@ $^
252 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
253 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
255 libtest: libtcc_test
256 ./libtcc_test
258 # targets for development
260 %.bin: %.c tcc
261 $(TCC) -g -o $@ $<
262 $(DISAS) $@
264 instr: instr.o
265 objdump -d instr.o
267 # tiny assembler testing
269 asmtest.ref: asmtest.S
270 $(CC) -c -o asmtest.ref.o asmtest.S
271 objdump -D asmtest.ref.o > $@
273 # XXX: we compute tcc.c to go faster during development !
274 asmtest.out: asmtest.S tcc
275 # ./tcc tcc.c -c asmtest.S
276 #asmtest.out: asmtest.S tcc
277 ./tcc -c asmtest.S
278 objdump -D asmtest.o > $@
280 asmtest: asmtest.out asmtest.ref
281 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
283 instr.o: instr.S
284 $(CC) -O2 -Wall -g -c -o $@ $<
286 cache: tcc_g
287 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
288 vg_annotate tcc.c > /tmp/linpack.cache.log
290 # documentation and man page
291 tcc-doc.html: tcc-doc.texi
292 -texi2html -monolithic -number $<
294 tcc.1: tcc-doc.texi
295 -./texi2pod.pl $< tcc.pod
296 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
298 FILE=tcc-$(shell cat VERSION)
300 # tar release (use 'make -k tar' on a checkouted tree)
301 tar:
302 rm -rf /tmp/$(FILE)
303 cp -r . /tmp/$(FILE)
304 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
305 rm -rf /tmp/$(FILE)