0001-Only-prefix-with-the-sysroot-a-subset-of-variables.patch 5.2 KB

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