2017-10-30 06:52:05 -07:00
|
|
|
local m = {}
|
2019-05-25 11:00:40 -07:00
|
|
|
m._VERSION = "1.1.0-dev"
|
2017-10-30 06:52:05 -07:00
|
|
|
|
|
|
|
|
local function os_capture(cmd)
|
|
|
|
|
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-25 11:00:40 -07:00
|
|
|
function m.add_includes(lib, alternative_cmd, alternative_flags)
|
2017-10-30 06:52:05 -07:00
|
|
|
local result
|
|
|
|
|
if not alternative_cmd then
|
|
|
|
|
result = os_capture("pkg-config --cflags "..lib)
|
|
|
|
|
else
|
2019-05-25 11:00:40 -07:00
|
|
|
if not alternative_flags then
|
|
|
|
|
result = os_capture(alternative_cmd.." --cflags")
|
|
|
|
|
else
|
|
|
|
|
result = os_capture(alternative_cmd.." "..alternative_flags)
|
|
|
|
|
end
|
2017-10-30 06:52:05 -07:00
|
|
|
end
|
|
|
|
|
|
2017-11-25 08:56:56 -08:00
|
|
|
-- Small trick: delete the space after -include so that we can detect
|
|
|
|
|
-- which files have to be force-included without difficulty.
|
|
|
|
|
result = result:gsub("%-include +(%g+)", "-include%1")
|
|
|
|
|
|
2017-10-30 06:52:05 -07:00
|
|
|
local dirs = {}
|
2017-11-25 08:56:56 -08:00
|
|
|
local files = {}
|
2017-10-30 06:52:05 -07:00
|
|
|
local options = {}
|
|
|
|
|
for w in string.gmatch(result, "[^' ']+") do
|
|
|
|
|
if string.sub(w,1,2) == "-I" then
|
|
|
|
|
table.insert(dirs, string.sub(w,3))
|
2017-11-25 08:56:56 -08:00
|
|
|
elseif string.sub(w,1,8) == "-include" then
|
|
|
|
|
table.insert(files, string.sub(w,9))
|
2017-10-30 06:52:05 -07:00
|
|
|
else
|
|
|
|
|
table.insert(options, w)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
sysincludedirs(dirs)
|
2017-11-25 08:56:56 -08:00
|
|
|
forceincludes(files)
|
2017-10-30 06:52:05 -07:00
|
|
|
buildoptions(options)
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-25 11:00:40 -07:00
|
|
|
function m.add_links(lib, alternative_cmd, alternative_flags)
|
2017-10-30 06:52:05 -07:00
|
|
|
local result
|
|
|
|
|
if not alternative_cmd then
|
|
|
|
|
result = os_capture("pkg-config --libs "..lib)
|
|
|
|
|
else
|
2019-05-25 11:00:40 -07:00
|
|
|
if not alternative_flags then
|
|
|
|
|
result = os_capture(alternative_cmd.." --libs")
|
|
|
|
|
else
|
|
|
|
|
result = os_capture(alternative_cmd.." "..alternative_flags)
|
|
|
|
|
end
|
2017-10-30 06:52:05 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- On OSX, wx-config outputs "-framework foo" instead of "-Wl,-framework,foo"
|
|
|
|
|
-- which doesn't fare well with the splitting into libs, libdirs and options
|
|
|
|
|
-- we perform afterwards.
|
|
|
|
|
result = result:gsub("%-framework +(%g+)", "-Wl,-framework,%1")
|
|
|
|
|
|
|
|
|
|
local libs = {}
|
|
|
|
|
local dirs = {}
|
|
|
|
|
local options = {}
|
|
|
|
|
for w in string.gmatch(result, "[^' ']+") do
|
|
|
|
|
if string.sub(w,1,2) == "-l" then
|
|
|
|
|
table.insert(libs, string.sub(w,3))
|
|
|
|
|
elseif string.sub(w,1,2) == "-L" then
|
|
|
|
|
table.insert(dirs, string.sub(w,3))
|
|
|
|
|
else
|
|
|
|
|
table.insert(options, w)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
links(libs)
|
|
|
|
|
libdirs(dirs)
|
|
|
|
|
linkoptions(options)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return m
|