autogen.sh 5.4 KB

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