summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-02 10:50:54 +0800
committerruki <[email protected]>2015-06-02 10:50:54 +0800
commit4b85064e874d050de835f4a4a0b2158f1405a6aa (patch)
treec3f0ccec578302d4ad215198014d7f6331975546
parentbf6315e4e63270175eb27d9ab73dc98f3408cea8 (diff)
reimpl unique for flags
-rw-r--r--tests/console/xmake.xproj10
-rw-r--r--xmake/scripts/base/utils.lua30
-rw-r--r--xmake/scripts/compiler/_clang.lua14
-rw-r--r--xmake/scripts/compiler/compiler.lua26
-rw-r--r--xmake/scripts/linker/_clang.lua14
-rw-r--r--xmake/scripts/linker/linker.lua22
6 files changed, 86 insertions, 30 deletions
diff --git a/tests/console/xmake.xproj b/tests/console/xmake.xproj
index aae24e89e..ac39513b0 100644
--- a/tests/console/xmake.xproj
+++ b/tests/console/xmake.xproj
@@ -54,8 +54,8 @@ project: console
deps: hello1
files: src/demo/*.c
links: hello1
- linkdirs: src/hello1
- includedirs: src/hello1
+ linkdirs: $(buildir)/src/hello1
+ includedirs: $(buildir)/src/hello1
cflags: -DHELLO1
# the modes
@@ -71,8 +71,8 @@ project: console
deps: hello2
files: src/demo/*.cpp
links: hello2
- linkdirs: src/hello2
- includedirs: src/hello2
+ linkdirs: $(buildir)/src/hello2
+ includedirs: $(buildir)/src/hello2
cxxflags: -DHELLO1
}
@@ -93,7 +93,7 @@ project: console
deps: hello3
files: src/demo/*.mm
mxflags: -DHELLO3
- ldflags: -lhello3, -lhello3, -L$(buildir)/lib
+ ldflags: -L$(buildir)/lib, -lhello3, -lhello3
# the linux platform
platforms: linux
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 7e4322eb9..c51e9eeb2 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -153,8 +153,10 @@ end
-- wrap object to table
function utils.wrap(object)
- -- check
- assert(object)
+ -- no object?
+ if not object then
+ return {}
+ end
-- wrap it if not table
if type(object) ~= "table" then
@@ -176,24 +178,26 @@ function utils.unique(array)
-- not only one?
if table.getn(array) ~= 1 then
-
- -- make unique table
+
+ -- done
+ local exists = {}
local unique = {}
for _, v in ipairs(array) do
if type(v) == "string" then
- unique[v] = v
+ if not exists[v] then
+ exists[v] = true
+ unique[table.getn(unique) + 1] = v
+ end
else
- unique["\"" .. v .. "\""] = v
+ if not exists["\"" .. v .. "\""] then
+ exists["\"" .. v .. "\""] = true
+ unique[table.getn(unique) + 1] = v
+ end
end
end
- -- make array again
- array = {}
- local i = 1
- for _, v in pairs(unique) do
- array[i] = v
- i = i + 1
- end
+ -- update it
+ array = unique
end
end
diff --git a/xmake/scripts/compiler/_clang.lua b/xmake/scripts/compiler/_clang.lua
index b275f23b8..00b49c47f 100644
--- a/xmake/scripts/compiler/_clang.lua
+++ b/xmake/scripts/compiler/_clang.lua
@@ -66,6 +66,20 @@ function _clang._make(configs, srcfile, objfile, flags)
return string.format("%s -c %s -o%s %s", configs.name, flags, objfile, srcfile)
end
+-- make the define flag
+function _clang._make_define(configs, define)
+
+ -- make it
+ return "-D" .. define
+end
+
+-- make the includedir flag
+function _clang._make_includedir(configs, includedir)
+
+ -- make it
+ return "-I" .. includedir
+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 a4c5c59b7..ac25f176a 100644
--- a/xmake/scripts/compiler/compiler.lua
+++ b/xmake/scripts/compiler/compiler.lua
@@ -91,24 +91,34 @@ function compiler._make(self, target, filetype, srcfile, objfile)
for _, flag_name in ipairs(flag_names) do
-- get flags
- local flags = target[flag_name]
- if flags then
- flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ")
- end
+ local flags = table.concat(compiler._mapflags(self, utils.wrap(target[flag_name])), " ")
-- append flags
flags_target = string.format("%s %s", flags_target, flags or "")
end
+ -- get the includedirs flags from the current project
+ if self._make_includedir then
+ local includedirs = utils.wrap(target.includedirs)
+ for _, includedir in ipairs(includedirs) do
+ flags_target = string.format("%s %s", flags_target, self._make_includedir(configs, includedir))
+ end
+ end
+
+ -- get the defines flags from the current project
+ if self._make_define then
+ local defines = utils.wrap(target.defines)
+ for _, define in ipairs(defines) do
+ flags_target = string.format("%s %s", flags_target, self._make_define(configs, define))
+ end
+ end
+
-- get the config flags
local flags_config = ""
for _, flag_name in ipairs(flag_names) do
-- get flags
- local flags = config.get(flag_name)
- if flags then
- flags = table.concat(compiler._mapflags(self, utils.wrap(flags)), " ")
- end
+ local flags = table.concat(compiler._mapflags(self, utils.wrap(config.get(flag_name))), " ")
-- append flags
flags_config = string.format("%s %s", flags_config, flags or "")
diff --git a/xmake/scripts/linker/_clang.lua b/xmake/scripts/linker/_clang.lua
index 0f9ce3fff..c5d778e04 100644
--- a/xmake/scripts/linker/_clang.lua
+++ b/xmake/scripts/linker/_clang.lua
@@ -57,6 +57,20 @@ function _clang._make(configs, objfiles, targetfile, flags)
return string.format("%s %s -o%s %s", configs.name, flags, objfiles, targetfile)
end
+-- make the link flag
+function _clang._make_link(configs, link)
+
+ -- make it
+ return "-l" .. link
+end
+
+-- make the linkdir flag
+function _clang._make_linkdir(configs, linkdir)
+
+ -- make it
+ return "-L" .. linkdir
+end
+
-- map gcc flag to the current linker flag
function _clang._mapflag(configs, flag)
diff --git a/xmake/scripts/linker/linker.lua b/xmake/scripts/linker/linker.lua
index 22b4c5ea1..15a15fdc3 100644
--- a/xmake/scripts/linker/linker.lua
+++ b/xmake/scripts/linker/linker.lua
@@ -85,13 +85,27 @@ function linker._make(self, target, objfiles, targetfile)
local flags_common = configs[flag_name] or ""
-- get the target flags from the current project
- local flags_target = target[flag_name] or ""
- flags_target = table.concat(linker._mapflags(self, utils.wrap(flags_target)), " ")
+ local flags_target = table.concat(linker._mapflags(self, utils.wrap(target[flag_name])), " ")
assert(flags_target)
+ -- get the linkdirs flags from the current project
+ if self._make_linkdir then
+ local linkdirs = utils.wrap(target.linkdirs)
+ for _, linkdir in ipairs(linkdirs) do
+ flags_target = string.format("%s %s", flags_target, self._make_linkdir(configs, linkdir))
+ end
+ end
+
+ -- get the links flags from the current project
+ if self._make_link then
+ local links = utils.wrap(target.links)
+ for _, link in ipairs(links) do
+ flags_target = string.format("%s %s", flags_target, self._make_link(configs, link))
+ end
+ end
+
-- get the config flags
- local flags_config = config.get(flag_name) or ""
- flags_config = table.concat(linker._mapflags(self, utils.wrap(flags_config)), " ")
+ local flags_config = table.concat(linker._mapflags(self, utils.wrap(config.get(flag_name))), " ")
assert(flags_config)
-- make the flags string