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))
168 # cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
195 # source directory or kernel build directory), external modules
212 # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.
213 $(shell mkdir -p "$(output)")
229 no-print-directory := --no-print-directory
232 need-sub-make := 1
235 ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
236 # If --no-print-directory is unset, recurse once again to set it.
237 # You may end up recursing into __sub-make twice. This is needed due to the
239 need-sub-make := 1
242 ifeq ($(need-sub-make),1)
244 PHONY += $(MAKECMDGOALS) __sub-make
246 $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
250 __sub-make:
251 $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \
252 -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
254 else # need-sub-make
296 clean-targets := %clean mrproper cleandocs
297 no-dot-config-targets := $(clean-targets) \
300 %asm-generic kernelversion %src-pkg dt_binding_check \
302 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
304 single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
306 config-build :=
307 mixed-build :=
308 need-config := 1
309 may-sync-config := 1
310 single-build :=
312 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
313 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
314 need-config :=
318 ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
319 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
320 may-sync-config :=
324 need-compiler := $(may-sync-config)
327 may-sync-config :=
332 config-build := 1
334 mixed-build := 1
340 ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
341 single-build := 1
342 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
343 mixed-build := 1
347 # For "make -j clean all", "make -j mrproper defconfig all", etc.
348 ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
349 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
350 mixed-build := 1
357 mixed-build := 1
361 ifdef mixed-build
372 $(Q)set -e; \
374 $(MAKE) -f $(srctree)/Makefile $$i; \
377 else # !mixed-build
382 KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)
388 # Cross compiling and selecting different set of gcc/bin-utils
389 # ---------------------------------------------------------------------------
399 # during compilation. Only gcc and related bin-utils executables
402 # make CROSS_COMPILE=aarch64-linux-gnu-
451 else ifneq ($(filter -%,$(LLVM)),)
462 HOSTPKG_CONFIG = pkg-config
464 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
465 -O2 -fomit-frame-pointer -std=gnu11
471 export rust_common_flags := --edition=2021 \
472 -Zbinary_dep_depinfo=y \
473 -Astable_features \
474 -Dnon_ascii_idents \
475 -Dunsafe_op_in_unsafe_fn \
476 -Wmissing_docs \
477 -Wrust_2018_idioms \
478 -Wunreachable_pub \
479 -Wclippy::all \
480 -Wclippy::ignored_unit_patterns \
481 -Wclippy::mut_mut \
482 -Wclippy::needless_bitwise_bool \
483 -Aclippy::needless_lifetimes \
484 -Wclippy::no_mangle_with_rust_abi \
485 -Wclippy::undocumented_unsafe_blocks \
486 -Wclippy::unnecessary_safety_comment \
487 -Wclippy::unnecessary_safety_doc \
488 -Wrustdoc::missing_crate_level_docs \
489 -Wrustdoc::unescaped_backticks
492 $(HOSTCFLAGS) -I $(srctree)/scripts/include
493 KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
494 -I $(srctree)/scripts/include
495 KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
496 -Zallow-features= $(HOSTRUSTFLAGS)
502 CPP = $(CC) -E
506 AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
507 NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
508 OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
509 OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
510 READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
511 STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
525 CLIPPY_DRIVER = clippy-driver
545 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
546 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
559 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
560 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
561 -I$(srctree)/include/uapi \
562 -I$(objtree)/include/generated/uapi \
563 -include $(srctree)/include/linux/compiler-version.h \
564 -include $(srctree)/include/linux/kconfig.h
569 -I$(srctree)/arch/$(SRCARCH)/include \
570 -I$(objtree)/arch/$(SRCARCH)/include/generated \
571 -I$(srctree)/include \
572 -I$(objtree)/include \
575 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
578 KBUILD_CFLAGS += -std=gnu11
579 KBUILD_CFLAGS += -fshort-wchar
580 KBUILD_CFLAGS += -funsigned-char
581 KBUILD_CFLAGS += -fno-common
582 KBUILD_CFLAGS += -fno-PIE
583 KBUILD_CFLAGS += -fno-strict-aliasing
585 KBUILD_CPPFLAGS := -D__KERNEL__
587 -Cpanic=abort -Cembed-bitcode=n -Clto=n \
588 -Cforce-unwind-tables=n -Ccodegen-units=1 \
589 -Csymbol-mangling-version=v0 \
590 -Crelocation-model=static \
591 -Zfunction-sections=n \
592 -Wclippy::float_arithmetic
597 KBUILD_AFLAGS_MODULE := -DMODULE
598 KBUILD_CFLAGS_MODULE := -DMODULE
599 KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
615 # Allows finding `.clippy.toml` in out-of-srctree builds.
636 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
637 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
638 -prune -o
650 # Before starting out-of-tree build, make sure the source tree is clean.
676 @if [ -f $(srctree)/.config -o \
677 -d $(srctree)/include/config -o \
678 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
686 @if [ -f $(srcroot)/modules.order ]; then \
689 echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \
694 $(Q)ln -fsn $(srcroot) source
696 $(Q)test -e .gitignore || \
705 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
706 RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
713 # cc-cross-prefix to determine CROSS_COMPILE.
714 ifdef need-compiler
718 ifdef config-build
720 # *config targets only - make sure prerequisites are updated, and descend
723 # Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.
735 else #!config-build
737 # Build targets only - this includes vmlinux, arch-specific targets, clean
741 # but instead __all depend on modules
746 __all: modules
751 # Decide whether to build built-in, modular, or both.
752 # Normally, just do built-in.
757 # If we have only "make modules", don't compile built-in objects.
758 ifeq ($(MAKECMDGOALS),modules)
762 # If we have "make <whatever> modules", compile modules
764 # Just "make" or "make all" shall build modules as well
766 ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),)
776 ifdef need-config
782 core-y :=
783 drivers-y :=
784 libs-y := lib/
789 # This allow a user to issue only 'make' to build a kernel including modules
793 CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
795 CFLAGS_GCOV += -fno-tree-loop-im
801 CC_FLAGS_FTRACE := -pg
806 ifdef need-config
807 ifdef may-sync-config
826 # This exploits the 'multi-target pattern rule' trick.
834 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
835 else # !may-sync-config
836 # External modules and some install targets need include/generated/autoconf.h
837 # and include/config/auto.conf but do not care if they are up-to-date.
840 checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf)
841 missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))
843 ifdef missing-configs
849 @printf >&2 '*** - %s\n' $(missing-configs)
855 endif # may-sync-config
856 endif # need-config
858 KBUILD_CFLAGS += -fno-delete-null-pointer-checks
861 KBUILD_CFLAGS += -O2
862 KBUILD_RUSTFLAGS += -Copt-level=2
864 KBUILD_CFLAGS += -Os
865 KBUILD_RUSTFLAGS += -Copt-level=s
868 # Always set `debug-assertions` and `overflow-checks` because their default
869 # depends on `opt-level` and `debug-assertions`, respectively.
870 KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
871 KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
873 # Tell gcc to never replace conditional load with a non-conditional one
875 # gcc-10 renamed --param=allow-store-data-races=0 to
876 # -fno-allow-store-data-races.
877 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
878 KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
886 KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
889 stackp-flags-y := -fno-stack-protector
890 stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
891 stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
893 KBUILD_CFLAGS += $(stackp-flags-y)
895 KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
896 KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
899 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
900 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
904 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
905 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
906 # -fomit-frame-pointer with FUNCTION_TRACER.
907 # In the Rust target specification, "frame-pointer" is set explicitly
908 # to "may-omit".
910 KBUILD_CFLAGS += -fomit-frame-pointer
916 KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
921 KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
923 # https://github.com/llvm/llvm-project/issues/44842
924 CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
932 KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
936 KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
941 CC_FLAGS_FTRACE += -mrecord-mcount
943 ifeq ($(call cc-option-yn, -mnop-mcount),y)
944 CC_FLAGS_FTRACE += -mnop-mcount
945 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
951 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
961 # s390-linux-gnu-gcc did not support -mfentry until gcc-9.
962 ifeq ($(call cc-option-yn, -mfentry),y)
963 CC_FLAGS_FTRACE += -mfentry
964 CC_FLAGS_USING += -DCC_USING_FENTRY
974 KBUILD_CFLAGS += -fno-inline-functions-called-once
977 # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
979 KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
980 KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
981 LDFLAGS_vmlinux += --gc-sections
986 CC_FLAGS_SCS := -fsanitize=shadow-call-stack
988 KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
995 CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
997 CC_FLAGS_LTO := -flto
999 CC_FLAGS_LTO += -fvisibility=hidden
1002 KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
1006 KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
1007 KBUILD_AFLAGS += -fno-lto
1012 CC_FLAGS_CFI := -fsanitize=kcfi
1014 CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
1017 # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
1019 RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
1027 # Architectures can define flags to add/remove for floating-point support
1028 CC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT
1034 # -fmin-function-alignment if it is available, or fall back to -falign-funtions.
1037 KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
1039 KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
1044 NOSTDINC_FLAGS += -nostdinc
1050 KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
1052 #Currently, disable -Wstringop-overflow for GCC 11, globally.
1053 KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
1054 KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
1057 KBUILD_CFLAGS += -fno-strict-overflow
1059 # Make sure -fstack-check isn't enabled (like gentoo apparently did)
1060 KBUILD_CFLAGS += -fno-stack-check
1064 KBUILD_CFLAGS += -fconserve-stack
1068 KBUILD_CFLAGS += -fno-builtin-wcslen
1072 KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=)
1076 include-y := scripts/Makefile.extrawarn
1077 include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
1078 include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
1079 include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1080 include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
1081 include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
1082 include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1083 include-$(CONFIG_KCOV) += scripts/Makefile.kcov
1084 include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
1085 include-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdo
1086 include-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propeller
1087 include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1089 include $(addprefix $(srctree)/, $(include-y))
1091 # scripts/Makefile.gcc-plugins is intentionally included last.
1092 # Do not add $(call cc-option,...) below this line. When you build the kernel
1101 KBUILD_LDFLAGS_MODULE += --build-id=sha1
1102 LDFLAGS_vmlinux += --build-id=sha1
1104 KBUILD_LDFLAGS += -z noexecstack
1106 KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
1110 LDFLAGS_vmlinux += -X
1114 # ld.lld before 15 did not support -z pack-relative-relocs.
1115 LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
1121 LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
1125 KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
1126 KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
1130 KBUILD_USERLDFLAGS += --ld-path=$(LD)
1134 CHECKFLAGS += --arch=$(ARCH)
1137 CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1140 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1167 MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
1174 build-dir := .
1175 clean-dirs := $(sort . Documentation \
1176 $(patsubst %/,%,$(filter %/, $(core-) \
1177 $(drivers-) $(libs-))))
1179 export ARCH_CORE := $(core-y)
1180 export ARCH_LIB := $(filter %/, $(libs-y))
1181 export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
1182 # Externally visible symbols (used by link-vmlinux.sh)
1184 KBUILD_VMLINUX_OBJS := ./built-in.a
1186 KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1187 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1189 KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
1197 # we have to build modules as well to determine what those symbols are.
1201 # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
1204 rm -f $@; \
1206 $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
1209 vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1214 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
1216 vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o
1233 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
1257 # or the modules are listed in "prepare".
1258 # A multi level approach is used. prepareN is processed before prepareN-1.
1265 asm-generic $(version_h) include/generated/utsrelease.h \
1267 include/generated/rustc_cfg remove-stale-files
1280 PHONY += remove-stale-files
1281 remove-stale-files:
1282 $(Q)$(srctree)/scripts/remove-stale-files
1284 # Support for using generic headers in asm-generic
1285 asm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj
1287 PHONY += asm-generic uapi-asm-generic
1288 asm-generic: uapi-asm-generic
1289 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1290 generic=include/asm-generic
1291 uapi-asm-generic:
1292 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1293 generic=include/uapi/asm-generic
1296 # ---------------------------------------------------------------------------
1303 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1311 if [ $(SUBLEVEL) -gt 255 ]; then \
1341 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1342 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
1344 # ---------------------------------------------------------------------------
1352 mkdir -p $(INSTALL_HDR_PATH); \
1353 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1362 hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1365 headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1367 $(Q)$(MAKE) $(hdr-inst)=include/uapi
1368 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
1382 # ---------------------------------------------------------------------------
1387 # to this Makefile to build and install external modules.
1393 # ---------------------------------------------------------------------------
1397 vdso_install: export INSTALL_FILES = $(vdso-install-y)
1399 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
1401 # ---------------------------------------------------------------------------
1428 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1432 $(Q)mkdir -p $(objtree)/tools
1433 $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1436 $(Q)mkdir -p $(objtree)/tools
1437 $(Q)$(MAKE) LDFLAGS= O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1439 # ---------------------------------------------------------------------------
1444 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1446 kselftest-%: headers FORCE
1447 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
1449 PHONY += kselftest-merge
1450 kselftest-merge:
1452 $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \
1453 xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config
1454 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1456 # ---------------------------------------------------------------------------
1473 $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
1491 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
1522 # ---------------------------------------------------------------------------
1523 # Modules
1527 # By default, build modules as well
1529 all: modules
1531 # When we're building modules with modversions, we need to consider
1532 # the built-in objects during the descend as well, in order to
1538 # Build modules
1545 modules: vmlinux
1548 modules: modules_prepare
1550 # Target to prepare building external modules
1559 # Leave enough to build external modules
1564 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
1565 modules.builtin modules.builtin.modinfo modules.nsdeps \
1566 modules.builtin.ranges vmlinux.o.map \
1568 rust-project.json .vmlinux.objs .vmlinux.export.c \
1569 .builtin-dtbs-list .builtin-dtb.S
1574 debian snap tar-install PKGBUILD pacman \
1579 vmlinux-gdb.py \
1583 # clean - Delete most, but leave enough to build external modules
1585 clean: private rm-files := $(CLEAN_FILES)
1590 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1591 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
1595 # mrproper - Delete all generated files, including .config
1597 mrproper: private rm-files := $(MRPROPER_FILES)
1598 mrproper-dirs := $(addprefix _mrproper_,scripts)
1600 PHONY += $(mrproper-dirs) mrproper
1601 $(mrproper-dirs):
1604 mrproper: clean $(mrproper-dirs)
1607 \( -name '*.rmeta' \) \
1608 -type f -print | xargs rm -f
1616 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1617 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1618 -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
1619 -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
1620 -type f -print | xargs rm -f
1624 # ---------------------------------------------------------------------------
1626 %src-pkg: FORCE
1627 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1629 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1632 # ---------------------------------------------------------------------------
1636 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1637 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1642 @echo ' clean - Remove most generated files but keep the config and'
1643 @echo ' enough build support to build external modules'
1644 @echo ' mrproper - Remove all generated files + config + various backup files'
1645 @echo ' distclean - mrproper + remove editor backup and patch files'
1647 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1650 @echo ' all - Build all targets marked with [*]'
1651 @echo '* vmlinux - Build the bare kernel'
1652 @echo '* modules - Build all modules'
1653 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1654 @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
1655 @echo ' dir/ - Build all files in dir and below'
1656 @echo ' dir/file.[ois] - Build specified target only'
1657 @echo ' dir/file.ll - Build the LLVM assembly file'
1659 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1661 @echo ' dir/file.ko - Build module including final link'
1662 @echo ' modules_prepare - Set up for building external modules'
1663 @echo ' tags/TAGS - Generate tags file for editors'
1664 @echo ' cscope - Generate cscope index'
1665 @echo ' gtags - Generate GNU GLOBAL index'
1666 @echo ' kernelrelease - Output the release version string (use with make -s)'
1667 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1668 @echo ' image_name - Output the image name (use with make -s)'
1669 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1673 @echo ' checkstack - Generate a list of stack hogs and consider all functions'
1675 @echo ' versioncheck - Sanity check on version.h usage'
1676 @echo ' includecheck - Check for duplicate included header files'
1677 @echo ' headerdep - Detect inclusion cycles in headers'
1678 @echo ' coccicheck - Check with Coccinelle'
1679 @echo ' clang-analyzer - Check with clang static analyzer'
1680 @echo ' clang-tidy - Check with clang-tidy'
1683 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1686 @echo ' kselftest - Build and run kernel selftest'
1690 @echo ' kselftest-all - Build kernel selftest'
1691 @echo ' kselftest-install - Build and install kernel selftest'
1692 @echo ' kselftest-clean - Remove all generated kselftest files'
1693 @echo ' kselftest-merge - Merge all the config dependencies of'
1697 @echo ' rustavailable - Checks whether the Rust toolchain is'
1699 @echo ' rustfmt - Reformat all the Rust code in the kernel'
1700 @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
1702 @echo ' rustdoc - Generate Rust documentation'
1704 @echo ' rusttest - Runs the Rust tests'
1706 @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
1708 @echo ' dir/file.[os] - Build specified target only'
1709 @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1712 @echo ' dir/file.ll - Build the LLVM assembly file'
1716 echo '* dtbs - Build device tree blobs for enabled boards'; \
1717 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1718 echo ' dt_binding_check - Validate device tree binding documents and examples'; \
1719 echo ' dt_binding_schemas - Build processed device tree binding schemas'; \
1720 echo ' dtbs_check - Validate device tree source files';\
1728 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
1731 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1733 @echo 'Architecture-specific targets ($(SRCARCH)):'
1735 echo ' No architecture-specific help defined for $(SRCARCH)')
1739 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1741 @$(if $(board-dirs), \
1742 $(foreach b, $(board-dirs), \
1743 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1744 printf " %-16s - Show all of the above\\n" help-boards; \
1751 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
1771 help-board-dirs := $(addprefix help-,$(board-dirs))
1773 help-boards: $(help-board-dirs)
1775 boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
1777 $(help-board-dirs): help-%:
1778 @echo 'Architecture-specific targets ($(SRCARCH) $*):'
1779 @$(if $(boards-per-dir), \
1780 $(foreach b, $(boards-per-dir), \
1781 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1786 # ---------------------------------------------------------------------------
1795 # ---------------------------------------------------------------------------
1804 # Using the singular to avoid running afoul of `no-dot-config-targets`.
1819 -type f -a -name '*.rs' -a ! -name '*generated*' -print \
1822 rustfmtcheck: rustfmt_flags = --check
1826 # ---------------------------------------------------------------------------
1828 PHONY += misc-check
1829 misc-check:
1830 $(Q)$(srctree)/scripts/misc-check
1832 all: misc-check
1837 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1849 # When building external modules the kernel used as basis is considered
1850 # read-only, and no consistency checks are made and the make
1854 # We are always building only modules.
1858 build-dir := .
1860 clean-dirs := .
1861 clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json
1875 @echo ' Building external modules.'
1876 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1878 @echo ' modules - default target, build the module(s)'
1879 @echo ' modules_install - install the module'
1880 @echo ' clean - remove generated files in module directory only'
1881 @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
1885 modules modules_install: __external_modules_error
1889 @echo >&2 '*** You cannot build or install external modules.'
1896 # ---------------------------------------------------------------------------
1897 # Modules
1899 PHONY += modules modules_install modules_sign modules_prepare
1902 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
1903 sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
1913 @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.'
1920 modules.order: $(build-dir)
1923 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
1925 modules: modpost
1927 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1931 modules_check: modules.order
1932 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
1936 modules:
1944 modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
1946 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1949 # ---------------------------------------------------------------------------
1954 # The supported suffixes for single-target are listed in 'single-targets'
1960 ifdef single-build
1963 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
1964 single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
1965 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
1967 $(single-ko): single_modules
1969 $(single-no-ko): $(build-dir)
1972 # Remove modules.order when done because it is not the real one.
1974 single_modules: $(single-no-ko) modules_prepare
1975 $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order
1976 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1978 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1980 $(Q)rm -f modules.order
1982 single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
1994 PHONY += $(build-dir)
1995 $(build-dir): prepare
1996 $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
1998 clean-dirs := $(addprefix _clean_, $(clean-dirs))
1999 PHONY += $(clean-dirs) clean
2000 $(clean-dirs):
2003 clean: $(clean-dirs)
2006 \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
2007 -o -name '*.ko.*' \
2008 -o -name '*.dtb' -o -name '*.dtbo' \
2009 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
2010 -o -name '*.dt.yaml' -o -name 'dtbs-list' \
2011 -o -name '*.dwo' -o -name '*.lst' \
2012 -o -name '*.su' -o -name '*.mod' \
2013 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
2014 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
2015 -o -name '*.asn1.[ch]' \
2016 -o -name '*.symtypes' -o -name 'modules.order' \
2017 -o -name '*.c.[012]*.*' \
2018 -o -name '*.ll' \
2019 -o -name '*.gcno' \
2020 \) -type f -print \
2021 -o -name '.tmp_*' -print \
2022 | xargs rm -rf
2025 # ---------------------------------------------------------------------------
2032 # Generate rust-project.json (a file that describes the structure of non-Cargo
2033 # Rust projects) for rust-analyzer (an implementation of the Language Server
2035 PHONY += rust-analyzer
2036 rust-analyzer:
2039 # FIXME: external modules must not descend into a sub-directory of the kernel
2046 # ---------------------------------------------------------------------------
2050 nsdeps: modules
2054 # ---------------------------------------------------------------------------
2057 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
2059 compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
2061 $(if $(CONFIG_MODULES), modules.order) FORCE
2066 PHONY += clang-tidy clang-analyzer
2070 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
2072 clang-tidy clang-analyzer: compile_commands.json
2075 clang-tidy clang-analyzer:
2081 # ---------------------------------------------------------------------------
2087 -name '*.[hcS]' -type f -print | sort \
2088 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
2092 -name '*.[hcS]' -type f -print | sort \
2093 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
2102 # else wants $(ARCH), including people doing cross-builds, which means
2111 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
2123 PHONY += run-command
2124 run-command:
2127 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
2128 cmd_rmfiles = rm -rf $(rm-files)
2131 existing-targets := $(wildcard $(sort $(targets)))
2133 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
2135 endif # config-build
2136 endif # mixed-build
2137 endif # need-sub-make