summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/main.lua10
-rw-r--r--xmake/scripts/base/option.lua2
-rw-r--r--xmake/scripts/base/path.lua72
-rw-r--r--xmake/scripts/base/string.lua44
-rw-r--r--xmake/scripts/base/utils.lua2
5 files changed, 124 insertions, 6 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 56e259efd..a0e94634a 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -21,9 +21,10 @@
--
-- define module: main
-local main = {}
+local main = main or {}
-- load modules
+local path = require("base/path")
local utils = require("base/utils")
local option = require("base/option")
@@ -305,12 +306,13 @@ function main.done_option()
-- init the project directory
options.project = options.project or _PROJECT_DIR
- options.project = path.getabsolute(options.project)
- print(options.project)
+ options.project = path.absolute(options.project)
+ assert(options.project)
-- init the xmake.lua file path
options.file = options.file or "xmake.lua"
- print(options.file)
+ options.file = path.absolute(options.file, options.project)
+ assert(options.file)
-- done action
return main.done_action()
diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua
index 364b59f57..0a6f4dd92 100644
--- a/xmake/scripts/base/option.lua
+++ b/xmake/scripts/base/option.lua
@@ -21,7 +21,7 @@
--
-- define module: option
-local option = {}
+local option = option or {}
-- load modules
local utils = require("base/utils")
diff --git a/xmake/scripts/base/path.lua b/xmake/scripts/base/path.lua
new file mode 100644
index 000000000..eb35283b2
--- /dev/null
+++ b/xmake/scripts/base/path.lua
@@ -0,0 +1,72 @@
+--!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 path.lua
+--
+
+-- define module: path
+local path = path or {}
+
+-- load modules
+local string = require("base/string")
+
+-- get the directory of the path
+function path.directory(p)
+ local i = p:find_last("[/\\]")
+ if i then
+ if i > 1 then i = i - 1 end
+ return p:sub(1, i)
+ else
+ return "."
+ end
+end
+
+-- get the filename of the path
+function path.filename(p)
+ local i = p:find_last("[/\\]")
+ if i then
+ return p:sub(i + 1)
+ else
+ return p
+ end
+end
+
+-- get the basename of the path
+function path.basename(p)
+ local name = path.filename(p)
+ local i = name:find_last(".", true)
+ if i then
+ return name:sub(1, i - 1)
+ else
+ return name
+ end
+end
+
+-- get the file extension of the path: .xxx
+function path.extension(p)
+ local i = p:find_last(".", true)
+ if i then
+ return p:sub(i)
+ else
+ return ""
+ end
+end
+
+-- return module: path
+return path
diff --git a/xmake/scripts/base/string.lua b/xmake/scripts/base/string.lua
new file mode 100644
index 000000000..87e37635a
--- /dev/null
+++ b/xmake/scripts/base/string.lua
@@ -0,0 +1,44 @@
+--!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 string.lua
+--
+
+-- define module: string
+local string = string or {}
+
+-- find the last substring with the given pattern
+function string.find_last(self, pattern, plain)
+ -- find the last substring
+ local curr = 0
+ repeat
+ local next = self:find(pattern, curr + 1, plain)
+ if next then
+ curr = next
+ end
+ until (not next)
+
+ -- found?
+ if curr > 0 then
+ return curr
+ end
+end
+
+-- return module: string
+return string
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 59cfc4cd0..4cad25de0 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -21,7 +21,7 @@
--
-- define module: utils
-local utils = {}
+local utils = utils or {}
-- the printf function
function utils.printf(msg, ...)