summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-09 16:00:21 +0800
committerruki <[email protected]>2015-06-09 16:00:21 +0800
commite18c9d7a5718c80852fab0eb89161b4da28b7a94 (patch)
tree97f3b07c525cb8f1b91a5ca5a13b729d6b0fc7e1
parentbf0040998da482cb640a3637fd91e36a0495b27b (diff)
fix defines bug
-rw-r--r--tests/console/xmake.lua5
-rw-r--r--xmake/scripts/base/clean.lua8
-rw-r--r--xmake/scripts/base/project.lua38
3 files changed, 30 insertions, 21 deletions
diff --git a/tests/console/xmake.lua b/tests/console/xmake.lua
index 40a940830..6d69379da 100644
--- a/tests/console/xmake.lua
+++ b/tests/console/xmake.lua
@@ -1,4 +1,5 @@
version("1.0.1")
+configfile("$(buildir)/demo.h")
if modes("debug") then
symbols("debug")
@@ -22,6 +23,10 @@ if modes("profile") then
optimize("fastest")
end
+if archs("x86", "x64") then
+ defines("ARCH=\"$(arch)\"", "PLAT=$(plat)", "MODE=$(mode)", "HOST=$(host)")
+end
+
target("hello1")
kind("static")
files("src/hello1/*.c")
diff --git a/xmake/scripts/base/clean.lua b/xmake/scripts/base/clean.lua
index e31466bdc..3426dc41e 100644
--- a/xmake/scripts/base/clean.lua
+++ b/xmake/scripts/base/clean.lua
@@ -61,13 +61,7 @@ function clean._remove_target(target_name, target, target_only, buildir)
-- check
assert(target_name and target)
-
- -- remove the configure file
- local configfile = rule.configfile(target)
- if configfile and not clean._remove(configfile) then
- return false
- end
-
+
-- remove the target file
if not clean._remove(rule.targetfile(target_name, target, buildir)) then
return false
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 09bdecd1b..ea4924360 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -37,7 +37,7 @@ function project._api_modes(env, ...)
assert(mode)
-- exists this mode?
- for _, m in ipairs(utils.wrap(...)) do
+ for _, m in ipairs(table.join(...)) do
if m and type(m) == "string" and m == mode then
return true
end
@@ -52,7 +52,7 @@ function project._api_plats(env, ...)
assert(plat)
-- exists this platform?
- for _, p in ipairs(utils.wrap(...)) do
+ for _, p in ipairs(table.join(...)) do
if p and type(p) == "string" and p == plat then
return true
end
@@ -67,7 +67,8 @@ function project._api_archs(env, ...)
assert(arch)
-- exists this architecture?
- for _, a in ipairs(utils.wrap(...)) do
+ for _, a in ipairs(table.join(...)) do
+ print(a, arch)
if a and type(a) == "string" and a == arch then
return true
end
@@ -81,7 +82,7 @@ function project._api_subdirs(env, ...)
assert(env)
-- done
- for _, subdir in ipairs(utils.wrap(...)) do
+ for _, subdir in ipairs(table.join(...)) do
if subdir and type(subdir) == "string" then
-- the project file
@@ -115,7 +116,7 @@ function project._api_subfiles(env, ...)
assert(env)
-- done
- for _, subfile in ipairs(utils.wrap(...)) do
+ for _, subfile in ipairs(table.join(...)) do
if subfile and type(subfile) == "string" then
-- the project file
@@ -197,10 +198,9 @@ function project._filter(values)
local newvals = {}
for _, v in ipairs(utils.wrap(values)) do
v = v:gsub("%$%((.*)%)", function (w)
- if w == "buildir" then
- return config.get("buildir")
- elseif w == "projectdir" then
- return xmake._PROJECT_DIR
+ local r = config.get(w)
+ if r and type(r) == "string" then return r
+ elseif w == "projectdir" then return xmake._PROJECT_DIR
end
end)
table.insert(newvals, v)
@@ -231,11 +231,12 @@ function project._makeconf_for_target(target_name, target)
-- the prefix
local prefix = target_name:upper() .. "_CONFIG"
-
+
-- open the file
- local file = io.open(configfile, "w")
+ local file = project._CONFILES[configfile] or io.open(configfile, "w")
-- make the head
+ if project._CONFILES[configfile] then file:write("\n") end
file:write(string.format("#ifndef %s_H\n", prefix))
file:write(string.format("#define %s_H\n", prefix))
file:write("\n")
@@ -268,7 +269,7 @@ function project._makeconf_for_target(target_name, target)
if target.defines then
file:write("// defines\n")
for _, define in ipairs(utils.wrap(target.defines)) do
- file:write(string.format("#define %s\n", define))
+ file:write(string.format("#define %s\n", define:gsub("=", " ")))
end
file:write("\n")
end
@@ -276,8 +277,8 @@ function project._makeconf_for_target(target_name, target)
-- make the tail
file:write("#endif\n")
- -- exit the file
- file:close()
+ -- cache the file
+ project._CONFILES[configfile] = file
-- ok
return true
@@ -468,6 +469,9 @@ end
-- make the configure file for the given target
function project.makeconf(target_name)
+ -- init files
+ project._CONFILES = project._CONFILES or {}
+
-- the target name
if target_name and target_name ~= "all" then
-- make configure for the target and dependents
@@ -483,6 +487,12 @@ function project.makeconf(target_name)
if not project._makeconf_for_target(target_name, target) then return false end
end
end
+
+ -- exit files
+ for _, file in pairs(project._CONFILES) do
+ file:close()
+ end
+ project._CONFILES = nil
-- ok
return true