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