summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2013-04-17 07:40:54 -0700
committerDan Nicholson <dbn.lists@gmail.com>2013-05-17 05:13:14 -0700
commita65d5cff5fdc842b9567d56771193820ae48b7b7 (patch)
tree9690cac6eec59d31a7b4b642acb101909fcaaeaa /parse.c
parent409ee76ce1ba3372f34ca4d14b629bd8ad8347e1 (diff)
downloadpkg-config-a65d5cff5fdc842b9567d56771193820ae48b7b7.tar.gz
Allow Windows prefix redefinition in any pkgconfig directory
The prefix redefinition feature on Windows to make packages relocatable was being confined only to locations where the .pc file was in a directory ending in lib/pkgconfig or share/pkgconfig. This is too restrictive as it's quite common for the libdir to have a different name such as lib64. This keeps the convention that the feature will only be enabled when the .pc file is in a pkgconfig directory, and it continues to define the prefix to the grandparent of the pkgconfig directory. The path handling is switched over to standard glib functions g_path_get_basename and g_path_get_dirname to avoid handrolled handling of Windows paths.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c53
1 files changed, 16 insertions, 37 deletions
diff --git a/parse.c b/parse.c
index 4e0857d..6c48e94 100644
--- a/parse.c
+++ b/parse.c
@@ -857,20 +857,6 @@ parse_url (Package *pkg, const char *str, const char *path)
#ifdef G_OS_WIN32
static char *orig_prefix = NULL;
-
-static int
-pathnamecmp (const char *a,
- const char *b)
-{
- while (*a && *b &&
- ((G_IS_DIR_SEPARATOR (*a) && G_IS_DIR_SEPARATOR (*b)) ||
- g_ascii_toupper (*a) == g_ascii_toupper (*b)))
- {
- a++;
- b++;
- }
- return g_ascii_toupper (*a) - g_ascii_toupper (*b);
-}
#endif
static void
@@ -973,31 +959,24 @@ parse_line (Package *pkg, const char *untrimmed, const char *path,
/* This is the prefix variable. Try to guesstimate a value for it
* for this package from the location of the .pc file.
*/
+ gchar *base;
+ gboolean is_pkgconfigdir;
- gchar *prefix = pkg->pcfiledir;
- const int prefix_len = strlen (prefix);
- const char *const lib_pkgconfig = "\\lib\\pkgconfig";
- const char *const share_pkgconfig = "\\share\\pkgconfig";
- const int lib_pkgconfig_len = strlen (lib_pkgconfig);
- const int share_pkgconfig_len = strlen (share_pkgconfig);
-
- if ((strlen (prefix) > lib_pkgconfig_len &&
- pathnamecmp (prefix + prefix_len - lib_pkgconfig_len, lib_pkgconfig) == 0) ||
- (strlen (prefix) > share_pkgconfig_len &&
- pathnamecmp (prefix + prefix_len - share_pkgconfig_len, share_pkgconfig) == 0))
- {
- /* It ends in lib\pkgconfig or share\pkgconfig. Good. */
-
- gchar *q;
+ base = g_path_get_basename (pkg->pcfiledir);
+ is_pkgconfigdir = g_ascii_strcasecmp (base, "pkgconfig") == 0;
+ g_free (base);
+ if (is_pkgconfigdir)
+ {
+ /* It ends in pkgconfig. Good. */
+ gchar *q;
+ gchar *prefix;
- orig_prefix = g_strdup (p);
-
- prefix = g_strdup (prefix);
- if (strlen (prefix) > lib_pkgconfig_len &&
- pathnamecmp (prefix + prefix_len - lib_pkgconfig_len, lib_pkgconfig) == 0)
- prefix[prefix_len - lib_pkgconfig_len] = '\0';
- else
- prefix[prefix_len - share_pkgconfig_len] = '\0';
+ orig_prefix = g_strdup (p);
+
+ /* Get grandparent directory for new prefix. */
+ q = g_path_get_dirname (pkg->pcfiledir);
+ prefix = g_path_get_dirname (q);
+ g_free (q);
/* Turn backslashes into slashes or
* g_shell_parse_argv() will eat them when ${prefix}