History

fix makefiles etc for subdirs

grischka committed 17 years ago

Commit 58297911 parent ea5e81b13 files · +321 −280Browse files

Unified · Split

13 files
  1. Makefile +153 −254
  2. configure +1 −7
  3. examples/ex1.c +1 −1
  4. examples/ex2.c +6 −5
  5. examples/ex3.c +4 −3
  6. examples/ex4.c +4 −3
  7. examples/ex5.c +1 −1
  8. include/tcclib.h +1 −0
  9. lib/alloca86-bt.S +1 −1
  10. lib/alloca86.S +1 −1
  11. tests/Makefile +144 −0
  12. tests/tcctest.c +1 −1
  13. win32/build-tcc.bat +3 −3
Makefile+153−254
@@ -1,7 +1,9 @@
1#1#
2# Tiny C Compiler Makefile2# Tiny C Compiler Makefile
3#3#
4include config.mak4
5TOP ?= .
6include $(TOP)/config.mak
5 7
6TARGET=8TARGET=
7CFLAGS+=-g -Wall9CFLAGS+=-g -Wall
@@ -33,312 +35,195 @@ CFLAGS+=-m386 -malign-functions=0 · 25 unmodified lines
33else35else
34CFLAGS+=-march=i386 -falign-functions=036CFLAGS+=-march=i386 -falign-functions=0
35ifneq ($(GCC_MAJOR),3)37ifneq ($(GCC_MAJOR),3)
36CFLAGS+=-Wno-pointer-sign -Wno-sign-compare38CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
37endif39endif
38endif40endif
39endif41endif
40 42
41DISAS=objdump -d43ifeq ($(TOP),.)
42INSTALL=install
43 44
44ifdef CONFIG_WIN32
45PROGS=tcc$(EXESUF)45PROGS=tcc$(EXESUF)
46ifdef CONFIG_CROSS46
47PROGS+=c67-tcc$(EXESUF) arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)47ARM_CROSS = arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
48endif48I386_CROSS = i386-tcc$(EXESUF)
49WIN32_CROSS = i386-win32-tcc$(EXESUF)
50C67_CROSS = c67-tcc$(EXESUF)
51X64_CROSS = x86_64-tcc$(EXESUF)
52
53ifdef CONFIG_WIN32
49PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)54PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
50else55PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
51ifeq ($(ARCH),i386)56
52PROGS=tcc$(EXESUF)57else ifeq ($(ARCH),i386)
53ifdef CONFIG_CROSS58PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
54PROGS+=arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)59
55endif60else ifeq ($(ARCH),arm)
56endif61PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(C67_CROSS)
57ifeq ($(ARCH),arm)62
58PROGS=tcc$(EXESUF)63else ifeq ($(ARCH),x86-64)
59ifdef CONFIG_CROSS64PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
60PROGS+=i386-tcc$(EXESUF)
61endif
62endif65endif
66
63ifdef CONFIG_CROSS67ifdef CONFIG_CROSS
64PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)68PROGS+=$(PROGS_CROSS)
65endif
66endif
67ifeq ($(ARCH),x86-64)
68PROGS=tcc$(EXESUF)
69endif69endif
70 70
71ifdef CONFIG_USE_LIBGCC71ifndef CONFIG_USE_LIBGCC
72LIBTCC1=
73else
74LIBTCC1=libtcc1.a72LIBTCC1=libtcc1.a
75endif73endif
76 74
77# run local version of tcc with local libraries and includes75all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
78TCC=./tcc -B. -I.76
79 77TCC_CORE_FILES = tcc.c tccelf.c tccasm.c tcctok.h libtcc.h config.h
80all: $(PROGS) \
81 $(LIBTCC1) $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
82 libtcc_test$(EXESUF)
83
84Makefile: config.mak
85
86# auto test
87
88test: test.ref test.out
89 @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
90
91tcctest.ref: tcctest.c
92 $(CC) $(CFLAGS) -w -I. -o $@ $<
93
94test.ref: tcctest.ref
95 ./tcctest.ref > $@
96
97test.out: tcc tcctest.c
98 $(TCC) -run tcctest.c > $@
99
100run: tcc tcctest.c
101 $(TCC) -run tcctest.c
102
103# iterated test2 (compile tcc then compile tcctest.c !)
104test2: 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
107
108# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
109test3: 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
112
113# binary output test
114test4: 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
132
133# memory and bound check auto test
134BOUNDS_OK = 1 4 8 10
135BOUNDS_FAIL= 2 5 7 9 11 12 13
136
137btest: 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 ; \
150 fi\
151 done ;\
152 echo Bound test OK
153
154# speed test
155speed: 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
160
161ex2: ex2.c
162 $(CC) $(CFLAGS) -o $@ $<
163
164ex3: ex3.c
165 $(CC) $(CFLAGS) -o $@ $<
166 78
167# Host Tiny C Compiler79# Host Tiny C Compiler
168ifdef CONFIG_WIN3280ifdef CONFIG_WIN32
169tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c81tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
170 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)82 $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
171else83
172ifeq ($(ARCH),i386)84else ifeq ($(ARCH),i386)
173tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h85tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
174 $(CC) $(CFLAGS) -o $@ $< $(LIBS)86 $(CC) -o $@ $< $(CFLAGS) $(LIBS)
175endif87
176ifeq ($(ARCH),arm)88else ifeq ($(ARCH),x86-64)
89tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c
90 $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
91
92else ifeq ($(ARCH),arm)
177ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)93ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
178ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)94ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
179 95tcc$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
180tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h96 $(CC) -o $@ $< -DTCC_TARGET_ARM $(ARMFLAGS) $(CFLAGS) $(LIBS)
181 $(CC) $(CFLAGS) -DTCC_TARGET_ARM $(ARMFLAGS) -o $@ $< $(LIBS)
182endif
183ifeq ($(ARCH),x86-64)
184tcc$(EXESUF): tcc.c tccelf.c tccasm.c tcctok.h libtcc.h x86_64-gen.c
185 $(CC) $(CFLAGS) -DTCC_TARGET_X86_64 -o $@ $< $(LIBS)
186endif
187endif97endif
188 98
189# Cross Tiny C Compilers99# Cross Tiny C Compilers
190i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h100i386-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
191 $(CC) $(CFLAGS) -o $@ $< $(LIBS)101 $(CC) -o $@ $< $(CFLAGS) $(LIBS)
102
103i386-win32-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
104 $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
105
106x86_64-tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c i386-asm.c i386-asm.h
107 $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
192 108
193c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c109c67-tcc$(EXESUF): $(TCC_CORE_FILES) c67-gen.c tcccoff.c
194 $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)110 $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
195 111
196arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h112arm-tcc-fpa$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
197 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)113 $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
114
115arm-tcc-fpa-ld$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
116 $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
117
118arm-tcc-vfp$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
119 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
120
121arm-tcc-vfp-eabi$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
122 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
123
124# libtcc generation and test
125libtcc.o: tcc.c i386-gen.c
126ifdef CONFIG_WIN32
127 $(CC) -o $@ -c $< -DTCC_TARGET_PE -DLIBTCC $(CFLAGS)
128else
129 $(CC) -o $@ -c $< $(TARGET) -DLIBTCC $(CFLAGS)
130endif
198 131
199arm-tcc-fpa-ld$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h132libtcc.a: libtcc.o
200 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -o $@ $< $(LIBS)133 $(AR) rcs $@ $^
201 134
202arm-tcc-vfp$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h135libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
203 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_VFP -o $@ $< $(LIBS)136 $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
204 137
205arm-tcc-vfp-eabi$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h138libtest: libtcc_test$(EXESUF) $(LIBTCC1)
206 $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)139 ./libtcc_test$(EXESUF) lib_path=.
207 140
208i386-win32-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c141# profiling version
209 $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)142tcc_p: tcc.c
143 $(CC) -o $@ $< $(CFLAGS_P) $(LIBS_P)
210 144
211# windows utilities145# windows utilities
212tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c146tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
213 $(CC) $(CFLAGS) -o $@ $< -lkernel32147 $(CC) -o $@ $< $(CFLAGS)
214tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c148tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
215 $(CC) $(CFLAGS) -o $@ $< -lkernel32149 $(CC) -o $@ $< $(CFLAGS)
216 150
217# TinyCC runtime libraries151# TinyCC runtime libraries
152LIBTCC1_OBJS=libtcc1.o
153LIBTCC1_CC=$(CC)
154VPATH+=lib
218ifdef CONFIG_WIN32155ifdef CONFIG_WIN32
219# for windows, we must use TCC because we generate ELF objects156# for windows, we must use TCC because we generate ELF objects
220LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o157LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
221LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE158LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
222else159VPATH+=win32/lib
223LIBTCC1_OBJS=libtcc1.o
224LIBTCC1_CC=$(CC)
225endif160endif
226ifeq ($(ARCH),i386)161ifeq ($(ARCH),i386)
227LIBTCC1_OBJS+=alloca86.o alloca86-bt.o162LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
228endif163endif
229 164
230%.o: %.c165%.o: %.c
231 $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<166 $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
232 167
233%.o: %.S168%.o: %.S
234 $(LIBTCC1_CC) -c -o $@ $<169 $(LIBTCC1_CC) -o $@ -c $<
235 170
236libtcc1.a: $(LIBTCC1_OBJS)171libtcc1.a: $(LIBTCC1_OBJS)
237 $(AR) rcs $@ $^172 $(AR) rcs $@ $^
238 173
239bcheck.o: bcheck.c174bcheck.o: bcheck.c
240 $(CC) -O2 -Wall -c -o $@ $<175 $(CC) -o $@ -c $< -O2 -Wall
241 176
242install: tcc_install libinstall177# install
178TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
179INSTALL=install
243 180
244tcc_install: $(PROGS) tcc.1 $(LIBTCC1) $(BCHECK_O) tcc-doc.html
245 mkdir -p "$(DESTDIR)$(bindir)"
246 $(INSTALL) -s -m755 $(PROGS) "$(DESTDIR)$(bindir)"
247ifndef CONFIG_WIN32181ifndef CONFIG_WIN32
248 mkdir -p "$(DESTDIR)$(mandir)/man1"182install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
249 $(INSTALL) tcc.1 "$(DESTDIR)$(mandir)/man1"183 mkdir -p "$(bindir)"
184 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
185 mkdir -p "$(mandir)/man1"
186 $(INSTALL) tcc.1 "$(mandir)/man1"
187 mkdir -p "$(tccdir)"
188 mkdir -p "$(tccdir)/include"
189ifneq ($(LIBTCC1),)
190 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
250endif191endif
251 mkdir -p "$(DESTDIR)$(tccdir)"192ifneq ($(BCHECK_O),)
252 mkdir -p "$(DESTDIR)$(tccdir)/include"193 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
253ifdef 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"
258else
259ifndef CONFIG_USE_LIBGCC
260 $(INSTALL) -m644 libtcc1.a "$(DESTDIR)$(tccdir)"
261endif
262ifneq ($(ARCH),x86-64)
263 $(INSTALL) -m644 $(BCHECK_O) "$(DESTDIR)$(tccdir)"
264endif
265 $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
266 tcclib.h "$(DESTDIR)$(tccdir)/include"
267endif
268 mkdir -p "$(DESTDIR)$(docdir)"
269 $(INSTALL) -m644 tcc-doc.html "$(DESTDIR)$(docdir)"
270ifdef CONFIG_WIN32
271 $(INSTALL) -m644 win32/tcc-win32.txt "$(DESTDIR)$(docdir)"
272endif194endif
195 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
196 mkdir -p "$(docdir)"
197 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
198 mkdir -p "$(libdir)"
199 $(INSTALL) -m644 libtcc.a "$(libdir)"
200 mkdir -p "$(includedir)"
201 $(INSTALL) -m644 libtcc.h "$(includedir)"
202
203uninstall:
204 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
205 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
206 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
207 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
208 rm -fv "$(libdir)/libtcc.a" "$(includedir)/libtcc.h"
273 209
274clean:
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
279
280distclean: clean
281 rm -f config.h config.mak config.texi
282
283# profiling version
284tcc_p: tcc.c Makefile
285 $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
286
287# libtcc generation and example
288libinstall: 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)"
293
294libtcc.o: tcc.c i386-gen.c Makefile
295ifdef CONFIG_WIN32
296 $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
297else210else
298 $(CC) $(CFLAGS) $(TARGET) -DLIBTCC -c -o $@ $<211install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
212 mkdir -p "$(tccdir)"
213 mkdir -p "$(tccdir)/lib"
214 mkdir -p "$(tccdir)/include"
215 mkdir -p "$(tccdir)/examples"
216 mkdir -p "$(tccdir)/doc"
217 mkdir -p "$(tccdir)/libtcc"
218 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
219 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
220 cp -r win32/include/. "$(tccdir)/include"
221 cp -r win32/examples/. "$(tccdir)/examples"
222 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
223 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt"$(tccdir)/doc"
224 $(INSTALL) -m644 libtcc.a libtcc.h "$(tccdir)/libtcc"
299endif225endif
300 226
301libtcc.a: libtcc.o
302 $(AR) rcs $@ $^
303
304libtcc_test$(EXESUF): libtcc_test.c libtcc.a
305 $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
306
307libtest: libtcc_test
308 ./libtcc_test lib_path=.
309
310# targets for development
311
312%.bin: %.c tcc
313 $(TCC) -g -o $@ $<
314 $(DISAS) $@
315
316instr: instr.o
317 objdump -d instr.o
318
319# tiny assembler testing
320
321asmtest.ref: asmtest.S
322 $(CC) -c -o asmtest.ref.o asmtest.S
323 objdump -D asmtest.ref.o > $@
324
325# XXX: we compute tcc.c to go faster during development !
326asmtest.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 > $@
331
332asmtest: asmtest.out asmtest.ref
333 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
334
335instr.o: instr.S
336 $(CC) -O2 -Wall -g -c -o $@ $<
337
338cache: tcc_g
339 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
340 vg_annotate tcc.c > /tmp/linpack.cache.log
341
342# documentation and man page227# documentation and man page
343tcc-doc.html: tcc-doc.texi228tcc-doc.html: tcc-doc.texi
344 -texi2html -monolithic -number $<229 -texi2html -monolithic -number $<
@@ -347,11 +232,25 @@ tcc.1: tcc-doc.texi · 2 unmodified lines
347 -./texi2pod.pl $< tcc.pod232 -./texi2pod.pl $< tcc.pod
348 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@233 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
349 234
350FILE=tcc-$(shell cat VERSION)
351
352# tar release (use 'make -k tar' on a checkouted tree)235# tar release (use 'make -k tar' on a checkouted tree)
236TCC-VERSION=tcc-$(shell cat VERSION)
353tar:237tar:
354 rm -rf /tmp/$(FILE)238 rm -rf /tmp/$(TCC-VERSION)
355 cp -r . /tmp/$(FILE)239 cp -r . /tmp/$(TCC-VERSION)
356 ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )240 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
357 rm -rf /tmp/$(FILE)241 rm -rf /tmp/$(TCC-VERSION)
242
243# in tests subdir
244test clean :
245 $(MAKE) -C tests $@
246
247# clean
248clean: local_clean
249local_clean:
250 rm -vf $(PROGS) tcc_p tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
251
252distclean: clean
253 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.html
254
255endif
256# ifeq ($(TOP),.)
configure+1−7
@@ -32,7 +32,6 @@ cross_prefix="" · 31 unmodified lines
32cc="gcc"32cc="gcc"
33host_cc="gcc"33host_cc="gcc"
34ar="ar"34ar="ar"
35make="make"
36strip="strip"35strip="strip"
37cpu=`uname -m`36cpu=`uname -m`
38case "$cpu" in37case "$cpu" in
@@ -115,8 +114,6 @@ for opt do · 76 unmodified lines
115 ;;114 ;;
116 --cc=*) cc=`echo $opt | cut -d '=' -f 2`115 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
117 ;;116 ;;
118 --make=*) make=`echo $opt | cut -d '=' -f 2`
119 ;;
120 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"117 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
121 ;;118 ;;
122 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"119 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
@@ -229,7 +226,6 @@ echo " --source-path=PATH path of source code [$source_path]" · 106 unmodified lines
229echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"226echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
230echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"227echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
231echo " --cc=CC use C compiler CC [$cc]"228echo " --cc=CC use C compiler CC [$cc]"
232echo " --make=MAKE use specified make [$make]"
233echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"229echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
234echo ""230echo ""
235#echo "NOTE: The object files are build at the place where configure is launched"231#echo "NOTE: The object files are build at the place where configure is launched"
@@ -238,7 +234,7 @@ fi · 2 unmodified lines
238 234
239if test "$mingw32" = "yes" ; then235if test "$mingw32" = "yes" ; then
240 if test -z "$prefix" ; then236 if test -z "$prefix" ; then
241 prefix="/c/Program Files/tcc"237 prefix="C:/Program Files/tcc"
242 fi238 fi
243 execprefix="$prefix"239 execprefix="$prefix"
244 bindir="$prefix"240 bindir="$prefix"
@@ -281,7 +277,6 @@ echo "Doc directory $docdir" · 36 unmodified lines
281echo "Target root prefix $sysroot"277echo "Target root prefix $sysroot"
282echo "Source path $source_path"278echo "Source path $source_path"
283echo "C compiler $cc"279echo "C compiler $cc"
284echo "make $make"
285echo "CPU $cpu"280echo "CPU $cpu"
286echo "Big Endian $bigendian"281echo "Big Endian $bigendian"
287echo "gprof enabled $gprof"282echo "gprof enabled $gprof"
@@ -302,7 +297,6 @@ echo "mandir=$mandir" >> config.mak · 14 unmodified lines
302echo "docdir=$docdir" >> config.mak297echo "docdir=$docdir" >> config.mak
303echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH298echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
304echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH299echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
305echo "MAKE=$make" >> config.mak
306echo "CC=$cc" >> config.mak300echo "CC=$cc" >> config.mak
307echo "GCC_MAJOR=$gcc_major" >> config.mak301echo "GCC_MAJOR=$gcc_major" >> config.mak
308echo "#define GCC_MAJOR $gcc_major" >> $TMPH302echo "#define GCC_MAJOR $gcc_major" >> $TMPH
examples/ex1.c+1−1
@@ -1,7 +1,7 @@
1#! /usr/local/bin/tcc -run1#! /usr/local/bin/tcc -run
2#include <tcclib.h>2#include <tcclib.h>
3 3
4int main() 4int main()
5{5{
6 printf("Hello World\n");6 printf("Hello World\n");
7 return 0;7 return 0;
examples/ex2.c+6−5
@@ -1,4 +1,5 @@
1#include "tcclib.h"1#include <stdlib.h>
2#include <stdio.h>
2 3
3#define N 204#define N 20
4 5
@@ -23,7 +24,7 @@ int find(int n, int i1, int a, int b, int op) · 18 unmodified lines
23 return 1;24 return 1;
24 tab[i1] = n;25 tab[i1] = n;
25 }26 }
26 27
27 for(i=0;i<nb_num;i++) {28 for(i=0;i<nb_num;i++) {
28 for(j=i+1;j<nb_num;j++) {29 for(j=i+1;j<nb_num;j++) {
29 a = tab[i];30 a = tab[i];
@@ -52,7 +53,7 @@ int find(int n, int i1, int a, int b, int op) · 22 unmodified lines
52 if (find(c, i, b, a, '/'))53 if (find(c, i, b, a, '/'))
53 return 1;54 return 1;
54 }55 }
55 56
56 stack_ptr--;57 stack_ptr--;
57 tab[i] = a;58 tab[i] = a;
58 tab[j] = b;59 tab[j] = b;
@@ -66,7 +67,7 @@ int find(int n, int i1, int a, int b, int op) · 7 unmodified lines
66int main(int argc, char **argv)67int main(int argc, char **argv)
67{68{
68 int i, res, p;69 int i, res, p;
69 70
70 if (argc < 3) {71 if (argc < 3) {
71 printf("usage: %s: result numbers...\n"72 printf("usage: %s: result numbers...\n"
72 "Try to find result from numbers with the 4 basic operations.\n", argv[0]);73 "Try to find result from numbers with the 4 basic operations.\n", argv[0]);
@@ -85,7 +86,7 @@ int main(int argc, char **argv) · 12 unmodified lines
85 res = find(0, 0, 0, 0, ' ');86 res = find(0, 0, 0, 0, ' ');
86 if (res) {87 if (res) {
87 for(i=0;i<=stack_ptr;i++) {88 for(i=0;i<=stack_ptr;i++) {
88 printf("%d %c %d = %d\n", 89 printf("%d %c %d = %d\n",
89 stack_res[3*i], stack_op[i],90 stack_res[3*i], stack_op[i],
90 stack_res[3*i+1], stack_res[3*i+2]);91 stack_res[3*i+1], stack_res[3*i+2]);
91 }92 }
examples/ex3.c+4−3
@@ -1,4 +1,5 @@
1#include <tcclib.h>1#include <stdlib.h>
2#include <stdio.h>
2 3
3int fib(n)4int fib(n)
4{5{
@@ -8,7 +9,7 @@ int fib(n) · 3 unmodified lines
8 return fib(n-1) + fib(n-2);9 return fib(n-1) + fib(n-2);
9}10}
10 11
11int main(int argc, char **argv) 12int main(int argc, char **argv)
12{13{
13 int n;14 int n;
14 if (argc < 2) {15 if (argc < 2) {
@@ -16,7 +17,7 @@ int main(int argc, char **argv) · 1 unmodified line
16 "Compute nth Fibonacci number\n");17 "Compute nth Fibonacci number\n");
17 return 1;18 return 1;
18 }19 }
19 20
20 n = atoi(argv[1]);21 n = atoi(argv[1]);
21 printf("fib(%d) = %d\n", n, fib(n, 2));22 printf("fib(%d) = %d\n", n, fib(n, 2));
22 return 0;23 return 0;
examples/ex4.c+4−3
@@ -1,9 +1,10 @@
1#!./tcc -run -L/usr/X11R6/lib -lX111#!./tcc -run -L/usr/X11R6/lib -lX11
2#include <stdlib.h>2#include <stdlib.h>
3/* Yes, TCC can use X11 too ! */
4#include <stdio.h>3#include <stdio.h>
5#include <X11/Xlib.h>4#include <X11/Xlib.h>
6 5
6/* Yes, TCC can use X11 too ! */
7
7int main(int argc, char **argv)8int main(int argc, char **argv)
8{9{
9 Display *display;10 Display *display;
@@ -16,8 +17,8 @@ int main(int argc, char **argv) · 6 unmodified lines
16 }17 }
17 printf("X11 display opened.\n");18 printf("X11 display opened.\n");
18 screen = XScreenOfDisplay(display, 0);19 screen = XScreenOfDisplay(display, 0);
19 printf("width = %d\nheight = %d\ndepth = %d\n", 20 printf("width = %d\nheight = %d\ndepth = %d\n",
20 screen->width, 21 screen->width,
21 screen->height,22 screen->height,
22 screen->root_depth);23 screen->root_depth);
23 XCloseDisplay(display);24 XCloseDisplay(display);
examples/ex5.c+1−1
@@ -1,7 +1,7 @@
1#include <stdlib.h>1#include <stdlib.h>
2#include <stdio.h>2#include <stdio.h>
3 3
4int main() 4int main()
5{5{
6 printf("Hello World\n");6 printf("Hello World\n");
7 return 0;7 return 0;
include/tcclib.h+1−0
@@ -18,6 +18,7 @@ void *realloc(void *ptr, size_t size); · 17 unmodified lines
18int atoi(const char *nptr);18int atoi(const char *nptr);
19long int strtol(const char *nptr, char **endptr, int base);19long int strtol(const char *nptr, char **endptr, int base);
20unsigned long int strtoul(const char *nptr, char **endptr, int base);20unsigned long int strtoul(const char *nptr, char **endptr, int base);
21int exit(int);
21 22
22/* stdio.h */23/* stdio.h */
23typedef struct __FILE FILE;24typedef struct __FILE FILE;
lib/alloca86-bt.S+1−1
@@ -1,7 +1,7 @@
1/* ---------------------------------------------- */1/* ---------------------------------------------- */
2/* alloca86b.S */2/* alloca86b.S */
3 3
4#include "config.h"4#include "../config.h"
5 5
6.globl __bound__alloca6.globl __bound__alloca
7 7
lib/alloca86.S+1−1
@@ -1,7 +1,7 @@
1/* ---------------------------------------------- */1/* ---------------------------------------------- */
2/* alloca86.S */2/* alloca86.S */
3 3
4#include "config.h"4#include "../config.h"
5 5
6.globl _alloca6.globl _alloca
7 7
tests/Makefile+144−0
@@ -0,0 +1,144 @@
1#
2# Tiny C Compiler Makefile - tests
3#
4
5# what tests to run
6TESTS = libtest test3
7
8# these should work too
9# TESTS += test1 test2 speed
10
11# these don't work as they should
12# TESTS += test4 btest asmtest
13
14
15TOP = ..
16include $(TOP)/Makefile
17
18# run local version of tcc with local libraries and includes
19TCC = ../tcc -B..
20RUN_TCC = -run ../tcc.c -B..
21DISAS=objdump -d
22
23all test : $(TESTS)
24
25# make sure that tcc exists
26$(TESTS) : ../tcc
27../tcc ../libtcc.a :
28 $(MAKE) -C ..
29
30# libtcc test
31libtest: libtcc_test$(EXESUF)
32 @echo ------------ $@ ------------
33 ./libtcc_test lib_path=..
34
35libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
36 $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)
37
38# test.ref - generate using gcc
39test.ref: tcctest.c
40 $(CC) -o tcctest.gcc $< -w -I.. -I../include $(CFLAGS)
41 ./tcctest.gcc > $@
42
43# auto test
44test1: test.ref
45 @echo ------------ $@ ------------
46 $(TCC) -run tcctest.c > test.out1
47 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
48
49# iterated test2 (compile tcc then compile tcctest.c !)
50test2: test.ref
51 @echo ------------ $@ ------------
52 $(TCC) $(RUN_TCC) $(RuN_TCC) -run tcctest.c > test.out2
53 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
54
55# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
56test3: test.ref
57 @echo ------------ $@ ------------
58 $(TCC) $(RUN_TCC) $(RuN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
59 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
60
61# binary output test
62test4: test.ref
63 @echo ------------ $@ ------------
64# dynamic output
65 $(TCC) -o tcctest1 tcctest.c
66 ./tcctest1 > test1.out
67 @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
68# object + link output
69 $(TCC) -c -o tcctest3.o tcctest.c
70 $(TCC) -o tcctest3 tcctest3.o
71 ./tcctest3 > test3.out
72 @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
73# static output
74 $(TCC) -static -o tcctest2 tcctest.c
75 ./tcctest2 > test2.out
76 @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
77# dynamic output + bound check
78 $(TCC) -b -o tcctest4 tcctest.c
79 ./tcctest4 > test4.out
80 @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
81
82# memory and bound check auto test
83BOUNDS_OK = 1 4 8 10
84BOUNDS_FAIL= 2 5 7 9 11 12 13
85
86btest: boundtest.c
87 @echo ------------ $@ ------------
88 @for i in $(BOUNDS_OK); do \
89 if $(TCC) -b -run boundtest.c $$i ; then \
90 /bin/true ; \
91 else\
92 echo Failed positive test $$i ; exit 1 ; \
93 fi ;\
94 done ;\
95 for i in $(BOUNDS_FAIL); do \
96 if $(TCC) -b -run boundtest.c $$i ; then \
97 echo Failed negative test $$i ; exit 1 ;\
98 else\
99 /bin/true ; \
100 fi ;\
101 done ;\
102 echo Bound test OK
103
104# speed test
105speed: ex2 ex3
106 @echo ------------ $@ ------------
107 time ./ex2 1238 2 3 4 10 13 4
108 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
109 time ./ex3 35
110 time $(TCC) -run ../examples/ex3.c 35
111
112ex%: ../examples/ex%.c
113 $(CC) -o $@ $< $(CFLAGS)
114
115# tiny assembler testing
116asmtest.ref: asmtest.S
117 $(CC) -o asmtest.ref.o -c asmtest.S
118 objdump -D asmtest.ref.o > $@
119
120asmtest: asmtest.ref
121 @echo ------------ $@ ------------
122 $(TCC) -c asmtest.S
123 objdump -D asmtest.o > $@
124 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
125
126# targets for development
127%.bin: %.c tcc
128 $(TCC) -g -o $@ $<
129 $(DISAS) $@
130
131instr: instr.o
132 objdump -d instr.o
133
134instr.o: instr.S
135 $(CC) -o $@ -c $< -O2 -Wall -g
136
137cache: tcc_g
138 cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
139 vg_annotate tcc.c > /tmp/linpack.cache.log
140
141# clean
142clean:
143 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
144 tcctest[1234] ex? libtcc_test tcc_g
tests/tcctest.c+1−1
@@ -1,7 +1,7 @@
1/*1/*
2 * TCC auto test program2 * TCC auto test program
3 */3 */
4#include "config.h"4#include "../config.h"
5 5
6#if GCC_MAJOR >= 36#if GCC_MAJOR >= 3
7 7
win32/build-tcc.bat+3−3
@@ -21,8 +21,8 @@ copy ..\libtcc.h libtcc · 20 unmodified lines
21.\tcc -c lib/dllcrt1.c21.\tcc -c lib/dllcrt1.c
22.\tcc -c lib/dllmain.c22.\tcc -c lib/dllmain.c
23.\tcc -c lib/chkstk.S23.\tcc -c lib/chkstk.S
24.\tcc -c ../libtcc1.c24.\tcc -c ../lib/libtcc1.c
25.\tcc -c ../alloca86.S25.\tcc -c ../lib/alloca86.S
26.\tcc -c ../alloca86-bt.S26.\tcc -c ../lib/alloca86-bt.S
27ar rcs lib/libtcc1.a crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o libtcc1.o alloca86.o alloca86-bt.o27ar rcs lib/libtcc1.a crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o libtcc1.o alloca86.o alloca86-bt.o
28del *.o28del *.o

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t