Checkin tiny_libmaker (ar replacement) by Timovj Lahde
[tinycc.git] / Makefile
blobe0757b056e04cda9a5b1d98a591dca111400ef9b
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$(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$(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) -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 tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
155 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
156 endif
157 endif
159 # Cross Tiny C Compilers
160 i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
161 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
163 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
164 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
166 arm-tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
167 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
169 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
170 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
172 # windows utilities
173 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
174 $(CC) $(CFLAGS) -o $@ $< -lkernel32
175 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
176 $(CC) $(CFLAGS) -o $@ $< -lkernel32
178 # TinyCC runtime libraries
179 ifdef CONFIG_WIN32
180 # for windows, we must use TCC because we generate ELF objects
181 LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
182 LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
183 else
184 LIBTCC1_OBJS=libtcc1.o
185 LIBTCC1_CC=$(CC)
186 endif
187 ifeq ($(ARCH),i386)
188 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
189 endif
191 %.o: %.c
192 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
194 %.o: %.S
195 $(LIBTCC1_CC) -c -o $@ $<
197 libtcc1.a: $(LIBTCC1_OBJS)
198 $(AR) rcs $@ $^
200 bcheck.o: bcheck.c
201 $(CC) -O2 -Wall -c -o $@ $<
203 install: tcc_install libinstall
205 tcc_install: $(PROGS) tcc.1 libtcc1.a $(BCHECK_O) tcc-doc.html
206 mkdir -p "$(bindir)"
207 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
208 ifndef CONFIG_WIN32
209 mkdir -p "$(mandir)/man1"
210 $(INSTALL) tcc.1 "$(mandir)/man1"
211 endif
212 mkdir -p "$(tccdir)"
213 mkdir -p "$(tccdir)/include"
214 ifdef CONFIG_WIN32
215 mkdir -p "$(tccdir)/lib"
216 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(tccdir)/lib"
217 cp -r win32/include/. "$(tccdir)/include"
218 cp -r win32/examples/. "$(tccdir)/examples"
219 else
220 $(INSTALL) -m644 libtcc1.a $(BCHECK_O) "$(tccdir)"
221 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
222 tcclib.h "$(tccdir)/include"
223 endif
224 mkdir -p "$(docdir)"
225 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
226 ifdef CONFIG_WIN32
227 $(INSTALL) -m644 win32/readme.txt "$(docdir)"
228 endif
230 clean:
231 rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
232 core gmon.out test.out test.ref a.out tcc_p \
233 *.exe *.lib tcc.pod libtcc_test \
234 tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
236 distclean: clean
237 rm -f config.h config.mak config.texi
239 # profiling version
240 tcc_p: tcc.c Makefile
241 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
243 # libtcc generation and example
244 libinstall: libtcc.a
245 mkdir -p "$(libdir)"
246 $(INSTALL) -m644 libtcc.a "$(libdir)"
247 mkdir -p "$(includedir)"
248 $(INSTALL) -m644 libtcc.h "$(includedir)"
250 libtcc.o: tcc.c i386-gen.c Makefile
251 ifdef CONFIG_WIN32
252 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
253 else
254 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
255 endif
257 libtcc.a: libtcc.o
258 $(AR) rcs $@ $^
260 libtcc_test$(EXESUF): libtcc_test.c libtcc.a
261 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
263 libtest: libtcc_test
264 ./libtcc_test
266 # targets for development
268 %.bin: %.c tcc
269 $(TCC) -g -o $@ $<
270 $(DISAS) $@
272 instr: instr.o
273 objdump -d instr.o
275 # tiny assembler testing
277 asmtest.ref: asmtest.S
278 $(CC) -c -o asmtest.ref.o asmtest.S
279 objdump -D asmtest.ref.o > $@
281 # XXX: we compute tcc.c to go faster during development !
282 asmtest.out: asmtest.S tcc
283 # ./tcc tcc.c -c asmtest.S
284 #asmtest.out: asmtest.S tcc
285 ./tcc -c asmtest.S
286 objdump -D asmtest.o > $@
288 asmtest: asmtest.out asmtest.ref
289 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
291 instr.o: instr.S
292 $(CC) -O2 -Wall -g -c -o $@ $<
294 cache: tcc_g
295 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
296 vg_annotate tcc.c > /tmp/linpack.cache.log
298 # documentation and man page
299 tcc-doc.html: tcc-doc.texi
300 -texi2html -monolithic -number $<
302 tcc.1: tcc-doc.texi
303 -./texi2pod.pl $< tcc.pod
304 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
306 FILE=tcc-$(shell cat VERSION)
308 # tar release (use 'make -k tar' on a checkouted tree)
309 tar:
310 rm -rf /tmp/$(FILE)
311 cp -r . /tmp/$(FILE)
312 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
313 rm -rf /tmp/$(FILE)