import ffi
import naive_interpreter
import pkgconfig
-import debugger_socket # To linearize `ToolContext::init`
redef class ToolContext
srcs.add_all mmodule.ffi_files
# Compiler options specific to this module
- var ldflags = mmodule.ldflags[""].join(" ")
+ var ldflags_array = mmodule.ldflags[""]
+ if ldflags_array.has("-lrt") and system("sh -c 'uname -s 2>/dev/null || echo not' | grep Darwin >/dev/null") == 0 then
+ # Remove -lrt on OS X
+ ldflags_array.remove "-lrt"
+ end
+ var ldflags = ldflags_array.join(" ")
# Protect pkg-config
var pkgconfigs = mmodule.pkgconfigs
var pkg_cflags = ""
if not pkgconfigs.is_empty then
- var cmd = "which pkg-config >/dev/null"
- if system(cmd) != 0 then
- v.fatal "FFI Error: Command `pkg-config` not found. Please install it"
- return false
- end
- for p in pkgconfigs do
- cmd = "pkg-config --exists '{p}'"
- if system(cmd) != 0 then
- v.fatal "FFI Error: package {p} is not found by `pkg-config`. Please install it."
- return false
- end
- end
+ # Check if the pkgconfig packages are available
+ v.modelbuilder.toolcontext.check_pkgconfig_packages pkgconfigs
+ if not v.modelbuilder.toolcontext.check_errors then return false
pkg_cflags = "`pkg-config --cflags {pkgconfigs.join(" ")}`"
ldflags += " `pkg-config --libs {pkgconfigs.join(" ")}`"