1#!/bin/sh
2
3set -e
4
5#---------------------------------------------------------------------
6# This quick and dirty script assists in updating the C++ demangler
7# machinery in coregrind/m_demangle.
8# The script will check out
9# - old and new revisions of the C++ demangler related files from GCC's trunk
10# - m_demangle from valgrind's trunk.
11# It will assemble
12# - a patch file with local changes that were applied to the C++
13#   demangler to make it work within valgrind
14# - a directory new_m_demangle whose contents should be copied to
15#   m_demangle in valgrind trunk
16# The patch will *not* be applied automatically.
17#---------------------------------------------------------------------
18
19# You need to modify these revision numbers for your update.
20old_gcc_revision=r240068  # the revision of the previous update
21new_gcc_revision=r246502  # the revision for this update
22
23# Unless the organization of demangler related files has changed, no
24# changes below this line should be necessary.
25
26# Setup a temp directory
27DIR=/tmp/demangle
28
29rm -rf $DIR
30mkdir -p $DIR
31
32cd $DIR
33
34echo "Updating the demangler in $DIR"
35
36# 1) Check out files from old GCC revision
37echo "Checking out GCC files @ $old_gcc_revision"
38
39mkdir gcc-$old_gcc_revision
40cd    gcc-$old_gcc_revision
41svn co -$old_gcc_revision svn://gcc.gnu.org/svn/gcc/trunk/libiberty libiberty > /dev/null
42svn co -$old_gcc_revision svn://gcc.gnu.org/svn/gcc/trunk/include   include   > /dev/null
43rm -rf libiberty/.svn
44rm -rf include/.svn
45cd ..
46
47# 2) Assemble the ones we need in $DIR/$old_gcc_revision
48mkdir $old_gcc_revision
49cd    $old_gcc_revision
50cp    ../gcc-$old_gcc_revision/include/ansidecl.h .
51cp    ../gcc-$old_gcc_revision/include/demangle.h .
52cp    ../gcc-$old_gcc_revision/include/dyn-string.h .
53cp    ../gcc-$old_gcc_revision/include/safe-ctype.h .
54cp    ../gcc-$old_gcc_revision/libiberty/cp-demangle.c .
55cp    ../gcc-$old_gcc_revision/libiberty/cp-demangle.h .
56cp    ../gcc-$old_gcc_revision/libiberty/cplus-dem.c .
57cp    ../gcc-$old_gcc_revision/libiberty/dyn-string.c .
58cp    ../gcc-$old_gcc_revision/libiberty/d-demangle.c .
59cp    ../gcc-$old_gcc_revision/libiberty/rust-demangle.c .
60cp    ../gcc-$old_gcc_revision/libiberty/safe-ctype.c .
61cd ..
62
63# 3) Check out files from new GCC revision
64
65echo "Checking out GCC files @ $new_gcc_revision"
66mkdir gcc-$new_gcc_revision
67cd    gcc-$new_gcc_revision
68svn co -$new_gcc_revision svn://gcc.gnu.org/svn/gcc/trunk/libiberty libiberty > /dev/null
69svn co -$new_gcc_revision svn://gcc.gnu.org/svn/gcc/trunk/include   include   > /dev/null
70rm -rf libiberty/.svn
71rm -rf include/.svn
72cd ..
73
74# 4) Assemble the ones we need in $DIR/$new_gcc_revision
75
76mkdir $new_gcc_revision
77cd    $new_gcc_revision
78cp    ../gcc-$new_gcc_revision/include/ansidecl.h .
79cp    ../gcc-$new_gcc_revision/include/demangle.h .
80cp    ../gcc-$new_gcc_revision/include/dyn-string.h .
81cp    ../gcc-$new_gcc_revision/include/safe-ctype.h .
82cp    ../gcc-$new_gcc_revision/libiberty/cp-demangle.c .
83cp    ../gcc-$new_gcc_revision/libiberty/cp-demangle.h .
84cp    ../gcc-$new_gcc_revision/libiberty/cplus-dem.c .
85cp    ../gcc-$new_gcc_revision/libiberty/dyn-string.c .
86cp    ../gcc-$new_gcc_revision/libiberty/d-demangle.c .
87cp    ../gcc-$new_gcc_revision/libiberty/rust-demangle.c .
88cp    ../gcc-$new_gcc_revision/libiberty/safe-ctype.c .
89cd ..
90
91# 5) Check out valgrind coregrind/m_demangle into old_m_demangle
92echo "Checking out coregrind/m_demangle"
93svn co svn://svn.valgrind.org/valgrind/trunk/coregrind/m_demangle old_m_demangle > /dev/null
94rm -rf old_m_demangle/.svn
95
96# 6) Create new_m_demangle
97cp -rp old_m_demangle new_m_demangle
98cp -rp $new_gcc_revision/*.[ch] new_m_demangle
99
100# 7) Compare files from previous GCC revision against old_m_demangle
101#    (This gets us the changes we made to the demangler).
102echo "Creating patch"
103set +e
104diff -r -u $old_gcc_revision old_m_demangle > our-changes
105echo "Patch file 'our-changes' created"
106
107# 7) See how the patch would apply
108echo "Attempting to apply the patch (but not actualy doing it)."
109cd new_m_demangle
110patch --dry -p1 < ../our-changes
111