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.
6 CC := $(CROSS_COMPILE)gcc
10 OUTPUT := $(shell pwd)
13 # The following are built by lib.mk common compile rules.
14 # TEST_CUSTOM_PROGS should be used by tests that require
15 # custom build rule and prevent common build rule use.
16 # TEST_PROGS are for test shell scripts.
17 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
18 # and install targets. Common clean doesn't touch them.
19 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
20 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
21 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
23 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
28 @echo "TAP version 13";
29 @for TEST in $(1); do \
30 BASENAME_TEST=`basename $$TEST`; \
31 test_num=`echo $$test_num+1 | bc`; \
32 echo "selftests: $$BASENAME_TEST"; \
33 echo "========================================"; \
34 if [ ! -x $$TEST ]; then \
35 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
36 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
38 if [ "X$(summary)" != "X" ]; then \
39 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
41 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;\
48 ifneq ($(KBUILD_SRC),)
49 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
50 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
52 @if [ "X$(TEST_PROGS)" != "X" ]; then
53 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
55 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
58 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
61 define INSTALL_SINGLE_RULE
62 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH))
63 $(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
64 $(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
68 $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE)
69 $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
70 $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE)
71 $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE)
72 $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE)
73 $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
74 $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE)
81 $(error Error: set INSTALL_PATH to use install)
85 @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
86 BASENAME_TEST=`basename $$TEST`; \
87 echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
94 # define if isn't already. It is undefined in make O= case.
100 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
106 # Enables to extend CFLAGS and LDFLAGS from command line, e.g.
107 # make USERCFLAGS=-Werror USERLDFLAGS=-static
108 CFLAGS += $(USERCFLAGS)
109 LDFLAGS += $(USERLDFLAGS)
111 # When make O= with kselftest target from main level
112 # the following aren't defined.
114 ifneq ($(KBUILD_SRC),)
115 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
116 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
117 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
121 $(LINK.c) $^ $(LDLIBS) -o $@
124 $(COMPILE.S) $^ -o $@
127 $(LINK.S) $^ $(LDLIBS) -o $@
129 .PHONY: run_tests all clean install emit_tests