-
Notifications
You must be signed in to change notification settings - Fork 34
/
readline_athame_setup.sh
executable file
·204 lines (187 loc) · 6.37 KB
/
readline_athame_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# readline_athame_setup.sh -- Full vim integration for your shell.
#
# Copyright (C) 2017 James Kolb
#
# This file is part of Athame.
#
# Athame is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version.
#
# Athame 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Athame. If not, see <http://www.gnu.org/licenses/>.
shopt -s extglob
patches=0
redownload=0
build=1
runtest=1
athame=1
dirty=0
rc=1
submodule=1
vimbin=""
destdir=""
sudo=""
prefix_flag="--prefix=/usr"
libdir_flag=""
for arg in "$@"
do
case "$arg" in
"--redownload" ) redownload=1;;
"--nobuild" ) build=0;;
"--notest" ) runtest=0;;
"--noathame" ) athame=0;;
"--dirty" ) dirty=1;;
"--norc" ) rc=0;;
"--nosubmodule" ) submodule=0;;
"--use_sudo" ) sudo="sudo ";;
--vimbin=*) vimbin="${arg#*=}";;
--destdir=*) destdir="${arg#*=}";;
--prefix=*) prefix_flag='--prefix='"${arg#*=}";;
--libdir=*) libdir="${arg#*=}";libdir_flag="--libdir=$libdir";;
"--help" ) echo -e " --redownload: redownload readline and patches\n" \
"--nobuild: stop before actually building src\n" \
"--notest: don't run tests\n" \
"--noathame: setup normal readline without athame\n" \
"--vimbin=path/to/vim: set a path to the vim binary\n"\
" you want athame to use\n" \
"--prefix: set prefix for configure\n"\
"--libdir: set libdir for configure\n"\
"--destdir: set DESTDIR for install\n"\
"--dirty: don't run the whole patching/configure process,\n" \
" just make and install changes\n" \
"--norc: don't copy the rc file to /etc/athamerc\n" \
"--nosubmodule: don't update submodules\n" \
"--use_sudo: use sudo for installation and copying athamerc\n" \
"--help: display this message"; exit;;
* ) echo Unknown flag "$arg" >&2; exit 1;;
esac
done
#Get vim binary
if [ -z "$vimbin" ]; then
vimmsg="Please provide a vim binary by running this script with --vimbin=/path/to/vim at the end. (replace with the actual path to vim)"
testvim="$(which vim)"
if [ -z "$testvim" ]; then
echo "Could not find a vim binary using 'which'"
echo $vimmsg
exit
fi
echo "No vim binary provided. Trying $testvim"
if [ "$($testvim --version | grep -E '(\+job|nvim)')" ]; then
vimbin="$testvim"
echo "$vimbin probably has job support. Using $vimbin as vim binary."
ATHAME_USE_JOBS_DEFAULT=1
elif [ "$($testvim --version | grep +clientserver)" ]; then
vimbin="$testvim"
echo "$vimbin probably has clientserver support. Using $vimbin as vim binary."
ATHAME_USE_JOBS_DEFAULT=0
else
echo "$testvim does not appear to have job or clientserver support."
echo $vimmsg
exit
fi
else
if [ "$($vimbin --version | grep -E '(\+job|nvim)')" ]; then
ATHAME_USE_JOBS_DEFAULT=1
else
ATHAME_USE_JOBS_DEFAULT=0
fi
fi
if [ $submodule = 1 ]; then
git submodule update --init
fi
#Download Readline
if [ $redownload = 1 ]; then
rm -r readline-8.0.tar.gz
fi
if [ ! -f readline-8.0.tar.gz ]; then
curl -O https://ftp.gnu.org/gnu/readline/readline-8.0.tar.gz
fi
mkdir -p readline_patches
cd readline_patches
for (( patch=1; patch <= patches; patch++ )); do
if [ $redownload = 1 ]; then
rm -r readline80-$(printf "%03d" $patch)
fi
if [ ! -f readline80-$(printf "%03d" $patch) ]; then
curl -O https://ftp.gnu.org/gnu/readline/readline-8.0-patches/readline80-$(printf "%03d" $patch)
fi
done
cd ..
if [ ! -d readline-8.0_tmp ]; then
dirty=0
fi
#Unpack readline dir
if [ $dirty = 0 ]; then
rm -rf readline-8.0_tmp
tar -xf readline-8.0.tar.gz
mv readline-8.0 readline-8.0_tmp
fi
#Move into readline directory
cd readline-8.0_tmp
if [ $dirty = 0 ]; then
#Patch readline with readline patches
for (( patch=1; patch <= patches; patch++ )); do
echo Patching with standard readline patch $patch
patch -p0 < ../readline_patches/readline80-$(printf "%03d" $patch)
done
fi
if [ $athame = 1 ]; then
if [ $dirty = 0 ]; then
../athame_patcher.sh readline .. || exit 1
else
../athame_patcher.sh --dirty readline .. || exit 1
fi
fi
if [ $build != 1 ]; then
exit 0
fi
#Build and install Readline
if [ ! -f Makefile ]; then
./configure "$prefix_flag" "$libdir_flag" || exit 1
fi
make CFLAGS=-std=c99 SHLIB_LIBS="-lncurses -lutil" ATHAME_VIM_BIN="$vimbin" ATHAME_USE_JOBS_DEFAULT="$ATHAME_USE_JOBS_DEFAULT" || exit 1
if [ $runtest = 1 ]; then
rm -rf $(pwd)/../test/build
mkdir -p $(pwd)/../test/build
make install DESTDIR=$(pwd)/../test/build || exit 1
cd ../test
export LD_LIBRARY_PATH="$(dirname $(find $(pwd)/build -name libreadline* | head -n 1))"
export ATHAME_VIMBED_LOCATION="$(find $(pwd)/build -name athame_readline | head -n 1)"
if [ "$($vimbin --version | grep nvim)" ]; then
nvim="nvim"
fi
if [ "$(uname)" == "Darwin" ]; then
export DYLD_LIBRARY_PATH="$LD_LIBRARY_PATH"
otool -L "$(which bash)" | grep libreadline.8.dylib >/dev/null
else
ldd "$(which bash)" | grep libreadline.so.8 >/dev/null
fi
if [ $? -eq 1 ]; then
echo "Bash isn't set to use system readline or is not using readline 8. Setting up local bash for testing."
cd ..
./bash_readline_setup.sh --destdir="$(pwd)/test/build" --use_readline="${LD_LIBRARY_PATH%+(/lib|/lib/*)}"
cd test
./runtests.sh "$(pwd)/build/bin/bash -i" bash $nvim || exit 1
else
./runtests.sh "bash -i" bash $nvim || exit 1
fi
cd ../readline-8.0_tmp
fi
echo "Installing Readline with Athame..."
if [ -n "$destdir" ]; then
mkdir -p "$destdir"
fi
${sudo}make install DESTDIR="$destdir" || exit 1
if [ $rc = 1 ]; then
${sudo}cp ../athamerc /etc/athamerc
if [ $? -ne 0 ]; then
printf "\e[0;31mThe athamerc was not copied. You should copy athamerc to /etc/athamerc or ~/.athamerc.\e[0;0m\n"
fi
fi