From a6991f0abaecf97dd8c3ddc70c7fc153524fb643 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Thu, 19 Dec 2019 17:44:52 +0100 Subject: [PATCH] pkg-config: add support for multiple sysroots --- config/functions | 3 + ...01-Add-support-for-multiple-sysroots.patch | 256 ++++++++++++++++++ .../pkg-config-0001-use-sysroot-path.patch | 44 --- tools/pkgcheck | 2 +- 4 files changed, 260 insertions(+), 45 deletions(-) create mode 100644 packages/devel/pkg-config/patches/0001-Add-support-for-multiple-sysroots.patch delete mode 100644 packages/devel/pkg-config/patches/pkg-config-0001-use-sysroot-path.patch diff --git a/config/functions b/config/functions index 2db7df64f8..16e78d7bcc 100644 --- a/config/functions +++ b/config/functions @@ -170,6 +170,7 @@ setup_pkg_config_target() { export PKG_CONFIG="$TOOLCHAIN/bin/pkg-config" export PKG_CONFIG_PATH="" export PKG_CONFIG_LIBDIR="$SYSROOT_PREFIX/usr/lib/pkgconfig:$SYSROOT_PREFIX/usr/share/pkgconfig" + export PKG_CONFIG_SYSROOT_BASE="$BUILD" export PKG_CONFIG_SYSROOT_DIR="$SYSROOT_PREFIX" export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 @@ -179,6 +180,7 @@ setup_pkg_config_host() { export PKG_CONFIG="$TOOLCHAIN/bin/pkg-config" export PKG_CONFIG_PATH="" export PKG_CONFIG_LIBDIR="$TOOLCHAIN/lib/pkgconfig:$TOOLCHAIN/share/pkgconfig" + export PKG_CONFIG_SYSROOT_BASE="" export PKG_CONFIG_SYSROOT_DIR="" unset PKG_CONFIG_ALLOW_SYSTEM_CFLAGS unset PKG_CONFIG_ALLOW_SYSTEM_LIBS @@ -481,6 +483,7 @@ reset_pkg_vars() { if [ "${var}" = "PKG_CONFIG" ] || \ [ "${var}" = "PKG_CONFIG_PATH" ] || \ [ "${var}" = "PKG_CONFIG_LIBDIR" ] || \ + [ "${var}" = "PKG_CONFIG_SYSROOT_BASE" ] || \ [ "${var}" = "PKG_CONFIG_SYSROOT_DIR" ] || \ [ "${var}" = "PKG_CONFIG_ALLOW_SYSTEM_CFLAGS" ] || \ [ "${var}" = "PKG_CONFIG_ALLOW_SYSTEM_LIBS" ]; then diff --git a/packages/devel/pkg-config/patches/0001-Add-support-for-multiple-sysroots.patch b/packages/devel/pkg-config/patches/0001-Add-support-for-multiple-sysroots.patch new file mode 100644 index 0000000000..61403a4c85 --- /dev/null +++ b/packages/devel/pkg-config/patches/0001-Add-support-for-multiple-sysroots.patch @@ -0,0 +1,256 @@ +From 64a39cd046040552729d32caef2a753b7f3dfc9c Mon Sep 17 00:00:00 2001 +From: Andre Heider +Date: Thu, 19 Dec 2019 17:42:01 +0100 +Subject: [PATCH] Add support for multiple sysroots + +Introduce PKG_CONFIG_SYSROOT_BASE, which can be set to a base directory +under which multiple install prefixes exist. + +Now it's possible to: +* configure and install libfoo with --prefix=/base/foo/usr +* configure and install libbar with --prefix=/base/bar/usr +* export PKG_CONFIG_SYSROOT_BASE=/base + +and pkg-config attempts to detect the sysroot directory for each .pc +file located under the base directory, and sets its sysroot accordingly. + +Example with libfoo.pc and libbar.pc both contain includedir=/usr/include + +$ PKG_CONFIG_PATH=/base/foo/usr/lib/pkg-config:/base/bar/usr/lib/pkgconfig \ + PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \ + pkg-config --cflags libfoo libbar + +Will print "-I/base/foo/usr/include -I/base/bar/usr/include" +--- + main.c | 5 ++++ + parse.c | 2 ++ + pkg.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- + pkg.h | 2 ++ + 4 files changed, 84 insertions(+), 3 deletions(-) + +diff --git a/main.c b/main.c +index 9b27d9a..409d474 100644 +--- a/main.c ++++ b/main.c +@@ -35,6 +35,7 @@ + #undef STRICT + #endif + ++GString *pcsysrootbase = NULL; + char *pcsysrootdir = NULL; + char *pkg_config_pc_path = NULL; + +@@ -531,6 +532,8 @@ main (int argc, char **argv) + add_search_dirs(pkg_config_pc_path, G_SEARCHPATH_SEPARATOR_S); + } + ++ pcsysrootbase = g_string_new(getenv("PKG_CONFIG_SYSROOT_BASE")); ++ + pcsysrootdir = getenv ("PKG_CONFIG_SYSROOT_DIR"); + if (pcsysrootdir) + { +@@ -834,5 +837,7 @@ main (int argc, char **argv) + if (need_newline) + printf ("\n"); + ++ g_string_free(pcsysrootbase, FALSE); ++ + return 0; + } +diff --git a/parse.c b/parse.c +index 6e9907c..bea87f3 100644 +--- a/parse.c ++++ b/parse.c +@@ -634,6 +634,7 @@ static void _do_parse_libs (Package *pkg, int argc, char **argv) + while (i < argc) + { + Flag *flag = g_new (Flag, 1); ++ flag->pkg = pkg; + char *tmp = trim_string (argv[i]); + char *arg = strdup_escape_shell(tmp); + char *p; +@@ -837,6 +838,7 @@ parse_cflags (Package *pkg, const char *str, const char *path) + while (i < argc) + { + Flag *flag = g_new (Flag, 1); ++ flag->pkg = pkg; + char *tmp = trim_string (argv[i]); + char *arg = strdup_escape_shell(tmp); + char *p = arg; +diff --git a/pkg.c b/pkg.c +index f29ecc7..ecae401 100644 +--- a/pkg.c ++++ b/pkg.c +@@ -408,6 +408,9 @@ flag_list_strip_duplicates (GList *list) + + if (cur->type == prev->type && g_strcmp0 (cur->arg, prev->arg) == 0) + { ++ if (cur->type & (CFLAGS_I | LIBS_L) && cur->pkg != prev->pkg) ++ continue; ++ + /* Remove the duplicate flag from the list and move to the last + * element to prepare for the next iteration. */ + GList *dup = tmp; +@@ -421,19 +424,75 @@ flag_list_strip_duplicates (GList *list) + return list; + } + ++static const struct _suffix { ++ const char * const suffix; ++ const size_t len; ++} suffixes[] = { ++ { ++ "/usr/local/lib/pkgconfig", ++ 24, ++ }, ++ { ++ "/usr/local/share/pkgconfig", ++ 26, ++ }, ++ { ++ "/usr/lib/pkgconfig", ++ 18, ++ }, ++ { ++ "/usr/share/pkgconfig", ++ 20, ++ }, ++ { ++ "/lib/pkgconfig", ++ 14, ++ }, ++ { ++ "/share/pkgconfig", ++ 16, ++ }, ++}; ++ ++static void ++get_sysroot(const Package *pkg, GString *dst) ++{ ++ if (pcsysrootbase->len && !strncmp(pkg->pcfiledir, pcsysrootbase->str, pcsysrootbase->len)) ++ { ++ size_t len = strlen(pkg->pcfiledir); ++ ++ for (int i = 0; i < sizeof(suffixes) / sizeof(*suffixes); i++) ++ { ++ const struct _suffix *x = &suffixes[i]; ++ ++ if (len > x->len && !strcmp(pkg->pcfiledir + len - x->len, x->suffix)) ++ { ++ g_string_assign(dst, pkg->pcfiledir); ++ g_string_truncate(dst, dst->len - x->len); ++ return; ++ } ++ } ++ } ++ ++ g_string_assign(dst, pcsysrootdir ? pcsysrootdir : ""); ++} ++ + static char * + flag_list_to_string (GList *list) + { + GList *tmp; + GString *str = g_string_new (""); ++ GString *sysroot = g_string_new (""); ++ GString *cmp = g_string_new(pcsysrootbase->len ? pcsysrootbase->str : pcsysrootdir); + char *retval; + + tmp = list; + while (tmp != NULL) { + Flag *flag = tmp->data; ++ get_sysroot(flag->pkg, sysroot); + char *tmpstr = flag->arg; + +- if (pcsysrootdir != NULL && flag->type & (CFLAGS_I | LIBS_L)) { ++ if (sysroot->len && flag->type & (CFLAGS_I | LIBS_L) && strncmp(tmpstr + 2, cmp->str, cmp->len)) { + /* Handle non-I Cflags like -isystem */ + if (flag->type & CFLAGS_I && strncmp (tmpstr, "-I", 2) != 0) { + char *space = strchr (tmpstr, ' '); +@@ -441,14 +500,17 @@ flag_list_to_string (GList *list) + /* 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, sysroot->str); + 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, sysroot->str); + g_string_append (str, tmpstr+2); + } ++ } else if (sysroot->len && !strncmp(tmpstr, "/usr", 4) && strncmp(tmpstr, cmp->str, cmp->len)) { ++ g_string_append (str, sysroot->str); ++ g_string_append (str, tmpstr); + } else { + g_string_append (str, tmpstr); + } +@@ -458,6 +520,8 @@ flag_list_to_string (GList *list) + + retval = str->str; + g_string_free (str, FALSE); ++ g_string_free (cmp, FALSE); ++ g_string_free (sysroot, TRUE); + + return retval; + } +@@ -1046,6 +1110,8 @@ packages_get_var (GList *pkgs, + { + GList *tmp; + GString *str; ++ GString *sysroot = g_string_new (""); ++ GString *cmp = g_string_new(pcsysrootbase->len ? pcsysrootbase->str : pcsysrootdir); + + str = g_string_new (NULL); + +@@ -1055,11 +1121,14 @@ packages_get_var (GList *pkgs, + Package *pkg = tmp->data; + char *var; + ++ get_sysroot(pkg, sysroot); + var = parse_package_variable (pkg, varname); + if (var) + { + if (str->len > 0) + g_string_append_c (str, ' '); ++ if (sysroot->len && (!strcmp(varname, "includedir") || !strcmp(varname, "libdir")) && strncmp(var, sysroot->str, sysroot->len)) ++ g_string_append(str, sysroot->str); + g_string_append (str, var); + g_free (var); + } +@@ -1067,6 +1136,9 @@ packages_get_var (GList *pkgs, + tmp = g_list_next (tmp); + } + ++ g_string_free(cmp, FALSE); ++ g_string_free(sysroot, TRUE); ++ + return g_string_free (str, FALSE); + } + +diff --git a/pkg.h b/pkg.h +index c6732bd..58edf38 100644 +--- a/pkg.h ++++ b/pkg.h +@@ -53,6 +53,7 @@ struct Flag_ + { + FlagType type; + char *arg; ++ Package *pkg; + }; + + struct RequiredVersion_ +@@ -126,6 +127,7 @@ void disable_requires_private(void); + /* If TRUE, do not automatically prefer uninstalled versions */ + extern gboolean disable_uninstalled; + ++extern GString *pcsysrootbase; + extern char *pcsysrootdir; + + /* pkg-config default search path. On Windows the current pkg-config install +-- +2.24.0 + diff --git a/packages/devel/pkg-config/patches/pkg-config-0001-use-sysroot-path.patch b/packages/devel/pkg-config/patches/pkg-config-0001-use-sysroot-path.patch deleted file mode 100644 index 851801dfd6..0000000000 --- a/packages/devel/pkg-config/patches/pkg-config-0001-use-sysroot-path.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 35fe817168fe0bdb78777d2707ba0189a4ce19bc Mon Sep 17 00:00:00 2001 -From: MilhouseVH -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 - diff --git a/tools/pkgcheck b/tools/pkgcheck index 491017e061..fb509b83cd 100755 --- a/tools/pkgcheck +++ b/tools/pkgcheck @@ -44,7 +44,7 @@ process_line() { DESTIMAGE CC CXX CPP LD AS AR NM \ RANLIB OBJCOPY OBJDUMP STRIP \ CPPFLAGS CFLAGS CXXFLAGS LDFLAGS \ - PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR PKG_CONFIG_ALLOW_SYSTEM_CFLAGS PKG_CONFIG_ALLOW_SYSTEM_LIBS \ + PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_BASE PKG_CONFIG_SYSROOT_DIR PKG_CONFIG_ALLOW_SYSTEM_CFLAGS PKG_CONFIG_ALLOW_SYSTEM_LIBS \ CMAKE_CONF CMAKE \ HOST_CC HOST_CXX HOSTCC HOSTCXX \ CC_FOR_BUILD CXX_FOR_BUILD BUILD_CC BUILD_CXX \