diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-06-13 10:22:48 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2016-01-29 14:32:24 -0800 |
commit | ae0a8b1ad5e40f68fc09ffedac215e038a50f070 (patch) | |
tree | bb8c37ac58dce6a6224b0f7b8db4cc8a6c7c0ea2 /pkg.c | |
parent | 9ef2d3475df0eba199427e9c47d9e502bd45b116 (diff) |
Allow overriding package variables with env vars
pkg-config allows a way to override package variables through the
--define-prefix interface, but this is very cumbersome to do in a global
way since it always needs to be passed on the command line and the
override cannot be scoped to a single packge.
Allow overriding package variables using environment variables of the
form PKG_CONFIG_$PACKAGE_$VARIABLE. For example, setting
PKG_CONFIG_GLADEUI_2_0_CATALOGDIR will override the variable
"catalogdir" in the "gladeui-2.0" package.
https://bugs.freedesktop.org/show_bug.cgi?id=90917
Diffstat (limited to 'pkg.c')
-rw-r--r-- | pkg.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -1021,6 +1021,24 @@ define_global_variable (const char *varname, } char * +var_to_env_var (const char *pkg, const char *var) +{ + char *new = g_strconcat ("PKG_CONFIG_", pkg, "_", var, NULL); + char *p; + for (p = new; *p != 0; p++) + { + char c = g_ascii_toupper (*p); + + if (!g_ascii_isalnum (c)) + c = '_'; + + *p = c; + } + + return new; +} + +char * package_get_var (Package *pkg, const char *var) { @@ -1028,7 +1046,23 @@ package_get_var (Package *pkg, if (globals) varval = g_strdup (g_hash_table_lookup (globals, var)); - + + /* Allow overriding specific variables using an environment variable of the + * form PKG_CONFIG_$PACKAGENAME_$VARIABLE + */ + if (pkg->key) + { + char *env_var = var_to_env_var (pkg->key, var); + const char *env_var_content = g_getenv (env_var); + g_free (env_var); + if (env_var_content) + { + debug_spew ("Overriding variable '%s' from environment\n", var); + return g_strdup (env_var_content); + } + } + + if (varval == NULL && pkg->vars) varval = g_strdup (g_hash_table_lookup (pkg->vars, var)); |