summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-30 15:18:19 +0800
committerruki <[email protected]>2015-05-30 15:18:19 +0800
commit87683f4d3ba6d41c0b8900244e05dee4f84e2e62 (patch)
tree43829a15b7bf2e7311302af6d826408bcdbad38d /xmake/scripts
parent9aa34cbeaac0f6117fc0879a4f5f7059438da3c1 (diff)
load compiler and make command
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/makefile.lua51
-rw-r--r--xmake/scripts/compiler/_clang.lua7
-rw-r--r--xmake/scripts/compiler/compiler.lua17
-rw-r--r--xmake/scripts/platform/platform.lua22
4 files changed, 95 insertions, 2 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 04e237a74..8a14c1d90 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -32,6 +32,46 @@ local config = require("base/config")
local project = require("base/project")
local platform = require("platform/platform")
+-- get the compiler from the given source file
+function makefile._compiler(srcfile)
+
+ -- get the source file type
+ local filetype = path.extension(srcfile)
+ if not filetype then
+ return nil, string.format("cannot get the source file type: %s", srcfile)
+ end
+
+ -- get the lower file type
+ filetype = filetype:lower()
+
+ -- get the compiler name
+ local name = nil
+ if filetype == ".c" then name = "cc"
+ elseif filetype == ".cpp" or filetype == ".cc" then name = "cxx"
+ elseif filetype == ".m" then name = "mm"
+ elseif filetype == ".mm" then name = "mxx"
+ elseif filetype == ".s" or filetype == ".asm" then name = "as"
+ else return nil, string.format("unknown file type: %s", filetype)
+ end
+
+ -- init compiler
+ makefile._COMPILERS = makefile._COMPILERS or {}
+ local compilers = makefile._COMPILERS
+
+ -- return it directly if the compiler has been cached
+ local c = compilers[name]
+ if c then return c end
+
+ -- get compiler from the current platform
+ c = platform.compiler(name)
+
+ -- cache this compiler
+ compilers[name] = c
+
+ -- ok
+ return c
+end
+
-- get the source files from the given target
function makefile._srcfiles(target)
@@ -153,6 +193,14 @@ function makefile._make_object(file, target, srcfile, objfile)
-- check
assert(file and target and srcfile and objfile)
+ -- get the compiler
+ local c, errors = makefile._compiler(srcfile);
+ if not c then
+ -- error
+ utils.error(errors)
+ return false
+ end
+
-- make head
file:write(string.format("%s:", objfile))
@@ -160,7 +208,8 @@ function makefile._make_object(file, target, srcfile, objfile)
file:write(string.format(" %s\n", srcfile))
-- make body
- file:write(string.format("\techo \"%s\"\n", srcfile))
+ file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile))
+ file:write(string.format("\t@%s\n", c:make(srcfile, objfile, "")))
-- make tail
file:write("\n")
diff --git a/xmake/scripts/compiler/_clang.lua b/xmake/scripts/compiler/_clang.lua
index 27f9b868f..6bfa83d69 100644
--- a/xmake/scripts/compiler/_clang.lua
+++ b/xmake/scripts/compiler/_clang.lua
@@ -33,6 +33,13 @@ function _clang._init(configs)
end
+-- make the compiler command
+function _clang._make(configs, srcfile, objfile, flags)
+
+ -- make it
+ return string.format("%s -c %s -o%s %s", configs.name, flags, objfile, srcfile)
+end
+
-- map gcc flag to the current compiler flag
function _clang._mapflag(configs, flag)
diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua
index bc84c177f..2be9eaf45 100644
--- a/xmake/scripts/compiler/compiler.lua
+++ b/xmake/scripts/compiler/compiler.lua
@@ -42,6 +42,20 @@ function compiler._get(self, name)
return configs[name]
end
+-- make the compile command
+function compiler._make(self, srcfile, objfile, flags)
+
+ -- check
+ assert(self);
+
+ -- the configure
+ local configs = self._CONFIGS
+ assert(configs)
+
+ -- get it
+ return self._make(configs, srcfile, objfile, flags)
+end
+
-- map gcc flags to the given compiler flags
function compiler._mapflags(self, flags)
@@ -68,7 +82,7 @@ function compiler._mapflags(self, flags)
end
-- ok?
- return flag_mapped;
+ return flag_mapped
end
-- load the given compiler
@@ -116,6 +130,7 @@ function compiler.load(name)
-- init interfaces
c["get"] = compiler._get
+ c["make"] = compiler._make
c["mapflags"] = compiler._mapflags
-- ok?
diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua
index 064138d45..920aeab14 100644
--- a/xmake/scripts/platform/platform.lua
+++ b/xmake/scripts/platform/platform.lua
@@ -28,6 +28,7 @@ local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
local config = require("base/config")
+local compiler = require("compiler/compiler")
-- load the given platform
function platform._load(plat)
@@ -88,13 +89,34 @@ end
-- get the format from the given kind
function platform.format(kind)
+ -- check
+ assert(kind)
+
-- get format
local format = platform.get("format")
+ assert(format)
-- get it
return format[kind] or {"", ""}
end
+-- get the compiler from the given name
+function platform.compiler(name)
+
+ -- check
+ assert(name)
+
+ -- get compiler
+ local c = platform.get("compiler")
+ assert(c)
+
+ -- load compiler
+ c = c[name]
+ if c then
+ return compiler.load(c)
+ end
+end
+
-- dump the platform configure
function platform.dump()