modernc.org/cc@v1.0.1/v2/testdata/tcc-0.9.26/tests/Makefile (about)

     1  #
     2  # Tiny C Compiler Makefile - tests
     3  #
     4  
     5  TOP = ..
     6  include $(TOP)/Makefile
     7  VPATH = $(top_srcdir)/tests
     8  
     9  # what tests to run
    10  TESTS = \
    11   hello-exe \
    12   hello-run \
    13   libtest \
    14   test3 \
    15   moretests
    16  
    17  # test4 -- problem with -static
    18  # asmtest -- minor differences with gcc
    19  # btest -- works on i386 (including win32)
    20  # test3 -- win32 does not know how to printf long doubles
    21  
    22  # bounds-checking is supported only on i386
    23  ifneq ($(ARCH),i386)
    24   TESTS := $(filter-out btest,$(TESTS))
    25  endif
    26  ifdef CONFIG_WIN32
    27   TESTS := $(filter-out test3,$(TESTS))
    28  endif
    29  ifeq ($(TARGETOS),Darwin)
    30   TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
    31  endif
    32  
    33  ifdef DISABLE_STATIC
    34   export LD_LIBRARY_PATH:=$(CURDIR)/..
    35  endif
    36  
    37  ifeq ($(TARGETOS),Darwin)
    38   CFLAGS+=-Wl,-flat_namespace,-undefined,warning
    39   export MACOSX_DEPLOYMENT_TARGET:=10.2
    40   NATIVE_DEFINES+=-D_ANSI_SOURCE
    41  endif
    42  
    43  # run local version of tcc with local libraries and includes
    44  TCCFLAGS = -B$(TOP)
    45  ifdef CONFIG_WIN32
    46   TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP)
    47  endif
    48  
    49  TCC = $(TOP)/tcc $(TCCFLAGS)
    50  RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(TOP)/tcc.c $(TCCFLAGS)
    51  
    52  DISAS = objdump -d
    53  
    54  # libtcc test
    55  ifdef LIBTCC1
    56   LIBTCC1:=$(TOP)/$(LIBTCC1)
    57  endif
    58  
    59  all test : $(TESTS)
    60  
    61  hello-exe: ../examples/ex1.c
    62  	@echo ------------ $@ ------------
    63  	$(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
    64  
    65  hello-run: ../examples/ex1.c
    66  	@echo ------------ $@ ------------
    67  	$(TCC) -run $<
    68  
    69  libtest: libtcc_test$(EXESUF) $(LIBTCC1)
    70  	@echo ------------ $@ ------------
    71  	./libtcc_test$(EXESUF) lib_path=..
    72  
    73  libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
    74  	$(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
    75  
    76  moretests:
    77  	@echo ------------ $@ ------------
    78  	$(MAKE) -C tests2
    79  
    80  # test.ref - generate using gcc
    81  # copy only tcclib.h so GCC's stddef and stdarg will be used
    82  test.ref: tcctest.c
    83  	cp ../include/tcclib.h .
    84  	gcc -o tcctest.gcc $< -I. $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS)
    85  	./tcctest.gcc > $@
    86  
    87  # auto test
    88  test1: test.ref
    89  	@echo ------------ $@ ------------
    90  	$(TCC) -run tcctest.c > test.out1
    91  	@if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
    92  
    93  # iterated test2 (compile tcc then compile tcctest.c !)
    94  test2: test.ref
    95  	@echo ------------ $@ ------------
    96  	$(TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out2
    97  	@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
    98  
    99  # iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
   100  test3: test.ref
   101  	@echo ------------ $@ ------------
   102  	$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run tcctest.c > test.out3
   103  	@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
   104  
   105  # binary output test
   106  test4: test.ref
   107  	@echo ------------ $@ ------------
   108  # object + link output
   109  	$(TCC) -c -o tcctest3.o tcctest.c
   110  	$(TCC) -o tcctest3 tcctest3.o
   111  	./tcctest3 > test3.out
   112  	@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
   113  # dynamic output
   114  	$(TCC) -o tcctest1 tcctest.c
   115  	./tcctest1 > test1.out
   116  	@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
   117  # dynamic output + bound check
   118  	$(TCC) -b -o tcctest4 tcctest.c
   119  	./tcctest4 > test4.out
   120  	@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
   121  # static output
   122  	$(TCC) -static -o tcctest2 tcctest.c
   123  	./tcctest2 > test2.out
   124  	@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
   125  
   126  # memory and bound check auto test
   127  BOUNDS_OK  = 1 4 8 10 14
   128  BOUNDS_FAIL= 2 5 7 9 11 12 13 15
   129  
   130  btest: boundtest.c
   131  	@echo ------------ $@ ------------
   132  	@for i in $(BOUNDS_OK); do \
   133  	   echo ; echo --- boundtest $$i ---; \
   134  	   if $(TCC) -b -run boundtest.c $$i ; then \
   135  	       echo succeded as expected; \
   136  	   else\
   137  	       echo Failed positive test $$i ; exit 1 ; \
   138  	   fi ;\
   139  	done ;\
   140  	for i in $(BOUNDS_FAIL); do \
   141  	   echo ; echo --- boundtest $$i ---; \
   142  	   if $(TCC) -b -run boundtest.c $$i ; then \
   143  	       echo Failed negative test $$i ; exit 1 ;\
   144  	   else\
   145  	       echo failed as expected; \
   146  	   fi ;\
   147  	done ;\
   148  	echo; echo Bound test OK
   149  
   150  # speed test
   151  speedtest: ex2 ex3
   152  	@echo ------------ $@ ------------
   153  	time ./ex2 1238 2 3 4 10 13 4
   154  	time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
   155  	time ./ex3 35
   156  	time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
   157  
   158  weaktest: test.ref
   159  	$(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
   160  	 $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
   161  	objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
   162  	objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
   163  	diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
   164  
   165  ex%: $(top_srcdir)/examples/ex%.c
   166  	$(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
   167  
   168  # tiny assembler testing
   169  asmtest.ref: asmtest.S
   170  	$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
   171  	objdump -D asmtest.ref.o > asmtest.ref
   172  
   173  asmtest: asmtest.ref
   174  	@echo ------------ $@ ------------
   175  	$(TCC) -c asmtest.S
   176  	objdump -D asmtest.o > asmtest.out
   177  	@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
   178  
   179  # targets for development
   180  %.bin: %.c tcc
   181  	$(TCC) -g -o $@ $<
   182  	$(DISAS) $@
   183  
   184  instr: instr.o
   185  	objdump -d instr.o
   186  
   187  instr.o: instr.S
   188  	$(CC) -o $@ -c $< -O2 -Wall -g
   189  
   190  cache: tcc_g
   191  	cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c
   192  	vg_annotate tcc.c > /tmp/linpack.cache.log
   193  
   194  # clean
   195  clean:
   196  	$(MAKE) -C tests2 $@
   197  	rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
   198  	   hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
   199