fix makefiles etc for subdirs

tcc-xref
grischka 2009-04-18 14:31:35 +02:00
parent ea5e81bd6a
commit 5829791ffa
13 changed files with 325 additions and 284 deletions

415
Makefile
View File

@ -1,7 +1,9 @@
#
# Tiny C Compiler Makefile
#
include config.mak
TOP ?= .
include $(TOP)/config.mak
TARGET=
CFLAGS+=-g -Wall
@ -33,311 +35,194 @@ 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),.)
PROGS=tcc$(EXESUF)
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=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
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
endif
ifdef CONFIG_CROSS
PROGS+=c67-tcc$(EXESUF) i386-win32-tcc$(EXESUF)
endif
endif
ifeq ($(ARCH),x86-64)
PROGS=tcc$(EXESUF)
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_USE_LIBGCC
LIBTCC1=
else
ifdef CONFIG_CROSS
PROGS+=$(PROGS_CROSS)
endif
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) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
all: $(PROGS) \
$(LIBTCC1) $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \
libtcc_test$(EXESUF)
Makefile: config.mak
# auto test
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 $@ $<
test.ref: tcctest.ref
./tcctest.ref > $@
test.out: tcc tcctest.c
$(TCC) -run tcctest.c > $@
run: tcc tcctest.c
$(TCC) -run tcctest.c
# 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
# 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
# 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
# memory and bound check auto test
BOUNDS_OK = 1 4 8 10
BOUNDS_FAIL= 2 5 7 9 11 12 13
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
# 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
ex2: ex2.c
$(CC) $(CFLAGS) -o $@ $<
ex3: ex3.c
$(CC) $(CFLAGS) -o $@ $<
TCC_CORE_FILES = tcc.c tccelf.c tccasm.c tcctok.h libtcc.h config.h
# Host Tiny C Compiler
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)
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)
endif
ifeq ($(ARCH),arm)
tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
$(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
else ifeq ($(ARCH),i386)
tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
$(CC) -o $@ $< $(CFLAGS) $(LIBS)
else ifeq ($(ARCH),x86-64)
tcc$(EXESUF): $(TCC_CORE_FILES) x86_64-gen.c
$(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
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.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
tcc$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
$(CC) -o $@ $< -DTCC_TARGET_ARM $(ARMFLAGS) $(CFLAGS) $(LIBS)
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)
i386-tcc$(EXESUF): $(TCC_CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
$(CC) -o $@ $< $(CFLAGS) $(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)
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)
arm-tcc-fpa$(EXESUF): tcc.c arm-gen.c tccelf.c tccasm.c tcctok.h libtcc.h
$(CC) $(CFLAGS) -DTCC_TARGET_ARM -o $@ $< $(LIBS)
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)
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)
c67-tcc$(EXESUF): $(TCC_CORE_FILES) c67-gen.c tcccoff.c
$(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
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)
arm-tcc-fpa$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
$(CC) -o $@ $< -DTCC_TARGET_ARM $(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)
arm-tcc-fpa-ld$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
$(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
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)
arm-tcc-vfp$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
$(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
arm-tcc-vfp-eabi$(EXESUF): $(TCC_CORE_FILES) arm-gen.c
$(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
# libtcc generation and test
libtcc.o: tcc.c i386-gen.c
ifdef CONFIG_WIN32
$(CC) -o $@ -c $< -DTCC_TARGET_PE -DLIBTCC $(CFLAGS)
else
$(CC) -o $@ -c $< $(TARGET) -DLIBTCC $(CFLAGS)
endif
libtcc.a: libtcc.o
$(AR) rcs $@ $^
libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
$(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
./libtcc_test$(EXESUF) lib_path=.
# 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
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_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
else
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+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
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"
ifneq ($(BCHECK_O),)
$(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
endif
$(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)"
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"
else
ifndef CONFIG_USE_LIBGCC
$(INSTALL) -m644 libtcc1.a "$(DESTDIR)$(tccdir)"
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
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"
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
distclean: clean
rm -f config.h config.mak config.texi
# profiling version
tcc_p: tcc.c Makefile
$(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P)
# 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 $@ $<
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
@ -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),.)

8
configure vendored
View File

@ -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

View File

@ -1,7 +1,7 @@
#! /usr/local/bin/tcc -run
#include <tcclib.h>
int main()
int main()
{
printf("Hello World\n");
return 0;

View File

@ -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]);
}

View File

@ -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;

View File

@ -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);

View File

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
int main()
int main()
{
printf("Hello World\n");
return 0;

View File

@ -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;

View File

@ -1,7 +1,7 @@
/* ---------------------------------------------- */
/* alloca86b.S */
#include "config.h"
#include "../config.h"
.globl __bound__alloca

View File

@ -1,7 +1,7 @@
/* ---------------------------------------------- */
/* alloca86.S */
#include "config.h"
#include "../config.h"
.globl _alloca

144
tests/Makefile 100644
View File

@ -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

View File

@ -1,7 +1,7 @@
/*
* TCC auto test program
*/
#include "config.h"
#include "../config.h"
#if GCC_MAJOR >= 3

View File

@ -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