summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-13 11:49:22 +0800
committerruki <[email protected]>2015-05-13 11:49:22 +0800
commit1f45e3bf9b41a413804305fc23810639b977a9f1 (patch)
tree1eaee4fe5f942fa8ee5c9dd2ec1e6a17dbe912f4 /xmake/scripts
parentba92342286d9fabb29c97acac4c5deed0906a25b (diff)
add project configure
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/_xmake_main.lua1
-rw-r--r--xmake/scripts/base/main.lua10
-rw-r--r--xmake/scripts/base/project.lua79
3 files changed, 89 insertions, 1 deletions
diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua
index 41977a6b3..44272d99b 100644
--- a/xmake/scripts/_xmake_main.lua
+++ b/xmake/scripts/_xmake_main.lua
@@ -30,6 +30,7 @@ xmake._PROGRAM_DIR = _PROGRAM_DIR
xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/"
xmake._OPTIONS = {}
xmake._CONFIGS = {}
+xmake._PROJECT = nil
-- init package path
package.path = xmake._SCRIPTS_DIR .. "?.lua;" .. package.path
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 77af72118..d52648fb3 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -27,6 +27,7 @@ local main = main or {}
local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
+local project = require("base/project")
local action = require("action/action")
-- init the option menu
@@ -274,10 +275,14 @@ function main._done_option()
end
assert(options.file)
- -- load and execute the xmake.lua script of the given project
+ -- load and execute the project script
local errors = nil
local script = loadfile(options.file)
if script then
+
+ -- init the project envirnoment
+ setfenv(script, project)
+
-- execute it
local ok, err = pcall(script)
if not ok then
@@ -319,6 +324,9 @@ function main._done_option()
return false
end
+ -- save project
+ xmake._PROJECT = project
+
-- done action
return action.done(options._ACTION or "build")
end
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
new file mode 100644
index 000000000..40d9c9269
--- /dev/null
+++ b/xmake/scripts/base/project.lua
@@ -0,0 +1,79 @@
+--!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 project.lua
+--
+
+-- load modules
+local utils = require("base/utils")
+
+-- enter project
+local _PROJECT = {}
+local _MAINENV = getfenv()
+setmetatable(_PROJECT, {__index = _G})
+setfenv(1, _PROJECT)
+
+-- init the parent and current scope
+local parent = nil
+local current = nil
+
+-- configure target
+function target(name)
+
+ -- check
+ assert(name and _ROOT)
+
+ -- init targets
+ _ROOT._TARGETS = _ROOT._TARGETS or {}
+
+ -- init target scope
+ _ROOT._TARGETS[name] = {}
+
+ -- TODO
+ -- enter target scope
+ parent = current
+ current = _ROOT._TARGETS[name]
+
+end
+
+-- configure project
+function project(name)
+
+ -- check
+ assert(name)
+
+ -- init the root scope, must be only one project
+ if not _ROOT then
+ _ROOT = {}
+ else
+ -- error
+ utils.error("the project: %s is redundant!", name)
+ return
+ end
+
+ -- init the project name
+ _ROOT.name = name
+
+ -- init the current scope
+ current = _ROOT
+end
+
+-- leave project
+setfenv(1, _MAINENV)
+return _PROJECT