]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes/pkgconfig: rationalise variable usage
authorRoss Burton <ross.burton@arm.com>
Thu, 26 Feb 2026 14:31:10 +0000 (14:31 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 5 Mar 2026 17:36:54 +0000 (17:36 +0000)
Our PKG_CONFIG_* variables were a bit of a mess.

First, PKG_CONFIG_DIR is not used by either pkg-config or pkgconf.  It's
set to (approximately) ${libdir}/pkgconfig but we also want to search
${datadir}/pkgconfig so it isn't actually useful as an intermediate
variable.

Remove PKG_CONFIG_DIR and replace with the neatest expression for the
value we want: ${STAGING_LIBDIR}/pkgconfig.

Second, PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR shouldn't be set to the
same paths. The semantics of these variables is that PKG_CONFIG_PATH is
searched first, followed by either PKG_CONFIG_LIBDIR or the default paths
compiled into the pkg-config binary.

Currently we set PKG_CONFIG_PATH to (approx.) ${libdir}:${datadir} and
PKG_CONFIG_LIBDIR to ${libdir}, so we search libdir twice.

Also the default paths embedded in the binary will be incorrect as they
point to pkgconfig-native's sysroot, so we absolutely need to set
PKG_CONFIG_LIBDIR.

Instead, set PKG_CONFIG_LIBDIR to ${libdir}:${datadir} so that the
default search path is correct. We can then leave PKG_CONFIG_PATH empty,
if a recipe has specific needs it can set that but normally it is not
needed anymore.

Then bubble these changes out to the few places where the variables are
used directly:

- Kernel/kconfig interaction where 'pkg-config' needs to read the
native files, not target.

- The class classes (native, etc) which redefine the values.  However,
as the values are defined in terms of sysroot variables, we can
typically remove assignments from those classes as they are redundant.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/cml1.bbclass
meta/classes-recipe/cross-canadian.bbclass
meta/classes-recipe/cross.bbclass
meta/classes-recipe/kernel.bbclass
meta/classes-recipe/native.bbclass
meta/classes-recipe/nativesdk.bbclass
meta/classes-recipe/pkgconfig.bbclass
meta/recipes-kernel/linux/linux-yocto.inc

index 3c2b4da4aff984dffbff29109817b692a6ab3409..ac65eec4bff84bcc5bcbca231a50006df84f931c 100644 (file)
@@ -51,12 +51,11 @@ python do_menuconfig() {
         mtime = 0
 
     # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-    d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
-    d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
-    d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
+    d.setVar("PKG_CONFIG_PATH", "")
+    d.setVar("PKG_CONFIG_LIBDIR", "${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig")
     d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
     # ensure that environment variables are overwritten with this tasks 'd' values
-    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
+    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
 
     oe_terminal("sh -c 'make %s; if [ $? -ne 0 ]; then echo \"Command failed.\"; printf \"Press any key to continue... \"; read r; fi'" % d.getVar('KCONFIG_CONFIG_COMMAND'),
                 d.getVar('PN') + ' Configuration', d)
index 059d9aa95f57dd77a0ab5172c4c15c13ed3bc43e..6d3d2f762315518fcaf703d01713c848194f5032 100644 (file)
@@ -161,8 +161,7 @@ libexecdir = "${exec_prefix}/libexec/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}
 
 FILES:${PN} = "${prefix}"
 
-export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
+PKG_CONFIG_LIBDIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig:${STAGING_DIR_HOST}${exec_prefix}/share/pkgconfig"
 
 do_populate_sysroot[stamp-extra-info] = ""
 do_packagedata[stamp-extra-info] = ""
index 574ce6988d2fe86135f277e6be52cbbc75a8a623..82a49dc8f5c08722aae611a5c2912a59c0fe562b 100644 (file)
@@ -33,8 +33,8 @@ PACKAGE_ARCH = "${BUILD_ARCH}"
 
 MULTIMACH_TARGET_SYS = "${BUILD_ARCH}${BUILD_VENDOR}-${BUILD_OS}"
 
-export PKG_CONFIG_DIR = "${exec_prefix}/lib/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = ""
+PKG_CONFIG_LIBDIR = "${exec_prefix}/lib/pkgconfig:${exec_prefix}/share/pkgconfig"
+PKG_CONFIG_SYSROOT_DIR = ""
 
 TARGET_CPPFLAGS = ""
 TARGET_CFLAGS = ""
index 22568d6e9cb4b7974c1d2ac9fec27d3988b932d4..6f4d84c286aa1359f6b20f6051bc4b59e5ea2803 100644 (file)
@@ -358,9 +358,7 @@ kernel_do_compile() {
        unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 
        # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-       export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
-       export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
-       export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
+       export PKG_CONFIG_LIBDIR="${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig"
        export PKG_CONFIG_SYSROOT_DIR=""
 
        if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
@@ -414,9 +412,7 @@ do_compile_kernelmodules() {
        unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 
        # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-       export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
-       export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
-       export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
+       export PKG_CONFIG_LIBDIR="${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig"
        export PKG_CONFIG_SYSROOT_DIR=""
 
        if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
index 65b5b97c690f3babc436feabff894d786986f347..5aa9c8e4145e0df39e3b1a675196b8b0bc4f045b 100644 (file)
@@ -98,7 +98,6 @@ do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN
 # Since we actually install these into situ there is no staging prefix
 STAGING_DIR_HOST = ""
 STAGING_DIR_TARGET = ""
-PKG_CONFIG_DIR = "${libdir}/pkgconfig"
 
 EXTRA_NATIVE_PKGCONFIG_PATH ?= ""
 PKG_CONFIG_PATH .= "${EXTRA_NATIVE_PKGCONFIG_PATH}"
index 4404a18856a2f261996aeda9b7ab1c93566da990..5adb7515bf14cdc2c34792b5664533e16bc158b0 100644 (file)
@@ -73,9 +73,6 @@ exec_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
 baselib = "lib"
 sbindir = "${bindir}"
 
-export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${libdir}/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
-
 python nativesdk_virtclass_handler () {
     pn = e.data.getVar("PN")
     if not (pn.endswith("-nativesdk") or pn.startswith("nativesdk-")):
index 98b6342013594f178d9120fa5b6aeb16435ed2be..c0d91393b3693656e906cddbafa1f65f6ee01091 100644 (file)
@@ -6,10 +6,11 @@
 
 DEPENDS:prepend = "pkgconfig-native "
 
-export PKG_CONFIG_DIR ?= "${STAGING_DIR_HOST}${libdir}/pkgconfig"
-export PKG_CONFIG_PATH ?= "${PKG_CONFIG_DIR}:${STAGING_DATADIR}/pkgconfig"
-export PKG_CONFIG_LIBDIR ?= "${PKG_CONFIG_DIR}"
+export PKG_CONFIG_PATH ?= ""
+export PKG_CONFIG_LIBDIR ?= "${STAGING_LIBDIR}/pkgconfig:${STAGING_DATADIR}/pkgconfig"
+
 export PKG_CONFIG_SYSROOT_DIR ?= "${STAGING_DIR_HOST}"
 export PKG_CONFIG_DISABLE_UNINSTALLED ?= "yes"
+
 export PKG_CONFIG_SYSTEM_LIBRARY_PATH ?= "${base_libdir}:${libdir}"
 export PKG_CONFIG_SYSTEM_INCLUDE_PATH ?= "${includedir}"
index 4d0a726bb65efd9c35a922621b2d4d94aab8fe0b..d57c1aae25e3b07a3efb01df1fb51a7df1202787 100644 (file)
@@ -89,9 +89,8 @@ EXTRA_OEMAKE += '${@bb.utils.contains("KERNEL_DEBUG", "True", "", "PAHOLE=false"
 
 do_devshell:prepend() {
     # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-    d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
-    d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
-    d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
+    d.setVar("PKG_CONFIG_PATH", "")
+    d.setVar("PKG_CONFIG_LIBDIR", "${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig")
     d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
-    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
+    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
 }