From patchwork Sun Nov 10 01:34:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869745 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63540145B39; Sun, 10 Nov 2024 01:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202619; cv=none; b=iwPB7SkVD2klwbk6lTzwTdJBy79y+sRpg4d52EXHfYrZDxix21yQJrG3TWE5b5T38OiFcmJOv0Z6hyyTt2b/5ksfr6+r7odMvwCEbSZo/pG8YnhAP+I4DWtaRv7zMY6PAmbvqpad1ZCLxo5DQE3O4f+pp73R6sXGO3LTxTtYPn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202619; c=relaxed/simple; bh=CuefUAuu2ymiIcWDp7fjjKsIw2/LHtdF4FuH73CuyK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZkVbMED3lKs90r8vV05Y9RJvtqXsTJ0gaAPjpsoEuwH8riy+oi8VuFrcgP0B756XJIgozoxYE5S/IDVviPee+PaMJCQHono1bo9Xye0IoiOj/+EJPnz7aKu0on4iOTvSnisVH0RxnSjyDGkCMlHsijUUfWgBRL7lI8ECoIMS2y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i7gQgzTR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i7gQgzTR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3A9CC4CED4; Sun, 10 Nov 2024 01:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202619; bh=CuefUAuu2ymiIcWDp7fjjKsIw2/LHtdF4FuH73CuyK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i7gQgzTRVWoE3MSGJo91WHpUNSu3jtq16SwETWmoDxFzWgfy+IA/6eqHr0gmxctPD Ezay9mIHwLgrsAcz3ji5zL6xLNl5C8bMWaBByQn6TrXO6X0voGE9Ab1c4GABhbVT3C GnuhVYXofepqdtV0hrIZtiHJ5xQdzTCSCzKNyrgWaKIsoHRBShdA5CAcWftM24CTHN i7RtSxOMkUTCKCsAo3jd2bd5NPcXMbYDEYOHj6oOJ5JKxFWfaVtExBVUdYMA3sFy+O nuZRaX78Gidhg1Q1KSCPrp9M51rI5LAgKJy07TVClwSqjNoK7Fd46dpsU5YsBbc4W2 cVU0U0X79lgJA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 01/11] kbuild: replace two $(abs_objtree) with $(CURDIR) in top Makefile Date: Sun, 10 Nov 2024 10:34:29 +0900 Message-ID: <20241110013649.34903-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Kbuild changes the working directory until it matches $(abs_objtree). When $(need-sub-make) is empty, $(abs_objtree) is the same as $(CURDIR). Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- (no changes since v1) Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8dceb6830486..891d28e54791 100644 --- a/Makefile +++ b/Makefile @@ -228,12 +228,12 @@ else # need-sub-make # We process the rest of the Makefile if this is the final invocation of make -ifeq ($(abs_srctree),$(abs_objtree)) +ifeq ($(abs_srctree),$(CURDIR)) # building in the source tree srctree := . building_out_of_srctree := else - ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) + ifeq ($(abs_srctree)/,$(dir $(CURDIR))) # building in a subdirectory of the source tree srctree := .. else From patchwork Sun Nov 10 01:34:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869746 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B35C1474A4; Sun, 10 Nov 2024 01:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202621; cv=none; b=rd6qhNXUafIcERF0RUNvywHChny9jLnjmRh/sJhPsrC4PpWwLE4oBKUKr2sSjAn7Qk93RCnHMk8XEvokQcVzEVmLeTo+LpougB2mXQTONCcWKDFF7JI/v1W8CVHMVB6KQLKUWxXGbEm8hPxOFPiuT0xj3HVnpGv38ca+3wOKJxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202621; c=relaxed/simple; bh=6i1YYERXoeK4NchDSXf7fBlYYK9mmrlTiZyLP0h7vss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FmPoa18T2Iyla4yj6h9CDtucJFo91+9bWielrK4j4LbAsCk1UgU43Hj8e9mXwo1Uw8REyFgW/faE2C4rcUNxPpXQXFMunMIv3vNF4Mxvpx4pVcqexPiYzuyJ0KvcSbt3TYTU3BYULjLy1QzfDEZc1fuLzOp+UAvZRKSzNcjNz9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iEh8VqkP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iEh8VqkP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1433C4CED4; Sun, 10 Nov 2024 01:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202621; bh=6i1YYERXoeK4NchDSXf7fBlYYK9mmrlTiZyLP0h7vss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iEh8VqkPzPuEgZNPH3JpYX1chq5w5yux7r0655wlb4LVkns8l8XFiXqVR5weZZ1v0 eMPSlFtK3Aq4//BKzP0+CHMzMoQUZLP2N5t2rry5sU237lkRIbIc+WsDDofMaGIYV0 haVd1X1MrizC+md/6FGJTuuwsbD9tx7d0f7pHwnnLbgE1CBQZkARbuvOpwWzg7K9jz QEo1zLsNmSJvg0NsqbMhXOXAy/YThw6WwQ58t/CqE8Y9BhZQri+alX87/9SQxBvsDs eLO0+qEMooWkS3o1ygYLpB0DJ2oJJRs792MCzfby3F/Bj1dFGdo9ahnZlwbBspUkru fGUjf/+t+/bFw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 02/11] kbuild: add $(objtree)/ prefix to some in-kernel build artifacts Date: Sun, 10 Nov 2024 10:34:30 +0900 Message-ID: <20241110013649.34903-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 $(objtree) refers to the top of the output directory of kernel builds. This commit adds the explicit $(objtree)/ prefix to build artifacts needed for building external modules. This change has no immediate impact, as the top-level Makefile currently defines: objtree := . This commit prepares for supporting the building of external modules in a different directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Add more $(objtree)/ to arch/*/Makefile Makefile | 10 +++++----- arch/arm/Makefile | 4 ++-- arch/arm64/Makefile | 2 +- arch/powerpc/Makefile | 4 ++-- arch/riscv/Makefile | 2 +- scripts/Kbuild.include | 2 +- scripts/Makefile.build | 4 ++-- scripts/Makefile.modfinal | 14 +++++++------- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 12 ++++++------ scripts/depmod.sh | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 891d28e54791..9b8f4f4cb01b 100644 --- a/Makefile +++ b/Makefile @@ -354,7 +354,7 @@ else # !mixed-build include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE = $(call read-file, include/config/kernel.release) +KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION @@ -720,7 +720,7 @@ endif export KBUILD_MODULES KBUILD_BUILTIN ifdef need-config -include include/config/auto.conf +include $(objtree)/include/config/auto.conf endif ifeq ($(KBUILD_EXTMOD),) @@ -783,13 +783,13 @@ else # !may-sync-config # and include/config/auto.conf but do not care if they are up-to-date. # Use auto.conf to show the error message -checked-configs := include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf +checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf) missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs)) ifdef missing-configs -PHONY += include/config/auto.conf +PHONY += $(objtree)/include/config/auto.conf -include/config/auto.conf: +$(objtree)/include/config/auto.conf: @echo >&2 '***' @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:' @printf >&2 '*** - %s\n' $(missing-configs) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index aafebf145738..00ca7886b18e 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -264,13 +264,13 @@ stack_protector_prepare: prepare0 -mstack-protector-guard=tls \ -mstack-protector-guard-offset=$(shell \ awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) else stack_protector_prepare: prepare0 $(eval SSP_PLUGIN_CFLAGS := \ -fplugin-arg-arm_ssp_per_task_plugin-offset=$(shell \ awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}'\ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) $(eval KBUILD_CFLAGS += $(SSP_PLUGIN_CFLAGS)) $(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS)) endif diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 9efd3f37c2fd..358c68565bfd 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -71,7 +71,7 @@ stack_protector_prepare: prepare0 -mstack-protector-guard-reg=sp_el0 \ -mstack-protector-guard-offset=$(shell \ awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index bbfe4a1f06ef..321b596d2550 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -402,9 +402,9 @@ prepare: stack_protector_prepare PHONY += stack_protector_prepare stack_protector_prepare: prepare0 ifdef CONFIG_PPC64 - $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h)) else - $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' $(objtree)/include/generated/asm-offsets.h)) endif endif diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index d469db9f46f4..a08cfeb6cbf9 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -129,7 +129,7 @@ stack_protector_prepare: prepare0 -mstack-protector-guard-reg=tp \ -mstack-protector-guard-offset=$(shell \ awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif # arch specific predefines for sparse diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index ed8a7493524b..8c311b997e24 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -205,7 +205,7 @@ if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:) cmd_and_fixdep = \ $(cmd); \ - scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ rm -f $(depfile) # Usage: $(call if_changed_rule,foo) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 8f423a1faf50..64cd046f8fd8 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -34,7 +34,7 @@ subdir-asflags-y := subdir-ccflags-y := # Read auto.conf if it exists, otherwise ignore --include include/config/auto.conf +-include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.compiler @@ -107,7 +107,7 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) -genksyms = scripts/genksyms/genksyms \ +genksyms = $(objtree)/scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 1482884ec3ca..6d8aa3059ee2 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -6,7 +6,7 @@ PHONY := __modfinal __modfinal: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include # for c_flags @@ -37,15 +37,15 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^) quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \ - if [ ! -f vmlinux ]; then \ + if [ ! -f $(objtree)/vmlinux ]; then \ printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ else \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@; \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux $@; \ + $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ fi; # Same as newer-prereqs, but allows to exclude specified extra dependencies @@ -57,8 +57,8 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE - +$(call if_changed_except,ld_ko_o,vmlinux) +%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE + +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index d97720943189..6fa9af4a25b4 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,7 +6,7 @@ PHONY := __modinst __modinst: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include install-y := diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 44936ebad161..12e7c15d099c 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -35,10 +35,10 @@ PHONY := __modpost __modpost: -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include -MODPOST = scripts/mod/modpost +MODPOST = $(objtree)/scripts/mod/modpost modpost-args = \ $(if $(CONFIG_MODULES),-M) \ @@ -119,11 +119,11 @@ include $(kbuild-file) output-symdump := $(KBUILD_EXTMOD)/Module.symvers -ifeq ($(wildcard Module.symvers),) -missing-input := Module.symvers +ifeq ($(wildcard $(objtree)/Module.symvers),) +missing-input := $(objtree)/Module.symvers else -modpost-args += -i Module.symvers -modpost-deps += Module.symvers +modpost-args += -i $(objtree)/Module.symvers +modpost-deps += $(objtree)/Module.symvers endif modpost-args += -e $(addprefix -i , $(KBUILD_EXTRA_SYMBOLS)) diff --git a/scripts/depmod.sh b/scripts/depmod.sh index e22da27fe13e..3c34fecacbc8 100755 --- a/scripts/depmod.sh +++ b/scripts/depmod.sh @@ -12,7 +12,7 @@ KERNELRELEASE=$1 : ${DEPMOD:=depmod} -if ! test -r System.map ; then +if ! test -r "${objtree}/System.map" ; then echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2 exit 0 fi @@ -25,7 +25,7 @@ if [ -z $(command -v $DEPMOD) ]; then exit 0 fi -set -- -ae -F System.map +set -- -ae -F "${objtree}/System.map" if test -n "$INSTALL_MOD_PATH"; then set -- "$@" -b "$INSTALL_MOD_PATH" fi From patchwork Sun Nov 10 01:34:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869747 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31259145B39; Sun, 10 Nov 2024 01:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202623; cv=none; b=L5OljHYeTUNTuzgpkdkcC7IsDDV6ZCfA2jF6CIDNf2vB4FSZRav1hSvLBtPn7nWPGtDM9DLx9SyLC6Et+cepU0A+pwA4LMK1ImpFbgcbJoCm/Opfv9vAtG/gT8GDxsPyJh+Y8zWM8JuIsMY4cJUt+YTTL9epZnjJKgPUSX1y/7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202623; c=relaxed/simple; bh=iCeqjzcVDDdoLZ9nZgMa6Iw5IDXnP0Lvgh2TSIu2WD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oarAkmiil9BiOnRjtqb6Ck602abssu+KjD4TiPLLlRcTf4+Zq8/MXOmryMUQwB+XcQ5ipqAXP2g0fRtaRw1QmLYQkJQ3BGwMn5il6sDwxLJCZAtkzsEBMqbt/dIRXw9VLDMhSNTirdd57S4qrEnkFUkFqjoiOw7mVNK3V57KgGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eIrvovJJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eIrvovJJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98BAEC4CED2; Sun, 10 Nov 2024 01:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202622; bh=iCeqjzcVDDdoLZ9nZgMa6Iw5IDXnP0Lvgh2TSIu2WD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eIrvovJJ4eitOtZYlTjmKrd3/mINe+aHZaNaC9amwYwqn34fP4V9WsiBWhQytQCvd TejFnusbblJS3ES9FDUk53jndG/8Ucdsh7GMP845PWwdG5THIUCEtUq58mlm62rn6q Jksnm9XLgD0YyumgHtsq6+GHVUewVZVdulDOYNdBu7KfDevReKG7phUrBV04GG6WVh qgntF0qk3pIQWr3E42vbYW4zXINh5jPdm9ltGHlcOdERvPEgfl9ELlayNmKZIC+YqE csxr8hP420L+ElVWAKB0LlszcJ1Bhqfp1NmLwVfkawD8BHYO0cWPnSKNI/htgYVp4O U4E1hut/47g1Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 03/11] kbuild: rename abs_objtree to abs_output Date: Sun, 10 Nov 2024 10:34:31 +0900 Message-ID: <20241110013649.34903-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 'objtree' refers to the top of the output directory of kernel builds. Rename abs_objtree to a more generic name, to better reflect its use in the context of external module builds. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- (no changes since v1) Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9b8f4f4cb01b..deb3f01863f8 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ __all: this-makefile := $(lastword $(MAKEFILE_LIST)) abs_srctree := $(realpath $(dir $(this-makefile))) -abs_objtree := $(CURDIR) +abs_output := $(CURDIR) ifneq ($(sub_make_done),1) @@ -185,8 +185,8 @@ ifneq ($(KBUILD_OUTPUT),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. $(shell mkdir -p "$(KBUILD_OUTPUT)") # $(realpath ...) resolves symlinks -abs_objtree := $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) +abs_output := $(realpath $(KBUILD_OUTPUT)) +$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) endif # ifneq ($(KBUILD_OUTPUT),) ifneq ($(words $(subst :, ,$(abs_srctree))), 1) @@ -197,7 +197,7 @@ export sub_make_done := 1 endif # sub_make_done -ifeq ($(abs_objtree),$(CURDIR)) +ifeq ($(abs_output),$(CURDIR)) # Suppress "Entering directory ..." if we are at the final work directory. no-print-directory := --no-print-directory else @@ -221,7 +221,7 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make # Invoke a second make in the output directory, passing relevant variables __sub-make: - $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \ + $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \ -f $(abs_srctree)/Makefile $(MAKECMDGOALS) else # need-sub-make From patchwork Sun Nov 10 01:34:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869748 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52796145A03; Sun, 10 Nov 2024 01:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202625; cv=none; b=khUQovASV1jneTmcyxfmzqjWJzomgiKos7374wxavS8L7vw4Q4XQCz3ynVKg6HBSQW6toVn1KeE1h1594gtcoTzlKuRiK8sAOTH6Vng/6cyl1Zq59PzNMInzIN6VNEJhFPfq/4WQNAq1DrU3b0TAVU1i0oNRk8Se67YDdn3T5/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202625; c=relaxed/simple; bh=4+lPEWVcZF6MP4lqk4tN8WFRUEgGMvVQurcrEWRHgtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDrkGszD/Flfgxco5H1Il7z/T06ZHogyUeNQdyX3SLKqK/NB+myDsJ29TapstaIanewbsA/LGj6KN12l90TtOg/RSi+sSwKh4yfb1PyJp0IF9BGf5Bu+IRXCafyao77ZQeQWh71yPYcE4yrN31wJf9176CK9tY9//hGAKPxtlJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MvF7QobB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MvF7QobB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51B35C4CECE; Sun, 10 Nov 2024 01:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202624; bh=4+lPEWVcZF6MP4lqk4tN8WFRUEgGMvVQurcrEWRHgtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MvF7QobBQqDTettWvOayNRcLsy9jjZBQiENvg66pi2Oxfa8Y9pHRF3u1DNVz9dLPp KQm4EZ8ON3K1KsirtFtw0HXcGxBY92FIieCYsMF+7f3MKVxGW7IU8cN9tqVnm9JOud Dv5fFMwhNT7s/iuHMzboXeNcR3/aG5hLBlcON2JBuIhfQYsqnyWxJxOdNrRLQi8MQx NPndGurbb44z6An+viiTYhNMGSPAlt9CfEujkpeC5Q21vD1B2hi65DXI1V5X7SYX79 J/LBuOCLX3R0/VNjAdNCIAkIJKRA5e4lUWL/LVs+2d/4JT1ycqkOVdVxgefoNW7XWb VM4OU/SHm7yUQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 04/11] kbuild: use 'output' variable to create the output directory Date: Sun, 10 Nov 2024 10:34:32 +0900 Message-ID: <20241110013649.34903-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 $(KBUILD_OUTPUT) specifies the output directory of kernel builds. Use a more generic name, 'output', to better reflect this code hunk in the context of external module builds. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- (no changes since v1) Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index deb3f01863f8..cf1d55560ae2 100644 --- a/Makefile +++ b/Makefile @@ -176,18 +176,20 @@ export KBUILD_EXTRA_WARN # The O= assignment takes precedence over the KBUILD_OUTPUT environment # variable. -# Do we want to change the working directory? ifeq ("$(origin O)", "command line") KBUILD_OUTPUT := $(O) endif -ifneq ($(KBUILD_OUTPUT),) +output := $(KBUILD_OUTPUT) + +# Do we want to change the working directory? +ifneq ($(output),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. -$(shell mkdir -p "$(KBUILD_OUTPUT)") +$(shell mkdir -p "$(output)") # $(realpath ...) resolves symlinks -abs_output := $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OUTPUT)")) -endif # ifneq ($(KBUILD_OUTPUT),) +abs_output := $(realpath $(output)) +$(if $(abs_output),,$(error failed to create output directory "$(output)")) +endif ifneq ($(words $(subst :, ,$(abs_srctree))), 1) $(error source directory cannot contain spaces or colons) From patchwork Sun Nov 10 01:34:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869749 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B60414A629; Sun, 10 Nov 2024 01:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202626; cv=none; b=Ly+RAtyi60hCIlJQoI1tiUOMpWc+/OkBTUCXHHrHkowp+VvR5RqRdl//m7hTuN3PjC1x2e9r/iM19nIgZEB5WFHPg1t9LBPSQrZxow5rmXye5h6ZU26Ec992pf90bdo2N3bndbob94UimnK9DYtHcJrshHwBW/eWRGxazFX6RGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202626; c=relaxed/simple; bh=6/uwZZEPyIGrWrIPgIcKHUZ4oPZIubvfn8y9Jxnpm00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzLWtoQKuee2tOhna5GPfekx8oMAI+ii4eY4SY161w8LzRcGP3DX1BfOrhvVEKUJBph40y068AxHdoZhWKxRwNpokPVMwD8aWCzrLu4S6nf+iJ6YDiePIKZpFW8MhNo8SF+Njvjck94UJKsDlBRvpRedRC6MNTyGkBTuaPIZ7bs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s2NB969z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s2NB969z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5302DC4CED4; Sun, 10 Nov 2024 01:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202626; bh=6/uwZZEPyIGrWrIPgIcKHUZ4oPZIubvfn8y9Jxnpm00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s2NB969zGfvxq3QMT+mtUPx9bmm2IGUiP6zlHtuGLob1Dc1ZLrLRY+kIftyUqQNXY OeltES4Y7rmNNY8rtz8Y81LRsAtbEneYCyASyZXm9Nk4I+CsqdayNMTz3WFpkiEguE iYgHt2bqNgaZez+SeXEfEntcVJZveslun1T+bnkyLbDvasAsdHY1hHZBug5H/4GPyl wHwhfs8ThbxlwaWnh5ruBAtp9LHpuLP/8qbaZZZ92Py3FfGQhNOtjUdN/az/qlT9Bs l9ksghibiSjNDm0ILIr6SMWtzMwXxuoLco06kIvYa7vpdhGHBaZvE1i8fXL2zQymLT +VhUnauS8suvA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada Subject: [PATCH v2 05/11] kbuild: change working directory to external module directory with M= Date: Sun, 10 Nov 2024 10:34:33 +0900 Message-ID: <20241110013649.34903-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, Kbuild always operates in the output directory of the kernel, even when building external modules. This increases the risk of external module Makefiles attempting to write to the kernel directory. This commit switches the working directory to the external module directory, allowing the removal of the $(KBUILD_EXTMOD)/ prefix from some build artifacts. The command for building external modules maintains backward compatibility, but Makefiles that rely on working in the kernel directory may break. In such cases, $(objtree) and $(srctree) should be used to refer to the output and source directories of the kernel. The appearance of the build log will change as follows: [Before] $ make -C /path/to/my/linux M=/path/to/my/externel/module make: Entering directory '/path/to/my/linux' CC [M] /path/to/my/externel/module/helloworld.o MODPOST /path/to/my/externel/module/Module.symvers CC [M] /path/to/my/externel/module/helloworld.mod.o CC [M] /path/to/my/externel/module/.module-common.o LD [M] /path/to/my/externel/module/helloworld.ko make: Leaving directory '/path/to/my/linux' [After] $ make -C /path/to/my/linux M=/path/to/my/externel/module make: Entering directory '/path/to/my/linux' make[1]: Entering directory '/path/to/my/externel/module' CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko make[1]: Leaving directory '/path/to/my/externel/module' make: Leaving directory '/path/to/my/linux' Printing "Entering directory" twice is cumbersome. This will be addressed later. Signed-off-by: Masahiro Yamada --- Changes in v2: - Introduce a new 'srcroot' variable and clean-up code - Reword Documentation/dev-tools/coccinelle.rst Documentation/dev-tools/coccinelle.rst | 20 ++----- Documentation/kbuild/makefiles.rst | 14 +++++ Makefile | 80 +++++++++++++++----------- rust/Makefile | 4 +- scripts/Makefile.build | 2 +- scripts/Makefile.clean | 2 +- scripts/Makefile.compiler | 2 +- scripts/Makefile.modpost | 6 +- scripts/coccicheck | 6 +- scripts/nsdeps | 8 +-- scripts/package/install-extmod-build | 7 +++ 11 files changed, 85 insertions(+), 66 deletions(-) diff --git a/Documentation/dev-tools/coccinelle.rst b/Documentation/dev-tools/coccinelle.rst index 535ce126fb4f..6e70a1e9a3c0 100644 --- a/Documentation/dev-tools/coccinelle.rst +++ b/Documentation/dev-tools/coccinelle.rst @@ -250,25 +250,17 @@ variables for .cocciconfig is as follows: - Your directory from which spatch is called is processed next - The directory provided with the ``--dir`` option is processed last, if used -Since coccicheck runs through make, it naturally runs from the kernel -proper dir; as such the second rule above would be implied for picking up a -.cocciconfig when using ``make coccicheck``. - ``make coccicheck`` also supports using M= targets. If you do not supply any M= target, it is assumed you want to target the entire kernel. The kernel coccicheck script has:: - if [ "$KBUILD_EXTMOD" = "" ] ; then - OPTIONS="--dir $srctree $COCCIINCLUDE" - else - OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" - fi + OPTIONS="--dir $srcroot $COCCIINCLUDE" -KBUILD_EXTMOD is set when an explicit target with M= is used. For both cases -the spatch ``--dir`` argument is used, as such third rule applies when whether -M= is used or not, and when M= is used the target directory can have its own -.cocciconfig file. When M= is not passed as an argument to coccicheck the -target directory is the same as the directory from where spatch was called. +Here, $srcroot refers to the source directory of the target: it points to the +external module's source directory when M= used, and otherwise, to the kernel +source directory. The third rule ensures the spatch reads the .cocciconfig from +the target directory, allowing external modules to have their own .cocciconfig +file. If not using the kernel's coccicheck target, keep the above precedence order logic of .cocciconfig reading. If using the kernel's coccicheck target, diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 7964e0c245ae..d36519f194dc 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -449,6 +449,20 @@ $(obj) to prerequisites are referenced with $(src) (because they are not generated files). +$(srcroot) + $(srcroot) refers to the root of the source you are building, which can be + either the kernel source or the external modules source, depending on whether + KBUILD_EXTMOD is set. This can be either a relative or an absolute path, but + if KBUILD_ABS_SRCTREE=1 is set, it is always an absolute path. + +$(srctree) + $(srctree) refers to the root of the kernel source tree. When building the + kernel, this is the same as $(srcroot). + +$(objtree) + $(objtree) refers to the root of the kernel object tree. It is ``.`` when + building the kernel, but it is different when building external modules. + $(kecho) echoing information to user in a rule is often a good practice but when execution ``make -s`` one does not expect to see any output diff --git a/Makefile b/Makefile index cf1d55560ae2..e5f7ac7647a7 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,24 @@ ifeq ("$(origin O)", "command line") KBUILD_OUTPUT := $(O) endif -output := $(KBUILD_OUTPUT) +ifdef KBUILD_EXTMOD + ifdef KBUILD_OUTPUT + objtree := $(realpath $(KBUILD_OUTPUT)) + $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) + else + objtree := $(CURDIR) + endif + output := $(KBUILD_EXTMOD) + # KBUILD_EXTMOD might be a relative path. Remember its absolute path before + # Make changes the working directory. + srcroot := $(realpath $(KBUILD_EXTMOD)) + $(if $(srcroot),,$(error specified external module directory "$(KBUILD_EXTMOD)" does not exist)) +else + objtree := . + output := $(KBUILD_OUTPUT) +endif + +export objtree srcroot # Do we want to change the working directory? ifneq ($(output),) @@ -230,35 +247,33 @@ else # need-sub-make # We process the rest of the Makefile if this is the final invocation of make -ifeq ($(abs_srctree),$(CURDIR)) - # building in the source tree - srctree := . - building_out_of_srctree := +ifndef KBUILD_EXTMOD +srcroot := $(abs_srctree) +endif + +ifeq ($(srcroot),$(CURDIR)) +building_out_of_srctree := else - ifeq ($(abs_srctree)/,$(dir $(CURDIR))) - # building in a subdirectory of the source tree - srctree := .. - else - srctree := $(abs_srctree) - endif - building_out_of_srctree := 1 +export building_out_of_srctree :=1 endif -ifneq ($(KBUILD_ABS_SRCTREE),) -srctree := $(abs_srctree) +ifdef KBUILD_ABS_SRCTREE + # Do not nothing. Use the absolute path. +else ifeq ($(srcroot),$(CURDIR)) + # Building in the source. + srcroot := . +else ifeq ($(srcroot)/,$(dir $(CURDIR))) + # Building in a subdirectory of the source. + srcroot := .. endif -objtree := . +export srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot)) -VPATH := - -ifeq ($(KBUILD_EXTMOD),) ifdef building_out_of_srctree -VPATH := $(srctree) +export VPATH := $(srcroot) +else +VPATH := endif -endif - -export building_out_of_srctree srctree objtree VPATH # To make sure we do not include .config for any of the *config targets # catch them early, and hand them over to scripts/kconfig/Makefile @@ -711,7 +726,7 @@ endif # in addition to whatever we do anyway. # Just "make" or "make all" shall build modules as well -ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),) +ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),) KBUILD_MODULES := 1 endif @@ -1107,7 +1122,7 @@ export MODLIB PHONY += prepare0 -export extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) +export extmod_prefix = export MODORDER := $(extmod_prefix)modules.order export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps @@ -1799,14 +1814,10 @@ filechk_kernel.release = echo $(KERNELRELEASE) KBUILD_BUILTIN := KBUILD_MODULES := 1 -build-dir := $(KBUILD_EXTMOD) +build-dir := . -compile_commands.json: $(extmod_prefix)compile_commands.json -PHONY += compile_commands.json - -clean-dirs := $(KBUILD_EXTMOD) -clean: private rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \ - $(KBUILD_EXTMOD)/compile_commands.json +clean-dirs := . +clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json PHONY += prepare # now expand this into a simple variable to reduce the cost of shell evaluations @@ -1948,7 +1959,7 @@ $(clean-dirs): clean: $(clean-dirs) $(call cmd,rmfiles) - @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ + @find . $(RCS_FIND_IGNORE) \ \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '*.ko.*' \ -o -name '*.dtb' -o -name '*.dtbo' \ @@ -1981,7 +1992,12 @@ tags TAGS cscope gtags: FORCE PHONY += rust-analyzer rust-analyzer: +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh +ifdef KBUILD_EXTMOD +# FIXME: external modules must not descend into a sub-directory of the kernel + $(Q)$(MAKE) $(build)=$(objtree)/rust src=$(srctree)/rust $@ +else $(Q)$(MAKE) $(build)=rust $@ +endif # Script to generate missing namespace dependencies # --------------------------------------------------------------------------- diff --git a/rust/Makefile b/rust/Makefile index b5e0a73b78f3..742740816c4b 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -362,8 +362,8 @@ rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ $(realpath $(srctree)) $(realpath $(objtree)) \ - $(rustc_sysroot) $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ - $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json + $(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \ + > rust-project.json redirect-intrinsics = \ __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \ diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 64cd046f8fd8..1aa928a6fb4f 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -3,7 +3,7 @@ # Building # ========================================================================== -src := $(if $(VPATH),$(VPATH)/)$(obj) +src := $(srcroot)/$(obj) PHONY := $(obj)/ $(obj)/: diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean index 4fcfab40ed61..6ead00ec7313 100644 --- a/scripts/Makefile.clean +++ b/scripts/Makefile.clean @@ -3,7 +3,7 @@ # Cleaning up # ========================================================================== -src := $(if $(VPATH),$(VPATH)/)$(obj) +src := $(srcroot)/$(obj) PHONY := __clean __clean: diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index e0842496d26e..8c1029687e2e 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -13,7 +13,7 @@ cc-cross-prefix = $(firstword $(foreach c, $(1), \ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) # output directory for tests below -TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ +TMPOUT = .tmp_$$$$ # try-run # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 12e7c15d099c..78d2ca4f25f5 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -111,13 +111,13 @@ endif else # set src + obj - they may be used in the modules's Makefile -obj := $(KBUILD_EXTMOD) -src := $(if $(VPATH),$(VPATH)/)$(obj) +obj := . +src := $(srcroot) # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS include $(kbuild-file) -output-symdump := $(KBUILD_EXTMOD)/Module.symvers +output-symdump := Module.symvers ifeq ($(wildcard $(objtree)/Module.symvers),) missing-input := $(objtree)/Module.symvers diff --git a/scripts/coccicheck b/scripts/coccicheck index e52cb43fede6..0e6bc5a10320 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -80,11 +80,7 @@ command results in a shift count error.' NPROC=1 else ONLINE=0 - if [ "$KBUILD_EXTMOD" = "" ] ; then - OPTIONS="--dir $srctree $COCCIINCLUDE" - else - OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" - fi + OPTIONS="--dir $srcroot $COCCIINCLUDE" # Use only one thread per core by default if hyperthreading is enabled THREADS_PER_CORE=$(LANG=C lscpu | grep "Thread(s) per core: " | tr -cd "[:digit:]") diff --git a/scripts/nsdeps b/scripts/nsdeps index f1718cc0d700..8ca12e2b5c03 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -19,12 +19,6 @@ if ! { echo "$SPATCH_REQ_VERSION"; echo "$SPATCH_VERSION"; } | sort -CV ; then exit 1 fi -if [ "$KBUILD_EXTMOD" ]; then - src_prefix= -else - src_prefix=$srctree/ -fi - generate_deps_for_ns() { $SPATCH --very-quiet --in-place --sp-file \ $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps -D ns=$1 $2 @@ -34,7 +28,7 @@ generate_deps() { local mod=${1%.ko:} shift local namespaces="$*" - local mod_source_files=$(sed "s|^\(.*\)\.o$|${src_prefix}\1.c|" $mod.mod) + local mod_source_files=$(sed "s|^\(.*\)\.o$|${srcroot}/\1.c|" $mod.mod) for ns in $namespaces; do echo "Adding namespace $ns to module $mod.ko." diff --git a/scripts/package/install-extmod-build b/scripts/package/install-extmod-build index 7ec1f061a519..64d958ee45f3 100755 --- a/scripts/package/install-extmod-build +++ b/scripts/package/install-extmod-build @@ -51,6 +51,13 @@ mkdir -p "${destdir}" if [ "${CC}" != "${HOSTCC}" ]; then echo "Rebuilding host programs with ${CC}..." + # This leverages external module building. + # - Clear sub_make_done to allow the top-level Makefile to redo sub-make. + # - Filter out --no-print-directory to print "Entering directory" logs + # when Make changes the working directory. + unset sub_make_done + MAKEFLAGS=$(echo "${MAKEFLAGS}" | sed s/--no-print-directory//) + cat <<-'EOF' > "${destdir}/Kbuild" subdir-y := scripts EOF From patchwork Sun Nov 10 01:34:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869750 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9D67219FC; Sun, 10 Nov 2024 01:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202629; cv=none; b=LSdUTSxBmPpICa2j80KVvKbI2TU7Ovo8WDKxeLdjMsE7teaF9w1NSRLcq5ToHwmhc5UyhsPzfP+wBhWxy7TdVbyUPfcbYPMsWqQOgWS778cWg/lMznntolMB50AtTh/gVdJCrcaUaKAG9inozkdUyVfXIoWlvQF40haXpk4G0KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202629; c=relaxed/simple; bh=BhVBR2hhzdfNMnrLYX5uGVTvLEYjQ0ro7XBUDNN+P64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hpgkyUTMEEwdawo8YapKIBbPG3mJqjGDFwpedNGiMxjERttVIWQuc1StD4NxN5fQkLJ7lJdm9xvIcOLe6o9ubqPOEKFWO6ZVKGiKiSNfrp7wEOQ1loYc3oFKfs95lw9amCip6G6z1mdNXbE7YrM7ms3hVJsanhLn69ABsKzDnQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uWGrXmo3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uWGrXmo3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13FA1C4CED8; Sun, 10 Nov 2024 01:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202628; bh=BhVBR2hhzdfNMnrLYX5uGVTvLEYjQ0ro7XBUDNN+P64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uWGrXmo3OaqsolvcUncI7F8NnDPtJEviXVOkvhh9spAMVKgwDmrlTx4k67gb1Ona4 LQmgRk3eHiVymIGeYDdXZYuZiUQ4/vfIfAj6DVOBeLe2X2S92I2PWGq+I8DFFWwWo7 EMUCrGtRx6Ad60NUR8xsAsQqSJUVxylGwJ9Y/wytiKfc409BjIiuPEHVgfndW0BAKt ne7TojjqzJgbE6QZAyZwDaNm8YweRLCSuumaxHRtSyi2YM7qpYRO+BHranSKc6F5KE TQpKiSMi+NRiZNn6roJEixDxTODdAfT4dQh0hcWfNJ7kM7A5dLoJsyuw7d2JrKTXNq /IrgL3rrdJtOw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 06/11] kbuild: remove extmod_prefix, MODORDER, MODULES_NSDEPS variables Date: Sun, 10 Nov 2024 10:34:34 +0900 Message-ID: <20241110013649.34903-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the previous changes, $(extmod_prefix), $(MODORDER), and $(MODULES_NSDEPS) are constant. (empty, modules.order, and modules.nsdeps, respectively). Remove these variables and hard-code their values. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - More cleanups Makefile | 22 +++++++++------------- scripts/Makefile.modfinal | 8 ++++---- scripts/Makefile.modinst | 6 +++--- scripts/Makefile.modpost | 6 +++--- scripts/nsdeps | 2 +- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index e5f7ac7647a7..c7eeb10455b6 100644 --- a/Makefile +++ b/Makefile @@ -1122,10 +1122,6 @@ export MODLIB PHONY += prepare0 -export extmod_prefix = -export MODORDER := $(extmod_prefix)modules.order -export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps - ifeq ($(KBUILD_EXTMOD),) build-dir := . @@ -1876,7 +1872,7 @@ endif ifdef CONFIG_MODULES -$(MODORDER): $(build-dir) +modules.order: $(build-dir) @: # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. @@ -1887,7 +1883,7 @@ ifneq ($(KBUILD_MODPOST_NOFINAL),1) endif PHONY += modules_check -modules_check: $(MODORDER) +modules_check: modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< else # CONFIG_MODULES @@ -1928,15 +1924,15 @@ $(single-ko): single_modules $(single-no-ko): $(build-dir) @: -# Remove MODORDER when done because it is not the real one. +# Remove modules.order when done because it is not the real one. PHONY += single_modules single_modules: $(single-no-ko) modules_prepare - $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER) + $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal endif - $(Q)rm -f $(MODORDER) + $(Q)rm -f modules.order single-goals := $(addprefix $(build-dir)/, $(single-no-ko)) @@ -2013,12 +2009,12 @@ nsdeps: modules quiet_cmd_gen_compile_commands = GEN $@ cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) -$(extmod_prefix)compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ +compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \ - $(if $(CONFIG_MODULES), $(MODORDER)) FORCE + $(if $(CONFIG_MODULES), modules.order) FORCE $(call if_changed,gen_compile_commands) -targets += $(extmod_prefix)compile_commands.json +targets += compile_commands.json PHONY += clang-tidy clang-analyzer @@ -2026,7 +2022,7 @@ ifdef CONFIG_CC_IS_CLANG quiet_cmd_clang_tools = CHECK $< cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< -clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json +clang-tidy clang-analyzer: compile_commands.json $(call cmd,clang_tools) else clang-tidy clang-analyzer: diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 6d8aa3059ee2..bab53884f7e3 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order -modules := $(call read-file, $(MODORDER)) +modules := $(call read-file, modules.order) __modfinal: $(modules:%.o=%.ko) @: @@ -30,7 +30,7 @@ quiet_cmd_cc_o_c = CC [M] $@ %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) -$(extmod_prefix).module-common.o: $(srctree)/scripts/module-common.c FORCE +.module-common.o: $(srctree)/scripts/module-common.c FORCE $(call if_changed_dep,cc_o_c) quiet_cmd_ld_ko_o = LD [M] $@ @@ -57,13 +57,13 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE +%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif -targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) $(extmod_prefix).module-common.o +targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) .module-common.o # Add FORCE to the prerequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 6fa9af4a25b4..f97c9926ed31 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -40,7 +40,7 @@ $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin. endif -modules := $(call read-file, $(MODORDER)) +modules := $(call read-file, modules.order) ifeq ($(KBUILD_EXTMOD),) dst := $(MODLIB)/kernel @@ -59,7 +59,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst endif -modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules)) +modules := $(patsubst %.o, $(dst)/%.ko$(suffix-y), $(modules)) install-$(CONFIG_MODULES) += $(modules) __modinst: $(install-y) @@ -119,7 +119,7 @@ endif # Create necessary directories $(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) -$(dst)/%.ko: $(extmod_prefix)%.ko FORCE +$(dst)/%.ko: %.ko FORCE $(call cmd,install) $(call cmd,strip) $(call cmd,sign) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 78d2ca4f25f5..ab0e94ea6249 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -46,7 +46,7 @@ modpost-args = \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_MODPOST_WARN),-w) \ - $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ + $(if $(KBUILD_NSDEPS),-d modules.nsdeps) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \ $(if $(findstring 1, $(KBUILD_EXTRA_WARN)),-W) \ -o $@ @@ -61,8 +61,8 @@ endif # Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". ifdef KBUILD_MODULES -modpost-args += -T $(MODORDER) -modpost-deps += $(MODORDER) +modpost-args += -T modules.order +modpost-deps += modules.order endif ifeq ($(KBUILD_EXTMOD),) diff --git a/scripts/nsdeps b/scripts/nsdeps index 8ca12e2b5c03..bab4ec870e50 100644 --- a/scripts/nsdeps +++ b/scripts/nsdeps @@ -51,4 +51,4 @@ generate_deps() { while read line do generate_deps $line -done < $MODULES_NSDEPS +done < modules.nsdeps From patchwork Sun Nov 10 01:34:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869751 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CCB814E2ED; Sun, 10 Nov 2024 01:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202630; cv=none; b=PavzmLDNQESuGNErUBVw/KmxcbtPNZWe63/6aC9fwWq9D3fIdw+7rRXz8DZ/0/SiLjYfnK/QiF9X25pUzk+iFtq0q5uuk2tkZNQsh4qbZnB02DDVz/AY1TsE9BCcZ1RtEOW3j9ae45gZz/C+Jw0ZBu5zwwr3qNJnwTg0YZSupzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202630; c=relaxed/simple; bh=Wf268ApS1D6QJ4TyEFsF5qod3tLLDRZrfLTApp+4NVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SrwmebUPx+M8jUjAXx00dmSIHX9bTUx35dgT5X+FS6lbD+vHsCOSyF+1d327yNMdDoICof1SG5YhALUAdtHIKrLsvMkTR9g+7pdrbQzPvU4l5qz9U8v3tpmVMntPzzMh9ktiTSVUvrJlXWmZ2VgnUMk1ISuWRxMCQgZfPU4OQqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iGy/5q8R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGy/5q8R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB330C4CED4; Sun, 10 Nov 2024 01:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202630; bh=Wf268ApS1D6QJ4TyEFsF5qod3tLLDRZrfLTApp+4NVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iGy/5q8R96N0gt2yyUnabXRSlHEhCzw6rpmrevpY7csp+2OFpPbxjAV7WNgsIO91K kvgyshHY+E8rhnFv79EaxAn//O5gAsVUJWeEVTo7DfMTV/kG6iAyK6KYZXorXtANJe VFhxXhp6o0MVTo+ZcURcN3ZL6b8GOmVEf0ZkhBNEQqhRlWAGFaHP/gD85i0O1OdC2e BEYemZX0IRp3wvPoJbdoCZ3po8rDbkUe+h+1NakUH3jU99TEGpKHtLuvjdF95SduSB sRIQ3zi+pBO4Ev9264K/LZ8kfA/k94+KPWup79dS4/N7ONDVRA8U6AMwsf+DGTJyXc tIz0w5dT6Q9RA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 07/11] kbuild: support building external modules in a separate build directory Date: Sun, 10 Nov 2024 10:34:35 +0900 Message-ID: <20241110013649.34903-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There has been a long-standing request to support building external modules in a separate build directory. This commit introduces a new environment variable, KBUILD_EXTMOD_OUTPUT, and its shorthand Make variable, MO. A simple usage: $ make -C M= MO= Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Add -I $(src) -I $(obj) for external modules as well - Fix a typo 'Speficies' to 'Specifies'. Documentation/kbuild/kbuild.rst | 8 +++++++- Documentation/kbuild/modules.rst | 8 +++++++- Makefile | 22 +++++++++++++++++++--- scripts/Makefile.host | 8 +++----- scripts/Makefile.lib | 2 -- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst index 1796b3eba37b..17c9f920f03d 100644 --- a/Documentation/kbuild/kbuild.rst +++ b/Documentation/kbuild/kbuild.rst @@ -137,12 +137,18 @@ Specify the output directory when building the kernel. This variable can also be used to point to the kernel output directory when building external modules against a pre-built kernel in a separate build directory. Please note that this does NOT specify the output directory for the -external modules themselves. +external modules themselves. (Use KBUILD_EXTMOD_OUTPUT for that purpose.) The output directory can also be specified using "O=...". Setting "O=..." takes precedence over KBUILD_OUTPUT. +KBUILD_EXTMOD_OUTPUT +-------------------- +Specify the output directory for external modules. + +Setting "MO=..." takes precedence over KBUILD_EXTMOD_OUTPUT. + KBUILD_EXTRA_WARN ----------------- Specify the extra build checks. The same value can be assigned by passing diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index cd5a54d91e6d..a01f3754c7fc 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -66,7 +66,10 @@ Options of the kernel output directory if the kernel was built in a separate build directory.) - make -C $KDIR M=$PWD + You can optionally pass MO= option if you want to build the modules in + a separate directory. + + make -C $KDIR M=$PWD [MO=$BUILD_DIR] -C $KDIR The directory that contains the kernel and relevant build @@ -80,6 +83,9 @@ Options directory where the external module (kbuild file) is located. + MO=$BUILD_DIR + Specifies a separate output directory for the external module. + Targets ------- diff --git a/Makefile b/Makefile index c7eeb10455b6..38ce19747728 100644 --- a/Makefile +++ b/Makefile @@ -134,6 +134,10 @@ ifeq ("$(origin M)", "command line") KBUILD_EXTMOD := $(M) endif +ifeq ("$(origin MO)", "command line") + KBUILD_EXTMOD_OUTPUT := $(MO) +endif + $(if $(word 2, $(KBUILD_EXTMOD)), \ $(error building multiple external modules is not supported)) @@ -187,7 +191,7 @@ ifdef KBUILD_EXTMOD else objtree := $(CURDIR) endif - output := $(KBUILD_EXTMOD) + output := $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) # KBUILD_EXTMOD might be a relative path. Remember its absolute path before # Make changes the working directory. srcroot := $(realpath $(KBUILD_EXTMOD)) @@ -555,7 +559,7 @@ USERINCLUDE := \ LINUXINCLUDE := \ -I$(srctree)/arch/$(SRCARCH)/include \ -I$(objtree)/arch/$(SRCARCH)/include/generated \ - $(if $(building_out_of_srctree),-I$(srctree)/include) \ + -I$(srctree)/include \ -I$(objtree)/include \ $(USERINCLUDE) @@ -645,6 +649,7 @@ quiet_cmd_makefile = GEN Makefile } > Makefile outputmakefile: +ifeq ($(KBUILD_EXTMOD),) @if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ @@ -654,7 +659,16 @@ outputmakefile: echo >&2 "***"; \ false; \ fi - $(Q)ln -fsn $(srctree) source +else + @if [ -f $(srcroot)/modules.order ]; then \ + echo >&2 "***"; \ + echo >&2 "*** The external module source tree is not clean."; \ + echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \ + echo >&2 "***"; \ + false; \ + fi +endif + $(Q)ln -fsn $(srcroot) source $(call cmd,makefile) $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore @@ -1940,6 +1954,8 @@ KBUILD_MODULES := 1 endif +prepare: outputmakefile + # Preset locale variables to speed up the build process. Limit locale # tweaks to this spot to avoid wrong language settings when running # make menuconfig etc. diff --git a/scripts/Makefile.host b/scripts/Makefile.host index e01c13a588dd..c1dedf646a39 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -96,12 +96,10 @@ hostrust_flags = --out-dir $(dir $@) --emit=dep-info=$(depfile) \ $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ $(HOSTRUSTFLAGS_$(target-stem)) -# $(objtree)/$(obj) for including generated headers from checkin source files -ifeq ($(KBUILD_EXTMOD),) +# $(obj) for including generated headers from checkin source files ifdef building_out_of_srctree -hostc_flags += -I $(objtree)/$(obj) -hostcxx_flags += -I $(objtree)/$(obj) -endif +hostc_flags += -I $(obj) +hostcxx_flags += -I $(obj) endif ##### diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index e7859ad90224..5660dfc9ed36 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -213,13 +213,11 @@ endif # $(src) for including checkin headers from generated source files # $(obj) for including generated headers from checkin source files -ifeq ($(KBUILD_EXTMOD),) ifdef building_out_of_srctree _c_flags += $(addprefix -I, $(src) $(obj)) _a_flags += $(addprefix -I, $(src) $(obj)) _cpp_flags += $(addprefix -I, $(src) $(obj)) endif -endif # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules is-kernel-object = $(or $(part-of-builtin),$(part-of-module)) From patchwork Sun Nov 10 01:34:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869752 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D75C3153573; Sun, 10 Nov 2024 01:37:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202631; cv=none; b=IQ2pv1VOil6u+Gp+1YYXasrokP5lvOXGFB/8S434yDEWPvPpaUtIHmv6+xU2RqyixmGSYDDbBRG2n9W0V6Gdz/edSvfEAuQ5hbndW8iHF7UgQZRotZJjE8nm7lY07E9bCr0472lM0v6NhYy9lqtNWlRV29uakgJW2aUqF7q52yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202631; c=relaxed/simple; bh=us5XMqVwdbsYqray5sAUkCpHJq/PzlTni1SE6suosWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qdCxgChqVYUem7cpkQYCKLAhe0oYXLQrDp+/fJK24+FU8bsfzrXNrMdE4ylfpQl91yXPucdLQVSmOqKJ1UUYAWWD5hm0lSq6dYgfHumZt2i8eNQZbUjK2wnIFrzt4AW+jqlTajFoyIa1aJKF7A0bDvmJaYjGZSEdMmFviMjJ5ik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FYpHijwk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FYpHijwk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70568C4CED2; Sun, 10 Nov 2024 01:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202631; bh=us5XMqVwdbsYqray5sAUkCpHJq/PzlTni1SE6suosWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FYpHijwk9mcoVCtK/bAUiFUeeUIfQf92dIktH/Ui4EM0+1FbLTrjZKR8ZDDZWsG8R 3tdxMA9KnbGlYbhUQoCkE3K/POCpboPw+Tsj8vHCI3RcxuB5dR0DL155C80qzwUqFa LflcVEYQv/FONuhc6bx14auG8qGNtGBwrxL5Z73IrBNDp4teVkkwgILQpFk1uqSihY hYnx4j3hz4//F5pxW0welWeNGSBQBr78iNnllRAmzWQQE7qyLqutK/JYjOeXc0u1QJ 6860ZflHe8fte6sr/phGtKskgwCDD3qWGZ4rRIzRALRMWDg9ZDbtMmBIVHbZCVUAL+ k0lEGg/1Euv5g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 08/11] kbuild: support -fmacro-prefix-map for external modules Date: Sun, 10 Nov 2024 10:34:36 +0900 Message-ID: <20241110013649.34903-9-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit makes -fmacro-prefix-map work for external modules built in a separate output directory. It improves the reproducibility of external modules and provides the benefits described in commit a73619a845d5 ("kbuild: use -fmacro-prefix-map to make __FILE__ a relative path"). When building_out_of_srctree is not defined (e.g., when the kernel or external module is built in the source directory), this option is unnecessary. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Check building_out_of_srctree instead of VPATH Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 38ce19747728..5488aa96b46b 100644 --- a/Makefile +++ b/Makefile @@ -1041,8 +1041,10 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -fconserve-stack endif -# change __FILE__ to the relative path from the srctree -KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) +# change __FILE__ to the relative path to the source directory +ifdef building_out_of_srctree +KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srcroot)/=) +endif # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn From patchwork Sun Nov 10 01:34:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869753 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9753A1531E1; Sun, 10 Nov 2024 01:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202633; cv=none; b=d+wsQWZN6cV8aPngxwLHE8qOFrU+k1KYqrIjL2ot9c+a7kibALZIe4R2+ejBk/oclnCjroLueAIrQ0dDMrs8JxWNqtsplaubx4XRFcrGW2wwcM+FmKIXk+FMHT6kCiJk9yi0KlqZ1pkmseBdDo6xM0wnFc4l5RiJZklNnXU9M/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202633; c=relaxed/simple; bh=rI9k7enmxwz9ojQI4LH1nAFQpHFd3uNrpzEHxR5/YGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H0kOyOohzQOa6H14m3lWMsF6D3m/AdoZl9w2Rf6Qud3L8n9/Uv6sDW1JdCxEXBvcxKDUS1FmR/sJonpMFGcjNX9ydOBVqTdTpnrkAO1+POIphEODFvuqCem7gUmvwLBxERsBtAtUsQhR3HhX8vcw49LVuwA8NGQc1TP5M1X/D8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GBfoOi0k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GBfoOi0k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3521EC4CECE; Sun, 10 Nov 2024 01:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202633; bh=rI9k7enmxwz9ojQI4LH1nAFQpHFd3uNrpzEHxR5/YGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBfoOi0k288Oc2FpvxiCdfmOinmODTTYiDyFLw6K17s+T/wbrVbtbnuZMSDqwE1ET msNvULVPK63bqpTIbrFlLy0KbKYWEin2Ci6T2Fg4ZvI/x/ZvCRikUxejIoGB97Byl9 uYPTr678oz1rAViMzpPddJ4CJu/E32uL4xaQAdmWAr+5S/9zKqv5uiHOFpzEySzL6z bQ8PQARZgubVRi6qgUDxHgogBBEVRp5J0vgeYUoEq27uOFL0kzCEx7YL3sTNwJeUN9 UuUzef+TBBmDpObs3j8i87lWEhlOacTFmEiPKfX9kK1BwQvy5KjYxy51kOYXV4sHYm Jr/yUTv1Q3Zmg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 09/11] kbuild: use absolute path in the generated wrapper Makefile Date: Sun, 10 Nov 2024 10:34:37 +0900 Message-ID: <20241110013649.34903-10-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Keep the consistent behavior when this Makefile is invoked from another directory. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- (no changes since v1) Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5488aa96b46b..35e34cce4942 100644 --- a/Makefile +++ b/Makefile @@ -644,8 +644,9 @@ ifdef building_out_of_srctree quiet_cmd_makefile = GEN Makefile cmd_makefile = { \ - echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ - echo "include $(srctree)/Makefile"; \ + echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ + echo "export KBUILD_OUTPUT = $(CURDIR)"; \ + echo "include $(abs_srctree)/Makefile"; \ } > Makefile outputmakefile: From patchwork Sun Nov 10 01:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869754 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37822155A30; Sun, 10 Nov 2024 01:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202635; cv=none; b=tHTIDd+idufV+NSpv7lwPG6B3MbgaG82TuAsPIH3uCyaR0LaWd2xdumqth79t1yiNODXULR6SPbgCPnbElvsl8le9oDk26fPXRUMvMyfmAcU3v4TfWl0a28Jv8g7g02ewMIZEfYxei9IBrem09g9jE7ID+6d9+Y1YoB3BcZsvbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202635; c=relaxed/simple; bh=0zuP6CP79N07MZokL7X/3TUXckWFEXEyNFcF1B4viqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VSD3a14KNEh08yjnMOXFNpZwPn+72wYvpW0BakdvWD7silDFG3KMiCkgNu4v291nnRrQW8+nQohrLyvsdMx6tWQDquiOiGTImDSpWL6lmDjRsGstlIVOeL3G7A14y8XRK794eukXTaAkD9FK5Z2yjOAUyc5R3j6x2q4u7qKb2zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rh5R+UeY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rh5R+UeY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8D9BC4CED5; Sun, 10 Nov 2024 01:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202635; bh=0zuP6CP79N07MZokL7X/3TUXckWFEXEyNFcF1B4viqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rh5R+UeYAqhDksHA37rS7cnbCjErm90Vq0kIK+C07uxDHBWJv+/AUidbid8iZ/yWJ ISIiZzgjZKfQO88nG6mL69Ns+mUF9dbV4uutOVbmLF1rtK9oc5HQ0o/AgTHFj7PRqc P1sDAazQJF+7K2Gi3TMaigW+JRyOKyKdOQp16aZpjCTfjJxSPMfuFNiNecd8mG70lb bCe9/pENPgONCF2E9LFI1CmGs6Vr0xoFWHqT/zGf/gjw2n1Y2+Zbrr9BsCKHXzzjni 8PDbNRwEWosRBNlEoe3RLy65EgeX7o3E++Pfvp3SNvj/Z1TUKzJ5OiY3yL6nszXv2S mp3dbi8zFefDA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 10/11] kbuild: make wrapper Makefile more convenient for external modules Date: Sun, 10 Nov 2024 10:34:38 +0900 Message-ID: <20241110013649.34903-11-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When Kbuild starts building in a separate output directory, it generates a wrapper Makefile, allowing you to invoke 'make' from the output directory. This commit makes it more convenient, so you can invoke 'make' without M= or MO=. First, you need to build external modules in a separate directory: $ make M=/path/to/module/source/dir MO=/path/to/module/build/dir Once the wrapper Makefile is generated in /path/to/module/build/dir, you can proceed as follows: $ cd /path/to/module/build/dir $ make Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - use $(srcroot) instead of $(_vpath) Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 35e34cce4942..df002595341a 100644 --- a/Makefile +++ b/Makefile @@ -642,10 +642,20 @@ ifdef building_out_of_srctree # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory +ifdef KBUILD_EXTMOD +print_env_for_makefile = \ + echo "export KBUILD_OUTPUT = $(objtree)"; \ + echo "export KBUILD_EXTMOD = $(realpath $(srcroot))" ; \ + echo "export KBUILD_EXTMOD_OUTPUT = $(CURDIR)" +else +print_env_for_makefile = \ + echo "export KBUILD_OUTPUT = $(CURDIR)" +endif + quiet_cmd_makefile = GEN Makefile cmd_makefile = { \ echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ - echo "export KBUILD_OUTPUT = $(CURDIR)"; \ + $(print_env_for_makefile); \ echo "include $(abs_srctree)/Makefile"; \ } > Makefile From patchwork Sun Nov 10 01:34:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13869755 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC991531E1; Sun, 10 Nov 2024 01:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202636; cv=none; b=eMyxE4hjlyrFuLQN0IJ9ARxr6WbnI3WWQ8BSlFQnmqyDcgENMChjvcccRtzh3zTgX6ZCDQPG2luax3m0o9icgBBxAPDoO3lADuAEctY5eJ7nUxRgmcAwW1YxLOLi51VpBlozqaU2lXoN0fl6qRMGE/JqVYjecsJMUk2I4wooDmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731202636; c=relaxed/simple; bh=JnWxdVvEakJui+gj8y0AxBpvkUHKa2A9Zi/L+iOkT1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ElVZnibyjkgk1bmpLtvkkU/Iv8FYdp0lwQVrgG463APoXO3oAa2W8jhFsY2BA3rYA03Bs+Gem4a4JSDFRh6xrG3dD+vbuUlDmleIvVVClpnWh4JmvP1OjXkL8dLITiOInUfAXjO91a49qbX8R4Y86cAyRnAGeV9Q8mzjPlYINQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bwaaGq2H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bwaaGq2H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D4A0C4CED4; Sun, 10 Nov 2024 01:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731202636; bh=JnWxdVvEakJui+gj8y0AxBpvkUHKa2A9Zi/L+iOkT1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bwaaGq2HqiVB2ahWcOSdWO3oIJXB7Eg6GV61J+xbFylFN/twskGjDMCQccPPIldvI zS0AxzPzUaaV/bw1hlYH+M74PtywkLUgBmISlhKQyFACz962upk1J4iuF6uhL8QKnL xy3mlAamzLiMZRvFiAqQItnFPAeTmxb9wzxzQrz/M5ul1BqXMQ+1T53dc9O7mp75oP m+zaJzb2Sje2GMiWQ/5XADl2KZK75KQhtD9hjFRlOL7DABkghTsk+SUjUxgHlIKtm9 j/tqReUhKCoTZ2r41ztMH5Kyhf4ksju/aRIIHqCqkRNs4F1fL/VRW+FBOEhWPfSVkC ODb2gw/ITRmKg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, cocci@inria.fr, Masahiro Yamada , Nicolas Schier Subject: [PATCH v2 11/11] kbuild: allow to start building external modules in any directory Date: Sun, 10 Nov 2024 10:34:39 +0900 Message-ID: <20241110013649.34903-12-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241110013649.34903-1-masahiroy@kernel.org> References: <20241110013649.34903-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Unless an explicit O= option is provided, external module builds must start from the kernel directory. This can be achieved by using the -C option: $ make -C /path/to/kernel M=/path/to/external/module This commit allows starting external module builds from any directory, so you can also do the following: $ make -f /path/to/kernel/Makefile M=/path/to/external/module The key difference is that the -C option changes the working directory and parses the Makefile located there, while the -f option only specifies the Makefile to use. As shown in the examples in Documentation/kbuild/modules.rst, external modules usually have a wrapper Makefile that allows you to build them without specifying any make arguments. The Makefile typically contains a rule as follows: KDIR ?= /path/to/kernel default: $(MAKE) -C $(KDIR) M=$(CURDIR) $(MAKECMDGOALS) The log will appear as follows: $ make make -C /path/to/kernel M=/path/to/external/module make[1]: Entering directory '/path/to/kernel' make[2]: Entering directory '/path/to/external/module' CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko make[2]: Leaving directory '/path/to/external/module' make[1]: Leaving directory '/path/to/kernel' This changes the working directory twice because the -C option first switches to the kernel directory, and then Kbuild internally recurses back to the external module directory. With this commit, the wrapper Makefile can directly include the kernel Makefile: KDIR ?= /path/to/kernel export KBUILD_EXTMOD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) include $(KDIR)/Makefile This avoids unnecessary sub-make invocations: $ make CC [M] helloworld.o MODPOST Module.symvers CC [M] helloworld.mod.o CC [M] .module-common.o LD [M] helloworld.ko Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Changes in v2: - Fix typos in the commit description (s/exernal/external/) - Fix `uname -r` to $(shell uname -r) in Example 3 Documentation/kbuild/modules.rst | 21 +++++++++++++++++++++ Makefile | 8 ++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index a01f3754c7fc..101de236cd0c 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -59,6 +59,12 @@ Command Syntax $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install + Starting from Linux 6.13, you can use the -f option instead of -C. This + will avoid unnecessary change of the working directory. The external + module will be output to the directory where you invoke make. + + $ make -f /lib/modules/`uname -r`/build/Makefile M=$PWD + Options ------- @@ -221,6 +227,21 @@ Separate Kbuild File and Makefile consisting of several hundred lines, and here it really pays off to separate the kbuild part from the rest. + Linux 6.13 and later support another way. The external module Makefile + can include the kernel Makefile directly, rather than invoking sub Make. + + Example 3:: + + --> filename: Kbuild + obj-m := 8123.o + 8123-y := 8123_if.o 8123_pci.o + + --> filename: Makefile + KDIR ?= /lib/modules/$(shell uname -r)/build + export KBUILD_EXTMOD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) + include $(KDIR)/Makefile + + Building Multiple Modules ------------------------- diff --git a/Makefile b/Makefile index df002595341a..0825a9a58ca9 100644 --- a/Makefile +++ b/Makefile @@ -189,9 +189,13 @@ ifdef KBUILD_EXTMOD objtree := $(realpath $(KBUILD_OUTPUT)) $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) else - objtree := $(CURDIR) + objtree := $(abs_srctree) endif - output := $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) + # If Make is invoked from the kernel directory (either kernel + # source directory or kernel build directory), external modules + # are built in $(KBUILD_EXTMOD) for backward compatibility, + # otherwise, built in the current directory. + output := $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(objtree) $(abs_srctree)),$(KBUILD_EXTMOD))) # KBUILD_EXTMOD might be a relative path. Remember its absolute path before # Make changes the working directory. srcroot := $(realpath $(KBUILD_EXTMOD))