pkg: add support for munging tuples based on $(pc_sysrootdir) if requested

pull/48/head
William Pitcock 2013-02-24 08:58:35 -06:00
parent bea204fa63
commit 01c2d1d44c
2 changed files with 20 additions and 8 deletions

25
pkg.c
View File

@ -143,12 +143,12 @@ pkg_get_parent_dir(pkg_t *pkg)
static pkg_t *pkg_cache = NULL; static pkg_t *pkg_cache = NULL;
/* /*
* pkg_new_from_file(filename, file) * pkg_new_from_file(filename, file, flags)
* *
* Parse a .pc file into a pkg_t object structure. * Parse a .pc file into a pkg_t object structure.
*/ */
pkg_t * pkg_t *
pkg_new_from_file(const char *filename, FILE *f) pkg_new_from_file(const char *filename, FILE *f, unsigned int flags)
{ {
pkg_t *pkg; pkg_t *pkg;
char readbuf[PKG_BUFSIZE]; char readbuf[PKG_BUFSIZE];
@ -221,7 +221,18 @@ pkg_new_from_file(const char *filename, FILE *f)
pkg->conflicts = pkg_dependency_parse(pkg, value); pkg->conflicts = pkg_dependency_parse(pkg, value);
break; break;
case '=': case '=':
pkg->vars = pkg_tuple_add(pkg->vars, key, value); if (!(flags & PKGF_MUNGE_SYSROOT_PREFIX) || strcasecmp(key, "prefix"))
pkg->vars = pkg_tuple_add(pkg->vars, key, value);
else
{
char mungebuf[PKG_BUFSIZE];
char *sysroot_dir = pkg_tuple_find_global("pc_sysrootdir");
strlcpy(mungebuf, sysroot_dir, sizeof mungebuf);
strlcat(mungebuf, value, sizeof mungebuf);
pkg->vars = pkg_tuple_add(pkg->vars, key, mungebuf);
}
break; break;
default: default:
break; break;
@ -294,11 +305,11 @@ pkg_try_specific_path(const char *path, const char *name, unsigned int flags)
if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL) if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
{ {
pkg = pkg_new_from_file(uninst_locbuf, f); pkg = pkg_new_from_file(uninst_locbuf, f, flags);
pkg->uninstalled = true; pkg->uninstalled = true;
} }
else if ((f = fopen(locbuf, "r")) != NULL) else if ((f = fopen(locbuf, "r")) != NULL)
pkg = pkg_new_from_file(locbuf, f); pkg = pkg_new_from_file(locbuf, f, flags);
return pkg; return pkg;
} }
@ -332,7 +343,7 @@ pkg_scan_dir(const char *path, pkg_iteration_func_t func)
if (f == NULL) if (f == NULL)
continue; continue;
pkg = pkg_new_from_file(filebuf, f); pkg = pkg_new_from_file(filebuf, f, 0);
if (pkg != NULL) if (pkg != NULL)
{ {
func(pkg); func(pkg);
@ -427,7 +438,7 @@ pkg_find(const char *name, unsigned int flags)
if (str_has_suffix(name, PKG_CONFIG_EXT)) if (str_has_suffix(name, PKG_CONFIG_EXT))
{ {
if ((f = fopen(name, "r")) != NULL) if ((f = fopen(name, "r")) != NULL)
return pkg_new_from_file(name, f); return pkg_new_from_file(name, f, flags);
} }
/* check cache */ /* check cache */

3
pkg.h
View File

@ -118,6 +118,7 @@ struct pkg_ {
#define PKGF_MERGE_PRIVATE_FRAGMENTS 0x10 #define PKGF_MERGE_PRIVATE_FRAGMENTS 0x10
#define PKGF_SKIP_CONFLICTS 0x20 #define PKGF_SKIP_CONFLICTS 0x20
#define PKGF_NO_CACHE 0x40 #define PKGF_NO_CACHE 0x40
#define PKGF_MUNGE_SYSROOT_PREFIX 0x80
#define PKG_ERRF_OK 0x0 #define PKG_ERRF_OK 0x0
#define PKG_ERRF_PACKAGE_NOT_FOUND 0x1 #define PKG_ERRF_PACKAGE_NOT_FOUND 0x1
@ -144,7 +145,7 @@ int pkg_libs(pkg_t *root, pkg_fragment_t **list, int maxdepth, unsigned int flag
pkg_comparator_t pkg_comparator_lookup_by_name(const char *name); pkg_comparator_t pkg_comparator_lookup_by_name(const char *name);
/* parse.c */ /* parse.c */
pkg_t *pkg_new_from_file(const char *path, FILE *f); pkg_t *pkg_new_from_file(const char *path, FILE *f, unsigned int flags);
pkg_dependency_t *pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends); pkg_dependency_t *pkg_dependency_parse_str(pkg_dependency_t *deplist_head, const char *depends);
pkg_dependency_t *pkg_dependency_parse(pkg_t *pkg, const char *depends); pkg_dependency_t *pkg_dependency_parse(pkg_t *pkg, const char *depends);
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail); pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);