added support for standalone operation
[tinycc.git] / Makefile
blob3e9a008c8fb280463d8c2e09123e38a9284acb8a
2 # Tiny C Compiler Makefile
4 prefix=/usr/local
6 CFLAGS=-O2 -g -Wall
7 LIBS=-ldl
8 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
9 LIBS_P=
11 CFLAGS+=-m386 -malign-functions=0
12 CFLAGS+=-DCONFIG_TCC_PREFIX=\"$(prefix)\"
13 DISAS=objdump -d
14 INSTALL=install
15 VERSION=0.9.8
17 # run local version of tcc with local libraries and includes
18 TCC=./tcc -B. -I.
20 all: tcc libtcc1.o bcheck.o tcc-doc.html
22 # auto test
24 test: test.ref test.out
25 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
27 tcctest.ref: tcctest.c
28 gcc $(CFLAGS) -I. -o $@ $<
30 test.ref: tcctest.ref
31 ./tcctest.ref > $@
33 test.out: tcc tcctest.c
34 $(TCC) tcctest.c > $@
36 run: tcc tcctest.c
37 $(TCC) tcctest.c
39 # iterated test2 (compile tcc then compile tcctest.c !)
40 test2: tcc tcc.c tcctest.c test.ref
41 $(TCC) tcc.c -B. -I. tcctest.c > test.out2
42 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
44 # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
45 test3: tcc tcc.c tcctest.c test.ref
46 $(TCC) tcc.c -B. -I. tcc.c -B. -I. tcctest.c > test.out3
47 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
49 # memory and bound check auto test
50 BOUNDS_OK = 1 4 8 10
51 BOUNDS_FAIL= 2 5 7 9 11 12 13
53 btest: boundtest.c tcc
54 @for i in $(BOUNDS_OK); do \
55 if $(TCC) -b boundtest.c $$i ; then \
56 /bin/true ; \
57 else\
58 echo Failed positive test $$i ; exit 1 ; \
59 fi ;\
60 done ;\
61 for i in $(BOUNDS_FAIL); do \
62 if $(TCC) -b boundtest.c $$i ; then \
63 echo Failed negative test $$i ; exit 1 ;\
64 else\
65 /bin/true ; \
66 fi\
67 done ;\
68 echo Bound test OK
70 # speed test
71 speed: tcc ex2 ex3
72 time ./ex2 1238 2 3 4 10 13 4
73 time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
74 time ./ex3 35
75 time ./tcc -I. ./ex3.c 35
77 ex2: ex2.c
78 gcc $(CFLAGS) -o $@ $<
80 ex3: ex3.c
81 gcc $(CFLAGS) -o $@ $<
83 # Native Tiny C Compiler
85 tcc_g: tcc.c i386-gen.c bcheck.c tcctok.h libtcc.h Makefile
86 gcc $(CFLAGS) -o $@ $< $(LIBS)
88 tcc: tcc_g
89 strip -s -R .comment -R .note -o $@ $<
91 # TinyCC runtime libraries
92 libtcc1.o: libtcc1.c
93 gcc -O2 -Wall -c -o $@ $<
95 bcheck.o: bcheck.c
96 gcc -O2 -Wall -c -o $@ $<
98 install: tcc libtcc1.o bcheck.o
99 $(INSTALL) -m755 tcc $(prefix)/bin
100 $(INSTALL) tcc.1 $(prefix)/man/man1
101 mkdir -p $(prefix)/lib/tcc
102 mkdir -p $(prefix)/lib/tcc/include
103 $(INSTALL) -m644 libtcc1.o bcheck.o $(prefix)/lib/tcc
104 $(INSTALL) -m644 stdarg.h stddef.h float.h stdbool.h \
105 tcclib.h $(prefix)/lib/tcc/include
107 clean:
108 rm -f *~ *.o tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \
109 core gmon.out test.out test.ref a.out tcc_p \
110 *.exe iltcc iltcc_g
112 # IL TCC
114 iltcc_g: tcc.c il-gen.c bcheck.c Makefile
115 gcc $(CFLAGS) -DTCC_TARGET_IL -o $@ $< $(LIBS)
117 iltcc: iltcc_g
118 strip -s -R .comment -R .note -o $@ $<
120 # win32 TCC
121 tcc_g.exe: tcc.c i386-gen.c bcheck.c Makefile
122 i386-mingw32msvc-gcc $(CFLAGS) -DCONFIG_TCC_STATIC -o $@ $<
124 tcc.exe: tcc_g.exe
125 i386-mingw32msvc-strip -o $@ $<
127 # profiling version
128 tcc_p: tcc.c Makefile
129 gcc $(CFLAGS_P) -o $@ $< $(LIBS_P)
131 # libtcc generation and example
132 libinstall: libtcc.a
133 $(INSTALL) -m644 libtcc.a $(prefix)/lib
134 $(INSTALL) -m644 libtcc.h $(prefix)/include
136 libtcc.o: tcc.c i386-gen.c bcheck.c Makefile
137 gcc $(CFLAGS) -DLIBTCC -c -o $@ $<
139 libtcc.a: libtcc.o
140 ar rcs $@ $^
142 libtcc_test: libtcc_test.c libtcc.a
143 gcc $(CFLAGS) -I. -o $@ $< -L. -ltcc -ldl
145 # targets for development
147 %.bin: %.c tcc
148 $(TCC) -g -o $@ $<
149 $(DISAS) $@
151 instr: instr.o
152 objdump -d instr.o
154 instr.o: instr.S
155 gcc -O2 -Wall -g -c -o $@ $<
157 # documentation
158 tcc-doc.html: tcc-doc.texi
159 texi2html -monolithic -number $<
161 FILE=tcc-$(VERSION)
163 tar:
164 rm -rf /tmp/$(FILE)
165 cp -r ../tcc /tmp/$(FILE)
166 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz \
167 $(FILE)/Makefile $(FILE)/Makefile.uClibc \
168 $(FILE)/README $(FILE)/TODO $(FILE)/COPYING \
169 $(FILE)/Changelog $(FILE)/tcc-doc.texi $(FILE)/tcc-doc.html \
170 $(FILE)/tcc.1 \
171 $(FILE)/tcc.c $(FILE)/i386-gen.c $(FILE)/tcctok.h \
172 $(FILE)/bcheck.c $(FILE)/libtcc1.c \
173 $(FILE)/il-opcodes.h $(FILE)/il-gen.c \
174 $(FILE)/elf.h $(FILE)/stab.h $(FILE)/stab.def \
175 $(FILE)/stddef.h $(FILE)/stdarg.h $(FILE)/stdbool.h $(FILE)/float.h \
176 $(FILE)/tcclib.h $(FILE)/libtcc.h $(FILE)/libtcc_test.c \
177 $(FILE)/ex*.c $(FILE)/tcctest.c $(FILE)/boundtest.c )
178 rm -rf /tmp/$(FILE)