OSDN Git Service

3e42a78c67ed8b01f65423fb6a0cb595e3c604bb
[pf3gnuchains/gcc-fork.git] / contrib / gcc_update
1 #! /bin/sh
2 #
3 # Update a local CVS tree from the GCC repository, with an emphasis
4 # on treating generated files correctly, so that autoconf, bison et
5 # al are not required for the ``end'' user.
6 #
7 # By default all command-line options are passed to `cvs update` in
8 # addition to $UPDATE_OPTIONS (defined below). If the first parameter
9 # reads --nostdflags, $UPDATE_OPTIONS as well as this parameter itself
10 # are omitted. 
11
12 # If the first parameter reads --patch, the second parameter is considered
13 # a patch file.
14
15 # If the first parameter is --touch, no cvs operation will be performed,
16 # only generated files that appear to be out of date in the local tree
17 # will be touched.
18 #
19 # If the first parameter is --list, a list of the generated files and
20 # their dependencies will be printed; --help prints this message.
21 #
22 # Examples:
23 #
24 # contrib/gcc_update -r gcc_latest_snapshot
25 # contrib/gcc_update -A
26 # contrib/gcc_update --nostdflags -P -r gcc-2_95-branch gcc/testsuite
27 # contrib/gcc_update --patch some-patch
28 # contrib/gcc_update --touch
29 # contrib/gcc_update --list
30 #
31 #
32 # (C) 1998-2000 Free Software Foundation
33 # Originally by Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>, August 1998.
34 #
35 # This script is Free Software, and it can be copied, distributed and
36 # modified as defined in the GNU General Public License.  A copy of
37 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
38
39
40 # Default options used when updating via CVS.
41 UPDATE_OPTIONS=-P
42 # Add -d to create any directories that exist in the repository but not
43 #        locally.
44 # Add -A to reset any sticky tags, dates, or `-k' options.
45
46 # Arrange for the value of $0 to be available for functions
47 self=$0
48
49 # This function prints a list of all generated files, along with their
50 # dependencies.  Note that only one target is supported per line: the
51 # colon is stripped from the output.
52 files_and_dependencies () {
53     sed -e 's/ *#.*//' -e '/^$/d' -e 's/://' <<\EOF
54 # All automake dependencies within texinfo
55 # In fact, not all, since we do not care about sub-directories that
56 # we do not build.  In particular, *.po and *.gmo are not touched.
57 texinfo/aclocal.m4: texinfo/configure.in texinfo/acinclude.m4
58 texinfo/Makefile.in: texinfo/Makefile.am texinfo/configure.in texinfo/aclocal.m4
59 texinfo/configure: texinfo/configure.in texinfo/aclocal.m4
60 texinfo/stamp-h.in: texinfo/configure.in texinfo/aclocal.m4 texinfo/acconfig.h
61 texinfo/lib/Makefile.in: texinfo/lib/Makefile.am texinfo/configure.in texinfo/aclocal.m4
62 texinfo/makeinfo/Makefile.in: texinfo/makeinfo/Makefile.am texinfo/configure.in texinfo/aclocal.m4
63 texinfo/util/Makefile.in: texinfo/util/Makefile.am texinfo/configure.in texinfo/aclocal.m4
64 # Now, proceed to gcc automatically generated files
65 gcc/configure: gcc/configure.in
66 gcc/cstamp-h.in: gcc/configure.in gcc/acconfig.h
67 gcc/config.in: gcc/cstamp-h.in
68 gcc/c-gperf.h: gcc/c-parse.gperf
69 gcc/fixinc/fixincl.x: gcc/fixinc/fixincl.tpl gcc/fixinc/inclhack.def
70 gcc/tradcif.c: gcc/tradcif.y
71 # And then, language-specific files
72 gcc/java/parse.h: gcc/java/parse.y
73 gcc/java/parse.c: gcc/java/parse.y gcc/java/lex.c gcc/java/parse.h gcc/java/lex.h
74 # And libraries, at last
75 libchill/configure: libchill/configure.in
76 libf2c/configure: libf2c/configure.in
77 libf2c/libF77/configure: libf2c/libF77/configure.in
78 libf2c/libI77/configure: libf2c/libI77/configure.in
79 libf2c/libU77/configure: libf2c/libU77/configure.in
80 libf2c/libU77/stamp-h.in: libf2c/libU77/configure.in libf2c/libU77/acconfig.h
81 libobjc/configure: libobjc/configure.in
82 EOF
83 }
84
85
86 # This function checks whether its first argument is newer than all
87 # the other arguments.  It returns success (0) otherwise.
88 is_out_of_date () {
89   test `ls -1dt ${1+"$@"} | sed 1q` != "$1"
90 }
91
92
93 # This function touches generated files such that the ``end'' user does
94 # not have to rebuild them.
95 touch_files () {
96     files_and_dependencies | while read f deps; do
97         if test -f $f && is_out_of_date "$f" $deps; then
98             echo Touching "$f"...
99             touch $f
100             if is_out_of_date "$f" $deps; then
101                 # Hmm, it may have got the same timestamp as one of
102                 # its touched dependencies.  Wait a second and retry
103                 sleep 1
104                 touch $f
105             fi
106         fi
107     done
108 }
109
110 # Whenever we update the tree or install a patch, we may be modifying
111 # this script.  By re-execing it, we ensure that the appropriate
112 # dependencies and rules will be used.
113 touch_files_reexec () {
114     echo "Adjusting file timestamps"
115     exec ${CONFIG_SHELL-/bin/sh} $self --touch
116 }    
117
118 # This functions applies a patch to an existing tree.
119 apply_patch () {
120     if [ -f $1 ]; then
121         echo "Applying patch file $1"
122         case "$1" in
123         *gz)
124             gzip -d -c $1 | patch -p1 ;;
125         *bz2)
126             bzip2 -d -c $1 | patch -p1 ;;
127         *)
128             cat $1 | patch -p1 ;;
129         esac
130     fi
131     touch_files_reexec
132 }
133
134 # Check whether this indeed looks like a local tree.
135 if [ ! -f gcc/version.c ]; then
136     echo "This does not seem to be a GCC tree!"
137     exit
138 fi
139
140 case "$1" in
141 # First of all, check whether we are going to process a patch.
142 --patch) 
143     if test "$#" != 2; then
144         echo "$1" expects only one argument >&2
145         exit 1
146     fi
147     apply_patch "${2}"
148     exit $?
149     ;;
150
151 --touch)
152     if test "$#" != 1; then
153         echo "$1" does not expect any argument >&2
154         exit 1
155     fi
156     touch_files
157     exit $?
158     ;;
159
160 --list)
161     if test "$#" != 1; then
162         echo "$1" does not expect any argument >&2
163         exit 1
164     fi
165     files_and_dependencies | sed 's/ /: /'
166     exit $?
167     ;;
168
169 --help)
170     sed -e '1,2d' -e '/^UPDATE_OPTIONS=/{i\
171 \
172
173 p
174 }' \
175         -e '/^$/,$d' -e 's/#//' -e 's/^ //' < $0
176     exit $?
177     ;;
178
179 esac
180
181 # Check whether this indeed looks like a local CVS tree.
182 if [ ! -d CVS ]; then
183     echo "This does not seem to be a GCC CVS tree!"
184     exit
185 fi
186
187 # Check command-line options
188 if [ x"${1}"x = x"--nostdflags"x ]; then
189     shift
190 else
191     set -- $UPDATE_OPTIONS ${1+"$@"}
192 fi
193
194 echo "Updating CVS tree"
195 cvs -q update ${1+"$@"}
196 if [ $? -ne 0 ]; then 
197     echo "CVS update of full tree failed." >&2
198     exit 1
199 fi
200
201 touch_files_reexec