From fd1b8ccca68abe52e1158aa3e5ef42267d952b74 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Thu, 18 Mar 2021 06:22:11 -0600 Subject: [PATCH] main: if PKG_CONFIG_FDO_SYSROOT_RULES is set, or DESTDIR matches PKG_CONFIG_SYSROOT_DIRS, disable the automatic sysroot rewriting Closes #205. --- cli/main.c | 13 +++++++++++++ libpkgconf/libpkgconf.h | 1 + libpkgconf/tuple.c | 7 +++++-- man/pkgconf.1 | 4 ++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/cli/main.c b/cli/main.c index f32b06c..11b8898 100644 --- a/cli/main.c +++ b/cli/main.c @@ -1015,6 +1015,9 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } + if (getenv("PKG_CONFIG_FDO_SYSROOT_RULES")) + want_client_flags |= PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES; + if ((want_flags & PKG_SHORT_ERRORS) == PKG_SHORT_ERRORS) want_client_flags |= PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS; @@ -1101,8 +1104,18 @@ main(int argc, char *argv[]) pkgconf_client_set_buildroot_dir(&pkg_client, builddir); if ((sysroot_dir = getenv("PKG_CONFIG_SYSROOT_DIR")) != NULL) + { + const char *destdir; + pkgconf_client_set_sysroot_dir(&pkg_client, sysroot_dir); + if ((destdir = getenv("DESTDIR")) != NULL) + { + if (!strcmp(destdir, sysroot_dir)) + want_client_flags |= PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES; + } + } + /* we have determined what features we want most likely. in some cases, we override later. */ pkgconf_client_set_flags(&pkg_client, want_client_flags); diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index 6f188de..8715789 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -251,6 +251,7 @@ PKGCONF_API pkgconf_cross_personality_t *pkgconf_cross_personality_find(const ch #define PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS 0x1000 #define PKGCONF_PKG_PKGF_DONT_FILTER_INTERNAL_CFLAGS 0x2000 #define PKGCONF_PKG_PKGF_DONT_MERGE_SPECIAL_FRAGMENTS 0x4000 +#define PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES 0x8000 #define PKGCONF_PKG_DEPF_INTERNAL 0x1 diff --git a/libpkgconf/tuple.c b/libpkgconf/tuple.c index 0d9946d..2d550d8 100644 --- a/libpkgconf/tuple.c +++ b/libpkgconf/tuple.c @@ -254,8 +254,11 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const const char *ptr; char *bptr = buf; - if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir))) - bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf); + if (!(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES)) + { + if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir))) + bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf); + } for (ptr = value; *ptr != '\0' && bptr - buf < PKGCONF_BUFSIZE; ptr++) { diff --git a/man/pkgconf.1 b/man/pkgconf.1 index 2df3d6a..ab603f1 100644 --- a/man/pkgconf.1 +++ b/man/pkgconf.1 @@ -213,6 +213,10 @@ The format of the debug log messages is implementation-specific. If set, disables the path relocation feature. .It Va PKG_CONFIG_MSVC_SYNTAX If set, uses MSVC syntax for fragments. +.It Va PKG_CONFIG_FDO_SYSROOT_RULES +If set, follow the sysroot prefixing rules that freedesktop.org pkg-config uses. +.It Va DESTDIR +If set to PKG_CONFIG_SYSROOT_DIR, assume that PKG_CONFIG_FDO_SYSROOT_RULES is set. .El .Sh EXAMPLES Displaying the CFLAGS of a package: