/
autogen.sh
executable file
·181 lines (135 loc) · 3.88 KB
/
autogen.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
#!/bin/bash
exname="$(basename "$0")"
##
## Functions
##
function get_path() {
local type
type="$(type -t "$1")"
case $type in
("file")
type -p "$1"
return 0
;;
("function" | "builtin" )
echo "$1"
return 0
;;
esac
return 1
}
function print_exit() {
echo $@
exit 1
}
function print_syntax_error() {
[ "$*" ] || print_syntax_error "$FUNCNAME: no arguments"
print_exit "${ERROR}script error:${NORMAL} $@" >&2
}
function print_syntax_warning() {
[ "$*" ] || print_syntax_error "$FUNCNAME: no arguments."
[ "$exname" ] || print_syntax_error "$FUNCNAME: 'exname' var is null or not defined."
echo "$exname: ${WARNING}script warning:${NORMAL} $@" >&2
}
function print_error() {
[ "$*" ] || print_syntax_warning "$FUNCNAME: no arguments."
[ "$exname" ] || print_exit "$FUNCNAME: 'exname' var is null or not defined." >&2
print_exit "$exname: ${ERROR}error:${NORMAL} $@" >&2
}
function depends() {
local i tr path
tr=$(get_path "tr")
test "$tr" ||
print_error "dependency check : couldn't find 'tr' command."
for i in $@ ; do
if ! path=$(get_path $i); then
new_name=$(echo $i | "$tr" '_' '-')
if [ "$new_name" != "$i" ]; then
depends "$new_name"
else
print_error "dependency check : couldn't find '$i' command."
fi
else
if ! test -z "$path" ; then
export "$(echo $i | "$tr" '-' '_')"=$path
fi
fi
done
}
function die() {
[ "$*" ] || print_syntax_warning "$FUNCNAME: no arguments."
[ "$exname" ] || print_exit "$FUNCNAME: 'exname' var is null or not defined." >&2
print_exit "$exname: ${ERROR}error:${NORMAL} $@" >&2
}
function matches() {
echo "$1" | "$grep" -E "^$2\$" >/dev/null 2>&1
}
##
## Code
##
depends git sed grep
if ! "$git" rev-parse HEAD >/dev/null 2>&1; then
die "Didn't find a git repository. autogen.sh uses git to create changelog \
and version information."
fi
long_tag="[0-9]+\.[0-9]+(\.[0-9]+)?-[0-9]+-[0-9a-f]+"
short_tag="[0-9]+\.[0-9]+(\.[0-9]+)?"
get_short_tag="s/^($short_tag).*\$/\1/g"
function get_current_git_date_timestamp() {
"$git" show -s --pretty=format:%ct
}
function dev_version_tag() {
date -d "@$(get_current_git_date_timestamp)" +%Y%m%d%H%M
}
function get_current_version() {
version=$("$git" describe --tags)
if matches "$version" "$short_tag"; then
echo "$version"
else
version=$(echo "$version" | "$sed" -r "$get_short_tag")
echo "${version}.1dev_r$(dev_version_tag)"
fi
}
function set_version() {
version=$(get_current_version)
short_version=$(echo "$version" | cut -f 1,2,3 -d ".")
year=$(date -d "@$(get_current_git_date_timestamp)" +%Y)
sed -ri "s/%%version%%/$version/g" pkg/pkginfo &&
sed -ri "s/%%year%%/$year/g" pkg/licence &&
sed -ri "s/%%short-version%%/${short_version}/g" pkg/pkginfo &&
echo "Version updated to $version."
}
##
## ChangeLog generation
##
if type -t gitchangelog > /dev/null 2>&1 ; then
gitchangelog > ChangeLog
if [ "$?" != 0 ]; then
print_error "Error while generating ChangeLog."
fi
echo "ChangeLog generated."
else
echo "No changelog generated (gitchangelog not found)"
fi
##
## Set version information
##
set_version
if [ "$?" != 0 ]; then
print_error "Error while updating version information."
fi
##
## Launch autoreconf if needed
##
if [ -f configure.ac -o -f configure.in ]; then
if ! type -p autoreconf >/dev/null; then
echo "``autoreconf`` not found."
echo "To autogen this package, please install autotools suite. (package ``autoconf`` in debian)"
exit 1
fi
if ! [ -f README ] && [ -f README.rst ]; then
cp README.rst README
fi
touch NEWS AUTHORS ChangeLog
autoreconf -i
fi