aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrischka <grischka>2009-04-18 14:31:35 +0200
committergrischka <grischka>2009-04-18 15:08:03 +0200
commit5829791ffaca0178fbbd4111fbdf8c7cbd6de27f (patch)
treed41bf8392e3059cc21c58b5193b5f81fb083ed71
parentea5e81bd6a3376232bf4747b2fa2e0a91c19b337 (diff)
downloadtinycc-5829791ffaca0178fbbd4111fbdf8c7cbd6de27f.tar.gz
tinycc-5829791ffaca0178fbbd4111fbdf8c7cbd6de27f.tar.bz2
fix makefiles etc for subdirs
-rw-r--r--Makefile391
-rwxr-xr-xconfigure8
-rwxr-xr-xexamples/ex1.c2
-rw-r--r--examples/ex2.c11
-rw-r--r--examples/ex3.c7
-rwxr-xr-xexamples/ex4.c7
-rw-r--r--examples/ex5.c2
-rw-r--r--include/tcclib.h1
-rw-r--r--lib/alloca86-bt.S2
-rw-r--r--lib/alloca86.S2
-rw-r--r--tests/Makefile144
-rw-r--r--tests/tcctest.c2
-rw-r--r--win32/build-tcc.bat6
13 files changed, 313 insertions, 272 deletions
diff --git a/Makefile b/Makefile
index b18da09..57a9ffe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,9 @@
#
# Tiny C Compiler Makefile
#
-include config.mak
+
+TOP ?= .
+include $(TOP)/config.mak
TARGET=
CFLAGS+=-g -Wall
@@ -33,312 +35,195 @@ CFLAGS+=-m386 -malign-functions=0
else
CFLAGS+=-march=i386 -falign-functions=0
ifneq ($(GCC_MAJOR),3)
-CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
+CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
endif
endif
endif
-DISAS=objdump -d
-INSTALL=install
+ifeq ($(TOP),.)
-ifdef CONFIG_WIN32
PROGS=tcc$(EXESUF)
-ifdef CONFIG_CROSS
-PROGS+=c67-tcc$(EXESUF) arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
-endif
+
+ARM_CROSS = arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
+I386_CROSS = i386-tcc$(EXESUF)
+WIN32_CROSS = i386-win32-tcc$(EXESUF)
+C67_CROSS = c67-tcc$(EXESUF)
+X64_CROSS = x86_64-tcc$(EXESUF)
+
+ifdef CONFIG_WIN32
PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
-else
-ifeq ($(ARCH),i386)
-PROGS=tcc$(EXESUF)
-ifdef CONFIG_CROSS
-PROGS+=arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
-endif
-endif
-ifeq ($(ARCH),arm)
-PROGS=tcc$(EXESUF)
-ifdef CONFIG_CROSS
-PROGS+=i386-tcc$(EXESUF)
-endif
+PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
+
+else ifeq ($(ARCH),i386)
+PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
+
+else ifeq ($(ARCH),arm)
+PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(C67_CROSS)
+
+else ifeq ($(ARCH),x86-64)
+PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(ARM_CROSS) $(C67_CROSS)
endif
+
ifdef CONFIG_CROSS
-PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
-endif
-endif
-ifeq ($(ARCH),x86-64)
-PROGS=tcc$(EXESUF)
+PROGS+=$(PROGS_CROSS)
endif
-ifdef CONFIG_USE_LIBGCC
-LIBTCC1=
-else
+ifndef CONFIG_USE_LIBGCC
LIBTCC1=libtcc1.a
endif
-# run local version of tcc with local libraries and includes
-TCC=./tcc -B. -I.
-
-all: $(PROGS) \
- $(LIBTCC1) $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
- libtcc_test$(EXESUF)
-
-Makefile: config.mak
+all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
-# auto test
+TCC_CORE_FILES = tcc.c tccelf.c tccasm.c tcctok.h libtcc.h config.h
-test: test.ref test.out
- @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
-
-tcctest.ref: tcctest.c
- $(CC) $(CFLAGS) -w -I. -o $@ $<
+# Host Tiny C Compiler
+ifdef CONFIG_WIN32
+tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
+ $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
-test.ref: tcctest.ref
- ./tcctest.ref > $@
+else ifeq ($(ARCH),i386)
+tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
+ $(CC) -o $@ $< $(CFLAGS) $(LIBS)
-test.out: tcc tcctest.c
- $(TCC) -run tcctest.c > $@
+else ifeq ($(ARCH),x86-64)
+tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
-run: tcc tcctest.c
- $(TCC) -run tcctest.c
+else ifeq ($(ARCH),arm)
+ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
+ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
+tcc$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_ARM $(ARMFLAGS) $(CFLAGS) $(LIBS)
+endif
-# iterated test2 (compile tcc then compile tcctest.c !)
-test2: tcc tcc.c tcctest.c test.ref
- $(TCC) -run $(TARGET) tcc.c -B. -I. -run tcctest.c > test.out2
- @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
+# Cross Tiny C Compilers
+i386-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
+ $(CC) -o $@ $< $(CFLAGS) $(LIBS)
-# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
-test3: tcc tcc.c tcctest.c test.ref
- $(TCC) -run $(TARGET) tcc.c -B. -I. -run $(TARGET) tcc.c -B. -I. -run tcctest.c > test.out3
- @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
+i386-win32-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
+ $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
-# binary output test
-test4: tcc test.ref
-# dynamic output
- $(TCC) -o tcctest1 tcctest.c
- ./tcctest1 > test1.out
- @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
-# static output
- $(TCC) -static -o tcctest2 tcctest.c
- ./tcctest2 > test2.out
- @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
-# object + link output
- $(TCC) -c -o tcctest3.o tcctest.c
- $(TCC) -o tcctest3 tcctest3.o
- ./tcctest3 > test3.out
- @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
-# dynamic output + bound check
- $(TCC) -b -o tcctest4 tcctest.c
- ./tcctest4 > test4.out
- @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
+x86_64-tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c i386-asm.c i386-asm.h
+ $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
-# memory and bound check auto test
-BOUNDS_OK = 1 4 8 10
-BOUNDS_FAIL= 2 5 7 9 11 12 13
+c67-tcc$(EXESUF): $(TCC_CORE_FILES) c67-gen.c tcccoff.c
+ $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
-btest: boundtest.c tcc
- @for i in $(BOUNDS_OK); do \
- if $(TCC) -b -run boundtest.c $$i ; then \
- /bin/true ; \
- else\
- echo Failed positive test $$i ; exit 1 ; \
- fi ;\
- done ;\
- for i in $(BOUNDS_FAIL); do \
- if $(TCC) -b -run boundtest.c $$i ; then \
- echo Failed negative test $$i ; exit 1 ;\
- else\
- /bin/true ; \
- fi\
- done ;\
- echo Bound test OK
+arm-tcc-fpa$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
-# speed test
-speed: tcc ex2 ex3
- time ./ex2 1238 2 3 4 10 13 4
- time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4
- time ./ex3 35
- time ./tcc -I. ./ex3.c 35
+arm-tcc-fpa-ld$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
-ex2: ex2.c
- $(CC) $(CFLAGS) -o $@ $<
+arm-tcc-vfp$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
-ex3: ex3.c
- $(CC) $(CFLAGS) -o $@ $<
+arm-tcc-vfp-eabi$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
+ $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
-# Host Tiny C Compiler
+# libtcc generation and test
+libtcc.o: tcc.c i386-gen.c
ifdef CONFIG_WIN32
-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h tccpe.c
- $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
+ $(CC) -o $@ -c $< -DTCC_TARGET_PE -DLIBTCC $(CFLAGS)
else
-ifeq ($(ARCH),i386)
-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
- $(CC) $(CFLAGS) -o $@ $< $(LIBS)
+ $(CC) -o $@ -c $< $(TARGET) -DLIBTCC $(CFLAGS)
endif
-ifeq ($(ARCH),arm)
-ARMFLAGS = $(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
-ARMFLAGS += $(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
-tcc$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
- $(CC) $(CFLAGS) -DTCC_TARGET_ARM $(ARMFLAGS) -o $@ $< $(LIBS)
-endif
-ifeq ($(ARCH),x86-64)
-tcc$(EXESUF): tcc.c tccelf.c tccasm.c tcctok.h libtcc.h x86_64-gen.c
- $(CC) $(CFLAGS) -DTCC_TARGET_X86_64 -o $@ $< $(LIBS)
-endif
-endif
-
-# Cross Tiny C Compilers
-i386-tcc$(EXESUF): tcc.c i386-gen.c tccelf.c tccasm.c i386-asm.c tcctok.h libtcc.h i386-asm.h
- $(CC) $(CFLAGS) -o $@ $< $(LIBS)
-
-c67-tcc$(EXESUF): tcc.c c67-gen.c tccelf.c tccasm.c tcctok.h libtcc.h tcccoff.c
- $(CC) $(CFLAGS) -DTCC_TARGET_C67 -o $@ $< $(LIBS)
-
-arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
- $(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
-
-arm-tcc-fpa-ld$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
- $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 -o $@ $< $(LIBS)
+libtcc.a: libtcc.o
+ $(AR) rcs $@ $^
-arm-tcc-vfp$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
- $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_VFP -o $@ $< $(LIBS)
+libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
+ $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
-arm-tcc-vfp-eabi$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
- $(CC) $(CFLAGS) -DTCC_TARGET_ARM -DTCC_ARM_EABI -o $@ $< $(LIBS)
+libtest: libtcc_test$(EXESUF) $(LIBTCC1)
+ ./libtcc_test$(EXESUF) lib_path=.
-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
- $(CC) $(CFLAGS) -DTCC_TARGET_PE -o $@ $< $(LIBS)
+# profiling version
+tcc_p: tcc.c
+ $(CC) -o $@ $< $(CFLAGS_P) $(LIBS_P)
# windows utilities
tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
- $(CC) $(CFLAGS) -o $@ $< -lkernel32
+ $(CC) -o $@ $< $(CFLAGS)
tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
- $(CC) $(CFLAGS) -o $@ $< -lkernel32
+ $(CC) -o $@ $< $(CFLAGS)
# TinyCC runtime libraries
+LIBTCC1_OBJS=libtcc1.o
+LIBTCC1_CC=$(CC)
+VPATH+=lib
ifdef CONFIG_WIN32
# for windows, we must use TCC because we generate ELF objects
-LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o
+LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
-else
-LIBTCC1_OBJS=libtcc1.o
-LIBTCC1_CC=$(CC)
+VPATH+=win32/lib
endif
ifeq ($(ARCH),i386)
LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
endif
%.o: %.c
- $(LIBTCC1_CC) -O2 -Wall -c -o $@ $<
+ $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
%.o: %.S
- $(LIBTCC1_CC) -c -o $@ $<
+ $(LIBTCC1_CC) -o $@ -c $<
libtcc1.a: $(LIBTCC1_OBJS)
$(AR) rcs $@ $^
bcheck.o: bcheck.c
- $(CC) -O2 -Wall -c -o $@ $<
+ $(CC) -o $@ -c $< -O2 -Wall
-install: tcc_install libinstall
+# install
+TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
+INSTALL=install
-tcc_install: $(PROGS) tcc.1 $(LIBTCC1) $(BCHECK_O) tcc-doc.html
- mkdir -p "$(DESTDIR)$(bindir)"
- $(INSTALL) -s -m755 $(PROGS) "$(DESTDIR)$(bindir)"
ifndef CONFIG_WIN32
- mkdir -p "$(DESTDIR)$(mandir)/man1"
- $(INSTALL) tcc.1 "$(DESTDIR)$(mandir)/man1"
+install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
+ mkdir -p "$(bindir)"
+ $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
+ mkdir -p "$(mandir)/man1"
+ $(INSTALL) tcc.1 "$(mandir)/man1"
+ mkdir -p "$(tccdir)"
+ mkdir -p "$(tccdir)/include"
+ifneq ($(LIBTCC1),)
+ $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
endif
- mkdir -p "$(DESTDIR)$(tccdir)"
- mkdir -p "$(DESTDIR)$(tccdir)/include"
-ifdef CONFIG_WIN32
- mkdir -p "$(DESTDIR)$(tccdir)/lib"
- $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(DESTDIR)$(tccdir)/lib"
- cp -r win32/include/. "$(DESTDIR)$(tccdir)/include"
- cp -r win32/examples/. "$(DESTDIR)$(tccdir)/examples"
-else
-ifndef CONFIG_USE_LIBGCC
- $(INSTALL) -m644 libtcc1.a "$(DESTDIR)$(tccdir)"
-endif
-ifneq ($(ARCH),x86-64)
- $(INSTALL) -m644 $(BCHECK_O) "$(DESTDIR)$(tccdir)"
-endif
- $(INSTALL) -m644 stdarg.h stddef.h stdbool.h float.h varargs.h \
- tcclib.h "$(DESTDIR)$(tccdir)/include"
+ifneq ($(BCHECK_O),)
+ $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
endif
- mkdir -p "$(DESTDIR)$(docdir)"
- $(INSTALL) -m644 tcc-doc.html "$(DESTDIR)$(docdir)"
-ifdef CONFIG_WIN32
- $(INSTALL) -m644 win32/tcc-win32.txt "$(DESTDIR)$(docdir)"
-endif
-
-clean:
- rm -f *~ *.o *.a tcc tcct tcc_g tcctest.ref *.bin *.i ex2 \
- core gmon.out test.out test.ref a.out tcc_p \
- *.exe *.lib tcc.pod libtcc_test \
- tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o
+ $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
+ mkdir -p "$(docdir)"
+ $(INSTALL) -m644 tcc-doc.html "$(docdir)"
+ mkdir -p "$(libdir)"
+ $(INSTALL) -m644 libtcc.a "$(libdir)"
+ mkdir -p "$(includedir)"
+ $(INSTALL) -m644 libtcc.h "$(includedir)"
-distclean: clean
- rm -f config.h config.mak config.texi
-
-# profiling version
-tcc_p: tcc.c Makefile
- $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
+uninstall:
+ rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
+ rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
+ rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
+ rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
+ rm -fv "$(libdir)/libtcc.a" "$(includedir)/libtcc.h"
-# libtcc generation and example
-libinstall: libtcc.a
- mkdir -p "$(DESTDIR)$(libdir)"
- $(INSTALL) -m644 libtcc.a "$(DESTDIR)$(libdir)"
- mkdir -p "$(DESTDIR)$(includedir)"
- $(INSTALL) -m644 libtcc.h "$(DESTDIR)$(includedir)"
-
-libtcc.o: tcc.c i386-gen.c Makefile
-ifdef CONFIG_WIN32
- $(CC) $(CFLAGS) -DTCC_TARGET_PE -DLIBTCC -c -o $@ $<
else
- $(CC) $(CFLAGS) $(TARGET) -DLIBTCC -c -o $@ $<
+install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
+ mkdir -p "$(tccdir)"
+ mkdir -p "$(tccdir)/lib"
+ mkdir -p "$(tccdir)/include"
+ mkdir -p "$(tccdir)/examples"
+ mkdir -p "$(tccdir)/doc"
+ mkdir -p "$(tccdir)/libtcc"
+ $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
+ $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
+ cp -r win32/include/. "$(tccdir)/include"
+ cp -r win32/examples/. "$(tccdir)/examples"
+ $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
+ $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt"$(tccdir)/doc"
+ $(INSTALL) -m644 libtcc.a libtcc.h "$(tccdir)/libtcc"
endif
-libtcc.a: libtcc.o
- $(AR) rcs $@ $^
-
-libtcc_test$(EXESUF): libtcc_test.c libtcc.a
- $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
-
-libtest: libtcc_test
- ./libtcc_test lib_path=.
-
-# targets for development
-
-%.bin: %.c tcc
- $(TCC) -g -o $@ $<
- $(DISAS) $@
-
-instr: instr.o
- objdump -d instr.o
-
-# tiny assembler testing
-
-asmtest.ref: asmtest.S
- $(CC) -c -o asmtest.ref.o asmtest.S
- objdump -D asmtest.ref.o > $@
-
-# XXX: we compute tcc.c to go faster during development !
-asmtest.out: asmtest.S tcc
-# ./tcc tcc.c -c asmtest.S
-#asmtest.out: asmtest.S tcc
- ./tcc -c asmtest.S
- objdump -D asmtest.o > $@
-
-asmtest: asmtest.out asmtest.ref
- @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
-
-instr.o: instr.S
- $(CC) -O2 -Wall -g -c -o $@ $<
-
-cache: tcc_g
- cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
- vg_annotate tcc.c > /tmp/linpack.cache.log
-
# documentation and man page
tcc-doc.html: tcc-doc.texi
-texi2html -monolithic -number $<
@@ -347,11 +232,25 @@ tcc.1: tcc-doc.texi
-./texi2pod.pl $< tcc.pod
-pod2man --section=1 --center=" " --release=" " tcc.pod > $@
-FILE=tcc-$(shell cat VERSION)
-
# tar release (use 'make -k tar' on a checkouted tree)
+TCC-VERSION=tcc-$(shell cat VERSION)
tar:
- rm -rf /tmp/$(FILE)
- cp -r . /tmp/$(FILE)
- ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
- rm -rf /tmp/$(FILE)
+ rm -rf /tmp/$(TCC-VERSION)
+ cp -r . /tmp/$(TCC-VERSION)
+ ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
+ rm -rf /tmp/$(TCC-VERSION)
+
+# in tests subdir
+test clean :
+ $(MAKE) -C tests $@
+
+# clean
+clean: local_clean
+local_clean:
+ rm -vf $(PROGS) tcc_p tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
+
+distclean: clean
+ rm -vf config.h config.mak config.texi tcc.1 tcc-doc.html
+
+endif
+# ifeq ($(TOP),.)
diff --git a/configure b/configure
index f4c718d..5b38f28 100755
--- a/configure
+++ b/configure
@@ -32,7 +32,6 @@ cross_prefix=""
cc="gcc"
host_cc="gcc"
ar="ar"
-make="make"
strip="strip"
cpu=`uname -m`
case "$cpu" in
@@ -115,8 +114,6 @@ for opt do
;;
--cc=*) cc=`echo $opt | cut -d '=' -f 2`
;;
- --make=*) make=`echo $opt | cut -d '=' -f 2`
- ;;
--extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
;;
--extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
@@ -229,7 +226,6 @@ echo " --source-path=PATH path of source code [$source_path]"
echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
echo " --cc=CC use C compiler CC [$cc]"
-echo " --make=MAKE use specified make [$make]"
echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
echo ""
#echo "NOTE: The object files are build at the place where configure is launched"
@@ -238,7 +234,7 @@ fi
if test "$mingw32" = "yes" ; then
if test -z "$prefix" ; then
- prefix="/c/Program Files/tcc"
+ prefix="C:/Program Files/tcc"
fi
execprefix="$prefix"
bindir="$prefix"
@@ -281,7 +277,6 @@ echo "Doc directory $docdir"
echo "Target root prefix $sysroot"
echo "Source path $source_path"
echo "C compiler $cc"
-echo "make $make"
echo "CPU $cpu"
echo "Big Endian $bigendian"
echo "gprof enabled $gprof"
@@ -302,7 +297,6 @@ echo "mandir=$mandir" >> config.mak
echo "docdir=$docdir" >> config.mak
echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
-echo "MAKE=$make" >> config.mak
echo "CC=$cc" >> config.mak
echo "GCC_MAJOR=$gcc_major" >> config.mak
echo "#define GCC_MAJOR $gcc_major" >> $TMPH
diff --git a/examples/ex1.c b/examples/ex1.c
index 2dcff7d..28139f9 100755
--- a/examples/ex1.c
+++ b/examples/ex1.c
@@ -1,7 +1,7 @@
#! /usr/local/bin/tcc -run
#include <tcclib.h>
-int main()
+int main()
{
printf("Hello World\n");
return 0;
diff --git a/examples/ex2.c b/examples/ex2.c
index 6368bee..d415e39 100644
--- a/examples/ex2.c
+++ b/examples/ex2.c
@@ -1,4 +1,5 @@
-#include "tcclib.h"
+#include <stdlib.h>
+#include <stdio.h>
#define N 20
@@ -23,7 +24,7 @@ int find(int n, int i1, int a, int b, int op)
return 1;
tab[i1] = n;
}
-
+
for(i=0;i<nb_num;i++) {
for(j=i+1;j<nb_num;j++) {
a = tab[i];
@@ -52,7 +53,7 @@ int find(int n, int i1, int a, int b, int op)
if (find(c, i, b, a, '/'))
return 1;
}
-
+
stack_ptr--;
tab[i] = a;
tab[j] = b;
@@ -66,7 +67,7 @@ int find(int n, int i1, int a, int b, int op)
int main(int argc, char **argv)
{
int i, res, p;
-
+
if (argc < 3) {
printf("usage: %s: result numbers...\n"
"Try to find result from numbers with the 4 basic operations.\n", argv[0]);
@@ -85,7 +86,7 @@ int main(int argc, char **argv)
res = find(0, 0, 0, 0, ' ');
if (res) {
for(i=0;i<=stack_ptr;i++) {
- printf("%d %c %d = %d\n",
+ printf("%d %c %d = %d\n",
stack_res[3*i], stack_op[i],
stack_res[3*i+1], stack_res[3*i+2]);
}
diff --git a/examples/ex3.c b/examples/ex3.c
index 6f6f630..7c466ad 100644
--- a/examples/ex3.c
+++ b/examples/ex3.c
@@ -1,4 +1,5 @@
-#include <tcclib.h>
+#include <stdlib.h>
+#include <stdio.h>
int fib(n)
{
@@ -8,7 +9,7 @@ int fib(n)
return fib(n-1) + fib(n-2);
}
-int main(int argc, char **argv)
+int main(int argc, char **argv)
{
int n;
if (argc < 2) {
@@ -16,7 +17,7 @@ int main(int argc, char **argv)
"Compute nth Fibonacci number\n");
return 1;
}
-
+
n = atoi(argv[1]);
printf("fib(%d) = %d\n", n, fib(n, 2));
return 0;
diff --git a/examples/ex4.c b/examples/ex4.c
index 3a3fed7..b33b033 100755
--- a/examples/ex4.c
+++ b/examples/ex4.c
@@ -1,9 +1,10 @@
#!./tcc -run -L/usr/X11R6/lib -lX11
#include <stdlib.h>
-/* Yes, TCC can use X11 too ! */
#include <stdio.h>
#include <X11/Xlib.h>
+/* Yes, TCC can use X11 too ! */
+
int main(int argc, char **argv)
{
Display *display;
@@ -16,8 +17,8 @@ int main(int argc, char **argv)
}
printf("X11 display opened.\n");
screen = XScreenOfDisplay(display, 0);
- printf("width = %d\nheight = %d\ndepth = %d\n",
- screen->width,
+ printf("width = %d\nheight = %d\ndepth = %d\n",
+ screen->width,
screen->height,
screen->root_depth);
XCloseDisplay(display);
diff --git a/examples/ex5.c b/examples/ex5.c
index da625c5..156425e 100644
--- a/examples/ex5.c
+++ b/examples/ex5.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
-int main()
+int main()
{
printf("Hello World\n");
return 0;
diff --git a/include/tcclib.h b/include/tcclib.h
index a7cc8a3..4ae3ea4 100644
--- a/include/tcclib.h
+++ b/include/tcclib.h
@@ -18,6 +18,7 @@ void *realloc(void *ptr, size_t size);
int atoi(const char *nptr);
long int strtol(const char *nptr, char **endptr, int base);
unsigned long int strtoul(const char *nptr, char **endptr, int base);
+int exit(int);
/* stdio.h */
typedef struct __FILE FILE;
diff --git a/lib/alloca86-bt.S b/lib/alloca86-bt.S
index 3fa8a53..037c845 100644
--- a/lib/alloca86-bt.S
+++ b/lib/alloca86-bt.S
@@ -1,7 +1,7 @@
/* ---------------------------------------------- */
/* alloca86b.S */
-#include "config.h"
+#include "../config.h"
.globl __bound__alloca
diff --git a/lib/alloca86.S b/lib/alloca86.S
index a60b140..3d5eb61 100644
--- a/lib/alloca86.S
+++ b/lib/alloca86.S
@@ -1,7 +1,7 @@
/* ---------------------------------------------- */
/* alloca86.S */
-#include "config.h"
+#include "../config.h"
.globl _alloca
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..c5a4165
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,144 @@
+#
+# Tiny C Compiler Makefile - tests
+#
+
+# what tests to run
+TESTS = libtest test3
+
+# these should work too
+# TESTS += test1 test2 speed
+
+# these don't work as they should
+# TESTS += test4 btest asmtest
+
+
+TOP = ..
+include $(TOP)/Makefile
+
+# run local version of tcc with local libraries and includes
+TCC = ../tcc -B..
+RUN_TCC = -run ../tcc.c -B..
+DISAS=objdump -d
+
+all test : $(TESTS)
+
+# make sure that tcc exists
+$(TESTS) : ../tcc
+../tcc ../libtcc.a :
+ $(MAKE) -C ..
+
+# libtcc test
+libtest: libtcc_test$(EXESUF)
+ @echo ------------ $@ ------------
+ ./libtcc_test lib_path=..
+
+libtcc_test$(EXESUF): libtcc_test.c ../libtcc.a
+ $(CC) -o $@ $^ -I.. $(CFLAGS) $(LIBS)
+
+# test.ref - generate using gcc
+test.ref: tcctest.c
+ $(CC) -o tcctest.gcc $< -w -I.. -I../include $(CFLAGS)
+ ./tcctest.gcc > $@
+
+# auto test
+test1: test.ref
+ @echo ------------ $@ ------------
+ $(TCC) -run tcctest.c > test.out1
+ @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
+
+# iterated test2 (compile tcc then compile tcctest.c !)
+test2: test.ref
+ @echo ------------ $@ ------------
+ $(TCC) $(RUN_TCC) $(RuN_TCC) -run tcctest.c > test.out2
+ @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
+
+# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
+test3: test.ref
+ @echo ------------ $@ ------------
+ $(TCC) $(RUN_TCC) $(RuN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
+ @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
+
+# binary output test
+test4: test.ref
+ @echo ------------ $@ ------------
+# dynamic output
+ $(TCC) -o tcctest1 tcctest.c
+ ./tcctest1 > test1.out
+ @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
+# object + link output
+ $(TCC) -c -o tcctest3.o tcctest.c
+ $(TCC) -o tcctest3 tcctest3.o
+ ./tcctest3 > test3.out
+ @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
+# static output
+ $(TCC) -static -o tcctest2 tcctest.c
+ ./tcctest2 > test2.out
+ @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
+# dynamic output + bound check
+ $(TCC) -b -o tcctest4 tcctest.c
+ ./tcctest4 > test4.out
+ @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
+
+# memory and bound check auto test
+BOUNDS_OK = 1 4 8 10
+BOUNDS_FAIL= 2 5 7 9 11 12 13
+
+btest: boundtest.c
+ @echo ------------ $@ ------------
+ @for i in $(BOUNDS_OK); do \
+ if $(TCC) -b -run boundtest.c $$i ; then \
+ /bin/true ; \
+ else\
+ echo Failed positive test $$i ; exit 1 ; \
+ fi ;\
+ done ;\
+ for i in $(BOUNDS_FAIL); do \
+ if $(TCC) -b -run boundtest.c $$i ; then \
+ echo Failed negative test $$i ; exit 1 ;\
+ else\
+ /bin/true ; \
+ fi ;\
+ done ;\
+ echo Bound test OK
+
+# speed test
+speed: ex2 ex3
+ @echo ------------ $@ ------------
+ time ./ex2 1238 2 3 4 10 13 4
+ time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
+ time ./ex3 35
+ time $(TCC) -run ../examples/ex3.c 35
+
+ex%: ../examples/ex%.c
+ $(CC) -o $@ $< $(CFLAGS)
+
+# tiny assembler testing
+asmtest.ref: asmtest.S
+ $(CC) -o asmtest.ref.o -c asmtest.S
+ objdump -D asmtest.ref.o > $@
+
+asmtest: asmtest.ref
+ @echo ------------ $@ ------------
+ $(TCC) -c asmtest.S
+ objdump -D asmtest.o > $@
+ @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
+
+# targets for development
+%.bin: %.c tcc
+ $(TCC) -g -o $@ $<
+ $(DISAS) $@
+
+instr: instr.o
+ objdump -d instr.o
+
+instr.o: instr.S
+ $(CC) -o $@ -c $< -O2 -Wall -g
+
+cache: tcc_g
+ cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
+ vg_annotate tcc.c > /tmp/linpack.cache.log
+
+# clean
+clean:
+ rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.gcc \
+ tcctest[1234] ex? libtcc_test tcc_g
diff --git a/tests/tcctest.c b/tests/tcctest.c
index 6c40245..55e356e 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -1,7 +1,7 @@
/*
* TCC auto test program
*/
-#include "config.h"
+#include "../config.h"
#if GCC_MAJOR >= 3
diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat
index 5e8c0f5..8821345 100644
--- a/win32/build-tcc.bat
+++ b/win32/build-tcc.bat
@@ -21,8 +21,8 @@ copy ..\libtcc.h libtcc
.\tcc -c lib/dllcrt1.c
.\tcc -c lib/dllmain.c
.\tcc -c lib/chkstk.S
-.\tcc -c ../libtcc1.c
-.\tcc -c ../alloca86.S
-.\tcc -c ../alloca86-bt.S
+.\tcc -c ../lib/libtcc1.c
+.\tcc -c ../lib/alloca86.S
+.\tcc -c ../lib/alloca86-bt.S
ar rcs lib/libtcc1.a crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o libtcc1.o alloca86.o alloca86-bt.o
del *.o