1 # This mimics the top-level Makefile. We do it 1 # This mimics the top-level Makefile. We do it explicitly here so that this 2 # Makefile can operate with or without the kbu 2 # Makefile can operate with or without the kbuild infrastructure. 3 ifneq ($(LLVM),) 3 ifneq ($(LLVM),) 4 ifneq ($(filter %/,$(LLVM)),) !! 4 CC := clang 5 LLVM_PREFIX := $(LLVM) << 6 else ifneq ($(filter -%,$(LLVM)),) << 7 LLVM_SUFFIX := $(LLVM) << 8 endif << 9 << 10 CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) << 11 << 12 CLANG_TARGET_FLAGS_arm := arm-linux-g << 13 CLANG_TARGET_FLAGS_arm64 := aarch64-lin << 14 CLANG_TARGET_FLAGS_hexagon := hexagon-lin << 15 CLANG_TARGET_FLAGS_i386 := i386-linux- << 16 CLANG_TARGET_FLAGS_m68k := m68k-linux- << 17 CLANG_TARGET_FLAGS_mips := mipsel-linu << 18 CLANG_TARGET_FLAGS_powerpc := powerpc64le << 19 CLANG_TARGET_FLAGS_riscv := riscv64-lin << 20 CLANG_TARGET_FLAGS_s390 := s390x-linux << 21 CLANG_TARGET_FLAGS_x86 := x86_64-linu << 22 CLANG_TARGET_FLAGS_x86_64 := x86_64-linu << 23 << 24 # Default to host architecture if ARCH is not << 25 ifeq ($(ARCH),) << 26 CLANG_TARGET_FLAGS := $(shell $(CLANG) -print- << 27 else << 28 CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(A << 29 endif << 30 << 31 ifeq ($(CROSS_COMPILE),) << 32 ifeq ($(CLANG_TARGET_FLAGS),) << 33 $(error Specify CROSS_COMPILE or add '--target << 34 else << 35 CLANG_FLAGS += --target=$(CLANG_TARGET_FLA << 36 endif # CLANG_TARGET_FLAGS << 37 else << 38 CLANG_FLAGS += --target=$(notdir $(CROSS_C << 39 endif # CROSS_COMPILE << 40 << 41 # gcc defaults to silence (off) for the follow << 42 # to the opposite. The warnings are not useful << 43 # why they have remained disabled in gcc for t << 44 # only due to including kernel data structures << 45 # warnings from clang. Therefore, disable the << 46 CFLAGS += -Wno-address-of-packed-member << 47 CFLAGS += -Wno-gnu-variable-sized-type-not-at- << 48 << 49 CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as << 50 else 5 else 51 CC := $(CROSS_COMPILE)gcc 6 CC := $(CROSS_COMPILE)gcc 52 endif # LLVM !! 7 endif 53 8 54 ifeq (0,$(MAKELEVEL)) 9 ifeq (0,$(MAKELEVEL)) 55 ifeq ($(OUTPUT),) !! 10 OUTPUT := $(shell pwd) 56 OUTPUT := $(shell pwd) !! 11 endif 57 DEFAULT_INSTALL_HDR_PATH := 1 << 58 endif << 59 endif << 60 selfdir = $(realpath $(dir $(filter %/lib.mk,$ << 61 top_srcdir = $(selfdir)/../../.. << 62 << 63 # msg: emit succinct information message descr << 64 # $1 - generic step name (e.g., CC, LINK, etc) << 65 # $2 - optional "flavor" specifier; if provide << 66 # $3 - target (assumed to be file); only file << 67 # $4 - optional extra arg, emitted as-is, if p << 68 ifeq ($(V),1) << 69 Q = << 70 msg = << 71 else << 72 Q = @ << 73 msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $ << 74 MAKEFLAGS += --no-print-directory << 75 endif << 76 << 77 ifeq ($(KHDR_INCLUDES),) << 78 KHDR_INCLUDES := -isystem $(top_srcdir)/usr/in << 79 endif << 80 << 81 # In order to use newer items that haven't yet << 82 # header files, add $(TOOLS_INCLUDES) to the c << 83 # each selftest. << 84 # You may need to add files to that location, << 85 # order to do that, run "make headers" from $( << 86 # header file that you want from $(top_srcdir) << 87 # subdir in $(TOOLS_INCLUDE). << 88 TOOLS_INCLUDES := -isystem $(top_srcdir)/tools << 89 12 90 # The following are built by lib.mk common com 13 # The following are built by lib.mk common compile rules. 91 # TEST_CUSTOM_PROGS should be used by tests th 14 # TEST_CUSTOM_PROGS should be used by tests that require 92 # custom build rule and prevent common build r 15 # custom build rule and prevent common build rule use. 93 # TEST_PROGS are for test shell scripts. 16 # TEST_PROGS are for test shell scripts. 94 # TEST_CUSTOM_PROGS and TEST_PROGS will be run 17 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests 95 # and install targets. Common clean doesn't to 18 # and install targets. Common clean doesn't touch them. 96 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(T 19 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 97 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTP 20 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 98 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(T 21 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 99 22 100 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTEND !! 23 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 101 $(if $(TEST_GEN_MODS_DIR),gen_mods_dir << 102 24 >> 25 .ONESHELL: 103 define RUN_TESTS 26 define RUN_TESTS 104 BASE_DIR="$(selfdir)"; !! 27 @test_num=`echo 0`; 105 . $(selfdir)/kselftest/runner.sh; !! 28 @echo "TAP version 13"; 106 if [ "X$(summary)" != "X" ]; then !! 29 @for TEST in $(1); do \ 107 per_test_logging=1; !! 30 BASENAME_TEST=`basename $$TEST`; \ 108 fi; !! 31 test_num=`echo $$test_num+1 | bc`; \ 109 run_many $(1) !! 32 echo "selftests: $$BASENAME_TEST"; \ 110 endef !! 33 echo "========================================"; \ 111 !! 34 if [ ! -x $$TEST ]; then \ 112 define INSTALL_INCLUDES !! 35 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ 113 $(if $(TEST_INCLUDES), \ !! 36 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ 114 relative_files=""; \ !! 37 else \ 115 for entry in $(TEST_INCLUDES); !! 38 if [ "X$(summary)" != "X" ]; then \ 116 entry_dir=$$(readlink !! 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;\ 117 entry_name=$$(basename !! 40 else \ 118 relative_dir=$${entry_ !! 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;\ 119 if [ "$$relative_dir" !! 42 fi; \ 120 echo "Error: T !! 43 fi; \ 121 exit 1; \ !! 44 done; 122 fi; \ << 123 relative_files="$$rela << 124 done; \ << 125 cd $(SRC_PATH) && rsync -aR $$ << 126 ) << 127 endef 45 endef 128 46 129 run_tests: all 47 run_tests: all 130 ifdef building_out_of_srctree !! 48 ifneq ($(KBUILD_SRC),) 131 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTE !! 49 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then 132 rsync -aq --copy-unsafe-links !! 50 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT) 133 fi 51 fi 134 @$(INSTALL_INCLUDES) !! 52 @if [ "X$(TEST_PROGS)" != "X" ]; then 135 @if [ "X$(TEST_PROGS)" != "X" ]; then !! 53 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) 136 $(call RUN_TESTS, $(TEST_GEN_P !! 54 else 137 $(addprefix !! 55 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)) 138 else \ << 139 $(call RUN_TESTS, $(TEST_GEN_P << 140 fi 56 fi 141 else 57 else 142 @$(call RUN_TESTS, $(TEST_GEN_PROGS) $ !! 58 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 143 endif 59 endif 144 60 145 gen_mods_dir: << 146 $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) << 147 << 148 clean_mods_dir: << 149 $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) cl << 150 << 151 define INSTALL_SINGLE_RULE 61 define INSTALL_SINGLE_RULE 152 $(if $(INSTALL_LIST),@mkdir -p $(INSTA 62 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 153 $(if $(INSTALL_LIST),rsync -a --copy-u !! 63 $(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 154 endef !! 64 $(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 155 << 156 define INSTALL_MODS_RULE << 157 $(if $(INSTALL_LIST),@mkdir -p $(INSTA << 158 $(if $(INSTALL_LIST),rsync -a --copy-u << 159 endef 65 endef 160 66 161 define INSTALL_RULE 67 define INSTALL_RULE 162 $(eval INSTALL_LIST = $(TEST_PROGS)) $ 68 $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE) 163 $(eval INSTALL_LIST = $(TEST_PROGS_EXT 69 $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 164 $(eval INSTALL_LIST = $(TEST_FILES)) $ 70 $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE) 165 $(eval INSTALL_LIST = $(TEST_GEN_PROGS 71 $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE) 166 $(eval INSTALL_LIST = $(TEST_CUSTOM_PR 72 $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) 167 $(eval INSTALL_LIST = $(TEST_GEN_PROGS 73 $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 168 $(eval INSTALL_LIST = $(TEST_GEN_FILES 74 $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) 169 $(eval INSTALL_LIST = $(notdir $(TEST_ << 170 $(eval INSTALL_LIST = $(wildcard confi << 171 endef 75 endef 172 76 173 install: all 77 install: all 174 ifdef INSTALL_PATH 78 ifdef INSTALL_PATH 175 $(INSTALL_RULE) 79 $(INSTALL_RULE) 176 $(INSTALL_INCLUDES) << 177 else 80 else 178 $(error Error: set INSTALL_PATH to use 81 $(error Error: set INSTALL_PATH to use install) 179 endif 82 endif 180 83 181 emit_tests: !! 84 define EMIT_TESTS 182 for TEST in $(TEST_GEN_PROGS) $(TEST_C !! 85 @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ 183 BASENAME_TEST=`basename $$TEST 86 BASENAME_TEST=`basename $$TEST`; \ 184 echo "$(COLLECTION):$$BASENAME !! 87 echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \ 185 done !! 88 done; >> 89 endef >> 90 >> 91 emit_tests: >> 92 $(EMIT_TESTS) 186 93 187 # define if isn't already. It is undefined in 94 # define if isn't already. It is undefined in make O= case. 188 ifeq ($(RM),) 95 ifeq ($(RM),) 189 RM := rm -f 96 RM := rm -f 190 endif 97 endif 191 98 192 define CLEAN 99 define CLEAN 193 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_ 100 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 194 endef 101 endef 195 102 196 clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_di !! 103 clean: 197 $(CLEAN) 104 $(CLEAN) 198 105 199 # Build with _GNU_SOURCE by default << 200 CFLAGS += -D_GNU_SOURCE= << 201 << 202 # Enables to extend CFLAGS and LDFLAGS from co 106 # Enables to extend CFLAGS and LDFLAGS from command line, e.g. 203 # make USERCFLAGS=-Werror USERLDFLAGS=-static 107 # make USERCFLAGS=-Werror USERLDFLAGS=-static 204 CFLAGS += $(USERCFLAGS) 108 CFLAGS += $(USERCFLAGS) 205 LDFLAGS += $(USERLDFLAGS) 109 LDFLAGS += $(USERLDFLAGS) 206 110 207 # When make O= with kselftest target from main 111 # When make O= with kselftest target from main level 208 # the following aren't defined. 112 # the following aren't defined. 209 # 113 # 210 ifdef building_out_of_srctree !! 114 ifneq ($(KBUILD_SRC),) 211 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS 115 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 212 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TAR 116 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 213 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAG 117 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 214 endif 118 endif 215 119 216 # Selftest makefiles can override those target !! 120 $(OUTPUT)/%:%.c 217 # OVERRIDE_TARGETS = 1. !! 121 $(LINK.c) $^ $(LDLIBS) -o $@ 218 ifeq ($(OVERRIDE_TARGETS),) << 219 LOCAL_HDRS += $(selfdir)/kselftest_harness.h $ << 220 $(OUTPUT)/%:%.c $(LOCAL_HDRS) << 221 $(call msg,CC,,$@) << 222 $(Q)$(LINK.c) $(filter-out $(LOCAL_HDR << 223 122 224 $(OUTPUT)/%.o:%.S 123 $(OUTPUT)/%.o:%.S 225 $(COMPILE.S) $^ -o $@ 124 $(COMPILE.S) $^ -o $@ 226 125 227 $(OUTPUT)/%:%.S 126 $(OUTPUT)/%:%.S 228 $(LINK.S) $^ $(LDLIBS) -o $@ 127 $(LINK.S) $^ $(LDLIBS) -o $@ 229 endif << 230 128 231 .PHONY: run_tests all clean install emit_tests !! 129 .PHONY: run_tests all clean install emit_tests
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.