-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate-patch.sh
executable file
·184 lines (126 loc) · 3.3 KB
/
generate-patch.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
#!/bin/sh
set -e
trap "cleanup" EXIT
while getopts hc:d:D:l:s:o:p:T:t:V:x arg
do
case $arg in
h) usage=0 ;;
c) compress=$OPTARG ;;
d) destdir=$OPTARG ;;
D) cleantmp=1 ;;
l) tarball=$OPTARG ;;
p) makepatch=$OPTARG ;;
s) srcdir=$OPTARG ;;
t) tmpdir=$OPTARG ;;
T) git_tag=$OPTARG ;;
V) lua_version=$OPTARG ;;
x) set -x ;;
?) usage=1 ;;
esac
done
cleanup () {
if [ "x$cleantmp" = x1 ]; then
chmod -R +w "$tmpdir"
rm -rf "$tmpdir"
fi
}
get_lua_version () {
lua_version=$(grep '#define LUA_RELEASE' $srcdir/src/lua.h | sed 's/[^0-9.]//g')
}
get_git_tag () {
git_tag=$(git tag | grep -F ${lua_version} | sort -r | head -1)
if [ "x$tag" = x ]; then
echo >&2 "couldn't find a tag for lua version ${lua_version}"
exit 1
fi
}
check_git_tag () {
tag=$(git tag | grep -F "$git_tag")
if [ "x$tag" = x ]; then
echo >&2 "'$git_tag' isn't a git tag"
exit 1
fi
if [ "${git_tag#$lua_version}" = "${git_tag}" ] ; then
echo >&2 "git tag '$git_tag' isn't consistent with Lua version $lua_version"
exit 1
fi
}
usage () {
cat >&2 <<EOF
usage: $0 <options>
Generate a patch for lua.
patch is left in the current directory.
-h print help and exit
-c <command> compression tool ("none" for none) [$compress]
-d <dir> absolute path to directory into which to write the patch [$destdir]
-D delete temp directory when done [default=don't]
-V <version> Lua version to patch [default=current checked out branch]
-T <tag> git tag to use to generate patch. [default = latest tag for Lua version]
-l <file> absolute path to lua tarball [automatically downloaded]
-p <command> patch tool [$makepatch]
-s <dir> absolute path to git source directory [$srcdir]
-t <dir> temporary directory [${tmpdir:-automatically generated}]
-x be extremely verbose
EOF
}
pwd=$(pwd)
: ${makepatch:=diff -urN}
: ${srcdir:=$pwd}
: ${destdir:=$pwd}
: ${compress:=bzip2 -c}
if [ "x$usage" != "x" ]; then
usage
exit $usage
fi
# don't initialize until we need it
: ${tmpdir:=$(mktemp -d)}
echo "Working in $tmpdir"
cd $tmpdir
GIT_DIR=$srcdir/.git
export GIT_DIR
# find latest git tag
if [ "$git_tag" = "" ] ; then
if [ "$lua_version" = "" ] ; then
get_lua_version
fi
get_git_tag
else
if [ "$lua_version" = "" ] ; then
lua_version=${git_tag%.[0-9][0-9]}
fi
check_git_tag
fi
echo "Lua version: $lua_version"
echo "Using tag: $git_tag"
original="lua-${lua_version}"
pkg_version=$(echo $git_tag | sed "s/$lua_version[.]//")
if [ "x$tarball" = x ]; then
# download lua tarball
tarball=lua-${lua_version}.tar.gz
echo "Downloading $tarball"
wget -q http://www.lua.org/ftp/$tarball
else
echo "Using $tarball as base"
fi
tar -xzf $tarball
patched="lua-${lua_version}-autotoolize-r${pkg_version}"
rm -rf $patched
mkdir $patched
git archive $git_tag \
| tar --exclude-vcs -C $patched -xf -
(cd $patched
sh autogen.sh
rm -rf autom4te.cache/
)
suffix=
case "$compress" in
bzip* ) suffix=.bz2 ;;
gzip* ) suffix=.gz ;;
xz* ) suffix=.xz ;;
none ) compress= ;;
esac
output="${patched}.patch${suffix}"
eval ${makepatch} $original $patched \
${compress:+| $compress} \
> $destdir/$output
echo "Wrote $destdir/$output"