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