lfs = require("lfs") modpath = "/etc/haproxy/mods" local compile = {} local user = "haproxy" local group = "haproxy" local libs = {"-lcurl", "-ljansson", "-lmaxminddb"} function compile.check(module) local sourcepath = modpath.."/"..module..".c" local binpath = modpath.."/"..module..".so" local binexists = io.open(binpath) if not binexists or (binexists and lfs.attributes(sourcepath).change > lfs.attributes(binpath).change ) then local cmd = "cc -I/usr/include/ -I/usr/include/lua5.3/ -fPIC -shared -o " .. binpath .. " " .. sourcepath .. " " ..table.concat(libs," ") local res = io.popen(cmd) local aa = res:read("a*") io.popen("chown "..user..":"..group.." "..binpath) io.popen("chmod 600 "..binpath) end end return compile