summaryrefslogtreecommitdiff
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
parentba92342286d9fabb29c97acac4c5deed0906a25b (diff)
add project configure
-rw-r--r--tests/console/xmake.lua79
-rw-r--r--xmake/scripts/_xmake_main.lua1
-rw-r--r--xmake/scripts/base/main.lua10
-rw-r--r--xmake/scripts/base/project.lua79
4 files changed, 131 insertions, 38 deletions
diff --git a/tests/console/xmake.lua b/tests/console/xmake.lua
index 983692e53..41784520e 100644
--- a/tests/console/xmake.lua
+++ b/tests/console/xmake.lua
@@ -1,57 +1,62 @@
---[[
+
project "console"
+--[[
target "hello1"
- kind "static"
- files { "src/hello1/*.c" }
+ kind "static"
+ files "src/hello1/*.c"
target "hello2"
- kind "shared"
- files { "$(projectdir)/src/hello2/*.c" }
+ kind "shared"
+ files "$(projectdir)/src/hello2/*.c"
target "hello3"
- kind "static"
- files { "src/hello3/*.c" }
- headers { "src/hello3/*.h" }
- headerdir "$(buildir)/inc"
- targetdir "$(buildir)/lib"
- objectdir "$(buildir)/obj"
+ kind "static"
+ files "src/hello3/*.c"
+ headers "src/hello3/*.h"
+ headerdir "$(buildir)/inc"
+ targetdir "$(buildir)/lib"
+ objectdir "$(buildir)/obj"
target "demo_c"
- kind "console"
- files { "src/demo/*.c" }
- links { "hello1" }
- linkdirs { "src/hello1" }
- includedirs { "src/hello1" }
- cflags { "-DHELLO1" }
+ kind "console"
+ deps "hello1"
+ files "src/demo/*.c"
+ links "hello1"
+ linkdirs "src/hello1"
+ includedirs "src/hello1"
+ cflags "-DHELLO1"
target "demo_cpp"
- kind "console"
- files { "src/demo/*.cpp" }
- links { "hello2" }
- linkdirs { "src/hello2" }
- includedirs { "src/hello2" }
- cxxflags { "-DHELLO1" }
+ kind "console"
+ deps "hello2"
+ files "src/demo/*.cpp"
+ links "hello2"
+ linkdirs "src/hello2"
+ includedirs "src/hello2"
+ cxxflags "-DHELLO1"
target "demo_objc"
- kind "console"
- files { "src/demo/*.m" }
- links { "hello3" }
- linkdirs { "$(buildir)/lib" }
- includedirs { "$(buildir)/inc" }
- mflags { "-DHELLO3" }
+ kind "console"
+ deps "hello3"
+ files "src/demo/*.m"
+ links "hello3"
+ linkdirs "$(buildir)/lib"
+ includedirs "$(buildir)/inc"
+ mflags "-DHELLO3"
target "demo_objcpp"
- kind "console"
- files { "src/demo/*.mm" }
- mxflags { "-DHELLO3" }
- ldflags { "-lhello3", "-L$(buildir)/lib" }
+ kind "console"
+ deps "hello3"
+ files "src/demo/*.mm"
+ mxflags "-DHELLO3"
+ ldflags { "-lhello3", "-L$(buildir)/lib" }
- plarforms { "linux" }
- defines { "PLAT=linux" }
+ plarforms "linux"
+ defines "PLAT=linux"
- plarforms { "windows" }
- defines { "PLAT=windows" }
+ plarforms "windows"
+ defines "PLAT=windows"
plarforms { "macosx", "ios" }
ldflags { "-framework Cocoa", "-framework IOKit" }
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