]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/testing/selftests/lib.mk
Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[karo-tx-linux.git] / tools / testing / selftests / lib.mk
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
5 ifeq (0,$(MAKELEVEL))
6 OUTPUT := $(shell pwd)
7 endif
8
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
14 define RUN_TESTS
15         @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
16                 BASENAME_TEST=`basename $$TEST`;        \
17                 cd `dirname $$TEST`; (./$$BASENAME_TEST && echo "selftests: $$BASENAME_TEST [PASS]") || echo "selftests:  $$BASENAME_TEST [FAIL]"; cd -;\
18         done;
19 endef
20
21 run_tests: all
22         $(RUN_TESTS)
23
24 define INSTALL_RULE
25         @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then                                        \
26                 mkdir -p ${INSTALL_PATH};                                                                               \
27                 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/";    \
28                 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/;           \
29         fi
30         @if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then                                    \
31                 mkdir -p ${INSTALL_PATH};                                                                               \
32                 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/";        \
33                 rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/;               \
34         fi
35 endef
36
37 install: all
38 ifdef INSTALL_PATH
39         $(INSTALL_RULE)
40 else
41         $(error Error: set INSTALL_PATH to use install)
42 endif
43
44 define EMIT_TESTS
45         @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
46                 BASENAME_TEST=`basename $$TEST`;        \
47                 echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
48         done;
49 endef
50
51 emit_tests:
52         $(EMIT_TESTS)
53
54 clean:
55         $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
56
57 $(OUTPUT)/%:%.c
58         $(LINK.c) $^ $(LDLIBS) -o $@
59
60 $(OUTPUT)/%.o:%.S
61         $(COMPILE.S) $^ -o $@
62
63 $(OUTPUT)/%:%.S
64         $(LINK.S) $^ $(LDLIBS) -o $@
65
66 .PHONY: run_tests all clean install emit_tests