xref: /openbsd-src/gnu/usr.bin/gcc/contrib/gcc_update (revision 4e43c760ad4cd5f644ec700462679d05749498d8)
17e568061Sespie#! /bin/sh
27e568061Sespie#
37e568061Sespie# Update a local CVS tree from the GCC repository, with an emphasis
47e568061Sespie# on treating generated files correctly, so that autoconf, gperf et
57e568061Sespie# al are not required for the ``end'' user.
67e568061Sespie#
77e568061Sespie# By default all command-line options are passed to `cvs update` in
87e568061Sespie# addition to $UPDATE_OPTIONS (defined below). If the first parameter
97e568061Sespie# reads --nostdflags, $UPDATE_OPTIONS as well as this parameter itself
107e568061Sespie# are omitted.
117e568061Sespie#
127e568061Sespie# If the first parameter reads --patch, the second parameter is considered
137e568061Sespie# a patch file.
147e568061Sespie#
157e568061Sespie# If the first parameter is --touch, no cvs operation will be performed,
167e568061Sespie# only generated files that appear to be out of date in the local tree
177e568061Sespie# will be touched.
187e568061Sespie#
197e568061Sespie# If the first parameter is --list, a list of the generated files and
207e568061Sespie# their dependencies will be printed; --help prints this message.
217e568061Sespie#
227e568061Sespie# Examples:
237e568061Sespie#
247e568061Sespie# contrib/gcc_update -r gcc_latest_snapshot
257e568061Sespie# contrib/gcc_update -A
267e568061Sespie# contrib/gcc_update --nostdflags -P -r gcc-2_95-branch gcc/testsuite
277e568061Sespie# contrib/gcc_update --patch some-patch
287e568061Sespie# contrib/gcc_update --touch
297e568061Sespie# contrib/gcc_update --list
307e568061Sespie#
317e568061Sespie#
327e568061Sespie# (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
337e568061Sespie# Originally by Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>, August 1998.
347e568061Sespie#
357e568061Sespie# This script is Free Software, and it can be copied, distributed and
367e568061Sespie# modified as defined in the GNU General Public License.  A copy of
377e568061Sespie# its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
387e568061Sespie
397e568061Sespie
407e568061Sespie# Default options used when updating via CVS.
417e568061SespieUPDATE_OPTIONS=-Pd
427e568061Sespie# Use -P to prune empty directories.
437e568061Sespie# Use -d to create any directories that exist in the repository but not
447e568061Sespie#           locally.
457e568061Sespie# Use -A to reset any sticky tags, dates, or `-k' options.
467e568061Sespie
477e568061Sespie######## Anything below shouldn't be changed by regular users.
487e568061Sespie
497e568061Sespie# Arrange for the value of $0 to be available for functions
507e568061Sespieself=$0
517e568061Sespie
527e568061Sespie# This function prints a list of all generated files, along with their
537e568061Sespie# dependencies.  Note that only one target is supported per line: the
547e568061Sespie# colon is stripped from the output.
557e568061Sespiefiles_and_dependencies () {
567e568061Sespie    sed -e 's/ *#.*//' -e '/^$/d' -e 's/://' <<\EOF
577e568061Sespie# All automake dependencies within texinfo
587e568061Sespie# In fact, not all, since we do not care about sub-directories that
597e568061Sespie# we do not build.  In particular, *.po and *.gmo are not touched.
607e568061Sespietexinfo/aclocal.m4: texinfo/configure.in texinfo/acinclude.m4
617e568061Sespietexinfo/Makefile.in: texinfo/Makefile.am texinfo/configure.in texinfo/aclocal.m4
627e568061Sespietexinfo/configure: texinfo/configure.in texinfo/aclocal.m4
637e568061Sespietexinfo/stamp-h.in: texinfo/configure.in texinfo/aclocal.m4 texinfo/acconfig.h
647e568061Sespietexinfo/lib/Makefile.in: texinfo/lib/Makefile.am texinfo/configure.in texinfo/aclocal.m4
657e568061Sespietexinfo/makeinfo/Makefile.in: texinfo/makeinfo/Makefile.am texinfo/configure.in texinfo/aclocal.m4
667e568061Sespietexinfo/util/Makefile.in: texinfo/util/Makefile.am texinfo/configure.in texinfo/aclocal.m4
677e568061Sespie# Now, proceed to gcc automatically generated files
687e568061Sespiegcc/configure: gcc/configure.in
697e568061Sespiegcc/cstamp-h.in: gcc/configure.in gcc/acconfig.h
707e568061Sespiegcc/config.in: gcc/cstamp-h.in
717e568061Sespiegcc/fixinc/fixincl.x: gcc/fixinc/fixincl.tpl gcc/fixinc/inclhack.def
727e568061Sespiegcc/intl/plural.c: gcc/intl/plural.y
737e568061Sespie# And then, language-specific files
747e568061Sespiegcc/f/intdoc.texi: gcc/f/intdoc.in gcc/f/intdoc.c gcc/f/intrin.h gcc/f/intrin.def
757e568061Sespiegcc/cp/cfns.h: gcc/cp/cfns.gperf
767e568061Sespiegcc/java/keyword.h: gcc/java/keyword.gperf
777e568061Sespiegcc/ada/treeprs.ads: gcc/ada/treeprs.adt gcc/ada/sinfo.ads gcc/ada/xtreeprs.adb
787e568061Sespiegcc/ada/einfo.h: gcc/ada/einfo.ads gcc/ada/einfo.adb gcc/ada/xeinfo.adb
797e568061Sespiegcc/ada/sinfo.h: gcc/ada/sinfo.ads gcc/ada/xsinfo.adb
807e568061Sespiegcc/ada/nmake.adb: gcc/ada/sinfo.ads gcc/ada/nmake.adt gcc/ada/xnmake.adb
817e568061Sespiegcc/ada/nmake.ads: gcc/ada/sinfo.ads gcc/ada/nmake.adt gcc/ada/xnmake.adb
827e568061Sespiegcc/ada/gnat_ug_unx.texi: gcc/ada/gnat_ug.texi gcc/ada/xgnatug.adb gcc/ada/ug_words
837e568061Sespiegcc/ada/gnat_ug_vms.texi: gcc/ada/gnat_ug.texi gcc/ada/xgnatug.adb gcc/ada/ug_words
847e568061Sespiegcc/ada/gnat_ug_vxw.texi: gcc/ada/gnat_ug.texi gcc/ada/xgnatug.adb gcc/ada/ug_words
85*4e43c760Sespiegcc/ada/gnat_ug_wnt.texi: gcc/ada/gnat_ug.texi gcc/ada/xgnatug.adb gcc/ada/ug_words
867e568061Sespie# testsuite
877e568061Sespie# Without this, _Pragma3.c can have a false negative.
887e568061Sespiegcc/testsuite/gcc.dg/cpp/_Pragma3.c: gcc/testsuite/gcc.dg/cpp/mi1c.h
897e568061Sespie# And libraries, at last
907e568061Sespielibf2c/configure: libf2c/configure.in
917e568061Sespielibf2c/libF77/configure: libf2c/libF77/configure.in
927e568061Sespielibf2c/libI77/configure: libf2c/libI77/configure.in
937e568061Sespielibf2c/libI77/stamp-h.in: libf2c/libI77/configure.in
947e568061Sespielibf2c/libI77/config.h.in: libf2c/libI77/configure.in libf2c/libI77/stamp-h.in
957e568061Sespielibf2c/libU77/configure: libf2c/libU77/configure.in
967e568061Sespielibf2c/libU77/stamp-h.in: libf2c/libU77/configure.in libf2c/libU77/acconfig.h
977e568061Sespielibobjc/configure: libobjc/configure.in
987e568061Sespie# fastjar
997e568061Sespiefastjar/aclocal.m4: fastjar/configure.in
1007e568061Sespiefastjar/Makefile.in: fastjar/Makefile.am fastjar/configure.in fastjar/aclocal.m4
1017e568061Sespiefastjar/configure: fastjar/configure.in fastjar/aclocal.m4
1027e568061Sespiefastjar/stamp-h.in: fastjar/configure.in fastjar/aclocal.m4
1037e568061Sespieboehm-gc/aclocal.m4: boehm-gc/configure.in boehm-gc/acinclude.m4
1047e568061Sespieboehm-gc/Makefile.in: boehm-gc/Makefile.am boehm-gc/configure.in boehm-gc/aclocal.m4
1057e568061Sespieboehm-gc/configure: boehm-gc/configure.in boehm-gc/aclocal.m4
1067e568061Sespielibjava/aclocal.m4: libjava/configure.in libjava/acinclude.m4
1077e568061Sespielibjava/Makefile.in: libjava/Makefile.am libjava/configure.in libjava/aclocal.m4
1087e568061Sespielibjava/configure: libjava/configure.in libjava/aclocal.m4
1097e568061Sespielibjava/libltdl/aclocal.m4: libjava/libltdl/configure.in libjava/libltdl/acinclude.m4
1107e568061Sespielibjava/libltdl/Makefile.in: libjava/libltdl/Makefile.am libjava/libltdl/configure.in libjava/libltdl/aclocal.m4
1117e568061Sespielibjava/libltdl/configure: libjava/libltdl/configure.in libjava/libltdl/aclocal.m4
1127e568061Sespielibjava/libltdl/stamp-h.in: libjava/libltdl/configure.in libjava/libltdl/aclocal.m4 libjava/libltdl/acconfig.h
1137e568061Sespie# Top level
1147e568061SespieMakefile.in: Makefile.tpl Makefile.def
1157e568061SespieEOF
1167e568061Sespie}
1177e568061Sespie
1187e568061Sespie
1197e568061Sespie# This function touches generated files such that the ``end'' user does
1207e568061Sespie# not have to rebuild them.
1217e568061Sespietouch_files () {
1227e568061Sespie    rm -f Makefile.$$
1237e568061Sespie    echo 'all: \' > Makefile.$$
1247e568061Sespie    files_and_dependencies | sed 's, .*, \\,' >> Makefile.$$
1257e568061Sespie    echo '; @true' >> Makefile.$$
1267e568061Sespie    files_and_dependencies | sed 's, ,: ,' >> Makefile.$$
1277e568061Sespie    files_and_dependencies | sed 's, .*, \\,' >> Makefile.$$
1287e568061Sespie    echo ':' >> Makefile.$$
1297e568061Sespie    echo '	@for f in $? $@; do test -f $$f || exit 0; done; \' >> Makefile.$$
1307e568061Sespie    echo '	echo Touching $@...; \' >> Makefile.$$
1317e568061Sespie    echo '	echo Touching $@... 1>&2; \' >> Makefile.$$
1327e568061Sespie    echo '	touch $@' >> Makefile.$$
1337e568061Sespie    files_and_dependencies | sed 's,[^ ]* ,,;s,$, :,' >> Makefile.$$
1347e568061Sespie    while ${MAKE-make} -s -f Makefile.$$ all | grep . > /dev/null; do
1357e568061Sespie      sleep 1
1367e568061Sespie    done 2>&1
1377e568061Sespie    rm -f Makefile.$$
1387e568061Sespie}
1397e568061Sespie
1407e568061Sespie
1417e568061Sespie# Whenever we update the tree or install a patch, we may be modifying
1427e568061Sespie# this script.  By re-execing it, we ensure that the appropriate
1437e568061Sespie# dependencies and rules will be used.
1447e568061Sespietouch_files_reexec () {
1457e568061Sespie    echo "Adjusting file timestamps"
1467e568061Sespie    exec ${CONFIG_SHELL-/bin/sh} $self --touch
1477e568061Sespie}
1487e568061Sespie
1497e568061Sespie# This functions applies a patch to an existing tree.
1507e568061Sespieapply_patch () {
1517e568061Sespie    if [ -f $1 ]; then
1527e568061Sespie	echo "Applying patch file $1"
1537e568061Sespie	case "$1" in
1547e568061Sespie	*gz)
1557e568061Sespie	    gzip -d -c $1 | patch -p1 ;;
1567e568061Sespie	*bz2)
1577e568061Sespie	    bzip2 -d -c $1 | patch -p1 ;;
1587e568061Sespie	*)
1597e568061Sespie	    cat $1 | patch -p1 ;;
1607e568061Sespie	esac
1617e568061Sespie    fi
1627e568061Sespie    touch_files_reexec
1637e568061Sespie}
1647e568061Sespie
1657e568061Sespie# Check whether this indeed looks like a local tree.
1667e568061Sespieif [ ! -f gcc/version.c ]; then
1677e568061Sespie    echo "This does not seem to be a GCC tree!"
1687e568061Sespie    exit
1697e568061Sespiefi
1707e568061Sespie
1717e568061Sespiecase "$1" in
1727e568061Sespie# First of all, check whether we are going to process a patch.
1737e568061Sespie--patch)
1747e568061Sespie    if test "$#" != 2; then
1757e568061Sespie        echo "$1" expects only one argument >&2
1767e568061Sespie	exit 1
1777e568061Sespie    fi
1787e568061Sespie    apply_patch "${2}"
1797e568061Sespie    exit $?
1807e568061Sespie    ;;
1817e568061Sespie
1827e568061Sespie--touch)
1837e568061Sespie    if test "$#" != 1; then
1847e568061Sespie        echo "$1" does not expect any argument >&2
1857e568061Sespie	exit 1
1867e568061Sespie    fi
1877e568061Sespie    touch_files
1887e568061Sespie    exit $?
1897e568061Sespie    ;;
1907e568061Sespie
1917e568061Sespie--list)
1927e568061Sespie    if test "$#" != 1; then
1937e568061Sespie        echo "$1" does not expect any argument >&2
1947e568061Sespie	exit 1
1957e568061Sespie    fi
1967e568061Sespie    files_and_dependencies | sed 's/ /: /'
1977e568061Sespie    exit $?
1987e568061Sespie    ;;
1997e568061Sespie
2007e568061Sespie--help)
2017e568061Sespie    sed -e '1,2d' -e '/^UPDATE_OPTIONS=/{i\
2027e568061Sespie\
2037e568061Sespie
2047e568061Sespiep
2057e568061Sespie}' \
2067e568061Sespie	-e '/^$/,$d' -e 's/#//' -e 's/^ //' < $0
2077e568061Sespie    exit $?
2087e568061Sespie    ;;
2097e568061Sespie
2107e568061Sespieesac
2117e568061Sespie
2127e568061Sespie# Check whether this indeed looks like a local CVS tree.
2137e568061Sespieif [ ! -d CVS ]; then
2147e568061Sespie    echo "This does not seem to be a GCC CVS tree!"
2157e568061Sespie    exit
2167e568061Sespiefi
2177e568061Sespie
2187e568061Sespie# Check command-line options
2197e568061Sespieif [ x"${1}"x = x"--nostdflags"x ]; then
2207e568061Sespie    shift
2217e568061Sespieelse
2227e568061Sespie    set -- $UPDATE_OPTIONS ${1+"$@"}
2237e568061Sespiefi
2247e568061Sespie
2257e568061Sespieecho "Updating CVS tree"
2267e568061Sespiecvs -q update ${1+"$@"}
2277e568061Sespieif [ $? -ne 0 ]; then
2287e568061Sespie    (touch_files_reexec)
2297e568061Sespie    echo "CVS update of full tree failed." >&2
2307e568061Sespie    exit 1
2317e568061Sespiefi
2327e568061Sespie
2337e568061Sespie{
2347e568061Sespie  date
2357e568061Sespie  TZ=UTC date
2367e568061Sespie} > LAST_UPDATED
2377e568061Sespietouch_files_reexec
238