Skip to contentSkip to conversation

kbuild: pacman-pkg: move common commands to a separate function

PATCH In review Masahiro Yamada 4 participants 9 messages Aug 16, 2024 – Aug 23, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kbuild: pacman-pkg: move common commands to a separate function

All build and package functions share the following commands:

  export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
  cd "${objtree}"

Factor out the common code.

---

 scripts/package/PKGBUILD | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/package/PKGBUILD +10 -7
index fbd7eb10a52c..e2d9c2601ca9 100644
@@ -36,11 +36,15 @@ makedepends=(
 )
 options=(!debug !strip !buildflags !makeflags)
 
-build() {
+_prologue() {
 	# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
 	# Bypass this override with a custom variable.
 	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
 	cd "${objtree}"
+}
+
+build() {
+	_prologue
 
 	${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
 }
@@ -48,10 +52,10 @@ build() {
 _package() {
 	pkgdesc="The ${pkgdesc} kernel and modules"
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
 	local modulesdir="${pkgdir}/usr/${MODLIB}"
 
+	_prologue
+
 	echo "Installing boot image..."
 	# systemd expects to find the kernel here to allow hibernation
 	# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
@@ -76,10 +80,10 @@ _package() {
 _package-headers() {
 	pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
 	local builddir="${pkgdir}/usr/${MODLIB}/build"
 
+	_prologue
+
 	if grep -q CONFIG_MODULES=y include/config/auto.conf; then
 		echo "Installing build files..."
 		"${srctree}/scripts/package/install-extmod-build" "${builddir}"
@@ -100,8 +104,7 @@ _package-api-headers() {
 	provides=(linux-api-headers)
 	conflicts=(linux-api-headers)
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
+	_prologue
 
 	${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
 }
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 kbuild: pacman-pkg: do not override objtree

objtree is defined and exported by the top-level Makefile. I prefer not to override it.

There is no need to pass the absolute pass of objtree. PKGBUILD can detect it by itself.

---

 scripts/Makefile.package | 3 +--
 scripts/package/PKGBUILD | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
scripts/Makefile.package +1 -2
index 4a80584ec771..2c261a0d42b0 100644
@@ -147,8 +147,7 @@ snap-pkg:
 PHONY += pacman-pkg
 pacman-pkg:
 	@ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
-	+objtree="$(realpath $(objtree))" \
-		BUILDDIR="$(realpath $(objtree))/pacman" \
+	BUILDDIR="$(realpath $(objtree))/pacman" \
 		CARCH="$(UTS_MACHINE)" \
 		KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
 		KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
scripts/package/PKGBUILD +3 -1
index e2d9c2601ca9..839cd5e634d2 100644
@@ -40,7 +40,9 @@ _prologue() {
 	# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
 	# Bypass this override with a custom variable.
 	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
+
+	# Kbuild works in the output directory, where this PKGBUILD is located.
+	cd "$(dirname "${BASH_SOURCE[0]}")"
 }
 
 build() {
Signature · 1 line
2.43.0
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] kbuild: pacman-pkg: do not override objtree

Aug 16, 2024 16:18:56 Masahiro Yamada <[email protected]>:

Quoted 4 lines

objtree is defined and exported by the top-level Makefile. I prefer not to override it.

There is no need to pass the absolute pass of objtree. PKGBUILD can

s/pass/path/g

Quoted 3 lines

detect it by itself.

Quoted 37 lines

---

scripts/Makefile.package | 3 +--
scripts/package/PKGBUILD | 4 +++-

2 files changed, 4 insertions(+), 3 deletions(-)
scripts/Makefile.package +0 -0
index 4a80584ec771..2c261a0d42b0 100644
@@ -147,8 +147,7 @@ snap-pkg:

PHONY += pacman-pkg
pacman-pkg:
    @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD -   +objtree="$(realpath $(objtree))" \
-       BUILDDIR="$(realpath $(objtree))/pacman" \
+   BUILDDIR="$(realpath $(objtree))/pacman" \
        CARCH="$(UTS_MACHINE)" \
        KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
        KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \

scripts/package/PKGBUILD +0 -0
index e2d9c2601ca9..839cd5e634d2 100644
@@ -40,7 +40,9 @@ _prologue() {
     # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
     # Bypass this override with a custom variable.

    export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-   cd "${objtree}"
+
+   # Kbuild works in the output directory, where this PKGBUILD is located. +   cd "$(dirname "${BASH_SOURCE[0]}")"
}

build() {
--
2.43.0

maintainer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] kbuild: pacman-pkg: do not override objtree

In reply to Masahiro Yamada
Quoted 7 lines · Masahiro Yamada

objtree is defined and exported by the top-level Makefile. I prefer not to override it.

There is no need to pass the absolute pass of objtree. PKGBUILD can detect it by itself.

Quoted 38 lines

---

 scripts/Makefile.package | 3 +--
 scripts/package/PKGBUILD | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
scripts/Makefile.package +1 -2
index 4a80584ec771..2c261a0d42b0 100644
@@ -147,8 +147,7 @@ snap-pkg:
 PHONY += pacman-pkg
 pacman-pkg:
 	@ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
-	+objtree="$(realpath $(objtree))" \
-		BUILDDIR="$(realpath $(objtree))/pacman" \
+	BUILDDIR="$(realpath $(objtree))/pacman" \
 		CARCH="$(UTS_MACHINE)" \
 		KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
 		KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
scripts/package/PKGBUILD +3 -1
index e2d9c2601ca9..839cd5e634d2 100644
@@ -40,7 +40,9 @@ _prologue() {
 	# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
 	# Bypass this override with a custom variable.
 	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
+
+	# Kbuild works in the output directory, where this PKGBUILD is located.
+	cd "$(dirname "${BASH_SOURCE[0]}")"
 }
 
 build() {
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] kbuild: pacman-pkg: do not override objtree

In reply to Masahiro Yamada
Quoted 5 lines · Masahiro Yamada

objtree is defined and exported by the top-level Makefile. I prefer not to override it.

There is no need to pass the absolute pass of objtree. PKGBUILD can detect it by itself.

Thomas already spotted the typo in the sentence above :)

Quoted 2 lines

---

#5 lore raw

Re: [PATCH 2/2] kbuild: pacman-pkg: do not override objtree

In reply to Masahiro Yamada
Quoted 19 lines · Masahiro Yamada

objtree is defined and exported by the top-level Makefile. I prefer not to override it.

There is no need to pass the absolute pass of objtree. PKGBUILD can detect it by itself.

---

 scripts/Makefile.package | 3 +--
 scripts/package/PKGBUILD | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
scripts/Makefile.package +0 -0
index 4a80584ec771..2c261a0d42b0 100644

scripts/Makefile.package snap-pkg: · line 150

Quoted 6 lines
scripts/Makefile.package +1 -2
@@ -147,8 +147,7 @@ snap-pkg:
 PHONY += pacman-pkg
 pacman-pkg:
        @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
-       +objtree="$(realpath $(objtree))" \
-               BUILDDIR="$(realpath $(objtree))/pacman" \
+       BUILDDIR="$(realpath $(objtree))/pacman" \

I restored the '+' prefix
when I applied this.

Quoted 21 lines
scripts/Makefile.package +0 -0
                CARCH="$(UTS_MACHINE)" \
                KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
                KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
scripts/package/PKGBUILD +3 -2
index e2d9c2601ca9..839cd5e634d2 100644
@@ -40,7 +40,9 @@ _prologue() {
        # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
        # Bypass this override with a custom variable.
        export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-       cd "${objtree}"
+
+       # Kbuild works in the output directory, where this PKGBUILD is located.
+       cd "$(dirname "${BASH_SOURCE[0]}")"
 }
 
 build() {
--

2.43.0

Signature · 2 lines
Best Regards
Masahiro Yamada
maintainer Acked-by on v1 1/2
#6 lore raw
In reply to Masahiro Yamada

Aug 16, 2024 16:18:53 Masahiro Yamada <[email protected]>:

Quoted 8 lines

All build and package functions share the following commands:

  export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
  cd "${objtree}"

Factor out the common code.

Quoted 64 lines

---

scripts/package/PKGBUILD | 17 ++++++++++-------

1 file changed, 10 insertions(+), 7 deletions(-)
scripts/package/PKGBUILD +1 -1
index fbd7eb10a52c..e2d9c2601ca9 100644
@@ -36,11 +36,15 @@ makedepends=(
 )
 options=(!debug !strip !buildflags !makeflags)
 
-build() {
+_prologue() {
     # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
     # Bypass this override with a custom variable.

    export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
    cd "${objtree}"

scripts/package/PKGBUILD +4 -0
+}
+
+build() {
+   _prologue

    ${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}" }

scripts/package/PKGBUILD +0 -0
@@ -48,10 +52,10 @@ build() {
 _package() {

    pkgdesc="The ${pkgdesc} kernel and modules"

-   export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-   cd "${objtree}"
    local modulesdir="${pkgdir}/usr/${MODLIB}"

+   _prologue
+
    echo "Installing boot image..."

    # systemd expects to find the kernel here to allow hibernation
    # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
scripts/package/PKGBUILD +0 -0
@@ -76,10 +80,10 @@ _package() {
 _package-headers() {

    pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"

-   export MAKEFLAGS="${KBUILD_MAKEFLAGS}" -   cd "${objtree}"
    local builddir="${pkgdir}/usr/${MODLIB}/build"

+   _prologue
+
    if grep -q CONFIG_MODULES=y include/config/auto.conf; then echo "Installing build files..." "${srctree}/scripts/package/install-extmod-build" "${builddir}"

scripts/package/PKGBUILD +1 -2
@@ -100,8 +104,7 @@ _package-api-headers() {
     provides=(linux-api-headers)
     conflicts=(linux-api-headers)
 
-   export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-   cd "${objtree}"
+   _prologue
 

    ${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr" }
--
2.43.0

maintainer Reviewed-by on v1 1/2
#7 lore raw
In reply to Masahiro Yamada
Quoted 8 lines · Masahiro Yamada

All build and package functions share the following commands:

  export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
  cd "${objtree}"

Factor out the common code.

Quoted 65 lines

---

 scripts/package/PKGBUILD | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
scripts/package/PKGBUILD +10 -7
index fbd7eb10a52c..e2d9c2601ca9 100644
@@ -36,11 +36,15 @@ makedepends=(
 )
 options=(!debug !strip !buildflags !makeflags)
 
-build() {
+_prologue() {
 	# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
 	# Bypass this override with a custom variable.
 	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
 	cd "${objtree}"
+}
+
+build() {
+	_prologue
 
 	${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
 }
@@ -48,10 +52,10 @@ build() {
 _package() {
 	pkgdesc="The ${pkgdesc} kernel and modules"
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
 	local modulesdir="${pkgdir}/usr/${MODLIB}"
 
+	_prologue
+
 	echo "Installing boot image..."
 	# systemd expects to find the kernel here to allow hibernation
 	# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
@@ -76,10 +80,10 @@ _package() {
 _package-headers() {
 	pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
 	local builddir="${pkgdir}/usr/${MODLIB}/build"
 
+	_prologue
+
 	if grep -q CONFIG_MODULES=y include/config/auto.conf; then
 		echo "Installing build files..."
 		"${srctree}/scripts/package/install-extmod-build" "${builddir}"
@@ -100,8 +104,7 @@ _package-api-headers() {
 	provides=(linux-api-headers)
 	conflicts=(linux-api-headers)
 
-	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
-	cd "${objtree}"
+	_prologue
 
 	${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
 }
Signature · 1 line
2.43.0