diff options
| author | ruki <[email protected]> | 2015-05-12 23:02:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-12 23:02:30 +0800 |
| commit | 905e90debb2a79993b16d5761c2eced8fdfad4cc (patch) | |
| tree | bc482ff7c9659ee89d0ed20ef7ddb9d403d46f3e | |
| parent | 97e6e62e5061f029b1195784671dea9d19211782 (diff) | |
auto-configure plat and arch
| -rwxr-xr-x | core/src/xmake/machine.c | 28 | ||||
| -rw-r--r-- | xmake/scripts/_xmake_main.lua | 2 | ||||
| -rw-r--r-- | xmake/scripts/action/config.lua | 72 |
3 files changed, 47 insertions, 55 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 3149daba8..659eb8afe 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -210,6 +210,34 @@ xm_machine_ref_t xm_machine_init() // bind string functions luaL_register(impl->lua, "string", g_string_functions); + // init platform +#if defined(TB_CONFIG_OS_WINDOWS) + lua_pushstring(impl->lua, "windows"); +#elif defined(TB_CONFIG_OS_MAC) + lua_pushstring(impl->lua, "macosx"); +#elif defined(TB_CONFIG_OS_LINUX) + lua_pushstring(impl->lua, "linux"); +#elif defined(TB_CONFIG_OS_IOS) + lua_pushstring(impl->lua, "ios"); +#elif defined(TB_CONFIG_OS_ANDROID) + lua_pushstring(impl->lua, "android"); +#elif defined(TB_CONFIG_OS_LIKE_UNIX) + lua_pushstring(impl->lua, "unix"); +#else + lua_pushstring(impl->lua, "unknown"); +#endif + lua_setglobal(impl->lua, "_PLAT"); + + // init architecture +#if defined(TB_ARCH_x86) || defined(TB_CONFIG_OS_WINDOWS) + lua_pushstring(impl->lua, "x86"); +#elif defined(TB_ARCH_x64) + lua_pushstring(impl->lua, "x64"); +#else + lua_pushstring(impl->lua, TB_ARCH_STRING); +#endif + lua_setglobal(impl->lua, "_ARCH"); + // init namespace: xmake lua_newtable(impl->lua); lua_setglobal(impl->lua, "xmake"); diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua index 8eec5251f..215db9323 100644 --- a/xmake/scripts/_xmake_main.lua +++ b/xmake/scripts/_xmake_main.lua @@ -23,6 +23,8 @@ -- init namespace: xmake xmake = xmake or {} xmake._ARGV = _ARGV +xmake._PLAT = _PLAT +xmake._ARCH = _ARCH xmake._VERSION = "XMake v1.0.1" xmake._PROGRAM_DIR = _PROGRAM_DIR xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/" diff --git a/xmake/scripts/action/config.lua b/xmake/scripts/action/config.lua index af16afad5..b9b33b836 100644 --- a/xmake/scripts/action/config.lua +++ b/xmake/scripts/action/config.lua @@ -58,7 +58,7 @@ function config._save() return true end --- load configs to xmake._OPTIONS from the configure file +-- load configs function config._load() -- the options @@ -121,71 +121,35 @@ function config._load() -- save the default option to the target if not configs[target][k] then - configs[target][k] = v + configs[target][k] = utils.ifelse(v == "auto", config._auto(k), v) end end end end --- save config -function config._save_option(file, option) - - -- check - assert(file and option) +-- auto configs +function config._auto(name) - -- save string - if type(option) == "string" then - file:write(string.format("%q", option)) - -- save boolean - elseif type(option) == "boolean" then - file:write(tostring(option)) - -- save number - elseif type(option) == "number" then - file:write(option) - -- save table - elseif type(option) == "table" then - - -- save head - file:write("{\n") - - -- save body - local i = 0 - for k, v in pairs(option) do - - -- skip --project and --file - if type(k) == "string" and not k:startswith("_") and k ~= "project" and k ~= "file" and k ~= "verbose" then - - -- save separator - file:write(utils.ifelse(i == 0, " ", ", "), k, " = ") - - -- save this key: value - if not config._save_option(file, v) then - return false - end - - -- save newline - file:write("\n") - i = i + 1 - end - end - - -- save tail - file:write("}\n") - else - -- error - utils.error("invalid option type: %s", type(option)) - return false - end + -- get platform + if name == "plat" then + return xmake._PLAT + -- get architecture + elseif name == "arch" then + return xmake._ARCH + end - -- ok - return true + -- unknown + utils.error("unknown config: %s", name) + return "unknown" end -- dump configs function config._dump() -- dump - utils.dump(xmake._CONFIGS, "configs = ") + if xmake._OPTIONS.verbose then + utils.dump(xmake._CONFIGS, "configs = ") + end end @@ -195,8 +159,6 @@ function config.done() -- load configs config._load() - -- TODO - -- dump configs config._dump() |
