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 @@
11 #
22 # Tiny C Compiler Makefile
33 #
4−include config.mak
4+
5+TOP ?= .
6+include $(TOP)/config.mak
57
68 TARGET=
79 CFLAGS+=-g -Wall
@@ -33,312 +35,195 @@ CFLAGS+=-m386 -malign-functions=0 · 25 unmodified lines
3335 else
3436 CFLAGS+=-march=i386 -falign-functions=0
3537 ifneq ($(GCC_MAJOR),3)
36−CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
38+CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
3739 endif
3840 endif
3941 endif
4042
41−DISAS=objdump -d
42−INSTALL=install
43+ifeq ($(TOP),.)
4344
44−ifdef CONFIG_WIN32
4545 PROGS=tcc$(EXESUF)
46−ifdef CONFIG_CROSS
47−PROGS+=c67-tcc$(EXESUF) arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
48−endif
46+
47+ARM_CROSS = arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
48+I386_CROSS = i386-tcc$(EXESUF)
49+WIN32_CROSS = i386-win32-tcc$(EXESUF)
50+C67_CROSS = c67-tcc$(EXESUF)
51+X64_CROSS = x86_64-tcc$(EXESUF)
52+
53+ifdef CONFIG_WIN32
4954 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
50−else
51−ifeq ($(ARCH),i386)
52−PROGS=tcc$(EXESUF)
53−ifdef CONFIG_CROSS
54−PROGS+=arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
55−endif
56−endif
57−ifeq ($(ARCH),arm)
58−PROGS=tcc$(EXESUF)
59−ifdef CONFIG_CROSS
60−PROGS+=i386-tcc$(EXESUF)
61−endif
55+PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
56+
57+else ifeq ($(ARCH),i386)
58+PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
59+
60+else ifeq ($(ARCH),arm)
61+PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(C67_CROSS)
62+
63+else ifeq ($(ARCH),x86-64)
64+PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
6265 endif
66+
6367 ifdef CONFIG_CROSS
64−PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
65−endif
66−endif
67−ifeq ($(ARCH),x86-64)
68−PROGS=tcc$(EXESUF)
68+PROGS+=$(PROGS_CROSS)
6969 endif
7070
71−ifdef CONFIG_USE_LIBGCC
72−LIBTCC1=
73−else
71+ifndef CONFIG_USE_LIBGCC
7472 LIBTCC1=libtcc1.a
7573 endif
7674
77−# run local version of tcc with local libraries and includes
78−TCC=./tcc -B. -I.
79−
80−all: $(PROGS) \
81− $(LIBTCC1) $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
82− libtcc_test$(EXESUF)
83−
84−Makefile: config.mak
85−
86−# auto test
87−
88−test: test.ref test.out
89− @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
90−
91−tcctest.ref: tcctest.c
92− $(CC) $(CFLAGS) -w -I. -o $@ $<
93−
94−test.ref: tcctest.ref
95− ./tcctest.ref > $@
96−
97−test.out: tcc tcctest.c
98− $(TCC) -run tcctest.c > $@
99−
100−run: tcc tcctest.c
101− $(TCC) -run tcctest.c
102−
103−# iterated test2 (compile tcc then compile tcctest.c !)
104−test2: 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 !)
109−test3: 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
114−test4: 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
134−BOUNDS_OK = 1 4 8 10
135−BOUNDS_FAIL= 2 5 7 9 11 12 13
136−
137−btest: 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
155−speed: 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−
161−ex2: ex2.c
162− $(CC) $(CFLAGS) -o $@ $<
163−
164−ex3: ex3.c
165− $(CC) $(CFLAGS) -o $@ $<
75+all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
76+
77+TCC_CORE_FILES = tcc.c tccelf.c tccasm.c tcctok.h libtcc.h config.h
16678
16779 # Host Tiny C Compiler
16880 ifdef CONFIG_WIN32
169−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)
171−else
172−ifeq ($(ARCH),i386)
173−tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
174− $(CC) $(CFLAGS) -o $@ $< $(LIBS)
175−endif
176−ifeq ($(ARCH),arm)
81+tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
82+ $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
83+
84+else ifeq ($(ARCH),i386)
85+tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
86+ $(CC) -o $@ $< $(CFLAGS) $(LIBS)
87+
88+else ifeq ($(ARCH),x86-64)
89+tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c
90+ $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
91+
92+else ifeq ($(ARCH),arm)
17793 ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
17894 ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
179−
180−tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
181− $(CC) $(CFLAGS) -DTCC_TARGET_ARM $(ARMFLAGS) -o $@ $< $(LIBS)
182−endif
183−ifeq ($(ARCH),x86-64)
184−tcc$(EXESUF): tcc.c tccelf.c tccasm.c tcctok.h libtcc.h x86_64-gen.c
185− $(CC) $(CFLAGS) -DTCC_TARGET_X86_64 -o $@ $< $(LIBS)
186−endif
95+tcc$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
96+ $(CC) -o $@ $< -DTCC_TARGET_ARM $(ARMFLAGS) $(CFLAGS) $(LIBS)
18797 endif
18898
18999 # Cross Tiny C Compilers
190−i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
191− $(CC) $(CFLAGS) -o $@ $< $(LIBS)
100+i386-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
101+ $(CC) -o $@ $< $(CFLAGS) $(LIBS)
102+
103+i386-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+
106+x86_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)
192108
193−c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
194− $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
109+c67-tcc$(EXESUF): $(TCC_CORE_FILES) c67-gen.c tcccoff.c
110+ $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
195111
196−arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
197− $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
112+arm-tcc-fpa$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
113+ $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
114+
115+arm-tcc-fpa-ld$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
116+ $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
117+
118+arm-tcc-vfp$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
119+ $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
120+
121+arm-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
125+libtcc.o: tcc.c i386-gen.c
126+ifdef CONFIG_WIN32
127+ $(CC) -o $@ -c $< -DTCC_TARGET_PE -DLIBTCC $(CFLAGS)
128+else
129+ $(CC) -o $@ -c $< $(TARGET) -DLIBTCC $(CFLAGS)
130+endif
198131
199−arm-tcc-fpa-ld$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
200− $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -o $@ $< $(LIBS)
132+libtcc.a: libtcc.o
133+ $(AR) rcs $@ $^
201134
202−arm-tcc-vfp$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
203− $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_VFP -o $@ $< $(LIBS)
135+libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
136+ $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
204137
205−arm-tcc-vfp-eabi$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
206− $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
138+libtest: libtcc_test$(EXESUF) $(LIBTCC1)
139+ ./libtcc_test$(EXESUF) lib_path=.
207140
208−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
209− $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
141+# profiling version
142+tcc_p: tcc.c
143+ $(CC) -o $@ $< $(CFLAGS_P) $(LIBS_P)
210144
211145 # windows utilities
212146 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
213− $(CC) $(CFLAGS) -o $@ $< -lkernel32
147+ $(CC) -o $@ $< $(CFLAGS)
214148 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
215− $(CC) $(CFLAGS) -o $@ $< -lkernel32
149+ $(CC) -o $@ $< $(CFLAGS)
216150
217151 # TinyCC runtime libraries
152+LIBTCC1_OBJS=libtcc1.o
153+LIBTCC1_CC=$(CC)
154+VPATH+=lib
218155 ifdef CONFIG_WIN32
219156 # for windows, we must use TCC because we generate ELF objects
220−LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
157+LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
221158 LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
222−else
223−LIBTCC1_OBJS=libtcc1.o
224−LIBTCC1_CC=$(CC)
159+VPATH+=win32/lib
225160 endif
226161 ifeq ($(ARCH),i386)
227162 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
228163 endif
229164
230165 %.o: %.c
231− $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
166+ $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
232167
233168 %.o: %.S
234− $(LIBTCC1_CC) -c -o $@ $<
169+ $(LIBTCC1_CC) -o $@ -c $<
235170
236171 libtcc1.a: $(LIBTCC1_OBJS)
237172 $(AR) rcs $@ $^
238173
239174 bcheck.o: bcheck.c
240− $(CC) -O2 -Wall -c -o $@ $<
175+ $(CC) -o $@ -c $< -O2 -Wall
241176
242−install: tcc_install libinstall
177+# install
178+TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
179+INSTALL=install
243180
244−tcc_install: $(PROGS) tcc.1 $(LIBTCC1) $(BCHECK_O) tcc-doc.html
245− mkdir -p "$(DESTDIR)$(bindir)"
246− $(INSTALL) -s -m755 $(PROGS) "$(DESTDIR)$(bindir)"
247181 ifndef CONFIG_WIN32
248− mkdir -p "$(DESTDIR)$(mandir)/man1"
249− $(INSTALL) tcc.1 "$(DESTDIR)$(mandir)/man1"
182+install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
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"
189+ifneq ($(LIBTCC1),)
190+ $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
250191 endif
251− mkdir -p "$(DESTDIR)$(tccdir)"
252− mkdir -p "$(DESTDIR)$(tccdir)/include"
253−ifdef 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"
258−else
259−ifndef CONFIG_USE_LIBGCC
260− $(INSTALL) -m644 libtcc1.a "$(DESTDIR)$(tccdir)"
261−endif
262−ifneq ($(ARCH),x86-64)
263− $(INSTALL) -m644 $(BCHECK_O) "$(DESTDIR)$(tccdir)"
264−endif
265− $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
266− tcclib.h "$(DESTDIR)$(tccdir)/include"
267−endif
268− mkdir -p "$(DESTDIR)$(docdir)"
269− $(INSTALL) -m644 tcc-doc.html "$(DESTDIR)$(docdir)"
270−ifdef CONFIG_WIN32
271− $(INSTALL) -m644 win32/tcc-win32.txt "$(DESTDIR)$(docdir)"
192+ifneq ($(BCHECK_O),)
193+ $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
272194 endif
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+
203+uninstall:
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"
273209
274−clean:
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−
280−distclean: clean
281− rm -f config.h config.mak config.texi
282−
283−# profiling version
284−tcc_p: tcc.c Makefile
285− $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
286−
287−# libtcc generation and example
288−libinstall: 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−
294−libtcc.o: tcc.c i386-gen.c Makefile
295−ifdef CONFIG_WIN32
296− $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
297210 else
298− $(CC) $(CFLAGS) $(TARGET) -DLIBTCC -c -o $@ $<
211+install: $(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"
299225 endif
300226
301−libtcc.a: libtcc.o
302− $(AR) rcs $@ $^
303−
304−libtcc_test$(EXESUF): libtcc_test.c libtcc.a
305− $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
306−
307−libtest: libtcc_test
308− ./libtcc_test lib_path=.
309−
310−# targets for development
311−
312−%.bin: %.c tcc
313− $(TCC) -g -o $@ $<
314− $(DISAS) $@
315−
316−instr: instr.o
317− objdump -d instr.o
318−
319−# tiny assembler testing
320−
321−asmtest.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 !
326−asmtest.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−
332−asmtest: 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−
335−instr.o: instr.S
336− $(CC) -O2 -Wall -g -c -o $@ $<
337−
338−cache: tcc_g
339− cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
340− vg_annotate tcc.c > /tmp/linpack.cache.log
341−
342227 # documentation and man page
343228 tcc-doc.html: tcc-doc.texi
344229 -texi2html -monolithic -number $<
@@ -347,11 +232,25 @@ tcc.1: tcc-doc.texi · 2 unmodified lines
347232 -./texi2pod.pl $< tcc.pod
348233 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
349234
350−FILE=tcc-$(shell cat VERSION)
351−
352235 # tar release (use 'make -k tar' on a checkouted tree)
236+TCC-VERSION=tcc-$(shell cat VERSION)
353237 tar:
354− rm -rf /tmp/$(FILE)
355− cp -r . /tmp/$(FILE)
356− ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
357− rm -rf /tmp/$(FILE)
238+ rm -rf /tmp/$(TCC-VERSION)
239+ cp -r . /tmp/$(TCC-VERSION)
240+ ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
241+ rm -rf /tmp/$(TCC-VERSION)
242+
243+# in tests subdir
244+test clean :
245+ $(MAKE) -C tests $@
246+
247+# clean
248+clean: local_clean
249+local_clean:
250+ rm -vf $(PROGS) tcc_p tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
251+
252+distclean: clean
253+ rm -vf config.h config.mak config.texi tcc.1 tcc-doc.html
254+
255+endif
256+# ifeq ($(TOP),.)
configure+1−7
@@ -32,7 +32,6 @@ cross_prefix="" · 31 unmodified lines
3232 cc="gcc"
3333 host_cc="gcc"
3434 ar="ar"
35−make="make"
3635 strip="strip"
3736 cpu=`uname -m`
3837 case "$cpu" in
@@ -115,8 +114,6 @@ for opt do · 76 unmodified lines
115114 ;;
116115 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
117116 ;;
118− --make=*) make=`echo $opt | cut -d '=' -f 2`
119− ;;
120117 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
121118 ;;
122119 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
@@ -229,7 +226,6 @@ echo " --source-path=PATH path of source code [$source_path]" · 106 unmodified lines
229226 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
230227 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
231228 echo " --cc=CC use C compiler CC [$cc]"
232−echo " --make=MAKE use specified make [$make]"
233229 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
234230 echo ""
235231 #echo "NOTE: The object files are build at the place where configure is launched"
@@ -238,7 +234,7 @@ fi · 2 unmodified lines
238234
239235 if test "$mingw32" = "yes" ; then
240236 if test -z "$prefix" ; then
241− prefix="/c/Program Files/tcc"
237+ prefix="C:/Program Files/tcc"
242238 fi
243239 execprefix="$prefix"
244240 bindir="$prefix"
@@ -281,7 +277,6 @@ echo "Doc directory $docdir" · 36 unmodified lines
281277 echo "Target root prefix $sysroot"
282278 echo "Source path $source_path"
283279 echo "C compiler $cc"
284−echo "make $make"
285280 echo "CPU $cpu"
286281 echo "Big Endian $bigendian"
287282 echo "gprof enabled $gprof"
@@ -302,7 +297,6 @@ echo "mandir=$mandir" >> config.mak · 14 unmodified lines
302297 echo "docdir=$docdir" >> config.mak
303298 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
304299 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
305−echo "MAKE=$make" >> config.mak
306300 echo "CC=$cc" >> config.mak
307301 echo "GCC_MAJOR=$gcc_major" >> config.mak
308302 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
examples/ex1.c+1−1
@@ -1,7 +1,7 @@
11 #! /usr/local/bin/tcc -run
22 #include <tcclib.h>
33
4−int main()
4+int main()
55 {
66 printf("Hello World\n");
77 return 0;
examples/ex2.c+6−5
@@ -1,4 +1,5 @@
1−#include "tcclib.h"
1+#include <stdlib.h>
2+#include <stdio.h>
23
34 #define N 20
45
@@ -23,7 +24,7 @@ int find(int n, int i1, int a, int b, int op) · 18 unmodified lines
2324 return 1;
2425 tab[i1] = n;
2526 }
26−
27+
2728 for(i=0;i<nb_num;i++) {
2829 for(j=i+1;j<nb_num;j++) {
2930 a = tab[i];
@@ -52,7 +53,7 @@ int find(int n, int i1, int a, int b, int op) · 22 unmodified lines
5253 if (find(c, i, b, a, '/'))
5354 return 1;
5455 }
55−
56+
5657 stack_ptr--;
5758 tab[i] = a;
5859 tab[j] = b;
@@ -66,7 +67,7 @@ int find(int n, int i1, int a, int b, int op) · 7 unmodified lines
6667 int main(int argc, char **argv)
6768 {
6869 int i, res, p;
69−
70+
7071 if (argc < 3) {
7172 printf("usage: %s: result numbers...\n"
7273 "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
8586 res = find(0, 0, 0, 0, ' ');
8687 if (res) {
8788 for(i=0;i<=stack_ptr;i++) {
88− printf("%d %c %d = %d\n",
89+ printf("%d %c %d = %d\n",
8990 stack_res[3*i], stack_op[i],
9091 stack_res[3*i+1], stack_res[3*i+2]);
9192 }
examples/ex3.c+4−3
@@ -1,4 +1,5 @@
1−#include <tcclib.h>
1+#include <stdlib.h>
2+#include <stdio.h>
23
34 int fib(n)
45 {
@@ -8,7 +9,7 @@ int fib(n) · 3 unmodified lines
89 return fib(n-1) + fib(n-2);
910 }
1011
11−int main(int argc, char **argv)
12+int main(int argc, char **argv)
1213 {
1314 int n;
1415 if (argc < 2) {
@@ -16,7 +17,7 @@ int main(int argc, char **argv) · 1 unmodified line
1617 "Compute nth Fibonacci number\n");
1718 return 1;
1819 }
19−
20+
2021 n = atoi(argv[1]);
2122 printf("fib(%d) = %d\n", n, fib(n, 2));
2223 return 0;
examples/ex4.c+4−3
@@ -1,9 +1,10 @@
11 #!./tcc -run -L/usr/X11R6/lib -lX11
22 #include <stdlib.h>
3−/* Yes, TCC can use X11 too ! */
43 #include <stdio.h>
54 #include <X11/Xlib.h>
65
6+/* Yes, TCC can use X11 too ! */
7+
78 int main(int argc, char **argv)
89 {
910 Display *display;
@@ -16,8 +17,8 @@ int main(int argc, char **argv) · 6 unmodified lines
1617 }
1718 printf("X11 display opened.\n");
1819 screen = XScreenOfDisplay(display, 0);
19− printf("width = %d\nheight = %d\ndepth = %d\n",
20− screen->width,
20+ printf("width = %d\nheight = %d\ndepth = %d\n",
21+ screen->width,
2122 screen->height,
2223 screen->root_depth);
2324 XCloseDisplay(display);
examples/ex5.c+1−1
@@ -1,7 +1,7 @@
11 #include <stdlib.h>
22 #include <stdio.h>
33
4−int main()
4+int main()
55 {
66 printf("Hello World\n");
77 return 0;
include/tcclib.h+1−0
@@ -18,6 +18,7 @@ void *realloc(void *ptr, size_t size); · 17 unmodified lines
1818 int atoi(const char *nptr);
1919 long int strtol(const char *nptr, char **endptr, int base);
2020 unsigned long int strtoul(const char *nptr, char **endptr, int base);
21+int exit(int);
2122
2223 /* stdio.h */
2324 typedef struct __FILE FILE;
lib/alloca86-bt.S+1−1
@@ -1,7 +1,7 @@
11 /* ---------------------------------------------- */
22 /* alloca86b.S */
33
4−#include "config.h"
4+#include "../config.h"
55
66 .globl __bound__alloca
77
lib/alloca86.S+1−1
@@ -1,7 +1,7 @@
11 /* ---------------------------------------------- */
22 /* alloca86.S */
33
4−#include "config.h"
4+#include "../config.h"
55
66 .globl _alloca
77
tests/Makefile+144−0
@@ -0,0 +1,144 @@
1+#
2+# Tiny C Compiler Makefile - tests
3+#
4+
5+# what tests to run
6+TESTS = 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+
15+TOP = ..
16+include $(TOP)/Makefile
17+
18+# run local version of tcc with local libraries and includes
19+TCC = ../tcc -B..
20+RUN_TCC = -run ../tcc.c -B..
21+DISAS=objdump -d
22+
23+all test : $(TESTS)
24+
25+# make sure that tcc exists
26+$(TESTS) : ../tcc
27+../tcc ../libtcc.a :
28+ $(MAKE) -C ..
29+
30+# libtcc test
31+libtest: libtcc_test$(EXESUF)
32+ @echo ------------ $@ ------------
33+ ./libtcc_test lib_path=..
34+
35+libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
36+ $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)
37+
38+# test.ref - generate using gcc
39+test.ref: tcctest.c
40+ $(CC) -o tcctest.gcc $< -w -I.. -I../include $(CFLAGS)
41+ ./tcctest.gcc > $@
42+
43+# auto test
44+test1: 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 !)
50+test2: 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 !)
56+test3: 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
62+test4: 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
83+BOUNDS_OK = 1 4 8 10
84+BOUNDS_FAIL= 2 5 7 9 11 12 13
85+
86+btest: 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
105+speed: 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+
112+ex%: ../examples/ex%.c
113+ $(CC) -o $@ $< $(CFLAGS)
114+
115+# tiny assembler testing
116+asmtest.ref: asmtest.S
117+ $(CC) -o asmtest.ref.o -c asmtest.S
118+ objdump -D asmtest.ref.o > $@
119+
120+asmtest: 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+
131+instr: instr.o
132+ objdump -d instr.o
133+
134+instr.o: instr.S
135+ $(CC) -o $@ -c $< -O2 -Wall -g
136+
137+cache: 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
142+clean:
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 @@
11 /*
22 * TCC auto test program
33 */
4−#include "config.h"
4+#include "../config.h"
55
66 #if GCC_MAJOR >= 3
77
win32/build-tcc.bat+3−3
@@ -21,8 +21,8 @@ copy ..\libtcc.h libtcc · 20 unmodified lines
2121 .\tcc -c lib/dllcrt1.c
2222 .\tcc -c lib/dllmain.c
2323 .\tcc -c lib/chkstk.S
24−.\tcc -c ../libtcc1.c
25−.\tcc -c ../alloca86.S
26−.\tcc -c ../alloca86-bt.S
24+.\tcc -c ../lib/libtcc1.c
25+.\tcc -c ../lib/alloca86.S
26+.\tcc -c ../lib/alloca86-bt.S
2727 ar rcs lib/libtcc1.a crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o libtcc1.o alloca86.o alloca86-bt.o
2828 del *.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