-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-vim
executable file
·378 lines (326 loc) · 8.79 KB
/
build-vim
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/usr/bin/env bash
#=======================================================================
# build-vim
# File ID: 6d23a156-5d3e-11df-9a9a-90e6ba3022ac
#
# Compile and install Vim
#
# Author: Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later.
#=======================================================================
progname=build-vim
VERSION=0.5.1
rcfile="$HOME/.${progname}rc"
configure_opts="--with-features=huge --with-x --enable-multibyte"
cloneurl=https://github.com/vim/vim.git
branch=master
remotename=origin
ARGS="$(getopt -o "\
f\
h\
n\
q\
u\
v\
y\
" -l "\
help,\
dry-run,\
no-install,\
quiet,\
update,\
verbose,\
yes,\
version,\
" -n "$progname" -- "$@")"
test "$?" = "0" || exit 1
eval set -- "$ARGS"
opt_f=0
opt_help=0
opt_dry_run=0
opt_no_install=0
opt_quiet=0
opt_update=0
opt_verbose=0
opt_yes=0
while :; do
case "$1" in
-f) opt_f=1; shift ;;
-h|--help) opt_help=1; shift ;;
-n|--dry-run) opt_dry_run=1; shift ;;
--no-install) opt_no_install=1; shift ;;
-q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
-u|--update) opt_update=1; shift ;;
-v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
-y|--yes) opt_yes=1; shift ;;
--version) echo $progname $VERSION; exit 0 ;;
--) shift; break ;;
*) echo $progname: Internal error >&2; exit 1 ;;
esac
done
opt_verbose=$(($opt_verbose - $opt_quiet))
if test "$opt_help" = "1"; then
test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
cat <<END
Compile and install Vim
Usage: $progname [options]
Options:
-f
Remove lockdir before installing The Holy Editor.
-h, --help
Show this help.
-n, --dry-run
Don't do anything, output commands that would be executed instead.
--no-install
Exit after the tests have been run, don't install.
-q, --quiet
Be more quiet. Can be repeated to increase silence.
-u, --update
Fetch new commits and update the source code before starting the
build.
-v, --verbose
Increase level of verbosity. Can be repeated.
-y
Answer 'y' to all questions, perform an automated build. May cause
the script to hang if sudo is used and it's timed out.
--version
Print version information.
If "$rcfile" exists, execute it before the compilation starts.
Use it to configure the build for each computer. For example:
prefix=~/local
sudo=
will place everything below the ~/local directory and not use sudo.
These are the main variables to control the build:
- cloneurl
Git URL to clone the source from if the \$srcdir directory
doesn't exist.
Default value: $cloneurl
- remotename
Local name of cloned remote.
Default value: $remotename
- branch
Check out this branch after cloning the source from \$cloneurl.
Default value: $branch
- srcdir
Directory where the cloned source from \$cloneurl is stored.
Default value: \$HOME/src/other/vim
- prefix
Top directory of the installed files.
Default value: /usr/local
- prgdir
Directory where the symlink of the current version is stored. Points
to \$destdir.
Default value: \$prefix/prg
- destdir
Directory where the compiled files are installed.
Default value: \$prefix/varprg/vim-\$desc
- configure_opts
Options passed to "./configure".
Default value: $configure_opts
- desc
Version number, you shouldn't need to touch this.
Default value is the output of "git describe --long --tags".
- user
Owner of the \$prefix directory.
Default value is the output of "whoami". "make install" is not
executed as root to be sure that no files are installed outside
\$prefix.
- group
Group of the \$prefix directory.
Default value: Same as \$user.
- sudo
Set to "1" or "true" if sudo(8) should be used. Any other value
disables sudo.
Default value: true
END
exit 0
fi
exec_rcfile() {
test -e "$rcfile" && . "$rcfile"
}
msg() {
unset no_lf
if test "$1" = "-n"; then
# If -n is first argument, don't terminate with \n
local no_lf="-n"
shift
fi
if test "$1" = "-s"; then
# If -s is specified, skip initial \n
shift
else
echo >&2
fi
echo $no_lf "$progname: $*" >&2
return
}
if test $(tput cols) -lt 80 -o $(tput lines) -lt 24; then
echo $progname: The tests need screen size 80x24 or more to run >&2
exit 1
fi
lockdir="$HOME/.$progname.LOCK"
if test "$opt_f" = "1"; then
rmdir -v "$lockdir"
fi
unset sim
if test "$opt_dry_run" = "1"; then
sim=echo
sim_str=" (Simulated)"
fi
cleanup() {
rmdir "$lockdir" || msg -s $lockdir: Cannot remove lockdir
}
continue_if_y() {
if test "$opt_yes" = "1"; then
echo y >&2
else
unset choice_y
until test "$choice_y" = "y"; do
read choice_y
test "$choice_y" = "n" && exit 0
if test "$choice_y" != "y"; then
msg -n -s "Please press 'y' or 'n': "
fi
done
fi
return
}
mkdir "$lockdir" || {
msg -s $lockdir: Lockdir exists, aborting
exit 1
}
trap cleanup EXIT
srcdir="$HOME/src/other/vim"
exec_rcfile
if test ! -d "$srcdir/READMEdir"; then
msg -s $srcdir/ doesn\'t exist, clone it &&
msg -n -s "from $cloneurl (y/n)?$sim_str " &&
continue_if_y &&
$sim git clone -o "$remotename" $cloneurl "$srcdir" &&
cd "$srcdir" &&
$sim git checkout "$branch" &&
echo >&2 ||
exit 1
fi
cd "$srcdir" || {
if test "$sim" = "echo"; then
msg $srcdir doesn\'t exist,
msg -s values of \$desc and \$destdir are not shown correctly.
msg -s Not a problem, since we\'re only simulating.
echo >&2
else
exit 1
fi
}
user="$(whoami)"
group="$user"
sudo=true
prefix="/usr/local"
exec_rcfile
prgdir="$prefix/prg"
exec_rcfile
test "$sudo" = "1" -o "$sudo" = "true" && sudo=sudo || unset sudo
if test "$sim" != "echo"; then
test -z "$(git status --porcelain)" || {
msg -s $srcdir is not clean
echo >&2
git status -s
msg -n Press \'y\' to clean it, or \'n\' to abort...
continue_if_y
git checkout -f
git clean -fxd
}
fi
if test "$opt_update" = "1"; then
$sim git fetch origin
$sim git merge --ff-only
fi
desc="$(git describe --long --tags)"
destdir="$prefix/varprg/vim-$desc"
if test "$opt_no_install" != "1"; then
test -e "$destdir" && {
$sim $sudo rmdir "$destdir" || {
msg -s $destdir already exists
exit 1
}
}
fi
test "$opt_no_install" = "1" && butnot_str=", but not" || butnot_str=" and"
cat <<END
Going to compile$butnot_str install "vim-$desc"$sim_str
cloneurl = "$cloneurl"
remotename = "$remotename"
branch = "$branch"
srcdir = "$srcdir"
prefix = "$prefix"
prgdir = "$prgdir"
destdir = "$destdir"
configure_opts = "$configure_opts"
user = "$user"
group = "$group"
sudo = "$sudo"
END
echo -n If that looks OK, press \'y\' to start the build or \'n\' to abort...
continue_if_y
if test "$opt_no_install" != "1"; then
msg mkdir and chown $destdir &&
$sim $sudo mkdir -p "$destdir" &&
$sim $sudo chown "$user"."$group" "$destdir" &&
msg mkdir -p $prefix/share/man/man1 &&
$sim mkdir -p "$prefix/share/man/man1" &&
msg mkdir -p $prefix/bin &&
$sim mkdir -p "$prefix/bin" || exit 1
fi
$sim cd "$srcdir" &&
msg git clean in $srcdir/ &&
$sim git clean -fxd &&
msg ./configure $configure_opts &&
$sim ./configure --prefix="$destdir" $configure_opts &&
msg make &&
$sim make &&
msg make test &&
$sim make test &&
test "$opt_no_install" != "1" &&
msg make install &&
$sim make install &&
$sim cd "$prgdir" &&
msg Update the vim symlink in $prgdir/ &&
$sim $sudo ln -fnsv "../varprg/vim-$desc" vim &&
$sim cd "$prefix/share/man/man1" &&
msg Create manpage symlinks in $prefix/share/man/man1/ &&
$sim $sudo ln -fnsv ../../../prg/vim/share/man/man1/* . &&
$sim cd "$prefix/share" &&
msg Create $prefix/share/vim symlink &&
$sim $sudo ln -fnsv ../prg/vim/share/vim . &&
$sim cd "$prefix/bin" &&
msg Create symlinks in $prefix/bin/ &&
$sim $sudo ln -fnsv ../prg/vim/bin/* . &&
if test -d "$prefix/.git/."; then
msg Commit the symlink &&
commitmsg=$(
echo $progname installed vim-$desc on $(hostname)
if suuid --version 2>/dev/null | grep -q "^suuid v"; then
echo
$sim suuid -t commit,$progname
fi || true
) &&
$sim cd "$prgdir" &&
$sim $sudo git add vim &&
echo Commit message: &&
echo $commitmsg &&
$sim $sudo git commit -m "$commitmsg"
fi &&
{
msg Successfully installed vim-$desc$sim_str
retval=0
} || {
if test "$opt_no_install" = "1"; then
msg --no-install is used, skipping install
retval=0
else
msg Something went bananas
retval=1
fi
}
exit $retval
# vim: set ts=4 sw=4 sts=4 et fenc=utf8 :