correct libtcc1 link order
[tinycc/miki.git] / Makefile
blob6966af66f38101020a426f4ffa9c0d9737c9e5aa
2 # Tiny C Compiler Makefile
4 include config.mak
6 CFLAGS=-O2 -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
19 endif
21 DISAS=objdump -d
22 INSTALL=install
23 PROGS=tcc$(EXESUF) c67-tcc$(EXESUF) arm-tcc$(EXESUF)
24 # run local version of tcc with local libraries and includes
25 TCC=./tcc -B. -I.
27 all: $(PROGS) \
28 libtcc1$(LIBSUF) $(BCHECK_O) tcc-doc.html tcc.1 libtcc$(LIBSUF) \
29 libtcc_test$(EXESUF)
31 Makefile: config.mak
33 # auto test
35 test: test.ref test.out
36 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
38 tcctest.ref: tcctest.c
39 $(CC) $(CFLAGS) -I. -o $@ $<
41 test.ref: tcctest.ref
42 ./tcctest.ref > $@
44 test.out: tcc tcctest.c
45 $(TCC) -run tcctest.c > $@
47 run: tcc tcctest.c
48 $(TCC) -run tcctest.c
50 # iterated test2 (compile tcc then compile tcctest.c !)
51 test2: tcc tcc.c tcctest.c test.ref
52 $(TCC) -run tcc.c -B. -I. -run tcctest.c > test.out2
53 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
55 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
56 test3: tcc tcc.c tcctest.c test.ref
57 $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3
58 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
60 # binary output test
61 test4: tcc test.ref
62 # dynamic output
63 $(TCC) -o tcctest1 tcctest.c
64 ./tcctest1 > test1.out
65 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
66 # static output
67 $(TCC) -static -o tcctest2 tcctest.c
68 ./tcctest2 > test2.out
69 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
70 # object + link output
71 $(TCC) -c -o tcctest3.o tcctest.c
72 $(TCC) -o tcctest3 tcctest3.o
73 ./tcctest3 > test3.out
74 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
75 # dynamic output + bound check
76 $(TCC) -b -o tcctest4 tcctest.c
77 ./tcctest4 > test4.out
78 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
80 # memory and bound check auto test
81 BOUNDS_OK = 1 4 8 10
82 BOUNDS_FAIL= 2 5 7 9 11 12 13
84 btest: boundtest.c tcc
85 @for i in $(BOUNDS_OK); do \
86 if $(TCC) -b -run boundtest.c $$i ; then \
87 /bin/true ; \
88 else\
89 echo Failed positive test $$i ; exit 1 ; \
90 fi ;\
91 done ;\
92 for i in $(BOUNDS_FAIL); do \
93 if $(TCC) -b -run boundtest.c $$i ; then \
94 echo Failed negative test $$i ; exit 1 ;\
95 else\
96 /bin/true ; \
97 fi\
98 done ;\
99 echo Bound test OK
101 # speed test
102 speed: tcc ex2 ex3
103 time ./ex2 1238 2 3 4 10 13 4
104 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
105 time ./ex3 35
106 time ./tcc -I. ./ex3.c 35
108 ex2: ex2.c
109 $(CC) $(CFLAGS) -o $@ $<
111 ex3: ex3.c
112 $(CC) $(CFLAGS) -o $@ $<
114 # Native Tiny C Compiler
116 tcc_g$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h Makefile
117 $(CC) $(CFLAGS) -o $@ $< $(LIBS)
119 tcc$(EXESUF): tcc_g$(EXESUF) Makefile
120 $(STRIP) -o $@ $<
122 c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c Makefile
123 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
125 arm-tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h Makefile
126 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
128 # TinyCC runtime libraries
129 libtcc1.o: libtcc1.c
130 $(CC) -O2 -Wall -c -o $@ $<
132 libtcc1$(LIBSUF): libtcc1.o
133 $(AR) rcs $@ $^
135 bcheck.o: bcheck.c
136 $(CC) -O2 -Wall -c -o $@ $<
138 install: tcc_install libinstall
140 tcc_install: $(PROGS) tcc.1 libtcc1$(LIBSUF) $(BCHECK_O) tcc-doc.html tcc.1
141 mkdir -p "$(bindir)"
142 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
143 ifndef CONFIG_WIN32
144 mkdir -p "$(mandir)/man1"
145 $(INSTALL) tcc.1 "$(mandir)/man1"
146 endif
147 mkdir -p "$(libdir)/tcc"
148 mkdir -p "$(libdir)/tcc/include"
149 $(INSTALL) -m644 libtcc1$(LIBSUF) $(BCHECK_O) "$(libdir)/tcc"
150 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
151 tcclib.h "$(libdir)/tcc/include"
152 mkdir -p "$(docdir)"
153 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
155 clean:
156 rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
157 core gmon.out test.out test.ref a.out tcc_p \
158 *.exe tcc-doc.html tcc.pod tcc.1 libtcc$(LIBSUF) libtcc_test \
159 tcctest[1234] test[1234].out c67-tcc arm-tcc
161 distclean: clean
162 rm -f config.h config.mak config.texi
164 # profiling version
165 tcc_p: tcc.c Makefile
166 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
168 # libtcc generation and example
169 libinstall: libtcc$(LIBSUF)
170 mkdir -p "$(libdir)"
171 $(INSTALL) -m644 libtcc$(LIBSUF) "$(libdir)"
172 mkdir -p "$(includedir)"
173 $(INSTALL) -m644 libtcc.h "$(includedir)"
175 libtcc.o: tcc.c i386-gen.c Makefile
176 $(CC) $(CFLAGS) -DLIBTCC -c -o $@ $<
178 libtcc$(LIBSUF): libtcc.o
179 $(AR) rcs $@ $^
181 libtcc_test$(EXESUF): libtcc_test.c libtcc$(LIBSUF)
182 $(CC) $(CFLAGS) -o $@ $< libtcc$(LIBSUF) $(LIBS)
184 libtest: libtcc_test
185 ./libtcc_test
187 # targets for development
189 %.bin: %.c tcc
190 $(TCC) -g -o $@ $<
191 $(DISAS) $@
193 instr: instr.o
194 objdump -d instr.o
196 # tiny assembler testing
198 asmtest.ref: asmtest.S
199 $(CC) -c -o asmtest.ref.o asmtest.S
200 objdump -D asmtest.ref.o > $@
202 # XXX: we compute tcc.c to go faster during development !
203 asmtest.out: asmtest.S tcc
204 # ./tcc tcc.c -c asmtest.S
205 #asmtest.out: asmtest.S tcc
206 ./tcc -c asmtest.S
207 objdump -D asmtest.o > $@
209 asmtest: asmtest.out asmtest.ref
210 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
212 instr.o: instr.S
213 $(CC) -O2 -Wall -g -c -o $@ $<
215 cache: tcc_g
216 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
217 vg_annotate tcc.c > /tmp/linpack.cache.log
219 # documentation and man page
220 tcc-doc.html: tcc-doc.texi
221 texi2html -monolithic -number $<
223 tcc.1: tcc-doc.texi
224 ./texi2pod.pl $< tcc.pod
225 pod2man --section=1 --center=" " --release=" " tcc.pod > $@
227 FILES= Makefile Makefile.uClibc configure VERSION \
228 README TODO COPYING \
229 Changelog tcc-doc.texi tcc-doc.html \
230 tcc.1 \
231 tcc.c tccelf.c tcctok.h tccasm.c i386-asm.c i386-asm.h \
232 tcccoff.c coff.h \
233 i386-gen.c c67-gen.c arm-gen.c \
234 bcheck.c libtcc1.c \
235 elf.h stab.h stab.def \
236 stddef.h stdarg.h stdbool.h float.h varargs.h \
237 tcclib.h libtcc.h libtcc_test.c \
238 ex1.c ex2.c ex3.c ex4.c ex5.c \
239 tcctest.c boundtest.c gcctestsuite.sh texi2pod.pl
241 FILE=tcc-$(VERSION)
243 tar:
244 rm -rf /tmp/$(FILE)
245 mkdir -p /tmp/$(FILE)
246 cp -P $(FILES) /tmp/$(FILE)
247 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) )
248 rm -rf /tmp/$(FILE)