summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/linker.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-11 11:59:45 +0800
committerruki <[email protected]>2015-06-11 11:59:45 +0800
commit2680c6575a238d0a199f2a31fcf47cd6d0687b62 (patch)
tree87bfdd3873bd2d560f3ce1192ba034974535b024 /xmake/scripts/base/linker.lua
parentb5815f7c047221ea4a85333f7a8b6be5a2a4c737 (diff)
check includes, links and interfaces
Diffstat (limited to 'xmake/scripts/base/linker.lua')
-rw-r--r--xmake/scripts/base/linker.lua73
1 files changed, 55 insertions, 18 deletions
diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua
index cefb24050..517f376fc 100644
--- a/xmake/scripts/base/linker.lua
+++ b/xmake/scripts/base/linker.lua
@@ -101,6 +101,31 @@ function linker._getflags(module, names, flags)
return flags_mapped
end
+-- get the linker from the given kind
+function linker.get(kind)
+
+ -- check
+ assert(kind)
+
+ -- get the linker name from the kind
+ local name = nil
+ if kind == "binary" then name = "ld"
+ elseif kind == "static" then name = "ar"
+ elseif kind == "shared" then name = "sh"
+ else return end
+
+ -- get it
+ local module = tools.get(name)
+
+ -- invalid linker?
+ if module and not module.command_link then
+ return
+ end
+
+ -- ok?
+ return module
+end
+
-- make the link command
function linker.make(module, target, objfiles, targetfile)
@@ -156,30 +181,42 @@ function linker.make(module, target, objfiles, targetfile)
return module.command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim())
end
--- get the linker from the given kind
-function linker.get(kind)
+-- check link for the project option
+function linker.check_link(opt, link, objectfile, targetfile)
-- check
- assert(kind)
+ assert(opt and link and objectfile and targetfile)
- -- get the linker name from the kind
- local name = nil
- if kind == "binary" then name = "ld"
- elseif kind == "static" then name = "ar"
- elseif kind == "shared" then name = "sh"
- else return end
-
- -- get it
- local module = tools.get(name)
+ -- get the linker
+ local l = linker.get("binary")
+ assert(l and l.flag_link)
- -- invalid linker?
- if module and not module.command_link then
- return
+ -- append the common flags
+ local flags = {}
+ table.join2(flags, l.ldflags)
+
+ -- append the option flags
+ table.join2(flags, linker._mapflags(l, opt.ldflags))
+
+ -- append the linkdirs flags
+ if opt.linkdirs and l.flag_linkdir then
+ for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do
+ table.join2(flags, l.flag_linkdir(linkdir))
+ end
end
- -- ok?
- return module
-end
+ -- append the links flags
+ table.join2(flags, l.flag_link(link))
+ -- make the compile command
+ local cmd = string.format("%s > %s 2>&1", l.command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV)
+ if not cmd then return end
+
+ -- check it
+ if 0 ~= os.execute(cmd) then return end
+
+ -- ok
+ return true
+end
-- return module: linker
return linker