Updated hexemplio grid
[freeciv.git] / autogen.sh
blob0dd43f1d7e8e4c9ffa36297fef22374945836e60
1 #!/bin/sh
2 # Run this to generate all the initial makefiles, etc.
4 DIE=0
5 package=freeciv
6 srcfile=common/game.c
8 SRCDIR=`dirname "$0"`
9 BUILDDIR=`pwd`
11 # Uncomment the line below to debug this file
12 #DEBUG=defined
14 FC_USE_NLS=yes
15 FC_HELP=no
16 FC_RUN_CONFIGURE=yes
18 # Leave out NLS checks
19 for NAME in $@ ; do
20 if [ "x$NAME" = "x--help" ]; then
21 FC_HELP=yes
23 if [ "x$NAME" = "x--disable-nls" ]; then
24 echo "! nls checks disabled"
25 FC_USE_NLS=no
27 if [ "x$NAME" = "x--no-configure-run" ]; then
28 FC_RUN_CONFIGURE=no
30 FC_NEWARGLINE="$FC_NEWARGLINE $NAME"
31 done
33 debug ()
34 # print out a debug message if DEBUG is a defined variable
36 if [ ! -z "$DEBUG" ]; then
37 echo "DEBUG: $1"
41 real_package_name ()
42 # solve a real name of suitable package
43 # first argument : package name (executable)
44 # second argument : source download url
45 # rest of arguments : major, minor, micro version
47 RPACKAGE=$1
48 RURL=$2
49 RMAJOR=$3
50 RMINOR=$4
51 RMICRO=$5
53 new_pkg=$RPACKAGE
55 # check if given package is suitable
56 if version_check 2 $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO; then
57 version_check 1 $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
58 else
59 # given package was too old or not available
60 # search for the newest one
61 if version_search $RPACKAGE; then
62 if version_check 2 $RPACKAGE $new_pkg $RURL $RMAJOR $RMINOR $RMICRO; then
63 # suitable package found
64 version_check 1 $RPACKAGE $new_pkg $RURL $RMAJOR $RMINOR $RMICRO
65 else
66 # the newest package is not new enough or it is broken
67 version_check 1 $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
68 return 1
70 else
71 # no version of given package with version information
72 # in its name available
73 version_check 1 $RPACKAGE $RPACKAGE $RURL $RMAJOR $RMINOR $RMICRO
74 return 1
78 REALPKGNAME=$new_pkg
81 version_search ()
82 # search the newest version of a package
83 # first argument : package name (executable)
85 SPACKAGE=$1
86 STOREDIFS=$IFS
87 IFS=":"
88 set -- $PATH
89 IFS=$STOREDIFS
91 s_pkg_major=0
92 s_pkg_minor=0
93 new_pkg=
95 for SEARCHDIR ; do
96 for MATCHSTUFF in `ls "$SEARCHDIR/$SPACKAGE-"* 2> /dev/null` ; do
97 for FOUNDPKG in $MATCHSTUFF; do
98 # parse version information from name
99 new_s_pkg_major=`echo $FOUNDPKG | cut -s -d- -f2 | cut -s -d. -f1`
100 new_s_pkg_minor=`echo $FOUNDPKG | cut -s -d- -f2 | cut -s -d. -f2`
102 CORRECT=
103 # check if version numbers are integers
104 [ ! "x$new_s_pkg_major" = "x" ] && \
105 [ "x`echo $new_s_pkg_major | sed s/[0-9]*//g`" = "x" ] && \
106 [ ! "x$new_s_pkg_minor" = "x" ] && \
107 [ "x`echo $new_s_pkg_minor | sed s/[0-9]*//g`" = "x" ] && \
108 CORRECT=1
110 if [ ! -z $CORRECT ]; then
111 if [ "$new_s_pkg_major" -gt "$s_pkg_major" ]; then
112 s_pkg_major=$new_s_pkg_major
113 s_pkg_minor=$new_s_pkg_minor
114 new_pkg="$FOUNDPKG"
115 elif [ "$new_s_pkg_major" -eq "$s_pkg_major" ]; then
116 if [ "$new_s_pkg_minor" -gt "$s_pkg_minor" ]; then
117 s_pkg_major=$new_s_pkg_major
118 s_pkg_minor=$new_s_pkg_minor
119 new_pkg="$FOUNDPKG"
123 done
124 done
125 done
127 if [ -z "$new_pkg" ]; then
128 return 1
129 else
130 return 0
134 version_check ()
135 # check the version of a package
136 # first argument : silent ('2'), complain ('1') or not ('0')
137 # second argument : package name
138 # third argument : package name (executable)
139 # fourth argument : source download url
140 # rest of arguments : major, minor, micro version
142 COMPLAIN=$1
143 PACKAGEMSG=$2
144 PACKAGE=$3
145 URL=$4
146 MAJOR=$5
147 MINOR=$6
148 MICRO=$7
150 WRONG=
152 debug "major $MAJOR minor $MINOR micro $MICRO"
153 VERSION=$MAJOR
154 if [ ! -z "$MINOR" ]; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
155 if [ ! -z "$MICRO" ]; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
157 debug "version $VERSION"
158 if [ "x$VERSION" != "x" ] ; then
159 if [ "$COMPLAIN" -ne "2" ]; then
160 echo "+ checking for $PACKAGEMSG >= $VERSION ... " | tr -d '\n'
162 else
163 MAJOR=0
164 if [ "$COMPLAIN" -ne "2" ]; then
165 echo "+ checking for $PACKAGEMSG ... " | tr -d '\n'
169 ($PACKAGE --version) < /dev/null > /dev/null 2>&1 ||
171 if [ "$COMPLAIN" -ne "2" ]; then
172 echo
173 echo "You must have $PACKAGEMSG installed to compile $package."
174 echo "Download the appropriate package for your distribution,"
175 echo "or get the source tarball at $URL"
177 return 1
180 # The following line is carefully crafted sed magic
181 pkg_version=`$PACKAGE --version 2>&1|grep -a -v " line " |head -n 1|sed 's/([^)]*)//g;s/^[a-zA-Z\.\ \-]*//;s/ .*$//'`
182 debug "pkg_version $pkg_version"
183 pkg_major=`echo $pkg_version | cut -d. -f1`
184 pkg_minor=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f2`
185 pkg_micro=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f3`
186 [ -z "$pkg_major" ] && pkg_major=0
187 [ -z "$pkg_minor" ] && pkg_minor=0
188 [ -z "$pkg_micro" ] && pkg_micro=0
190 debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
192 # Start checking the version
193 if [ "$pkg_major" -lt "$MAJOR" ]; then
194 WRONG=1
195 elif [ "$pkg_major" -eq "$MAJOR" ]; then
196 if [ "$pkg_minor" -lt "$MINOR" ]; then
197 WRONG=1
198 elif [ "$pkg_minor" -eq "$MINOR" -a "$pkg_micro" -lt "$MICRO" ]; then
199 WRONG=1
203 if [ ! -z "$WRONG" ]; then
204 if [ "$COMPLAIN" -ne "2" ]; then
205 echo "found $pkg_version, not ok !"
207 if [ "$COMPLAIN" -eq "1" ]; then
208 echo
209 echo "You must have $PACKAGEMSG $VERSION or greater to compile $package."
210 echo "Get the latest version from <$URL>."
211 echo
213 return 1
214 else
215 if [ "$COMPLAIN" -ne "2" ]; then
216 echo "found $pkg_version, ok."
221 # Chdir to the srcdir, then run auto* tools.
222 cd "$SRCDIR"
224 [ -f $srcfile ] || {
225 echo "Are you sure \"$SRCDIR\" is a valid source directory?"
226 exit 1
229 # Check against acinclude.m4, which earlier versions used to generate.
230 [ -f acinclude.m4 ] && {
231 echo "There is file acinclude.m4 in source directory."
232 echo "It's probably left from earlier Freeciv build, and can cause"
233 echo "unexpected results. Please remove it."
234 exit 1
237 # autoconf and autoheader version numbers must be kept in sync
238 real_package_name "autoconf" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 61 || DIE=1
239 AUTOCONF=$REALPKGNAME
240 real_package_name "autoheader" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 61 || DIE=1
241 AUTOHEADER=$REALPKGNAME
243 # automake and aclocal version numbers must be kept in sync
244 real_package_name "automake" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 10 || DIE=1
245 AUTOMAKE=$REALPKGNAME
246 real_package_name "aclocal" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 10 || DIE=1
247 ACLOCAL=$REALPKGNAME
248 real_package_name "libtoolize" "ftp://ftp.gnu.org/pub/gnu/libtool/" 1 5 2 || DIE=1
249 LIBTOOLIZE=$REALPKGNAME
250 real_package_name "python" "https://www.python.org/" || DIE=1
252 if [ "$FC_USE_NLS" = "yes" ]; then
253 DIE2=0
254 version_check 1 "xgettext" "xgettext" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 14 || DIE2=1
255 version_check 1 "msgfmt" "msgfmt" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 14 || DIE2=1
256 if [ "$DIE2" -eq 1 ]; then
257 echo
258 echo "You may want to use --disable-nls to disable NLS."
259 echo "This will also remove the dependency for xgettext and msgfmt."
260 DIE=1
264 if [ "$DIE" -eq 1 ]; then
265 exit 1
268 echo "+ running $ACLOCAL ..."
269 $ACLOCAL -I m4 -I dependencies/m4 $ACLOCAL_FLAGS || {
270 echo
271 echo "$ACLOCAL failed - check that all needed development files are present on system"
272 exit 1
275 echo "+ running $AUTOHEADER ... "
276 $AUTOHEADER || {
277 echo
278 echo "$AUTOHEADER failed"
279 exit 1
281 echo "+ running $LIBTOOLIZE ... "
282 $LIBTOOLIZE -f -c || {
283 echo
284 echo "$LIBTOOLIZE failed"
285 exit 1
287 echo "+ running $ACLOCAL for libtool installed files..."
288 $ACLOCAL -I m4 -I dependencies/m4 $ACLOCAL_FLAGS || {
289 echo
290 echo "$ACLOCAL failed on libtool files run"
291 exit 1
293 echo "+ running $AUTOCONF ... "
294 $AUTOCONF || {
295 echo
296 echo "$AUTOCONF failed"
297 exit 1
299 echo "+ running $AUTOMAKE ... "
300 $AUTOMAKE -a -c || {
301 echo
302 echo "$AUTOMAKE failed"
303 exit 1
306 # Chdir back to the builddir before the configure step.
307 cd "$BUILDDIR"
309 # now remove the cache, because it can be considered dangerous in this case
310 echo "+ removing config.cache ... "
311 rm -f config.cache
313 # exit if we did --no-configure-run
314 if [ "$FC_RUN_CONFIGURE" = "no" ]; then
315 echo
316 echo "Now type 'configure' to configure $package."
317 exit 0
320 echo "+ running configure ... "
321 echo
322 if [ -z "$FC_NEWARGLINE" ]; then
323 echo "I am going to run ./configure with no arguments - if you wish "
324 echo "to pass any to it, please specify them on the $0 command line."
325 else
326 echo "using: $FC_NEWARGLINE"
328 echo
330 "$SRCDIR/configure" $FC_NEWARGLINE || {
331 echo
332 echo "configure failed"
333 exit 1
336 # abort if we did --help
337 if [ "$FC_HELP" = "yes" ]; then
338 exit 1
341 echo
342 echo "Now type 'make' to compile $package."
344 exit 0