Linux Documentation
 help / color / mirror / Atom feed
* [PATCH] kbuild: let the environment set HOSTPKG_CONFIG
@ 2026-08-05  5:54 Trevor Woerner
  2026-08-08  5:31 ` Nicolas Schier
  0 siblings, 1 reply; 2+ messages in thread
From: Trevor Woerner @ 2026-08-05  5:54 UTC (permalink / raw)
  To: linux-kernel, Nathan Chancellor, Nicolas Schier, Jonathan Corbet,
	Shuah Khan, Gang Yan, David Disseldorp, Miguel Ojeda, Gary Guo,
	Thomas Weißschuh, Luis Augenstein, Masahiro Yamada,
	Andrew Jones

HOSTPKG_CONFIG was added so that "tooling that builds the kernel" could
choose which pkg-config the host tools ask about their dependencies, but
it is assigned with '=', so only a make command line assignment takes
effect. Exporting it does nothing, silently.

That is surprising, because the other inputs to host program builds do
honour the environment: HOSTCFLAGS, HOSTCXXFLAGS, HOSTLDFLAGS and
HOSTLDLIBS are all read from it and documented in kbuild.rst as such.

It also matters. A cross development environment sets
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH so that pkg-config answers
for the target rather than the build machine. Those settings are correct
for everything that will run on the target and wrong for a program that
has to run on the build machine. objtool asks pkg-config where libelf is,
gets the target's include directory, and compiles a host tool against
the target's C library headers. Because the directory arrives as -I it
is not treated as a system header directory, -Wno-system-headers no
longer covers it, and the build stops on warnings that would otherwise
be suppressed:

  usr/include/sys/cdefs.h:486: error: "__attribute_const__" redefined [-Werror]
  tools/include/linux/compiler.h:123: note: previous definition
  usr/include/stdio.h:449: error: redundant redeclaration of 'fscanf'

An environment that knows it is cross building can then say

  export HOSTPKG_CONFIG="env -u PKG_CONFIG_SYSROOT_DIR \
                             -u PKG_CONFIG_PATH pkg-config"

once, in the shell it hands to the user, instead of every make command
line growing an override. Build systems that already pass it on the
command line are unaffected.

Assisted-by: Codex:claude-opus-5
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
 Documentation/kbuild/kbuild.rst | 5 +++++
 Makefile                        | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index 5a9013bacfb7..6d7de86764be 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -110,6 +110,11 @@ HOSTLDLIBS
 ----------
 Additional libraries to link against when building host programs.
 
+HOSTPKG_CONFIG
+--------------
+The pkg-config to use when building host programs. Set this when cross
+building, where the default would otherwise answer for the target.
+
 .. _userkbuildflags:
 
 USERCFLAGS
diff --git a/Makefile b/Makefile
index 902f3f3d54b7..ba64518d5309 100644
--- a/Makefile
+++ b/Makefile
@@ -461,7 +461,7 @@ HOSTCC	= gcc
 HOSTCXX	= g++
 endif
 HOSTRUSTC = rustc
-HOSTPKG_CONFIG	= pkg-config
+HOSTPKG_CONFIG	?= pkg-config
 
 # the KERNELDOC macro needs to be exported, as scripts/Makefile.build
 # has a logic to call it
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-08  5:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05  5:54 [PATCH] kbuild: let the environment set HOSTPKG_CONFIG Trevor Woerner
2026-08-08  5:31 ` Nicolas Schier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox