summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-12 12:45:43 +0800
committerruki <[email protected]>2015-06-12 12:45:43 +0800
commit1b9fc52acd62fea9dfa017481b146cf59993b1df (patch)
treecd3d531fc73051415e32877eca2f49d0b7c3e9fb /xmake/scripts
parent99b9eb72c8db9854311fc0b5a79e07f8cae85242 (diff)
update platform for linux
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/compiler.lua4
-rw-r--r--xmake/scripts/base/makefile.lua2
-rw-r--r--xmake/scripts/platform/linux/linux.lua31
-rw-r--r--xmake/scripts/platform/linux/prober.lua76
-rw-r--r--xmake/scripts/tools/tools.lua13
5 files changed, 111 insertions, 15 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua
index f0c71053f..bbf9a6106 100644
--- a/xmake/scripts/base/compiler.lua
+++ b/xmake/scripts/base/compiler.lua
@@ -371,13 +371,13 @@ function compiler.get(srcfile)
-- invalid compiler
if not module.command_compile then
- return nil, string.format("invalid compiler: %s", path.filename(platform.tool(kind)))
+ return nil, string.format("invalid compiler for %s", kind)
end
-- save kind
module._KIND = kind
else
- return nil, string.format("unknown compiler: %s", path.filename(platform.tool(kind)))
+ return nil, string.format("unknown compiler for %s", kind)
end
-- ok?
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 8be6334a5..4a91c0b3d 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -125,7 +125,7 @@ function makefile._make_target(file, name, target)
-- get the linker from the given kind
local l = linker.get(target.kind)
- assert(l)
+ if not l then return false end
-- make head
file:write(string.format("%s:", name))
diff --git a/xmake/scripts/platform/linux/linux.lua b/xmake/scripts/platform/linux/linux.lua
index 6c68a6f1b..40f9b5999 100644
--- a/xmake/scripts/platform/linux/linux.lua
+++ b/xmake/scripts/platform/linux/linux.lua
@@ -43,15 +43,30 @@ function linux.make(configs)
-- init the toolchains
configs.tools = {}
- configs.tools.make = "make"
+ configs.tools.make = config.get("make")
configs.tools.ccache = config.get("__ccache")
- configs.tools.cc = config.get("cc") or "gcc"
- configs.tools.cxx = config.get("cxx") or "g++"
- configs.tools.mm = config.get("mm") or configs.tools.cc
- configs.tools.mxx = config.get("mxx") or configs.tools.cxx
- configs.tools.ld = config.get("ld") or "g++"
- configs.tools.ar = config.get("ar") or "ar"
- configs.tools.sh = config.get("sh") or "g++"
+ configs.tools.cc = config.get("cc")
+ configs.tools.cxx = config.get("cxx")
+ configs.tools.mm = config.get("mm")
+ configs.tools.mxx = config.get("mxx")
+ configs.tools.ld = config.get("ld")
+ configs.tools.ar = config.get("ar")
+ configs.tools.sh = config.get("sh")
+
+ -- init flags for architecture
+ local archflags = nil
+ local arch = config.get("arch")
+ if arch then
+ if arch == "x64" then archflags = "-m64"
+ elseif arch == "x86" then archflags = "-m32"
+ else archflags = "-arch " .. arch
+ end
+ end
+ configs.cxflags = { archflags }
+ configs.mxflags = { archflags }
+ configs.asflags = { archflags }
+ configs.ldflags = { archflags }
+ configs.shflags = { archflags }
end
diff --git a/xmake/scripts/platform/linux/prober.lua b/xmake/scripts/platform/linux/prober.lua
index 9f18ccd15..ce23dadb5 100644
--- a/xmake/scripts/platform/linux/prober.lua
+++ b/xmake/scripts/platform/linux/prober.lua
@@ -51,6 +51,26 @@ function prober._probe_arch(configs)
return true
end
+-- probe the make
+function prober._probe_make(configs)
+
+ -- ok?
+ local make = configs.get("make")
+ if make then return true end
+
+ -- probe the make path
+ make = tools.probe("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"})
+
+ -- probe ok? update it
+ if make then configs.set("make", make) end
+
+ -- trace
+ utils.verbose("checking for the make ... %s", utils.ifelse(make, make, "no"))
+
+ -- ok
+ return true
+end
+
-- probe the ccache
function prober._probe_ccache(configs)
@@ -82,12 +102,63 @@ function prober._probe_ccache(configs)
return true
end
+-- probe the tool path
+function prober._probe_toolpath(configs, kind, cross, name, description)
+
+ -- check
+ assert(kind)
+
+ -- get the cross
+ cross = configs.get("cross") or cross
+
+ -- attempt to get it from the given cross toolchains
+ local toolpath = nil
+ local toolchains = configs.get("toolchains")
+ if toolchains then
+ toolpath = tools.probe(cross .. (configs.get(kind) or name), toolchains)
+ end
+
+ -- attempt to get it directly from the configure
+ if not toolpath then
+ toolpath = configs.get(kind)
+ end
+
+ -- attempt to run it directly
+ if not toolpath then
+ toolpath = tools.probe(cross .. name)
+ end
+
+ -- probe ok? update it
+ if toolpath then configs.set(kind, toolpath) end
+
+ -- trace
+ utils.verbose("checking for %s (%s) ... %s", description, kind, utils.ifelse(toolpath, path.filename(toolpath), "no"))
+
+ -- ok
+ return true
+end
+
+-- probe the toolchains
+function prober._probe_toolchains(configs)
+
+ -- done
+ if not prober._probe_toolpath(configs, "cc", "", "gcc", "the c compiler") then return false end
+ if not prober._probe_toolpath(configs, "cxx", "", "g++", "the c++ compiler") then return false end
+ if not prober._probe_toolpath(configs, "as", "", "gcc", "the assember") then return false end
+ if not prober._probe_toolpath(configs, "ld", "", "g++", "the linker") then return false end
+ if not prober._probe_toolpath(configs, "ar", "", "ar", "the static library linker") then return false end
+ if not prober._probe_toolpath(configs, "sh", "", "g++", "the shared library linker") then return false end
+ return true
+end
+
-- probe the project configure
function prober.config()
-- call all probe functions
utils.call( { prober._probe_arch
- , prober._probe_ccache}
+ , prober._probe_make
+ , prober._probe_ccache
+ , prober._probe_toolchains}
, nil
, config)
end
@@ -96,7 +167,8 @@ end
function prober.global()
-- call all probe functions
- utils.call( prober._probe_ccache
+ utils.call( { prober._probe_make
+ , prober._probe_ccache}
, nil
, global)
end
diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua
index 3dafcd749..862397704 100644
--- a/xmake/scripts/tools/tools.lua
+++ b/xmake/scripts/tools/tools.lua
@@ -171,8 +171,17 @@ function tools.load(name, root)
end
-- get the given tool from the current platform
-function tools.get(name)
- return tools.load(platform.tool(name))
+function tools.get(kind)
+
+ -- get the tool name
+ local toolname = platform.tool(kind)
+ if not toolname then
+ utils.error("cannot get tool name for %s", kind)
+ return
+ end
+
+ -- load it
+ return tools.load(toolname)
end
-- probe it's absolute path if exists from the given tool name