summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-15 20:30:21 +0800
committerruki <[email protected]>2017-02-15 20:30:21 +0800
commitdfce526796ade25d4da69c2542929e9c4662402a (patch)
tree728b41a29712a38f02ebc075620ac2a905e72666
parent80d3a926e762d7b05654fdc778c70dad9881356d (diff)
add linker to target
-rwxr-xr-xxmake/actions/build/kinds/binary.lua5
-rwxr-xr-xxmake/actions/build/kinds/shared.lua5
-rwxr-xr-xxmake/actions/build/kinds/static.lua5
-rw-r--r--xmake/core/project/target.lua42
-rwxr-xr-xxmake/plugins/project/makefile/makefile.lua6
5 files changed, 49 insertions, 14 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index f231fabca..ff24faaa4 100755
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -24,7 +24,6 @@
-- imports
import("core.base.option")
-import("core.tool.linker")
import("object")
-- build binary target
@@ -62,10 +61,10 @@ function build(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker.linkcmd(objectfiles, targetfile, target))
+ print(target:linkcmd(objectfiles))
end
-- link it
- linker.link(objectfiles, targetfile, target)
+ target:link(objectfiles)
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 718a685a8..3c6d2ad09 100755
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -24,7 +24,6 @@
-- imports
import("core.base.option")
-import("core.tool.linker")
import("object")
-- build binary target
@@ -75,10 +74,10 @@ function build(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker.linkcmd(objectfiles, targetfile, target))
+ print(target:linkcmd(objectfiles))
end
-- link it
- linker.link(objectfiles, targetfile, target)
+ target:link(objectfiles)
end
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 612ba194b..8df5de5c8 100755
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -24,7 +24,6 @@
-- imports
import("core.base.option")
-import("core.tool.linker")
import("object")
-- build binary target
@@ -75,10 +74,10 @@ function build(target, buildinfo)
-- trace verbose info
if verbose then
- print(linker.linkcmd(objectfiles, targetfile, target))
+ print(target:linkcmd(objectfiles))
end
-- link it
- linker.link(objectfiles, targetfile, target)
+ target:link(objectfiles)
end
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 546276caf..35b98c4eb 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -67,6 +67,48 @@ function target:name()
return self._NAME
end
+-- get the target linker
+function target:linker()
+
+ -- get it from cache first
+ if self._LINKER then
+ return self._LINKER
+ end
+
+ -- get the linker instance
+ local instance, errors = linker.load(self:get("kind"), self:sourcekinds())
+ if not instance then
+ os.raise(errors)
+ end
+
+ -- cache it
+ self._LINKER = instance
+
+ -- get it
+ return instance
+end
+
+-- make linking command for this target
+function target:linkcmd(objectfiles)
+
+ -- make command
+ return self:linker():linkcmd(objectfiles or self:objectfiles(), self:targetfile(), self)
+end
+
+-- make link flags for the given target
+function target:linkflags()
+
+ -- make flags
+ return self:linker():linkflags(self)
+end
+
+-- link target file
+function target:link(objectfiles)
+
+ -- link it
+ self:linker():link(objectfiles or self:objectfiles(), self:targetfile(), self)
+end
+
-- get the options
function target:options()
diff --git a/xmake/plugins/project/makefile/makefile.lua b/xmake/plugins/project/makefile/makefile.lua
index 1c7ea5733..fd76227de 100755
--- a/xmake/plugins/project/makefile/makefile.lua
+++ b/xmake/plugins/project/makefile/makefile.lua
@@ -24,7 +24,6 @@
-- imports
import("core.tool.tool")
-import("core.tool.linker")
import("core.tool.compiler")
import("core.project.config")
import("core.project.project")
@@ -160,13 +159,10 @@ function _make_target(makefile, target)
-- make dependence end
makefile:print("")
- -- make the command
- local command = linker.linkcmd(target:objectfiles(), targetfile, target)
-
-- make body
makefile:print("\t@echo linking.$(mode) %s", path.filename(targetfile))
_mkdir(makefile, path.directory(targetfile))
- makefile:print("\t@%s > %s 2>&1", command, _logfile())
+ makefile:print("\t@%s > %s 2>&1", target:linkcmd(), _logfile())
-- make headers
local srcheaders, dstheaders = target:headerfiles()