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 ifneq ($(filter %/,$(LLVM)),) 5 LLVM_PREFIX := $(LLVM) 5 LLVM_PREFIX := $(LLVM) 6 else ifneq ($(filter -%,$(LLVM)),) 6 else ifneq ($(filter -%,$(LLVM)),) 7 LLVM_SUFFIX := $(LLVM) 7 LLVM_SUFFIX := $(LLVM) 8 endif 8 endif 9 9 10 CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) << 11 << 12 CLANG_TARGET_FLAGS_arm := arm-linux-g 10 CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi 13 CLANG_TARGET_FLAGS_arm64 := aarch64-lin 11 CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu 14 CLANG_TARGET_FLAGS_hexagon := hexagon-lin 12 CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl 15 CLANG_TARGET_FLAGS_i386 := i386-linux- << 16 CLANG_TARGET_FLAGS_m68k := m68k-linux- 13 CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu 17 CLANG_TARGET_FLAGS_mips := mipsel-linu 14 CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu 18 CLANG_TARGET_FLAGS_powerpc := powerpc64le 15 CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu 19 CLANG_TARGET_FLAGS_riscv := riscv64-lin 16 CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu 20 CLANG_TARGET_FLAGS_s390 := s390x-linux 17 CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu 21 CLANG_TARGET_FLAGS_x86 := x86_64-linu 18 CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu 22 CLANG_TARGET_FLAGS_x86_64 := x86_64-linu !! 19 CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 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 20 31 ifeq ($(CROSS_COMPILE),) 21 ifeq ($(CROSS_COMPILE),) 32 ifeq ($(CLANG_TARGET_FLAGS),) 22 ifeq ($(CLANG_TARGET_FLAGS),) 33 $(error Specify CROSS_COMPILE or add '--target !! 23 $(error Specify CROSS_COMPILE or add '--target=' option to lib.mk 34 else 24 else 35 CLANG_FLAGS += --target=$(CLANG_TARGET_FLA 25 CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) 36 endif # CLANG_TARGET_FLAGS 26 endif # CLANG_TARGET_FLAGS 37 else 27 else 38 CLANG_FLAGS += --target=$(notdir $(CROSS_C 28 CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 39 endif # CROSS_COMPILE 29 endif # CROSS_COMPILE 40 30 41 # gcc defaults to silence (off) for the follow !! 31 CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as 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 32 else 51 CC := $(CROSS_COMPILE)gcc 33 CC := $(CROSS_COMPILE)gcc 52 endif # LLVM 34 endif # LLVM 53 35 54 ifeq (0,$(MAKELEVEL)) 36 ifeq (0,$(MAKELEVEL)) 55 ifeq ($(OUTPUT),) 37 ifeq ($(OUTPUT),) 56 OUTPUT := $(shell pwd) 38 OUTPUT := $(shell pwd) 57 DEFAULT_INSTALL_HDR_PATH := 1 39 DEFAULT_INSTALL_HDR_PATH := 1 58 endif 40 endif 59 endif 41 endif 60 selfdir = $(realpath $(dir $(filter %/lib.mk,$ 42 selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) 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 43 90 # The following are built by lib.mk common com 44 # The following are built by lib.mk common compile rules. 91 # TEST_CUSTOM_PROGS should be used by tests th 45 # TEST_CUSTOM_PROGS should be used by tests that require 92 # custom build rule and prevent common build r 46 # custom build rule and prevent common build rule use. 93 # TEST_PROGS are for test shell scripts. 47 # TEST_PROGS are for test shell scripts. 94 # TEST_CUSTOM_PROGS and TEST_PROGS will be run 48 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests 95 # and install targets. Common clean doesn't to 49 # and install targets. Common clean doesn't touch them. 96 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(T 50 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) 97 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTP 51 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 98 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(T 52 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 99 53 100 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTEND !! 54 ifdef KSFT_KHDR_INSTALL 101 $(if $(TEST_GEN_MODS_DIR),gen_mods_dir !! 55 top_srcdir ?= ../../../.. >> 56 include $(top_srcdir)/scripts/subarch.include >> 57 ARCH ?= $(SUBARCH) >> 58 >> 59 # set default goal to all, so make without a target runs all, even when >> 60 # all isn't the first target in the file. >> 61 .DEFAULT_GOAL := all >> 62 >> 63 # Invoke headers install with --no-builtin-rules to avoid circular >> 64 # dependency in "make kselftest" case. In this case, second level >> 65 # make inherits builtin-rules which will use the rule generate >> 66 # Makefile.o and runs into >> 67 # "Circular Makefile.o <- prepare dependency dropped." >> 68 # and headers_install fails and test compile fails. >> 69 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile >> 70 # invokes them as sub-makes and --no-builtin-rules is not necessary, >> 71 # but doesn't cause any failures. Keep it simple and use the same >> 72 # flags in both cases. >> 73 # Note that the support to install headers from lib.mk is necessary >> 74 # when test Makefile is run directly with "make -C". >> 75 # When local build is done, headers are installed in the default >> 76 # INSTALL_HDR_PATH usr/include. >> 77 .PHONY: khdr >> 78 .NOTPARALLEL: >> 79 khdr: >> 80 ifndef KSFT_KHDR_INSTALL_DONE >> 81 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) >> 82 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install >> 83 else >> 84 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \ >> 85 ARCH=$(ARCH) -C $(top_srcdir) headers_install >> 86 endif >> 87 endif >> 88 >> 89 all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) >> 90 else >> 91 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) >> 92 endif 102 93 103 define RUN_TESTS 94 define RUN_TESTS 104 BASE_DIR="$(selfdir)"; 95 BASE_DIR="$(selfdir)"; \ 105 . $(selfdir)/kselftest/runner.sh; 96 . $(selfdir)/kselftest/runner.sh; \ 106 if [ "X$(summary)" != "X" ]; then 97 if [ "X$(summary)" != "X" ]; then \ 107 per_test_logging=1; 98 per_test_logging=1; \ 108 fi; 99 fi; \ 109 run_many $(1) 100 run_many $(1) 110 endef 101 endef 111 102 112 define INSTALL_INCLUDES << 113 $(if $(TEST_INCLUDES), \ << 114 relative_files=""; \ << 115 for entry in $(TEST_INCLUDES); << 116 entry_dir=$$(readlink << 117 entry_name=$$(basename << 118 relative_dir=$${entry_ << 119 if [ "$$relative_dir" << 120 echo "Error: T << 121 exit 1; \ << 122 fi; \ << 123 relative_files="$$rela << 124 done; \ << 125 cd $(SRC_PATH) && rsync -aR $$ << 126 ) << 127 endef << 128 << 129 run_tests: all 103 run_tests: all 130 ifdef building_out_of_srctree 104 ifdef building_out_of_srctree 131 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTE !! 105 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 132 rsync -aq --copy-unsafe-links !! 106 rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 133 fi 107 fi 134 @$(INSTALL_INCLUDES) << 135 @if [ "X$(TEST_PROGS)" != "X" ]; then 108 @if [ "X$(TEST_PROGS)" != "X" ]; then \ 136 $(call RUN_TESTS, $(TEST_GEN_P 109 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ 137 $(addprefix 110 $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ 138 else \ 111 else \ 139 $(call RUN_TESTS, $(TEST_GEN_P 112 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \ 140 fi 113 fi 141 else 114 else 142 @$(call RUN_TESTS, $(TEST_GEN_PROGS) $ 115 @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 143 endif 116 endif 144 117 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 118 define INSTALL_SINGLE_RULE 152 $(if $(INSTALL_LIST),@mkdir -p $(INSTA 119 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 153 $(if $(INSTALL_LIST),rsync -a --copy-u !! 120 $(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 154 endef << 155 << 156 define INSTALL_MODS_RULE << 157 $(if $(INSTALL_LIST),@mkdir -p $(INSTA << 158 $(if $(INSTALL_LIST),rsync -a --copy-u << 159 endef 121 endef 160 122 161 define INSTALL_RULE 123 define INSTALL_RULE 162 $(eval INSTALL_LIST = $(TEST_PROGS)) $ 124 $(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE) 163 $(eval INSTALL_LIST = $(TEST_PROGS_EXT 125 $(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 164 $(eval INSTALL_LIST = $(TEST_FILES)) $ 126 $(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE) 165 $(eval INSTALL_LIST = $(TEST_GEN_PROGS 127 $(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE) 166 $(eval INSTALL_LIST = $(TEST_CUSTOM_PR 128 $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) 167 $(eval INSTALL_LIST = $(TEST_GEN_PROGS 129 $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) 168 $(eval INSTALL_LIST = $(TEST_GEN_FILES 130 $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) 169 $(eval INSTALL_LIST = $(notdir $(TEST_ << 170 $(eval INSTALL_LIST = $(wildcard confi 131 $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) 171 endef 132 endef 172 133 173 install: all 134 install: all 174 ifdef INSTALL_PATH 135 ifdef INSTALL_PATH 175 $(INSTALL_RULE) 136 $(INSTALL_RULE) 176 $(INSTALL_INCLUDES) << 177 else 137 else 178 $(error Error: set INSTALL_PATH to use 138 $(error Error: set INSTALL_PATH to use install) 179 endif 139 endif 180 140 181 emit_tests: 141 emit_tests: 182 for TEST in $(TEST_GEN_PROGS) $(TEST_C 142 for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ 183 BASENAME_TEST=`basename $$TEST 143 BASENAME_TEST=`basename $$TEST`; \ 184 echo "$(COLLECTION):$$BASENAME 144 echo "$(COLLECTION):$$BASENAME_TEST"; \ 185 done 145 done 186 146 187 # define if isn't already. It is undefined in 147 # define if isn't already. It is undefined in make O= case. 188 ifeq ($(RM),) 148 ifeq ($(RM),) 189 RM := rm -f 149 RM := rm -f 190 endif 150 endif 191 151 192 define CLEAN 152 define CLEAN 193 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_ 153 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) 194 endef 154 endef 195 155 196 clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_di !! 156 clean: 197 $(CLEAN) 157 $(CLEAN) 198 158 199 # Build with _GNU_SOURCE by default << 200 CFLAGS += -D_GNU_SOURCE= << 201 << 202 # Enables to extend CFLAGS and LDFLAGS from co << 203 # make USERCFLAGS=-Werror USERLDFLAGS=-static << 204 CFLAGS += $(USERCFLAGS) << 205 LDFLAGS += $(USERLDFLAGS) << 206 << 207 # When make O= with kselftest target from main 159 # When make O= with kselftest target from main level 208 # the following aren't defined. 160 # the following aren't defined. 209 # 161 # 210 ifdef building_out_of_srctree 162 ifdef building_out_of_srctree 211 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS 163 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 212 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TAR 164 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 213 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAG 165 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) 214 endif 166 endif 215 167 216 # Selftest makefiles can override those target 168 # Selftest makefiles can override those targets by setting 217 # OVERRIDE_TARGETS = 1. 169 # OVERRIDE_TARGETS = 1. 218 ifeq ($(OVERRIDE_TARGETS),) 170 ifeq ($(OVERRIDE_TARGETS),) 219 LOCAL_HDRS += $(selfdir)/kselftest_harness.h $ 171 LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h 220 $(OUTPUT)/%:%.c $(LOCAL_HDRS) 172 $(OUTPUT)/%:%.c $(LOCAL_HDRS) 221 $(call msg,CC,,$@) !! 173 $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@ 222 $(Q)$(LINK.c) $(filter-out $(LOCAL_HDR << 223 174 224 $(OUTPUT)/%.o:%.S 175 $(OUTPUT)/%.o:%.S 225 $(COMPILE.S) $^ -o $@ 176 $(COMPILE.S) $^ -o $@ 226 177 227 $(OUTPUT)/%:%.S 178 $(OUTPUT)/%:%.S 228 $(LINK.S) $^ $(LDLIBS) -o $@ 179 $(LINK.S) $^ $(LDLIBS) -o $@ 229 endif 180 endif 230 181 231 .PHONY: run_tests all clean install emit_tests !! 182 .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.