summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-04-27 14:14:04 +0800
committerruki <[email protected]>2015-04-27 14:14:04 +0800
commit3987c001cff96c26aed3067943886f3fd72d3fa8 (patch)
tree9b57b7fd83c93a3fc1080ff6ff66e9a19f6d4668
parent9c8b29bfc32e9d74c97471c430e7cef3566e4ed4 (diff)
add install script
-rwxr-xr-xcore/src/xmake/machine.c43
-rwxr-xr-xinstall72
-rw-r--r--xmake/scripts/xmake_main.lua2
3 files changed, 111 insertions, 6 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index e7cd478aa..6e58f7d70 100755
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -43,6 +43,9 @@ typedef struct __xm_machine_impl_t
// the lua
lua_State* lua;
+ // print verbose info?
+ tb_bool_t verbose;
+
}xm_machine_impl_t;
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -60,6 +63,10 @@ static tb_bool_t xm_machine_main_save_arguments(xm_machine_impl_t* impl, tb_int_
tb_int_t i = 0;
for (i = 1; i < argc; i++)
{
+ // print verbose info
+ if (!tb_strncmp(argv[i], "--verbose", 9) || !tb_strncmp(argv[i], "-v", 2))
+ impl->verbose = tb_true;
+
// get the project directory
if (!tb_strncmp(argv[i], "--project=", 10))
{
@@ -88,15 +95,18 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl,
tb_bool_t ok = tb_false;
do
{
- // attempt to get it from the environment variable first
+ // get it from the environment variable
tb_char_t data[TB_PATH_MAXN] = {0};
- if ( !tb_environment_get_one("XMAKE_PROGRAM_DIR", data, sizeof(data))
- || !tb_path_full(data, path, maxn))
+ if (!tb_environment_get_one("XMAKE_PROGRAM_DIR", data, sizeof(data)))
{
- // TODO
+ // trace
+ if (impl->verbose) tb_trace_i("please set XMAKE_PROGRAM_DIR first!");
break;
}
+ // get the full path
+ if (!tb_path_full(data, path, maxn)) break;
+
// trace
tb_trace_d("program: %s", path);
@@ -142,6 +152,9 @@ static tb_bool_t xm_machine_main_get_project_directory(xm_machine_impl_t* impl,
} while (0);
+ // failed?
+ if (!ok && impl->verbose) tb_trace_i("not found the project directory!");
+
// ok?
return ok;
}
@@ -170,6 +183,9 @@ xm_machine_ref_t xm_machine_init()
// TODO: bind lua interfaces
// ...
+ // init verbose
+ impl->verbose = tb_false;
+
// ok
ok = tb_true;
@@ -218,11 +234,26 @@ tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** ar
tb_strcat(path, "/scripts/xmake_main.lua");
// exists this script?
- if (!tb_file_info(path, tb_null)) return -1;
+ if (!tb_file_info(path, tb_null))
+ {
+ // trace
+ if (impl->verbose) tb_trace_i("not found main script: %s", path);
+ return -1;
+ }
// trace
tb_trace_d("main: %s", path);
// exec the script file
- return luaL_dofile(impl->lua, path);
+ tb_int_t error = luaL_dofile(impl->lua, path);
+
+ // failed? print the error info
+ if (error && impl->verbose)
+ {
+ // trace
+ tb_trace_i("%s", lua_tostring(impl->lua, -1));
+ }
+
+ // ok?
+ return error;
}
diff --git a/install b/install
new file mode 100755
index 000000000..641e7523b
--- /dev/null
+++ b/install
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# is debug?
+debug=n
+if [ $1 ]; then
+ if [ $1 = "--debug" ] || [ $1 = "-d" ]; then
+ debug=y
+ fi
+fi
+
+# probe plat
+uname=`uname`
+if [ $uname = "MSVC" ]; then
+ plat=msvc
+elif [ $uname = "Darwin" ] || [ `uname | egrep -i darwin` ]; then
+ plat=mac
+elif [ $uname = "Linux" ] || [ `uname | egrep -i linux` ]; then
+ plat=linux
+elif [ `uname | egrep -i msys` ]; then
+ plat=msvc
+elif [ `uname | egrep -i cygwin` ]; then
+ plat=msvc
+else
+ plat=linux
+fi
+
+# probe arch
+arch=x86
+if [ $plat = "linux" ] || [ $plat = "mac" ]; then
+ if [ `getconf LONG_BIT` = "64" ]; then
+ arch=x64
+ fi
+fi
+
+# compile xmake-core
+cd ./core
+make f DEBUG=$debug
+if [ $? -ne 0 ]; then exit; fi
+make r
+if [ $? -ne 0 ]; then exit; fi
+cd ..
+
+# create the xmake install directory
+xmake_dir_install=/usr/local/share/xmake
+if [ ! -d $xmake_dir_install ]; then
+ sudo mkdir $xmake_dir_install
+fi
+if [ $? -ne 0 ]; then exit; fi
+
+# install the xmake core file
+xmake_core=./core/bin/demo.pkg/bin/$plat/$arch/demo.b
+xmake_core_install=$xmake_dir_install/xmake
+sudo cp $xmake_core $xmake_core_install
+sudo chmod 777 $xmake_core_install
+if [ $? -ne 0 ]; then exit; fi
+
+# install the xmake directory
+sudo cp -r ./xmake/* $xmake_dir_install/
+if [ $? -ne 0 ]; then exit; fi
+
+# make the xmake loader
+xmake_loader=/tmp/xmake_loader
+echo "#!/bin/bash" > $xmake_loader
+echo "export XMAKE_PROGRAM_DIR=$xmake_dir_install" >> $xmake_loader
+echo "$xmake_core_install" >> $xmake_loader
+if [ $? -ne 0 ]; then exit; fi
+
+# install the xmake loader
+xmake_loader_install=/usr/local/bin/xmake
+sudo mv $xmake_loader $xmake_loader_install
+sudo chmod 777 $xmake_loader_install
+if [ $? -ne 0 ]; then exit; fi
diff --git a/xmake/scripts/xmake_main.lua b/xmake/scripts/xmake_main.lua
index 1f8f055ef..482fb6ac0 100644
--- a/xmake/scripts/xmake_main.lua
+++ b/xmake/scripts/xmake_main.lua
@@ -2,3 +2,5 @@
print("_PROGRAM_DIR: ", _PROGRAM_DIR)
print("_PROJECT_DIR: ", _PROJECT_DIR)
+
+