tcc -dt -run ... : simpler is better
[tinycc.git] / tests / tests2 / Makefile
blob4dd1591d5fb937902f8c023cfc7ab4b93eaaa97a
1 TOP = ../..
2 include $(TOP)/Makefile
3 SRC = $(TOPSRC)/tests/tests2
4 VPATH = $(SRC)
6 TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c))))
8 # some tests do not pass on all platforms, remove them for now
9 SKIP = 34_array_assignment.test # array assignment is not in C standard
10 ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
11 SKIP += 22_floating_point.test
12 endif
13 ifdef CONFIG_OSX
14 SKIP += 40_stdio.test 42_function_pointer.test
15 FLAGS += -w
16 endif
17 ifeq ($(ARCH),x86_64)
18 SKIP += 73_arm64.test
19 endif
20 ifeq (,$(filter i386 x86_64,$(ARCH)))
21 SKIP += 85_asm-outside-function.test
22 endif
23 ifeq (-$(findstring gcc,$(CC))-,--)
24 SKIP += $(patsubst %.expect,%.test,$(GEN-ALWAYS))
25 endif
26 ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-)
27 SKIP += 95_bitfields_ms.test # type_align is differnt on 32bit-non-windows
28 endif
30 # Some tests might need arguments
31 ARGS =
32 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
33 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c
35 # And some tests don't test the right thing with -run
36 NORUN =
37 42_function_pointer.test : NORUN = true
39 # Some tests might need different flags
40 FLAGS =
41 76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers
43 # These tests run several snippets from the same file one by one
44 60_errors_and_warnings.test : FLAGS += -dt
45 96_nodata_wanted.test : FLAGS += -dt
47 # Always generate certain .expects (don't put these in the GIT),
48 GEN-ALWAYS =
49 GEN-ALWAYS += 95_bitfields.expect
51 # using the ms compiler for the really ms-compatible bitfields
52 95_bitfields_ms.test : GEN = $(GEN-MSC)
54 # Filter source directory in warnings/errors (out-of-tree builds)
55 FILTER = 2>&1 | sed 's,$(SRC)/,,g'
56 # Filter some always-warning
57 ifeq (-$(findstring arm,$(ARCH))-,-arm-)
58 FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported'
59 endif
61 all test tests2.all: $(filter-out $(SKIP),$(TESTS)) ;
63 %.test: %.c %.expect
64 @echo Test: $*...
65 @$(if $(NORUN),$(T1),$(T2)) $(if $(NODIFF),,$(T3))
67 T1 = $(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS)
68 T2 = $(TCC) $(FLAGS) -run $< $(ARGS)
69 T3 = $(FILTER) >$*.output 2>&1 || true \
70 && diff -Nbu $(filter %.expect,$^) $*.output \
71 && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
73 # run single test and update .expect file, e.g. "make tests2.37+"
74 tests2.%+:
75 @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory
77 # just run tcc to see the output, e.g. "make tests2.37-"
78 tests2.%-:
79 @$(MAKE) $(call F1,$*) NODIFF=true --no-print-directory
81 # run single test, e.g. "make tests2.37"
82 tests2.%:
83 @$(MAKE) $(call F1,$*) --no-print-directory
85 F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test)
86 F2 = $1 UPDATE="$(patsubst %.test,%.expect,$1)"
88 # automatically generate .expect files with gcc:
89 %.expect :
90 @echo Generating: $@
91 @$(call GEN,$(SRC)/$*.c) $(FILTER) >$@ 2>&1
92 @rm -f *.exe *.obj *.pdb
94 # using TCC for .expect if -dt in FLAGS
95 GEN = $(if $(filter -dt,$(FLAGS)),$(GEN-TCC),$(GEN-CC))
96 GEN-CC = $(CC) -w -std=gnu99 $(FLAGS) $1 -o a.exe && ./a.exe $(ARGS)
97 GEN-TCC = $(TCC) $(FLAGS) -run $1 $(ARGS)
98 GEN-MSC = $(MS-CC) $1 && ./$(basename $@).exe
99 MS-CC = cl
101 # tell make not to delete
102 .PRECIOUS: %.expect
104 # force .expect generation for these files
105 $(sort $(GEN-ALWAYS) $(UPDATE)) : force
106 force:
108 clean:
109 rm -f fred.txt *.output a.exe $(GEN-ALWAYS)