summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-14 09:00:26 +0800
committerruki <[email protected]>2017-02-14 09:00:26 +0800
commit5e23aa6f9344b21dee98ad3fad9182808d690485 (patch)
tree2592b6b087dce76b6447d4de2a5a1446b6c98169
parentf7eaf51c4cad7d94989e130de2172df2cbc74193 (diff)
modify interface for compiling multiple source files
-rwxr-xr-xtests/tests3
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/compiler.lua48
-rw-r--r--xmake/core/tool/compiler.lua10
-rwxr-xr-xxmake/tools/cl.lua26
-rwxr-xr-xxmake/tools/gcc.lua46
-rwxr-xr-xxmake/tools/go.lua50
-rwxr-xr-xxmake/tools/ml.lua25
-rw-r--r--xmake/tools/swiftc.lua26
8 files changed, 175 insertions, 59 deletions
diff --git a/tests/tests b/tests/tests
index b5f16fef7..0302826aa 100755
--- a/tests/tests
+++ b/tests/tests
@@ -49,7 +49,8 @@ build "./tests/static_library_c++"
build "./tests/shared_library_c++"
# build for go
-build "./tests/console_go"
+# build "./tests/console_go"
+# build "./tests/static_library_go"
# merge object
build "./tests/merge_object"
diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
index 6dc7f6faf..a3ae9d69b 100644
--- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua
+++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
@@ -33,45 +33,61 @@ local raise = require("sandbox/modules/raise")
local assert = require("sandbox/modules/assert")
-- make command for compiling source file
-function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target)
+function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target, sourcekind)
+
+ -- get source kind if only one source file
+ if not sourcekind and type(sourcefiles) == "string" then
+ sourcekind = language.sourcekind_of(sourcefiles)
+ end
-- get the compiler instance
- local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile)))
+ local instance, errors = compiler.load(sourcekind)
if not instance then
raise(errors)
end
-- make command
- return instance:compcmd(sourcefile, objectfile, target)
+ return instance:compcmd(sourcefiles, objectfile, target)
end
--- make compiling flags for the given target
-function sandbox_core_tool_compiler.compflags(sourcefile, target)
+-- compile source files
+function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfiles, target, sourcekind)
+
+ -- get source kind if only one source file
+ if not sourcekind and type(sourcefiles) == "string" then
+ sourcekind = language.sourcekind_of(sourcefiles)
+ end
-- get the compiler instance
- local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile)))
+ local instance, errors = compiler.load(sourcekind)
if not instance then
raise(errors)
end
- -- make flags
- return instance:compflags(target)
+ -- compile it
+ local ok, errors = instance:compile(sourcefiles, objectfile, incdepfiles, target)
+ if not ok then
+ raise(errors)
+ end
end
--- compile source file
-function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target)
+-- TODO modify: compflags(sourcekind, target)
+-- make compiling flags for the given target
+function sandbox_core_tool_compiler.compflags(sourcefiles, target, sourcekind)
+
+ -- get source kind if only one source file
+ if not sourcekind and type(sourcefiles) == "string" then
+ sourcekind = language.sourcekind_of(sourcefiles)
+ end
-- get the compiler instance
- local instance, errors = compiler.load(assert(language.sourcekind_of(sourcefile)))
+ local instance, errors = compiler.load(sourcekind)
if not instance then
raise(errors)
end
- -- compile it
- local ok, errors = instance:compile(sourcefile, objectfile, incdepfile, target)
- if not ok then
- raise(errors)
- end
+ -- make flags
+ return instance:compflags(target)
end
-- return module
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index cf175e622..18af4adb4 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -104,18 +104,18 @@ function compiler.load(sourcekind)
return instance
end
--- compile the source file
-function compiler:compile(sourcefile, objectfile, incdepfile, target)
+-- compile the source files
+function compiler:compile(sourcefiles, objectfile, incdepfiles, target)
-- compile it
- return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, (self:compflags(target)))
+ return sandbox.load(self:_tool().compile, sourcefiles, objectfile, incdepfiles, (self:compflags(target)))
end
-- get the compile command
-function compiler:compcmd(sourcefile, objectfile, target)
+function compiler:compcmd(sourcefiles, objectfile, target)
-- get it
- return self:_tool().compcmd(sourcefile, objectfile, (self:compflags(target)))
+ return self:_tool().compcmd(sourcefiles, objectfile, (self:compflags(target)))
end
-- get the compling flags
diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index 963bf3447..12016b421 100755
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -218,14 +218,14 @@ function nf_includedir(dir)
end
-- make the complie command
-function compcmd(sourcefile, objectfile, flags)
+function _compcmd1(sourcefile, objectfile, flags)
-- make it
return format("%s -c %s -Fo%s %s", _g.shellname, flags, objectfile, sourcefile)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags)
+function _compile1(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
@@ -239,7 +239,7 @@ function compile(sourcefile, objectfile, incdepfile, flags)
local outdata = try
{
function ()
- return os.iorun(compcmd(sourcefile, objectfile, flags))
+ return os.iorun(_compcmd1(sourcefile, objectfile, flags))
end,
catch
@@ -285,6 +285,26 @@ function compile(sourcefile, objectfile, incdepfile, flags)
end
end
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfiles, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfiles, flags)
+end
+
-- check the given flags
function check(flags)
diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua
index 6ad26c04e..0f555245d 100755
--- a/xmake/tools/gcc.lua
+++ b/xmake/tools/gcc.lua
@@ -245,8 +245,18 @@ function linkcmd(objectfiles, targetfile, flags)
return format("%s -o %s %s %s", _g.shellname, targetfile, objectfiles, flags)
end
+-- link the target file
+function link(objectfiles, targetfile, flags)
+
+ -- ensure the target directory
+ os.mkdir(path.directory(targetfile))
+
+ -- link it
+ os.run(linkcmd(objectfiles, targetfile, flags))
+end
+
-- make the complie command
-function compcmd(sourcefile, objectfile, flags)
+function _compcmd1(sourcefile, objectfile, flags)
-- get ccache
local ccache = nil
@@ -264,18 +274,8 @@ function compcmd(sourcefile, objectfile, flags)
return command
end
--- link the target file
-function link(objectfiles, targetfile, flags)
-
- -- ensure the target directory
- os.mkdir(path.directory(targetfile))
-
- -- link it
- os.run(linkcmd(objectfiles, targetfile, flags))
-end
-
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags)
+function _compile1(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
@@ -284,7 +284,7 @@ function compile(sourcefile, objectfile, incdepfile, flags)
try
{
function ()
- local outdata, errdata = os.iorun(compcmd(sourcefile, objectfile, flags))
+ local outdata, errdata = os.iorun(_compcmd1(sourcefile, objectfile, flags))
return (outdata or "") .. (errdata or "")
end,
finally
@@ -347,6 +347,26 @@ function compile(sourcefile, objectfile, incdepfile, flags)
end
end
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfiles, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfiles, flags)
+end
+
-- check the given flags
function check(flags)
diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua
index c81a0c206..1703862b1 100755
--- a/xmake/tools/go.lua
+++ b/xmake/tools/go.lua
@@ -69,13 +69,6 @@ function linkcmd(objectfiles, targetfile, flags)
return format("%s tool link %s -o %s %s", _g.shellname, flags, targetfile, objectfiles)
end
--- make the complie command
-function compcmd(sourcefile, objectfile, flags)
-
- -- make it
- return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, sourcefile)
-end
-
-- make the archive command
function archivecmd(objectfiles, targetfile, flags)
@@ -103,24 +96,51 @@ function link(objectfiles, targetfile, flags)
os.run(linkcmd(objectfiles, targetfile, flags))
end
+-- archive the library file
+function archive(objectfiles, targetfile, flags)
+
+ -- ensure the target directory
+ os.mkdir(path.directory(targetfile))
+
+ -- link it
+ os.run(archivecmd(objectfiles, targetfile, flags))
+end
+
+-- make the complie command
+function _compcmd1(sourcefile, objectfile, flags)
+
+ -- make it
+ return format("%s tool compile %s -o %s %s", _g.shellname, flags, objectfile, sourcefile)
+end
+
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags)
+function _compile1(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
- os.run(compcmd(sourcefile, objectfile, flags))
+ os.run(_compcmd1(sourcefile, objectfile, flags))
end
--- archive the library file
-function archive(objectfiles, targetfile, flags)
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
- -- ensure the target directory
- os.mkdir(path.directory(targetfile))
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
- -- link it
- os.run(archivecmd(objectfiles, targetfile, flags))
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfiles, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfiles, flags)
end
-- check the given flags
diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua
index 372a84ac4..9a5f6ae7e 100755
--- a/xmake/tools/ml.lua
+++ b/xmake/tools/ml.lua
@@ -103,22 +103,41 @@ function nf_includedir(dir)
end
-- make the complie command
-function compcmd(sourcefile, objectfile, flags)
+function _compcmd1(sourcefile, objectfile, flags)
-- make it
return format("%s -c %s -Fo%s %s", _g.shellname, flags, objectfile, sourcefile)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags)
+function _compile1(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
- os.run(compcmd(sourcefile, objectfile, flags))
+ os.run(_compcmd1(sourcefile, objectfile, flags))
end
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfiles, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfiles, flags)
+end
-- check the given flags
function check(flags)
diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua
index 266c64cf4..f5dec36aa 100644
--- a/xmake/tools/swiftc.lua
+++ b/xmake/tools/swiftc.lua
@@ -173,7 +173,7 @@ function nf_framework(framework)
end
-- make the compile command
-function compcmd(sourcefile, objectfile, flags)
+function _compcmd1(sourcefile, objectfile, flags)
-- get ccache
local ccache = nil
@@ -192,13 +192,33 @@ function compcmd(sourcefile, objectfile, flags)
end
-- complie the source file
-function compile(sourcefile, objectfile, incdepfile, flags)
+function _compile1(sourcefile, objectfile, incdepfile, flags)
-- ensure the object directory
os.mkdir(path.directory(objectfile))
-- compile it
- os.run(compcmd(sourcefile, objectfile, flags))
+ os.run(_compcmd1(sourcefile, objectfile, flags))
+end
+
+-- make the complie command
+function compcmd(sourcefiles, objectfile, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ return _compcmd1(sourcefiles, objectfile, flags)
+end
+
+-- complie the source file
+function compile(sourcefiles, objectfile, incdepfiles, flags)
+
+ -- only support single source file now
+ assert(type(sourcefiles) == "string", "not support")
+
+ -- for only single source file
+ _compile1(sourcefiles, objectfile, incdepfiles, flags)
end
-- check the given flags