forked from drmikehenry/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildtool_old
executable file
·212 lines (189 loc) · 5.12 KB
/
buildtool_old
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
#!/bin/bash
DOWNLOAD_DIRS="$HOME/download/programming/vim /tools/software/vim"
function usage()
{
cat <<EOF
Usage: `basename "$0"` VIM_SOURCE_PATH [ACTION+]
VIM_SOURCE_PATH must end in a Vim version number in the form MAJOR.MINOR
and may be relative or absolute, e.g.:
7.3
../sources/7.3
/download/vim/7.3
Relative paths will be searched in the current directory, then in these
"standard" locations:
EOF
for d in $DOWNLOAD_DIRS; do
echo " $d"
done
cat <<EOF
Valid ACTIONs are:
update - use "git pull" to update git/ directory
unpack - unpack Vim sources below CWD
configure - configure Vim with standard build options
build - build Vim and create binary tarball
Default action list: unpack configure build
Building takes place in "vim-MAJOR.MINOR" in current working directory.
Vim source must be MAJOR.MINOR/git/ or MAJOR.MINOR/vim-MAJOR.MINOR.tar.bz2.
Checkout vim with git, e.g.:
cd .../vim
git clone https://github.com/vim/vim.git git
EOF
}
function die()
{
if [ -n "$1" ]; then
echo "$1"
fi
echo "For usage instructions, run with no arguments."
exit
}
function setup()
{
DIR="$1"
if [ -z "$DIR" ]; then
usage
exit
fi
VERSION=`basename "$DIR"`
if ! echo $VERSION | grep -q '^[0-9]\+\.[0-9]\+$'; then
die "Version \"$VERSION\" not in form MAJOR.MINOR"
fi
if [ ! -d "$DIR" ]; then
for d in $DOWNLOAD_DIRS; do
probeDir="$d/$DIR"
if [ -d "$probeDir" ]; then
DIR="$probeDir"
break
fi
done
fi
if [ ! -d "$DIR" ]; then
die "Cannot find source directory $DIR"
fi
echo "Vim $VERSION sources in $DIR"
VIMNAME=vim-$VERSION
VIMDIR=$VIMNAME
echo "Vim build directory in $VIMDIR"
}
function update()
{
gitDir="$DIR/git"
if [ -d "$gitDir" ]; then
(cd "$gitDir"; git pull)
else
die "Cannot update; missing path \"$gitDir\""
fi
}
function patchlevel()
{
grep -A 3 '^static int included_patches' "$VIMDIR"/src/version.c |
tail -n 1 | perl -pe 's/^\s*(\d+).*/$1/'
}
# Return list of matching paths, reverse-sorted by version number.
# listVersions /path/to/vim-7.3. .tar.bz2
# ==>
# /path/to/vim-7.3.100.tar.bz2
# /path/to/vim-7.3.99.tar.bz2
# ...
# /path/to/vim-7.3.2.tar.bz2
# /path/to/vim-7.3.1.tar.bz2
function listVersions()
{
prefix="$1"
suffix="$2"
for i in $prefix[0-9]{,[0-9]{,[0-9]{,[0-9]}}}$suffix; do
echo "${i:${#prefix}}"
done | sort -rn | while read tail; do
echo "$prefix$tail"
done
}
function latestVersion()
{
prefix="$1"
suffix="$2"
largest=`listVersions "$prefix" "$suffix" | head -1`
echo "$largest"
}
function unpack()
{
if [ -d "$VIMDIR" ]; then
die "Must remove directory $VIMDIR manually before continuing"
fi
echo "Unpacking Vim $VERSION..."
if [ -d "$DIR/git" ]; then
echo " Extracting source from git to $VIMDIR..."
mkdir "$VIMDIR" || die "Couldn't create $VIMDIR"
(cd "$DIR/git"; git archive master) | tar -C "$VIMDIR" -x
TARNAME="$VIMDIR.`patchlevel`.tar.bz2"
SRCTAR="$VIMDIR/$TARNAME"
echo " Creating source archive $SRCTAR..."
tar -jcf "$TARNAME" --exclude "$TARNAME" "$VIMDIR"
mv "$TARNAME" "$SRCTAR"
else
TARPREFIX="$DIR/$VIMNAME."
suffix=".tar.bz2"
TARNAME=`latestVersion "$TARPREFIX" "$suffix"`
if [ -n "$TARNAME" -a -f "$TARNAME" ]; then
echo " Unpacking $TARNAME..."
tar -jxf "$TARNAME"
else
die "Error: couldn't find $VIMNAME sources; exiting"
fi
fi
}
function configure()
{
echo "Configuring in $VIMDIR..."
(
cd $VIMDIR;
./configure \
--quiet \
--with-features=huge \
--enable-perlinterp \
--enable-pythoninterp \
--enable-tclinterp \
--enable-rubyinterp \
--enable-cscope \
)
}
function build()
{
echo "Building in $VIMDIR..."
PATCHLEVEL=`patchlevel`
VIMFULLNAME="$VIMNAME.$PATCHLEVEL"
tar --version | grep 'GNU tar' > /dev/null 2>&1 &&
TAROPTS="--owner=0 --group=0"
(
TARNAME="$VIMFULLNAME.`uname -m`.tar.gz"
cd $VIMDIR
echo " Removing DESTDIR..."
rm -rf DESTDIR
mkdir DESTDIR
echo " Compiling $VIMFULLNAME..." && \
make && \
echo " Installing in $VIMDIR/DESTDIR..." && \
make install DESTDIR=`pwd`/DESTDIR && \
chmod -R u=rwX,go=rX DESTDIR && \
echo " Creating tar from $VIMDIR/DESTDIR" && \
tar -C DESTDIR --numeric-owner $TAROPTS -zcf $TARNAME . && \
echo " Created archive $VIMDIR/$TARNAME"
)
}
# Trap any exiting, setup to exit on any failures.
trap "trap - EXIT; echo Aborting" EXIT
set -e
setup "$1"
shift
if [ -z "$1" ]; then
unpack
configure
build
else
while [ -n "$1" ]; do
$1
shift
done
fi
# Reset exit trap.
trap - EXIT