autogen.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #!/bin/sh
  2. ### autogen.sh - tool to help build Emacs from a repository checkout
  3. ## Copyright (C) 2011-2015 Free Software Foundation, Inc.
  4. ## Author: Glenn Morris <rgm@gnu.org>
  5. ## Maintainer: emacs-devel@gnu.org
  6. ## This file is part of GNU Emacs.
  7. ## GNU Emacs is free software: you can redistribute it and/or modify
  8. ## it under the terms of the GNU General Public License as published by
  9. ## the Free Software Foundation, either version 3 of the License, or
  10. ## (at your option) any later version.
  11. ## GNU Emacs is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ### Commentary:
  18. ## The Emacs repository does not include the configure script (and
  19. ## associated helpers). The first time you fetch Emacs from the repo,
  20. ## run this script to generate the necessary files.
  21. ## For more details, see the file INSTALL.REPO.
  22. ### Code:
  23. ## Tools we need:
  24. ## Note that we respect the values of AUTOCONF etc, like autoreconf does.
  25. progs="autoconf automake"
  26. ## Minimum versions we need:
  27. autoconf_min=`sed -n 's/^ *AC_PREREQ(\([0-9\.]*\)).*/\1/p' configure.ac`
  28. ## This will need improving if more options are ever added to the
  29. ## AM_INIT_AUTOMAKE call.
  30. automake_min=`sed -n 's/^ *AM_INIT_AUTOMAKE(\([0-9\.]*\)).*/\1/p' configure.ac`
  31. ## $1 = program, eg "autoconf".
  32. ## Echo the version string, eg "2.59".
  33. ## FIXME does not handle things like "1.4a", but AFAIK those are
  34. ## all old versions, so it is OK to fail there.
  35. ## Also note that we do not handle micro versions.
  36. get_version ()
  37. {
  38. ## Remove eg "./autogen.sh: line 50: autoconf: command not found".
  39. $1 --version 2>&1 | sed -e '/not found/d' -e 's/.* //' -n -e '1 s/\([0-9][0-9\.]*\).*/\1/p'
  40. }
  41. ## $1 = version string, eg "2.59"
  42. ## Echo the major version, eg "2".
  43. major_version ()
  44. {
  45. echo $1 | sed -e 's/\([0-9][0-9]*\)\..*/\1/'
  46. }
  47. ## $1 = version string, eg "2.59"
  48. ## Echo the minor version, eg "59".
  49. minor_version ()
  50. {
  51. echo $1 | sed -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/'
  52. }
  53. ## $1 = program
  54. ## $2 = minimum version.
  55. ## Return 0 if program is present with version >= minimum version.
  56. ## Return 1 if program is missing.
  57. ## Return 2 if program is present but too old.
  58. ## Return 3 for unexpected error (eg failed to parse version).
  59. check_version ()
  60. {
  61. ## Respect eg $AUTOMAKE if it is set, like autoreconf does.
  62. uprog=`echo $1 | sed -e 's/-/_/g' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
  63. eval uprog=\$${uprog}
  64. [ x"$uprog" = x ] && uprog=$1
  65. have_version=`get_version $uprog`
  66. [ x"$have_version" = x ] && return 1
  67. have_maj=`major_version $have_version`
  68. need_maj=`major_version $2`
  69. [ x"$have_maj" != x ] && [ x"$need_maj" != x ] || return 3
  70. [ $have_maj -gt $need_maj ] && return 0
  71. [ $have_maj -lt $need_maj ] && return 2
  72. have_min=`minor_version $have_version`
  73. need_min=`minor_version $2`
  74. [ x"$have_min" != x ] && [ x"$need_min" != x ] || return 3
  75. [ $have_min -ge $need_min ] && return 0
  76. return 2
  77. }
  78. cat <<EOF
  79. Checking whether you have the necessary tools...
  80. (Read INSTALL.REPO for more details on building Emacs)
  81. EOF
  82. missing=
  83. for prog in $progs; do
  84. sprog=`echo "$prog" | sed 's/-/_/g'`
  85. eval min=\$${sprog}_min
  86. echo "Checking for $prog (need at least version $min)..."
  87. check_version $prog $min
  88. retval=$?
  89. case $retval in
  90. 0) stat="ok" ;;
  91. 1) stat="missing" ;;
  92. 2) stat="too old" ;;
  93. *) stat="unable to check" ;;
  94. esac
  95. echo $stat
  96. if [ $retval -ne 0 ]; then
  97. missing="$missing $prog"
  98. eval ${sprog}_why=\""$stat"\"
  99. fi
  100. done
  101. if [ x"$missing" != x ]; then
  102. cat <<EOF
  103. Building Emacs from the repository requires the following specialized programs:
  104. EOF
  105. for prog in $progs; do
  106. sprog=`echo "$prog" | sed 's/-/_/g'`
  107. eval min=\$${sprog}_min
  108. echo "$prog (minimum version $min)"
  109. done
  110. cat <<EOF
  111. Your system seems to be missing the following tool(s):
  112. EOF
  113. for prog in $missing; do
  114. sprog=`echo "$prog" | sed 's/-/_/g'`
  115. eval why=\$${sprog}_why
  116. echo "$prog ($why)"
  117. done
  118. cat <<EOF
  119. If you think you have the required tools, please add them to your PATH
  120. and re-run this script.
  121. Otherwise, please try installing them.
  122. On systems using rpm and yum, try: "yum install PACKAGE"
  123. On systems using dpkg and apt, try: "apt-get install PACKAGE"
  124. Then re-run this script.
  125. If you do not have permission to do this, or if the version provided
  126. by your system is too old, it is normally straightforward to build
  127. these packages from source. You can find the sources at:
  128. ftp://ftp.gnu.org/gnu/PACKAGE/
  129. Download the package (make sure you get at least the minimum version
  130. listed above), extract it using tar, then run configure, make,
  131. make install. Add the installation directory to your PATH and re-run
  132. this script.
  133. If you know that the required versions are in your PATH, but this
  134. script has made an error, then you can simply run
  135. autoreconf -fi -I m4
  136. instead of this script.
  137. Please report any problems with this script to bug-gnu-emacs@gnu.org .
  138. EOF
  139. exit 1
  140. fi
  141. echo 'Your system has the required tools.'
  142. echo "Running 'autoreconf -fi -I m4' ..."
  143. ## Let autoreconf figure out what, if anything, needs doing.
  144. ## Use autoreconf's -f option in case autoreconf itself has changed.
  145. autoreconf -fi -I m4 || exit $?
  146. ## Create a timestamp, so that './autogen.sh; make' doesn't
  147. ## cause 'make' to needlessly run 'autoheader'.
  148. echo timestamp > src/stamp-h.in || exit
  149. ## Configure Git, if using Git.
  150. if test -d .git && (git status -s) >/dev/null 2>&1; then
  151. # Configure 'git diff' hunk header format.
  152. git config 'diff.elisp.xfuncname' \
  153. '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)' || exit
  154. git config 'diff.texinfo.xfuncname' \
  155. '^@node[[:space:]]+([^,[:space:]][^,]+)' || exit
  156. # Install Git hooks.
  157. tailored_hooks=
  158. sample_hooks=
  159. for hook in commit-msg pre-commit; do
  160. cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
  161. tailored_hooks="$tailored_hooks $hook"
  162. done
  163. for hook in applypatch-msg pre-applypatch; do
  164. test ! -r .git/hooks/$hook.sample ||
  165. cmp .git/hooks/$hook.sample .git/hooks/$hook >/dev/null 2>&1 ||
  166. sample_hooks="$sample_hooks $hook"
  167. done
  168. if test -n "$tailored_hooks$sample_hooks"; then
  169. echo "Installing git hooks..."
  170. case `cp --help 2>/dev/null` in
  171. *--backup*--verbose*)
  172. cp_options='--backup=numbered --verbose';;
  173. *)
  174. cp_options='-f';;
  175. esac
  176. if test -n "$tailored_hooks"; then
  177. for hook in $tailored_hooks; do
  178. cp $cp_options build-aux/git-hooks/$hook .git/hooks || exit
  179. chmod a-w .git/hooks/$hook || exit
  180. done
  181. fi
  182. if test -n "$sample_hooks"; then
  183. for hook in $sample_hooks; do
  184. cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
  185. chmod a-w .git/hooks/$hook || exit
  186. done
  187. fi
  188. fi
  189. fi
  190. echo "You can now run './configure'."
  191. exit 0
  192. ### autogen.sh ends here