summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-05 10:18:00 +0800
committerruki <[email protected]>2015-06-05 10:18:00 +0800
commit12ce7dea3c7a74f77e9792236cb85bab4fd001e4 (patch)
treea64fd1ef7c1380ae63e5c982472e8712489b3374 /xmake/scripts/base
parentf9cecfd11c958122bb6d619069593b91333bdf6f (diff)
add ccache
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/main.lua18
-rw-r--r--xmake/scripts/base/makefile.lua29
2 files changed, 38 insertions, 9 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 2bd243ac4..96c3eac00 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -182,8 +182,12 @@ local menu =
, {'-', "host", "kv", xmake._HOST, "The current host environment." }
, {}
- , {'o', "buildir", "kv", "build", "Set the build directory" }
- , {'k', "packages", "kv", "pkg", "Set the packages directory" }
+ , {'o', "buildir", "kv", "build", "Set the build directory." }
+ , {'k', "packages", "kv", "pkg", "Set the packages directory." }
+
+ , {}
+ , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache."
+ , " --ccache=[y|n]" }
, {}
, {nil, "cross", "kv", nil, "The cross toolchains prefix"
@@ -252,16 +256,18 @@ local menu =
-- options
, options =
{
- {'c', "clean", "k", nil, "Clean the cached configure and configure all again." }
+ {'c', "clean", "k", nil, "Clean the cached configure and configure all again." }
+ , {nil, "ccache", "kv", "auto", "Enable or disable the c/c++ compiler cache."
+ , " --ccache=[y|n]" }
, {}
-- the options for all platforms
, function () return platform.menu("global") end
, {}
- , {'v', "verbose", "k", nil, "Print lots of verbose information." }
- , {nil, "version", "k", nil, "Print the version number and exit." }
- , {'h', "help", "k", nil, "Print this help message and exit." }
+ , {'v', "verbose", "k", nil, "Print lots of verbose information." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
}
}
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index c3af02d05..275e15d07 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -34,6 +34,7 @@ local project = require("base/project")
local linker = require("base/linker")
local compiler = require("base/compiler")
local tools = require("tools/tools")
+local platform = require("platform/platform")
-- make the object to the makefile
function makefile._make_object(file, target, srcfile, objfile)
@@ -49,6 +50,22 @@ function makefile._make_object(file, target, srcfile, objfile)
return false
end
+ -- get mode
+ local mode = config.get("mode") or ""
+ if mode == "release" then mode = ".r"
+ elseif mode == "debug" then mode = ".d"
+ elseif mode == "profile" then mode = ".p"
+ else mode = "" end
+
+ -- get ccache
+ local ccache = platform.tool("ccache")
+
+ -- make command
+ local cmd = compiler.make(c, target, srcfile, objfile)
+ if ccache then
+ cmd = ccache:append(cmd, " ")
+ end
+
-- make head
file:write(string.format("%s:", objfile))
@@ -56,8 +73,7 @@ function makefile._make_object(file, target, srcfile, objfile)
file:write(string.format(" %s\n", srcfile))
-- make body
- local cmd = compiler.make(c, target, srcfile, objfile)
- file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile))
+ file:write(string.format("\t@echo %scompiling%s %s\n", utils.ifelse(ccache, "ccache ", ""), mode, srcfile))
file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("%s", "%%20")))
file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile)))
file:write(string.format("\t@%s > %s 2>&1\n", cmd, makefile._LOGFILE))
@@ -130,9 +146,16 @@ function makefile._make_target(file, name, target)
-- make dependence end
file:write("\n")
+ -- get mode
+ local mode = config.get("mode") or ""
+ if mode == "release" then mode = ".r"
+ elseif mode == "debug" then mode = ".d"
+ elseif mode == "profile" then mode = ".p"
+ else mode = "" end
+
-- make body
local cmd = linker.make(l, target, objfiles, targetfile)
- file:write(string.format("\t@echo [%s]: linking %s\n", config.get("mode"), path.filename(targetfile)))
+ file:write(string.format("\t@echo linking%s %s\n", mode, path.filename(targetfile)))
file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("%s", "%%20")))
file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile)))
file:write(string.format("\t@%s > %s 2>&1\n", cmd, makefile._LOGFILE))