Michael Ellerman | 84f887b | 2015-03-04 21:41:31 +1100 | [diff] [blame] | 1 | # This mimics the top-level Makefile. We do it explicitly here so that this |
| 2 | # Makefile can operate with or without the kbuild infrastructure. |
| 3 | CC := $(CROSS_COMPILE)gcc |
| 4 | |
Shuah Khan | e53aff4 | 2017-03-01 15:15:07 -0700 | [diff] [blame] | 5 | ifeq (0,$(MAKELEVEL)) |
| 6 | OUTPUT := $(shell pwd) |
| 7 | endif |
| 8 | |
Michael Ellerman | d83c3ba | 2017-02-09 19:56:26 +1100 | [diff] [blame] | 9 | TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) |
| 10 | TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) |
| 11 | |
| 12 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) |
| 13 | |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 14 | .ONESHELL: |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 15 | define RUN_TESTS |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 16 | @test_num=`echo 0`; |
| 17 | @echo "TAP version 13"; |
| 18 | @for TEST in $(1); do \ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 19 | BASENAME_TEST=`basename $$TEST`; \ |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 20 | test_num=`echo $$test_num+1 | bc`; \ |
| 21 | echo "selftests: $$BASENAME_TEST"; \ |
| 22 | echo "========================================"; \ |
Luis R. Rodriguez | 43c6437 | 2017-08-03 13:24:36 -0700 | [diff] [blame] | 23 | if [ ! -x $$BASENAME_TEST ]; then \ |
| 24 | echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 25 | echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ |
Luis R. Rodriguez | 43c6437 | 2017-08-03 13:24:36 -0700 | [diff] [blame] | 26 | else \ |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 27 | 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. Rodriguez | 43c6437 | 2017-08-03 13:24:36 -0700 | [diff] [blame] | 28 | fi; \ |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 29 | done; |
| 30 | endef |
| 31 | |
| 32 | run_tests: all |
Shuah Khan | 77d802e | 2017-08-23 14:42:44 -0600 | [diff] [blame] | 33 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS)) |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 34 | |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 35 | define INSTALL_RULE |
Bamvor Jian Zhang | 900d65e | 2015-09-09 21:06:28 +0800 | [diff] [blame] | 36 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ |
| 37 | mkdir -p ${INSTALL_PATH}; \ |
bamvor.zhangjian@huawei.com | 5fe5979 | 2016-11-29 19:55:48 +0800 | [diff] [blame] | 38 | 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.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 40 | 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 Zhang | a7d0f07 | 2015-08-14 21:43:35 +0800 | [diff] [blame] | 45 | fi |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 46 | endef |
| 47 | |
| 48 | install: all |
| 49 | ifdef INSTALL_PATH |
| 50 | $(INSTALL_RULE) |
| 51 | else |
| 52 | $(error Error: set INSTALL_PATH to use install) |
| 53 | endif |
| 54 | |
| 55 | define EMIT_TESTS |
bamvor.zhangjian@huawei.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 56 | @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 57 | BASENAME_TEST=`basename $$TEST`; \ |
| 58 | echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \ |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 59 | done; |
| 60 | endef |
| 61 | |
| 62 | emit_tests: |
| 63 | $(EMIT_TESTS) |
| 64 | |
Shuah Khan | df6438f | 2017-04-21 16:07:51 -0600 | [diff] [blame] | 65 | define CLEAN |
bamvor.zhangjian@huawei.com | 80d443e8 | 2016-11-29 19:55:51 +0800 | [diff] [blame] | 66 | $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) |
Shuah Khan | df6438f | 2017-04-21 16:07:51 -0600 | [diff] [blame] | 67 | endef |
| 68 | |
| 69 | clean: |
| 70 | $(CLEAN) |
bamvor.zhangjian@huawei.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 71 | |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 72 | $(OUTPUT)/%:%.c |
Michael Ellerman | 2047f1d | 2017-02-09 19:56:27 +1100 | [diff] [blame] | 73 | $(LINK.c) $^ $(LDLIBS) -o $@ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 74 | |
| 75 | $(OUTPUT)/%.o:%.S |
Michael Ellerman | 634ce97 | 2017-02-09 19:56:28 +1100 | [diff] [blame] | 76 | $(COMPILE.S) $^ -o $@ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 77 | |
| 78 | $(OUTPUT)/%:%.S |
Michael Ellerman | 634ce97 | 2017-02-09 19:56:28 +1100 | [diff] [blame] | 79 | $(LINK.S) $^ $(LDLIBS) -o $@ |
bamvor.zhangjian@huawei.com | 7d758af | 2016-11-29 19:55:49 +0800 | [diff] [blame] | 80 | |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 81 | .PHONY: run_tests all clean install emit_tests |