[PATCH 3/3] sandbox: Use pkg-config to detect and config sdl2

Jiaxun Yang jiaxun.yang at flygoat.com
Sat May 18 00:09:29 CEST 2024


sdl2-config is not cross compile friendly, it can only detect
and config stuff from build host.

Use pkg-config instead, which is a generic way to config libraries
on any sane system & cross toolchain should have it ready.

The output of pkg-config practically have no difference with
sdl2-config.

Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
---
 Makefile                     | 3 ++-
 arch/sandbox/Kconfig         | 2 +-
 arch/sandbox/config.mk       | 5 ++---
 doc/arch/sandbox/sandbox.rst | 6 ------
 4 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 596f6458e6b2..5e397e107a80 100644
--- a/Makefile
+++ b/Makefile
@@ -383,6 +383,7 @@ LDR		= $(CROSS_COMPILE)ldr
 STRIP		= $(CROSS_COMPILE)strip
 OBJCOPY		= $(CROSS_COMPILE)objcopy
 OBJDUMP		= $(CROSS_COMPILE)objdump
+PKG_CONFIG	= $(CROSS_COMPILE)pkg-config
 LEX		= flex
 YACC		= bison
 AWK		= awk
@@ -439,7 +440,7 @@ UBOOTVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SU
 
 export VERSION PATCHLEVEL SUBLEVEL UBOOTRELEASE UBOOTVERSION
 export ARCH CPU BOARD VENDOR SOC CPUDIR BOARDDIR
-export CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
+export CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC PKG_CONFIG
 export CPP AR NM LDR STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
 export MAKE LEX YACC AWK PERL PYTHON PYTHON2 PYTHON3
 export HOSTCXX KBUILD_HOSTCXXFLAGS CHECK CHECKFLAGS DTC DTC_FLAGS
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index c3954e33aceb..5af074e3e700 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -71,7 +71,7 @@ config HOST_ARCH_UNKNOWN
 		 !HOST_ARCH_RISCV32 && !HOST_ARCH_RISCV64
 
 config HOST_HAS_SDL
-	def_bool $(success,sdl2-config --version)
+	def_bool $(success,$(PKG_CONFIG) sdl2)
 
 config SANDBOX_SDL
 	bool "Enable SDL2 support in sandbox"
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 6b1da993ba4e..94c11fd78918 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -4,13 +4,12 @@
 PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE
 PLATFORM_CPPFLAGS += -fPIC -ffunction-sections -fdata-sections
 PLATFORM_LIBS += -lrt
-SDL_CONFIG ?= sdl2-config
 
 # Define this to avoid linking with SDL, which requires SDL libraries
 # This can solve 'sdl-config: Command not found' errors
 ifeq ($(CONFIG_SANDBOX_SDL),y)
-PLATFORM_LIBS += $(shell $(SDL_CONFIG) --libs)
-PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
+PLATFORM_LIBS += $(shell $(PKG_CONFIG) sdl2 --libs)
+PLATFORM_CPPFLAGS += $(shell $(PKG_CONFIG) sdl2 --cflags)
 endif
 
 SANITIZERS :=
diff --git a/doc/arch/sandbox/sandbox.rst b/doc/arch/sandbox/sandbox.rst
index 5f8db126657f..9ad1b654989c 100644
--- a/doc/arch/sandbox/sandbox.rst
+++ b/doc/arch/sandbox/sandbox.rst
@@ -526,12 +526,6 @@ For debugging with GDB or LLDB, it is preferable to reduce the compiler
 optimization level (CONFIG_CC_OPTIMIZE_FOR_DEBUG=y) and to disable Link Time
 Optimization (CONFIG_LTO=n).
 
-SDL_CONFIG
-----------
-
-If sdl-config is on a different path from the default, set the SDL_CONFIG
-environment variable to the correct pathname before building U-Boot.
-
 
 Using valgrind / memcheck
 -------------------------

-- 
2.34.1



More information about the U-Boot mailing list