gcc_update 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #! /bin/sh
  2. #
  3. # Update a local Subversion, Git or Mercurial tree from the GCC
  4. # repository, with an emphasis on treating generated files correctly, so
  5. # that autoconf, gperf et al are not required for the ``end'' user.
  6. #
  7. # (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009,
  8. # 2010, 2011, 2012, 2013, 2014, 2015, 2017 Free Software Foundation
  9. # Originally by Gerald Pfeifer <gerald@pfeifer.com>, August 1998.
  10. #
  11. # This script is Free Software, and it can be copied, distributed and
  12. # modified as defined in the GNU General Public License. A copy of
  13. # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
  14. #
  15. #
  16. # By default all command-line options are passed to `svn update` or `hg/git
  17. # pull` in addition to $UPDATE_OPTIONS (defined below). If the first parameter
  18. # reads --nostdflags, $UPDATE_OPTIONS as well as this parameter itself
  19. # are omitted.
  20. #
  21. # If the first parameter reads --patch, the second parameter is considered
  22. # a patch file.
  23. #
  24. # If the first parameter is --touch, no svn operation will be performed,
  25. # only generated files that appear to be out of date in the local tree
  26. # will be touched.
  27. #
  28. # If the first parameter is --list, a list of the generated files and
  29. # their dependencies will be printed; --help prints this message.
  30. #
  31. # If the first parameter is --silent, this script prints nothing other
  32. # than error messages; the second parameter is then interpreted as above.
  33. #
  34. # Examples:
  35. #
  36. # contrib/gcc_update -r 8712
  37. # contrib/gcc_update --patch some-patch
  38. # contrib/gcc_update --touch
  39. # contrib/gcc_update --list
  40. # Default options used when updating (none).
  41. UPDATE_OPTIONS=""
  42. # Set the locale to C to make this script work for users with foreign
  43. # locale like e.g. French UTF-8.
  44. LANG=C
  45. LC_ALL=C
  46. export LANG LC_ALL
  47. ######## Anything below shouldn't be changed by regular users.
  48. # Arrange for the value of $0 to be available for functions
  49. self=$0
  50. # This function prints its arguments to standard output unless
  51. # "silent" is set.
  52. unset silent
  53. chat () {
  54. if [ -z "$silent" ]; then
  55. echo "$@"
  56. fi
  57. }
  58. # This function prints a list of all generated files, along with their
  59. # dependencies. Note that only one target is supported per line: the
  60. # colon is stripped from the output.
  61. files_and_dependencies () {
  62. sed -e 's/ *#.*//' -e '/^$/d' -e 's/://' <<\EOF
  63. # fixincludes
  64. fixincludes/configure: fixincludes/configure.ac fixincludes/aclocal.m4
  65. fixincludes/config.h.in: fixincludes/configure.ac fixincludes/aclocal.m4
  66. # intl library
  67. intl/plural.c: intl/plural.y
  68. intl/plural-config.h: intl/plural.y
  69. intl/configure: intl/configure.ac intl/aclocal.m4
  70. intl/config.h.in: intl/configure.ac intl/aclocal.m4
  71. # Now, proceed to gcc automatically generated files
  72. gcc/configure: gcc/configure.ac
  73. gcc/cstamp-h.in: gcc/configure.ac
  74. gcc/config.in: gcc/cstamp-h.in
  75. gcc/fixinc/fixincl.x: gcc/fixinc/fixincl.tpl gcc/fixinc/inclhack.def
  76. gcc/config/aarch64/aarch64-tune.md: gcc/config/aarch64/aarch64-cores.def gcc/config/aarch64/gentune.sh
  77. gcc/config/arm/arm-tune.md: gcc/config/arm/arm-cpus.in gcc/config/arm/parsecpu.awk
  78. gcc/config/arm/arm-tables.opt: gcc/config/arm/arm-cpus.in gcc/config/arm/parsecpu.awk
  79. gcc/config/c6x/c6x-tables.opt: gcc/config/c6x/c6x-isas.def gcc/config/c6x/genopt.sh
  80. gcc/config/c6x/c6x-sched.md: gcc/config/c6x/c6x-sched.md.in gcc/config/c6x/gensched.sh
  81. gcc/config/c6x/c6x-mult.md: gcc/config/c6x/c6x-mult.md.in gcc/config/c6x/genmult.sh
  82. gcc/config/loongarch/loongarch-str.h: gcc/config/loongarch/genopts/genstr.sh gcc/config/loongarch/genopts/loongarch-strings
  83. gcc/config/loongarch/loongarch.opt: gcc/config/loongarch/genopts/genstr.sh gcc/config/loongarch/genopts/loongarch.opt.in
  84. gcc/config/m68k/m68k-tables.opt: gcc/config/m68k/m68k-devices.def gcc/config/m68k/m68k-isas.def gcc/config/m68k/m68k-microarchs.def gcc/config/m68k/genopt.sh
  85. gcc/config/mips/mips-tables.opt: gcc/config/mips/mips-cpus.def gcc/config/mips/genopt.sh
  86. gcc/config/rs6000/rs6000-tables.opt: gcc/config/rs6000/rs6000-cpus.def gcc/config/rs6000/genopt.sh
  87. gcc/config/rs6000/fusion.md: gcc/config/rs6000/genfusion.pl
  88. gcc/config/tilegx/mul-tables.cc: gcc/config/tilepro/gen-mul-tables.cc
  89. gcc/config/tilepro/mul-tables.cc: gcc/config/tilepro/gen-mul-tables.cc
  90. # And then, language-specific files
  91. gcc/cp/cfns.h: gcc/cp/cfns.gperf
  92. # testsuite
  93. # Without this, _Pragma3.c can have a false negative.
  94. gcc/testsuite/gcc.dg/cpp/_Pragma3.c: gcc/testsuite/gcc.dg/cpp/mi1c.h
  95. # Similarly, without this, you will see:
  96. # direct2s.c:35: warning: current file is older than direct2.c
  97. gcc/testsuite/gcc.dg/cpp/direct2s.c: gcc/testsuite/gcc.dg/cpp/direct2.c
  98. # lto-plugin
  99. lto-plugin/configure: lto-plugin/configure.ac lto-plugin/aclocal.m4
  100. lto-plugin/Makefile.in: lto-plugin/Makefile.am lto-plugin/aclocal.m4
  101. # tools
  102. c++tools/configure: c++tools/configure.ac
  103. c++tools/config.h.in: c++tools/configure.ac
  104. # And libraries, at last
  105. libbanshee/configure: libbanshee/configure.ac
  106. libmudflap/configure: libmudflap/configure.ac
  107. libobjc/configure: libobjc/configure.ac
  108. zlib/aclocal.m4: zlib/configure.ac zlib/acinclude.m4
  109. zlib/Makefile.in: zlib/Makefile.am zlib/configure.ac zlib/aclocal.m4
  110. zlib/configure: zlib/configure.ac zlib/aclocal.m4
  111. fastjar/aclocal.m4: fastjar/configure.ac
  112. fastjar/Makefile.in: fastjar/Makefile.am fastjar/configure.ac fastjar/aclocal.m4
  113. fastjar/configure: fastjar/configure.ac fastjar/aclocal.m4
  114. boehm-gc/aclocal.m4: boehm-gc/configure.ac
  115. boehm-gc/Makefile.in: boehm-gc/Makefile.am boehm-gc/configure.ac boehm-gc/aclocal.m4
  116. boehm-gc/configure: boehm-gc/configure.ac boehm-gc/aclocal.m4
  117. libada/configure: libada/configure.ac
  118. libffi/aclocal.m4: libffi/configure.ac libffi/acinclude.m4
  119. libffi/Makefile.in: libffi/Makefile.am libffi/configure.ac libffi/aclocal.m4
  120. libffi/configure: libffi/configure.ac libffi/aclocal.m4
  121. libffi/fficonfig.h.in: libffi/configure.ac libffi/aclocal.m4
  122. libgfortran/aclocal.m4: libgfortran/configure.ac libgfortran/acinclude.m4
  123. libgfortran/Makefile.in: libgfortran/Makefile.am libgfortran/configure.ac libgfortran/aclocal.m4
  124. libquadmath/configure: libquadmath/configure.ac libquadmath/aclocal.m4
  125. libquadmath/aclocal.m4: libquadmath/configure.ac libquadmath/acinclude.m4
  126. libquadmath/Makefile.in: libquadmath/Makefile.am libquadmath/configure.ac libgfortran/aclocal.m4
  127. libgfortran/configure: libgfortran/configure.ac libgfortran/aclocal.m4
  128. libcody/configure: libcody/configure.ac libcody/config.m4
  129. libcpp/aclocal.m4: libcpp/configure.ac
  130. libcpp/Makefile.in: libcpp/configure.ac libcpp/aclocal.m4
  131. libcpp/configure: libcpp/configure.ac libcpp/aclocal.m4
  132. libgomp/aclocal.m4: libgomp/configure.ac libgomp/acinclude.m4
  133. libgomp/Makefile.am: libgomp/plugin/Makefrag.am
  134. libgomp/Makefile.in: libgomp/Makefile.am libgomp/aclocal.m4
  135. libgomp/testsuite/Makefile.in: libgomp/testsuite/Makefile.am libgomp/aclocal.m4
  136. libgomp/configure.ac: libgomp/plugin/configfrag.ac
  137. libgomp/configure: libgomp/configure.ac libgomp/aclocal.m4
  138. libgomp/config.h.in: libgomp/configure.ac libgomp/aclocal.m4
  139. libitm/aclocal.m4: libitm/configure.ac libitm/acinclude.m4
  140. libitm/Makefile.in: libitm/Makefile.am libitm/aclocal.m4
  141. libitm/testsuite/Makefile.in: libitm/testsuite/Makefile.am libitm/aclocal.m4
  142. libitm/configure: libitm/configure.ac libitm/aclocal.m4
  143. libitm/config.h.in: libitm/configure.ac libitm/aclocal.m4
  144. libatomic/aclocal.m4: libatomic/configure.ac libatomic/acinclude.m4
  145. libatomic/Makefile.in: libatomic/Makefile.am libatomic/aclocal.m4
  146. libatomic/testsuite/Makefile.in: libatomic/testsuite/Makefile.am libatomic/aclocal.m4
  147. libatomic/configure: libatomic/configure.ac libatomic/aclocal.m4
  148. libatomic/auto-config.h.in: libatomic/configure.ac libatomic/aclocal.m4
  149. libsanitizer/aclocal.m4: libsanitizer/configure.ac libsanitizer/acinclude.m4
  150. libsanitizer/Makefile.in: libsanitizer/Makefile.am libsanitizer/aclocal.m4
  151. libsanitizer/configure: libsanitizer/configure.ac libsanitizer/aclocal.m4
  152. libsanitizer/asan/Makefile.in: libsanitizer/asan/Makefile.am libsanitizer/aclocal.m4
  153. libsanitizer/interception/Makefile.in: libsanitizer/interception/Makefile.am libsanitizer/aclocal.m4
  154. libsanitizer/sanitizer_common/Makefile.in: libsanitizer/sanitizer_common/Makefile.am libsanitizer/aclocal.m4
  155. libvtv/aclocal.m4: libvtv/configure.ac libvtv/acinclude.m4
  156. libvtv/Makefile.in: libvtv/Makefile.am libvtv/aclocal.m4
  157. libvtv/configure: libvtv/configure.ac libvtv/aclocal.m4
  158. liboffloadmic/aclocal.m4: liboffloadmic/configure.ac
  159. liboffloadmic/Makefile.in: liboffloadmic/Makefile.am
  160. liboffloadmic/configure: liboffloadmic/configure.ac
  161. liboffloadmic/plugin/aclocal.m4: liboffloadmic/plugin/configure.ac
  162. liboffloadmic/plugin/Makefile.in: liboffloadmic/plugin/Makefile.am
  163. liboffloadmic/plugin/configure: liboffloadmic/plugin/configure.ac
  164. libbacktrace/aclocal.m4: libbacktrace/configure.ac
  165. libbacktrace/Makefile.in: libbacktrace/Makefile.am libbacktrace/aclocal.m4
  166. libbacktrace/configure: libbacktrace/configure.ac libbacktrace/aclocal.m4
  167. libbacktrace/config.h.in: libbacktrace/configure.ac libbacktrace/aclocal.m4
  168. libphobos/Makefile.in: libphobos/Makefile.am libphobos/configure.ac libphobos/aclocal.m4
  169. libphobos/aclocal.m4: libphobos/configure.ac libphobos/acinclude.m4
  170. libphobos/config.h.in: libphobos/configure.ac libphobos/aclocal.m4
  171. libphobos/configure: libphobos/configure.ac libphobos/aclocal.m4
  172. libphobos/src/Makefile.in: libphobos/src/Makefile.am libphobos/aclocal.m4
  173. libphobos/testsuite/Makefile.in: libphobos/testsuite/Makefile.am libphobos/aclocal.m4
  174. # Top level
  175. Makefile.in: Makefile.tpl Makefile.def
  176. configure: configure.ac config/acx.m4
  177. EOF
  178. }
  179. # This function touches generated files such that the ``end'' user does
  180. # not have to rebuild them.
  181. touch_files () {
  182. rm -f Makefile.$$
  183. echo 'all: \' > Makefile.$$
  184. files_and_dependencies | sed 's, .*, \\,' >> Makefile.$$
  185. echo '; @true' >> Makefile.$$
  186. files_and_dependencies | sed 's, ,: ,' >> Makefile.$$
  187. files_and_dependencies | sed 's, .*, \\,' >> Makefile.$$
  188. echo ':' >> Makefile.$$
  189. echo ' @for f in $? $@; do test -f $$f || exit 0; done; \' >> Makefile.$$
  190. echo ' echo Touching $@...; \' >> Makefile.$$
  191. chat ' echo Touching $@... 1>&2; \' >> Makefile.$$
  192. echo ' touch $@' >> Makefile.$$
  193. files_and_dependencies | sed 's,[^ ]* ,,;s,$, :,' >> Makefile.$$
  194. # We would have to explicitly shut off the "Entering... Leaving..."
  195. # messages through "--no-print-directory" to handle the case when
  196. # we were called from a recursive invocation (i.e. "$(MAKE)" in a
  197. # Makefile, not just make). Passing only "-s" doesn't help then,
  198. # because make has helpfully added "-w" to MAKEFLAGS automatically.
  199. # Unfortunately we do not require GNU make other than for building
  200. # and testing, so let's just grep known text explicitly echoed by
  201. # the rule.
  202. while ${MAKE-make} -s -f Makefile.$$ all | grep Touching > /dev/null; do
  203. sleep 1
  204. done 2>&1
  205. rm -f Makefile.$$
  206. }
  207. # Whenever we update the tree or install a patch, we may be modifying
  208. # this script. By re-execing it, we ensure that the appropriate
  209. # dependencies and rules will be used.
  210. touch_files_reexec () {
  211. chat "Adjusting file timestamps"
  212. exec ${CONFIG_SHELL-/bin/sh} $self ${silent+"--silent"} --touch
  213. }
  214. # This functions applies a patch to an existing tree.
  215. apply_patch () {
  216. if [ -f "$1" ]; then
  217. echo "Applying patch file $1"
  218. case $1 in
  219. *gz)
  220. gzip -d -c "$1" | patch -p1 ;;
  221. *bz2)
  222. bzip2 -d -c "$1" | patch -p1 ;;
  223. *)
  224. patch -p1 < "$1";;
  225. esac
  226. fi
  227. touch_files_reexec
  228. }
  229. # Check whether this indeed looks like a local tree.
  230. if [ ! -f gcc/reload.cc ]; then
  231. echo "This does not seem to be a GCC tree!"
  232. exit
  233. fi
  234. case "$1" in
  235. --silent)
  236. silent=t
  237. shift
  238. ;;
  239. esac
  240. case "$1" in
  241. # First of all, check whether we are going to process a patch.
  242. --patch)
  243. if test "$#" != 2; then
  244. echo "$1" expects only one argument >&2
  245. exit 1
  246. fi
  247. apply_patch "${2}"
  248. exit $?
  249. ;;
  250. --touch)
  251. if test "$#" != 1; then
  252. echo "$1" does not expect any argument >&2
  253. exit 1
  254. fi
  255. touch_files
  256. exit $?
  257. ;;
  258. --list)
  259. if test "$#" != 1; then
  260. echo "$1" does not expect any argument >&2
  261. exit 1
  262. fi
  263. files_and_dependencies | sed 's/ /: /'
  264. exit $?
  265. ;;
  266. --help)
  267. sed -e '1,2d' -e '/^UPDATE_OPTIONS=/{i\
  268. \
  269. p
  270. }' \
  271. -e '/^$/,$d' -e 's/#//' -e 's/^ //' < $0
  272. exit $?
  273. ;;
  274. esac
  275. # Check for known version control systems.
  276. if [ -d .git ] || [ -f .git ]; then
  277. GCC_GIT=${GCC_GIT-${GIT-git}}
  278. vcs_type="git"
  279. elif [ -d .hg ]; then
  280. GCC_HG=${GCC_HG-${HG-hg}}
  281. vcs_type="hg"
  282. elif [ -d .svn ]; then
  283. GCC_SVN=${GCC_SVN-${SVN-svn}}
  284. vcs_type="svn"
  285. else
  286. echo "This does not seem to be a GCC GIT/HG/SVN tree!"
  287. exit
  288. fi
  289. # Check command-line options
  290. if [ x"${1}"x = x"--nostdflags"x ]; then
  291. shift
  292. else
  293. set -- $UPDATE_OPTIONS ${1+"$@"}
  294. fi
  295. case $vcs_type in
  296. git)
  297. chat "Updating GIT tree"
  298. $GCC_GIT diff --quiet --exit-code HEAD
  299. if [ $? -ne 0 ]; then
  300. echo "Attempting to update a dirty git tree!" >&2
  301. echo "Commit or stash your changes first and retry." >&2
  302. exit 1
  303. fi
  304. $GCC_GIT pull ${silent+-q} --rebase ${1+"$@"}
  305. if [ $? -ne 0 ]; then
  306. (touch_files_reexec)
  307. echo "git pull of full tree failed." >&2
  308. exit 1
  309. fi
  310. # Open-coded version of "git gcc-descr" from contrib/gcc-git-customization.sh
  311. revision=`$GCC_GIT log -n1 --pretty=tformat:%h`
  312. r=`$GCC_GIT describe --all --match 'basepoints/gcc-[0-9]*' HEAD \
  313. | sed -n 's,^\(tags/\)\?basepoints/gcc-\([0-9]\+\)-\([0-9]\+\)-g[0-9a-f]*$,r\2-\3,p;s,^\(tags/\)\?basepoints/gcc-\([0-9]\+\)$,r\2-0,p'`;
  314. if test -n $r; then
  315. o=`$GCC_GIT config --get gcc-config.upstream`;
  316. rr=`echo $r | sed -n 's,^r\([0-9]\+\)-[0-9]\+\(-g[0-9a-f]\+\)\?$,\1,p'`;
  317. if $GCC_GIT rev-parse --verify --quiet ${o:-origin}/releases/gcc-$rr >/dev/null; then
  318. m=releases/gcc-$rr;
  319. else
  320. m=master;
  321. fi;
  322. if $GCC_GIT merge-base --is-ancestor HEAD ${o:-origin}/$m; then
  323. revision=${r}-g${revision};
  324. fi
  325. fi
  326. branch=`$GCC_GIT name-rev --name-only HEAD || :`
  327. ;;
  328. hg)
  329. chat "Updating HG tree"
  330. # Add -q so untracked files aren't listed.
  331. if [ `$GCC_HG status -q | wc -l` -gt 0 ]; then
  332. echo "Attempting to update a dirty hg tree!" >&2
  333. echo "Commit or revert your changes first and retry." >&2
  334. exit 1
  335. fi
  336. # Check for mq extension. mq patches must be popped so tip has
  337. # been converted from the SVN tree.
  338. if [ -d .hg/patches ] && [ `$GCC_HG qapplied | wc -l` -gt 0 ]; then
  339. # FIXME: Perhaps pop queue instead? We could do that since we
  340. # know the tree is clean.
  341. echo "Attempting to update hg tree with mq patches applied!" >&2
  342. echo "Pop your patches first and retry." >&2
  343. exit 1
  344. fi
  345. # Update tree, but make sure to only pull the default branch.
  346. # Otherwise all branches in the upstream repo are added, even if
  347. # only a single one has been cloned.
  348. $GCC_HG pull ${silent+-q} -r`$GCC_HG branch` ${1+"$@"}
  349. if [ $? -ne 0 ]; then
  350. (touch_files_reexec)
  351. echo "hg pull of full tree failed." >&2
  352. exit 1
  353. fi
  354. # Update tree. Needs to be done separately from pull so
  355. # gcc_update -rREV works.
  356. $GCC_HG update ${silent+-q} ${1+"$@"}
  357. if [ $? -ne 0 ]; then
  358. (touch_files_reexec)
  359. echo "hg update of full tree failed." >&2
  360. exit 1
  361. fi
  362. # Extract SVN revision corresponding to parents, as stored by
  363. # hg convert. Before hg 1.4.3, there's no template keyword
  364. # corresponding to the extra: tag, so need to use hg log --debug
  365. # to extract the info.
  366. parents=`$GCC_HG parents --template '{rev}'`
  367. convert_revision=`$GCC_HG log --debug -r$parents | \
  368. sed -ne "/^extra:.*convert_revision=svn:/ {
  369. s%^[^/]*/%%
  370. p
  371. }"`
  372. revision=`echo $convert_revision | sed -e 's/.*@//'`
  373. branch=`echo $convert_revision | sed -e 's%branches/%%' -e 's/@.*//'`
  374. ;;
  375. svn)
  376. chat "Updating SVN tree"
  377. $GCC_SVN ${silent+-q} --non-interactive update ${1+"$@"}
  378. if [ $? -ne 0 ]; then
  379. (touch_files_reexec)
  380. echo "SVN update of full tree failed." >&2
  381. exit 1
  382. fi
  383. revision=`$GCC_SVN info | awk '/Revision:/ { print $2 }'`
  384. branch=`$GCC_SVN info | sed -ne "/^URL:/ {
  385. s,.*/trunk,trunk,
  386. s,.*/branches/,,
  387. s,.*/tags/,,
  388. p
  389. }"`
  390. ;;
  391. esac
  392. rm -f LAST_UPDATED gcc/REVISION
  393. {
  394. date
  395. echo "`TZ=UTC date` (revision $revision)"
  396. } > LAST_UPDATED
  397. echo "[$branch $revision]" > gcc/REVISION
  398. touch_files_reexec