function os.capture(cmd)
	local f = io.popen(cmd, 'r')
	if (f) then
		local s = f:read('*a')
		if (f:close()) then
			return s
		end
	end
	return nil
end

hash = (os.capture("git rev-parse HEAD") or "UnknownRevision"):gsub("\n$", "")
clean = ((os.capture("git diff --name-only") or "0"):gsub("\n$", "") == "") and "1" or "0"

local output = io.open(arg[1], "w")
if (output) then
	output:write("// This file was automatically generated by buildinfo.lua\n#pragma once\n\n")
	output:write("#define ETH_COMMIT_HASH "..hash.."\n")
	output:write("#define ETH_CLEAN_REPO "..clean.."\n")
	output:close()
end