2023-07-22 04:49:44

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 01/19] kbuild: rpm-pkg: define _arch conditionally

Commit 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is
undefined") does not work as intended; _arch is always defined as
$UTS_MACHINE.

The intention was to define _arch to $UTS_MACHINE only when it is not
defined.

Fixes: 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is undefined")
Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 8049f0e2c110..c9299f9c1f3e 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -57,7 +57,7 @@ $S BuildRequires: gcc make openssl openssl-devel perl python3 rsync

# $UTS_MACHINE as a fallback of _arch in case
# /usr/lib/rpm/platform/*/macros was not included.
- %define _arch %{?_arch:$UTS_MACHINE}
+ %{!?_arch: %define _arch $UTS_MACHINE}
%define __spec_install_post /usr/lib/rpm/brp-compress || :
%define debug_package %{nil}

--
2.39.2



2023-07-22 04:50:34

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 11/19] kbuild: rpm-pkg: use a dummy string for _arch when undefined

If this affects only %{buildroot}, it should be enough to use a fixed
string for _arch when it is undefined.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 783e1997d94a..22b980cf3d00 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -36,6 +36,8 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
%define ARCH ${ARCH}
%define KERNELRELEASE ${KERNELRELEASE}

+# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included.
+%{!?_arch: %define _arch dummy}
%{!?make: %define make make}
%define makeflags %{?_smp_mflags} ARCH=%{ARCH}

@@ -55,9 +57,6 @@ $S BuildRequires: bc binutils bison dwarves
$S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
$S BuildRequires: gcc make openssl openssl-devel perl python3 rsync

- # $UTS_MACHINE as a fallback of _arch in case
- # /usr/lib/rpm/platform/*/macros was not included.
- %{!?_arch: %define _arch $UTS_MACHINE}
%define __spec_install_post /usr/lib/rpm/brp-compress || :
%define debug_package %{nil}

--
2.39.2


2023-07-22 05:00:59

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 05/19] kbuild: rpm-pkg: record ARCH option in spec file

Currently, we rely on the top Makefile defining ARCH option when we
run 'make rpm-pkg' or 'make binrpm-pkg'.

It does not apply when we run 'make srcrpm-pkg', and separately run
'rpmbuild' for the generated SRPM. This is a problem for cross-build.

Just like the Debian package, save the value of ARCH in the spec file.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index a1ce6677880a..0befb4e2ac6b 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -38,8 +38,10 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
# $S: this line is enabled only when building source package
# $M: this line is enabled only when CONFIG_MODULES is enabled
sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
+%define ARCH ${ARCH}
+
%{!?make: %define make make}
-%define makeflags %{?_smp_mflags}
+%define makeflags %{?_smp_mflags} ARCH=%{ARCH}

Name: kernel
Summary: The Linux Kernel
--
2.39.2


2023-07-22 05:03:07

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 16/19] kbuild: rpm-pkg: rename binkernel.spec to kernel.spec

Now kernel.spec and binkernel.spec have the exactly same contents.

Use kernel.spec for binrpm-pkg as well.

Signed-off-by: Masahiro Yamada <[email protected]>
---

.gitignore | 2 +-
Makefile | 2 +-
scripts/Makefile.package | 4 ++--
scripts/remove-stale-files | 2 ++
4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9fd4c9533b3d..0bbae167bf93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,7 +74,7 @@ modules.order
#
# RPM spec file (make rpm-pkg)
#
-/*.spec
+/kernel.spec
/rpmbuild/

#
diff --git a/Makefile b/Makefile
index f258ef13fa5d..5a263e5f6559 100644
--- a/Makefile
+++ b/Makefile
@@ -1595,7 +1595,7 @@ MRPROPER_FILES += include/config include/generated \
certs/signing_key.pem \
certs/x509.genkey \
vmlinux-gdb.py \
- *.spec rpmbuild \
+ kernel.spec rpmbuild \
rust/libmacros.so

# clean - Delete most, but leave enough to build external modules
diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index c36ae03d6002..be9602fa98da 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -86,9 +86,9 @@ srcrpm-pkg: linux.tar.gz
# ---------------------------------------------------------------------------
PHONY += binrpm-pkg
binrpm-pkg:
- $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+ $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/kernel.spec
+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
- $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \
+ $(UTS_MACHINE)-linux -bb $(objtree)/kernel.spec \
--build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \
--define='make $(MAKE)'

diff --git a/scripts/remove-stale-files b/scripts/remove-stale-files
index f3659ea0335b..8b1a636f8543 100755
--- a/scripts/remove-stale-files
+++ b/scripts/remove-stale-files
@@ -37,3 +37,5 @@ rm -f .scmversion
rm -rf include/ksym

find . -name '*.usyms' | xargs rm -f
+
+rm -f binkernel.spec
--
2.39.2


2023-07-22 05:04:30

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 17/19] kbuild: rpm-pkg: build the kernel in-place for rpm-pkg

Currently, 'make rpm-pkg' always builds the kernel from the pristine
source tree in the ~/rpmbuild/BUILD/ directory.

Build the kernel incrementally just like 'make binrpm-pkg'.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 1 +
1 file changed, 1 insertion(+)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index be9602fa98da..bf2da97f29d0 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -72,6 +72,7 @@ PHONY += rpm-pkg
rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
rpm-pkg: srcrpm-pkg
+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
+ --build-in-place --noprep \
--define='_smp_mflags %{nil}' --define='make $(MAKE)'

# srcrpm-pkg
--
2.39.2


2023-07-22 05:07:59

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 13/19] kbuild: rpm-pkg: run modules_install for non-modular kernel

For the same reason as commit 4243afdb9326 ("kbuild: builddeb: always
make modules_install, to install modules.builtin*"), run modules_install
even when CONFIG_MODULES=n to install modules.builtin*.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index a9425d993667..2613e85cd844 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -101,16 +101,13 @@ $S$M
%else
cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE}
%endif
-$M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
+ %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE}
cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
-$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build
-$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source
+ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
+ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/source
$S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
-$S$M cd %{buildroot}/lib/modules/%{KERNELRELEASE}
-$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} build
-$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source

%clean
rm -rf %{buildroot}
@@ -138,9 +135,9 @@ $S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source

%files
%defattr (-, root, root)
-$M /lib/modules/%{KERNELRELEASE}
-$M %exclude /lib/modules/%{KERNELRELEASE}/build
-$M %exclude /lib/modules/%{KERNELRELEASE}/source
+ /lib/modules/%{KERNELRELEASE}
+ %exclude /lib/modules/%{KERNELRELEASE}/build
+ %exclude /lib/modules/%{KERNELRELEASE}/source
/boot/*

%files headers
--
2.39.2


2023-07-22 05:14:28

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 19/19] kbuild: rpm-pkg: skip build dependency check on non-rpm systems

Commit 8818039f959b ("kbuild: add ability to make source rpm buildable
using koji") added the BuildRequires: field.

Checking the build dependency is fine, but one annoyance is that
'make (bin)rpm-pkg' fails on non-rpm systems [1]. For example, Debian
provides rpmbuild via 'apt install rpm', but of course cannot meet the
requirement listed in the BuildRequires: field.

It is possible to pass RPMOPTS=--nodeps to work around it, but it is
reasonable to do it automatically.

If 'rpm -q rpm' fails, it is not an RPM-managed system. (The command
'rpm' is not installed at all, or was installed by other means.)

In that case, pass --nodeps to skip the build dependency check.

[1]: https://lore.kernel.org/linux-kbuild/[email protected]/

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 0ace3973a0d1..85beab0363d7 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -92,7 +92,8 @@ rpm-pkg srcrpm-pkg binrpm-pkg: kernel.spec
+$(strip rpmbuild -b$(build-type) kernel.spec \
--define='_topdir $(abspath rpmbuild)' \
$(if $(filter a b, $(build-type)), \
- --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}') \
+ --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}' \
+ $$(rpm -q rpm >/dev/null 2>&1 || echo --nodeps)) \
$(if $(filter b, $(build-type)), \
--without devel) \
$(RPMOPTS))
--
2.39.2


2023-07-22 05:14:28

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 06/19] kbuild: rpm-pkg: replace $__KERNELRELEASE in spec file with %{version}

${version} will be replaced with the value of the Version field.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 0befb4e2ac6b..a6a383aaaea7 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -81,12 +81,12 @@ $S BuildRequires: gcc make openssl openssl-devel perl python3 rsync
glibc package.

$S$M %package devel
-$S$M Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel
+$S$M Summary: Development package for building kernel modules to match the %{version} kernel
$S$M Group: System Environment/Kernel
$S$M AutoReqProv: no
$S$M %description -n kernel-devel
$S$M This package provides kernel headers and makefiles sufficient to build modules
-$S$M against the $__KERNELRELEASE kernel package.
+$S$M against the %{version} kernel package.
$S$M
$S %prep
$S %setup -q -n linux
--
2.39.2


2023-07-22 05:14:32

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 18/19] kbuild: rpm-pkg: refactor *rpm-pkg targets

Merge the similar build targets.

Also, make the output location consistent.

Previously, source packages were created in the build directory,
while binary packages under ~/rpmbuild/RPMS/.

Now, Kbuild creates the rpmbuild/ directory in the build directory,
and saves all packages under it.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 52 +++++++++++++++++++++-------------------
scripts/package/mkspec | 8 -------
2 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index bf2da97f29d0..0ace3973a0d1 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -11,7 +11,6 @@ TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
samples scripts security sound tools usr virt \
.config Makefile \
Kbuild Kconfig COPYING $(wildcard localversion*)
-MKSPEC := $(srctree)/scripts/package/mkspec

quiet_cmd_src_tar = TAR $(2).tar.gz
cmd_src_tar = \
@@ -66,32 +65,37 @@ $(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
$(linux-tarballs): .tmp_HEAD FORCE
$(call if_changed,archive)

-# rpm-pkg
+# rpm-pkg srcrpm-pkg binrpm-pkg
# ---------------------------------------------------------------------------
-PHONY += rpm-pkg
-rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
-rpm-pkg: srcrpm-pkg
- +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
- --build-in-place --noprep \
- --define='_smp_mflags %{nil}' --define='make $(MAKE)'

-# srcrpm-pkg
-# ---------------------------------------------------------------------------
-PHONY += srcrpm-pkg
-srcrpm-pkg: linux.tar.gz
- $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
- +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
- --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
+quiet_cmd_mkspec = GEN $@
+ cmd_mkspec = $(srctree)/scripts/package/mkspec > $@

-# binrpm-pkg
-# ---------------------------------------------------------------------------
-PHONY += binrpm-pkg
-binrpm-pkg:
- $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/kernel.spec
- +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
- $(UTS_MACHINE)-linux -bb $(objtree)/kernel.spec \
- --build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \
- --define='make $(MAKE)'
+kernel.spec: FORCE
+ $(call cmd,mkspec)
+
+PHONY += rpm-sources
+rpm-sources: linux.tar.gz
+ $(Q)mkdir -p rpmbuild/SOURCES
+ $(Q)ln -f linux.tar.gz rpmbuild/SOURCES/linux.tar.gz
+ $(Q)cp $(KCONFIG_CONFIG) rpmbuild/SOURCES/config
+ $(Q)$(srctree)/scripts/package/gen-diff-patch rpmbuild/SOURCES/diff.patch
+
+PHONY += rpm-pkg srcrpm-pkg binrpm-pkg
+
+rpm-pkg: private build-type := a
+srcrpm-pkg: private build-type := s
+binrpm-pkg: private build-type := b
+
+rpm-pkg srcrpm-pkg: rpm-sources
+rpm-pkg srcrpm-pkg binrpm-pkg: kernel.spec
+ +$(strip rpmbuild -b$(build-type) kernel.spec \
+ --define='_topdir $(abspath rpmbuild)' \
+ $(if $(filter a b, $(build-type)), \
+ --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}') \
+ $(if $(filter b, $(build-type)), \
+ --without devel) \
+ $(RPMOPTS))

# deb-pkg srcdeb-pkg bindeb-pkg
# ---------------------------------------------------------------------------
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index c08567ae7fb1..d41608efb747 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -9,14 +9,6 @@
# Patched for non-x86 by Opencon (L) 2002 <[email protected]>
#

-# how we were called determines which rpms we build and how we build them
-if [ -z "$1" ]; then
- mkdir -p rpmbuild/SOURCES
- cp linux.tar.gz rpmbuild/SOURCES
- cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config
- "${srctree}/scripts/package/gen-diff-patch" rpmbuild/SOURCES/diff.patch
-fi
-
if grep -q CONFIG_MODULES=y include/config/auto.conf; then
echo '%define with_devel %{?_without_devel: 0} %{?!_without_devel: 1}'
else
--
2.39.2


2023-07-22 05:14:44

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 12/19] kbuild: rpm-pkg: invoke the kernel build from rpmbuild for binrpm-pkg

To reduce the preprocess of the spec file, invoke the kernel build
from rpmbuild.

Run init/build-version to increment the release number not only for
binrpm-pkg but also for srcrpm-pkg and rpm-pkg.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 2 +-
scripts/package/mkspec | 31 ++++++++++++++++---------------
2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 7cd61a374dae..8373644a0473 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -86,10 +86,10 @@ srcrpm-pkg: linux.tar.gz
# ---------------------------------------------------------------------------
PHONY += binrpm-pkg
binrpm-pkg:
- $(MAKE) -f $(srctree)/Makefile
$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \
+ --build-in-place --noprep --define='_smp_mflags %{nil}' \
--define='make $(MAKE)'

# deb-pkg srcdeb-pkg bindeb-pkg
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 22b980cf3d00..a9425d993667 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -35,6 +35,7 @@ fi
sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
%define ARCH ${ARCH}
%define KERNELRELEASE ${KERNELRELEASE}
+%define pkg_release $("${srctree}/init/build-version")

# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included.
%{!?_arch: %define _arch dummy}
@@ -44,18 +45,18 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
Name: kernel
Summary: The Linux Kernel
Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g')
- Release: $(cat .version 2>/dev/null || echo 1)
+ Release: %{pkg_release}
License: GPL
Group: System Environment/Kernel
Vendor: The Linux Community
URL: https://www.kernel.org
-$S Source0: linux.tar.gz
-$S Source1: config
-$S Source2: diff.patch
+ Source0: linux.tar.gz
+ Source1: config
+ Source2: diff.patch
Provides: kernel-%{KERNELRELEASE}
-$S BuildRequires: bc binutils bison dwarves
-$S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
-$S BuildRequires: gcc make openssl openssl-devel perl python3 rsync
+ BuildRequires: bc binutils bison dwarves
+ BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
+ BuildRequires: gcc make openssl openssl-devel perl python3 rsync

%define __spec_install_post /usr/lib/rpm/brp-compress || :
%define debug_package %{nil}
@@ -83,14 +84,14 @@ $S$M %description -n kernel-devel
$S$M This package provides kernel headers and makefiles sufficient to build modules
$S$M against the %{version} kernel package.
$S$M
-$S %prep
-$S %setup -q -n linux
-$S cp %{SOURCE1} .config
-$S patch -p1 < %{SOURCE2}
-$S
-$S %build
-$S %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
-$S
+ %prep
+ %setup -q -n linux
+ cp %{SOURCE1} .config
+ patch -p1 < %{SOURCE2}
+
+ %build
+ %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
+
%install
mkdir -p %{buildroot}/boot
%ifarch ia64
--
2.39.2


2023-07-22 05:14:48

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 08/19] kbuild: add a phony target to run a command with Kbuild env vars

There are some cases where we want to run a command with the same
environment variables as Kbuild uses. For example, 'make coccicheck'
invokes scripts/coccicheck from the top Makefile so that the script can
reference to ${LINUXINCLUDE}, ${KBUILD_EXTMOD}, etc. The top Makefile
defines several phony targets that run a script.

We do it also for an internally used script, which results in a somewhat
complex call graph.

One example:

debian/rules binary-arch
-> make intdeb-pkg
-> scripts/package/builddeb

It is also tedious to add a dedicated target like 'intdeb-pkg' for each
use case.

Add a generic target 'run-command' to run an arbitrary command in an
environment with all Kbuild variables set.

The usage is:

$ make run-command KBUILD_RUN_COMMAND=<command>

The concept is similar to:

$ dpkg-architecture -c <command>

This executes <command> in an environment which has all DEB_* variables
defined.

Convert the existing 'make intdeb-pkg'.

Another possible usage is to interrogate a Make variable.

$ make run-command KBUILD_RUN_COMMAND='echo $(KBUILD_CFLAGS)'

might be useful to see KBUILD_CFLAGS set by the top Makefile.

Signed-off-by: Masahiro Yamada <[email protected]>
---

Makefile | 4 ++++
scripts/Makefile.package | 4 ----
scripts/package/mkdebian | 3 ++-
3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 47690c28456a..f258ef13fa5d 100644
--- a/Makefile
+++ b/Makefile
@@ -2133,6 +2133,10 @@ kernelversion:
image_name:
@echo $(KBUILD_IMAGE)

+PHONY += run-command
+run-command:
+ $(Q)$(KBUILD_RUN_COMMAND)
+
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
cmd_rmfiles = rm -rf $(rm-files)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index e9217e997c68..7cd61a374dae 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -146,10 +146,6 @@ deb-pkg srcdeb-pkg bindeb-pkg:
--no-check-builddeps) \
$(DPKG_FLAGS))

-PHONY += intdeb-pkg
-intdeb-pkg:
- +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
-
# snap-pkg
# ---------------------------------------------------------------------------
PHONY += snap-pkg
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
index ba2453e08d40..9105abab9728 100755
--- a/scripts/package/mkdebian
+++ b/scripts/package/mkdebian
@@ -283,7 +283,8 @@ build: build-arch
binary-indep:
binary-arch: build-arch
\$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \
- KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg
+ KERNELRELEASE=\$(KERNELRELEASE) \
+ run-command KBUILD_RUN_COMMAND=+\$(srctree)/scripts/package/builddeb

clean:
rm -rf debian/files debian/linux-*
--
2.39.2


2023-07-22 05:14:51

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 07/19] kbuild: rpm-pkg: replace $KERNELRELEASE in spec file with %{KERNELRELEASE}

Avoid hard-coding the value of KERNELRELEASE in the generated spec file.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 59 +++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index a6a383aaaea7..34b2489106cf 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -39,6 +39,7 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
# $M: this line is enabled only when CONFIG_MODULES is enabled
sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
%define ARCH ${ARCH}
+%define KERNELRELEASE ${KERNELRELEASE}

%{!?make: %define make make}
%define makeflags %{?_smp_mflags} ARCH=%{ARCH}
@@ -54,7 +55,7 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
$S Source0: linux.tar.gz
$S Source1: config
$S Source2: diff.patch
- Provides: kernel-$KERNELRELEASE
+ Provides: kernel-%{KERNELRELEASE}
$S BuildRequires: bc binutils bison dwarves
$S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
$S BuildRequires: gcc make openssl openssl-devel perl python3 rsync
@@ -94,58 +95,58 @@ $S cp %{SOURCE1} .config
$S patch -p1 < %{SOURCE2}
$S
$S %build
-$S %{make} %{makeflags} KERNELRELEASE=$KERNELRELEASE KBUILD_BUILD_VERSION=%{release}
+$S %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
$S
%install
mkdir -p %{buildroot}/boot
%ifarch ia64
mkdir -p %{buildroot}/boot/efi
- cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
- ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/
+ cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-%{KERNELRELEASE}
+ ln -s efi/vmlinuz-%{KERNELRELEASE} %{buildroot}/boot/
%else
- cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
+ cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE}
%endif
$M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
- cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE
- cp .config %{buildroot}/boot/config-$KERNELRELEASE
-$S$M rm -f %{buildroot}/lib/modules/$KERNELRELEASE/build
-$S$M rm -f %{buildroot}/lib/modules/$KERNELRELEASE/source
-$S$M mkdir -p %{buildroot}/usr/src/kernels/$KERNELRELEASE
-$S$M tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/$KERNELRELEASE
-$S$M cd %{buildroot}/lib/modules/$KERNELRELEASE
-$S$M ln -sf /usr/src/kernels/$KERNELRELEASE build
-$S$M ln -sf /usr/src/kernels/$KERNELRELEASE source
+ cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE}
+ cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
+$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build
+$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source
+$S$M mkdir -p %{buildroot}/usr/src/kernels/%{KERNELRELEASE}
+$S$M tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/%{KERNELRELEASE}
+$S$M cd %{buildroot}/lib/modules/%{KERNELRELEASE}
+$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} build
+$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source

%clean
rm -rf %{buildroot}

%post
- if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then
- cp /boot/vmlinuz-$KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm
- cp /boot/System.map-$KERNELRELEASE /boot/.System.map-$KERNELRELEASE-rpm
- rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE
- /sbin/installkernel $KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
- rm -f /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
+ if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then
+ cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm
+ cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm
+ rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE}
+ /sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
+ rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
fi

%preun
if [ -x /sbin/new-kernel-pkg ]; then
- new-kernel-pkg --remove $KERNELRELEASE --rminitrd --initrdfile=/boot/initramfs-$KERNELRELEASE.img
+ new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img
elif [ -x /usr/bin/kernel-install ]; then
- kernel-install remove $KERNELRELEASE
+ kernel-install remove %{KERNELRELEASE}
fi

%postun
if [ -x /sbin/update-bootloader ]; then
- /sbin/update-bootloader --remove $KERNELRELEASE
+ /sbin/update-bootloader --remove %{KERNELRELEASE}
fi

%files
%defattr (-, root, root)
-$M /lib/modules/$KERNELRELEASE
-$M %exclude /lib/modules/$KERNELRELEASE/build
-$M %exclude /lib/modules/$KERNELRELEASE/source
+$M /lib/modules/%{KERNELRELEASE}
+$M %exclude /lib/modules/%{KERNELRELEASE}/build
+$M %exclude /lib/modules/%{KERNELRELEASE}/source
/boot/*

%files headers
@@ -154,7 +155,7 @@ $M %exclude /lib/modules/$KERNELRELEASE/source
$S$M
$S$M %files devel
$S$M %defattr (-, root, root)
-$S$M /usr/src/kernels/$KERNELRELEASE
-$S$M /lib/modules/$KERNELRELEASE/build
-$S$M /lib/modules/$KERNELRELEASE/source
+$S$M /usr/src/kernels/%{KERNELRELEASE}
+$S$M /lib/modules/%{KERNELRELEASE}/build
+$S$M /lib/modules/%{KERNELRELEASE}/source
EOF
--
2.39.2


2023-07-22 05:14:59

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 14/19] kbuild: rpm-pkg: introduce %{with_devel} switch to select devel package

scripts/package/mkspec preprocesses the spec file by sed, but it is
unreadable. This commit removes the last portion of the sed scripting.

Remove the $S$M prefixes from the conditionally generated lines.
Instead, surround the code with %if %{with_devel} ... %endif.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.package | 2 +-
scripts/package/mkspec | 53 +++++++++++++++++++---------------------
2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/scripts/Makefile.package b/scripts/Makefile.package
index 8373644a0473..c36ae03d6002 100644
--- a/scripts/Makefile.package
+++ b/scripts/Makefile.package
@@ -89,7 +89,7 @@ binrpm-pkg:
$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \
- --build-in-place --noprep --define='_smp_mflags %{nil}' \
+ --build-in-place --noprep --define='_smp_mflags %{nil}' --without devel \
--define='make $(MAKE)'

# deb-pkg srcdeb-pkg bindeb-pkg
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 2613e85cd844..511cae46a90d 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -10,11 +10,7 @@
#

# how we were called determines which rpms we build and how we build them
-if [ "$1" = prebuilt ]; then
- S=DEL
-else
- S=
-
+if [ -z "$1" ]; then
mkdir -p rpmbuild/SOURCES
cp linux.tar.gz rpmbuild/SOURCES
cp "${KCONFIG_CONFIG}" rpmbuild/SOURCES/config
@@ -22,17 +18,12 @@ else
fi

if grep -q CONFIG_MODULES=y include/config/auto.conf; then
- M=
+echo '%define with_devel %{?_without_devel: 0} %{?!_without_devel: 1}'
else
- M=DEL
+echo '%define with_devel 0'
fi

-# We can label the here-doc lines for conditional output to the spec file
-#
-# Labels:
-# $S: this line is enabled only when building source package
-# $M: this line is enabled only when CONFIG_MODULES is enabled
-sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
+cat<<-EOF
%define ARCH ${ARCH}
%define KERNELRELEASE ${KERNELRELEASE}
%define pkg_release $("${srctree}/init/build-version")
@@ -76,14 +67,16 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
building most standard programs and are also needed for rebuilding the
glibc package.

-$S$M %package devel
-$S$M Summary: Development package for building kernel modules to match the %{version} kernel
-$S$M Group: System Environment/Kernel
-$S$M AutoReqProv: no
-$S$M %description -n kernel-devel
-$S$M This package provides kernel headers and makefiles sufficient to build modules
-$S$M against the %{version} kernel package.
-$S$M
+ %if %{with_devel}
+ %package devel
+ Summary: Development package for building kernel modules to match the %{version} kernel
+ Group: System Environment/Kernel
+ AutoReqProv: no
+ %description -n kernel-devel
+ This package provides kernel headers and makefiles sufficient to build modules
+ against the %{version} kernel package.
+ %endif
+
%prep
%setup -q -n linux
cp %{SOURCE1} .config
@@ -107,7 +100,9 @@ $S$M
cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/source
-$S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
+ %if %{with_devel}
+ %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
+ %endif

%clean
rm -rf %{buildroot}
@@ -143,10 +138,12 @@ $S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/pa
%files headers
%defattr (-, root, root)
/usr/include
-$S$M
-$S$M %files devel
-$S$M %defattr (-, root, root)
-$S$M /usr/src/kernels/%{KERNELRELEASE}
-$S$M /lib/modules/%{KERNELRELEASE}/build
-$S$M /lib/modules/%{KERNELRELEASE}/source
+
+ %if %{with_devel}
+ %files devel
+ %defattr (-, root, root)
+ /usr/src/kernels/%{KERNELRELEASE}
+ /lib/modules/%{KERNELRELEASE}/build
+ /lib/modules/%{KERNELRELEASE}/source
+ %endif
EOF
--
2.39.2


2023-07-22 05:15:01

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 04/19] kbuild: rpm-pkg: use %{makeflags} to pass common Make options

This is useful to pass more common Make options.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 9b2b4386019d..a1ce6677880a 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -39,6 +39,7 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
# $M: this line is enabled only when CONFIG_MODULES is enabled
sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
%{!?make: %define make make}
+%define makeflags %{?_smp_mflags}

Name: kernel
Summary: The Linux Kernel
@@ -91,19 +92,19 @@ $S cp %{SOURCE1} .config
$S patch -p1 < %{SOURCE2}
$S
$S %build
-$S %{make} %{?_smp_mflags} KERNELRELEASE=$KERNELRELEASE KBUILD_BUILD_VERSION=%{release}
+$S %{make} %{makeflags} KERNELRELEASE=$KERNELRELEASE KBUILD_BUILD_VERSION=%{release}
$S
%install
mkdir -p %{buildroot}/boot
%ifarch ia64
mkdir -p %{buildroot}/boot/efi
- cp \$(%{make} -s image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
+ cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/
%else
- cp \$(%{make} -s image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
+ cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
%endif
-$M %{make} %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install
- %{make} %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
+$M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
+ %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE
cp .config %{buildroot}/boot/config-$KERNELRELEASE
$S$M rm -f %{buildroot}/lib/modules/$KERNELRELEASE/build
--
2.39.2


2023-07-22 05:15:04

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 10/19] kbuild: rpm-pkg: derive the Version from %{KERNELRELEASE}

Avoid hard-coding the Version field in the generated spec file.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/mkspec | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 22e290d23d8a..783e1997d94a 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -27,8 +27,6 @@ else
M=DEL
fi

-__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
-
# We can label the here-doc lines for conditional output to the spec file
#
# Labels:
@@ -43,7 +41,7 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF

Name: kernel
Summary: The Linux Kernel
- Version: $__KERNELRELEASE
+ Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g')
Release: $(cat .version 2>/dev/null || echo 1)
License: GPL
Group: System Environment/Kernel
--
2.39.2


2023-07-22 05:15:06

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 09/19] kbuild: refactor kernel-devel RPM package and linux-headers Deb package

The kernel-devel RPM package and the linux-headers Debian package
provide headers and scripts needed for building external modules.

They copy the necessary files in slightly different ways - the RPM
copies almost everything except some exclude patterns, while the Debian
copies less number of files. There is no need to maintain different code
to do the same thing.

Split the Debian code out to scripts/package/install-extmod-build, which
is called from both of the packages.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/builddeb | 29 +--------------------
scripts/package/install-extmod-build | 39 ++++++++++++++++++++++++++++
scripts/package/mkspec | 6 +----
3 files changed, 41 insertions(+), 33 deletions(-)
create mode 100755 scripts/package/install-extmod-build

diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 032774eb061e..bf3f8561aa68 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -162,34 +162,7 @@ install_kernel_headers () {

rm -rf $pdir

- (
- cd $srctree
- find . arch/$SRCARCH -maxdepth 1 -name Makefile\*
- find include scripts -type f -o -type l
- find arch/$SRCARCH -name Kbuild.platforms -o -name Platform
- find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f
- ) > debian/hdrsrcfiles
-
- {
- if is_enabled CONFIG_OBJTOOL; then
- echo tools/objtool/objtool
- fi
-
- find arch/$SRCARCH/include Module.symvers include scripts -type f
-
- if is_enabled CONFIG_GCC_PLUGINS; then
- find scripts/gcc-plugins -name \*.so
- fi
- } > debian/hdrobjfiles
-
- destdir=$pdir/usr/src/linux-headers-$version
- mkdir -p $destdir
- tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir
- tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir
- rm -f debian/hdrsrcfiles debian/hdrobjfiles
-
- # copy .config manually to be where it's expected to be
- cp $KCONFIG_CONFIG $destdir/.config
+ "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"

mkdir -p $pdir/lib/modules/$version/
ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
diff --git a/scripts/package/install-extmod-build b/scripts/package/install-extmod-build
new file mode 100755
index 000000000000..af7fe9f5b1e4
--- /dev/null
+++ b/scripts/package/install-extmod-build
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+set -e
+
+destdir=${1}
+
+test -n "${srctree}"
+test -n "${SRCARCH}"
+
+is_enabled() {
+ grep -q "^$1=y" include/config/auto.conf
+}
+
+mkdir -p "${destdir}"
+
+(
+ cd "${srctree}"
+ echo Makefile
+ find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*'
+ find include scripts -type f -o -type l
+ find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform
+ find "$(find "arch/${SRCARCH}" -name include -o -name scripts -type d)" -type f
+) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}"
+
+{
+ if is_enabled CONFIG_OBJTOOL; then
+ echo tools/objtool/objtool
+ fi
+
+ find "arch/${SRCARCH}/include" Module.symvers include scripts -type f
+
+ if is_enabled CONFIG_GCC_PLUGINS; then
+ find scripts/gcc-plugins -name '*.so'
+ fi
+} | tar -c -f - -T - | tar -xf - -C "${destdir}"
+
+# copy .config manually to be where it's expected to be
+cp "${KCONFIG_CONFIG}" "${destdir}/.config"
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 34b2489106cf..22e290d23d8a 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -28,9 +28,6 @@ else
fi

__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
-EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
---exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \
---exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s"

# We can label the here-doc lines for conditional output to the spec file
#
@@ -112,8 +109,7 @@ $M %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/build
$S$M rm -f %{buildroot}/lib/modules/%{KERNELRELEASE}/source
-$S$M mkdir -p %{buildroot}/usr/src/kernels/%{KERNELRELEASE}
-$S$M tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/%{KERNELRELEASE}
+$S$M %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
$S$M cd %{buildroot}/lib/modules/%{KERNELRELEASE}
$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} build
$S$M ln -sf /usr/src/kernels/%{KERNELRELEASE} source
--
2.39.2


2023-07-22 05:15:06

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 15/19] kbuild: rpm-pkg: split out the body of spec file

Most of the lines in the spec file are independent of any build
condition.

Split the body of the spec file into scripts/package/kernel.spec.
scripts/package/mkspec will prepend some env-dependent variables.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/package/kernel.spec | 117 ++++++++++++++++++++++++++++++++++
scripts/package/mkspec | 123 +-----------------------------------
2 files changed, 120 insertions(+), 120 deletions(-)
create mode 100644 scripts/package/kernel.spec

diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec
new file mode 100644
index 000000000000..ac3f2ee6d7a0
--- /dev/null
+++ b/scripts/package/kernel.spec
@@ -0,0 +1,117 @@
+# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included.
+%{!?_arch: %define _arch dummy}
+%{!?make: %define make make}
+%define makeflags %{?_smp_mflags} ARCH=%{ARCH}
+%define __spec_install_post /usr/lib/rpm/brp-compress || :
+%define debug_package %{nil}
+
+Name: kernel
+Summary: The Linux Kernel
+Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g')
+Release: %{pkg_release}
+License: GPL
+Group: System Environment/Kernel
+Vendor: The Linux Community
+URL: https://www.kernel.org
+Source0: linux.tar.gz
+Source1: config
+Source2: diff.patch
+Provides: kernel-%{KERNELRELEASE}
+BuildRequires: bc binutils bison dwarves
+BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
+BuildRequires: gcc make openssl openssl-devel perl python3 rsync
+
+%description
+The Linux Kernel, the operating system core itself
+
+%package headers
+Summary: Header files for the Linux kernel for use by glibc
+Group: Development/System
+Obsoletes: kernel-headers
+Provides: kernel-headers = %{version}
+%description headers
+Kernel-headers includes the C header files that specify the interface
+between the Linux kernel and userspace libraries and programs. The
+header files define structures and constants that are needed for
+building most standard programs and are also needed for rebuilding the
+glibc package.
+
+%if %{with_devel}
+%package devel
+Summary: Development package for building kernel modules to match the %{version} kernel
+Group: System Environment/Kernel
+AutoReqProv: no
+%description -n kernel-devel
+This package provides kernel headers and makefiles sufficient to build modules
+against the %{version} kernel package.
+%endif
+
+%prep
+%setup -q -n linux
+cp %{SOURCE1} .config
+patch -p1 < %{SOURCE2}
+
+%build
+%{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
+
+%install
+mkdir -p %{buildroot}/boot
+%ifarch ia64
+mkdir -p %{buildroot}/boot/efi
+cp $(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-%{KERNELRELEASE}
+ln -s efi/vmlinuz-%{KERNELRELEASE} %{buildroot}/boot/
+%else
+cp $(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE}
+%endif
+%{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
+%{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
+cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE}
+cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
+ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
+ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/source
+%if %{with_devel}
+%{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
+%endif
+
+%clean
+rm -rf %{buildroot}
+
+%post
+if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then
+cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm
+cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm
+rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE}
+/sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
+rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
+fi
+
+%preun
+if [ -x /sbin/new-kernel-pkg ]; then
+new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img
+elif [ -x /usr/bin/kernel-install ]; then
+kernel-install remove %{KERNELRELEASE}
+fi
+
+%postun
+if [ -x /sbin/update-bootloader ]; then
+/sbin/update-bootloader --remove %{KERNELRELEASE}
+fi
+
+%files
+%defattr (-, root, root)
+/lib/modules/%{KERNELRELEASE}
+%exclude /lib/modules/%{KERNELRELEASE}/build
+%exclude /lib/modules/%{KERNELRELEASE}/source
+/boot/*
+
+%files headers
+%defattr (-, root, root)
+/usr/include
+
+%if %{with_devel}
+%files devel
+%defattr (-, root, root)
+/usr/src/kernels/%{KERNELRELEASE}
+/lib/modules/%{KERNELRELEASE}/build
+/lib/modules/%{KERNELRELEASE}/source
+%endif
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 511cae46a90d..c08567ae7fb1 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -23,127 +23,10 @@ else
echo '%define with_devel 0'
fi

-cat<<-EOF
+cat<<EOF
%define ARCH ${ARCH}
%define KERNELRELEASE ${KERNELRELEASE}
%define pkg_release $("${srctree}/init/build-version")
-
-# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included.
-%{!?_arch: %define _arch dummy}
-%{!?make: %define make make}
-%define makeflags %{?_smp_mflags} ARCH=%{ARCH}
-
- Name: kernel
- Summary: The Linux Kernel
- Version: %(echo %{KERNELRELEASE} | sed -e 's/-/_/g')
- Release: %{pkg_release}
- License: GPL
- Group: System Environment/Kernel
- Vendor: The Linux Community
- URL: https://www.kernel.org
- Source0: linux.tar.gz
- Source1: config
- Source2: diff.patch
- Provides: kernel-%{KERNELRELEASE}
- BuildRequires: bc binutils bison dwarves
- BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
- BuildRequires: gcc make openssl openssl-devel perl python3 rsync
-
- %define __spec_install_post /usr/lib/rpm/brp-compress || :
- %define debug_package %{nil}
-
- %description
- The Linux Kernel, the operating system core itself
-
- %package headers
- Summary: Header files for the Linux kernel for use by glibc
- Group: Development/System
- Obsoletes: kernel-headers
- Provides: kernel-headers = %{version}
- %description headers
- Kernel-headers includes the C header files that specify the interface
- between the Linux kernel and userspace libraries and programs. The
- header files define structures and constants that are needed for
- building most standard programs and are also needed for rebuilding the
- glibc package.
-
- %if %{with_devel}
- %package devel
- Summary: Development package for building kernel modules to match the %{version} kernel
- Group: System Environment/Kernel
- AutoReqProv: no
- %description -n kernel-devel
- This package provides kernel headers and makefiles sufficient to build modules
- against the %{version} kernel package.
- %endif
-
- %prep
- %setup -q -n linux
- cp %{SOURCE1} .config
- patch -p1 < %{SOURCE2}
-
- %build
- %{make} %{makeflags} KERNELRELEASE=%{KERNELRELEASE} KBUILD_BUILD_VERSION=%{release}
-
- %install
- mkdir -p %{buildroot}/boot
- %ifarch ia64
- mkdir -p %{buildroot}/boot/efi
- cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/efi/vmlinuz-%{KERNELRELEASE}
- ln -s efi/vmlinuz-%{KERNELRELEASE} %{buildroot}/boot/
- %else
- cp \$(%{make} %{makeflags} -s image_name) %{buildroot}/boot/vmlinuz-%{KERNELRELEASE}
- %endif
- %{make} %{makeflags} INSTALL_MOD_PATH=%{buildroot} modules_install
- %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
- cp System.map %{buildroot}/boot/System.map-%{KERNELRELEASE}
- cp .config %{buildroot}/boot/config-%{KERNELRELEASE}
- ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
- ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/source
- %if %{with_devel}
- %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='\${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
- %endif
-
- %clean
- rm -rf %{buildroot}
-
- %post
- if [ -x /sbin/installkernel -a -r /boot/vmlinuz-%{KERNELRELEASE} -a -r /boot/System.map-%{KERNELRELEASE} ]; then
- cp /boot/vmlinuz-%{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm
- cp /boot/System.map-%{KERNELRELEASE} /boot/.System.map-%{KERNELRELEASE}-rpm
- rm -f /boot/vmlinuz-%{KERNELRELEASE} /boot/System.map-%{KERNELRELEASE}
- /sbin/installkernel %{KERNELRELEASE} /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
- rm -f /boot/.vmlinuz-%{KERNELRELEASE}-rpm /boot/.System.map-%{KERNELRELEASE}-rpm
- fi
-
- %preun
- if [ -x /sbin/new-kernel-pkg ]; then
- new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img
- elif [ -x /usr/bin/kernel-install ]; then
- kernel-install remove %{KERNELRELEASE}
- fi
-
- %postun
- if [ -x /sbin/update-bootloader ]; then
- /sbin/update-bootloader --remove %{KERNELRELEASE}
- fi
-
- %files
- %defattr (-, root, root)
- /lib/modules/%{KERNELRELEASE}
- %exclude /lib/modules/%{KERNELRELEASE}/build
- %exclude /lib/modules/%{KERNELRELEASE}/source
- /boot/*
-
- %files headers
- %defattr (-, root, root)
- /usr/include
-
- %if %{with_devel}
- %files devel
- %defattr (-, root, root)
- /usr/src/kernels/%{KERNELRELEASE}
- /lib/modules/%{KERNELRELEASE}/build
- /lib/modules/%{KERNELRELEASE}/source
- %endif
EOF
+
+cat "${srctree}/scripts/package/kernel.spec"
--
2.39.2


2023-07-24 20:18:26

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 08/19] kbuild: add a phony target to run a command with Kbuild env vars

On Sat, Jul 22, 2023 at 01:47:55PM +0900 Masahiro Yamada wrote:
> There are some cases where we want to run a command with the same
> environment variables as Kbuild uses. For example, 'make coccicheck'
> invokes scripts/coccicheck from the top Makefile so that the script can
> reference to ${LINUXINCLUDE}, ${KBUILD_EXTMOD}, etc. The top Makefile
> defines several phony targets that run a script.
>
> We do it also for an internally used script, which results in a somewhat
> complex call graph.
>
> One example:
>
> debian/rules binary-arch
> -> make intdeb-pkg
> -> scripts/package/builddeb
>
> It is also tedious to add a dedicated target like 'intdeb-pkg' for each
> use case.
>
> Add a generic target 'run-command' to run an arbitrary command in an
> environment with all Kbuild variables set.
>
> The usage is:
>
> $ make run-command KBUILD_RUN_COMMAND=<command>
>
> The concept is similar to:
>
> $ dpkg-architecture -c <command>
>
> This executes <command> in an environment which has all DEB_* variables
> defined.
>
> Convert the existing 'make intdeb-pkg'.
>
> Another possible usage is to interrogate a Make variable.
>
> $ make run-command KBUILD_RUN_COMMAND='echo $(KBUILD_CFLAGS)'

nice idea, I like that.

Reviewed-by: Nicolas Schier <[email protected]>


>
> might be useful to see KBUILD_CFLAGS set by the top Makefile.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> Makefile | 4 ++++
> scripts/Makefile.package | 4 ----
> scripts/package/mkdebian | 3 ++-
> 3 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 47690c28456a..f258ef13fa5d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2133,6 +2133,10 @@ kernelversion:
> image_name:
> @echo $(KBUILD_IMAGE)
>
> +PHONY += run-command
> +run-command:
> + $(Q)$(KBUILD_RUN_COMMAND)
> +
> quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
> cmd_rmfiles = rm -rf $(rm-files)
>
> diff --git a/scripts/Makefile.package b/scripts/Makefile.package
> index e9217e997c68..7cd61a374dae 100644
> --- a/scripts/Makefile.package
> +++ b/scripts/Makefile.package
> @@ -146,10 +146,6 @@ deb-pkg srcdeb-pkg bindeb-pkg:
> --no-check-builddeps) \
> $(DPKG_FLAGS))
>
> -PHONY += intdeb-pkg
> -intdeb-pkg:
> - +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
> -
> # snap-pkg
> # ---------------------------------------------------------------------------
> PHONY += snap-pkg
> diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
> index ba2453e08d40..9105abab9728 100755
> --- a/scripts/package/mkdebian
> +++ b/scripts/package/mkdebian
> @@ -283,7 +283,8 @@ build: build-arch
> binary-indep:
> binary-arch: build-arch
> \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \
> - KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg
> + KERNELRELEASE=\$(KERNELRELEASE) \
> + run-command KBUILD_RUN_COMMAND=+\$(srctree)/scripts/package/builddeb
>
> clean:
> rm -rf debian/files debian/linux-*
> --
> 2.39.2

--
epost|xmpp: [email protected] irc://oftc.net/nsc
↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f
-- frykten for herren er opphav til kunnskap --


Attachments:
(No filename) (3.24 kB)
signature.asc (849.00 B)
Download all attachments

2023-09-12 07:17:59

by chenxiang (M)

[permalink] [raw]
Subject: Re: [PATCH 11/19] kbuild: rpm-pkg: use a dummy string for _arch when undefined

Hi,

I build the latest kernel (6.6-rc1) for arm64 platform on x86 server
(with cross complile), and the complile command is as following:

export
PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

make -j64 Image (ok)

make binrpm-pkg -j64 (failed)

But when complile binrpm-pkg, it is failed and the error info is as
following:

rpmbuild -bb kernel.spec --define='_topdir
/home/chenxiang/kernel/mainline/linux-next/rpmbuild' --target
aarch64-linux --build-in-place --noprep --define='_smp_mflags %{nil}'
$(rpm -q rpm >/dev/null 2>&1 || echo --nodeps) --without devel
rpmbuild: --build-in-place: unknown option
make[2]: *** [scripts/Makefile.package:92: binrpm-pkg] Error 1
make[1]: *** [/home/chenxiang/kernel/mainline/linux-next/Makefile:1538:
binrpm-pkg] Error 2
make: *** [Makefile:234: __sub-make] Error 2

But it is ok with v6.5-rc7, so i bisect the kernel code and find the
patch (kbuild: rpm-pkg: use a dummy string for _arch when undefined):

706a741595047797872e (v6.6-rc1) good
0bb80ecc33a8fb5a6(v6.5-rc7) bad
[461f35f014466c4e26dca6be0f431f57297df3f2] Merge tag
'drm-next-2023-08-30' of git://anongit.freedesktop.org/drm/drm good
[e925992671907314b7db6793a28eb39b36bc21a4] Merge tag 'staging-6.6-rc1'
of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging good
[3c31041e37324e143bee98604bb31481e905b4b3] Merge tag 'printk-for-6.6' of
git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux good
[4a0fc73da97efd23a383ca839e6fe86410268f6b] Merge tag 's390-6.6-2' of
git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux bad
[61401a8724c2ce912b243ef95427a9b2e5a1ed50] Merge tag 'kbuild-v6.6' of
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild bad
[2be6bc48df59c99d35aab16a51d4a814e9bb8c35] Merge tag 'leds-next-6.6' of
git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds good
[3f86ed6ec0b390c033eae7f9c487a3fea268e027] Merge tag 'arc-6.6-rc1' of
git://git.kernel.org/pub/scm/linux/kernel/git/vgupta/arc good
[4cdb71b6ba3283fb2b7eaccc333f8f2c5b81797b] sparc: replace #include
<asm/export.h> with #include <linux/export.h> bad
[975667d02d134f7b48d15ee7ff0d49e69a6774cf] kbuild: rpm-pkg: rename
binkernel.spec to kernel.spec bad
[a06d9ef897d59f719102e2890abd8a2b91e29a60] kbuild: rpm-pkg: record ARCH
option in spec file good
[d5d2d4cc60888f02dd4a6b2bfb03ff2fd7be4fc2] kbuild: rpm-pkg: derive the
Version from %{KERNELRELEASE} good
[b537925fdd689ca33b6d9eed4569bc625550b3ef] kbuild: rpm-pkg: run
modules_install for non-modular kernel bad
[1789fc9125414bd9ca4d50a8966752ee6103d547] kbuild: rpm-pkg: invoke the
kernel build from rpmbuild for binrpm-pkg bad
[d4f651277e9208b580b55da212e17ddd309c91e7] kbuild: rpm-pkg: use a dummy
string for _arch when undefined


Do you have any idea about this issue?


Thanks

Xiang Chen

在 2023/7/22 星期六 12:47, Masahiro Yamada 写道:
> If this affects only %{buildroot}, it should be enough to use a fixed
> string for _arch when it is undefined.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> scripts/package/mkspec | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/package/mkspec b/scripts/package/mkspec
> index 783e1997d94a..22b980cf3d00 100755
> --- a/scripts/package/mkspec
> +++ b/scripts/package/mkspec
> @@ -36,6 +36,8 @@ sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
> %define ARCH ${ARCH}
> %define KERNELRELEASE ${KERNELRELEASE}
>
> +# _arch is undefined if /usr/lib/rpm/platform/*/macros was not included.
> +%{!?_arch: %define _arch dummy}
> %{!?make: %define make make}
> %define makeflags %{?_smp_mflags} ARCH=%{ARCH}
>
> @@ -55,9 +57,6 @@ $S BuildRequires: bc binutils bison dwarves
> $S BuildRequires: (elfutils-libelf-devel or libelf-devel) flex
> $S BuildRequires: gcc make openssl openssl-devel perl python3 rsync
>
> - # $UTS_MACHINE as a fallback of _arch in case
> - # /usr/lib/rpm/platform/*/macros was not included.
> - %{!?_arch: %define _arch $UTS_MACHINE}
> %define __spec_install_post /usr/lib/rpm/brp-compress || :
> %define debug_package %{nil}
>

2023-09-14 04:59:17

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 11/19] kbuild: rpm-pkg: use a dummy string for _arch when undefined

On Tue, Sep 12, 2023 at 4:09 PM chenxiang (M) <[email protected]> wrote:
>
> Hi,
>
> I build the latest kernel (6.6-rc1) for arm64 platform on x86 server
> (with cross complile), and the complile command is as following:
>
> export
> PATH=$PATH:/opt/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/
> export ARCH=arm64
> export CROSS_COMPILE=aarch64-linux-gnu-
>
> make -j64 Image (ok)
>
> make binrpm-pkg -j64 (failed)
>
> But when complile binrpm-pkg, it is failed and the error info is as
> following:
>
> rpmbuild -bb kernel.spec --define='_topdir
> /home/chenxiang/kernel/mainline/linux-next/rpmbuild' --target
> aarch64-linux --build-in-place --noprep --define='_smp_mflags %{nil}'
> $(rpm -q rpm >/dev/null 2>&1 || echo --nodeps) --without devel
> rpmbuild: --build-in-place: unknown option


I cannot reproduce it on my build environment,
but the error message:

rpmbuild: --build-in-place: unknown option

describes the issue.


Which version of rpmbuild did you use?

Using a newer version fixes the issue?









--
Best Regards
Masahiro Yamada