-- This should be turned into a proper module and not use globals.
-- Or combined into a generiv test utility module. With FFI
-- functionality turned off, if the FFI module is not built-in.

local ffi = require("ffi")

local incroot = os.getenv("INCROOT") or "/usr/include"
local cdefs = os.getenv("CDEFS") or ""

function include(name)
  local flags = ffi.abi("32bit") and "-m32" or "-m64"
  if string.sub(name, 1, 1) ~= "/" then name = incroot.."/"..name end
  local fp = assert(io.popen("cc -E -P "..flags.." "..cdefs.." "..name))
  local s = fp:read("*a")
  fp:close()
  ffi.cdef(s)
end

