summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-08 16:25:00 +0800
committerGitHub <[email protected]>2017-05-08 16:25:00 +0800
commit5da5e37eed97e96247ff198c411793f32e5c9916 (patch)
tree4940da5ecbd1756ea058417fc501ac30c159aa83
parent74421dd37565851f41f7415c80fd7046227b40df (diff)
parent52c8ee6e3a5782f49e19bb1b4b9c8fa79661c0e0 (diff)
Merge pull request #80 from TitanSnow/readline
detect readline
-rw-r--r--core/detect/readline.c3
-rw-r--r--core/makefile4
-rw-r--r--core/src/xmake/machine.c2
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/os/versioninfo.c226
-rw-r--r--core/src/xmake/sandbox/interactive.c13
-rwxr-xr-xscripts/get.sh70
-rw-r--r--xmake/core/sandbox/modules/os.lua5
-rw-r--r--xmake/plugins/lua/scripts/versioninfo.lua3
9 files changed, 293 insertions, 34 deletions
diff --git a/core/detect/readline.c b/core/detect/readline.c
new file mode 100644
index 000000000..13452bd84
--- /dev/null
+++ b/core/detect/readline.c
@@ -0,0 +1,3 @@
+#include<stdio.h>
+#include<readline/readline.h>
+int main(){readline(0);return 0;}
diff --git a/core/makefile b/core/makefile
index 68a6c3274..fcee1b008 100644
--- a/core/makefile
+++ b/core/makefile
@@ -269,8 +269,8 @@ base_LIBNAMES := ws2_32
endif
ifeq ($(PLAT),linux)
-base_LIBPATH := $(shell find "/usr" -name libreadline.a | grep ".*/" -o)
-base_LIBNAMES := $(shell find "/usr" -name libreadline.a | grep readline -o) m dl pthread
+base_LIBPATH :=
+base_LIBNAMES := $(shell if { cat detect/readline.c | $(CC) -xc - -lreadline -o /dev/null 2>/dev/null; }; then echo readline; fi ) m dl pthread
endif
# check jit compiler
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c
index 547279bb9..b0e86fd00 100644
--- a/core/src/xmake/machine.c
+++ b/core/src/xmake/machine.c
@@ -80,6 +80,7 @@ tb_int_t xm_os_getenv(lua_State* lua);
tb_int_t xm_os_emptydir(lua_State* lua);
tb_int_t xm_os_strerror(lua_State* lua);
tb_int_t xm_os_getwinsize(lua_State* lua);
+tb_int_t xm_os_versioninfo(lua_State* lua);
// the path functions
tb_int_t xm_path_relative(lua_State* lua);
@@ -131,6 +132,7 @@ static luaL_Reg const g_os_functions[] =
, { "emptydir", xm_os_emptydir }
, { "strerror", xm_os_strerror }
, { "getwinsize", xm_os_getwinsize}
+, { "versioninfo", xm_os_versioninfo}
, { tb_null, tb_null }
};
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index f3b2f97c0..0d41f4439 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -36,6 +36,7 @@ xmake_C_FILES += \
os/emptydir \
os/strerror \
os/getwinsize \
+ os/versioninfo \
path/relative \
path/absolute \
path/translate \
diff --git a/core/src/xmake/os/versioninfo.c b/core/src/xmake/os/versioninfo.c
new file mode 100644
index 000000000..f9e3fe890
--- /dev/null
+++ b/core/src/xmake/os/versioninfo.c
@@ -0,0 +1,226 @@
+/*!The Make-like Build Utility based on Lua
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+ *
+ * @author TitanSnow
+ * @file versioninfo.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "versioninfo"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+static void xm_os_insert_set(lua_State* lua, const char** p)
+{
+ for (; *p; ++p)
+ {
+ lua_pushstring(lua, *p);
+ lua_pushboolean(lua, tb_true);
+ lua_settable(lua, -3);
+ }
+}
+
+// get versioninfo
+tb_int_t xm_os_versioninfo(lua_State* lua)
+{
+ // features
+ const char* features_table[] = {
+# ifdef XM_CONFIG_API_HAVE_READLINE
+ "readline",
+# endif
+ tb_null
+ };
+
+ // configuration table
+ lua_newtable(lua);
+ lua_pushstring(lua, "features");
+
+ // table for features
+ lua_newtable(lua);
+
+ // insert
+ xm_os_insert_set(lua, features_table);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // table for version
+ lua_pushstring(lua, "version");
+ lua_newtable(lua);
+ // major
+ lua_pushstring(lua, "major");
+ lua_pushinteger(lua, XM_VERSION_MAJOR);
+ lua_settable(lua, -3);
+ // minor
+ lua_pushstring(lua, "minor");
+ lua_pushinteger(lua, XM_VERSION_MINOR);
+ lua_settable(lua, -3);
+ // alter
+ lua_pushstring(lua, "alter");
+ lua_pushinteger(lua, XM_VERSION_ALTER);
+ lua_settable(lua, -3);
+ // build
+ lua_pushstring(lua, "build");
+ lua_pushnumber(lua, XM_VERSION_BUILD);
+ lua_settable(lua, -3);
+ // build string
+ lua_pushstring(lua, "build_string");
+ lua_pushstring(lua, XM_VERSION_BUILD_STRING);
+ lua_settable(lua, -3);
+ // version string
+ lua_pushstring(lua, "version_string");
+ lua_pushstring(lua, XM_VERSION_STRING);
+ lua_settable(lua, -3);
+ // short version string
+ lua_pushstring(lua, "short_version_string");
+ lua_pushstring(lua, XM_VERSION_SHORT_STRING);
+ lua_settable(lua, -3);
+
+ // table for tbox version
+ lua_pushstring(lua, "tbox");
+ lua_newtable(lua);
+ // major
+ lua_pushstring(lua, "major");
+ lua_pushinteger(lua, TB_VERSION_MAJOR);
+ lua_settable(lua, -3);
+ // minor
+ lua_pushstring(lua, "minor");
+ lua_pushinteger(lua, TB_VERSION_MINOR);
+ lua_settable(lua, -3);
+ // alter
+ lua_pushstring(lua, "alter");
+ lua_pushinteger(lua, TB_VERSION_ALTER);
+ lua_settable(lua, -3);
+ // build
+ lua_pushstring(lua, "build");
+ lua_pushnumber(lua, TB_VERSION_BUILD);
+ lua_settable(lua, -3);
+ // build string
+ lua_pushstring(lua, "build_string");
+ lua_pushstring(lua, TB_VERSION_BUILD_STRING);
+ lua_settable(lua, -3);
+ // version string
+ lua_pushstring(lua, "version_string");
+ lua_pushstring(lua, TB_VERSION_STRING);
+ lua_settable(lua, -3);
+ // short version string
+ lua_pushstring(lua, "short_version_string");
+ lua_pushstring(lua, TB_VERSION_SHORT_STRING);
+ lua_settable(lua, -3);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // table for lua version
+ lua_pushstring(lua, "lua");
+ lua_newtable(lua);
+
+ // version
+ lua_pushstring(lua, "version");
+ lua_pushstring(lua, LUA_RELEASE);
+ lua_settable(lua, -3);
+
+ // version num
+ lua_pushstring(lua, "version_num");
+ lua_pushinteger(lua, LUA_VERSION_NUM);
+ lua_settable(lua, -3);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // table for luajit version
+ lua_pushstring(lua, "luajit");
+ lua_newtable(lua);
+
+ // version
+ lua_pushstring(lua, "version");
+ lua_pushstring(lua, LUAJIT_VERSION);
+ lua_settable(lua, -3);
+
+ // version num
+ lua_pushstring(lua, "version_num");
+ lua_pushinteger(lua, LUAJIT_VERSION_NUM);
+ lua_settable(lua, -3);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // mode table
+ const char* mode_table[] = {
+# ifdef __xm_small__
+ "small",
+# endif
+# ifdef __xm_debug__
+ "debug",
+# endif
+ tb_null
+ };
+
+ // table for mode
+ lua_pushstring(lua, "modes");
+ lua_newtable(lua);
+
+ // insert
+ xm_os_insert_set(lua, mode_table);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // packages table
+ const char* packages_table[] = {
+# ifdef XM_CONFIG_PACKAGE_HAVE_TBOX
+ "tbox",
+# endif
+# ifdef XM_CONFIG_PACKAGE_HAVE_LUAJIT
+ "luajit",
+# endif
+# ifdef XM_CONFIG_PACKAGE_HAVE_BASE
+ "base",
+# endif
+ tb_null
+ };
+
+ // table for packages
+ lua_pushstring(lua, "packages");
+ lua_newtable(lua);
+
+ // insert
+ xm_os_insert_set(lua, packages_table);
+
+ // set back to table
+ lua_settable(lua, -3);
+
+ // ok
+ return 1;
+}
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c
index c59e1060b..258256d0e 100644
--- a/core/src/xmake/sandbox/interactive.c
+++ b/core/src/xmake/sandbox/interactive.c
@@ -40,6 +40,11 @@
* includes
*/
#include "prefix.h"
+#ifdef XM_CONFIG_API_HAVE_READLINE
+# include <stdio.h> // on some OS (like centos) required
+# include <readline/readline.h>
+# include <readline/history.h>
+#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
@@ -52,14 +57,6 @@
#define LUA_PROMPT2 ">> "
/* //////////////////////////////////////////////////////////////////////////////////////
- * declaration
- */
-#ifdef XM_CONFIG_API_HAVE_READLINE
-extern char* readline (const char*);
-extern void add_history(const char*);
-#endif
-
-/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
diff --git a/scripts/get.sh b/scripts/get.sh
index 52a990dc7..3d174e702 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -1,8 +1,9 @@
#!/bin/bash
# xmake getter
-# usage: bash <(curl -s <my location>) [branch]
+# usage: bash <(curl -s <my location>) [[mirror:]branch] [commit/__install_only__]
+set -o pipefail
# print a LOGO!
echo ' _ '
echo ' __ ___ __ __ __ _| | ______ '
@@ -12,7 +13,7 @@ echo ' /_/\_\_|_| |_|\__ \|_|\_\____| getter '
echo ' '
brew --version >/dev/null 2>&1 && brew install --HEAD xmake && xmake --version && exit
-if [ 0 -ne $(id -u) ]
+if [ 0 -ne "$(id -u)" ]
then
sudoprefix=sudo
else
@@ -31,57 +32,78 @@ my_exit(){
then
if [ $rv -eq 0 ];then rv=$2;fi
fi
- exit $rv
+ exit "$rv"
}
test_tools()
{
+ prog='#include<stdio.h>\n#include<readline/readline.h>\nint main(){readline(0);return 0;}'
{
git --version &&
make --version &&
{
- cc --version ||
- gcc --version ||
- clang --version
+ echo -e "$prog" | cc -xc - -o /dev/null -lreadline ||
+ echo -e "$prog" | gcc -xc - -o /dev/null -lreadline ||
+ echo -e "$prog" | clang -xc - -o /dev/null -lreadline
}
} >/dev/null 2>&1
}
install_tools()
{
- { apt-get --version >/dev/null 2>&1 && $sudoprefix apt-get install -y git build-essential; } ||
- { yum --version >/dev/null 2>&1 && $sudoprefix yum install -y git && $sudoprefix yum groupinstall -y 'Development Tools'; } ||
- { zypper --version >/dev/null 2>&1 && $sudoprefix zypper --non-interactive install git && $sudoprefix zypper --non-interactive install -t pattern devel_C_C++; } ||
- { pacman -V >/dev/null 2>&1 && $sudoprefix pacman -S --noconfirm git base-devel; }
+ { apt-get --version >/dev/null 2>&1 && $sudoprefix apt-get install -y git build-essential libreadline-dev; } ||
+ { yum --version >/dev/null 2>&1 && $sudoprefix yum install -y git readline-devel && $sudoprefix yum groupinstall -y 'Development Tools'; } ||
+ { zypper --version >/dev/null 2>&1 && $sudoprefix zypper --non-interactive install git readline-devel && $sudoprefix zypper --non-interactive install -t pattern devel_C_C++; } ||
+ { pacman -V >/dev/null 2>&1 && $sudoprefix pacman -S --noconfirm --needed git base-devel; }
}
test_tools || { install_tools && test_tools; } || my_exit 'Dependencies Installation Fail' 1
-branch=
+branch=master
+mirror=tboox
+IFS=':'
if [ x != "x$1" ]
then
- branch="-b $1"
- echo "Branch: $1"
+ brancharr=($1)
+ if [ ${#brancharr[@]} -eq 1 ]
+ then
+ branch=${brancharr[0]}
+ fi
+ if [ ${#brancharr[@]} -eq 2 ]
+ then
+ branch=${brancharr[1]}
+ mirror=${brancharr[0]}
+ fi
+ echo "Branch: $branch"
fi
-if [ 'x-b __local__' != "x$branch" ]
+if [ 'x__local__' != "x$branch" ]
then
- git clone --depth=1 $branch https://github.com/tboox/xmake.git /tmp/$$xmake_getter || my_exit 'Clone Fail'
+ git clone --depth=50 -b "$branch" "https://github.com/$mirror/xmake.git" /tmp/$$xmake_getter || my_exit 'Clone Fail'
+ if [ x != "x$2" ]
+ then
+ cd /tmp/$$xmake_getter || my_exit 'Chdir Error'
+ git checkout -qf "$2"
+ cd - || my_exit 'Chdir Error'
+ fi
else
- cp -r "$(git rev-parse --show-toplevel 2>/dev/null || hg root 2>/dev/null || echo $PWD)" /tmp/$$xmake_getter || my_exit 'Clone Fail'
+ cp -r "$(git rev-parse --show-toplevel 2>/dev/null || hg root 2>/dev/null || echo "$PWD")" /tmp/$$xmake_getter || my_exit 'Clone Fail'
fi
-make -C /tmp/$$xmake_getter --no-print-directory build || my_exit 'Build Fail'
-IFS=':'
-patharr=($PATH)
+if [ 'x__install_only__' != "x$2" ]
+then
+ make -C /tmp/$$xmake_getter --no-print-directory build || my_exit 'Build Fail'
+fi
+PATHclone=$PATH
+patharr=($PATHclone)
prefix=
-for st in ${patharr[@]}
+for st in "${patharr[@]}"
do
if [[ "$st" = "$HOME"* ]]
then
- cwd=$(pwd)
+ cwd=$PWD
mkdir -p "$st"
- cd "$st"
+ cd "$st" || continue
echo $$ > $$xmake_getter_test 2>/dev/null || continue
rm $$xmake_getter_test 2>/dev/null || continue
- cd ..
+ cd .. || continue
mkdir -p share 2>/dev/null || continue
prefix=$(pwd)
- cd "$cwd"
+ cd "$cwd" || my_exit 'Chdir Error'
break
fi
done
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 4fbc1740b..b2a41aa31 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -514,6 +514,11 @@ function sandbox_os.sudol(runner, luafile, luaargv)
sandbox_os.sudov(runner, path.join(sandbox_os.programdir(), "xmake"), table.join(argv, luafile, luaargv))
end
+-- get versioninfo
+function sandbox_os.versioninfo()
+ return os.versioninfo()
+end
+
-- return module
return sandbox_os
diff --git a/xmake/plugins/lua/scripts/versioninfo.lua b/xmake/plugins/lua/scripts/versioninfo.lua
new file mode 100644
index 000000000..c6d01667b
--- /dev/null
+++ b/xmake/plugins/lua/scripts/versioninfo.lua
@@ -0,0 +1,3 @@
+function main()
+ table.dump(os.versioninfo())
+end