Index: EcnlProtoTool/trunk/tcc-0.9.27/tests/Makefile
===================================================================
--- EcnlProtoTool/trunk/tcc-0.9.26/tests/Makefile	(revision 279)
+++ EcnlProtoTool/trunk/tcc-0.9.27/tests/Makefile	(revision 331)
@@ -5,5 +5,6 @@
 TOP = ..
 include $(TOP)/Makefile
-VPATH = $(top_srcdir)/tests
+VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
+CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
 
 # what tests to run
@@ -13,114 +14,138 @@
  libtest \
  test3 \
- moretests
+ memtest \
+ dlltest \
+ abitest \
+ asm-c-connect-test \
+ vla_test-run \
+ cross-test \
+ tests2-dir \
+ pp-dir
+
+BTESTS = test1b test3b btest
 
 # test4 -- problem with -static
-# asmtest -- minor differences with gcc
+# asmtest / asmtest2 -- minor differences with gcc
 # btest -- works on i386 (including win32)
-# test3 -- win32 does not know how to printf long doubles
 
 # bounds-checking is supported only on i386
 ifneq ($(ARCH),i386)
- TESTS := $(filter-out btest,$(TESTS))
+ TESTS := $(filter-out $(BTESTS),$(TESTS))
 endif
 ifdef CONFIG_WIN32
+ TESTS := $(filter-out $(BTESTS),$(TESTS))
+endif
+ifdef CONFIG_OSX # -run only
+ TESTS := hello-run libtest tests2-dir pp-dir
+endif
+ifeq (,$(filter arm64 i386 x86_64,$(ARCH)))
+ TESTS := $(filter-out vla_test-run,$(TESTS))
+endif
+ifeq ($(CONFIG_arm_eabi),yes)
  TESTS := $(filter-out test3,$(TESTS))
 endif
-ifeq ($(TARGETOS),Darwin)
- TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
-endif
-
-ifdef DISABLE_STATIC
- export LD_LIBRARY_PATH:=$(CURDIR)/..
-endif
-
-ifeq ($(TARGETOS),Darwin)
- CFLAGS+=-Wl,-flat_namespace,-undefined,warning
- export MACOSX_DEPLOYMENT_TARGET:=10.2
- NATIVE_DEFINES+=-D_ANSI_SOURCE
-endif
-
-# run local version of tcc with local libraries and includes
-TCCFLAGS = -B$(TOP)
-ifdef CONFIG_WIN32
- TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP)
-endif
-
-TCC = $(TOP)/tcc $(TCCFLAGS)
-RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS)
-
+ifeq (,$(filter i386 x86_64,$(ARCH)))
+ TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS))
+endif
+ifndef CONFIG_cross
+ TESTS := $(filter-out cross-%,$(TESTS))
+endif
+
+ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll
+ PATH := $(CURDIR)/$(TOP)$(if $(findstring :\,$(PATH)),;,:)$(PATH)
+endif
+
+RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS)
 DISAS = objdump -d
-
-# libtcc test
-ifdef LIBTCC1
- LIBTCC1:=$(TOP)/$(LIBTCC1)
-endif
-
-all test : $(TESTS)
+DUMPTCC = (set -x; $(TOP)/tcc -vv; ldd $(TOP)/tcc; exit 1)
+
+all test : clean-s $(TESTS)
 
 hello-exe: ../examples/ex1.c
 	@echo ------------ $@ ------------
-	$(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
+	$(TCC) $< -o hello$(EXESUF) && ./hello$(EXESUF) || $(DUMPTCC)
 
 hello-run: ../examples/ex1.c
 	@echo ------------ $@ ------------
-	$(TCC) -run $<
-
-libtest: libtcc_test$(EXESUF) $(LIBTCC1)
-	@echo ------------ $@ ------------
-	./libtcc_test$(EXESUF) lib_path=..
-
-libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
-	$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
-
-moretests:
-	@echo ------------ $@ ------------
-	$(MAKE) -C tests2
-
-# test.ref - generate using gcc
-# copy only tcclib.h so GCC's stddef and stdarg will be used
+	$(TCC) -run $< || $(DUMPTCC)
+
+libtest: libtcc_test$(EXESUF)
+	@echo ------------ $@ ------------
+	./libtcc_test$(EXESUF) $(TCCFLAGS)
+
+libtcc_test$(EXESUF): libtcc_test.c $(LIBTCC)
+	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+
+%-dir:
+	@echo ------------ $@ ------------
+	$(MAKE) -k -C $*
+
+# test.ref - generate using cc
 test.ref: tcctest.c
-	cp ../include/tcclib.h .
-	gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
+	$(CC) -o tcctest.gcc $< $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
 	./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
+test1 test1b: tcctest.c test.ref
+	@echo ------------ $@ ------------
+	$(TCC) -run $< > test.out1
+	@diff -u test.ref test.out1 && echo "Auto Test OK"
 
 # 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
+test2 test2b: tcctest.c test.ref
+	@echo ------------ $@ ------------
+	$(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
+	@diff -u test.ref test.out2 && echo "Auto Test2 OK"
 
 # 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
+test3 test3b: tcctest.c test.ref
+	@echo ------------ $@ ------------
+	$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
+	@diff -u test.ref test.out3 && echo "Auto Test3 OK"
+
+test%b : TCCFLAGS += -b
 
 # binary output test
-test4: test.ref
+test4: tcctest.c test.ref
 	@echo ------------ $@ ------------
 # object + link output
-	$(TCC) -c -o tcctest3.o tcctest.c
+	$(TCC) -c -o tcctest3.o $<
 	$(TCC) -o tcctest3 tcctest3.o
 	./tcctest3 > test3.out
 	@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
 # dynamic output
-	$(TCC) -o tcctest1 tcctest.c
+	$(TCC) -o tcctest1 $<
 	./tcctest1 > test1.out
 	@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
 # dynamic output + bound check
-	$(TCC) -b -o tcctest4 tcctest.c
+	$(TCC) -b -o tcctest4 $<
 	./tcctest4 > test4.out
 	@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
 # static output
-	$(TCC) -static -o tcctest2 tcctest.c
+	$(TCC) -static -o tcctest2 $<
 	./tcctest2 > test2.out
 	@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
+
+# use tcc to create libtcc.so/.dll and the tcc(.exe) frontend and run them
+dlltest:
+	@echo ------------ $@ ------------
+	$(TCC) $(NATIVE_DEFINES) -DLIBTCC_AS_DLL $(TOPSRC)/libtcc.c $(LIBS) -shared -o libtcc2$(DLLSUF)
+	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
+	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
+ifndef CONFIG_WIN32
+	@echo ------------ $@ with PIC ------------
+	$(CC) $(CFLAGS) -fPIC $(NATIVE_DEFINES) -DLIBTCC_AS_DLL -c $(TOPSRC)/libtcc.c
+	$(TCC) libtcc.o $(LIBS) -shared -o libtcc2$(DLLSUF)
+	$(TCC) $(NATIVE_DEFINES) -DONE_SOURCE=0 $(TOPSRC)/tcc.c libtcc2$(DLLSUF) $(LIBS) -Wl,-rpath=. -o tcc2$(EXESUF)
+	./tcc2$(EXESUF) $(TCCFLAGS) $(RUN_TCC) -run $(TOPSRC)/examples/ex1.c
+endif
+	@rm tcc2$(EXESUF) libtcc2$(DLLSUF)
+
+memtest:
+	@echo ------------ $@ ------------
+	$(CC) $(CFLAGS) $(NATIVE_DEFINES) -DMEM_DEBUG=2 $(TOPSRC)/tcc.c $(LIBS) -o memtest-tcc$(EXESUF)
+	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) $(TOPSRC)/tcc.c $(LIBS)
+	./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) $(TOPSRC)/tests/tcctest.c
+
 
 # memory and bound check auto test
@@ -132,6 +157,6 @@
 	@for i in $(BOUNDS_OK); do \
 	   echo ; echo --- boundtest $$i ---; \
-	   if $(TCC) -b -run boundtest.c $$i ; then \
-	       echo succeded as expected; \
+	   if $(TCC) -b -run $< $$i ; then \
+	       echo succeeded as expected; \
 	   else\
 	       echo Failed positive test $$i ; exit 1 ; \
@@ -140,5 +165,5 @@
 	for i in $(BOUNDS_FAIL); do \
 	   echo ; echo --- boundtest $$i ---; \
-	   if $(TCC) -b -run boundtest.c $$i ; then \
+	   if $(TCC) -b -run $< $$i ; then \
 	       echo Failed negative test $$i ; exit 1 ;\
 	   else\
@@ -152,17 +177,17 @@
 	@echo ------------ $@ ------------
 	time ./ex2 1238 2 3 4 10 13 4
-	time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
+	time $(TCC) -run $(TOPSRC)/examples/ex2.c 1238 2 3 4 10 13 4
 	time ./ex3 35
-	time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
-
-weaktest: test.ref
-	$(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
-	 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
+	time $(TCC) -run $(TOPSRC)/examples/ex3.c 35
+
+weaktest: tcctest.c test.ref
+	$(TCC) -c $< -o weaktest.tcc.o
+	$(CC) -c $< -o weaktest.gcc.o $(NATIVE_DEFINES) $(CFLAGS) -w -O0 -std=gnu99 -fno-omit-frame-pointer
 	objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
 	objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
 	diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
 
-ex%: $(top_srcdir)/examples/ex%.c
-	$(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
+ex%: $(TOPSRC)/examples/ex%.c
+	$(CC) -o $@ $< $(CFLAGS)
 
 # tiny assembler testing
@@ -171,9 +196,68 @@
 	objdump -D asmtest.ref.o > asmtest.ref
 
-asmtest: asmtest.ref
-	@echo ------------ $@ ------------
-	$(TCC) -c asmtest.S
+asmtest asmtest2: asmtest.ref
+	@echo ------------ $@ ------------
+	$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
 	objdump -D asmtest.o > asmtest.out
 	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
+
+# test assembler with tcc compiled by itself
+asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
+
+# Check that code generated by libtcc is binary compatible with
+# that generated by CC
+abitest-cc$(EXESUF): abitest.c $(LIBTCC)
+	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -w
+
+abitest-tcc$(EXESUF): abitest.c libtcc.c
+	$(TCC) -o $@ $^ $(NATIVE_DEFINES) $(LIBS)
+
+ABITESTS := abitest-cc$(EXESUF)
+ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
+ ABITESTS += abitest-tcc$(EXESUF)
+endif
+
+abitest: $(ABITESTS)
+	@echo ------------ $@ ------------
+	./abitest-cc$(EXESUF) $(TCCFLAGS)
+ifneq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
+	./abitest-tcc$(EXESUF) $(TCCFLAGS)
+endif
+
+vla_test$(EXESUF): vla_test.c
+	$(TCC) -o $@ $^
+
+vla_test-run: vla_test$(EXESUF)
+	@echo ------------ $@ ------------
+	./vla_test$(EXESUF)
+
+asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
+	$(TCC) -o $@ $^
+
+asm-c-connect-%.o: asm-c-connect-%.c
+	$(TCC) -c -o $@ $<
+
+asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
+	$(TCC) -o $@ $^
+
+asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
+	@echo ------------ $@ ------------
+	./asm-c-connect$(EXESUF) > asm-c-connect.out1 && cat asm-c-connect.out1
+	./asm-c-connect-sep$(EXESUF) > asm-c-connect.out2 && cat asm-c-connect.out2
+	@diff -u asm-c-connect.out1 asm-c-connect.out2 && echo "ok"
+
+cross-test :
+	@echo ------------ $@ ------------
+	$(TOP)/i386-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/x86_64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/arm-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/arm64-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/c67-tcc$(EXESUF) $(TCCFLAGS-unx) -c $(TOPSRC)/examples/ex3.c && echo "ok"
+	$(TOP)/i386-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
+	$(TOP)/x86_64-win32-tcc$(EXESUF) $(TCCFLAGS-win) $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
+	$(TOP)/arm-wince-tcc$(EXESUF) $(TCCFLAGS-win) -c $(TOPSRC)/win32/examples/hello_win.c && echo "ok"
 
 # targets for development
@@ -194,6 +278,12 @@
 # clean
 clean:
-	$(MAKE) -C tests2 $@
-	rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
-	   hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
-
+	rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc
+	rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234]
+	rm -f asm-c-connect$(EXESUF)
+	rm -f ex? tcc_g weaktest.*.txt *.def
+	@$(MAKE) -C tests2 $@
+	@$(MAKE) -C pp $@
+
+# silent clean, used before running tests
+clean-s:
+	@$(MAKE) -s --no-print-directory clean
