From a300be5877f35379bb569313eec901bda9c8d762 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sun, 30 Apr 2023 22:08:39 -0700
Subject: [PATCH] meson: Use PKG_CONFIG_SYSROOT_DIR when using pkg-config

OE cross-builds and absolute paths found by pkg-config points to
non-sysroot'ed locations which are not correct as they point into native
sysroot from build machine which is incorrect.

Upstream-Status: Inappropriate [OE-specific]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meson.build | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/meson.build b/meson.build
index d563dd08..9b72aeb4 100644
--- a/meson.build
+++ b/meson.build
@@ -38,6 +38,9 @@ metadata_dir = meson.project_source_root() / 'bindings'/ 'metadata'
 po_dir = meson.project_source_root() / 'po'
 vapi_dir = meson.project_source_root() / 'bindings' / 'vapi'
 
+# pkg-config sysroot location
+pkgconf_sysroot = run_command('python3', '-c', 'import os; print(os.environ.get("PKG_CONFIG_SYSROOT_DIR"))').stdout().strip()
+
 # Compiler configuration
 add_project_arguments([
     # Make sure Meson can find custom VAPIs
@@ -120,7 +123,7 @@ icu_uc = declare_dependency(
 if libunwind_dep.found()
   # We need to add native lib to the search path for these so Flatpak
   # builds can find it.
-  unwind_lib = libunwind_dep.get_variable(pkgconfig: 'libdir')
+  unwind_lib = pkgconf_sysroot + libunwind_dep.get_variable(pkgconfig: 'libdir')
   libunwind = declare_dependency(
      dependencies: [
        valac.find_library('libunwind', dirs: [vapi_dir, unwind_lib]),
@@ -207,8 +210,7 @@ vala_unit_proj = subproject(
 vala_unit_dep = vala_unit_proj.get_variable('vala_unit_dep')
 
 # Language detection
-
-iso_codes_dir = iso_codes.get_variable(pkgconfig: 'prefix')/'share'/'xml'/'iso-codes'
+iso_codes_dir = pkgconf_sysroot + iso_codes.get_variable(pkgconfig: 'prefix')/'share'/'xml'/'iso-codes'
 
 iso_639_xml = get_option('iso_639_xml')
 if iso_639_xml == ''
-- 
2.40.1

