summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h2
-rw-r--r--core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h4
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/directory.h13
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/path.h45
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/windows/interface/interface.h1
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/windows/interface/shell32.h73
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/platform/windows/prefix.h4
-rwxr-xr-xcore/pkg/tbox.pkg/inc/tbox/prefix/trace.h24
-rw-r--r--core/pkg/tbox.pkg/lib/msvc/x86/tboxd.pdbbin290816 -> 290816 bytes
-rw-r--r--core/pkg/tbox.pkg/lib/msvc/x86/tboxr.pdbbin282624 -> 282624 bytes
-rwxr-xr-xcore/src/xmake/machine.c10
-rwxr-xr-xcore/src/xmake/makefile3
-rwxr-xr-xcore/src/xmake/path/absolute.c (renamed from core/src/xmake/path/getabsolute.c)15
-rwxr-xr-xcore/src/xmake/path/translate.c57
-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
19 files changed, 340 insertions, 41 deletions
diff --git a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
index 1a64bb537..d05f235cd 100644
--- a/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
+++ b/core/pkg/tbox.pkg/inc/mac/x64/tbox.config.h
@@ -14,7 +14,7 @@
#define TB_CONFIG_VERSION_ALTER 8
// build version
-#define TB_CONFIG_VERSION_BUILD 201504251218
+#define TB_CONFIG_VERSION_BUILD 201505041915
// small
#define TB_CONFIG_SMALL (0)
diff --git a/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h b/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h
index cf912fd77..8bfead6db 100644
--- a/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h
+++ b/core/pkg/tbox.pkg/inc/msvc/x86/tbox.config.h
@@ -15,10 +15,10 @@
#define TB_CONFIG_VERSION_ALTER 8
// build version
-#define TB_CONFIG_VERSION_BUILD 201504271443
+#define TB_CONFIG_VERSION_BUILD 201505042322
// small
-#define TB_CONFIG_SMALL (1)
+#define TB_CONFIG_SMALL (0)
// os
#define TB_CONFIG_OS_WINDOWS
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/directory.h b/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
index 31dded3ca..e011ad0ac 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/directory.h
@@ -61,14 +61,14 @@ tb_bool_t tb_directory_create(tb_char_t const* path);
*/
tb_bool_t tb_directory_remove(tb_char_t const* path);
-/*! the temporary directory
+/*! the home directory
*
* @param path the directory path data
* @param maxn the directory path maxn
*
* @return the directory path size
*/
-tb_size_t tb_directory_temporary(tb_char_t* path, tb_size_t maxn);
+tb_size_t tb_directory_home(tb_char_t* path, tb_size_t maxn);
/*! the current directory
*
@@ -79,6 +79,15 @@ tb_size_t tb_directory_temporary(tb_char_t* path, tb_size_t maxn);
*/
tb_size_t tb_directory_current(tb_char_t* path, tb_size_t maxn);
+/*! the temporary directory
+ *
+ * @param path the directory path data
+ * @param maxn the directory path maxn
+ *
+ * @return the directory path size
+ */
+tb_size_t tb_directory_temporary(tb_char_t* path, tb_size_t maxn);
+
/*! the directory walk
*
* @param path the directory path
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/path.h b/core/pkg/tbox.pkg/inc/tbox/platform/path.h
index 0335f5807..878c34e84 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/path.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/path.h
@@ -37,21 +37,56 @@ __tb_extern_c_enter__
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
+
+// the path maximum
#define TB_PATH_MAXN (4096)
/* //////////////////////////////////////////////////////////////////////////////////////
* interfaces
*/
-/*! the full path
+/*! translate the path to the native path
+ *
+ * - transform the path separator
+ * - remove the repeat path separator
+ * - expand the user directory with the prefix: ~
+ *
+ * @param path the path
+ * @param size the path size, optional
+ * @param maxn the path maxn
+ *
+ * @return tb_true or tb_false
+ */
+tb_size_t tb_path_translate(tb_char_t* path, tb_size_t size, tb_size_t maxn);
+
+/*! the path is absolute?
+ *
+ * @param path the path
+ *
+ * @return tb_true or tb_false
+ */
+tb_bool_t tb_path_is_absolute(tb_char_t const* path);
+
+/*! get the absolute path which relative to the current directory
+ *
+ * @param path the path
+ * @param data the path data
+ * @param maxn the path maxn
+ *
+ * @return the absolute path
+ */
+tb_char_t const* tb_path_absolute(tb_char_t const* path, tb_char_t* data, tb_size_t maxn);
+
+/*! get the absolute path which relative to the given root directory
*
- * @param path the path path
- * @param full the full path
+ * @param root the root path
+ * @param path the path
+ * @param data the path data
* @param maxn the path maxn
*
- * @return the full path
+ * @return the absolute path
*/
-tb_char_t const* tb_path_full(tb_char_t const* path, tb_char_t* full, tb_size_t maxn);
+tb_char_t const* tb_path_absolute_to(tb_char_t const* root, tb_char_t const* path, tb_char_t* data, tb_size_t maxn);
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/interface.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/interface.h
index 55b54498d..24e843258 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/interface.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/interface.h
@@ -30,6 +30,7 @@
#include "user32.h"
#include "ws2_32.h"
#include "mswsock.h"
+#include "shell32.h"
#include "dbghelp.h"
#include "kernel32.h"
#include "iphlpapi.h"
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/shell32.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/shell32.h
new file mode 100755
index 000000000..54f3d38ca
--- /dev/null
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/interface/shell32.h
@@ -0,0 +1,73 @@
+/*!The Treasure Box Library
+ *
+ * TBox 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.
+ *
+ * TBox 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 TBox;
+ * 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 shell32.h
+ *
+ */
+#ifndef TB_PLATFORM_WINDOWS_INTERFACE_SHELL32_H
+#define TB_PLATFORM_WINDOWS_INTERFACE_SHELL32_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * extern
+ */
+__tb_extern_c_enter__
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * types
+ */
+
+// the SHGetSpecialFolderLocation func type
+typedef HRESULT (WINAPI* tb_shell32_SHGetSpecialFolderLocation_t)(HWND hwndOwner, tb_int_t nFolder, tb_handle_t *ppidl);
+
+// the SHGetPathFromIDListW func type
+typedef BOOL (WINAPI* tb_shell32_SHGetPathFromIDListW_t)(tb_handle_t pidl, LPWSTR pszPath);
+
+// the shell32 interfaces type
+typedef struct __tb_shell32_t
+{
+ // SHGetSpecialFolderLocation
+ tb_shell32_SHGetSpecialFolderLocation_t SHGetSpecialFolderLocation;
+
+ // SHGetPathFromIDListW
+ tb_shell32_SHGetPathFromIDListW_t SHGetPathFromIDListW;
+
+}tb_shell32_t, *tb_shell32_ref_t;
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
+/* the shell32 interfaces
+ *
+ * @return the shell32 interfaces pointer
+ */
+tb_shell32_ref_t tb_shell32(tb_noarg_t);
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * extern
+ */
+__tb_extern_c_leave__
+
+
+#endif
diff --git a/core/pkg/tbox.pkg/inc/tbox/platform/windows/prefix.h b/core/pkg/tbox.pkg/inc/tbox/platform/windows/prefix.h
index 5fd75e83a..d14a6fea8 100755
--- a/core/pkg/tbox.pkg/inc/tbox/platform/windows/prefix.h
+++ b/core/pkg/tbox.pkg/inc/tbox/platform/windows/prefix.h
@@ -50,11 +50,11 @@ static __tb_inline__ tb_time_t tb_filetime_to_time(FILETIME ft)
}
// the path full for wchar
-static __tb_inline__ tb_wchar_t const* tb_path_full_w(tb_char_t const* path, tb_wchar_t* full, tb_size_t maxn)
+static __tb_inline__ tb_wchar_t const* tb_path_absolute_w(tb_char_t const* path, tb_wchar_t* full, tb_size_t maxn)
{
// the path full
tb_char_t full_a[TB_PATH_MAXN] = {0};
- if (!tb_path_full(path, full_a, TB_PATH_MAXN)) return tb_null;
+ if (!tb_path_absolute(path, full_a, TB_PATH_MAXN)) return tb_null;
// atow
tb_size_t size = tb_atow(full, full_a, maxn);
diff --git a/core/pkg/tbox.pkg/inc/tbox/prefix/trace.h b/core/pkg/tbox.pkg/inc/tbox/prefix/trace.h
index 2804577dd..15fcbf4a4 100755
--- a/core/pkg/tbox.pkg/inc/tbox/prefix/trace.h
+++ b/core/pkg/tbox.pkg/inc/tbox/prefix/trace.h
@@ -66,12 +66,12 @@ __tb_extern_c_enter__
# define tb_tracef_assert_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: " fmt " at %s(): %d, %s", ##arg, __tb_func__, __tb_line__, __tb_file__); tb_trace_sync(); } while (0)
# define tb_tracef_warning_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: " fmt " at %s(): %d, %s", ##arg, __tb_func__, __tb_line__, __tb_file__); tb_trace_sync(); } while (0)
# else
-# define tb_trace_error_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[error]: " fmt __tb_newline__, ##arg); tb_trace_sync(); } while (0)
-# define tb_trace_assert_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: " fmt __tb_newline__, ##arg); tb_trace_sync(); } while (0)
-# define tb_trace_warning_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: " fmt __tb_newline__, ##arg); tb_trace_sync(); } while (0)
-# define tb_tracef_error_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[error]: " fmt, ##arg); tb_trace_sync(); } while (0)
-# define tb_tracef_assert_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: " fmt, ##arg); tb_trace_sync(); } while (0)
-# define tb_tracef_warning_p(prefix, fmt, arg ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: " fmt, ##arg); tb_trace_sync(); } while (0)
+# define tb_trace_error_p(prefix, fmt, arg ...)
+# define tb_trace_assert_p(prefix, fmt, arg ...)
+# define tb_trace_warning_p(prefix, fmt, arg ...)
+# define tb_tracef_error_p(prefix, fmt, arg ...)
+# define tb_tracef_assert_p(prefix, fmt, arg ...)
+# define tb_tracef_warning_p(prefix, fmt, arg ...)
# endif
#elif defined(TB_COMPILER_IS_MSVC) && TB_COMPILER_VERSION_BE(13, 0)
# define tb_trace_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, fmt __tb_newline__, __VA_ARGS__); } while (0)
@@ -84,12 +84,12 @@ __tb_extern_c_enter__
# define tb_tracef_assert_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: at %s(): %d, %s: " fmt, __tb_func__, __tb_line__, __tb_file__, __VA_ARGS__); tb_trace_sync(); } while (0)
# define tb_tracef_warning_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: at %s(): %d, %s: " fmt, __tb_func__, __tb_line__, __tb_file__, __VA_ARGS__); tb_trace_sync(); } while (0)
# else
-# define tb_trace_error_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[error]: " fmt __tb_newline__, __VA_ARGS__); tb_trace_sync(); } while (0)
-# define tb_trace_assert_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: " fmt __tb_newline__, __VA_ARGS__); tb_trace_sync(); } while (0)
-# define tb_trace_warning_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: " fmt __tb_newline__, __VA_ARGS__); tb_trace_sync(); } while (0)
-# define tb_tracef_error_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[error]: " fmt, __VA_ARGS__); tb_trace_sync(); } while (0)
-# define tb_tracef_assert_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[assert]: " fmt, __VA_ARGS__); tb_trace_sync(); } while (0)
-# define tb_tracef_warning_p(prefix, fmt, ...) do { tb_trace_done(prefix, TB_TRACE_MODULE_NAME, "[warning]: " fmt, __VA_ARGS__); tb_trace_sync(); } while (0)
+# define tb_trace_error_p(prefix, fmt, ...)
+# define tb_trace_assert_p(prefix, fmt, ...)
+# define tb_trace_warning_p(prefix, fmt, ...)
+# define tb_tracef_error_p(prefix, fmt, ...)
+# define tb_tracef_assert_p(prefix, fmt, ...)
+# define tb_tracef_warning_p(prefix, fmt, ...)
# endif
#else
# define tb_trace_p
diff --git a/core/pkg/tbox.pkg/lib/msvc/x86/tboxd.pdb b/core/pkg/tbox.pkg/lib/msvc/x86/tboxd.pdb
index 522dedf4d..33b90d45d 100644
--- a/core/pkg/tbox.pkg/lib/msvc/x86/tboxd.pdb
+++ b/core/pkg/tbox.pkg/lib/msvc/x86/tboxd.pdb
Binary files differ
diff --git a/core/pkg/tbox.pkg/lib/msvc/x86/tboxr.pdb b/core/pkg/tbox.pkg/lib/msvc/x86/tboxr.pdb
index 895a17b7e..136751985 100644
--- a/core/pkg/tbox.pkg/lib/msvc/x86/tboxr.pdb
+++ b/core/pkg/tbox.pkg/lib/msvc/x86/tboxr.pdb
Binary files differ
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index ad993da9c..a6bcf0e35 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -53,7 +53,8 @@ typedef struct __xm_machine_impl_t
*/
// the path functions
-tb_int_t xm_path_getabsolute(lua_State* lua);
+tb_int_t xm_path_absolute(lua_State* lua);
+tb_int_t xm_path_translate(lua_State* lua);
// the string functions
tb_int_t xm_string_startswith(lua_State* lua);
@@ -65,7 +66,8 @@ tb_int_t xm_string_startswith(lua_State* lua);
// the path functions
static luaL_Reg const g_path_functions[] =
{
- { "getabsolute", xm_path_getabsolute }
+ { "absolute", xm_path_absolute }
+, { "translate", xm_path_translate }
, { tb_null, tb_null }
};
@@ -125,7 +127,7 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl,
}
// get the full path
- if (!tb_path_full(data, path, maxn)) break;
+ if (!tb_path_absolute(data, path, maxn)) break;
// trace
tb_trace_d("program: %s", path);
@@ -154,7 +156,7 @@ static tb_bool_t xm_machine_main_get_project_directory(xm_machine_impl_t* impl,
// attempt to get it from the environment variable first
tb_char_t data[TB_PATH_MAXN] = {0};
if ( !tb_environment_get_one("XMAKE_PROJECT_DIR", data, sizeof(data))
- || !tb_path_full(data, path, maxn))
+ || !tb_path_absolute(data, path, maxn))
{
// get it from the current directory
if (!tb_directory_current(path, maxn)) break;
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 35d8e9f7a..0b65dc2a2 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -14,7 +14,8 @@ xmake_CONFIG = y
xmake_C_FILES += \
xmake \
machine \
- path/getabsolute \
+ path/absolute \
+ path/translate \
string/startswith
diff --git a/core/src/xmake/path/getabsolute.c b/core/src/xmake/path/absolute.c
index 8d1bae3ed..1695d5dd1 100755
--- a/core/src/xmake/path/getabsolute.c
+++ b/core/src/xmake/path/absolute.c
@@ -17,14 +17,14 @@
* Copyright (C) 2009 - 2015, ruki All rights reserved.
*
* @author ruki
- * @file getabsolute.c
+ * @file absolute.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "getabsolute"
+#define TB_TRACE_MODULE_NAME "absolute"
#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -35,7 +35,7 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_path_getabsolute(lua_State* lua)
+tb_int_t xm_path_absolute(lua_State* lua)
{
// check
tb_assert_and_check_return_val(lua, 0);
@@ -44,9 +44,12 @@ tb_int_t xm_path_getabsolute(lua_State* lua)
tb_char_t const* path = luaL_checkstring(lua, 1);
tb_check_return_val(path, 0);
- // TODO
- // done path:getabsolute()
- tb_trace_i("%s", path);
+ // get the root
+ tb_char_t const* root = luaL_optstring(lua, 2, tb_null);
+
+ // done path:absolute(root)
+ tb_char_t data[TB_PATH_MAXN];
+ lua_pushstring(lua, tb_path_absolute_to(root, path, data, sizeof(data) - 1));
// ok
return 1;
diff --git a/core/src/xmake/path/translate.c b/core/src/xmake/path/translate.c
new file mode 100755
index 000000000..7b53662ea
--- /dev/null
+++ b/core/src/xmake/path/translate.c
@@ -0,0 +1,57 @@
+/*!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 translate.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "translate"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_path_translate(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the path
+ tb_char_t const* path = luaL_checkstring(lua, 1);
+ tb_check_return_val(path, 0);
+
+ // copy path
+ tb_char_t data[TB_PATH_MAXN];
+ tb_strlcpy(data, path, sizeof(data) - 1);
+ data[sizeof(data) - 1] = '\0';
+
+ // done path:translate()
+ lua_pushstring(lua, tb_path_translate(data, 0, sizeof(data) - 1)? data : tb_null);
+
+ // ok
+ return 1;
+}
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, ...)