lib.mk (a23e1966932464e1c5226cb9ac4ce1d5fc10ba22) lib.mk (cc937dad85aea4ab9e4f9827d7ea55932c86906b)
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.
3ifneq ($(LLVM),)
4ifneq ($(filter %/,$(LLVM)),)
5LLVM_PREFIX := $(LLVM)
6else ifneq ($(filter -%,$(LLVM)),)
7LLVM_SUFFIX := $(LLVM)
8endif
9
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.
3ifneq ($(LLVM),)
4ifneq ($(filter %/,$(LLVM)),)
5LLVM_PREFIX := $(LLVM)
6else ifneq ($(filter -%,$(LLVM)),)
7LLVM_SUFFIX := $(LLVM)
8endif
9
10CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
11
10CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
11CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
12CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
13CLANG_TARGET_FLAGS_i386 := i386-linux-gnu
14CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
15CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
16CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
17CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
18CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
19CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
20CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu
12CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
13CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
14CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
15CLANG_TARGET_FLAGS_i386 := i386-linux-gnu
16CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
17CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
18CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
19CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
20CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
21CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
22CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu
21CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
22
23
24# Default to host architecture if ARCH is not explicitly given.
25ifeq ($(ARCH),)
26CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple)
27else
28CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
29endif
30
23ifeq ($(CROSS_COMPILE),)
24ifeq ($(CLANG_TARGET_FLAGS),)
25$(error Specify CROSS_COMPILE or add '--target=' option to lib.mk)
26else
27CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
28endif # CLANG_TARGET_FLAGS
29else
30CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
31endif # CROSS_COMPILE
32
31ifeq ($(CROSS_COMPILE),)
32ifeq ($(CLANG_TARGET_FLAGS),)
33$(error Specify CROSS_COMPILE or add '--target=' option to lib.mk)
34else
35CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
36endif # CLANG_TARGET_FLAGS
37else
38CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
39endif # CROSS_COMPILE
40
33CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as
41CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
34else
35CC := $(CROSS_COMPILE)gcc
36endif # LLVM
37
38ifeq (0,$(MAKELEVEL))
39 ifeq ($(OUTPUT),)
40 OUTPUT := $(shell pwd)
41 DEFAULT_INSTALL_HDR_PATH := 1
42 endif
43endif
44selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
45top_srcdir = $(selfdir)/../../..
46
42else
43CC := $(CROSS_COMPILE)gcc
44endif # LLVM
45
46ifeq (0,$(MAKELEVEL))
47 ifeq ($(OUTPUT),)
48 OUTPUT := $(shell pwd)
49 DEFAULT_INSTALL_HDR_PATH := 1
50 endif
51endif
52selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
53top_srcdir = $(selfdir)/../../..
54
55# msg: emit succinct information message describing current building step
56# $1 - generic step name (e.g., CC, LINK, etc);
57# $2 - optional "flavor" specifier; if provided, will be emitted as [flavor];
58# $3 - target (assumed to be file); only file name will be emitted;
59# $4 - optional extra arg, emitted as-is, if provided.
60ifeq ($(V),1)
61Q =
62msg =
63else
64Q = @
65msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))";
66MAKEFLAGS += --no-print-directory
67endif
68
47ifeq ($(KHDR_INCLUDES),)
48KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
49endif
50
69ifeq ($(KHDR_INCLUDES),)
70KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
71endif
72
73# In order to use newer items that haven't yet been added to the user's system
74# header files, add $(TOOLS_INCLUDES) to the compiler invocation in each
75# each selftest.
76# You may need to add files to that location, or to refresh an existing file. In
77# order to do that, run "make headers" from $(top_srcdir), then copy the
78# header file that you want from $(top_srcdir)/usr/include/... , to the matching
79# subdir in $(TOOLS_INCLUDE).
80TOOLS_INCLUDES := -isystem $(top_srcdir)/tools/include/uapi
81
51# The following are built by lib.mk common compile rules.
52# TEST_CUSTOM_PROGS should be used by tests that require
53# custom build rule and prevent common build rule use.
54# TEST_PROGS are for test shell scripts.
55# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
56# and install targets. Common clean doesn't touch them.
57TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
58TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))

--- 93 unchanged lines hidden (view full) ---

152
153define CLEAN
154 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
155endef
156
157clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
158 $(CLEAN)
159
82# The following are built by lib.mk common compile rules.
83# TEST_CUSTOM_PROGS should be used by tests that require
84# custom build rule and prevent common build rule use.
85# TEST_PROGS are for test shell scripts.
86# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
87# and install targets. Common clean doesn't touch them.
88TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
89TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))

--- 93 unchanged lines hidden (view full) ---

183
184define CLEAN
185 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
186endef
187
188clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir)
189 $(CLEAN)
190
191# Build with _GNU_SOURCE by default
192CFLAGS += -D_GNU_SOURCE=
193
160# Enables to extend CFLAGS and LDFLAGS from command line, e.g.
161# make USERCFLAGS=-Werror USERLDFLAGS=-static
162CFLAGS += $(USERCFLAGS)
163LDFLAGS += $(USERLDFLAGS)
164
165# When make O= with kselftest target from main level
166# the following aren't defined.
167#
168ifdef building_out_of_srctree
169LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
170COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
171LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
172endif
173
174# Selftest makefiles can override those targets by setting
175# OVERRIDE_TARGETS = 1.
176ifeq ($(OVERRIDE_TARGETS),)
177LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
178$(OUTPUT)/%:%.c $(LOCAL_HDRS)
194# Enables to extend CFLAGS and LDFLAGS from command line, e.g.
195# make USERCFLAGS=-Werror USERLDFLAGS=-static
196CFLAGS += $(USERCFLAGS)
197LDFLAGS += $(USERLDFLAGS)
198
199# When make O= with kselftest target from main level
200# the following aren't defined.
201#
202ifdef building_out_of_srctree
203LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
204COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
205LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
206endif
207
208# Selftest makefiles can override those targets by setting
209# OVERRIDE_TARGETS = 1.
210ifeq ($(OVERRIDE_TARGETS),)
211LOCAL_HDRS += $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h
212$(OUTPUT)/%:%.c $(LOCAL_HDRS)
179 $(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
213 $(call msg,CC,,$@)
214 $(Q)$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@
180
181$(OUTPUT)/%.o:%.S
182 $(COMPILE.S) $^ -o $@
183
184$(OUTPUT)/%:%.S
185 $(LINK.S) $^ $(LDLIBS) -o $@
186endif
187
188.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir
215
216$(OUTPUT)/%.o:%.S
217 $(COMPILE.S) $^ -o $@
218
219$(OUTPUT)/%:%.S
220 $(LINK.S) $^ $(LDLIBS) -o $@
221endif
222
223.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir