+
+ # Is the external program `pkg-config` available?
+ var pkgconfig_is_available: Bool is lazy do
+ # Ignore/silence the process output
+ var proc_which = new ProcessReader("which", "pkg-config")
+ proc_which.wait
+
+ var status = proc_which.status
+ if status != 0 then
+ error(null, "Error: program `pkg-config` not found, make sure it is installed.")
+ return false
+ end
+ return true
+ end
+
+ # Check if the `packages` are known by the external program `pkg-config`
+ #
+ # Missing packages are reported to the console via `ToolContext::error`.
+ # Check for errors using `check_errors`.
+ fun check_pkgconfig_packages(packages: Array[String])
+ do
+ if not pkgconfig_is_available then return
+
+ for pkg in packages do
+ var proc_exist = new Process("pkg-config", "--exists", pkg)
+ proc_exist.wait
+ var status = proc_exist.status
+ if status == 1 then
+ error(null,
+ "Error: dev package for `{pkg}` unknown by `pkg-config`, install it with `apt-get`, `brew` or similar.")
+ else if status != 0 then
+ error(null,
+ "Error: something went wrong calling `pkg-config`, make sure it is correctly configured.")
+ end
+ end
+ end