forked from freeciv/freeciv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.sh
executable file
·346 lines (304 loc) · 8.85 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
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
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
DIE=0
package=freeciv
srcfile=common/game.c
SRCDIR=`dirname "$0"`
BUILDDIR=`pwd`
# Uncomment the line below to debug this file
#DEBUG=defined
FC_USE_NLS=yes
FC_HELP=no
FC_RUN_CONFIGURE=yes
# Leave out NLS checks
for NAME in $@ ; do
if [ "${NAME}" = "--help" ]; then
FC_HELP=yes
fi
if [ "${NAME}" = "--disable-nls" ]; then
echo "! nls checks disabled"
FC_USE_NLS=no
fi
if [ "${NAME}" = "--no-configure-run" ]; then
FC_RUN_CONFIGURE=no
fi
FC_NEWARGLINE="${FC_NEWARGLINE} ${NAME}"
done
debug ()
# print out a debug message if DEBUG is a defined variable
{
if [ ! -z "${DEBUG}" ]; then
echo "{DEBUG}: $1"
fi
}
real_package_name ()
# solve a real name of suitable package
# first argument : package name (executable)
# second argument : source download url
# third-fifth argument : major, minor, micro version
# sixth argument : "2" - silent
{
RPACKAGE=$1
RURL=$2
RMAJOR=$3
RMINOR=$4
RMICRO=$5
new_pkg=$RPACKAGE
if test "$6" = "" ; then
RPN_COMPLAIN=1
else
RPN_COMPLAIN=$6
fi
# check if given package is suitable
if version_check 2 $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO; then
version_check $RPN_COMPLAIN $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
else
# given package was too old or not available
# search for the newest one
if version_search $RPACKAGE; then
if version_check 2 $RPACKAGE $new_pkg $RURL $RMAJOR $RMINOR $RMICRO; then
# suitable package found
version_check $RPN_COMPLAIN $RPACKAGE $new_pkg $RURL $RMAJOR $RMINOR $RMICRO
else
# the newest package is not new enough or it is broken
version_check $RPN_COMPLAIN $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
return 1
fi
else
# no version of given package with version information
# in its name available
version_check $RPN_COMPLAIN $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
return 1
fi
fi
REALPKGNAME=$new_pkg
}
version_search ()
# search the newest version of a package
# first argument : package name (executable)
{
SPACKAGE=$1
STOREDIFS=$IFS
IFS=":"
set -- $PATH
IFS=$STOREDIFS
s_pkg_major=0
s_pkg_minor=0
new_pkg=
for SEARCHDIR ; do
for MATCHSTUFF in `ls "$SEARCHDIR/$SPACKAGE-"* 2> /dev/null` ; do
for FOUNDPKG in $MATCHSTUFF; do
# parse version information from name
new_s_pkg_major=`echo $FOUNDPKG | cut -s -d- -f2 | cut -s -d. -f1`
new_s_pkg_minor=`echo $FOUNDPKG | cut -s -d- -f2 | cut -s -d. -f2`
CORRECT=
# check if version numbers are integers
[ ! "${new_s_pkg_major}" = "" ] && \
[ "$(echo ${new_s_pkg_major} | sed s/[0-9]*//g)" = "" ] && \
[ ! "${new_s_pkg_minor}" = "" ] && \
[ "$(echo ${new_s_pkg_minor} | sed s/[0-9]*//g)" = "" ] && \
CORRECT=1
if [ ! -z $CORRECT ]; then
if [ "$new_s_pkg_major" -gt "$s_pkg_major" ]; then
s_pkg_major=$new_s_pkg_major
s_pkg_minor=$new_s_pkg_minor
new_pkg="$FOUNDPKG"
elif [ "$new_s_pkg_major" -eq "$s_pkg_major" ]; then
if [ "$new_s_pkg_minor" -gt "$s_pkg_minor" ]; then
s_pkg_major=$new_s_pkg_major
s_pkg_minor=$new_s_pkg_minor
new_pkg="$FOUNDPKG"
fi
fi
fi
done
done
done
if [ -z "$new_pkg" ]; then
return 1
else
return 0
fi
}
version_check ()
# check the version of a package
# first argument : silent ('2'), complain ('1') or not ('0')
# second argument : package name
# third argument : package name (executable)
# fourth argument : source download url
# rest of arguments : major, minor, micro version
{
COMPLAIN=$1
PACKAGEMSG=$2
PACKAGE=$3
URL=$4
MAJOR=$5
MINOR=$6
MICRO=$7
WRONG=
debug "major $MAJOR minor $MINOR micro $MICRO"
VERSION=$MAJOR
if [ ! -z "$MINOR" ]; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
if [ ! -z "$MICRO" ]; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
debug "version $VERSION"
if [ "${VERSION}" != "" ] ; then
if [ "$COMPLAIN" -ne "2" ]; then
echo "+ checking for $PACKAGEMSG >= $VERSION ... " | tr -d '\n'
fi
else
MAJOR=0
if [ "$COMPLAIN" -ne "2" ]; then
echo "+ checking for $PACKAGEMSG ... " | tr -d '\n'
fi
fi
($PACKAGE --version) < /dev/null > /dev/null 2>&1 ||
{
if [ "$COMPLAIN" -eq "1" ]; then
echo
echo "You must have $PACKAGEMSG installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at $URL"
elif [ "$COMPLAIN" -ne "2" ]; then
echo
fi
return 1
}
# The following line is carefully crafted sed magic
pkg_version=`$PACKAGE --version 2>&1|grep -a -v " line " |head -n 1|sed 's/([^)]*)//g;s/^[a-zA-Z\.\ \-]*//;s/ .*$//'`
debug "pkg_version $pkg_version"
pkg_major=`echo $pkg_version | cut -d. -f1`
pkg_minor=`echo $pkg_version | sed s/[-,a-z,A-Z+].*// | cut -d. -f2`
pkg_micro=`echo $pkg_version | sed s/[-,a-z,A-Z+].*// | cut -d. -f3`
[ -z "$pkg_major" ] && pkg_major=0
[ -z "$pkg_minor" ] && pkg_minor=0
[ -z "$pkg_micro" ] && pkg_micro=0
debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
# Start checking the version
if [ "$pkg_major" -lt "$MAJOR" ]; then
WRONG=1
elif [ "$pkg_major" -eq "$MAJOR" ]; then
if [ "$pkg_minor" -lt "$MINOR" ]; then
WRONG=1
elif [ "$pkg_minor" -eq "$MINOR" -a "$pkg_micro" -lt "$MICRO" ]; then
WRONG=1
fi
fi
if [ ! -z "$WRONG" ]; then
if [ "$COMPLAIN" -ne "2" ]; then
echo "found $pkg_version, not ok !"
fi
if [ "$COMPLAIN" -eq "1" ]; then
echo
echo "You must have $PACKAGEMSG $VERSION or greater to compile $package."
echo "Get the latest version from <$URL>."
echo
fi
return 1
else
if [ "$COMPLAIN" -ne "2" ]; then
echo "found $pkg_version, ok."
fi
fi
}
# Chdir to the srcdir, then run auto* tools.
cd "$SRCDIR"
[ -f $srcfile ] || {
echo "Are you sure \"$SRCDIR\" is a valid source directory?"
exit 1
}
# autoconf and autoheader version numbers must be kept in sync
real_package_name "autoconf" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 69 || DIE=1
AUTOCONF="${REALPKGNAME}"
real_package_name "autoheader" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 69 || DIE=1
AUTOHEADER="${REALPKGNAME}"
# automake and aclocal version numbers must be kept in sync
real_package_name "automake" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 13 || DIE=1
AUTOMAKE=$REALPKGNAME
real_package_name "aclocal" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 13 || DIE=1
ACLOCAL=$REALPKGNAME
real_package_name "libtoolize" "ftp://ftp.gnu.org/pub/gnu/libtool/" 2 2 ||
real_package_name "glibtoolize" "ftp://ftp.gnu.org/pub/gnu/libtool/" 2 2 "" "0" || DIE=1
LIBTOOLIZE=$REALPKGNAME
real_package_name "python3" "https://www.python.org/" 3 6 || DIE=1
if [ "$FC_USE_NLS" = "yes" ]; then
DIE2=0
version_check 1 "xgettext" "xgettext" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 16 || DIE2=1
version_check 1 "msgfmt" "msgfmt" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 16 || DIE2=1
if [ "$DIE2" -eq 1 ]; then
echo
echo "You may want to use --disable-nls to disable NLS."
echo "This will also remove the dependency for xgettext and msgfmt."
DIE=1
fi
fi
if [ "$DIE" -eq 1 ]; then
exit 1
fi
echo "+ running $ACLOCAL ..."
$ACLOCAL -I m4 -I dependencies/m4 $ACLOCAL_FLAGS || {
echo
echo "$ACLOCAL failed - check that all needed development files are present on system"
exit 1
}
echo "+ running $AUTOHEADER ... "
$AUTOHEADER || {
echo
echo "$AUTOHEADER failed"
exit 1
}
echo "+ running $LIBTOOLIZE ... "
$LIBTOOLIZE -f -c || {
echo
echo "$LIBTOOLIZE failed"
exit 1
}
echo "+ running $ACLOCAL for libtool installed files..."
$ACLOCAL -I m4 -I dependencies/m4 $ACLOCAL_FLAGS || {
echo
echo "$ACLOCAL failed on libtool files run"
exit 1
}
echo "+ running ${AUTOCONF} ... "
"${AUTOCONF}" || {
echo
echo "${AUTOCONF} failed"
exit 1
}
echo "+ running $AUTOMAKE ... "
$AUTOMAKE -a -c || {
echo
echo "$AUTOMAKE failed"
exit 1
}
# Chdir back to the builddir before the configure step.
cd "$BUILDDIR"
# now remove the cache, because it can be considered dangerous in this case
echo "+ removing config.cache ... "
rm -f config.cache
# exit if we did --no-configure-run
if [ "$FC_RUN_CONFIGURE" = "no" ]; then
echo
echo "Now type 'configure' to configure $package."
exit 0
fi
echo "+ running configure ... "
echo
if [ -z "$FC_NEWARGLINE" ]; then
echo "I am going to run $SRCDIR/configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
else
echo "using: $FC_NEWARGLINE"
fi
echo
"$SRCDIR/configure" $FC_NEWARGLINE || {
echo
echo "configure failed"
exit 1
}
# Abort if we did --help
if [ "$FC_HELP" = "yes" ]; then
exit 1
fi
echo
echo "Now type 'make' to compile $package."
exit 0