From 35fe817168fe0bdb78777d2707ba0189a4ce19bc Mon Sep 17 00:00:00 2001
From: MilhouseVH <milhouseVH.github@nmacleod.com>
Date: Fri, 5 May 2017 08:23:25 +0100
Subject: [PATCH] pkg-config: use sysroot path (see #1135)

---
 pkg.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pkg.c b/pkg.c
index f29ecc7..a7a1f2a 100644
--- a/pkg.c
+++ b/pkg.c
@@ -433,7 +433,7 @@ flag_list_to_string (GList *list)
     Flag *flag = tmp->data;
     char *tmpstr = flag->arg;
 
-    if (pcsysrootdir != NULL && flag->type & (CFLAGS_I | LIBS_L)) {
+    if (pcsysrootdir != NULL && flag->type & (CFLAGS_I | LIBS_L) && strncmp(tmpstr+2, pcsysrootdir, strlen(pcsysrootdir)) != 0) {
       /* Handle non-I Cflags like -isystem */
       if (flag->type & CFLAGS_I && strncmp (tmpstr, "-I", 2) != 0) {
         char *space = strchr (tmpstr, ' ');
@@ -449,6 +449,9 @@ flag_list_to_string (GList *list)
         g_string_append (str, pcsysrootdir);
         g_string_append (str, tmpstr+2);
       }
+    } else if (pcsysrootdir != NULL && strncmp(tmpstr, "/usr", 4) == 0 && strncmp(tmpstr, pcsysrootdir, strlen(pcsysrootdir)) != 0) {
+      g_string_append (str, pcsysrootdir);
+      g_string_append (str, tmpstr);
     } else {
       g_string_append (str, tmpstr);
     }
@@ -1060,6 +1063,8 @@ packages_get_var (GList      *pkgs,
         {
           if (str->len > 0)
             g_string_append_c (str, ' ');
+          if (pcsysrootdir != NULL && (strcmp(varname, "includedir") == 0 || strcmp(varname, "libdir") == 0) && strncmp(var, pcsysrootdir, strlen(pcsysrootdir)) != 0)
+            g_string_append (str, pcsysrootdir);
           g_string_append (str, var);
           g_free (var);
         }
-- 
2.7.4

