autogen.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #!/bin/sh
  2. ### autogen.sh - tool to help build Emacs from a repository checkout
  3. ## Copyright (C) 2011-2016 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. do_autoconf=false
  79. test $# -eq 0 && do_autoconf=true
  80. do_git=false
  81. for arg; do
  82. case $arg in
  83. --help)
  84. exec echo "$0: usage: $0 [all|autoconf|git]";;
  85. all)
  86. do_autoconf=true
  87. test -e .git && do_git=true;;
  88. autoconf)
  89. do_autoconf=true;;
  90. git)
  91. do_git=true;;
  92. *)
  93. echo >&2 "$0: $arg: unknown argument"; exit 1;;
  94. esac
  95. done
  96. # Generate Autoconf and Automake related files, if requested.
  97. if $do_autoconf; then
  98. echo 'Checking whether you have the necessary tools...
  99. (Read INSTALL.REPO for more details on building Emacs)'
  100. missing=
  101. for prog in $progs; do
  102. sprog=`echo "$prog" | sed 's/-/_/g'`
  103. eval min=\$${sprog}_min
  104. echo "Checking for $prog (need at least version $min)..."
  105. check_version $prog $min
  106. retval=$?
  107. case $retval in
  108. 0) stat="ok" ;;
  109. 1) stat="missing" ;;
  110. 2) stat="too old" ;;
  111. *) stat="unable to check" ;;
  112. esac
  113. echo $stat
  114. if [ $retval -ne 0 ]; then
  115. missing="$missing $prog"
  116. eval ${sprog}_why=\""$stat"\"
  117. fi
  118. done
  119. if [ x"$missing" != x ]; then
  120. echo '
  121. Building Emacs from the repository requires the following specialized programs:'
  122. for prog in $progs; do
  123. sprog=`echo "$prog" | sed 's/-/_/g'`
  124. eval min=\$${sprog}_min
  125. echo "$prog (minimum version $min)"
  126. done
  127. echo '
  128. Your system seems to be missing the following tool(s):'
  129. for prog in $missing; do
  130. sprog=`echo "$prog" | sed 's/-/_/g'`
  131. eval why=\$${sprog}_why
  132. echo "$prog ($why)"
  133. done
  134. echo '
  135. If you think you have the required tools, please add them to your PATH
  136. and re-run this script.
  137. Otherwise, please try installing them.
  138. On systems using rpm and yum, try: "yum install PACKAGE"
  139. On systems using dpkg and apt, try: "apt-get install PACKAGE"
  140. Then re-run this script.
  141. If you do not have permission to do this, or if the version provided
  142. by your system is too old, it is normally straightforward to build
  143. these packages from source. You can find the sources at:
  144. ftp://ftp.gnu.org/gnu/PACKAGE/
  145. Download the package (make sure you get at least the minimum version
  146. listed above), extract it using tar, then run configure, make,
  147. make install. Add the installation directory to your PATH and re-run
  148. this script.
  149. If you know that the required versions are in your PATH, but this
  150. script has made an error, then you can simply run
  151. autoreconf -fi -I m4
  152. instead of this script.
  153. Please report any problems with this script to bug-gnu-emacs@gnu.org .'
  154. exit 1
  155. fi
  156. echo 'Your system has the required tools.'
  157. echo "Running 'autoreconf -fi -I m4' ..."
  158. ## Let autoreconf figure out what, if anything, needs doing.
  159. ## Use autoreconf's -f option in case autoreconf itself has changed.
  160. autoreconf -fi -I m4 || exit $?
  161. ## Create a timestamp, so that './autogen.sh; make' doesn't
  162. ## cause 'make' to needlessly run 'autoheader'.
  163. echo timestamp > src/stamp-h.in || exit
  164. fi
  165. # True if the Git setup was OK before autogen.sh was run.
  166. git_was_ok=true
  167. if $do_git; then
  168. case `cp --help 2>/dev/null` in
  169. *--backup*--verbose*)
  170. cp_options='--backup=numbered --verbose';;
  171. *)
  172. cp_options='-f';;
  173. esac
  174. fi
  175. # Like 'git config NAME VALUE' but verbose on change and exiting on failure.
  176. # Also, do not configure unless requested.
  177. git_config ()
  178. {
  179. name=$1
  180. value=$2
  181. ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
  182. if $do_git; then
  183. if $git_was_ok; then
  184. echo 'Configuring local git repository...'
  185. case $cp_options in
  186. --backup=*)
  187. config=$git_common_dir/config
  188. cp $cp_options --force -- "$config" "$config" || exit;;
  189. esac
  190. fi
  191. echo "git config $name '$value'"
  192. git config "$name" "$value" || exit
  193. fi
  194. git_was_ok=false
  195. }
  196. }
  197. ## Configure Git, if requested.
  198. # Get location of Git's common configuration directory. For older Git
  199. # versions this is just '.git'. Newer Git versions support worktrees.
  200. { test -e .git &&
  201. git_common_dir=`git rev-parse --no-flags --git-common-dir 2>/dev/null` &&
  202. test -n "$git_common_dir"
  203. } || git_common_dir=.git
  204. hooks=$git_common_dir/hooks
  205. # Check hashes when transferring objects among repositories.
  206. git_config transfer.fsckObjects true
  207. # Configure 'git diff' hunk header format.
  208. git_config diff.elisp.xfuncname \
  209. '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
  210. git_config 'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
  211. git_config 'diff.make.xfuncname' \
  212. '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
  213. git_config 'diff.shell.xfuncname' \
  214. '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
  215. git_config diff.texinfo.xfuncname \
  216. '^@node[[:space:]]+([^,[:space:]][^,]+)'
  217. # Install Git hooks.
  218. tailored_hooks=
  219. sample_hooks=
  220. for hook in commit-msg pre-commit; do
  221. cmp -- build-aux/git-hooks/$hook "$hooks/$hook" >/dev/null 2>&1 ||
  222. tailored_hooks="$tailored_hooks $hook"
  223. done
  224. for hook in applypatch-msg pre-applypatch; do
  225. cmp -- "$hooks/$hook.sample" "$hooks/$hook" >/dev/null 2>&1 ||
  226. sample_hooks="$sample_hooks $hook"
  227. done
  228. if test -n "$tailored_hooks$sample_hooks"; then
  229. if $do_git; then
  230. echo "Installing git hooks..."
  231. if test -n "$tailored_hooks"; then
  232. for hook in $tailored_hooks; do
  233. dst=$hooks/$hook
  234. cp $cp_options -- build-aux/git-hooks/$hook "$dst" || exit
  235. chmod -- a-w "$dst" || exit
  236. done
  237. fi
  238. if test -n "$sample_hooks"; then
  239. for hook in $sample_hooks; do
  240. dst=$hooks/$hook
  241. cp $cp_options -- "$dst.sample" "$dst" || exit
  242. chmod -- a-w "$dst" || exit
  243. done
  244. fi
  245. else
  246. git_was_ok=false
  247. fi
  248. fi
  249. if test ! -f configure; then
  250. echo "You can now run '$0 autoconf'."
  251. elif test -e .git && test $git_was_ok = false && test $do_git = false; then
  252. echo "You can now run '$0 git'."
  253. elif test ! -f config.status ||
  254. test -n "`find src/stamp-h.in -newer config.status`"; then
  255. echo "You can now run './configure'."
  256. fi
  257. exit 0
  258. ### autogen.sh ends here