autogen.sh 9.7 KB

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