diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2016-09-23 20:05:01 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2017-03-20 07:13:23 -0500 |
commit | d5d80748936c1ddb2e32bc713f2ed51dc6f753ea (patch) | |
tree | 393ef535432227cc69aedd6c33e7d45f490f2b5a | |
parent | 7707d2ff337fa4bc9e7273d9eead6641a7a49208 (diff) | |
download | pkg-config-d5d80748936c1ddb2e32bc713f2ed51dc6f753ea.tar.gz |
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
-rwxr-xr-x | check/check-special-flags | 2 | ||||
-rwxr-xr-x | check/check-sysroot | 2 | ||||
-rw-r--r-- | parse.c | 4 | ||||
-rw-r--r-- | 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" @@ -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++; @@ -434,10 +434,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); } @@ -772,8 +783,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))) |