OSDN Git Service

libgo: Always use AM_LDFLAGS when linking libgo.la.
[pf3gnuchains/gcc-fork.git] / libgo / merge.sh
1 #!/bin/sh
2
3 # Copyright 2009 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
6
7 # This script merges changes from the master copy of the Go library
8 # into the libgo library.  This does the easy stuff; the hard stuff is
9 # left to the user.
10
11 # The file MERGE should hold the Mercurial revision number of the last
12 # revision which was merged into these sources.  Given that, and given
13 # the current sources, we can run the usual diff3 algorithm to merge
14 # all changes into our sources.
15
16 set -e
17
18 TMPDIR=${TMPDIR:-/tmp}
19
20 OLDDIR=${TMPDIR}/libgo-merge-old
21 NEWDIR=${TMPDIR}/libgo-merge-new
22
23 if ! test -f MERGE; then
24   echo 1>&2 "merge.sh: must be run in libgo source directory"
25   exit 1
26 fi
27
28 if test $# -ne 1; then
29   echo 1>&2 "merge.sh: Usage: merge.sh mercurial-repository"
30   exit 1
31 fi
32
33 repository=$1
34
35 merge_rev=`sed 1q MERGE`
36
37 rm -rf ${OLDDIR}
38 hg clone -r ${merge_rev} ${repository} ${OLDDIR}
39
40 rm -rf ${NEWDIR}
41 hg clone ${repository} ${NEWDIR}
42
43 new_rev=`cd ${NEWDIR} && hg log | sed 1q | sed -e 's/.*://'`
44
45 merge() {
46   name=$1
47   old=$2
48   new=$3
49   libgo=$4
50   if ! test -f ${new}; then
51     # The file does not exist in the new version.
52     if ! test -f ${old}; then
53       echo 1>&2 "merge.sh internal error no files $old $new"
54       exit 1
55     fi
56     if ! test -f ${libgo}; then
57       # File removed in new version and libgo.
58       :;
59     else
60       echo "merge.sh: ${name}: REMOVED"
61       rm -f ${libgo}
62       hg rm ${libgo}
63     fi
64   elif test -f ${old}; then
65     # The file exists in the old version.
66     if ! test -f ${libgo}; then
67       echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
68       continue
69     fi
70     if cmp -s ${old} ${libgo}; then
71       # The libgo file is unchanged from the old version.
72       if cmp -s ${new} ${libgo}; then
73         # File is unchanged from old to new version.
74         continue
75       fi
76       # Update file in libgo.
77       echo "merge.sh: $name: updating"
78       cp ${new} ${libgo}
79     else
80       # The libgo file has local changes.
81       set +e
82       diff3 -m -E ${libgo} ${old} ${new} > ${libgo}.tmp
83       status=$?
84       set -e
85       case $status in
86       0)
87         echo "merge.sh: $name: updating"
88         mv ${libgo}.tmp ${libgo}
89         ;;
90       1)
91         echo "merge.sh: $name: CONFLICTS"
92         mv ${libgo}.tmp ${libgo}
93         hg resolve -u ${libgo}
94         ;;
95       *)
96         echo 1>&2 "merge.sh: $name: diff3 failure"
97         exit 1
98         ;;
99       esac
100     fi
101   else
102     # The file does not exist in the old version.
103     if test -f ${libgo}; then
104       if ! cmp -s ${new} ${libgo}; then
105         echo 1>&2 "merge.sh: $name: IN NEW AND LIBGO BUT NOT OLD"
106       fi
107     else
108       echo "merge.sh: $name: NEW"
109       dir=`dirname ${libgo}`
110       if ! test -d ${dir}; then
111         mkdir -p ${dir}
112       fi
113       cp ${new} ${libgo}
114       hg add ${libgo}
115     fi
116   fi
117 }
118
119 (cd ${NEWDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
120   if test `dirname $f` = "./syscall"; then
121     continue
122   fi
123   oldfile=${OLDDIR}/src/pkg/$f
124   newfile=${NEWDIR}/src/pkg/$f
125   libgofile=go/$f
126   merge $f ${oldfile} ${newfile} ${libgofile}
127 done
128
129 (cd ${NEWDIR}/src/pkg && find . -name testdata -print) | while read d; do
130   oldtd=${OLDDIR}/src/pkg/$d
131   newtd=${NEWDIR}/src/pkg/$d
132   libgotd=go/$d
133   if ! test -d ${oldtd}; then
134     continue
135   fi
136   (cd ${oldtd} && hg status -A .) | while read f; do
137     if test "`basename $f`" = ".hgignore"; then
138       continue
139     fi
140     f=`echo $f | sed -e 's/^..//'`
141     name=$d/$f
142     oldfile=${oldtd}/$f
143     newfile=${newtd}/$f
144     libgofile=${libgotd}/$f
145     merge ${name} ${oldfile} ${newfile} ${libgofile}
146   done
147 done
148
149 runtime="goc2c.c mcache.c mcentral.c mfinal.c mfixalloc.c mgc0.c mheap.c msize.c malloc.h malloc.goc mprof.goc"
150 for f in $runtime; do
151   oldfile=${OLDDIR}/src/pkg/runtime/$f
152   newfile=${NEWDIR}/src/pkg/runtime/$f
153   libgofile=runtime/$f
154   merge $f ${oldfile} ${newfile} ${libgofile}
155 done
156
157 (cd ${OLDDIR}/src/pkg && find . -name '*.go' -print) | while read f; do
158   oldfile=${OLDDIR}/src/pkg/$f
159   newfile=${NEWDIR}/src/pkg/$f
160   libgofile=go/$f
161   if test -f ${newfile}; then
162     continue
163   fi
164   if ! test -f ${libgofile}; then
165     continue
166   fi
167   echo "merge.sh: ${libgofile}: REMOVED"
168   rm -f ${libgofile}
169   hg rm ${libgofile}
170 done
171
172 (echo ${new_rev}; sed -ne '2,$p' MERGE) > MERGE.tmp
173 mv MERGE.tmp MERGE