summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-02 09:35:37 +0800
committerruki <[email protected]>2015-06-02 09:35:37 +0800
commitf6177ffb405aa474e5d8e8af787778bd8ed8439c (patch)
treec4520100c7b617a4ef54f137f2f8acb13d98f5ab /xmake/scripts/base
parent52b7de2f4d73e08aba2fea79aa04bb06a9af449d (diff)
add linker and compiler common flags
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/main.lua16
-rw-r--r--xmake/scripts/base/makefile.lua81
-rw-r--r--xmake/scripts/base/project.lua1
3 files changed, 19 insertions, 79 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 2d4e0ea10..28e9ca14b 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -197,13 +197,21 @@ local menu =
, {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" }
, {}
- , {nil, "ld", "kv", nil, "The Linker" }
- , {nil, "ldflags", "kv", nil, "The Linker Flags" }
-
- , {}
, {nil, "as", "kv", nil, "The Assembler" }
, {nil, "asflags", "kv", nil, "The Assembler Flags" }
+ , {}
+ , {nil, "ld", "kv", nil, "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" }
+
+ , {}
+ , {nil, "ar", "kv", nil, "The Static Library Linker" }
+ , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" }
+
+ , {}
+ , {nil, "sh", "kv", nil, "The Shared Library Linker" }
+ , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" }
+
-- the options for all platforms
, function () return platform.menu("config") end
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 7d873665b..808ff819c 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -32,67 +32,6 @@ local config = require("base/config")
local project = require("base/project")
local platform = require("platform/platform")
--- get the linker from the given kind
-function makefile._linker(kind)
-
- -- init linkers
- makefile._LINKERS = makefile._LINKERS or {}
- local linkers = makefile._LINKERS
-
- -- return it directly if the linker has been cached
- local l = linkers[kind]
- if l then return l end
-
- -- get compiler from the current platform
- l = platform.linker(kind)
-
- -- cache this compiler
- linkers[kind] = l
-
- -- ok
- return l
-end
-
--- 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 compilers
- 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)
@@ -189,11 +128,11 @@ 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);
+ -- get the compiler and filetype
+ local c, filetype = platform.compiler(srcfile);
if not c then
-- error
- utils.error(errors)
+ utils.error("unknown source file: %s", srcfile)
return false
end
@@ -206,7 +145,7 @@ function makefile._make_object(file, target, srcfile, objfile)
-- make body
file:write(string.format("\t@echo [%s]: compiling %s\n", config.get("mode"), srcfile))
file:write(string.format("\t@xmake l mkdir %s\n", path.directory(objfile)))
- file:write(string.format("\t@%s\n", c:make(srcfile, objfile, "")))
+ file:write(string.format("\t@%s\n", c:make(filetype, srcfile, objfile, "")))
-- make tail
file:write("\n")
@@ -254,17 +193,9 @@ function makefile._make_target(file, name, target)
assert(targetfile)
-- the linker
- local l = makefile._linker(target.kind)
+ local l = platform.linker(target.kind)
assert(l)
- -- the make command
- local make_command = l["make_" .. target.kind]
- if not make_command then
- -- error
- utils.error("the target kind: %s in not surpported now!", target.kind)
- return false
- end
-
-- make head
file:write(string.format("%s:", name))
@@ -287,7 +218,7 @@ function makefile._make_target(file, name, target)
-- make body
file:write(string.format("\t@echo [%s]: linking %s\n", config.get("mode"), path.filename(targetfile)))
file:write(string.format("\t@xmake l mkdir %s\n", path.directory(targetfile)))
- file:write(string.format("\t@%s\n", make_command(l, objfiles, targetfile, "")))
+ file:write(string.format("\t@%s\n", l:make(target.kind, objfiles, targetfile, "")))
-- make tail
file:write("\n")
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 0b7783e2c..1ed00372b 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -163,6 +163,7 @@ function project.loadxproj(file)
, "mxflags"
, "mxxflags"
, "ldflags"
+ , "shflags"
, "defines"}
-- init filter