summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-17 10:28:22 +0800
committerruki <[email protected]>2015-05-17 10:28:22 +0800
commit7be8238f634969e80e678f59ab418900f846b094 (patch)
tree75c956fde24193c7d6e21a7406de5cc8518d9ab8
parentb7344cd33b93ba1a1aa96eea057adf4b71f7139a (diff)
add some os interfaces
-rwxr-xr-x.gitignore1
-rwxr-xr-xcore/src/xmake/machine.c33
-rwxr-xr-xcore/src/xmake/makefile9
-rwxr-xr-xcore/src/xmake/os/cpdir.c53
-rwxr-xr-xcore/src/xmake/os/cpfile.c53
-rwxr-xr-xcore/src/xmake/os/exists.c52
-rwxr-xr-xcore/src/xmake/os/isdir.c53
-rwxr-xr-xcore/src/xmake/os/isfile.c53
-rwxr-xr-xcore/src/xmake/os/mkdir.c52
-rw-r--r--core/src/xmake/os/prefix.h35
-rwxr-xr-xcore/src/xmake/os/rename.c53
-rwxr-xr-xcore/src/xmake/os/rmdir.c52
-rwxr-xr-xcore/src/xmake/os/rmfile.c52
-rw-r--r--xmake/scripts/_xmake_main.lua1
-rw-r--r--xmake/scripts/action/_config.lua11
-rw-r--r--xmake/scripts/base/main.lua12
-rw-r--r--xmake/scripts/base/os.lua102
-rw-r--r--xmake/scripts/base/project.lua2
18 files changed, 674 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 68f9ebc14..fad6a05ab 100755
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ other
tags
doc
install.log
+build
core/bin
core/pre
core/tool/msys
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 375f12bd8..dd4ae864c 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -49,6 +49,17 @@ typedef struct __xm_machine_impl_t
* declaration
*/
+// the os functions
+tb_int_t xm_os_isdir(lua_State* lua);
+tb_int_t xm_os_rmdir(lua_State* lua);
+tb_int_t xm_os_mkdir(lua_State* lua);
+tb_int_t xm_os_cpdir(lua_State* lua);
+tb_int_t xm_os_isfile(lua_State* lua);
+tb_int_t xm_os_rmfile(lua_State* lua);
+tb_int_t xm_os_cpfile(lua_State* lua);
+tb_int_t xm_os_rename(lua_State* lua);
+tb_int_t xm_os_exists(lua_State* lua);
+
// the path functions
tb_int_t xm_path_absolute(lua_State* lua);
tb_int_t xm_path_translate(lua_State* lua);
@@ -64,6 +75,21 @@ tb_int_t xm_preprocessor_loadx(lua_State* lua);
* globals
*/
+// the os functions
+static luaL_Reg const g_os_functions[] =
+{
+ { "isdir", xm_os_isdir }
+, { "rmdir", xm_os_rmdir }
+, { "mkdir", xm_os_mkdir }
+, { "cpdir", xm_os_cpdir }
+, { "isfile", xm_os_isfile }
+, { "rmfile", xm_os_rmfile }
+, { "cpfile", xm_os_cpfile }
+, { "rename", xm_os_rename }
+, { "exists", xm_os_exists }
+, { tb_null, tb_null }
+};
+
// the path functions
static luaL_Reg const g_path_functions[] =
{
@@ -83,8 +109,8 @@ static luaL_Reg const g_string_functions[] =
// the preprocessor functions
static luaL_Reg const g_preprocessor_functions[] =
{
- { "loadx", xm_preprocessor_loadx }
-, { tb_null, tb_null }
+ { "loadx", xm_preprocessor_loadx }
+, { tb_null, tb_null }
};
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -207,6 +233,9 @@ xm_machine_ref_t xm_machine_init()
// open lua libraries
luaL_openlibs(impl->lua);
+ // bind os functions
+ luaL_register(impl->lua, "os", g_os_functions);
+
// bind path functions
luaL_register(impl->lua, "path", g_path_functions);
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index e0b530bb1..899ceaf3a 100755
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -14,6 +14,15 @@ xmake_CONFIG = y
xmake_C_FILES += \
xmake \
machine \
+ os/isdir \
+ os/rmdir \
+ os/mkdir \
+ os/cpdir \
+ os/isfile \
+ os/rmfile \
+ os/cpfile \
+ os/rename \
+ os/exists \
path/absolute \
path/translate \
path/is_absolute \
diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c
new file mode 100755
index 000000000..349b8c1cb
--- /dev/null
+++ b/core/src/xmake/os/cpdir.c
@@ -0,0 +1,53 @@
+/*!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 cpdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "cpdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_cpdir(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the source and destination
+ tb_char_t const* src = luaL_checkstring(lua, 1);
+ tb_char_t const* dst = luaL_checkstring(lua, 2);
+ tb_check_return_val(src && dst, 0);
+
+ // done os.cpdir(src, dst)
+ lua_pushboolean(lua, tb_directory_copy(src, dst));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c
new file mode 100755
index 000000000..49ac4f062
--- /dev/null
+++ b/core/src/xmake/os/cpfile.c
@@ -0,0 +1,53 @@
+/*!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 cpfile.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "cpfile"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_cpfile(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the source and destination
+ tb_char_t const* src = luaL_checkstring(lua, 1);
+ tb_char_t const* dst = luaL_checkstring(lua, 2);
+ tb_check_return_val(src && dst, 0);
+
+ // done os.cpfile(src, dst)
+ lua_pushboolean(lua, tb_file_copy(src, dst));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/exists.c b/core/src/xmake/os/exists.c
new file mode 100755
index 000000000..797b1c7d0
--- /dev/null
+++ b/core/src/xmake/os/exists.c
@@ -0,0 +1,52 @@
+/*!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 exists.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "exists"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_exists(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);
+
+ // done os.exists(path)
+ lua_pushboolean(lua, tb_file_info(path, tb_null));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c
new file mode 100755
index 000000000..d85468625
--- /dev/null
+++ b/core/src/xmake/os/isdir.c
@@ -0,0 +1,53 @@
+/*!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 isdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "isdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_isdir(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);
+
+ // done os.isdir(path)
+ tb_file_info_t info = {0};
+ lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_DIRECTORY));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c
new file mode 100755
index 000000000..33fa69236
--- /dev/null
+++ b/core/src/xmake/os/isfile.c
@@ -0,0 +1,53 @@
+/*!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 isfile.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "isfile"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_isfile(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);
+
+ // done os.isfile(path)
+ tb_file_info_t info = {0};
+ lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c
new file mode 100755
index 000000000..9c22e15b9
--- /dev/null
+++ b/core/src/xmake/os/mkdir.c
@@ -0,0 +1,52 @@
+/*!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 mkdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "mkdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_mkdir(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);
+
+ // done os.mkdir(path)
+ lua_pushboolean(lua, tb_directory_create(path));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/prefix.h b/core/src/xmake/os/prefix.h
new file mode 100644
index 000000000..68cf6ce0f
--- /dev/null
+++ b/core/src/xmake/os/prefix.h
@@ -0,0 +1,35 @@
+/*!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 prefix.h
+ *
+ */
+#ifndef XM_OS_PREFIX_H
+#define XM_OS_PREFIX_H
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "../prefix.h"
+#include "luajit/luajit.h"
+
+
+#endif
+
+
diff --git a/core/src/xmake/os/rename.c b/core/src/xmake/os/rename.c
new file mode 100755
index 000000000..b715b7d35
--- /dev/null
+++ b/core/src/xmake/os/rename.c
@@ -0,0 +1,53 @@
+/*!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 rename.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "rename"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_rename(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // get the source and destination
+ tb_char_t const* src = luaL_checkstring(lua, 1);
+ tb_char_t const* dst = luaL_checkstring(lua, 2);
+ tb_check_return_val(src && dst, 0);
+
+ // done os.rename(src, dst)
+ lua_pushboolean(lua, tb_file_rename(src, dst));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c
new file mode 100755
index 000000000..2daba8207
--- /dev/null
+++ b/core/src/xmake/os/rmdir.c
@@ -0,0 +1,52 @@
+/*!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 rmdir.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "rmdir"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_rmdir(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);
+
+ // done os.rmdir(path)
+ lua_pushboolean(lua, tb_directory_remove(path));
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/os/rmfile.c b/core/src/xmake/os/rmfile.c
new file mode 100755
index 000000000..0b6b96b8b
--- /dev/null
+++ b/core/src/xmake/os/rmfile.c
@@ -0,0 +1,52 @@
+/*!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 rmfile.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "rmfile"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_os_rmfile(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);
+
+ // done os.rmfile(path)
+ lua_pushboolean(lua, tb_file_remove(path));
+
+ // ok
+ return 1;
+}
diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua
index 41977a6b3..2aeeef35f 100644
--- a/xmake/scripts/_xmake_main.lua
+++ b/xmake/scripts/_xmake_main.lua
@@ -27,6 +27,7 @@ xmake._HOST = _HOST
xmake._ARCH = _ARCH
xmake._VERSION = "XMake v1.0.1"
xmake._PROGRAM_DIR = _PROGRAM_DIR
+xmake._PROJECT_DIR = _PROJECT_DIR
xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/"
xmake._OPTIONS = {}
xmake._CONFIGS = {}
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index ee730a718..3bc9dba5a 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -24,13 +24,22 @@
local _config = _config or {}
-- load modules
-local io = require("base/io")
+local os = require("base/os")
local utils = require("base/utils")
local config = require("base/config")
-- done the given config
function _config.done()
+ -- the configs
+ local configs = config._CONFIGS
+ assert(configs and configs.buildir)
+
+ -- make the build directory
+ if not os.isdir(configs.buildir) then
+ assert(os.mkdir(configs.buildir))
+ end
+
-- save configs
if not config.savexconf() then
return false
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 17f0af74b..1eb0fc5e9 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -266,10 +266,13 @@ function main._done_option()
assert(options)
-- init the project directory
- options.project = options.project or options._DEFAULTS.project or _PROJECT_DIR
+ options.project = options.project or options._DEFAULTS.project or xmake._PROJECT_DIR
options.project = path.absolute(options.project)
assert(options.project)
+ -- save the project directory
+ xmake._PROJECT_DIR = options.project
+
-- init the xmake.xproj file path
options.file = options.file or options._DEFAULTS.file or "xmake.xproj"
if not path.is_absolute(options.file) then
@@ -283,6 +286,13 @@ function main._done_option()
-- load xmake.xproj file
errors = project.loadxproj(options.file)
end
+ assert(config._CONFIGS)
+
+ -- init the build directory
+ if config._CONFIGS.buildir and not path.is_absolute(config._CONFIGS.buildir) then
+ config._CONFIGS.buildir = path.absolute(config._CONFIGS.buildir, xmake._PROJECT_DIR)
+ end
+ assert(config._CONFIGS.buildir)
-- done help
if options.help then
diff --git a/xmake/scripts/base/os.lua b/xmake/scripts/base/os.lua
new file mode 100644
index 000000000..e87eb1ec9
--- /dev/null
+++ b/xmake/scripts/base/os.lua
@@ -0,0 +1,102 @@
+--!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 os.lua
+--
+
+-- define module: os
+local os = os or {}
+
+-- copy file or directory
+function os.cp(src, dst)
+
+ -- check
+ assert(src and dst)
+
+ -- is file?
+ if os.isfile(src) then
+ -- copy file
+ if not os.cpfile(src, dst) then
+ return false, string.format("cannot copy file %s to %s!", src, dst)
+ end
+ -- is directory?
+ elseif os.isdir(src) then
+ -- copy directory
+ if not os.cpdir(src, dst) then
+ return false, string.format("cannot copy directory %s to %s!", src, dst)
+ end
+ -- not exists?
+ else
+ return false, string.format("cannot copy file %s, not found this file!", src)
+ end
+
+ -- ok
+ return true
+end
+
+-- move file or directory
+function os.mv(src, dst)
+
+ -- check
+ assert(src and dst)
+
+ -- exists file or directory?
+ if os.exists(src) then
+ -- move file or directory
+ if not os.rename(src, dst) then
+ return false, string.format("cannot move %s to %s!", src, dst)
+ end
+ -- not exists?
+ else
+ return false, string.format("cannot move %s to %s, not found this file!", src, dst)
+ end
+
+ -- ok
+ return true
+end
+
+-- remove file or directory
+function os.rm(path)
+
+ -- check
+ assert(path)
+
+ -- is file?
+ if os.isfile(path) then
+ -- remove file
+ if not os.rmfile(path) then
+ return false, string.format("cannot remove file %s!", path)
+ end
+ -- is directory?
+ elseif os.isdir(path) then
+ -- remove directory
+ if not os.rmdir(path) then
+ return false, string.format("cannot remove directory %s!", path)
+ end
+ -- not exists?
+ else
+ return false, string.format("cannot remove file %s, not found this file!", path)
+ end
+
+ -- ok
+ return true
+end
+
+-- return module: os
+return os
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 1a25b9bda..73483ba5c 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -58,7 +58,7 @@ function project.loadxproj(file)
local target = config.getarget()
return utils.ifelse(target, target.output, nil);
elseif v == "projectdir" then
- return xmake._OPTIONS.project
+ return xmake._PROJECT_DIR
end
return v
end