Lines Matching +full:sub +full:- +full:modules

1 # SPDX-License-Identifier: GPL-2.0
14 ifeq ($(filter output-sync,$(.FEATURES)),)
28 # Most importantly: sub-Makefiles should only ever modify files in
31 # unavoidable when linking the built-in.a targets which finally
32 # turn into vmlinux), we will call a sub make in that other dir, and
41 this-makefile := $(lastword $(MAKEFILE_LIST))
42 abs_srctree := $(realpath $(dir $(this-makefile)))
47 # Do not use make's built-in rules and variables
48 # (this increases performance and avoids hard-to-debug behaviour)
49 MAKEFLAGS += -rR
61 # ---------------------------------------------------------------------------
71 # A simple variant is to prefix commands with $(Q) - that's useful
72 # for commands that shall be hidden in non-verbose mode.
94 # If the user is running make -s (silent mode), suppress echoing of
96 ifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),)
106 # Use 'make C=1' to enable checking of only re-compiled files.
108 # of whether they are re-compiled or not.
110 # See the file "Documentation/dev-tools/sparse.rst" for more details,
142 $(error building multiple external modules is not supported))
165 # cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
192 # source directory or kernel build directory), external modules
209 # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.
210 $(shell mkdir -p "$(output)")
226 no-print-directory := --no-print-directory
229 need-sub-make := 1
232 ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
233 # If --no-print-directory is unset, recurse once again to set it.
234 # You may end up recursing into __sub-make twice. This is needed due to the
236 need-sub-make := 1
239 ifeq ($(need-sub-make),1)
241 PHONY += $(MAKECMDGOALS) __sub-make
243 $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
247 __sub-make:
248 $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \
249 -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
251 else # need-sub-make
293 clean-targets := %clean mrproper cleandocs
294 no-dot-config-targets := $(clean-targets) \
296 kconfig-sym-check \
298 %asm-generic kernelversion %src-pkg dt_binding_check \
302 run-command
303 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
305 single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.header-check %/
307 config-build :=
308 mixed-build :=
309 need-config := 1
310 may-sync-config := 1
311 single-build :=
313 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
314 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
315 need-config :=
319 ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
320 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
321 may-sync-config :=
325 need-compiler := $(may-sync-config)
328 may-sync-config :=
333 config-build := 1
335 mixed-build := 1
341 ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
342 single-build := 1
343 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
344 mixed-build := 1
348 # For "make -j clean all", "make -j mrproper defconfig all", etc.
349 ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
350 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
351 mixed-build := 1
358 mixed-build := 1
362 ifdef mixed-build
373 $(Q)set -e; \
375 $(MAKE) -f $(srctree)/Makefile $$i; \
378 else # !mixed-build
383 KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)
389 # Cross compiling and selecting different set of gcc/bin-utils
390 # ---------------------------------------------------------------------------
400 # during compilation. Only gcc and related bin-utils executables
403 # make CROSS_COMPILE=aarch64-linux-gnu-
452 else ifneq ($(filter -%,$(LLVM)),)
465 HOSTPKG_CONFIG = pkg-config
469 KERNELDOC = $(srctree)/tools/docs/kernel-doc
472 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
473 -O2 -fomit-frame-pointer -std=gnu11
480 # `-Aclippy::comparison_chain`: the lint has been demoted since 1.87.
481 # `-Aclippy::unwrap_or_default`: the lint is buggy [1] and ignores our
483 # [1] https://github.com/rust-lang/rust-clippy/issues/17379
484 export rust_common_flags := --edition=2021 \
485 -Zbinary_dep_depinfo=y \
486 -Astable_features \
487 -Aunused_features \
488 -Dnon_ascii_idents \
489 -Dunsafe_op_in_unsafe_fn \
490 -Wmissing_docs \
491 -Wrust_2018_idioms \
492 -Wunreachable_pub \
493 -Wclippy::all \
494 -Wclippy::as_ptr_cast_mut \
495 -Wclippy::as_underscore \
496 -Wclippy::cast_lossless \
497 -Aclippy::collapsible_if \
498 -Aclippy::collapsible_match \
499 -Aclippy::comparison_chain \
500 -Wclippy::ignored_unit_patterns \
501 -Aclippy::incompatible_msrv \
502 -Wclippy::mut_mut \
503 -Wclippy::needless_bitwise_bool \
504 -Aclippy::needless_lifetimes \
505 -Wclippy::no_mangle_with_rust_abi \
506 -Wclippy::ptr_as_ptr \
507 -Wclippy::ptr_cast_constness \
508 -Wclippy::ref_as_ptr \
509 -Wclippy::undocumented_unsafe_blocks \
510 -Aclippy::uninlined_format_args \
511 -Wclippy::unnecessary_safety_comment \
512 -Wclippy::unnecessary_safety_doc \
513 -Aclippy::unwrap_or_default \
514 -Wrustdoc::missing_crate_level_docs \
515 -Wrustdoc::unescaped_backticks
518 $(HOSTCFLAGS) -I $(srctree)/scripts/include
519 KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
520 -I $(srctree)/scripts/include
521 KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
522 -Zallow-features=
528 CPP = $(CC) -E
532 AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
533 LLVM_LINK = $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)
534 NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
535 OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
536 OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
537 READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
538 STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
539 ifeq ($(filter -fuse-ld=% --ld-path=%,$(KBUILD_HOSTLDFLAGS)),)
540 KBUILD_HOSTLDFLAGS += -fuse-ld=lld
555 CLIPPY_DRIVER = clippy-driver
576 KPGZIP := $(if $(shell command -v pigz 2>/dev/null),$(PYTHON3) $(abs_srctree)/scripts/jobserver-exec pigz -p %PARALLELISM%,$(KGZIP))
579 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
580 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
593 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
594 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
595 -I$(srctree)/include/uapi \
596 -I$(objtree)/include/generated/uapi \
597 -include $(srctree)/include/linux/compiler-version.h \
598 -include $(srctree)/include/linux/kconfig.h
603 -I$(srctree)/arch/$(SRCARCH)/include \
604 -I$(objtree)/arch/$(SRCARCH)/include/generated \
605 -I$(srctree)/include \
606 -I$(objtree)/include \
609 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
612 KBUILD_CFLAGS += -fshort-wchar
613 KBUILD_CFLAGS += -funsigned-char
614 KBUILD_CFLAGS += -fno-common
615 KBUILD_CFLAGS += -fno-PIE
616 KBUILD_CFLAGS += -fno-strict-aliasing
618 KBUILD_CPPFLAGS := -D__KERNEL__
620 -Cpanic=abort -Cembed-bitcode=n -Clto=n \
621 -Cforce-unwind-tables=n -Ccodegen-units=1 \
622 -Csymbol-mangling-version=v0 \
623 -Crelocation-model=static \
624 -Zfunction-sections=n \
625 -Wclippy::float_arithmetic
631 KBUILD_AFLAGS_MODULE := -DMODULE
632 KBUILD_CFLAGS_MODULE := -DMODULE
633 KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
649 # Allows finding `.clippy.toml` in out-of-srctree builds.
670 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
671 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
672 -prune -o
686 # Before starting out-of-tree build, make sure the source tree is clean.
715 @if [ -f $(srctree)/.config -o \
716 -d $(srctree)/include/config -o \
717 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
725 @if [ -f $(srcroot)/modules.order ]; then \
728 echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \
733 $(Q)ln -fsn $(srcroot) source
734 $(Q)test -e .gitignore || \
743 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
744 RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
745 PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))
752 # cc-cross-prefix to determine CROSS_COMPILE.
753 ifdef need-compiler
757 ifdef config-build
759 # *config targets only - make sure prerequisites are updated, and descend
762 # Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.
774 else #!config-build
776 # Build targets only - this includes vmlinux, arch-specific targets, clean
780 # but instead __all depend on modules
785 __all: modules
790 # Decide whether to build built-in, modular, or both.
791 # Normally, just do built-in.
796 # If we have only "make modules", don't compile built-in objects.
797 ifeq ($(MAKECMDGOALS),modules)
801 # If we have "make <whatever> modules", compile modules
803 # Just "make" or "make all" shall build modules as well
805 ifneq ($(filter all modules nsdeps compile_commands.json clang-% sbom,$(MAKECMDGOALS)),)
815 ifdef need-config
819 CC_FLAGS_DIALECT := -std=gnu11
825 CC_FLAGS_DIALECT += -Wno-gnu
826 CC_FLAGS_DIALECT += -Wno-microsoft-anon-tag
833 core-y :=
834 drivers-y :=
835 libs-y := lib/
840 # This allow a user to issue only 'make' to build a kernel including modules
846 CC_FLAGS_FTRACE := -pg
868 # Per-version Rust flags. These are like `rust_common_flags`, but may
869 # depend on the Rust compiler version (e.g. using `rustc-min-version`).
871 # `-Aclippy::precedence`: the lint was extended in Rust 1.85.0 to
876 $(if $(call rustc-min-version,108600),,-Aclippy::precedence)
884 ifdef need-config
885 ifdef may-sync-config
904 # This exploits the 'multi-target pattern rule' trick.
912 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
913 else # !may-sync-config
914 # External modules and some install targets need include/generated/autoconf.h
915 # and include/config/auto.conf but do not care if they are up-to-date.
918 checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf)
919 missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))
921 ifdef missing-configs
927 @printf >&2 '*** - %s\n' $(missing-configs)
933 endif # may-sync-config
934 endif # need-config
936 KBUILD_CFLAGS += -fno-delete-null-pointer-checks
939 KBUILD_CFLAGS += -O2
940 KBUILD_RUSTFLAGS += -Copt-level=2
942 KBUILD_CFLAGS += -Os
943 KBUILD_RUSTFLAGS += -Copt-level=s
946 # Always set `debug-assertions` and `overflow-checks` because their default
947 # depends on `opt-level` and `debug-assertions`, respectively.
948 KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
949 KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
951 # Tell gcc to never replace conditional load with a non-conditional one
953 # gcc-10 renamed --param=allow-store-data-races=0 to
954 # -fno-allow-store-data-races.
964 KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
967 stackp-flags-y := -fno-stack-protector
968 stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
969 stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
971 KBUILD_CFLAGS += $(stackp-flags-y)
974 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
975 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
977 # https://github.com/rust-lang/rust/pull/156980.
978 KBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109800),,-Zllvm_module_flag=frame-pointer:u32:2:max)
982 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
983 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
984 # -fomit-frame-pointer with FUNCTION_TRACER.
985 # In the Rust target specification, "frame-pointer" is set explicitly
986 # to "may-omit".
988 KBUILD_CFLAGS += -fomit-frame-pointer
994 KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
999 KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
1001 # https://github.com/llvm/llvm-project/issues/44842
1002 CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
1010 KBUILD_CFLAGS += -falloc-token-max=16
1015 KBUILD_CFLAGS += -fexperimental-late-parse-attributes
1025 # sub-targets, so the architecture's flags matter.
1026 KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
1037 KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
1042 CC_FLAGS_FTRACE += -mrecord-mcount
1045 CC_FLAGS_FTRACE += -mnop-mcount
1046 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
1052 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
1063 CC_FLAGS_FTRACE += -mfentry
1064 CC_FLAGS_USING += -DCC_USING_FENTRY
1074 KBUILD_CFLAGS += -fno-inline-functions-called-once
1077 # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
1079 KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
1080 KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
1081 LDFLAGS_vmlinux += --gc-sections
1086 CC_FLAGS_SCS := -fsanitize=shadow-call-stack
1088 KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
1098 CC_FLAGS_RUST_INLINE_HELPERS := -mllvm -trap-unreachable \
1099 -mllvm -no-trap-after-noreturn
1105 CC_FLAGS_LTO := -flto
1107 CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
1109 # These LLVM options were initially added with only in-process ThinLTO
1112 KBUILD_LDFLAGS += $(call ld-option,--lto-whole-program-visibility -mllvm -always-rename-promoted-locals=false)
1115 CC_FLAGS_LTO += -fvisibility=hidden
1118 KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
1122 KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
1123 KBUILD_AFLAGS += -fno-lto
1128 CC_FLAGS_CFI := -fsanitize=kcfi
1130 CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
1133 CC_FLAGS_CFI += -fsanitize-kcfi-arity
1136 # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
1139 RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zmerge-functions=disabled
1147 # Architectures can define flags to add/remove for floating-point support
1148 CC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT
1154 # -fmin-function-alignment if it is available, or fall back to -falign-functions.
1157 KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
1159 KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
1164 NOSTDINC_FLAGS += -nostdinc
1173 KBUILD_CFLAGS += -fno-strict-overflow
1175 # Make sure -fstack-check isn't enabled (like gentoo apparently did)
1176 KBUILD_CFLAGS += -fno-stack-check
1180 KBUILD_CFLAGS += -fconserve-stack
1184 KBUILD_CFLAGS += -fno-builtin-wcslen
1186 CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
1188 CFLAGS_GCOV += -fno-tree-loop-im
1189 # Use atomic counter updates to avoid concurrent-access crashes in GCOV.
1190 # Only enable if -fprofile-update=prefer-atomic does not introduce new
1192 CFLAGS_GCOV += $(call try-run,\
1194 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \
1195 -ftest-coverage -x c - -c -o "$$TMP.base" && \
1197 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \
1198 -ftest-coverage -fprofile-update=prefer-atomic \
1199 -x c - -c -o "$$TMP" && \
1202 cmp -s "$$TMP.ubase" "$$TMP.utest",\
1203 -fprofile-update=prefer-atomic)
1209 CFLAGS_PREFIX_MAP := -fmacro-prefix-map=$(srcroot)/=
1213 ifeq ($(call rustc-option-yn, --remap-path-scope=macro),y)
1214 KBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macro
1219 include-y := scripts/Makefile.warn
1220 include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
1221 include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
1222 include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1223 include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
1224 include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
1225 include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1226 include-$(CONFIG_KCOV) += scripts/Makefile.kcov
1227 include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
1228 include-$(CONFIG_KSTACK_ERASE) += scripts/Makefile.kstack_erase
1229 include-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdo
1230 include-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propeller
1231 include-$(CONFIG_WARN_CONTEXT_ANALYSIS) += scripts/Makefile.context-analysis
1232 include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1234 include $(addprefix $(srctree)/, $(include-y))
1236 # scripts/Makefile.gcc-plugins is intentionally included last.
1237 # Do not add $(call cc-option,...) below this line. When you build the kernel
1246 KBUILD_LDFLAGS_MODULE += --build-id=sha1
1247 LDFLAGS_vmlinux += --build-id=sha1
1250 # COMDAT-deduplicated sections. Use --force-group-allocation to resolve these
1251 # groups when linking modules. The option is available from ld.bfd 2.29 and
1255 KBUILD_LDFLAGS += -z noexecstack
1261 LDFLAGS_vmlinux += -X
1265 # ld.lld before 15 did not support -z pack-relative-relocs.
1266 LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
1272 LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
1275 # --emit-relocs is added by scripts/link-vmlinux.sh, for the final link only.
1277 LDFLAGS_vmlinux += --discard-none
1281 USERFLAGS_FROM_KERNEL := --target=%
1288 USERFLAGS_FROM_KERNEL += -m32 -m64
1296 KBUILD_USERLDFLAGS += --ld-path=$(LD)
1300 CHECKFLAGS += --arch=$(ARCH)
1303 CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1306 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1310 ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1)
1341 MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
1348 build-dir := .
1349 clean-dirs := $(sort . Documentation \
1350 $(patsubst %/,%,$(filter %/, $(core-) \
1351 $(drivers-) $(libs-))))
1353 export ARCH_CORE := $(core-y)
1354 export ARCH_LIB := $(filter %/, $(libs-y))
1355 export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
1356 # Externally visible symbols (used by link-vmlinux.sh)
1358 KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1359 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1366 # we have to build modules as well to determine what those symbols are.
1371 vmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1372 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a
1379 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
1398 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
1422 # or the modules are listed in "prepare".
1423 # A multi level approach is used. prepareN is processed before prepareN-1.
1430 asm-generic $(version_h) include/generated/utsrelease.h \
1432 include/generated/rustc_cfg remove-stale-files
1445 PHONY += remove-stale-files
1446 remove-stale-files:
1447 $(Q)$(srctree)/scripts/remove-stale-files
1449 # Support for using generic headers in asm-generic
1450 asm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj
1452 PHONY += asm-generic uapi-asm-generic
1453 asm-generic: uapi-asm-generic
1454 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1455 generic=include/asm-generic
1456 uapi-asm-generic:
1457 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1458 generic=include/uapi/asm-generic
1461 # ---------------------------------------------------------------------------
1468 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1476 if [ $(SUBLEVEL) -gt 255 ]; then \
1506 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1507 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
1509 # ---------------------------------------------------------------------------
1517 mkdir -p $(INSTALL_HDR_PATH); \
1518 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1527 hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1530 headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders
1532 $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers
1534 $(Q)$(MAKE) $(hdr-inst)=include/uapi
1535 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
1554 # ---------------------------------------------------------------------------
1562 header-check-dirs := $(filter-out %.h,$(HEADER_CHECK))
1563 header-check-files := $(filter %.h,$(HEADER_CHECK)) $(if $(header-check-dirs),$(shell cd $(srctree) && find $(header-check-dirs) -name '*.h' 2>/dev/null))
1564 header-check-targets := $(patsubst %.h,%.header-check,$(sort $(header-check-files)))
1567 $(if $(header-check-targets),,$(error $@ found no headers in HEADER_CHECK="$(HEADER_CHECK)"))
1568 $(Q)$(MAKE) $(header-check-targets)
1574 # ---------------------------------------------------------------------------
1579 # to this Makefile to build and install external modules.
1585 # ---------------------------------------------------------------------------
1589 vdso_install: export INSTALL_FILES = $(vdso-install-y)
1591 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
1593 # ---------------------------------------------------------------------------
1614 # the target's --target=/--sysroot= flags into the host clang invocation under
1618 $(Q)mkdir -p $(objtree)/tools
1619 $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ \
1636 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1645 $(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) $(patsubst objtool_%,%,$@)
1654 $(Q)$(MAKE) -sC $(srctree)/tools/bootconfig O=$(bootconfig_O) clean
1658 $(Q)mkdir -p $(objtree)/tools
1659 $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1662 $(Q)mkdir -p $(objtree)/tools
1663 $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1665 # ---------------------------------------------------------------------------
1670 $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1672 kselftest-%: headers FORCE
1673 $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $*
1675 PHONY += kselftest-merge
1676 kselftest-merge:
1678 $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \
1679 xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config
1680 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1682 # ---------------------------------------------------------------------------
1705 $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
1723 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
1756 $(Q)$(srctree)/scripts/dtc/dt-style-selftest/run.sh
1758 # ---------------------------------------------------------------------------
1759 # Modules
1763 # By default, build modules as well
1765 all: modules
1767 # When we're building modules with modversions, we need to consider
1768 # the built-in objects during the descend as well, in order to
1774 # Build modules
1781 modules: vmlinux
1784 modules: modules_prepare
1786 # Target to prepare building external modules
1795 # Leave enough to build external modules
1800 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
1801 modules.builtin modules.builtin.modinfo modules.nsdeps \
1802 modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \
1804 vmlinux.thinlto-index builtin.order \
1806 rust-project.json .vmlinux.objs .vmlinux.export.c \
1807 .builtin-dtbs-list .builtin-dtbs.S sbom-*.spdx.json
1812 debian snap tar-install PKGBUILD pacman \
1817 vmlinux-gdb.py \
1823 # clean - Delete most, but leave enough to build external modules
1825 clean: private rm-files := $(CLEAN_FILES)
1830 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1831 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
1835 # mrproper - Delete all generated files, including .config
1837 mrproper: private rm-files := $(MRPROPER_FILES)
1838 mrproper-dirs := $(addprefix _mrproper_,scripts)
1840 PHONY += $(mrproper-dirs) mrproper
1841 $(mrproper-dirs):
1844 mrproper: clean objtool_mrproper $(mrproper-dirs)
1847 \( -name '*.rmeta' \) \
1848 -type f -print | xargs rm -f
1856 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1857 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1858 -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
1859 -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
1860 -type f -print | xargs rm -f
1864 # ---------------------------------------------------------------------------
1866 modules-cpio-pkg: scripts_gen_init_cpio
1868 %src-pkg: FORCE
1869 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1871 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1874 # ---------------------------------------------------------------------------
1878 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1879 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1884 @echo ' clean - Remove most generated files but keep the config and'
1885 @echo ' enough build support to build external modules'
1886 @echo ' mrproper - Remove all generated files + config + various backup files'
1887 @echo ' distclean - mrproper + remove editor backup and patch files'
1889 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1892 @echo ' all - Build all targets marked with [*]'
1893 @echo '* vmlinux - Build the bare kernel'
1894 @echo '* modules - Build all modules'
1895 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1896 @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
1897 @echo ' dir/ - Build all files in dir and below'
1898 @echo ' dir/file.[ois] - Build specified target only'
1899 @echo ' dir/file.ll - Build the LLVM assembly file'
1901 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1903 @echo ' dir/file.ko - Build module including final link'
1904 @echo ' modules_prepare - Set up for building external modules'
1905 @echo ' tags/TAGS - Generate tags file for editors'
1906 @echo ' cscope - Generate cscope index'
1907 @echo ' gtags - Generate GNU GLOBAL index'
1908 @echo ' kernelrelease - Output the release version string (use with make -s)'
1909 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1910 @echo ' image_name - Output the image name (use with make -s)'
1911 @echo ' headers - Build ready-to-install UAPI headers in usr/include'
1912 @echo ' headers_install - Install sanitised kernel UAPI headers to INSTALL_HDR_PATH'; \
1916 @echo ' checkstack - Generate a list of stack hogs and consider all functions'
1918 @echo ' versioncheck - Sanity check on version.h usage'
1919 @echo ' includecheck - Check for duplicate included header files'
1920 @echo ' headerdep - Detect inclusion cycles in headers'
1921 @echo ' headercheck - Check headers in HEADER_CHECK=(headers|dirs) are'
1922 @echo ' self-contained, have header guards, and pass kernel-doc.'
1923 @echo ' coccicheck - Check with Coccinelle'
1924 @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references'
1925 @echo ' clang-analyzer - Check with clang static analyzer'
1926 @echo ' clang-tidy - Check with clang-tidy'
1929 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1930 @echo ' sbom - Generate Software Bill of Materials'
1933 @echo ' kselftest - Build and run kernel selftest'
1937 @echo ' kselftest-all - Build kernel selftest'
1938 @echo ' kselftest-install - Build and install kernel selftest'
1939 @echo ' kselftest-clean - Remove all generated kselftest files'
1940 @echo ' kselftest-merge - Merge all the config dependencies of'
1944 @echo ' rustavailable - Checks whether the Rust toolchain is'
1946 @echo ' rustfmt - Reformat all the Rust code in the kernel'
1947 @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
1949 @echo ' rustdoc - Generate Rust documentation'
1951 @echo ' rusttest - Runs the Rust tests'
1953 @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
1955 @echo ' dir/file.[os] - Build specified target only'
1956 @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1959 @echo ' dir/file.ll - Build the LLVM assembly file'
1963 echo '* dtbs - Build device tree blobs for enabled boards'; \
1964 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1965 echo ' dt_binding_check - Validate device tree binding documents and examples'; \
1966 echo ' dt_binding_schemas - Build processed device tree binding schemas'; \
1967 echo ' dt_style_selftest - Run dt-check-style fixture tests'; \
1968 echo ' dtbs_check - Validate device tree source files';\
1976 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
1979 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1981 @echo 'Architecture-specific targets ($(SRCARCH)):'
1983 echo ' No architecture-specific help defined for $(SRCARCH)')
1987 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1989 @$(if $(board-dirs), \
1990 $(foreach b, $(board-dirs), \
1991 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1992 printf " %-16s - Show all of the above\\n" help-boards; \
1999 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
2021 help-board-dirs := $(addprefix help-,$(board-dirs))
2023 help-boards: $(help-board-dirs)
2025 boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
2027 $(help-board-dirs): help-%:
2028 @echo 'Architecture-specific targets ($(SRCARCH) $*):'
2029 @$(if $(boards-per-dir), \
2030 $(foreach b, $(boards-per-dir), \
2031 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
2036 # ---------------------------------------------------------------------------
2039 htmldocs-redirects testdocs
2047 # ---------------------------------------------------------------------------
2056 # Using the singular to avoid running afoul of `no-dot-config-targets`.
2074 -path $(srctree)/rust/proc-macro2 \
2075 -o -path $(srctree)/rust/quote \
2076 -o -path $(srctree)/rust/syn \
2077 -o -path $(srctree)/rust/zerocopy \
2078 -o -path $(srctree)/rust/zerocopy-derive \
2079 \) -prune -o \
2080 -type f -a -name '*.rs' -a ! -name '*generated*' -print \
2083 rustfmtcheck: rustfmt_flags = --check
2087 # ---------------------------------------------------------------------------
2089 PHONY += misc-check
2090 misc-check:
2091 $(Q)$(srctree)/scripts/misc-check
2093 all: misc-check
2098 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
2110 # When building external modules the kernel used as basis is considered
2111 # read-only, and no consistency checks are made and the make
2115 # We are always building only modules.
2119 build-dir := .
2121 clean-dirs := .
2122 clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json
2142 @echo ' Building external modules.'
2143 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
2145 @echo ' modules - default target, build the module(s)'
2146 @echo ' modules_install - install the module'
2147 @echo ' clean - remove generated files in module directory only'
2148 @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
2152 modules modules_install: __external_modules_error
2156 @echo >&2 '*** You cannot build or install external modules.'
2163 # ---------------------------------------------------------------------------
2164 # Modules
2166 PHONY += modules modules_install modules_sign modules_prepare
2169 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
2170 sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
2180 @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.'
2187 modules.order: $(build-dir)
2190 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
2192 modules: modpost
2194 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
2198 modules_check: modules.order
2199 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
2203 modules:
2211 modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
2213 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
2216 # ---------------------------------------------------------------------------
2221 # The supported suffixes for single-target are listed in 'single-targets'
2227 ifdef single-build
2230 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
2231 single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
2232 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
2234 $(single-ko): single_modules
2236 $(single-no-ko): $(build-dir)
2239 # Remove modules.order when done because it is not the real one.
2241 single_modules: $(single-no-ko) modules_prepare
2242 $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order
2243 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
2245 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
2247 $(Q)rm -f modules.order
2249 single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
2261 PHONY += $(build-dir)
2262 $(build-dir): prepare
2263 $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
2265 clean-dirs := $(addprefix _clean_, $(clean-dirs))
2266 PHONY += $(clean-dirs) clean
2267 $(clean-dirs):
2270 clean: $(clean-dirs)
2273 \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
2274 -o -name '*.ko.*' -o -name '*.o.thinlto.bc' \
2275 -o -name '*.dtb' -o -name '*.dtbo' \
2276 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
2277 -o -name '*.dt.yaml' -o -name 'dtbs-list' \
2278 -o -name '*.dwo' -o -name '*.lst' \
2279 -o -name '*.su' -o -name '*.mod' \
2280 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
2281 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
2282 -o -name '*.asn1.[ch]' \
2283 -o -name '*.symtypes' -o -name 'modules.order' \
2284 -o -name '*.c.[012]*.*' \
2285 -o -name '*.ll' \
2286 -o -name '*.gcno' \
2287 -o -name '*.long-type-*.txt' \
2288 -o -name '*.header-check' \
2289 \) -type f -print \
2290 -o -name '.tmp_*' -print \
2291 | xargs rm -rf
2294 # ---------------------------------------------------------------------------
2301 # Generate rust-project.json (a file that describes the structure of non-Cargo
2302 # Rust projects) for rust-analyzer (an implementation of the Language Server
2304 PHONY += rust-analyzer
2305 rust-analyzer:
2308 # FIXME: external modules must not descend into a sub-directory of the kernel
2315 # ---------------------------------------------------------------------------
2319 nsdeps: modules
2323 # ---------------------------------------------------------------------------
2326 sbom_targets := sbom-source.spdx.json
2328 sbom_targets += sbom-build.spdx.json sbom-output.spdx.json
2330 cmd_sbom = printf "%s\n" "$(KBUILD_IMAGE)" >"$(tmp-target)"; \
2331 $(if $(CONFIG_MODULES),sed 's/\.o$$/.ko/' $(objtree)/modules.order >> "$(tmp-target)";) \
2333 --src-tree $(abspath $(srctree)) \
2334 --obj-tree $(abspath $(objtree)) \
2335 --roots-file "$(tmp-target)" \
2336 --output-directory $(abspath $(objtree)) \
2337 --generate-spdx \
2338 --package-license "GPL-2.0 WITH Linux-syscall-note" \
2339 --package-version "$(KERNELVERSION)" \
2340 --write-output-on-error;
2342 sbom: $(notdir $(KBUILD_IMAGE)) include/generated/autoconf.h $(if $(CONFIG_MODULES),modules modules.order)
2346 # ---------------------------------------------------------------------------
2349 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
2351 compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
2353 $(if $(CONFIG_MODULES), modules.order) FORCE
2358 PHONY += clang-tidy clang-analyzer
2362 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
2364 clang-tidy clang-analyzer: compile_commands.json
2367 clang-tidy clang-analyzer:
2373 # ---------------------------------------------------------------------------
2375 PHONY += includecheck versioncheck coccicheck kconfig-sym-check
2379 -name '*.[hcS]' -type f -print | sort \
2380 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
2384 -name '*.[hcS]' -type f -print | sort \
2385 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
2390 kconfig-sym-check:
2391 $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES)
2397 # else wants $(ARCH), including people doing cross-builds, which means
2406 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
2418 PHONY += run-command
2419 run-command:
2422 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
2423 cmd_rmfiles = rm -rf $(rm-files)
2426 existing-targets := $(wildcard $(sort $(targets)))
2428 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
2430 endif # config-build
2431 endif # mixed-build
2432 endif # need-sub-make