Skip to content

Commit 440cf77

Browse files
Leo-Yannamhyung
authored andcommitted
perf: build: Setup PKG_CONFIG_LIBDIR for cross compilation
On recent Linux distros like Ubuntu Noble and Debian Bookworm, the 'pkg-config-aarch64-linux-gnu' package is missing. As a result, the aarch64-linux-gnu-pkg-config command is not available, which causes build failures. When a build passes the environment variables PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH, like a user uses make command or a build system (like Yocto, Buildroot, etc) prepares the variables and passes to the Perf's Makefile, the commit keeps these variables for package configuration. Otherwise, this commit sets the PKG_CONFIG_LIBDIR variable to use the Multiarch libs for the cross compilation. Signed-off-by: Leo Yan <[email protected]> Tested-by: Ian Rogers <[email protected]> Cc: [email protected] Cc: Thomas Richter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 4c17736 commit 440cf77

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

tools/build/feature/Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,30 @@ FILES= \
8282

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

85-
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
85+
# Some distros provide the command $(CROSS_COMPILE)pkg-config for
86+
# searching packges installed with Multiarch. Use it for cross
87+
# compilation if it is existed.
88+
ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
89+
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
90+
else
91+
PKG_CONFIG ?= pkg-config
92+
93+
# PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
94+
# for modified system root, are required for the cross compilation.
95+
# If these PKG_CONFIG environment variables are not set, Multiarch library
96+
# paths are used instead.
97+
ifdef CROSS_COMPILE
98+
ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
99+
CROSS_ARCH = $(shell $(CC) -dumpmachine)
100+
PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
101+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
102+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
103+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
104+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
105+
export PKG_CONFIG_LIBDIR
106+
endif
107+
endif
108+
endif
86109

87110
all: $(FILES)
88111

tools/perf/Makefile.perf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,32 @@ HOSTLD ?= ld
193193
HOSTAR ?= ar
194194
CLANG ?= clang
195195

196-
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
196+
# Some distros provide the command $(CROSS_COMPILE)pkg-config for
197+
# searching packges installed with Multiarch. Use it for cross
198+
# compilation if it is existed.
199+
ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
200+
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
201+
else
202+
PKG_CONFIG ?= pkg-config
203+
204+
# PKG_CONFIG_PATH or PKG_CONFIG_LIBDIR, alongside PKG_CONFIG_SYSROOT_DIR
205+
# for modified system root, is required for the cross compilation.
206+
# If these PKG_CONFIG environment variables are not set, Multiarch library
207+
# paths are used instead.
208+
ifdef CROSS_COMPILE
209+
ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
210+
CROSS_ARCH = $(shell $(CC) -dumpmachine)
211+
PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
212+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
213+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
214+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
215+
PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
216+
export PKG_CONFIG_LIBDIR
217+
$(warning Missing PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH and PKG_CONFIG_SYSROOT_DIR for cross compilation,)
218+
$(warning set PKG_CONFIG_LIBDIR for using Multiarch libs.)
219+
endif
220+
endif
221+
endif
197222

198223
RM = rm -f
199224
LN = ln -f

0 commit comments

Comments
 (0)