| 1 | #!/bin/bash |
| 2 | ### update_autogen - update the generated files in Emacs autogen/ directory |
| 3 | |
| 4 | ## Copyright (C) 2011 Free Software Foundation, Inc. |
| 5 | |
| 6 | ## Author: Glenn Morris <rgm@gnu.org> |
| 7 | |
| 8 | ## This file is part of GNU Emacs. |
| 9 | |
| 10 | ## GNU Emacs is free software: you can redistribute it and/or modify |
| 11 | ## it under the terms of the GNU General Public License as published by |
| 12 | ## the Free Software Foundation, either version 3 of the License, or |
| 13 | ## (at your option) any later version. |
| 14 | |
| 15 | ## GNU Emacs is distributed in the hope that it will be useful, |
| 16 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | ## GNU General Public License for more details. |
| 19 | |
| 20 | ## You should have received a copy of the GNU General Public License |
| 21 | ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | ### Commentary: |
| 24 | |
| 25 | ## This is a helper script to update the pre-built generated files in |
| 26 | ## the autogen/ directory. This is suitable for running from cron. |
| 27 | ## Only Emacs maintainers need use this, so it uses bash features. |
| 28 | ## |
| 29 | ## With the -l option, it also updates the versioned loaddefs-like |
| 30 | ## files in lisp/. These include ldefs-boot, cl-loaddefs, rmail, etc. |
| 31 | |
| 32 | ### Code: |
| 33 | |
| 34 | die () # write error to stderr and exit |
| 35 | { |
| 36 | [ $# -gt 0 ] && echo "$PN: $@" >&2 |
| 37 | exit 1 |
| 38 | } |
| 39 | |
| 40 | PN=${0##*/} # basename of script |
| 41 | PD=${0%/*} |
| 42 | |
| 43 | [ "$PD" = "$0" ] && PD=. # if PATH includes PWD |
| 44 | |
| 45 | ## This should be the autogen directory. |
| 46 | cd $PD |
| 47 | cd ../ |
| 48 | [ -d autogen ] || die "Could not locate autogen directory" |
| 49 | |
| 50 | |
| 51 | usage () |
| 52 | { |
| 53 | cat 1>&2 <<EOF |
| 54 | Usage: ${PN} [-f] [-c] [-q] [-l [-L]] [-C] [-- make-flags] |
| 55 | Update the generated files in the Emacs autogen/ directory. |
| 56 | Options: |
| 57 | -f: force an update even if the source files are locally modified. |
| 58 | -c: if the update succeeds and the generated files are modified, |
| 59 | commit them (caution). |
| 60 | -q: be quiet; only give error messages, not status messages. |
| 61 | -l: also update the versioned loaddefs-like files in lisp/. |
| 62 | This requires a build. Passes any non-option args to make (eg -- -j2). |
| 63 | -L: also update ldefs-boot.el. |
| 64 | -C: start from a clean state. Slower, but more correct. |
| 65 | EOF |
| 66 | exit 1 |
| 67 | } |
| 68 | |
| 69 | |
| 70 | ## Defaults. |
| 71 | |
| 72 | force= |
| 73 | commit= |
| 74 | quiet= |
| 75 | clean= |
| 76 | ldefs_flag= |
| 77 | lboot_flag= |
| 78 | |
| 79 | ## Parameters. |
| 80 | ldefs_in=lisp/loaddefs.el |
| 81 | ldefs_out=lisp/ldefs-boot.el |
| 82 | sources="configure.in lib/Makefile.am" |
| 83 | genfiles=" |
| 84 | configure aclocal.m4 src/config.in lib/Makefile.in |
| 85 | build-aux/compile build-aux/config.guess build-aux/config.sub |
| 86 | build-aux/depcomp build-aux/install-sh build-aux/missing |
| 87 | " |
| 88 | |
| 89 | for g in $genfiles; do |
| 90 | basegen="$basegen ${g##*/}" |
| 91 | done |
| 92 | |
| 93 | [ "$basegen" ] || die "internal error" |
| 94 | |
| 95 | tempfile=/tmp/$PN.$$ |
| 96 | |
| 97 | trap "rm -f $tempfile 2> /dev/null" EXIT |
| 98 | |
| 99 | |
| 100 | while getopts ":hcflqCL" option ; do |
| 101 | case $option in |
| 102 | (h) usage ;; |
| 103 | |
| 104 | (c) commit=1 ;; |
| 105 | |
| 106 | (f) force=1 ;; |
| 107 | |
| 108 | (l) ldefs_flag=1 ;; |
| 109 | |
| 110 | (q) quiet=1 ;; |
| 111 | |
| 112 | (C) clean=1 ;; |
| 113 | |
| 114 | (L) lboot_flag=1 ;; |
| 115 | |
| 116 | (\?) die "Bad option -$OPTARG" ;; |
| 117 | |
| 118 | (:) die "Option -$OPTARG requires an argument" ;; |
| 119 | |
| 120 | (*) die "getopts error" ;; |
| 121 | esac |
| 122 | done |
| 123 | shift $(( --OPTIND )) |
| 124 | OPTIND=1 |
| 125 | |
| 126 | |
| 127 | ## Does not work 100% because a lot of Emacs batch output comes on stderr (?). |
| 128 | [ "$quiet" ] && exec 1> /dev/null |
| 129 | |
| 130 | |
| 131 | echo "Running bzr status..." |
| 132 | |
| 133 | bzr status -S $sources ${ldefs_flag:+lisp} >| $tempfile || \ |
| 134 | die "bzr status error for sources" |
| 135 | |
| 136 | ## The lisp portion could be more permissive, eg only care about .el files. |
| 137 | while read stat file; do |
| 138 | |
| 139 | case $stat in |
| 140 | M) |
| 141 | echo "Locally modified: $file" |
| 142 | [ "$force" ] || die "There are local modifications" |
| 143 | ;; |
| 144 | |
| 145 | *) die "Unexpected status ($stat) for $file" ;; |
| 146 | esac |
| 147 | done < $tempfile |
| 148 | |
| 149 | |
| 150 | ## Probably this is overkill, and there's no need to "bootstrap" just |
| 151 | ## for making autoloads. |
| 152 | [ "$clean" ] && { |
| 153 | |
| 154 | echo "Running 'make maintainer-clean'..." |
| 155 | |
| 156 | make maintainer-clean #|| die "Cleaning error" |
| 157 | |
| 158 | rm -f $ldefs_in |
| 159 | } |
| 160 | |
| 161 | |
| 162 | echo "Running autoreconf..." |
| 163 | |
| 164 | autoreconf ${clean:+-f} -i -I m4 2>| $tempfile |
| 165 | |
| 166 | retval=$? |
| 167 | |
| 168 | ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr. |
| 169 | if [ "$quiet" ]; then |
| 170 | grep -v 'installing `\.' $tempfile 1>&2 |
| 171 | else |
| 172 | cat "$tempfile" 1>&2 |
| 173 | fi |
| 174 | |
| 175 | [ $retval -ne 0 ] && die "autoreconf error" |
| 176 | |
| 177 | |
| 178 | cp $genfiles autogen/ |
| 179 | |
| 180 | |
| 181 | cd autogen |
| 182 | |
| 183 | echo "Checking status of generated files..." |
| 184 | |
| 185 | bzr status -S $basegen >| $tempfile || \ |
| 186 | die "bzr status error for generated files" |
| 187 | |
| 188 | |
| 189 | modified= |
| 190 | |
| 191 | while read stat file; do |
| 192 | |
| 193 | [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file" |
| 194 | |
| 195 | modified="$modified $file" |
| 196 | |
| 197 | done < $tempfile |
| 198 | |
| 199 | |
| 200 | cd ../ |
| 201 | |
| 202 | |
| 203 | ## Uses global $commit. |
| 204 | commit () |
| 205 | { |
| 206 | local type=$1 |
| 207 | shift |
| 208 | |
| 209 | [ $# -gt 0 ] || { |
| 210 | echo "No files were modified" |
| 211 | return 0 |
| 212 | } |
| 213 | |
| 214 | echo "Modified file(s): $@" |
| 215 | |
| 216 | [ "$commit" ] || return 0 |
| 217 | |
| 218 | echo "Committing..." |
| 219 | |
| 220 | ## bzr status output is always relative to top-level, not PWD. |
| 221 | bzr commit -m "Auto-commit of $type files." "$@" || return $? |
| 222 | |
| 223 | echo "Committed files: $@" |
| 224 | } # function commit |
| 225 | |
| 226 | |
| 227 | commit "generated" $modified || die "bzr commit error" |
| 228 | |
| 229 | |
| 230 | [ "$ldefs_flag" ] || exit 0 |
| 231 | |
| 232 | |
| 233 | echo "Finding loaddef targets..." |
| 234 | |
| 235 | sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \ |
| 236 | sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error" |
| 237 | |
| 238 | genfiles= |
| 239 | |
| 240 | while read genfile; do |
| 241 | |
| 242 | [ -r lisp/$genfile ] || die "Unable to read $genfile" |
| 243 | |
| 244 | genfiles="$genfiles $genfile" |
| 245 | done < $tempfile |
| 246 | |
| 247 | |
| 248 | [ "$genfiles" ] || die "Error setting genfiles" |
| 249 | |
| 250 | |
| 251 | [ -e Makefile ] || { |
| 252 | echo "Running ./configure..." |
| 253 | |
| 254 | ## Minimize required packages. |
| 255 | ./configure --without-x || die "configure error" |
| 256 | } |
| 257 | |
| 258 | |
| 259 | ## Build the minimum needed to get the autoloads. |
| 260 | echo "Running lib/ make..." |
| 261 | |
| 262 | make -C lib "$@" all || die "make lib error" |
| 263 | |
| 264 | |
| 265 | echo "Running src/ make..." |
| 266 | |
| 267 | make -C src "$@" bootstrap-emacs || die "make src error" |
| 268 | |
| 269 | |
| 270 | echo "Running lisp/ make..." |
| 271 | |
| 272 | make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error" |
| 273 | |
| 274 | |
| 275 | ## Ignore comment differences. |
| 276 | [ ! "$lboot_flag" ] || \ |
| 277 | diff -q -I '^;' $ldefs_in $ldefs_out || \ |
| 278 | cp $ldefs_in $ldefs_out || die "cp ldefs_boot error" |
| 279 | |
| 280 | |
| 281 | cd lisp |
| 282 | |
| 283 | echo "Checking status of loaddef files..." |
| 284 | |
| 285 | ## It probably would be fine to just check+commit lisp/, since |
| 286 | ## making autoloads should not effect any other files. But better |
| 287 | ## safe than sorry. |
| 288 | bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \ |
| 289 | die "bzr status error for generated files" |
| 290 | |
| 291 | |
| 292 | modified= |
| 293 | |
| 294 | while read stat file; do |
| 295 | |
| 296 | [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file" |
| 297 | modified="$modified $file" |
| 298 | |
| 299 | done < $tempfile |
| 300 | |
| 301 | |
| 302 | cd ../ |
| 303 | |
| 304 | |
| 305 | commit "loaddefs" $modified || die "bzr commit error" |
| 306 | |
| 307 | |
| 308 | exit 0 |
| 309 | |
| 310 | ### update_autogen ends here |