summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/makefile.lua
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/base/makefile.lua
parent9aa34cbeaac0f6117fc0879a4f5f7059438da3c1 (diff)
load compiler and make command
Diffstat (limited to 'xmake/scripts/base/makefile.lua')
-rw-r--r--xmake/scripts/base/makefile.lua51
1 files changed, 50 insertions, 1 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")