2015-03-04 18:41:31 +08:00
|
|
|
# This mimics the top-level Makefile. We do it explicitly here so that this
|
|
|
|
# Makefile can operate with or without the kbuild infrastructure.
|
2021-04-13 23:34:13 +08:00
|
|
|
ifneq ($(LLVM),)
|
kbuild: Make $(LLVM) more flexible
The LLVM make variable allows a developer to quickly switch between the
GNU and LLVM tools. However, it does not handle versioned binaries, such
as the ones shipped by Debian, as LLVM=1 just defines the tool variables
with the unversioned binaries.
There was some discussion during the review of the patch that introduces
LLVM=1 around versioned binaries, ultimately coming to the conclusion
that developers can just add the folder that contains the unversioned
binaries to their PATH, as Debian's versioned suffixed binaries are
really just symlinks to the unversioned binaries in /usr/lib/llvm-#/bin:
$ realpath /usr/bin/clang-14
/usr/lib/llvm-14/bin/clang
$ PATH=/usr/lib/llvm-14/bin:$PATH make ... LLVM=1
However, that can be cumbersome to developers who are constantly testing
series with different toolchains and versions. It is simple enough to
support these versioned binaries directly in the Kbuild system by
allowing the developer to specify the version suffix with LLVM=, which
is shorter than the above suggestion:
$ make ... LLVM=-14
It does not change the meaning of LLVM=1 (which will continue to use
unversioned binaries) and it does not add too much additional complexity
to the existing $(LLVM) code, while allowing developers to quickly test
their series with different versions of the whole LLVM suite of tools.
Some developers may build LLVM from source but not add the binaries to
their PATH, as they may not want to use that toolchain systemwide.
Support those developers by allowing them to supply the directory that
the LLVM tools are available in, as it is no more complex to support
than the version suffix change above.
$ make ... LLVM=/path/to/llvm/
Update and reorder the documentation to reflect these new additions.
At the same time, notate that LLVM=0 is not the same as just omitting it
altogether, which has confused people in the past.
Link: https://lore.kernel.org/r/20200317215515.226917-1-ndesaulniers@google.com/
Link: https://lore.kernel.org/r/20220224151322.072632223@infradead.org/
Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2022-03-05 01:08:14 +08:00
|
|
|
ifneq ($(filter %/,$(LLVM)),)
|
|
|
|
LLVM_PREFIX := $(LLVM)
|
|
|
|
else ifneq ($(filter -%,$(LLVM)),)
|
|
|
|
LLVM_SUFFIX := $(LLVM)
|
|
|
|
endif
|
|
|
|
|
2022-06-14 20:10:45 +08:00
|
|
|
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
|
|
|
|
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
|
2022-08-09 22:22:31 +08:00
|
|
|
CLANG_TARGET_FLAGS_i386 := i386-linux-gnu
|
2022-06-14 20:10:45 +08:00
|
|
|
CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
|
|
|
|
CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
|
2022-08-09 22:22:31 +08:00
|
|
|
CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu
|
2022-06-14 20:10:45 +08:00
|
|
|
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
|
|
|
|
|
|
|
|
ifeq ($(CROSS_COMPILE),)
|
|
|
|
ifeq ($(CLANG_TARGET_FLAGS),)
|
2023-01-12 06:33:07 +08:00
|
|
|
$(error Specify CROSS_COMPILE or add '--target=' option to lib.mk)
|
2022-06-14 20:10:45 +08:00
|
|
|
else
|
|
|
|
CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
|
|
|
|
endif # CLANG_TARGET_FLAGS
|
|
|
|
else
|
|
|
|
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
|
|
|
|
endif # CROSS_COMPILE
|
|
|
|
|
|
|
|
CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as
|
2021-04-13 23:34:13 +08:00
|
|
|
else
|
2015-03-04 18:41:31 +08:00
|
|
|
CC := $(CROSS_COMPILE)gcc
|
2022-06-14 20:10:45 +08:00
|
|
|
endif # LLVM
|
2015-03-04 18:41:31 +08:00
|
|
|
|
2017-03-02 06:15:07 +08:00
|
|
|
ifeq (0,$(MAKELEVEL))
|
2019-05-11 09:38:39 +08:00
|
|
|
ifeq ($(OUTPUT),)
|
|
|
|
OUTPUT := $(shell pwd)
|
|
|
|
DEFAULT_INSTALL_HDR_PATH := 1
|
2019-04-16 05:51:42 +08:00
|
|
|
endif
|
2017-03-02 06:15:07 +08:00
|
|
|
endif
|
2019-04-25 07:12:30 +08:00
|
|
|
selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
|
2022-08-20 03:19:28 +08:00
|
|
|
top_srcdir = $(selfdir)/../../..
|
2017-03-02 06:15:07 +08:00
|
|
|
|
2023-12-09 10:01:44 +08:00
|
|
|
ifeq ($(KHDR_INCLUDES),)
|
|
|
|
KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
|
2022-09-09 18:34:02 +08:00
|
|
|
endif
|
|
|
|
|
2017-09-12 03:06:33 +08:00
|
|
|
# The following are built by lib.mk common compile rules.
|
|
|
|
# TEST_CUSTOM_PROGS should be used by tests that require
|
|
|
|
# custom build rule and prevent common build rule use.
|
|
|
|
# TEST_PROGS are for test shell scripts.
|
|
|
|
# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
|
|
|
|
# and install targets. Common clean doesn't touch them.
|
2017-02-09 16:56:26 +08:00
|
|
|
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
|
2017-09-07 08:36:22 +08:00
|
|
|
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
|
2017-02-09 16:56:26 +08:00
|
|
|
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
|
|
|
|
|
2023-12-09 10:01:44 +08:00
|
|
|
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
|
2018-09-04 18:47:21 +08:00
|
|
|
|
2015-03-11 12:05:59 +08:00
|
|
|
define RUN_TESTS
|
2020-05-27 15:16:57 +08:00
|
|
|
BASE_DIR="$(selfdir)"; \
|
2019-04-25 07:12:35 +08:00
|
|
|
. $(selfdir)/kselftest/runner.sh; \
|
2019-04-25 07:12:32 +08:00
|
|
|
if [ "X$(summary)" != "X" ]; then \
|
|
|
|
per_test_logging=1; \
|
|
|
|
fi; \
|
|
|
|
run_many $(1)
|
2015-03-11 12:05:59 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
run_tests: all
|
2019-07-06 11:07:12 +08:00
|
|
|
ifdef building_out_of_srctree
|
2020-05-27 15:16:58 +08:00
|
|
|
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
|
2023-08-22 21:58:37 +08:00
|
|
|
rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
|
2017-09-12 09:03:11 +08:00
|
|
|
fi
|
2020-05-27 15:16:57 +08:00
|
|
|
@if [ "X$(TEST_PROGS)" != "X" ]; then \
|
2021-03-03 08:44:20 +08:00
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \
|
|
|
|
$(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \
|
2020-05-27 15:16:57 +08:00
|
|
|
else \
|
|
|
|
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \
|
2017-09-12 09:03:11 +08:00
|
|
|
fi
|
|
|
|
else
|
2020-05-27 15:16:57 +08:00
|
|
|
@$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
|
2017-09-12 09:03:11 +08:00
|
|
|
endif
|
2015-03-11 12:05:59 +08:00
|
|
|
|
2020-02-06 16:40:52 +08:00
|
|
|
define INSTALL_SINGLE_RULE
|
|
|
|
$(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH))
|
2023-08-22 21:58:37 +08:00
|
|
|
$(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/)
|
2020-02-06 16:40:52 +08:00
|
|
|
endef
|
|
|
|
|
2015-03-11 12:06:00 +08:00
|
|
|
define INSTALL_RULE
|
2020-02-06 16:40:52 +08:00
|
|
|
$(eval INSTALL_LIST = $(TEST_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_FILES)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE)
|
|
|
|
$(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE)
|
2021-05-27 11:17:54 +08:00
|
|
|
$(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE)
|
2015-03-11 12:06:00 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
install: all
|
|
|
|
ifdef INSTALL_PATH
|
|
|
|
$(INSTALL_RULE)
|
|
|
|
else
|
|
|
|
$(error Error: set INSTALL_PATH to use install)
|
|
|
|
endif
|
|
|
|
|
2019-04-25 07:12:31 +08:00
|
|
|
emit_tests:
|
2018-05-02 02:15:34 +08:00
|
|
|
for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
|
2016-11-29 19:55:52 +08:00
|
|
|
BASENAME_TEST=`basename $$TEST`; \
|
2020-09-29 04:26:48 +08:00
|
|
|
echo "$(COLLECTION):$$BASENAME_TEST"; \
|
|
|
|
done
|
2015-03-11 12:06:00 +08:00
|
|
|
|
2017-09-07 08:36:22 +08:00
|
|
|
# define if isn't already. It is undefined in make O= case.
|
|
|
|
ifeq ($(RM),)
|
|
|
|
RM := rm -f
|
|
|
|
endif
|
|
|
|
|
2017-04-22 06:07:51 +08:00
|
|
|
define CLEAN
|
2016-11-29 19:55:51 +08:00
|
|
|
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
|
2017-04-22 06:07:51 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(CLEAN)
|
2016-11-29 19:55:47 +08:00
|
|
|
|
2022-09-09 18:39:01 +08:00
|
|
|
# Enables to extend CFLAGS and LDFLAGS from command line, e.g.
|
|
|
|
# make USERCFLAGS=-Werror USERLDFLAGS=-static
|
|
|
|
CFLAGS += $(USERCFLAGS)
|
|
|
|
LDFLAGS += $(USERLDFLAGS)
|
|
|
|
|
2017-09-07 08:36:22 +08:00
|
|
|
# When make O= with kselftest target from main level
|
|
|
|
# the following aren't defined.
|
|
|
|
#
|
2019-07-06 11:07:12 +08:00
|
|
|
ifdef building_out_of_srctree
|
2017-09-07 08:36:22 +08:00
|
|
|
LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
|
|
|
|
COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
|
|
|
|
LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
|
|
|
|
endif
|
|
|
|
|
2018-06-02 20:44:03 +08:00
|
|
|
# Selftest makefiles can override those targets by setting
|
|
|
|
# OVERRIDE_TARGETS = 1.
|
|
|
|
ifeq ($(OVERRIDE_TARGETS),)
|
2021-11-06 00:25:29 +08:00
|
|
|
LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
|
2020-03-26 07:16:49 +08:00
|
|
|
$(OUTPUT)/%:%.c $(LOCAL_HDRS)
|
2020-10-08 20:26:21 +08:00
|
|
|
$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
|
2016-11-29 19:55:52 +08:00
|
|
|
|
|
|
|
$(OUTPUT)/%.o:%.S
|
2017-02-09 16:56:28 +08:00
|
|
|
$(COMPILE.S) $^ -o $@
|
2016-11-29 19:55:52 +08:00
|
|
|
|
|
|
|
$(OUTPUT)/%:%.S
|
2017-02-09 16:56:28 +08:00
|
|
|
$(LINK.S) $^ $(LDLIBS) -o $@
|
2018-06-02 20:44:03 +08:00
|
|
|
endif
|
2016-11-29 19:55:49 +08:00
|
|
|
|
2015-03-11 12:06:00 +08:00
|
|
|
.PHONY: run_tests all clean install emit_tests
|