A prefix for default library/include search paths
[tinycc/k1w1.git] / Makefile
blob3ccebe35823ab3643562736c4f18c8d70767797c
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 ifneq ($(GCC_MAJOR),3)
23 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
24 endif
25 endif
27 DISAS=objdump -d
28 INSTALL=install
30 ifdef CONFIG_WIN32
31 PROGS=tcc$(EXESUF)
32 ifdef CONFIG_CROSS
33 PROGS+=c67-tcc$(EXESUF) arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
34 endif
35 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
36 else
37 ifeq ($(ARCH),i386)
38 PROGS=tcc$(EXESUF)
39 ifdef CONFIG_CROSS
40 PROGS+=arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
41 endif
42 endif
43 ifeq ($(ARCH),arm)
44 PROGS=tcc$(EXESUF)
45 ifdef CONFIG_CROSS
46 PROGS+=i386-tcc$(EXESUF)
47 endif
48 endif
49 ifdef CONFIG_CROSS
50 PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
51 endif
52 endif
54 # run local version of tcc with local libraries and includes
55 TCC=./tcc -B. -I.
57 all: $(PROGS) \
58 libtcc1.a $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
59 libtcc_test$(EXESUF)
61 Makefile: config.mak
63 # auto test
65 test: test.ref test.out
66 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
68 tcctest.ref: tcctest.c
69 $(CC) $(CFLAGS) -w -I. -o $@ $<
71 test.ref: tcctest.ref
72 ./tcctest.ref > $@
74 test.out: tcc tcctest.c
75 $(TCC) -run tcctest.c > $@
77 run: tcc tcctest.c
78 $(TCC) -run tcctest.c
80 # iterated test2 (compile tcc then compile tcctest.c !)
81 test2: tcc tcc.c tcctest.c test.ref
82 $(TCC) -run tcc.c -B. -I. -run tcctest.c > test.out2
83 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
85 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
86 test3: tcc tcc.c tcctest.c test.ref
87 $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3
88 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
90 # binary output test
91 test4: tcc test.ref
92 # dynamic output
93 $(TCC) -o tcctest1 tcctest.c
94 ./tcctest1 > test1.out
95 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
96 # static output
97 $(TCC) -static -o tcctest2 tcctest.c
98 ./tcctest2 > test2.out
99 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
100 # object + link output
101 $(TCC) -c -o tcctest3.o tcctest.c
102 $(TCC) -o tcctest3 tcctest3.o
103 ./tcctest3 > test3.out
104 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
105 # dynamic output + bound check
106 $(TCC) -b -o tcctest4 tcctest.c
107 ./tcctest4 > test4.out
108 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
110 # memory and bound check auto test
111 BOUNDS_OK = 1 4 8 10
112 BOUNDS_FAIL= 2 5 7 9 11 12 13
114 btest: boundtest.c tcc
115 @for i in $(BOUNDS_OK); do \
116 if $(TCC) -b -run boundtest.c $$i ; then \
117 /bin/true ; \
118 else\
119 echo Failed positive test $$i ; exit 1 ; \
120 fi ;\
121 done ;\
122 for i in $(BOUNDS_FAIL); do \
123 if $(TCC) -b -run boundtest.c $$i ; then \
124 echo Failed negative test $$i ; exit 1 ;\
125 else\
126 /bin/true ; \
128 done ;\
129 echo Bound test OK
131 # speed test
132 speed: tcc ex2 ex3
133 time ./ex2 1238 2 3 4 10 13 4
134 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
135 time ./ex3 35
136 time ./tcc -I. ./ex3.c 35
138 ex2: ex2.c
139 $(CC) $(CFLAGS) -o $@ $<
141 ex3: ex3.c
142 $(CC) $(CFLAGS) -o $@ $<
144 # Host Tiny C Compiler
145 ifdef CONFIG_WIN32
146 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
147 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
148 else
149 ifeq ($(ARCH),i386)
150 tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
151 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
152 endif
153 ifeq ($(ARCH),arm)
154 ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
155 ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
157 tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
158 $(CC) $(CFLAGS) -DTCC_TARGET_ARM $(ARMFLAGS) -o $@ $< $(LIBS)
159 endif
160 endif
162 # Cross Tiny C Compilers
163 i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
164 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
166 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
167 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
169 arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
170 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
172 arm-tcc-fpa-ld$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
173 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -o $@ $< $(LIBS)
175 arm-tcc-vfp$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
176 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_VFP -o $@ $< $(LIBS)
178 arm-tcc-vfp-eabi$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
179 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
181 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
182 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
184 # windows utilities
185 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
186 $(CC) $(CFLAGS) -o $@ $< -lkernel32
187 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
188 $(CC) $(CFLAGS) -o $@ $< -lkernel32
190 # TinyCC runtime libraries
191 ifdef CONFIG_WIN32
192 # for windows, we must use TCC because we generate ELF objects
193 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
194 LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
195 else
196 LIBTCC1_OBJS=libtcc1.o
197 LIBTCC1_CC=$(CC)
198 endif
199 ifeq ($(ARCH),i386)
200 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
201 endif
203 %.o: %.c
204 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
206 %.o: %.S
207 $(LIBTCC1_CC) -c -o $@ $<
209 libtcc1.a: $(LIBTCC1_OBJS)
210 $(AR) rcs $@ $^
212 bcheck.o: bcheck.c
213 $(CC) -O2 -Wall -c -o $@ $<
215 install: tcc_install libinstall
217 tcc_install: $(PROGS) tcc.1 libtcc1.a $(BCHECK_O) tcc-doc.html
218 mkdir -p "$(DESTDIR)$(bindir)"
219 $(INSTALL) -s -m755 $(PROGS) "$(DESTDIR)$(bindir)"
220 ifndef CONFIG_WIN32
221 mkdir -p "$(DESTDIR)$(mandir)/man1"
222 $(INSTALL) tcc.1 "$(DESTDIR)$(mandir)/man1"
223 endif
224 mkdir -p "$(DESTDIR)$(tccdir)"
225 mkdir -p "$(DESTDIR)$(tccdir)/include"
226 ifdef CONFIG_WIN32
227 mkdir -p "$(DESTDIR)$(tccdir)/lib"
228 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(DESTDIR)$(tccdir)/lib"
229 cp -r win32/include/. "$(DESTDIR)$(tccdir)/include"
230 cp -r win32/examples/. "$(DESTDIR)$(tccdir)/examples"
231 else
232 $(INSTALL) -m644 libtcc1.a $(BCHECK_O) "$(DESTDIR)$(tccdir)"
233 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
234 tcclib.h "$(DESTDIR)$(tccdir)/include"
235 endif
236 mkdir -p "$(DESTDIR)$(docdir)"
237 $(INSTALL) -m644 tcc-doc.html "$(DESTDIR)$(docdir)"
238 ifdef CONFIG_WIN32
239 $(INSTALL) -m644 win32/readme.txt "$(DESTDIR)$(docdir)"
240 endif
242 clean:
243 rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
244 core gmon.out test.out test.ref a.out tcc_p \
245 *.exe *.lib tcc.pod libtcc_test \
246 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
248 distclean: clean
249 rm -f config.h config.mak config.texi
251 # profiling version
252 tcc_p: tcc.c Makefile
253 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
255 # libtcc generation and example
256 libinstall: libtcc.a
257 mkdir -p "$(DESTDIR)$(libdir)"
258 $(INSTALL) -m644 libtcc.a "$(DESTDIR)$(libdir)"
259 mkdir -p "$(DESTDIR)$(includedir)"
260 $(INSTALL) -m644 libtcc.h "$(DESTDIR)$(includedir)"
262 libtcc.o: tcc.c i386-gen.c Makefile
263 ifdef CONFIG_WIN32
264 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
265 else
266 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
267 endif
269 libtcc.a: libtcc.o
270 $(AR) rcs $@ $^
272 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
273 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
275 libtest: libtcc_test
276 ./libtcc_test
278 # targets for development
280 %.bin: %.c tcc
281 $(TCC) -g -o $@ $<
282 $(DISAS) $@
284 instr: instr.o
285 objdump -d instr.o
287 # tiny assembler testing
289 asmtest.ref: asmtest.S
290 $(CC) -c -o asmtest.ref.o asmtest.S
291 objdump -D asmtest.ref.o > $@
293 # XXX: we compute tcc.c to go faster during development !
294 asmtest.out: asmtest.S tcc
295 # ./tcc tcc.c -c asmtest.S
296 #asmtest.out: asmtest.S tcc
297 ./tcc -c asmtest.S
298 objdump -D asmtest.o > $@
300 asmtest: asmtest.out asmtest.ref
301 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
303 instr.o: instr.S
304 $(CC) -O2 -Wall -g -c -o $@ $<
306 cache: tcc_g
307 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
308 vg_annotate tcc.c > /tmp/linpack.cache.log
310 # documentation and man page
311 tcc-doc.html: tcc-doc.texi
312 -texi2html -monolithic -number $<
314 tcc.1: tcc-doc.texi
315 -./texi2pod.pl $< tcc.pod
316 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
318 FILE=tcc-$(shell cat VERSION)
320 # tar release (use 'make -k tar' on a checkouted tree)
321 tar:
322 rm -rf /tmp/$(FILE)
323 cp -r . /tmp/$(FILE)
324 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
325 rm -rf /tmp/$(FILE)