Lines Matching +full:build +full:- +full:tools +full:- +full:and +full:- +full:docs +full:- +full:debian

1 # SPDX-License-Identifier: GPL-2.0
12 # expect to learn how to build the kernel reading this file.
25 # We are using a recursive build, so we need to do a little thinking
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
37 # effects are thus separated out and done before the recursive
41 this-makefile := $(lastword $(MAKEFILE_LIST))
42 export 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 # ---------------------------------------------------------------------------
63 # Most of build commands in Kbuild start with "cmd_". You can optionally define
71 # A simple variant is to prefix commands with $(Q) - that's useful
72 # for commands that shall be hidden in non-verbose mode.
74 # $(Q)$(MAKE) $(build)=scripts/basic
94 # If the user is running make -s (silent mode), suppress echoing of
96 # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS.
99 short-opts := $(firstword -$(MAKEFLAGS))
101 short-opts := $(filter-out --%,$(MAKEFLAGS))
104 ifneq ($(findstring s,$(short-opts)),)
114 # Use 'make C=1' to enable checking of only re-compiled files.
116 # of whether they are re-compiled or not.
118 # See the file "Documentation/dev-tools/sparse.rst" for more details,
140 # directory of external module to build. Setting M= takes precedence.
163 # cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
184 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
186 abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
199 # 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
200 # We need to invoke sub-make to avoid implicit rules in the top Makefile.
201 need-sub-make := 1
203 $(this-makefile): ;
212 no-print-directory := --no-print-directory
215 need-sub-make := 1
218 ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
219 # If --no-print-directory is unset, recurse once again to set it.
220 # You may end up recursing into __sub-make twice. This is needed due to the
222 need-sub-make := 1
225 ifeq ($(need-sub-make),1)
227 PHONY += $(MAKECMDGOALS) __sub-make
229 $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
233 __sub-make:
234 $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
235 -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
237 else # need-sub-make
265 # catch them early, and hand them over to scripts/kconfig/Makefile
267 # mixing *config targets and build targets.
269 # Detect when mixed targets is specified, and make a second invocation
274 clean-targets := %clean mrproper cleandocs
275 no-dot-config-targets := $(clean-targets) \
276 cscope gtags TAGS tags help% %docs check% coccicheck \
278 %asm-generic kernelversion %src-pkg dt_binding_check \
281 # is an exception where build artifacts may be updated. This must be fixed.
282 no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
284 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
286 single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/
288 config-build :=
289 mixed-build :=
290 need-config := 1
291 need-compiler := 1
292 may-sync-config := 1
293 single-build :=
295 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
296 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
297 need-config :=
301 ifneq ($(filter $(no-compiler-targets), $(MAKECMDGOALS)),)
302 ifeq ($(filter-out $(no-compiler-targets), $(MAKECMDGOALS)),)
303 need-compiler :=
307 ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
308 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
309 may-sync-config :=
314 may-sync-config :=
319 config-build := 1
321 mixed-build := 1
326 # We cannot build single targets and the others at the same time
327 ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
328 single-build := 1
329 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
330 mixed-build := 1
334 # For "make -j clean all", "make -j mrproper defconfig all", etc.
335 ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
336 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
337 mixed-build := 1
341 # install and modules_install need also be processed one by one
344 mixed-build := 1
348 ifdef mixed-build
350 # We're called with mixed targets (*config and build targets).
359 $(Q)set -e; \
361 $(MAKE) -f $(srctree)/Makefile $$i; \
364 else # !mixed-build
369 KERNELRELEASE = $(call read-file, include/config/kernel.release)
375 # Cross compiling and selecting different set of gcc/bin-utils
376 # ---------------------------------------------------------------------------
386 # during compilation. Only gcc and related bin-utils executables
389 # make CROSS_COMPILE=ia64-linux-
438 else ifneq ($(filter -%,$(LLVM)),)
449 HOSTPKG_CONFIG = pkg-config
451 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
452 -O2 -fomit-frame-pointer -std=gnu11
456 # These flags apply to all Rust code in the tree, including the kernel and
458 export rust_common_flags := --edition=2021 \
459 -Zbinary_dep_depinfo=y \
460 -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
461 -Dunreachable_pub -Dnon_ascii_idents \
462 -Wmissing_docs \
463 -Drustdoc::missing_crate_level_docs \
464 -Dclippy::correctness -Dclippy::style \
465 -Dclippy::suspicious -Dclippy::complexity \
466 -Dclippy::perf \
467 -Dclippy::let_unit_value -Dclippy::mut_mut \
468 -Dclippy::needless_bitwise_bool \
469 -Dclippy::needless_continue \
470 -Dclippy::no_mangle_with_rust_abi \
471 -Wclippy::dbg_macro
474 KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
475 KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
476 -Zallow-features= $(HOSTRUSTFLAGS)
481 CPP = $(CC) -E
485 AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
486 NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
487 OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
488 OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
489 READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
490 STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
504 CLIPPY_DRIVER = clippy-driver
508 RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
525 PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
527 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
528 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
541 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
542 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
543 -I$(srctree)/include/uapi \
544 -I$(objtree)/include/generated/uapi \
545 -include $(srctree)/include/linux/compiler-version.h \
546 -include $(srctree)/include/linux/kconfig.h
551 -I$(srctree)/arch/$(SRCARCH)/include \
552 -I$(objtree)/arch/$(SRCARCH)/include/generated \
553 $(if $(building_out_of_srctree),-I$(srctree)/include) \
554 -I$(objtree)/include \
557 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
560 KBUILD_CFLAGS += -std=gnu11
561 KBUILD_CFLAGS += -fshort-wchar
562 KBUILD_CFLAGS += -funsigned-char
563 KBUILD_CFLAGS += -fno-common
564 KBUILD_CFLAGS += -fno-PIE
565 KBUILD_CFLAGS += -fno-strict-aliasing
567 KBUILD_CPPFLAGS := -D__KERNEL__
569 --target=$(objtree)/scripts/target.json \
570 -Cpanic=abort -Cembed-bitcode=n -Clto=n \
571 -Cforce-unwind-tables=n -Ccodegen-units=1 \
572 -Csymbol-mangling-version=v0 \
573 -Crelocation-model=static \
574 -Zfunction-sections=n \
575 -Dclippy::float_arithmetic
580 KBUILD_AFLAGS_MODULE := -DMODULE
581 KBUILD_CFLAGS_MODULE := -DMODULE
582 KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
621 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
622 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
623 -prune -o
624 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
625 --exclude CVS --exclude .pc --exclude .hg --exclude .git
628 # Rules shared between *config targets and build targets
633 $(Q)$(MAKE) $(build)=scripts/basic
637 # Before starting out-of-tree build, make sure the source tree is clean.
651 @if [ -f $(srctree)/.config -o \
652 -d $(srctree)/include/config -o \
653 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
660 $(Q)ln -fsn $(srctree) source
662 $(Q)test -e .gitignore || \
663 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
669 # and from include/config/auto.conf.cmd to detect the compiler upgrade.
670 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
677 # cc-cross-prefix to determine CROSS_COMPILE.
678 ifdef need-compiler
682 ifdef config-build
684 # *config targets only - make sure prerequisites are updated, and descend
694 $(Q)$(MAKE) $(build)=scripts/kconfig $@
697 $(Q)$(MAKE) $(build)=scripts/kconfig $@
699 else #!config-build
701 # Build targets only - this includes vmlinux, arch specific targets, clean
702 # targets and others. In general all targets except *config targets.
715 # Decide whether to build built-in, modular, or both.
716 # Normally, just do built-in.
721 # If we have only "make modules", don't compile built-in objects.
728 # Just "make" or "make all" shall build modules as well
730 ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
740 ifdef need-config
746 core-y :=
747 drivers-y :=
748 libs-y := lib/
753 # This allow a user to issue only 'make' to build a kernel including modules
757 CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
759 CFLAGS_GCOV += -fno-tree-loop-im
765 CC_FLAGS_FTRACE := -pg
770 ifdef need-config
771 ifdef may-sync-config
786 # The actual configuration files used during the build are stored in
787 # include/generated/ and include/config/. Update them if .config is newer than
790 # This exploits the 'multi-target pattern rule' trick.
798 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
799 else # !may-sync-config
800 # External modules and some install targets need include/generated/autoconf.h
801 # and include/config/auto.conf but do not care if they are up-to-date.
806 @test -e include/generated/autoconf.h -a -e $@ || ( \
814 endif # may-sync-config
815 endif # need-config
817 KBUILD_CFLAGS += -fno-delete-null-pointer-checks
820 KBUILD_CFLAGS += -O2
821 KBUILD_RUSTFLAGS += -Copt-level=2
823 KBUILD_CFLAGS += -Os
824 KBUILD_RUSTFLAGS += -Copt-level=s
827 # Always set `debug-assertions` and `overflow-checks` because their default
828 # depends on `opt-level` and `debug-assertions`, respectively.
829 KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
830 KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
832 # Tell gcc to never replace conditional load with a non-conditional one
834 # gcc-10 renamed --param=allow-store-data-races=0 to
835 # -fno-allow-store-data-races.
836 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
837 KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
845 KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
848 stackp-flags-y := -fno-stack-protector
849 stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
850 stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
852 KBUILD_CFLAGS += $(stackp-flags-y)
854 KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
855 KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
858 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
859 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
863 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
864 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
865 # -fomit-frame-pointer with FUNCTION_TRACER.
866 # In the Rust target specification, "frame-pointer" is set explicitly
867 # to "may-omit".
869 KBUILD_CFLAGS += -fomit-frame-pointer
875 KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
880 KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
882 # https://github.com/llvm/llvm-project/issues/44842
883 CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
891 KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
893 # Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
895 KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
900 CC_FLAGS_FTRACE += -mrecord-mcount
902 ifeq ($(call cc-option-yn, -mnop-mcount),y)
903 CC_FLAGS_FTRACE += -mnop-mcount
904 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
910 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
920 # s390-linux-gnu-gcc did not support -mfentry until gcc-9.
921 ifeq ($(call cc-option-yn, -mfentry),y)
922 CC_FLAGS_FTRACE += -mfentry
923 CC_FLAGS_USING += -DCC_USING_FENTRY
933 KBUILD_CFLAGS += -fno-inline-functions-called-once
936 # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
938 KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
939 KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
940 LDFLAGS_vmlinux += --gc-sections
945 CC_FLAGS_SCS := -fsanitize=shadow-call-stack
953 CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
955 CC_FLAGS_LTO := -flto
957 CC_FLAGS_LTO += -fvisibility=hidden
960 KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
965 ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y)
966 KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN)
972 KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
973 KBUILD_AFLAGS += -fno-lto
978 CC_FLAGS_CFI := -fsanitize=kcfi
984 KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
988 NOSTDINC_FLAGS += -nostdinc
990 # To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
992 # arrays. Enforce this for everything that may examine structure sizes and
994 KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
997 KBUILD_CFLAGS += -fno-strict-overflow
999 # Make sure -fstack-check isn't enabled (like gentoo apparently did)
1000 KBUILD_CFLAGS += -fno-stack-check
1004 KBUILD_CFLAGS += -fconserve-stack
1008 KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
1011 include-y := scripts/Makefile.extrawarn
1012 include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
1013 include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1014 include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
1015 include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
1016 include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1017 include-$(CONFIG_KCOV) += scripts/Makefile.kcov
1018 include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
1019 include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1021 include $(addprefix $(srctree)/, $(include-y))
1023 # scripts/Makefile.gcc-plugins is intentionally included last.
1024 # Do not add $(call cc-option,...) below this line. When you build the kernel
1027 # Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments
1033 KBUILD_LDFLAGS_MODULE += --build-id=sha1
1034 LDFLAGS_vmlinux += --build-id=sha1
1036 KBUILD_LDFLAGS += -z noexecstack
1038 KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
1042 LDFLAGS_vmlinux += -X
1046 # ld.lld before 15 did not support -z pack-relative-relocs.
1047 LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
1053 LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
1057 KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1058 KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1061 CHECKFLAGS += --arch=$(ARCH)
1064 CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1067 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1069 # Default kernel image to build when no specific target is given.
1077 # INSTALL_PATH specifies where to place the updated kernel and system map
1082 # INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
1090 # relocations required by build roots. This is not defined in the
1105 build-dir := .
1106 clean-dirs := $(sort . Documentation \
1107 $(patsubst %/,%,$(filter %/, $(core-) \
1108 $(drivers-) $(libs-))))
1110 export ARCH_CORE := $(core-y)
1111 export ARCH_LIB := $(filter %/, $(libs-y))
1112 export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
1113 # Externally visible symbols (used by link-vmlinux.sh)
1115 KBUILD_VMLINUX_OBJS := ./built-in.a
1117 KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1118 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1120 KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
1128 # we have to build modules as well to determine what those symbols are.
1132 # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
1135 rm -f $@; \
1137 $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
1140 vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1145 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
1164 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
1181 # Carefully list dependencies so we do not try to build scripts twice
1185 $(Q)$(MAKE) $(build)=$(@)
1189 # A multi level approach is used. prepareN is processed before prepareN-1.
1190 # archprepare is used in arch Makefiles and when processed asm symlink,
1191 # version.h and scripts_basic is processed / created.
1196 asm-generic $(version_h) include/generated/utsrelease.h \
1197 include/generated/compile.h include/generated/autoconf.h remove-stale-files
1200 $(Q)$(MAKE) $(build)=scripts/mod
1201 $(Q)$(MAKE) $(build)=. prepare
1207 $(Q)$(MAKE) $(build)=rust
1210 PHONY += remove-stale-files
1211 remove-stale-files:
1212 $(Q)$(srctree)/scripts/remove-stale-files
1214 # Support for using generic headers in asm-generic
1215 asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1217 PHONY += asm-generic uapi-asm-generic
1218 asm-generic: uapi-asm-generic
1219 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1220 generic=include/asm-generic
1221 uapi-asm-generic:
1222 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1223 generic=include/uapi/asm-generic
1226 # ---------------------------------------------------------------------------
1233 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1241 if [ $(SUBLEVEL) -gt 255 ]; then \
1271 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1272 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
1274 # ---------------------------------------------------------------------------
1282 mkdir -p $(INSTALL_HDR_PATH); \
1283 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1292 hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1295 headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1297 $(Q)$(MAKE) $(hdr-inst)=include/uapi
1298 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
1306 $(Q)$(MAKE) $(build)=scripts scripts/unifdef
1308 # ---------------------------------------------------------------------------
1313 # to this Makefile to build and install external modules.
1319 # ---------------------------------------------------------------------------
1323 vdso_install: export INSTALL_FILES = $(vdso-install-y)
1325 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
1327 # ---------------------------------------------------------------------------
1328 # Tools
1331 prepare: tools/objtool
1336 prepare: tools/bpf/resolve_btfids
1342 resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
1344 # tools/bpf/resolve_btfids directory might not exist
1348 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1356 tools/: FORCE
1357 $(Q)mkdir -p $(objtree)/tools
1358 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1360 tools/%: FORCE
1361 $(Q)mkdir -p $(objtree)/tools
1362 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1364 # ---------------------------------------------------------------------------
1369 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1371 kselftest-%: headers FORCE
1372 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
1374 PHONY += kselftest-merge
1375 kselftest-merge:
1377 $(Q)find $(srctree)/tools/testing/selftests -name config | \
1378 xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config
1379 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1381 # ---------------------------------------------------------------------------
1391 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1394 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1398 $(Q)$(MAKE) $(build)=$(dtstree)
1426 $(Q)$(MAKE) $(build)=scripts/dtc
1434 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1438 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@
1440 # ---------------------------------------------------------------------------
1445 # By default, build modules as well
1450 # the built-in objects during the descend as well, in order to
1456 # Build modules
1470 $(Q)$(MAKE) $(build)=scripts scripts/module.lds
1477 # Leave enough to build external modules
1478 # make mrproper Delete the current configuration, and all generated files
1479 # make distclean Remove editor backup files, patch leftover files and the like
1482 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
1485 rust-project.json .vmlinux.objs .vmlinux.export.c
1490 debian snap tar-install \
1495 vmlinux-gdb.py \
1499 # clean - Delete most, but leave enough to build external modules
1501 clean: rm-files := $(CLEAN_FILES)
1506 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1507 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
1511 # mrproper - Delete all generated files, including .config
1513 mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
1514 mrproper-dirs := $(addprefix _mrproper_,scripts)
1516 PHONY += $(mrproper-dirs) mrproper
1517 $(mrproper-dirs):
1520 mrproper: clean $(mrproper-dirs)
1523 \( -name '*.rmeta' \) \
1524 -type f -print | xargs rm -f
1532 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1533 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1534 -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
1535 -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
1536 -type f -print | xargs rm -f
1540 # ---------------------------------------------------------------------------
1542 %src-pkg: FORCE
1543 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1545 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1548 # ---------------------------------------------------------------------------
1552 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1553 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1558 @echo ' clean - Remove most generated files but keep the config and'
1559 @echo ' enough build support to build external modules'
1560 @echo ' mrproper - Remove all generated files + config + various backup files'
1561 @echo ' distclean - mrproper + remove editor backup and patch files'
1563 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1566 @echo ' all - Build all targets marked with [*]'
1567 @echo '* vmlinux - Build the bare kernel'
1568 @echo '* modules - Build all modules'
1569 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1570 @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
1571 @echo ' dir/ - Build all files in dir and below'
1572 @echo ' dir/file.[ois] - Build specified target only'
1573 @echo ' dir/file.ll - Build the LLVM assembly file'
1575 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1576 @echo ' (requires a recent binutils and recent build (System.map))'
1577 @echo ' dir/file.ko - Build module including final link'
1578 @echo ' modules_prepare - Set up for building external modules'
1579 @echo ' tags/TAGS - Generate tags file for editors'
1580 @echo ' cscope - Generate cscope index'
1581 @echo ' gtags - Generate GNU GLOBAL index'
1582 @echo ' kernelrelease - Output the release version string (use with make -s)'
1583 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1584 @echo ' image_name - Output the image name (use with make -s)'
1585 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1589 @echo ' checkstack - Generate a list of stack hogs'
1590 @echo ' versioncheck - Sanity check on version.h usage'
1591 @echo ' includecheck - Check for duplicate included header files'
1592 @echo ' export_report - List the usages of all exported symbols'
1593 @echo ' headerdep - Detect inclusion cycles in headers'
1594 @echo ' coccicheck - Check with Coccinelle'
1595 @echo ' clang-analyzer - Check with clang static analyzer'
1596 @echo ' clang-tidy - Check with clang-tidy'
1598 @echo 'Tools:'
1599 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1602 @echo ' kselftest - Build and run kernel selftest'
1603 @echo ' Build, install, and boot kernel before'
1606 @echo ' kselftest-all - Build kernel selftest'
1607 @echo ' kselftest-install - Build and install kernel selftest'
1608 @echo ' kselftest-clean - Remove all generated kselftest files'
1609 @echo ' kselftest-merge - Merge all the config dependencies of'
1613 @echo ' rustavailable - Checks whether the Rust toolchain is'
1614 @echo ' available and, if not, explains why.'
1615 @echo ' rustfmt - Reformat all the Rust code in the kernel'
1616 @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
1618 @echo ' rustdoc - Generate Rust documentation'
1620 @echo ' rusttest - Runs the Rust tests'
1622 @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
1624 @echo ' dir/file.[os] - Build specified target only'
1625 @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1628 @echo ' dir/file.ll - Build the LLVM assembly file'
1632 echo '* dtbs - Build device tree blobs for enabled boards'; \
1633 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1634 echo ' dt_binding_check - Validate device tree binding documents'; \
1635 echo ' dtbs_check - Validate device tree source files';\
1638 @echo 'Userspace tools targets:'
1639 @echo ' use "make tools/help"'
1640 @echo ' or "cd tools; make help"'
1643 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
1646 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1654 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1656 @$(if $(board-dirs), \
1657 $(foreach b, $(board-dirs), \
1658 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1659 printf " %-16s - Show all of the above\\n" help-boards; \
1662 @echo ' make V=n [targets] 1: verbose build'
1664 @echo ' V=1 and V=2 can be combined with V=12'
1666 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
1670 @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where'
1671 @echo ' 1: warnings which may be relevant and do not occur too often'
1678 echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \
1681 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1685 help-board-dirs := $(addprefix help-,$(board-dirs))
1687 help-boards: $(help-board-dirs)
1689 boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
1691 $(help-board-dirs): help-%:
1693 @$(if $(boards-per-dir), \
1694 $(foreach b, $(boards-per-dir), \
1695 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1700 # ---------------------------------------------------------------------------
1705 $(Q)$(MAKE) $(build)=Documentation $@
1709 # ---------------------------------------------------------------------------
1718 # Using the singular to avoid running afoul of `no-dot-config-targets`.
1721 $(Q)$(MAKE) $(build)=rust $@
1726 $(Q)$(MAKE) $(build)=rust $@
1737 $(Q)find $(abs_srctree) -type f -name '*.rs' \
1738 -o -path $(abs_srctree)/rust/alloc -prune \
1739 -o -path $(abs_objtree)/rust/test -prune \
1740 | grep -Fv $(abs_srctree)/rust/alloc \
1741 | grep -Fv $(abs_objtree)/rust/test \
1742 | grep -Fv generated \
1745 rustfmtcheck: rustfmt_flags = --check
1749 # ---------------------------------------------------------------------------
1751 PHONY += misc-check
1752 misc-check:
1753 $(Q)$(srctree)/scripts/misc-check
1755 all: misc-check
1759 $(Q)$(MAKE) $(build)=scripts/gdb
1760 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1773 # read-only, and no consistency checks are made and the make
1781 build-dir := $(KBUILD_EXTMOD)
1786 clean-dirs := $(KBUILD_EXTMOD)
1787 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
1795 echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
1803 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1805 @echo ' modules - default target, build the module(s)'
1806 @echo ' modules_install - install the module'
1807 @echo ' clean - remove generated files in module directory only'
1808 @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
1816 @echo >&2 '*** You cannot build or install external modules.'
1823 # ---------------------------------------------------------------------------
1829 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
1830 sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
1847 $(MODORDER): $(build-dir)
1854 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1859 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
1871 modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
1873 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1876 # ---------------------------------------------------------------------------
1877 # To build individual files in subdirectories, you can do like this:
1881 # The supported suffixes for single-target are listed in 'single-targets'
1883 # To build only under specific subdirectories, you can do like this:
1887 ifdef single-build
1890 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
1891 single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
1892 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
1894 $(single-ko): single_modules
1896 $(single-no-ko): $(build-dir)
1901 single_modules: $(single-no-ko) modules_prepare
1902 $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER)
1903 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1905 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1907 $(Q)rm -f $(MODORDER)
1909 single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
1915 # Preset locale variables to speed up the build process. Limit locale
1919 PHONY += $(build-dir)
1920 $(build-dir): prepare
1921 $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
1923 clean-dirs := $(addprefix _clean_, $(clean-dirs))
1924 PHONY += $(clean-dirs) clean
1925 $(clean-dirs):
1928 clean: $(clean-dirs)
1931 \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
1932 -o -name '*.ko.*' \
1933 -o -name '*.dtb' -o -name '*.dtbo' \
1934 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
1935 -o -name '*.dt.yaml' \
1936 -o -name '*.dwo' -o -name '*.lst' \
1937 -o -name '*.su' -o -name '*.mod' \
1938 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1939 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
1940 -o -name '*.asn1.[ch]' \
1941 -o -name '*.symtypes' -o -name 'modules.order' \
1942 -o -name '*.c.[012]*.*' \
1943 -o -name '*.ll' \
1944 -o -name '*.gcno' \
1945 -o -name '*.*.symversions' \) -type f -print \
1946 -o -name '.tmp_*' -print \
1947 | xargs rm -rf
1950 # ---------------------------------------------------------------------------
1958 PHONY += rust-analyzer
1959 rust-analyzer:
1960 $(Q)$(MAKE) $(build)=rust $@
1963 # ---------------------------------------------------------------------------
1971 # ---------------------------------------------------------------------------
1974 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
1976 $(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
1983 PHONY += clang-tidy clang-analyzer
1987 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
1989 clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json
1992 clang-tidy clang-analyzer:
1998 # ---------------------------------------------------------------------------
2004 -name '*.[hcS]' -type f -print | sort \
2005 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
2009 -name '*.[hcS]' -type f -print | sort \
2010 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
2022 # else wants $(ARCH), including people doing cross-builds, which means
2030 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
2042 PHONY += run-command
2043 run-command:
2046 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
2047 cmd_rmfiles = rm -rf $(rm-files)
2050 existing-targets := $(wildcard $(sort $(targets)))
2052 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
2054 endif # config-build
2055 endif # mixed-build
2056 endif # need-sub-make
2062 # information in a variable so we can use it in if_changed and friends.