diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-02-07 22:25:09 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2018-02-08 07:44:37 +0100 |
commit | 7f0e90a5c34f437b7ab8f9197a9d42fc835b1a60 (patch) | |
tree | f65705f17cd1e3dcda3882cd8a6fb998747e3c1c /vala/valacodecontext.vala | |
parent | cc629f3724d4a72e38726a4264ab69a925aa00c9 (diff) | |
download | vala-7f0e90a5c34f437b7ab8f9197a9d42fc835b1a60.tar.gz |
valac: Always use the given "pkg-config" and respect PKG_CONFIG envar
Diffstat (limited to 'vala/valacodecontext.vala')
-rw-r--r-- | vala/valacodecontext.vala | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 713ba7eb2..d3955df70 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -72,6 +72,11 @@ public class Vala.CodeContext { public bool ccode_only { get; set; } /** + * Command to run pkg-config. + */ + public string pkg_config_command { get; set; default = "pkg-config"; } + + /** * Enable support for ABI stability. */ public bool abi_stability { get; set; } @@ -684,4 +689,61 @@ public class Vala.CodeContext { return rpath; } + + public bool pkg_config_exists (string package_name) { + string pc = pkg_config_command + " --exists " + package_name; + int exit_status; + + try { + Process.spawn_command_line_sync (pc, null, null, out exit_status); + return (0 == exit_status); + } catch (SpawnError e) { + Report.error (null, e.message); + return false; + } + } + + public string? pkg_config_modversion (string package_name) { + string pc = pkg_config_command + " --silence-errors --modversion " + package_name; + string? output = null; + int exit_status; + + try { + Process.spawn_command_line_sync (pc, out output, null, out exit_status); + if (exit_status != 0) { + output = output[0:-1]; + if (output == "") { + output = null; + } + } + } catch (SpawnError e) { + output = null; + } + + return output; + } + + public string? pkg_config_compile_flags (string package_name) { + string pc = pkg_config_command + " --cflags"; + if (!compile_only) { + pc += " --libs"; + } + pc += package_name; + + string? output = null; + int exit_status; + + try { + Process.spawn_command_line_sync (pc, out output, null, out exit_status); + if (exit_status != 0) { + Report.error (null, "%s exited with status %d".printf (pkg_config_command, exit_status)); + return null; + } + } catch (SpawnError e) { + Report.error (null, e.message); + output = null; + } + + return output; + } } |