update_autogen 3.91 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 28 29 30
#!/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.

### Code:

31
die ()                 # write error to stderr and exit
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
{
    [ $# -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"


48
usage ()
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
{
    cat 1>&2 <<EOF
Usage: ${PN} [-f] [-c] [-q]
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.
EOF
    exit 1
}


## Defaults.

force=
commit=
quiet=

## Parameters.
sources="configure.in lib/Makefile.am"
71
genfiles="configure aclocal.m4 src/config.in lib/Makefile.in compile config.guess config.sub depcomp install-sh missing"
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

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

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

tempfile=/tmp/$PN.$$

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


while getopts ":hcfq" option ; do
    case $option in
        (h) usage ;;

        (c) commit=1 ;;

        (f) force=1 ;;

        (q) quiet=1 ;;

        (\?) die "Bad option -$OPTARG" ;;

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

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

[ $# -eq 0 ] || die "Wrong number of arguments"


107
[ "$quiet" ] && exec 1> /dev/null
108 109


110
echo "Running bzr status..."
111 112 113 114 115 116 117

bzr status -S $sources >| $tempfile || die "bzr status error for sources"

while read stat file; do

    case $stat in
        M)
118
            echo "Locally modified: $file"
119 120 121 122 123 124 125 126
            [ "$force" ] || die "There are local modifications"
            ;;

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


127
echo "Running autoreconf..."
128

129
autoreconf -f -i -I m4 2>| $tempfile
130 131 132 133 134 135 136 137 138 139 140

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"
141 142 143 144 145 146 147


cp $genfiles autogen/


cd autogen

148
echo "Checking status of generated files..."
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

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


[ "$modified" ] || {
166
    echo "No files were modified"
167 168 169
    exit 0
}

170
echo "Modified file(s): $modified"
171 172 173 174

[ "$commit" ] || exit 0


175
echo "Committing..."
176 177 178 179

## bzr status output is annoyingly always relative to top-level, not PWD.
cd ../

180
bzr commit -m "Auto-commit of generated files." $modified || \
181 182 183
    die "bzr commit error"


184
echo "Committed files: $modified"
185 186 187 188

exit

### update_autogen ends here