update_autogen 6.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/bin/bash
### update_autogen - update the generated files in Emacs autogen/ directory

## Copyright (C) 2011  Free Software Foundation, Inc.

## Author: Glenn Morris <rgm@gnu.org>

## This file is part of GNU Emacs.

## GNU Emacs is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.

## GNU Emacs is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

### Commentary:

## This is a helper script to update the pre-built generated files in
## the autogen/ directory.  This is suitable for running from cron.
## Only Emacs maintainers need use this, so it uses bash features.
28 29 30
##
## With the -l option, it also updates the versioned loaddefs-like
## files in lisp/.  These include ldefs-boot, cl-loaddefs, rmail, etc.
31 32 33

### Code:

34
die ()                 # write error to stderr and exit
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
{
    [ $# -gt 0 ] && echo "$PN: $@" >&2
    exit 1
}

PN=${0##*/}                     # basename of script
PD=${0%/*}

[ "$PD" = "$0" ] && PD=.        # if PATH includes PWD

## This should be the autogen directory.
cd $PD
cd ../
[ -d autogen ] || die "Could not locate autogen directory"


51
usage ()
52 53
{
    cat 1>&2 <<EOF
54
Usage: ${PN} [-f] [-c] [-q] [-l] [-C] [-- make-flags]
55 56 57 58 59 60
Update the generated files in the Emacs autogen/ directory.
Options:
-f: force an update even if the source files are locally modified.
-c: if the update succeeds and the generated files are modified,
    commit them (caution).
-q: be quiet; only give error messages, not status messages.
61 62 63
-l: also update the versioned loaddefs-like files in lisp/.
This requires a build.  Passes any non-option args to make (eg -- -j2).
-C: start from a clean state.  Slower, but more correct.
64 65 66 67 68 69 70 71 72 73
EOF
    exit 1
}


## Defaults.

force=
commit=
quiet=
74 75
clean=
ldefs_flag=
76 77

## Parameters.
78 79
ldefs_in=lisp/loaddefs.el
ldefs_out=lisp/ldefs-boot.el
80
sources="configure.in lib/Makefile.am"
81
genfiles="configure aclocal.m4 src/config.in lib/Makefile.in compile config.guess config.sub depcomp install-sh missing"
82 83 84 85 86 87 88 89 90 91 92 93

for g in $genfiles; do
    basegen="$basegen ${g##*/}"
done

[ "$basegen" ] || die "internal error"

tempfile=/tmp/$PN.$$

trap "rm -f $tempfile 2> /dev/null" EXIT


94
while getopts ":hcflqC" option ; do
95 96 97 98 99 100 101
    case $option in
        (h) usage ;;

        (c) commit=1 ;;

        (f) force=1 ;;

102 103
        (l) ldefs_flag=1 ;;

104 105
        (q) quiet=1 ;;

106 107
        (C) clean=1 ;;

108 109 110 111 112 113 114 115 116 117 118
        (\?) die "Bad option -$OPTARG" ;;

        (:) die "Option -$OPTARG requires an argument" ;;

        (*) die "getopts error" ;;
    esac
done
shift $(( --OPTIND ))
OPTIND=1


119
## Does not work 100% because a lot of Emacs batch output comes on stderr (?).
120
[ "$quiet" ] && exec 1> /dev/null
121 122


123
echo "Running bzr status..."
124

125 126
bzr status -S $sources ${ldefs_flag:+lisp} >| $tempfile || \
    die "bzr status error for sources"
127

128
## The lisp portion could be more permissive, eg only care about .el files.
129 130 131 132
while read stat file; do

    case $stat in
        M)
133
            echo "Locally modified: $file"
134 135 136 137 138 139 140 141
            [ "$force" ] || die "There are local modifications"
            ;;

        *) die "Unexpected status ($stat) for $file" ;;
    esac
done < $tempfile


142 143 144 145 146 147 148 149 150 151 152 153
## Probably this is overkill, and there's no need to "bootstrap" just
## for making autoloads.
[ "$clean" ] && {

    echo "Running 'make maintainer-clean'..."

    make maintainer-clean #|| die "Cleaning error"

    rm -f $ldefs_in
}


154
echo "Running autoreconf..."
155

156
autoreconf ${clean:+-f} -i -I m4 2>| $tempfile
157 158 159 160 161 162 163 164 165 166 167

retval=$?

## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
if [ "$quiet" ]; then
    grep -v 'installing `\.' $tempfile 1>&2
else
    cat "$tempfile" 1>&2
fi

[ $retval -ne 0 ] && die "autoreconf error"
168 169 170 171 172 173 174


cp $genfiles autogen/


cd autogen

175
echo "Checking status of generated files..."
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

bzr status -S $basegen >| $tempfile || \
    die "bzr status error for generated files"


modified=

while read stat file; do

    [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"

    modified="$modified $file"

done < $tempfile


192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
cd ../


## Uses global $commit.
commit ()
{
    local type=$1
    shift

    [ $# -gt 0 ] || {
        echo "No files were modified"
        return 0
    }

    echo "Modified file(s): $@"

    [ "$commit" ] || return 0

    echo "Committing..."

    ## bzr status output is always relative to top-level, not PWD.
    bzr commit -m "Auto-commit of $type files." "$@" || return $?

    echo "Committed files: $@"
}                               # function commit


commit "generated" $modified || die "bzr commit error"


[ "$ldefs_flag" ] || exit 0


echo "Finding loaddef targets..."

sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \
    sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error"

genfiles=

while read genfile; do

    [ -r lisp/$genfile ] || die "Unable to read $genfile"

    genfiles="$genfiles $genfile"
done < $tempfile


[ "$genfiles" ] || die "Error setting genfiles"


[ -e Makefile ] || {
    echo "Running ./configure..."

    ./configure || die "configure error"
247 248 249
}


250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
## Build the minimum needed to get the autoloads.
echo "Running lib/ make..."

make -C lib "$@" all || die "make lib error"


echo "Running src/ make..."

make -C src "$@" bootstrap-emacs || die "make src error"


echo "Running lisp/ make..."

make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"


cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
267 268


269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
cd lisp

echo "Checking status of loaddef files..."

## It probably would be fine to just check+commit lisp/, since
## making autoloads should not effect any other files.  But better
## safe than sorry.
bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \
    die "bzr status error for generated files"


modified=

while read stat file; do

    [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
    modified="$modified $file"

done < $tempfile

289 290 291 292

cd ../


293
commit "loaddefs" $modified || die "bzr commit error"
294 295


296
exit 0
297 298

### update_autogen ends here