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.
4 ifneq ($(filter %/,$(LLVM)),)
6 else ifneq ($(filter -%,$(LLVM)),)
10 CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
11 CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
12 CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
13 CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
14 CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
15 CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
16 CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
17 CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
18 CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
19 CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
21 ifeq ($(CROSS_COMPILE),)
22 ifeq ($(CLANG_TARGET_FLAGS),)
23 $(error Specify CROSS_COMPILE or add '--target=' option to lib.mk
25 CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
26 endif # CLANG_TARGET_FLAGS
28 CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
31 CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as
33 CC := $(CROSS_COMPILE)gcc
38 OUTPUT := $(shell pwd)
39 DEFAULT_INSTALL_HDR_PATH := 1
42 selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
44 # The following are built by lib.mk common compile rules.
45 # TEST_CUSTOM_PROGS should be used by tests that require
46 # custom build rule and prevent common build rule use.
47 # TEST_PROGS are for test shell scripts.
48 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
49 # and install targets. Common clean doesn't touch them.
50 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
51 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
52 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
54 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
57 BASE_DIR="$(selfdir)"; \
58 . $(selfdir)/kselftest/runner.sh; \
59 if [ "X$(summary)" != "X" ]; then \
66 ifdef building_out_of_srctree
67 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
68 rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
70 @if [ "X$(TEST_PROGS)" != "X" ]; then \
71 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
72 $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
74 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \
77 @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
80 define INSTALL_SINGLE_RULE
81 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH))
82 $(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
86 $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE)
87 $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
88 $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE)
89 $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE)
90 $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE)
91 $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
92 $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE)
93 $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE)
100 $(error Error: set INSTALL_PATH to use install)
104 for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
105 BASENAME_TEST=`basename $$TEST`; \
106 echo "$(COLLECTION):$$BASENAME_TEST"; \
109 # define if isn't already. It is undefined in make O= case.
115 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
121 # When make O= with kselftest target from main level
122 # the following aren't defined.
124 ifdef building_out_of_srctree
125 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
126 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
127 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
130 # Selftest makefiles can override those targets by setting
131 # OVERRIDE_TARGETS = 1.
132 ifeq ($(OVERRIDE_TARGETS),)
133 LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
134 $(OUTPUT)/%:%.c $(LOCAL_HDRS)
135 $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
138 $(COMPILE.S) $^ -o $@
141 $(LINK.S) $^ $(LDLIBS) -o $@
144 .PHONY: run_tests all clean install emit_tests