summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-14 14:38:30 +0800
committerruki <[email protected]>2015-05-14 14:38:30 +0800
commitb303b16817e3773c729f2cd1096d685b491db75b (patch)
treee1782f1bfe8e873554ce2818a3008726e2e030e6 /xmake/scripts
parent914fd0881e2242f01b497650dd09432316aa48d3 (diff)
register configure and impl project.lua
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/main.lua2
-rw-r--r--xmake/scripts/base/project.lua160
-rw-r--r--xmake/scripts/base/utils.lua41
3 files changed, 121 insertions, 82 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index c5e3d0e4e..7754f1d6b 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -295,6 +295,8 @@ function main._done_option()
errors = string.format("load %s failed!", options.file)
end
+ utils.dump(project._ROOT, "", "_PARENT")
+
-- done help
if options.help then
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index fe7986ba7..e208ea726 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -29,99 +29,69 @@ local _MAINENV = getfenv()
setmetatable(_PROJECT, {__index = _G})
setfenv(1, _PROJECT)
--- init the parent and current scope
-local parent = nil
-local current = nil
+-- init the current scope
+local current = nil
-- configure scope end
function scopend()
-end
-
--- configure kind
-function kind()
-end
-
--- configure deps
-function deps()
-end
--- configure files
-function files()
-end
-
--- configure links
-function links()
-end
-
--- configure headers
-function headers()
-end
+ -- check
+ assert(current)
--- configure headerdir
-function headerdir()
+ -- leave the current scope
+ current = current._PARENT
end
--- configure targetdir
-function targetdir()
-end
+-- configure platforms
+function plarforms(...)
--- configure objectdir
-function objectdir()
-end
+ -- check
+ assert(current)
--- configure linkdirs
-function linkdirs()
-end
+ -- init platforms
+ current._PLATFORMS = current._PLATFORMS or {}
--- configure includedirs
-function includedirs()
-end
+ -- init scope
+ local scope = {}
--- configure cflags
-function cflags()
-end
+ -- configure all platforms
+ local arg = arg or {...}
+ for _, name in ipairs(arg) do
--- configure cxxflags
-function cxxflags()
-end
+ -- check
+ if current._PLATFORMS[name] then
+ -- error
+ utils.error("the platform: %s has been defined repeatly!", name)
+ assert(false)
+ end
--- configure ldflags
-function ldflags()
-end
+ -- init the platform scope
+ current._PLATFORMS[name] = scope
--- configure mflags
-function mflags()
-end
-
--- configure mxflags
-function mxflags()
-end
-
--- configure defines
-function defines()
-end
+ end
--- configure plarforms
-function plarforms()
+ -- enter scope
+ local parent = current
+ current = scope
+ current._PARENT = parent
end
-- configure target
function target(name)
-- check
- assert(name and _ROOT)
+ assert(name and current)
-- init targets
--- current._TARGETS = current._TARGETS or {}
+ current._TARGETS = current._TARGETS or {}
-- init target scope
--- current._TARGETS[name] = {}
+ current._TARGETS[name] = {}
- -- TODO
-- enter target scope
--- parent = current
--- current = _ROOT._TARGETS[name]
-
+ local parent = current
+ current = current._TARGETS[name]
+ current._PARENT = parent
end
-- configure project
@@ -144,8 +114,66 @@ function project(name)
-- init the current scope
current = _ROOT
+ current._PARENT = nil
+
end
+-- register configures
+function _register(names)
+
+ -- check
+ assert(_PROJECT)
+ assert(names and type(names) == "table")
+
+ -- register all configures
+ for _, name in ipairs(names) do
+
+ -- register the configure
+ _PROJECT[name] = _PROJECT[name] or function(...)
+
+ -- check
+ assert(current)
+
+ -- init ldflags
+ current[name] = current[name] or {}
+
+ -- get arguments
+ local arg = arg or {...}
+ if table.getn(arg) == 0 then
+ -- no argument
+ current[name] = nil
+ elseif table.getn(arg) == 1 then
+ -- save only one argument
+ current[name] = arg[1]
+ else
+ -- save all arguments
+ for i, v in ipairs(arg) do
+ current[name][i] = v
+ end
+ end
+ end
+ end
+end
+
+-- register all configures
+_register { "kind"
+ , "deps"
+ , "files"
+ , "links"
+ , "mflags"
+ , "headers"
+ , "headerdir"
+ , "targetdir"
+ , "objectdir"
+ , "linkdirs"
+ , "includedirs"
+ , "cflags"
+ , "cxxflags"
+ , "ldflags"
+ , "mxflags"
+ , "defines"}
+
+
-- leave project
setfenv(1, _MAINENV)
return _PROJECT
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index f6af24e9b..c3b4cc38b 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -51,7 +51,7 @@ function utils.ifelse(a, b, c)
end
-- dump object with the level
-function utils._dump_with_level(object, level)
+function utils._dump_with_level(object, exclude, level)
-- check
assert(object)
@@ -79,22 +79,31 @@ function utils._dump_with_level(object, level)
local i = 0
for k, v in pairs(object) do
- -- dump spaces
- for l = 1, level do
- io.write(" ")
- end
+ -- exclude some keys
+ if not exclude or type(k) ~= "string" or not k:find(exclude) then
- -- dump separator
- io.write(utils.ifelse(i == 0, " ", ", "), k, " = ")
+ -- dump spaces
+ for l = 1, level do
+ io.write(" ")
+ end
- -- dump this key: value
- if not utils._dump_with_level(v, level + 1) then
- return false
- end
+ -- dump separator
+ io.write(utils.ifelse(i == 0, " ", ", "))
+
+ -- dump key
+ if type(k) == "string" then
+ io.write(k, " = ")
+ end
- -- dump newline
- io.write("\n")
- i = i + 1
+ -- dump value
+ if not utils._dump_with_level(v, exclude, level + 1) then
+ return false
+ end
+
+ -- dump newline
+ io.write("\n")
+ i = i + 1
+ end
end
-- dump tail
@@ -113,7 +122,7 @@ function utils._dump_with_level(object, level)
end
-- dump object
-function utils.dump(object, prefix)
+function utils.dump(object, prefix, exclude)
-- dump prefix
if prefix and type(prefix) == "string" then
@@ -121,7 +130,7 @@ function utils.dump(object, prefix)
end
-- dump it
- utils._dump_with_level(object, 0)
+ utils._dump_with_level(object, exclude, 0)
-- return it
return object