From 517dbcf8915c5d4f10a2e72b37bc436b9fa80edb Mon Sep 17 00:00:00 2001 Message-Id: <517dbcf8915c5d4f10a2e72b37bc436b9fa80edb.1474690202.git.dbn.lists@gmail.com> From: Dan Nicholson Date: Fri, 23 Sep 2016 20:05:01 -0700 Subject: [PATCH] Respect sysroot for -isystem and -idirafter Treat -isystem and -idirafter as -I Cflags since they control the compiler search path. Adjust the sysroot handling so that the arguments to these options have the sysroot prefixed. However, leave them out of the system Cflags handling since these directives are explicitly trying to adjust the compiler's system header search behavior. The special-flags test case output needs adjustment since all the flags are now considered -I flags and come out in the order specified in the pc file. https://bugs.freedesktop.org/show_bug.cgi?id=97337 --- check/check-special-flags | 2 +- check/check-sysroot | 2 +- parse.c | 4 +++- pkg.c | 27 +++++++++++++++++++++------ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/check/check-special-flags b/check/check-special-flags index 35b56e6..78e6341 100755 --- a/check/check-special-flags +++ b/check/check-special-flags @@ -4,7 +4,7 @@ set -e . ${srcdir}/common -RESULT="-g -isystem /system1 -idirafter /after1 -ffoo -idirafter /after2 -isystem /system2 -I/foo -I/bar" +RESULT="-g -ffoo -I/foo -isystem /system1 -idirafter /after1 -I/bar -idirafter /after2 -isystem /system2" run_test --cflags special-flags RESULT="-L/foo -L/bar -framework Foo -lsimple -framework Bar -Wl,-framework -Wl,Baz" diff --git a/check/check-sysroot b/check/check-sysroot index 43d0b5b..7da415f 100755 --- a/check/check-sysroot +++ b/check/check-sysroot @@ -31,7 +31,7 @@ run_test --cflags public-dep RESULT="-L$root/sysroot/public-dep/lib -lpublic-dep" run_test --libs public-dep -RESULT="-g -isystem /system1 -idirafter /after1 -ffoo -idirafter /after2 -isystem /system2 -I$root/sysroot/foo -I$root/sysroot/bar" +RESULT="-g -ffoo -I$root/sysroot/foo -isystem $root/sysroot/system1 -idirafter $root/sysroot/after1 -I$root/sysroot/bar -idirafter $root/sysroot/after2 -isystem $root/sysroot/system2" run_test --cflags special-flags RESULT="-L$root/sysroot/foo -L$root/sysroot/bar -framework Foo -lsimple -framework Bar -Wl,-framework -Wl,Baz" diff --git a/parse.c b/parse.c index 229d6f2..7bb666d 100644 --- a/parse.c +++ b/parse.c @@ -861,7 +861,9 @@ parse_cflags (Package *pkg, const char *str, const char *path) tmp = trim_string (argv[i+1]); option = strdup_escape_shell (tmp); - flag->type = CFLAGS_OTHER; + + /* These are -I flags since they control the search path */ + flag->type = CFLAGS_I; flag->arg = g_strconcat (arg, " ", option, NULL); pkg->cflags = g_list_prepend (pkg->cflags, flag); i++; diff --git a/pkg.c b/pkg.c index 5aa4380..5306336 100644 --- a/pkg.c +++ b/pkg.c @@ -469,10 +469,21 @@ flag_list_to_string (GList *list) char *tmpstr = flag->arg; if (pcsysrootdir != NULL && flag->type & (CFLAGS_I | LIBS_L)) { - g_string_append_c (str, '-'); - g_string_append_c (str, tmpstr[1]); - g_string_append (str, pcsysrootdir); - g_string_append (str, tmpstr+2); + /* Handle non-I Cflags like -isystem */ + if (flag->type & CFLAGS_I && strncmp (tmpstr, "-I", 2) != 0) { + char *space = strchr (tmpstr, ' '); + + /* Ensure this has a separate arg */ + g_assert (space != NULL && space[1] != '\0'); + g_string_append_len (str, tmpstr, space - tmpstr + 1); + g_string_append (str, pcsysrootdir); + g_string_append (str, space + 1); + } else { + g_string_append_c (str, '-'); + g_string_append_c (str, tmpstr[1]); + g_string_append (str, pcsysrootdir); + g_string_append (str, tmpstr+2); + } } else { g_string_append (str, tmpstr); } @@ -801,8 +812,12 @@ verify_package (Package *pkg) if (!(flag->type & CFLAGS_I)) continue; - /* we put things in canonical -I/usr/include (vs. -I /usr/include) format, - * but if someone changes it later we may as well be robust + /* Handle the system cflags. We put things in canonical + * -I/usr/include (vs. -I /usr/include) format, but if someone + * changes it later we may as well be robust. + * + * Note that the -i* flags are left out of this handling since + * they're intended to adjust the system cflags behavior. */ if (((strncmp (flag->arg, "-I", 2) == 0) && (offset = 2))|| ((strncmp (flag->arg, "-I ", 3) == 0) && (offset = 3))) -- 2.4.11