From 9439b683ca23a98edcd0f0335d5489c943ec2592 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 May 2018 19:27:53 -0500 Subject: [PATCH] libpkgconf: personality: add stub cross personality loader --- Makefile.am | 3 ++- configure.ac | 7 ++++++ libpkgconf/personality.c | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2855469..a819f51 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,10 +5,11 @@ includedir = @includedir@ system_includedir = @SYSTEM_INCLUDEDIR@ system_libdir = @SYSTEM_LIBDIR@ pkg_default_dir = @PKG_DEFAULT_PATH@ +personality_dir = @PERSONALITY_PATH@ pkgconfigdir = $(libdir)/pkgconfig nodist_pkgconfig_DATA = libpkgconf.pc -AM_CFLAGS = -DPKG_DEFAULT_PATH=\"$(pkg_default_dir)\" -DSYSTEM_INCLUDEDIR=\"$(system_includedir)\" -DSYSTEM_LIBDIR=\"$(system_libdir)\" +AM_CFLAGS = -DPERSONALITY_PATH=\"$(personality_dir)\" -DPKG_DEFAULT_PATH=\"$(pkg_default_dir)\" -DSYSTEM_INCLUDEDIR=\"$(system_includedir)\" -DSYSTEM_LIBDIR=\"$(system_libdir)\" bin_PROGRAMS = pkgconf lib_LTLIBRARIES = libpkgconf.la diff --git a/configure.ac b/configure.ac index f4a3854..52b47e8 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,13 @@ LT_INIT AC_SYS_LARGEFILE +AC_ARG_WITH([personality-dir],[AC_HELP_STRING([--with-personality-dir],[specify + the place where cross-compile personality files will be found])], + PERSONALITY_PATH="$withval", + PERSONALITY_PATH="${datadir}/pkgconfig/personality.d:${etcdir}/pkgconfig/personality.d") + +AC_SUBST([PERSONALITY_PATH]) + AC_ARG_WITH([pkg-config-dir],[AC_HELP_STRING([--with-pkg-config-dir],[specify the place where pc files will be found])],PKG_DEFAULT_PATH="$withval", PKG_DEFAULT_PATH="${libdir}/pkgconfig:${datadir}/pkgconfig") diff --git a/libpkgconf/personality.c b/libpkgconf/personality.c index 3474ac5..bf7302c 100644 --- a/libpkgconf/personality.c +++ b/libpkgconf/personality.c @@ -94,3 +94,57 @@ pkgconf_cross_personality_default(void) default_personality_init = true; return &default_personality; } + +static bool +valid_triplet(const char *triplet) +{ + const char *c = triplet; + + for (; c != '\0'; c++) + if (!isalnum(*c) && *c != '-') + return false; + + return true; +} + +static pkgconf_cross_personality_t * +load_personality_with_path(const char *path, const char *triplet) +{ + return NULL; +} + +/* + * !doc + * + * .. c:function:: pkgconf_cross_personality_t *pkgconf_cross_personality_find(const char *triplet) + * + * Attempts to find a cross-compile personality given a triplet. + * + * :rtype: pkgconf_cross_personality_t* + * :return: the default cross-compile personality + */ +pkgconf_cross_personality_t * +pkgconf_cross_personality_find(const char *triplet) +{ + pkgconf_list_t plist; + pkgconf_node_t *n; + pkgconf_cross_personality_t *out = NULL; + + if (!valid_triplet(triplet)) + return NULL; + + pkgconf_path_split(PERSONALITY_PATH, &plist, true); + + PKGCONF_FOREACH_LIST_ENTRY(plist.head, n) + { + pkgconf_path_t *pn = n->data; + + out = load_personality_with_path(pn->path, triplet); + if (out != NULL) + goto finish; + } + +finish: + pkgconf_path_free(&plist); + return out; +}