forked from ariadne/pkgconf
libpkgconf: improve API to support any number of builtin packages
parent
12a0eb124c
commit
9e415ea151
|
@ -158,6 +158,7 @@ const char *pkgconf_pkg_get_comparator(const pkgconf_dependency_t *pkgdep);
|
||||||
int pkgconf_pkg_cflags(pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags);
|
int pkgconf_pkg_cflags(pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags);
|
||||||
int pkgconf_pkg_libs(pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags);
|
int pkgconf_pkg_libs(pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags);
|
||||||
pkgconf_pkg_comparator_t pkgconf_pkg_comparator_lookup_by_name(const char *name);
|
pkgconf_pkg_comparator_t pkgconf_pkg_comparator_lookup_by_name(const char *name);
|
||||||
|
pkgconf_pkg_t *pkgconf_builtin_pkg_get(const char *name);
|
||||||
|
|
||||||
int pkgconf_compare_version(const char *a, const char *b);
|
int pkgconf_compare_version(const char *a, const char *b);
|
||||||
void pkgconf_scan_all(pkgconf_pkg_iteration_func_t func);
|
void pkgconf_scan_all(pkgconf_pkg_iteration_func_t func);
|
||||||
|
|
|
@ -480,6 +480,10 @@ pkgconf_pkg_find(const char *name, unsigned int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check builtins */
|
||||||
|
if ((pkg = pkgconf_builtin_pkg_get(name)) != NULL)
|
||||||
|
return pkg;
|
||||||
|
|
||||||
/* check cache */
|
/* check cache */
|
||||||
if (!(flags & PKGCONF_PKG_PKGF_NO_CACHE))
|
if (!(flags & PKGCONF_PKG_PKGF_NO_CACHE))
|
||||||
{
|
{
|
||||||
|
@ -660,6 +664,52 @@ static pkgconf_pkg_t pkg_config_virtual = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static pkgconf_pkg_t pkgconf_virtual = {
|
||||||
|
.id = "pkgconf",
|
||||||
|
.realname = "pkgconf",
|
||||||
|
.description = "virtual package defining pkgconf API version supported",
|
||||||
|
.url = PACKAGE_BUGREPORT,
|
||||||
|
.version = PACKAGE_VERSION,
|
||||||
|
.flags = PKGCONF_PKG_PROPF_VIRTUAL,
|
||||||
|
.vars = {
|
||||||
|
.head = &(pkgconf_node_t){
|
||||||
|
.prev = NULL,
|
||||||
|
.next = NULL,
|
||||||
|
.data = &(pkgconf_tuple_t){
|
||||||
|
.key = "pc_path",
|
||||||
|
.value = PKG_DEFAULT_PATH,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tail = NULL,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
pkgconf_pkg_t *pkg;
|
||||||
|
} pkgconf_builtin_pkg_pair_t;
|
||||||
|
|
||||||
|
/* keep these in alphabetical order */
|
||||||
|
static const pkgconf_builtin_pkg_pair_t pkgconf_builtin_pkg_pair_set[] = {
|
||||||
|
{"pkg-config", &pkg_config_virtual},
|
||||||
|
{"pkgconf", &pkgconf_virtual},
|
||||||
|
};
|
||||||
|
|
||||||
|
static int pkgconf_builtin_pkg_pair_cmp(const void *key, const void *ptr)
|
||||||
|
{
|
||||||
|
const pkgconf_builtin_pkg_pair_t *pair = ptr;
|
||||||
|
return strcasecmp(key, pair->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgconf_pkg_t *pkgconf_builtin_pkg_get(const char *name)
|
||||||
|
{
|
||||||
|
const pkgconf_builtin_pkg_pair_t *pair = bsearch(name, pkgconf_builtin_pkg_pair_set,
|
||||||
|
PKGCONF_ARRAY_SIZE(pkgconf_builtin_pkg_pair_set), sizeof(pkgconf_builtin_pkg_pair_t),
|
||||||
|
pkgconf_builtin_pkg_pair_cmp);
|
||||||
|
|
||||||
|
return (pair != NULL) ? pair->pkg : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
typedef bool (*pkgconf_vercmp_res_func_t)(pkgconf_pkg_t *pkg, pkgconf_dependency_t *pkgdep);
|
typedef bool (*pkgconf_vercmp_res_func_t)(pkgconf_pkg_t *pkg, pkgconf_dependency_t *pkgdep);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -786,22 +836,18 @@ pkgconf_pkg_comparator_lookup_by_name(const char *name)
|
||||||
pkgconf_pkg_t *
|
pkgconf_pkg_t *
|
||||||
pkgconf_pkg_verify_dependency(pkgconf_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags)
|
pkgconf_pkg_verify_dependency(pkgconf_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags)
|
||||||
{
|
{
|
||||||
pkgconf_pkg_t *pkg = &pkg_config_virtual;
|
pkgconf_pkg_t *pkg = NULL;
|
||||||
|
|
||||||
if (eflags != NULL)
|
if (eflags != NULL)
|
||||||
*eflags = PKGCONF_PKG_ERRF_OK;
|
*eflags = PKGCONF_PKG_ERRF_OK;
|
||||||
|
|
||||||
/* pkg-config package name is special cased. */
|
pkg = pkgconf_pkg_find(pkgdep->package, flags);
|
||||||
if (strcasecmp(pkgdep->package, "pkg-config"))
|
if (pkg == NULL)
|
||||||
{
|
{
|
||||||
pkg = pkgconf_pkg_find(pkgdep->package, flags);
|
if (eflags != NULL)
|
||||||
if (pkg == NULL)
|
*eflags |= PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND;
|
||||||
{
|
|
||||||
if (eflags != NULL)
|
|
||||||
*eflags |= PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkg->id == NULL)
|
if (pkg->id == NULL)
|
||||||
|
|
Loading…
Reference in New Issue