From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 # We process the rest of the Makefile if this is the final invocation of m= ake =20 -ifeq ($(abs_srctree),$(abs_objtree)) +ifeq ($(abs_srctree),$(CURDIR)) # building in the source tree srctree :=3D . building_out_of_srctree :=3D else - ifeq ($(abs_srctree)/,$(dir $(abs_objtree))) + ifeq ($(abs_srctree)/,$(dir $(CURDIR))) # building in a subdirectory of the source tree srctree :=3D .. else --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" $(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 :=3D . 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 =20 # Read KERNELRELEASE from include/config/kernel.release (if it exists) -KERNELRELEASE =3D $(call read-file, include/config/kernel.release) +KERNELRELEASE =3D $(call read-file, $(objtree)/include/config/kernel.relea= se) KERNELVERSION =3D $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEV= EL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION =20 @@ -720,7 +720,7 @@ endif export KBUILD_MODULES KBUILD_BUILTIN =20 ifdef need-config -include include/config/auto.conf +include $(objtree)/include/config/auto.conf endif =20 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 =20 -checked-configs :=3D include/generated/autoconf.h include/generated/rustc_= cfg include/config/auto.conf +checked-configs :=3D $(addprefix $(objtree)/, include/generated/autoconf.h= include/generated/rustc_cfg include/config/auto.conf) missing-configs :=3D $(filter-out $(wildcard $(checked-configs)), $(checke= d-configs)) =20 ifdef missing-configs -PHONY +=3D include/config/auto.conf +PHONY +=3D $(objtree)/include/config/auto.conf =20 -include/config/auto.conf: +$(objtree)/include/config/auto.conf: @echo >&2 '***' @echo >&2 '*** ERROR: Kernel configuration is invalid. The following f= iles 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=3Dtls \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "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 :=3D \ -fplugin-arg-arm_ssp_per_task_plugin-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}'\ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) $(eval KBUILD_CFLAGS +=3D $(SSP_PLUGIN_CFLAGS)) $(eval GCC_PLUGINS_CFLAGS +=3D $(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=3Dsp_el0 \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif =20 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 +=3D stack_protector_prepare stack_protector_prepare: prepare0 ifdef CONFIG_PPC64 - $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "PACA_CANARY") print $$3;}' $(objtree)/include/generated/asm= -offsets.h)) else - $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shell awk '{= if ($$2 =3D=3D "TASK_CANARY") print $$3;}' $(objtree)/include/generated/asm= -offsets.h)) endif endif =20 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=3Dtp \ -mstack-protector-guard-offset=3D$(shell \ awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' \ - include/generated/asm-offsets.h)) + $(objtree)/include/generated/asm-offsets.h)) endif =20 # 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 =3D $(if $(if-changed-cond),$(cmd_and_fi= xdep),@:) =20 cmd_and_fixdep =3D = \ $(cmd); \ - scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ + $(objtree)/scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-targe= t).cmd;\ rm -f $(depfile) =20 # 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 :=3D subdir-ccflags-y :=3D =20 # Read auto.conf if it exists, otherwise ignore --include include/config/auto.conf +-include $(objtree)/include/config/auto.conf =20 include $(srctree)/scripts/Kbuild.include include $(srctree)/scripts/Makefile.compiler @@ -107,7 +107,7 @@ cmd_cpp_i_c =3D $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(obj)/%.c FORCE $(call if_changed_dep,cpp_i_c) =20 -genksyms =3D scripts/genksyms/genksyms \ +genksyms =3D $(objtree)/scripts/genksyms/genksyms \ $(if $(1), -T $(2)) \ $(if $(KBUILD_PRESERVE), -p) \ -r $(or $(wildcard $(2:.symtypes=3D.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 :=3D __modfinal __modfinal: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 # for c_flags @@ -37,15 +37,15 @@ quiet_cmd_ld_ko_o =3D LD [M] $@ cmd_ld_ko_o =3D \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^) =20 quiet_cmd_btf_ko =3D BTF [M] $@ cmd_btf_ko =3D \ - 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=3D"$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE= _FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@; \ + LLVM_OBJCOPY=3D"$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE= _FLAGS) --btf_base $(objtree)/vmlinux $@; \ + $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ fi; =20 # Same as newer-prereqs, but allows to exclude specified extra dependencies @@ -57,8 +57,8 @@ if_changed_except =3D $(if $(call newer_prereqs_except,$(= 2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ :=3D $(make-cmd)' > $(dot-target).cmd, @:) =20 # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(an= d $(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/modu= le.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 :=3D __modinst __modinst: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 install-y :=3D 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 :=3D __modpost __modpost: =20 -include include/config/auto.conf +include $(objtree)/include/config/auto.conf include $(srctree)/scripts/Kbuild.include =20 -MODPOST =3D scripts/mod/modpost +MODPOST =3D $(objtree)/scripts/mod/modpost =20 modpost-args =3D \ $(if $(CONFIG_MODULES),-M) \ @@ -119,11 +119,11 @@ include $(kbuild-file) =20 output-symdump :=3D $(KBUILD_EXTMOD)/Module.symvers =20 -ifeq ($(wildcard Module.symvers),) -missing-input :=3D Module.symvers +ifeq ($(wildcard $(objtree)/Module.symvers),) +missing-input :=3D $(objtree)/Module.symvers else -modpost-args +=3D -i Module.symvers -modpost-deps +=3D Module.symvers +modpost-args +=3D -i $(objtree)/Module.symvers +modpost-deps +=3D $(objtree)/Module.symvers endif =20 modpost-args +=3D -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=3D$1 =20 : ${DEPMOD:=3Ddepmod} =20 -if ! test -r System.map ; then +if ! test -r "${objtree}/System.map" ; then echo "Warning: modules_install: missing 'System.map' file. Skipping depmo= d." >&2 exit 0 fi @@ -25,7 +25,7 @@ if [ -z $(command -v $DEPMOD) ]; then exit 0 fi =20 -set -- -ae -F System.map +set -- -ae -F "${objtree}/System.map" if test -n "$INSTALL_MOD_PATH"; then set -- "$@" -b "$INSTALL_MOD_PATH" fi --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" '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: =20 this-makefile :=3D $(lastword $(MAKEFILE_LIST)) abs_srctree :=3D $(realpath $(dir $(this-makefile))) -abs_objtree :=3D $(CURDIR) +abs_output :=3D $(CURDIR) =20 ifneq ($(sub_make_done),1) =20 @@ -185,8 +185,8 @@ ifneq ($(KBUILD_OUTPUT),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' fi= rst. $(shell mkdir -p "$(KBUILD_OUTPUT)") # $(realpath ...) resolves symlinks -abs_objtree :=3D $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_O= UTPUT)")) +abs_output :=3D $(realpath $(KBUILD_OUTPUT)) +$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OU= TPUT)")) endif # ifneq ($(KBUILD_OUTPUT),) =20 ifneq ($(words $(subst :, ,$(abs_srctree))), 1) @@ -197,7 +197,7 @@ export sub_make_done :=3D 1 =20 endif # sub_make_done =20 -ifeq ($(abs_objtree),$(CURDIR)) +ifeq ($(abs_output),$(CURDIR)) # Suppress "Entering directory ..." if we are at the final work directory. no-print-directory :=3D --no-print-directory else @@ -221,7 +221,7 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: = __sub-make =20 # 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) =20 else # need-sub-make --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" $(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=3D assignment takes precedence over the KBUILD_OUTPUT environment # variable. =20 -# Do we want to change the working directory? ifeq ("$(origin O)", "command line") KBUILD_OUTPUT :=3D $(O) endif =20 -ifneq ($(KBUILD_OUTPUT),) +output :=3D $(KBUILD_OUTPUT) + +# Do we want to change the working directory? +ifneq ($(output),) # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' fi= rst. -$(shell mkdir -p "$(KBUILD_OUTPUT)") +$(shell mkdir -p "$(output)") # $(realpath ...) resolves symlinks -abs_output :=3D $(realpath $(KBUILD_OUTPUT)) -$(if $(abs_output),,$(error failed to create output directory "$(KBUILD_OU= TPUT)")) -endif # ifneq ($(KBUILD_OUTPUT),) +abs_output :=3D $(realpath $(output)) +$(if $(abs_output),,$(error failed to create output directory "$(output)")) +endif =20 ifneq ($(words $(subst :, ,$(abs_srctree))), 1) $(error source directory cannot contain spaces or colons) --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D/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=3D/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-too= ls/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 u= sed =20 -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=3D targets. If you do not supply any M=3D target, it is assumed you want to target the entire kernel. The kernel coccicheck script has:: =20 - if [ "$KBUILD_EXTMOD" =3D "" ] ; then - OPTIONS=3D"--dir $srctree $COCCIINCLUDE" - else - OPTIONS=3D"--dir $KBUILD_EXTMOD $COCCIINCLUDE" - fi + OPTIONS=3D"--dir $srcroot $COCCIINCLUDE" =20 -KBUILD_EXTMOD is set when an explicit target with M=3D is used. For both c= ases -the spatch ``--dir`` argument is used, as such third rule applies when whe= ther -M=3D is used or not, and when M=3D is used the target directory can have i= ts own -.cocciconfig file. When M=3D 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=3D used, and otherwise, to the k= ernel +source directory. The third rule ensures the spatch reads the .cocciconfig= from +the target directory, allowing external modules to have their own .coccico= nfig +file. =20 If not using the kernel's coccicheck target, keep the above precedence order logic of .cocciconfig reading. If using the kernel's coccicheck targ= et, diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.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). =20 +$(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 wh= ether + KBUILD_EXTMOD is set. This can be either a relative or an absolute path,= but + if KBUILD_ABS_SRCTREE=3D1 is set, it is always an absolute path. + +$(srctree) + $(srctree) refers to the root of the kernel source tree. When building t= he + 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 :=3D $(O) endif =20 -output :=3D $(KBUILD_OUTPUT) +ifdef KBUILD_EXTMOD + ifdef KBUILD_OUTPUT + objtree :=3D $(realpath $(KBUILD_OUTPUT)) + $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTP= UT)" does not exist)) + else + objtree :=3D $(CURDIR) + endif + output :=3D $(KBUILD_EXTMOD) + # KBUILD_EXTMOD might be a relative path. Remember its absolute path b= efore + # Make changes the working directory. + srcroot :=3D $(realpath $(KBUILD_EXTMOD)) + $(if $(srcroot),,$(error specified external module directory "$(KBUILD= _EXTMOD)" does not exist)) +else + objtree :=3D . + output :=3D $(KBUILD_OUTPUT) +endif + +export objtree srcroot =20 # Do we want to change the working directory? ifneq ($(output),) @@ -230,35 +247,33 @@ else # need-sub-make =20 # We process the rest of the Makefile if this is the final invocation of m= ake =20 -ifeq ($(abs_srctree),$(CURDIR)) - # building in the source tree - srctree :=3D . - building_out_of_srctree :=3D +ifndef KBUILD_EXTMOD +srcroot :=3D $(abs_srctree) +endif + +ifeq ($(srcroot),$(CURDIR)) +building_out_of_srctree :=3D else - ifeq ($(abs_srctree)/,$(dir $(CURDIR))) - # building in a subdirectory of the source tree - srctree :=3D .. - else - srctree :=3D $(abs_srctree) - endif - building_out_of_srctree :=3D 1 +export building_out_of_srctree :=3D1 endif =20 -ifneq ($(KBUILD_ABS_SRCTREE),) -srctree :=3D $(abs_srctree) +ifdef KBUILD_ABS_SRCTREE + # Do not nothing. Use the absolute path. +else ifeq ($(srcroot),$(CURDIR)) + # Building in the source. + srcroot :=3D . +else ifeq ($(srcroot)/,$(dir $(CURDIR))) + # Building in a subdirectory of the source. + srcroot :=3D .. endif =20 -objtree :=3D . +export srctree :=3D $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot)) =20 -VPATH :=3D - -ifeq ($(KBUILD_EXTMOD),) ifdef building_out_of_srctree -VPATH :=3D $(srctree) +export VPATH :=3D $(srcroot) +else +VPATH :=3D endif -endif - -export building_out_of_srctree srctree objtree VPATH =20 # 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 =20 -ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECM= DGOALS)),) +ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMD= GOALS)),) KBUILD_MODULES :=3D 1 endif =20 @@ -1107,7 +1122,7 @@ export MODLIB =20 PHONY +=3D prepare0 =20 -export extmod_prefix =3D $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) +export extmod_prefix =3D export MODORDER :=3D $(extmod_prefix)modules.order export MODULES_NSDEPS :=3D $(extmod_prefix)modules.nsdeps =20 @@ -1799,14 +1814,10 @@ filechk_kernel.release =3D echo $(KERNELRELEASE) KBUILD_BUILTIN :=3D KBUILD_MODULES :=3D 1 =20 -build-dir :=3D $(KBUILD_EXTMOD) +build-dir :=3D . =20 -compile_commands.json: $(extmod_prefix)compile_commands.json -PHONY +=3D compile_commands.json - -clean-dirs :=3D $(KBUILD_EXTMOD) -clean: private rm-files :=3D $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTM= OD)/modules.nsdeps \ - $(KBUILD_EXTMOD)/compile_commands.json +clean-dirs :=3D . +clean: private rm-files :=3D Module.symvers modules.nsdeps compile_command= s.json =20 PHONY +=3D prepare # now expand this into a simple variable to reduce the cost of shell evalu= ations @@ -1948,7 +1959,7 @@ $(clean-dirs): =20 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 +=3D 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 ker= nel + $(Q)$(MAKE) $(build)=3D$(objtree)/rust src=3D$(srctree)/rust $@ +else $(Q)$(MAKE) $(build)=3Drust $@ +endif =20 # 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=3D'core=3D$(core-cfgs)' --cfgs=3D'alloc=3D$(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 =20 redirect-intrinsics =3D \ __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 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -src :=3D $(if $(VPATH),$(VPATH)/)$(obj) +src :=3D $(srcroot)/$(obj) =20 PHONY :=3D $(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 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -src :=3D $(if $(VPATH),$(VPATH)/)$(obj) +src :=3D $(srcroot)/$(obj) =20 PHONY :=3D __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 =3D $(firstword $(foreach c, $(1), \ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) =20 # output directory for tests below -TMPOUT =3D $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ +TMPOUT =3D .tmp_$$$$ =20 # try-run # Usage: option =3D $(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 =20 # set src + obj - they may be used in the modules's Makefile -obj :=3D $(KBUILD_EXTMOD) -src :=3D $(if $(VPATH),$(VPATH)/)$(obj) +obj :=3D . +src :=3D $(srcroot) =20 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS include $(kbuild-file) =20 -output-symdump :=3D $(KBUILD_EXTMOD)/Module.symvers +output-symdump :=3D Module.symvers =20 ifeq ($(wildcard $(objtree)/Module.symvers),) missing-input :=3D $(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=3D1 else ONLINE=3D0 - if [ "$KBUILD_EXTMOD" =3D "" ] ; then - OPTIONS=3D"--dir $srctree $COCCIINCLUDE" - else - OPTIONS=3D"--dir $KBUILD_EXTMOD $COCCIINCLUDE" - fi + OPTIONS=3D"--dir $srcroot $COCCIINCLUDE" =20 # Use only one thread per core by default if hyperthreading is enabled THREADS_PER_CORE=3D$(LANG=3DC 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 =20 -if [ "$KBUILD_EXTMOD" ]; then - src_prefix=3D -else - src_prefix=3D$srctree/ -fi - generate_deps_for_ns() { $SPATCH --very-quiet --in-place --sp-file \ $srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps -D ns=3D$= 1 $2 @@ -34,7 +28,7 @@ generate_deps() { local mod=3D${1%.ko:} shift local namespaces=3D"$*" - local mod_source_files=3D$(sed "s|^\(.*\)\.o$|${src_prefix}\1.c|" $mod.mo= d) + local mod_source_files=3D$(sed "s|^\(.*\)\.o$|${srcroot}/\1.c|" $mod.mod) =20 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}" !=3D "${HOSTCC}" ]; then echo "Rebuilding host programs with ${CC}..." =20 + # 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=3D$(echo "${MAKEFLAGS}" | sed s/--no-print-directory//) + cat <<-'EOF' > "${destdir}/Kbuild" subdir-y :=3D scripts EOF --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 PHONY +=3D prepare0 =20 -export extmod_prefix =3D -export MODORDER :=3D $(extmod_prefix)modules.order -export MODULES_NSDEPS :=3D $(extmod_prefix)modules.nsdeps - ifeq ($(KBUILD_EXTMOD),) =20 build-dir :=3D . @@ -1876,7 +1872,7 @@ endif =20 ifdef CONFIG_MODULES =20 -$(MODORDER): $(build-dir) +modules.order: $(build-dir) @: =20 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. @@ -1887,7 +1883,7 @@ ifneq ($(KBUILD_MODPOST_NOFINAL),1) endif =20 PHONY +=3D modules_check -modules_check: $(MODORDER) +modules_check: modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< =20 else # CONFIG_MODULES @@ -1928,15 +1924,15 @@ $(single-ko): single_modules $(single-no-ko): $(build-dir) @: =20 -# Remove MODORDER when done because it is not the real one. +# Remove modules.order when done because it is not the real one. PHONY +=3D single_modules single_modules: $(single-no-ko) modules_prepare - $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=3D%.o);) }= > $(MODORDER) + $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=3D%.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 =20 single-goals :=3D $(addprefix $(build-dir)/, $(single-no-ko)) =20 @@ -2013,12 +2009,12 @@ nsdeps: modules quiet_cmd_gen_compile_commands =3D GEN $@ cmd_gen_compile_commands =3D $(PYTHON3) $< -a $(AR) -o $@ $(filter-o= ut $<, $(real-prereqs)) =20 -$(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) =20 -targets +=3D $(extmod_prefix)compile_commands.json +targets +=3D compile_commands.json =20 PHONY +=3D clang-tidy clang-analyzer =20 @@ -2026,7 +2022,7 @@ ifdef CONFIG_CC_IS_CLANG quiet_cmd_clang_tools =3D CHECK $< cmd_clang_tools =3D $(PYTHON3) $(srctree)/scripts/clang-tools/run-cl= ang-tools.py $@ $< =20 -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 =20 # find all modules listed in modules.order -modules :=3D $(call read-file, $(MODORDER)) +modules :=3D $(call read-file, modules.order) =20 __modfinal: $(modules:%.o=3D%.ko) @: @@ -30,7 +30,7 @@ quiet_cmd_cc_o_c =3D CC [M] $@ %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) =20 -$(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) =20 quiet_cmd_ld_ko_o =3D LD [M] $@ @@ -57,13 +57,13 @@ if_changed_except =3D $(if $(call newer_prereqs_except,= $(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ :=3D $(make-cmd)' > $(dot-target).cmd, @:) =20 # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o $(extmod_prefix).module-common.o $(objtree)/scripts/modu= le.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/= vmlinux) FORCE +%.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(C= ONFIG_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 =20 -targets +=3D $(modules:%.o=3D%.ko) $(modules:%.o=3D%.mod.o) $(extmod_prefi= x).module-common.o +targets +=3D $(modules:%.o=3D%.ko) $(modules:%.o=3D%.mod.o) .module-common= .o =20 # Add FORCE to the prerequisites of a target to force it to be always rebu= ilt. # ------------------------------------------------------------------------= --- 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.m= odinfo modules.builtin. =20 endif =20 -modules :=3D $(call read-file, $(MODORDER)) +modules :=3D $(call read-file, modules.order) =20 ifeq ($(KBUILD_EXTMOD),) dst :=3D $(MODLIB)/kernel @@ -59,7 +59,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_XZ) :=3D .xz suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) :=3D .zst endif =20 -modules :=3D $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(mod= ules)) +modules :=3D $(patsubst %.o, $(dst)/%.ko$(suffix-y), $(modules)) install-$(CONFIG_MODULES) +=3D $(modules) =20 __modinst: $(install-y) @@ -119,7 +119,7 @@ endif # Create necessary directories $(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir))) =20 -$(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 =3D \ $(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 +=3D -T $(MODORDER) -modpost-deps +=3D $(MODORDER) +modpost-args +=3D -T modules.order +modpost-deps +=3D modules.order endif =20 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 --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D MO=3D 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.) =20 The output directory can also be specified using "O=3D...". =20 Setting "O=3D..." takes precedence over KBUILD_OUTPUT. =20 +KBUILD_EXTMOD_OUTPUT +-------------------- +Specify the output directory for external modules. + +Setting "MO=3D..." 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/module= s.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.) =20 - make -C $KDIR M=3D$PWD + You can optionally pass MO=3D option if you want to build the modules in + a separate directory. + + make -C $KDIR M=3D$PWD [MO=3D$BUILD_DIR] =20 -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. =20 + MO=3D$BUILD_DIR + Specifies a separate output directory for the external module. + Targets ------- =20 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 :=3D $(M) endif =20 +ifeq ("$(origin MO)", "command line") + KBUILD_EXTMOD_OUTPUT :=3D $(MO) +endif + $(if $(word 2, $(KBUILD_EXTMOD)), \ $(error building multiple external modules is not supported)) =20 @@ -187,7 +191,7 @@ ifdef KBUILD_EXTMOD else objtree :=3D $(CURDIR) endif - output :=3D $(KBUILD_EXTMOD) + output :=3D $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) # KBUILD_EXTMOD might be a relative path. Remember its absolute path b= efore # Make changes the working directory. srcroot :=3D $(realpath $(KBUILD_EXTMOD)) @@ -555,7 +559,7 @@ USERINCLUDE :=3D \ LINUXINCLUDE :=3D \ -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) =20 @@ -645,6 +649,7 @@ quiet_cmd_makefile =3D GEN Makefile } > Makefile =20 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=3D$(realpath $(srcroo= t)) 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 :=3D 1 =20 endif =20 +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 =3D --out-dir $(dir $@) --emit=3Ddep-inf= o=3D$(depfile) \ $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ $(HOSTRUSTFLAGS_$(target-stem)) =20 -# $(objtree)/$(obj) for including generated headers from checkin source fi= les -ifeq ($(KBUILD_EXTMOD),) +# $(obj) for including generated headers from checkin source files ifdef building_out_of_srctree -hostc_flags +=3D -I $(objtree)/$(obj) -hostcxx_flags +=3D -I $(objtree)/$(obj) -endif +hostc_flags +=3D -I $(obj) +hostcxx_flags +=3D -I $(obj) endif =20 ##### 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 =20 # $(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 +=3D $(addprefix -I, $(src) $(obj)) _a_flags +=3D $(addprefix -I, $(src) $(obj)) _cpp_flags +=3D $(addprefix -I, $(src) $(obj)) endif -endif =20 # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or = modules is-kernel-object =3D $(or $(part-of-builtin),$(part-of-module)) --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 +=3D -fconserve-stack endif =20 -# change __FILE__ to the relative path from the srctree -KBUILD_CPPFLAGS +=3D $(call cc-option,-fmacro-prefix-map=3D$(srctree)/=3D) +# change __FILE__ to the relative path to the source directory +ifdef building_out_of_srctree +KBUILD_CPPFLAGS +=3D $(call cc-option,-fmacro-prefix-map=3D$(srcroot)/=3D) +endif =20 # include additional Makefiles when needed include-y :=3D scripts/Makefile.extrawarn --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 quiet_cmd_makefile =3D GEN Makefile cmd_makefile =3D { \ - 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 =3D $(CURDIR)"; \ + echo "include $(abs_srctree)/Makefile"; \ } > Makefile =20 outputmakefile: --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D or MO=3D. First, you need to build external modules in a separate directory: $ make M=3D/path/to/module/source/dir MO=3D/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 =20 +ifdef KBUILD_EXTMOD +print_env_for_makefile =3D \ + echo "export KBUILD_OUTPUT =3D $(objtree)"; \ + echo "export KBUILD_EXTMOD =3D $(realpath $(srcroot))" ; \ + echo "export KBUILD_EXTMOD_OUTPUT =3D $(CURDIR)" +else +print_env_for_makefile =3D \ + echo "export KBUILD_OUTPUT =3D $(CURDIR)" +endif + quiet_cmd_makefile =3D GEN Makefile cmd_makefile =3D { \ echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit";= \ - echo "export KBUILD_OUTPUT =3D $(CURDIR)"; \ + $(print_env_for_makefile); \ echo "include $(abs_srctree)/Makefile"; \ } > Makefile =20 --=20 2.43.0 From nobody Sat Nov 23 22:49:40 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unless an explicit O=3D 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=3D/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=3D/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 ?=3D /path/to/kernel default: $(MAKE) -C $(KDIR) M=3D$(CURDIR) $(MAKECMDGOALS) The log will appear as follows: $ make make -C /path/to/kernel M=3D/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 ?=3D /path/to/kernel export KBUILD_EXTMOD :=3D $(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/module= s.rst index a01f3754c7fc..101de236cd0c 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -59,6 +59,12 @@ Command Syntax =20 $ make -C /lib/modules/`uname -r`/build M=3D$PWD modules_install =20 + 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=3D$PWD + Options ------- =20 @@ -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. =20 + 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 :=3D 8123.o + 8123-y :=3D 8123_if.o 8123_pci.o + + --> filename: Makefile + KDIR ?=3D /lib/modules/$(shell uname -r)/build + export KBUILD_EXTMOD :=3D $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) + include $(KDIR)/Makefile + + Building Multiple Modules ------------------------- =20 diff --git a/Makefile b/Makefile index df002595341a..0825a9a58ca9 100644 --- a/Makefile +++ b/Makefile @@ -189,9 +189,13 @@ ifdef KBUILD_EXTMOD objtree :=3D $(realpath $(KBUILD_OUTPUT)) $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTP= UT)" does not exist)) else - objtree :=3D $(CURDIR) + objtree :=3D $(abs_srctree) endif - output :=3D $(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 :=3D $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(obj= tree) $(abs_srctree)),$(KBUILD_EXTMOD))) # KBUILD_EXTMOD might be a relative path. Remember its absolute path b= efore # Make changes the working directory. srcroot :=3D $(realpath $(KBUILD_EXTMOD)) --=20 2.43.0