summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-03 09:29:35 +0800
committerruki <[email protected]>2015-06-03 09:29:35 +0800
commit08bba742c061c93f28c14499fa17af2f1edc2df8 (patch)
tree769eb97f37ada860b6e4c29f6ca247ccf70cbdbc
parent03f445c175b2f8e4768bbff28065f935b9fe3201 (diff)
add private configure for preprocessor
-rwxr-xr-x.gitignore2
-rwxr-xr-xcore/src/xmake/machine.c2
-rwxr-xr-xcore/src/xmake/makefile1
-rwxr-xr-xcore/src/xmake/os/setenv.c53
-rw-r--r--xmake/scripts/base/config.lua8
-rw-r--r--xmake/scripts/base/global.lua4
-rw-r--r--xmake/scripts/base/preprocessor.lua36
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua1
8 files changed, 98 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index fad6a05ab..fe82d6803 100755
--- a/.gitignore
+++ b/.gitignore
@@ -21,7 +21,7 @@
.demo
.svn
.DS_Store
-xmake.xconf
+.xmake.xconf
cscope.*
gmon.out
other
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index c09955e85..a0c17b0e9 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -63,6 +63,7 @@ tb_int_t xm_os_rmfile(lua_State* lua);
tb_int_t xm_os_cpfile(lua_State* lua);
tb_int_t xm_os_rename(lua_State* lua);
tb_int_t xm_os_exists(lua_State* lua);
+tb_int_t xm_os_setenv(lua_State* lua);
// the path functions
tb_int_t xm_path_relative(lua_State* lua);
@@ -97,6 +98,7 @@ static luaL_Reg const g_os_functions[] =
, { "cpfile", xm_os_cpfile }
, { "rename", xm_os_rename }
, { "exists", xm_os_exists }
+, { "setenv", xm_os_setenv }
, { tb_null, tb_null }
};
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index cfb8510fb..c61411dd8 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -27,6 +27,7 @@ xmake_C_FILES += \
os/cpfile \
os/rename \
os/exists \
+ os/setenv \
path/relative \
path/absolute \
path/translate \
diff --git a/core/src/xmake/os/setenv.c b/core/src/xmake/os/setenv.c
new file mode 100755
index 000000000..1b911bbdc
--- /dev/null
+++ b/core/src/xmake/os/setenv.c
@@ -0,0 +1,53 @@
+/*!The Automatic Cross-platform Build Tool
+ *
+ * XMake is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * XMake is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with XMake;
+ * If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+ *
+ * Copyright (C) 2009 - 2015, ruki All rights reserved.
+ *
+ * @author ruki
+ * @file setenv.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "setenv"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_setenv(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the name and value
+ tb_char_t const* name = luaL_checkstring(lua, 1);
+ tb_char_t const* value = luaL_checkstring(lua, 2);
+ tb_check_return_val(name, 0);
+
+ // done os.setenv(name, value)
+ lua_pushboolean(lua, tb_environment_set_one(name, value));
+
+ // ok
+ return 1;
+}
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index 877f7d026..f53338a05 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -153,7 +153,7 @@ function config._make()
-- get configs from all targets
for k, v in pairs(configs) do
- if type(k) == "string" and not k:startswith("_") then
+ if type(k) == "string" and not k:find("_%u+") then
current[k] = v
end
end
@@ -242,7 +242,7 @@ function config.savexconf()
assert(configs)
-- open the configure file
- local path = options.project .. "/xmake.xconf"
+ local path = options.project .. "/.xmake.xconf"
local file = io.open(path, "w")
if not file then
-- error
@@ -288,7 +288,7 @@ function config.loadxconf()
end
-- load and execute the xmake.xconf
- local path = options.project .. "/xmake.xconf"
+ local path = options.project .. "/.xmake.xconf"
local newenv = preprocessor.loadfile(path, "config", configures, {"target"})
-- exists local configures?
@@ -370,7 +370,7 @@ function config.dump()
assert(config._CURRENT)
-- dump
- utils.dump(config._CURRENT)
+ utils.dump(config._CURRENT, "__%w*")
end
diff --git a/xmake/scripts/base/global.lua b/xmake/scripts/base/global.lua
index 095d49adb..64836bd2c 100644
--- a/xmake/scripts/base/global.lua
+++ b/xmake/scripts/base/global.lua
@@ -120,7 +120,7 @@ function global._make()
-- make current global configure
for k, v in pairs(configs) do
- if type(k) == "string" and not k:startswith("_") then
+ if type(k) == "string" and not k:find("_%u+") then
current[k] = v
end
end
@@ -269,7 +269,7 @@ function global.dump()
assert(global._CURRENT)
-- dump
- utils.dump(global._CURRENT)
+ utils.dump(global._CURRENT, "__%w*")
end
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 235ae8011..10a64593b 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -79,7 +79,7 @@ function preprocessor._register(env, names, filter)
local _current = env._current
assert(_current)
- -- init ldflags
+ -- init the configure entry
_current[name] = _current[name] or {}
-- get arguments
@@ -109,7 +109,39 @@ function preprocessor._init(root, configures, scopes, filter, import)
-- enter new environment
local newenv = {}
local oldenv = getfenv()
- setmetatable(newenv, {__index = _G})
+ setmetatable(newenv, { __index = function(tbl, key)
+ -- private configure entry? we can get it directly and need not register it
+ if key and type(key) == "string" and key:startswith("__") then
+
+ return function(...)
+
+ -- check
+ local _current = newenv._current
+ assert(_current)
+
+ -- init the configure entry
+ _current[key] = _current[key] or {}
+
+ -- get arguments
+ local arg = arg or {...}
+ if table.getn(arg) == 0 then
+ -- no argument
+ _current[key] = nil
+ elseif table.getn(arg) == 1 then
+ -- save only one argument
+ _current[key] = preprocessor._filter(newenv, arg[1], filter)
+ else
+ -- save all arguments
+ for i, v in ipairs(arg) do
+ _current[key][i] = preprocessor._filter(newenv, v, filter)
+ end
+ end
+ end
+ end
+
+ -- get it from the global table
+ return rawget(_G, key)
+ end})
setfenv(1, newenv)
-- register all configures
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index 6ab67da0f..8ff4d31cc 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -59,6 +59,7 @@ function _macosx.make(configs)
-- init xcode sdk directory
configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. config.get("xcode_sdkver") .. ".sdk"
+
end
-- get the option menu for action: xmake config or global