update_autogen 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #!/bin/bash
  2. ### update_autogen - update the generated files in Emacs autogen/ directory
  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. ## This is a helper script to update the pre-built generated files in
  18. ## the autogen/ directory. This is suitable for running from cron.
  19. ## Only Emacs maintainers need use this, so it uses bash features.
  20. ##
  21. ## With the -l option, it also updates the versioned loaddefs-like
  22. ## files in lisp/. These include ldefs-boot, cl-loaddefs, rmail, etc.
  23. ### Code:
  24. die () # write error to stderr and exit
  25. {
  26. [ $# -gt 0 ] && echo "$PN: $@" >&2
  27. exit 1
  28. }
  29. PN=${0##*/} # basename of script
  30. PD=${0%/*}
  31. [ "$PD" = "$0" ] && PD=. # if PATH includes PWD
  32. ## This should be the autogen directory.
  33. cd $PD
  34. cd ../
  35. [ -d autogen ] || die "Could not locate autogen directory"
  36. usage ()
  37. {
  38. cat 1>&2 <<EOF
  39. Usage: ${PN} [-f] [-c] [-q] [-l [-L]] [-C] [-- make-flags]
  40. Update the generated files in the Emacs autogen/ directory.
  41. Options:
  42. -f: force an update even if the source files are locally modified.
  43. -c: if the update succeeds and the generated files are modified,
  44. commit them (caution).
  45. -q: be quiet; only give error messages, not status messages.
  46. -l: also update the versioned loaddefs-like files in lisp/.
  47. This requires a build. Passes any non-option args to make (eg -- -j2).
  48. -L: also update ldefs-boot.el.
  49. -C: start from a clean state. Slower, but more correct.
  50. EOF
  51. exit 1
  52. }
  53. ## Defaults.
  54. force=
  55. commit=
  56. quiet=
  57. clean=
  58. ldefs_flag=
  59. lboot_flag=
  60. ## Parameters.
  61. ldefs_in=lisp/loaddefs.el
  62. ldefs_out=lisp/ldefs-boot.el
  63. sources="configure.in lib/Makefile.am"
  64. genfiles="
  65. configure aclocal.m4 src/config.in lib/Makefile.in
  66. build-aux/compile build-aux/config.guess build-aux/config.sub
  67. build-aux/depcomp build-aux/install-sh build-aux/missing
  68. "
  69. for g in $genfiles; do
  70. basegen="$basegen ${g##*/}"
  71. done
  72. [ "$basegen" ] || die "internal error"
  73. tempfile=/tmp/$PN.$$
  74. trap "rm -f $tempfile 2> /dev/null" EXIT
  75. while getopts ":hcflqCL" option ; do
  76. case $option in
  77. (h) usage ;;
  78. (c) commit=1 ;;
  79. (f) force=1 ;;
  80. (l) ldefs_flag=1 ;;
  81. (q) quiet=1 ;;
  82. (C) clean=1 ;;
  83. (L) lboot_flag=1 ;;
  84. (\?) die "Bad option -$OPTARG" ;;
  85. (:) die "Option -$OPTARG requires an argument" ;;
  86. (*) die "getopts error" ;;
  87. esac
  88. done
  89. shift $(( --OPTIND ))
  90. OPTIND=1
  91. ## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
  92. [ "$quiet" ] && exec 1> /dev/null
  93. echo "Running bzr status..."
  94. bzr status -S $sources ${ldefs_flag:+lisp} >| $tempfile || \
  95. die "bzr status error for sources"
  96. ## The lisp portion could be more permissive, eg only care about .el files.
  97. while read stat file; do
  98. case $stat in
  99. M)
  100. echo "Locally modified: $file"
  101. [ "$force" ] || die "There are local modifications"
  102. ;;
  103. *) die "Unexpected status ($stat) for $file" ;;
  104. esac
  105. done < $tempfile
  106. ## Probably this is overkill, and there's no need to "bootstrap" just
  107. ## for making autoloads.
  108. [ "$clean" ] && {
  109. echo "Running 'make maintainer-clean'..."
  110. make maintainer-clean #|| die "Cleaning error"
  111. rm -f $ldefs_in
  112. }
  113. echo "Running autoreconf..."
  114. autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
  115. retval=$?
  116. ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
  117. if [ "$quiet" ]; then
  118. grep -v 'installing `\.' $tempfile 1>&2
  119. else
  120. cat "$tempfile" 1>&2
  121. fi
  122. [ $retval -ne 0 ] && die "autoreconf error"
  123. cp $genfiles autogen/
  124. cd autogen
  125. echo "Checking status of generated files..."
  126. bzr status -S $basegen >| $tempfile || \
  127. die "bzr status error for generated files"
  128. modified=
  129. while read stat file; do
  130. [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
  131. modified="$modified $file"
  132. done < $tempfile
  133. cd ../
  134. ## Uses global $commit.
  135. commit ()
  136. {
  137. local type=$1
  138. shift
  139. [ $# -gt 0 ] || {
  140. echo "No files were modified"
  141. return 0
  142. }
  143. echo "Modified file(s): $@"
  144. [ "$commit" ] || return 0
  145. echo "Committing..."
  146. ## bzr status output is always relative to top-level, not PWD.
  147. bzr commit -m "Auto-commit of $type files." "$@" || return $?
  148. echo "Committed files: $@"
  149. } # function commit
  150. commit "generated" $modified || die "bzr commit error"
  151. [ "$ldefs_flag" ] || exit 0
  152. echo "Finding loaddef targets..."
  153. sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \
  154. sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error"
  155. genfiles=
  156. while read genfile; do
  157. [ -r lisp/$genfile ] || die "Unable to read $genfile"
  158. genfiles="$genfiles $genfile"
  159. done < $tempfile
  160. [ "$genfiles" ] || die "Error setting genfiles"
  161. [ -e Makefile ] || {
  162. echo "Running ./configure..."
  163. ## Minimize required packages.
  164. ./configure --without-x || die "configure error"
  165. }
  166. ## Build the minimum needed to get the autoloads.
  167. echo "Running lib/ make..."
  168. make -C lib "$@" all || die "make lib error"
  169. echo "Running src/ make..."
  170. make -C src "$@" bootstrap-emacs || die "make src error"
  171. echo "Running lisp/ make..."
  172. make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
  173. ## Ignore comment differences.
  174. [ ! "$lboot_flag" ] || \
  175. diff -q -I '^;' $ldefs_in $ldefs_out || \
  176. cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
  177. cd lisp
  178. echo "Checking status of loaddef files..."
  179. ## It probably would be fine to just check+commit lisp/, since
  180. ## making autoloads should not effect any other files. But better
  181. ## safe than sorry.
  182. bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \
  183. die "bzr status error for generated files"
  184. modified=
  185. while read stat file; do
  186. [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
  187. modified="$modified $file"
  188. done < $tempfile
  189. cd ../
  190. commit "loaddefs" $modified || die "bzr commit error"
  191. exit 0
  192. ### update_autogen ends here