blob: 693616651da5cbc27a779868e64697df80582ef3 [file] [log] [blame]
Michael Ellerman84f887b2015-03-04 21:41:31 +11001# This mimics the top-level Makefile. We do it explicitly here so that this
2# Makefile can operate with or without the kbuild infrastructure.
3CC := $(CROSS_COMPILE)gcc
4
Shuah Khane53aff42017-03-01 15:15:07 -07005ifeq (0,$(MAKELEVEL))
6OUTPUT := $(shell pwd)
7endif
8
Michael Ellermand83c3ba2017-02-09 19:56:26 +11009TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
10TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
11
12all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
13
Shuah Khan1f87c7c2017-08-23 18:46:00 -060014.ONESHELL:
Michael Ellerman5e29a912015-03-11 15:05:59 +110015define RUN_TESTS
Shuah Khan1f87c7c2017-08-23 18:46:00 -060016 @test_num=`echo 0`;
17 @echo "TAP version 13";
18 @for TEST in $(1); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080019 BASENAME_TEST=`basename $$TEST`; \
Shuah Khan1f87c7c2017-08-23 18:46:00 -060020 test_num=`echo $$test_num+1 | bc`; \
21 echo "selftests: $$BASENAME_TEST"; \
22 echo "========================================"; \
Luis R. Rodriguez43c64372017-08-03 13:24:36 -070023 if [ ! -x $$BASENAME_TEST ]; then \
24 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
Shuah Khan1f87c7c2017-08-23 18:46:00 -060025 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
Luis R. Rodriguez43c64372017-08-03 13:24:36 -070026 else \
Shuah Khan1f87c7c2017-08-23 18:46:00 -060027 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
Luis R. Rodriguez43c64372017-08-03 13:24:36 -070028 fi; \
Michael Ellerman5e29a912015-03-11 15:05:59 +110029 done;
30endef
31
32run_tests: all
Shuah Khan77d802e2017-08-23 14:42:44 -060033 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS))
Michael Ellerman5e29a912015-03-11 15:05:59 +110034
Michael Ellerman32dcfba2015-03-11 15:06:00 +110035define INSTALL_RULE
Bamvor Jian Zhang900d65e2015-09-09 21:06:28 +080036 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
37 mkdir -p ${INSTALL_PATH}; \
bamvor.zhangjian@huawei.com5fe59792016-11-29 19:55:48 +080038 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
39 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080040 fi
41 @if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
42 mkdir -p ${INSTALL_PATH}; \
43 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
44 rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
Bamvor Jian Zhanga7d0f072015-08-14 21:43:35 +080045 fi
Michael Ellerman32dcfba2015-03-11 15:06:00 +110046endef
47
48install: all
49ifdef INSTALL_PATH
50 $(INSTALL_RULE)
51else
52 $(error Error: set INSTALL_PATH to use install)
53endif
54
55define EMIT_TESTS
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080056 @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080057 BASENAME_TEST=`basename $$TEST`; \
58 echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
Michael Ellerman32dcfba2015-03-11 15:06:00 +110059 done;
60endef
61
62emit_tests:
63 $(EMIT_TESTS)
64
Shuah Khandf6438f2017-04-21 16:07:51 -060065define CLEAN
bamvor.zhangjian@huawei.com80d443e82016-11-29 19:55:51 +080066 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
Shuah Khandf6438f2017-04-21 16:07:51 -060067endef
68
69clean:
70 $(CLEAN)
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080071
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080072$(OUTPUT)/%:%.c
Michael Ellerman2047f1d2017-02-09 19:56:27 +110073 $(LINK.c) $^ $(LDLIBS) -o $@
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080074
75$(OUTPUT)/%.o:%.S
Michael Ellerman634ce972017-02-09 19:56:28 +110076 $(COMPILE.S) $^ -o $@
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080077
78$(OUTPUT)/%:%.S
Michael Ellerman634ce972017-02-09 19:56:28 +110079 $(LINK.S) $^ $(LDLIBS) -o $@
bamvor.zhangjian@huawei.com7d758af2016-11-29 19:55:49 +080080
Michael Ellerman32dcfba2015-03-11 15:06:00 +110081.PHONY: run_tests all clean install emit_tests