working on adding code to generate the c++ header from the libre-soc spec csv files
[simplev-cpp.git] / Makefile
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
3 .PHONY: all tests clean fix-tests
4
5 CC = powerpc64le-linux-gnu-gcc
6 CXX = powerpc64le-linux-gnu-g++
7 CFLAGS = -O3 -Iinclude -g0 -mno-altivec -mno-vsx -Wall
8 CXXFLAGS = -std=gnu++17
9
10 all: tests
11
12 TESTS_SOURCE := $(wildcard tests/*/test.cpp) $(wildcard tests/*/test.c)
13 TESTS_DIR := $(dir $(TESTS_SOURCE))
14 TESTS_BUILD_DIR := $(addprefix build/,$(TESTS_DIR))
15 TESTS_DIFF := $(addsuffix diff.txt,$(TESTS_BUILD_DIR))
16 TESTS_FILTERED_OUT := $(addsuffix filtered-out.s,$(TESTS_BUILD_DIR))
17 EXTRA_DEPS := Makefile $(wildcard include/*.h)
18
19 build/tests/%/:
20 mkdir -p $@
21
22 build/tests/%/out.s: tests/%/test.cpp $(EXTRA_DEPS) | build/tests/%/
23 $(CXX) -S $(CFLAGS) $(CXXFLAGS) $< -o $@
24
25 build/tests/%/out.s: tests/%/test.c $(EXTRA_DEPS) | build/tests/%/
26 $(CC) -S $(CFLAGS) $< -o $@
27
28 build/tests/%/filtered-out.s: build/tests/%/out.s $(EXTRA_DEPS)
29 sed 's/\(^\t.ident\t"\).*"/\1GCC"/' < $< > $@
30
31 build/tests/%/diff.txt: tests/%/expected.s build/tests/%/filtered-out.s $(EXTRA_DEPS)
32 diff -u $< build/$(dir $<)filtered-out.s > $@ || true
33
34 .PRECIOUS: build/tests/%/out.s build/tests/%/filtered-out.s build/tests/%/
35
36 tests: $(TESTS_DIFF)
37 @failed=0; \
38 for i in $+; do \
39 if [ -s "$$i" -o ! -e "$$i" ]; then \
40 echo "Test failed: $$i" >&2; \
41 head -n 10 "$$i" >&2; \
42 failed=$$((failed + 1)); \
43 fi; \
44 done; \
45 if [ $$((failed)) != 0 ]; then \
46 echo "$$failed test(s) failed" >&2; \
47 false; \
48 else \
49 echo "all tests passed"; \
50 fi
51
52 fix-tests: $(TESTS_FILTERED_OUT)
53 @for i in $(TESTS_FILTERED_OUT); do \
54 target="$$(dirname "$${i##build/}")/expected.s"; \
55 status=""; \
56 [ "$(FORCE_FIX_TESTS)" = "$$target" ] || status="$$(git status --porcelain "$$target")"; \
57 if [ -z "$$status" ]; then \
58 cp -v "$$i" "$$target"; \
59 elif ! cmp "$$i" "$$target"; then \
60 echo "$$target has uncommitted changes, not overwriting -- commit changes or run make with FORCE_FIX_TESTS=$$target" >&2; \
61 exit 1; \
62 fi; \
63 done
64
65 clean:
66 rm -rf build/tests