Re: [PATCH v3 1/7] perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation

From: Leo Yan
Date: Fri Jul 12 2024 - 06:13:38 EST


Hi Namhyung,

On 7/12/24 05:52, Namhyung Kim wrote:

[...]

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index ed54cef450f5..65fd2b2cfacb 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -82,7 +82,31 @@ FILES= \

FILES := $(addprefix $(OUTPUT),$(FILES))

-PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+# Some distros provide the command $(CROSS_COMPILE)pkg-config for
+# searching packges installed with Multiarch. Use it for cross
+# compilation if it is existed.
+ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
+ PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+else
+ PKG_CONFIG ?= pkg-config
+
+ # PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR is required for the cross

And PKG_CONFIG_SYSROOT_DIR too.

I will refine the comment as:

# PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
# for modified system root, is required for the cross compilation.
# If these PKG_CONFIG environment variables are not set, Multiarch library
# paths are used instead.

+ # compilation. If both is not set, try to set the lib paths installed
+ # by multiarch.
+ ifdef CROSS_COMPILE
+ ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
+ CROSS_ARCH = $(shell $(CC) -dumpmachine)
+ PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
+ PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
+ export PKG_CONFIG_LIBDIR
+ $(warning Missing PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH for cross compilation,)

Probably you need to add it here too.

Will do.

+ $(warning set PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR) for building with Multiarch libs.)

I guess the message would get too long. Maybe it's ok to hide the
actual value..

Will do.

In addition, I think this message will be displayed multiple times -
once here and later in Makefile.perf. Maybe we can show it once in
the latter only?

Will polish for this.

Thanks,
Leo