`pakk_logg`: Make it work on the mobile
[sunny256-utils.git] / build-vim
blob6aad8c1e034df8bdc3956dc92b31d410d9dda410
1 #!/usr/bin/env bash
3 #=======================================================================
4 # build-vim
5 # File ID: 6d23a156-5d3e-11df-9a9a-90e6ba3022ac
7 # Compile and install Vim
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=build-vim
14 VERSION=0.5.1
15 rcfile="$HOME/.${progname}rc"
16 configure_opts="--with-features=huge --with-x --enable-multibyte"
17 cloneurl=https://github.com/vim/vim.git
18 branch=master
19 remotename=origin
21 ARGS="$(getopt -o "\
29 " -l "\
30 help,\
31 dry-run,\
32 no-install,\
33 quiet,\
34 update,\
35 verbose,\
36 yes,\
37 version,\
38 " -n "$progname" -- "$@")"
39 test "$?" = "0" || exit 1
40 eval set -- "$ARGS"
42 opt_f=0
43 opt_help=0
44 opt_dry_run=0
45 opt_no_install=0
46 opt_quiet=0
47 opt_update=0
48 opt_verbose=0
49 opt_yes=0
50 while :; do
51 case "$1" in
52 -f) opt_f=1; shift ;;
53 -h|--help) opt_help=1; shift ;;
54 -n|--dry-run) opt_dry_run=1; shift ;;
55 --no-install) opt_no_install=1; shift ;;
56 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
57 -u|--update) opt_update=1; shift ;;
58 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
59 -y|--yes) opt_yes=1; shift ;;
60 --version) echo $progname $VERSION; exit 0 ;;
61 --) shift; break ;;
62 *) echo $progname: Internal error >&2; exit 1 ;;
63 esac
64 done
65 opt_verbose=$(($opt_verbose - $opt_quiet))
67 if test "$opt_help" = "1"; then
68 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
69 cat <<END
71 Compile and install Vim
73 Usage: $progname [options]
75 Options:
78 Remove lockdir before installing The Holy Editor.
79 -h, --help
80 Show this help.
81 -n, --dry-run
82 Don't do anything, output commands that would be executed instead.
83 --no-install
84 Exit after the tests have been run, don't install.
85 -q, --quiet
86 Be more quiet. Can be repeated to increase silence.
87 -u, --update
88 Fetch new commits and update the source code before starting the
89 build.
90 -v, --verbose
91 Increase level of verbosity. Can be repeated.
93 Answer 'y' to all questions, perform an automated build. May cause
94 the script to hang if sudo is used and it's timed out.
95 --version
96 Print version information.
98 If "$rcfile" exists, execute it before the compilation starts.
99 Use it to configure the build for each computer. For example:
101 prefix=~/local
102 sudo=
104 will place everything below the ~/local directory and not use sudo.
106 These are the main variables to control the build:
108 - cloneurl
109 Git URL to clone the source from if the \$srcdir directory
110 doesn't exist.
111 Default value: $cloneurl
112 - remotename
113 Local name of cloned remote.
114 Default value: $remotename
115 - branch
116 Check out this branch after cloning the source from \$cloneurl.
117 Default value: $branch
118 - srcdir
119 Directory where the cloned source from \$cloneurl is stored.
120 Default value: \$HOME/src/other/vim
121 - prefix
122 Top directory of the installed files.
123 Default value: /usr/local
124 - prgdir
125 Directory where the symlink of the current version is stored. Points
126 to \$destdir.
127 Default value: \$prefix/prg
128 - destdir
129 Directory where the compiled files are installed.
130 Default value: \$prefix/varprg/vim-\$desc
131 - configure_opts
132 Options passed to "./configure".
133 Default value: $configure_opts
134 - desc
135 Version number, you shouldn't need to touch this.
136 Default value is the output of "git describe --long --tags".
137 - user
138 Owner of the \$prefix directory.
139 Default value is the output of "whoami". "make install" is not
140 executed as root to be sure that no files are installed outside
141 \$prefix.
142 - group
143 Group of the \$prefix directory.
144 Default value: Same as \$user.
145 - sudo
146 Set to "1" or "true" if sudo(8) should be used. Any other value
147 disables sudo.
148 Default value: true
151 exit 0
154 exec_rcfile() {
155 test -e "$rcfile" && . "$rcfile"
158 msg() {
159 unset no_lf
160 if test "$1" = "-n"; then
161 # If -n is first argument, don't terminate with \n
162 local no_lf="-n"
163 shift
165 if test "$1" = "-s"; then
166 # If -s is specified, skip initial \n
167 shift
168 else
169 echo >&2
171 echo $no_lf "$progname: $*" >&2
172 return
175 if test $(tput cols) -lt 80 -o $(tput lines) -lt 24; then
176 echo $progname: The tests need screen size 80x24 or more to run >&2
177 exit 1
180 lockdir="$HOME/.$progname.LOCK"
182 if test "$opt_f" = "1"; then
183 rmdir -v "$lockdir"
186 unset sim
187 if test "$opt_dry_run" = "1"; then
188 sim=echo
189 sim_str=" (Simulated)"
192 cleanup() {
193 rmdir "$lockdir" || msg -s $lockdir: Cannot remove lockdir
196 continue_if_y() {
197 if test "$opt_yes" = "1"; then
198 echo y >&2
199 else
200 unset choice_y
201 until test "$choice_y" = "y"; do
202 read choice_y
203 test "$choice_y" = "n" && exit 0
204 if test "$choice_y" != "y"; then
205 msg -n -s "Please press 'y' or 'n': "
207 done
209 return
212 mkdir "$lockdir" || {
213 msg -s $lockdir: Lockdir exists, aborting
214 exit 1
217 trap cleanup EXIT
219 srcdir="$HOME/src/other/vim"
220 exec_rcfile
221 if test ! -d "$srcdir/READMEdir"; then
222 msg -s $srcdir/ doesn\'t exist, clone it &&
223 msg -n -s "from $cloneurl (y/n)?$sim_str " &&
224 continue_if_y &&
225 $sim git clone -o "$remotename" $cloneurl "$srcdir" &&
226 cd "$srcdir" &&
227 $sim git checkout "$branch" &&
228 echo >&2 ||
229 exit 1
231 cd "$srcdir" || {
232 if test "$sim" = "echo"; then
233 msg $srcdir doesn\'t exist,
234 msg -s values of \$desc and \$destdir are not shown correctly.
235 msg -s Not a problem, since we\'re only simulating.
236 echo >&2
237 else
238 exit 1
242 user="$(whoami)"
243 group="$user"
244 sudo=true
245 prefix="/usr/local"
246 exec_rcfile
247 prgdir="$prefix/prg"
248 exec_rcfile
249 test "$sudo" = "1" -o "$sudo" = "true" && sudo=sudo || unset sudo
251 if test "$sim" != "echo"; then
252 test -z "$(git status --porcelain)" || {
253 msg -s $srcdir is not clean
254 echo >&2
255 git status -s
256 msg -n Press \'y\' to clean it, or \'n\' to abort...
257 continue_if_y
258 git checkout -f
259 git clean -fxd
263 if test "$opt_update" = "1"; then
264 $sim git fetch origin
265 $sim git merge --ff-only
268 desc="$(git describe --long --tags)"
269 destdir="$prefix/varprg/vim-$desc"
271 if test "$opt_no_install" != "1"; then
272 test -e "$destdir" && {
273 $sim $sudo rmdir "$destdir" || {
274 msg -s $destdir already exists
275 exit 1
280 test "$opt_no_install" = "1" && butnot_str=", but not" || butnot_str=" and"
281 cat <<END
282 Going to compile$butnot_str install "vim-$desc"$sim_str
284 cloneurl = "$cloneurl"
285 remotename = "$remotename"
286 branch = "$branch"
287 srcdir = "$srcdir"
288 prefix = "$prefix"
289 prgdir = "$prgdir"
290 destdir = "$destdir"
291 configure_opts = "$configure_opts"
292 user = "$user"
293 group = "$group"
294 sudo = "$sudo"
298 echo -n If that looks OK, press \'y\' to start the build or \'n\' to abort...
299 continue_if_y
301 if test "$opt_no_install" != "1"; then
302 msg mkdir and chown $destdir &&
303 $sim $sudo mkdir -p "$destdir" &&
304 $sim $sudo chown "$user"."$group" "$destdir" &&
306 msg mkdir -p $prefix/share/man/man1 &&
307 $sim mkdir -p "$prefix/share/man/man1" &&
309 msg mkdir -p $prefix/bin &&
310 $sim mkdir -p "$prefix/bin" || exit 1
313 $sim cd "$srcdir" &&
315 msg git clean in $srcdir/ &&
316 $sim git clean -fxd &&
318 msg ./configure $configure_opts &&
319 $sim ./configure --prefix="$destdir" $configure_opts &&
320 msg make &&
321 $sim make &&
323 msg make test &&
324 $sim make test &&
326 test "$opt_no_install" != "1" &&
328 msg make install &&
329 $sim make install &&
331 $sim cd "$prgdir" &&
332 msg Update the vim symlink in $prgdir/ &&
333 $sim $sudo ln -fnsv "../varprg/vim-$desc" vim &&
335 $sim cd "$prefix/share/man/man1" &&
336 msg Create manpage symlinks in $prefix/share/man/man1/ &&
337 $sim $sudo ln -fnsv ../../../prg/vim/share/man/man1/* . &&
339 $sim cd "$prefix/share" &&
340 msg Create $prefix/share/vim symlink &&
341 $sim $sudo ln -fnsv ../prg/vim/share/vim . &&
343 $sim cd "$prefix/bin" &&
344 msg Create symlinks in $prefix/bin/ &&
345 $sim $sudo ln -fnsv ../prg/vim/bin/* . &&
347 if test -d "$prefix/.git/."; then
348 msg Commit the symlink &&
349 commitmsg=$(
350 echo $progname installed vim-$desc on $(hostname)
351 if suuid --version 2>/dev/null | grep -q "^suuid v"; then
352 echo
353 $sim suuid -t commit,$progname
354 fi || true
355 ) &&
356 $sim cd "$prgdir" &&
357 $sim $sudo git add vim &&
358 echo Commit message: &&
359 echo $commitmsg &&
360 $sim $sudo git commit -m "$commitmsg"
361 fi &&
364 msg Successfully installed vim-$desc$sim_str
365 retval=0
366 } || {
367 if test "$opt_no_install" = "1"; then
368 msg --no-install is used, skipping install
369 retval=0
370 else
371 msg Something went bananas
372 retval=1
376 exit $retval
378 # vim: set ts=4 sw=4 sts=4 et fenc=utf8 :