Simplify by avoiding confusing use of strncpy etc.
[emacs.git] / autogen.sh
blob0c92047e469821dd5394d032db471da95664e695
1 #!/bin/sh
2 ### autogen.sh - tool to help build Emacs from a bzr checkout
4 ## Copyright (C) 2011-2012 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
8 ## This file is part of GNU Emacs.
10 ## GNU Emacs is free software: you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation, either version 3 of the License, or
13 ## (at your option) any later version.
15 ## GNU Emacs is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ### Commentary:
25 ## The Emacs bzr repository does not include the configure script
26 ## (and associated helpers). The first time you fetch Emacs from bzr,
27 ## run this script to generate the necessary files.
28 ## For more details, see the file INSTALL.BZR.
30 ### Code:
32 ## Tools we need:
33 ## Note that we respect the values of AUTOCONF etc, like autoreconf does.
34 progs="autoconf automake"
36 ## Minimum versions we need:
37 autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
39 ## FIXME how to determine this from the sources?
40 automake_min=1.11
43 ## $1 = program, eg "autoconf".
44 ## Echo the version string, eg "2.59".
45 ## FIXME does not handle things like "1.4a", but AFAIK those are
46 ## all old versions, so it is OK to fail there.
47 ## Also note that we do not handle micro versions.
48 get_version ()
50 ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
51 $1 --version 2>&1 | sed -e '/not found/d' -n -e '1 s/.* \([1-9][0-9\.]*\).*/\1/p'
54 ## $1 = version string, eg "2.59"
55 ## Echo the major version, eg "2".
56 major_version ()
58 echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
61 ## $1 = version string, eg "2.59"
62 ## Echo the minor version, eg "59".
63 minor_version ()
65 echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
68 ## $1 = program
69 ## $2 = minimum version.
70 ## Return 0 if program is present with version >= minimum version.
71 ## Return 1 if program is missing.
72 ## Return 2 if program is present but too old.
73 ## Return 3 for unexpected error (eg failed to parse version).
74 check_version ()
76 ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
77 uprog=`echo $1 | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
79 eval uprog=\$${uprog}
81 [ x"$uprog" = x ] && uprog=$1
83 have_version=`get_version $uprog`
85 [ x"$have_version" = x ] && return 1
87 have_maj=`major_version $have_version`
88 need_maj=`major_version $2`
90 [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
92 [ $have_maj -gt $need_maj ] && return 0
93 [ $have_maj -lt $need_maj ] && return 2
95 have_min=`minor_version $have_version`
96 need_min=`minor_version $2`
98 [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
100 [ $have_min -ge $need_min ] && return 0
101 return 2
105 cat <<EOF
106 Checking whether you have the necessary tools...
107 (Read INSTALL.BZR for more details on building Emacs)
111 missing=
113 for prog in $progs; do
115 eval min=\$${prog}_min
117 echo "Checking for $prog (need at least version $min)..."
119 check_version $prog $min
121 retval=$?
123 case $retval in
124 0) stat="ok" ;;
125 1) stat="missing" ;;
126 2) stat="too old" ;;
127 *) stat="unable to check" ;;
128 esac
130 echo $stat
132 if [ $retval -ne 0 ]; then
133 missing="$missing $prog"
134 eval ${prog}_why=\""$stat"\"
137 done
140 if [ x"$missing" != x ]; then
142 cat <<EOF
144 Building Emacs from Bzr requires the following specialized programs:
147 for prog in $progs; do
148 eval min=\$${prog}_min
150 echo "$prog (minimum version $min)"
151 done
154 cat <<EOF
156 Your system seems to be missing the following tool(s):
159 for prog in $missing; do
160 eval why=\$${prog}_why
162 echo "$prog ($why)"
163 done
165 cat <<EOF
167 If you think you have the required tools, please add them to your PATH
168 and re-run this script.
170 Otherwise, please try installing them.
171 On systems using rpm and yum, try: "yum install PACKAGE"
172 On systems using dpkg and apt, try: "apt-get install PACKAGE"
173 Then re-run this script.
175 If you do not have permission to do this, or if the version provided
176 by your system is too old, it is normally straightforward to build
177 these packages from source. You can find the sources at:
179 ftp://ftp.gnu.org/gnu/PACKAGE/
181 Download the package (make sure you get at least the minimum version
182 listed above), extract it using tar, then run configure, make,
183 make install. Add the installation directory to your PATH and re-run
184 this script.
186 If you know that the required versions are in your PATH, but this
187 script has made an error, then you can simply run
189 autoreconf -i -I m4
191 instead of this script.
193 If all else fails, you can try using the pre-built versions of the
194 generated files by doing:
196 ./autogen/copy_autogen
198 This is not recommended - see the comments in \`copy_autogen'.
200 Please report any problems with this script to bug-gnu-emacs@gnu.org .
203 exit 1
206 echo "Your system has the required tools, running autoreconf..."
209 ## Let autoreconf figure out what, if anything, needs doing.
210 autoreconf -i -I m4 || exit $?
212 echo "You can now run \`./configure'."
214 exit 0
216 ### autogen.sh ends here