1*4882a593SmuzhiyunFrom 267a57022699453e8d8f517519df25ac6bf6ac4e Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 3*4882a593SmuzhiyunDate: Sun, 16 Dec 2018 11:52:18 +0100 4*4882a593SmuzhiyunSubject: [PATCH] Only prefix with the sysroot a subset of variables 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunThe standard logic of pkg-config is to prefix all absolute paths by 7*4882a593Smuzhiyunthe sysroot defined in PKG_CONFIG_SYSROOT_DIR. However, while some 8*4882a593Smuzhiyunpaths (like includedir, libdir, and paths used in -L and -I options) 9*4882a593Smuzhiyunindeed need to be prefixed by the sysroot, it is not necessarily the 10*4882a593Smuzhiyuncase for paths that are used on the target. If they get prefixed by 11*4882a593Smuzhiyunthe sysroot, the runtime path on the target is incorrect. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunUnfortunately, pkg-config doesn't have a sense of which path needs to 14*4882a593Smuzhiyunbe prefixed by the sysroot, and which path should not be prefixed by 15*4882a593Smuzhiyunthe sysroot. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunSo, let's simply have a whitelist of paths that should be prefixed: 18*4882a593Smuzhiyung_ir_scanner, g_ir_compiler, g_ir_generate, includedir, libdir, mapdir, 19*4882a593Smuzhiyunpkgdatadir and sdkdir. This list of variables was collected over years of 20*4882a593SmuzhiyunBuildroot development. All other paths are not prefixed by the sysroot. 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> 23*4882a593Smuzhiyun[Updated to include gobject-introspection paths] 24*4882a593SmuzhiyunSigned-off-by: Adam Duskett <aduskett@gmail.com> 25*4882a593Smuzhiyun--- 26*4882a593Smuzhiyun libpkgconf/tuple.c | 60 ++++++++++++++++++++++++++++++++-------------- 27*4882a593Smuzhiyun 1 file changed, 42 insertions(+), 18 deletions(-) 28*4882a593Smuzhiyun 29*4882a593Smuzhiyundiff --git a/libpkgconf/tuple.c b/libpkgconf/tuple.c 30*4882a593Smuzhiyunindex 8523709..7cd2fff 100644 31*4882a593Smuzhiyun--- a/libpkgconf/tuple.c 32*4882a593Smuzhiyun+++ b/libpkgconf/tuple.c 33*4882a593Smuzhiyun@@ -161,6 +161,21 @@ dequote(const char *value) 34*4882a593Smuzhiyun return buf; 35*4882a593Smuzhiyun } 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun+static char * 38*4882a593Smuzhiyun+pkgconf_tuple_parse_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, bool add_sysroot); 39*4882a593Smuzhiyun+ 40*4882a593Smuzhiyun+const char *sysrooted_keys[] = { 41*4882a593Smuzhiyun+ "g_ir_scanner", 42*4882a593Smuzhiyun+ "g_ir_compiler", 43*4882a593Smuzhiyun+ "g_ir_generate", 44*4882a593Smuzhiyun+ "includedir", 45*4882a593Smuzhiyun+ "libdir", 46*4882a593Smuzhiyun+ "mapdir", 47*4882a593Smuzhiyun+ "pkgdatadir", 48*4882a593Smuzhiyun+ "sdkdir", 49*4882a593Smuzhiyun+ NULL, 50*4882a593Smuzhiyun+}; 51*4882a593Smuzhiyun+ 52*4882a593Smuzhiyun /* 53*4882a593Smuzhiyun * !doc 54*4882a593Smuzhiyun * 55*4882a593Smuzhiyun@@ -181,6 +193,8 @@ pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const ch 56*4882a593Smuzhiyun { 57*4882a593Smuzhiyun char *dequote_value; 58*4882a593Smuzhiyun pkgconf_tuple_t *tuple = calloc(sizeof(pkgconf_tuple_t), 1); 59*4882a593Smuzhiyun+ bool add_sysroot = false; 60*4882a593Smuzhiyun+ int i; 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun pkgconf_tuple_find_delete(list, key); 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun@@ -188,9 +202,13 @@ pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const ch 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, dequote_value, parse); 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun+ for (i = 0; sysrooted_keys[i] != NULL; i++) 69*4882a593Smuzhiyun+ if (!strcmp(key, sysrooted_keys[i])) 70*4882a593Smuzhiyun+ add_sysroot = true; 71*4882a593Smuzhiyun+ 72*4882a593Smuzhiyun tuple->key = strdup(key); 73*4882a593Smuzhiyun if (parse) 74*4882a593Smuzhiyun- tuple->value = pkgconf_tuple_parse(client, list, dequote_value); 75*4882a593Smuzhiyun+ tuple->value = pkgconf_tuple_parse_sysroot(client, list, dequote_value, add_sysroot); 76*4882a593Smuzhiyun else 77*4882a593Smuzhiyun tuple->value = strdup(dequote_value); 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun@@ -234,27 +252,14 @@ pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const c 80*4882a593Smuzhiyun return NULL; 81*4882a593Smuzhiyun } 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun-/* 84*4882a593Smuzhiyun- * !doc 85*4882a593Smuzhiyun- * 86*4882a593Smuzhiyun- * .. c:function:: char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value) 87*4882a593Smuzhiyun- * 88*4882a593Smuzhiyun- * Parse an expression for variable substitution. 89*4882a593Smuzhiyun- * 90*4882a593Smuzhiyun- * :param pkgconf_client_t* client: The pkgconf client object to access. 91*4882a593Smuzhiyun- * :param pkgconf_list_t* list: The variable list to search for variables (along side the global variable list). 92*4882a593Smuzhiyun- * :param char* value: The ``key=value`` string to parse. 93*4882a593Smuzhiyun- * :return: the variable data with any variables substituted 94*4882a593Smuzhiyun- * :rtype: char * 95*4882a593Smuzhiyun- */ 96*4882a593Smuzhiyun-char * 97*4882a593Smuzhiyun-pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value) 98*4882a593Smuzhiyun+static char * 99*4882a593Smuzhiyun+pkgconf_tuple_parse_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, bool add_sysroot) 100*4882a593Smuzhiyun { 101*4882a593Smuzhiyun char buf[PKGCONF_BUFSIZE]; 102*4882a593Smuzhiyun const char *ptr; 103*4882a593Smuzhiyun char *bptr = buf; 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun- if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir))) 106*4882a593Smuzhiyun+ if (add_sysroot && *value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir))) 107*4882a593Smuzhiyun bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf); 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun for (ptr = value; *ptr != '\0' && bptr - buf < PKGCONF_BUFSIZE; ptr++) 110*4882a593Smuzhiyun@@ -294,7 +299,7 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun if (kv != NULL) 113*4882a593Smuzhiyun { 114*4882a593Smuzhiyun- parsekv = pkgconf_tuple_parse(client, vars, kv); 115*4882a593Smuzhiyun+ parsekv = pkgconf_tuple_parse_sysroot(client, vars, kv, add_sysroot); 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun strncpy(bptr, parsekv, PKGCONF_BUFSIZE - (bptr - buf)); 118*4882a593Smuzhiyun bptr += strlen(parsekv); 119*4882a593Smuzhiyun@@ -339,6 +344,25 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const 120*4882a593Smuzhiyun return strdup(buf); 121*4882a593Smuzhiyun } 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun+/* 124*4882a593Smuzhiyun+ * !doc 125*4882a593Smuzhiyun+ * 126*4882a593Smuzhiyun+ * .. c:function:: char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value) 127*4882a593Smuzhiyun+ * 128*4882a593Smuzhiyun+ * Parse an expression for variable substitution. 129*4882a593Smuzhiyun+ * 130*4882a593Smuzhiyun+ * :param pkgconf_client_t* client: The pkgconf client object to access. 131*4882a593Smuzhiyun+ * :param pkgconf_list_t* list: The variable list to search for variables (along side the global variable list). 132*4882a593Smuzhiyun+ * :param char* value: The ``key=value`` string to parse. 133*4882a593Smuzhiyun+ * :return: the variable data with any variables substituted 134*4882a593Smuzhiyun+ * :rtype: char * 135*4882a593Smuzhiyun+ */ 136*4882a593Smuzhiyun+char * 137*4882a593Smuzhiyun+pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value) 138*4882a593Smuzhiyun+{ 139*4882a593Smuzhiyun+ return pkgconf_tuple_parse_sysroot(client, vars, value, true); 140*4882a593Smuzhiyun+} 141*4882a593Smuzhiyun+ 142*4882a593Smuzhiyun /* 143*4882a593Smuzhiyun * !doc 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun-- 146*4882a593Smuzhiyun2.19.2 147*4882a593Smuzhiyun 148