Experimental maglevs: note that Big Land units can't use them, and that
[freeciv.git] / autogen.sh
blob79fd4b010a87b1cc3ca83480cca8df4b0753fd40
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 [ "$COMPLAIN" -ne "2" ]; then
159 echo "+ checking for $PACKAGEMSG >= $VERSION ... " | tr -d '\n'
162 ($PACKAGE --version) < /dev/null > /dev/null 2>&1 ||
164 if [ "$COMPLAIN" -ne "2" ]; then
165 echo
166 echo "You must have $PACKAGEMSG installed to compile $package."
167 echo "Download the appropriate package for your distribution,"
168 echo "or get the source tarball at $URL"
170 return 1
173 # the following line is carefully crafted sed magic
174 pkg_version=`$PACKAGE --version|head -n 1|sed 's/([^)]*)//g;s/^[a-zA-Z\.\ \-]*//;s/ .*$//'`
175 debug "pkg_version $pkg_version"
176 pkg_major=`echo $pkg_version | cut -d. -f1`
177 pkg_minor=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f2`
178 pkg_micro=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f3`
179 [ -z "$pkg_minor" ] && pkg_minor=0
180 [ -z "$pkg_micro" ] && pkg_micro=0
182 debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
184 #start checking the version
185 if [ "$pkg_major" -lt "$MAJOR" ]; then
186 WRONG=1
187 elif [ "$pkg_major" -eq "$MAJOR" ]; then
188 if [ "$pkg_minor" -lt "$MINOR" ]; then
189 WRONG=1
190 elif [ "$pkg_minor" -eq "$MINOR" -a "$pkg_micro" -lt "$MICRO" ]; then
191 WRONG=1
195 if [ ! -z "$WRONG" ]; then
196 if [ "$COMPLAIN" -ne "2" ]; then
197 echo "found $pkg_version, not ok !"
199 if [ "$COMPLAIN" -eq "1" ]; then
200 echo
201 echo "You must have $PACKAGEMSG $VERSION or greater to compile $package."
202 echo "Get the latest version from <$URL>."
203 echo
205 return 1
206 else
207 if [ "$COMPLAIN" -ne "2" ]; then
208 echo "found $pkg_version, ok."
213 # Chdir to the srcdir, then run auto* tools.
214 cd "$SRCDIR"
216 [ -f $srcfile ] || {
217 echo "Are you sure \"$SRCDIR\" is a valid source directory?"
218 exit 1
221 # Check against acinclude.m4, which earlier versions used to generate.
222 [ -f acinclude.m4 ] && {
223 echo "There is file acinclude.m4 in source directory."
224 echo "It's probably left from earlier Freeciv build, and can cause"
225 echo "unexpected results. Please remove it."
226 exit 1
229 # autoconf and autoheader version numbers must be kept in sync
230 real_package_name "autoconf" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 61 || DIE=1
231 AUTOCONF=$REALPKGNAME
232 real_package_name "autoheader" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 61 || DIE=1
233 AUTOHEADER=$REALPKGNAME
235 # automake and aclocal version numbers must be kept in sync
236 real_package_name "automake" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 9 || DIE=1
237 AUTOMAKE=$REALPKGNAME
238 real_package_name "aclocal" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 9 || DIE=1
239 ACLOCAL=$REALPKGNAME
240 real_package_name "libtoolize" "ftp://ftp.gnu.org/pub/gnu/libtool/" 1 4 3 || DIE=1
241 LIBTOOLIZE=$REALPKGNAME
243 if [ "$FC_USE_NLS" = "yes" ]; then
244 DIE2=0
245 version_check 1 "xgettext" "xgettext" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 10 36 || DIE2=1
246 version_check 1 "msgfmt" "msgfmt" "ftp://ftp.gnu.org/pub/gnu/gettext/" 0 10 36 || DIE2=1
247 if [ "$DIE2" -eq 1 ]; then
248 echo
249 echo "You may want to use --disable-nls to disable NLS."
250 echo "This will also remove the dependency for xgettext and msgfmt."
251 DIE=1
255 if [ "$DIE" -eq 1 ]; then
256 exit 1
259 echo "+ running $ACLOCAL ..."
260 $ACLOCAL -I m4 -I dependencies/m4 $ACLOCAL_FLAGS || {
261 echo
262 echo "$ACLOCAL failed - check that all needed development files are present on system"
263 exit 1
266 echo "+ running $AUTOHEADER ... "
267 $AUTOHEADER || {
268 echo
269 echo "$AUTOHEADER failed"
270 exit 1
272 echo "+ running $LIBTOOLIZE ... "
273 $LIBTOOLIZE -f || {
274 echo
275 echo "$LIBTOOLIZE failed"
276 exit 1
278 echo "+ running $AUTOCONF ... "
279 $AUTOCONF || {
280 echo
281 echo "$AUTOCONF failed"
282 exit 1
284 echo "+ running $AUTOMAKE ... "
285 $AUTOMAKE -a -c || {
286 echo
287 echo "$AUTOMAKE failed"
288 exit 1
291 # Chdir back to the builddir before the configure step.
292 cd "$BUILDDIR"
294 # now remove the cache, because it can be considered dangerous in this case
295 echo "+ removing config.cache ... "
296 rm -f config.cache
298 # exit if we did --no-configure-run
299 if [ "$FC_RUN_CONFIGURE" = "no" ]; then
300 echo
301 echo "Now type 'configure' to configure $package."
302 exit 0
305 echo "+ running configure ... "
306 echo
307 if [ -z "$FC_NEWARGLINE" ]; then
308 echo "I am going to run ./configure with no arguments - if you wish "
309 echo "to pass any to it, please specify them on the $0 command line."
310 else
311 echo "using: $FC_NEWARGLINE"
313 echo
315 "$SRCDIR/configure" $FC_NEWARGLINE || {
316 echo
317 echo "configure failed"
318 exit 1
321 # abort if we did --help
322 if [ "$FC_HELP" = "yes" ]; then
323 exit 1
326 echo
327 echo "Now type 'make' to compile $package."
329 exit 0