+@endif gcc
+
+# ---------------------
+# GCC bootstrap support
+# ---------------------
+
+# We track the current stage (the one in 'gcc') in the stage_current file.
+# stage_last instead tracks the stage that was built last. These targets
+# are dummy when toplevel bootstrap is not active.
+
+# While making host and target tools, symlinks to the final stage must be
+# there, so $(unstage) should be run at various points. To avoid excessive
+# recursive invocations of make, we "inline" them using a variable. These
+# must be referenced as ": $(MAKE) ; $(unstage)" rather than "$(unstage)"
+# to avoid warnings from the GNU Make job server.
+
+unstage = :
+stage = :
+current_stage = ""
+
+@if gcc-bootstrap
+unstage = if [ -f stage_last ]; then [ -f stage_current ] || $(MAKE) `cat stage_last`-start || exit 1; else :; fi
+stage = if [ -f stage_current ]; then $(MAKE) `cat stage_current`-end || exit 1; else :; fi
+current_stage = "`cat stage_current 2> /dev/null`"
+@endif gcc-bootstrap
+
+.PHONY: unstage stage
+unstage:
+ @: $(MAKE); $(unstage)
+stage:
+ @: $(MAKE); $(stage)
+
+# Disable commands for lean bootstrap.
+LEAN = false
+
+# We name the build directories for the various stages "stage1-gcc",
+# "stage2-gcc","stage3-gcc", etc.
+
+# Since the 'compare' process will fail (on debugging information) if any
+# directory names are different, we need to link the gcc directory for
+# the previous stage to a constant name ('prev-gcc'), and to make the name of
+# the build directories constant as well. For the latter, we use naked names
+# like 'gcc', because the scripts in that directory assume it. We use
+# mv on platforms where symlinks to directories do not work or are not
+# reliable.
+
+# 'touch' doesn't work right on some platforms.
+STAMP = echo timestamp >
+
+# We only want to compare .o files, so set this!
+objext = .o
+
+[+ FOR bootstrap-stage +]
+.PHONY: stage[+id+]-start stage[+id+]-end
+
+stage[+id+]-start::
+ @: $(MAKE); $(stage); \
+ echo stage[+id+] > stage_current ; \
+ echo stage[+id+] > stage_last; \
+ $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)[+
+ FOR host_modules +][+ IF bootstrap +]
+@if [+ module +]
+ @cd $(HOST_SUBDIR); [ -d stage[+id+]-[+module+] ] || \
+ mkdir stage[+id+]-[+module+]; \
+ mv stage[+id+]-[+module+] [+module+] [+ IF prev +] ; \
+ mv stage[+prev+]-[+module+] prev-[+module+] || test -f stage[+prev+]-lean [+ ENDIF prev +]
+@endif [+ module +][+ ENDIF bootstrap +][+ ENDFOR host_modules +]
+ @[ -d stage[+id+]-$(TARGET_SUBDIR) ] || \
+ mkdir stage[+id+]-$(TARGET_SUBDIR); \
+ mv stage[+id+]-$(TARGET_SUBDIR) $(TARGET_SUBDIR) [+ IF prev +] ; \
+ mv stage[+prev+]-$(TARGET_SUBDIR) prev-$(TARGET_SUBDIR) || test -f stage[+prev+]-lean [+ ENDIF prev +]
+
+stage[+id+]-end:: [+ FOR host_modules +][+ IF bootstrap +]
+@if [+ module +]
+ @if test -d $(HOST_SUBDIR)/[+module+] ; then \
+ cd $(HOST_SUBDIR); mv [+module+] stage[+id+]-[+module+] [+ IF prev +]; \
+ mv prev-[+module+] stage[+prev+]-[+module+] ; : [+ ENDIF prev +] ; \
+ fi
+@endif [+ module +][+ ENDIF bootstrap +][+ ENDFOR host_modules +]
+ @if test -d $(TARGET_SUBDIR) ; then \
+ mv $(TARGET_SUBDIR) stage[+id+]-$(TARGET_SUBDIR) [+ IF prev +] ; \
+ mv prev-$(TARGET_SUBDIR) stage[+prev+]-$(TARGET_SUBDIR) ; : [+ ENDIF prev +] ; \
+ fi
+ rm -f stage_current
+
+# Bubble a bugfix through all the stages up to stage [+id+]. They are
+# remade, but not reconfigured. The next stage (if any) will not be
+# reconfigured as well.
+.PHONY: stage[+id+]-bubble
+stage[+id+]-bubble:: [+ IF prev +]stage[+prev+]-bubble[+ ENDIF +]
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ if test -f stage[+id+]-lean [+
+ IF prev +]|| test -f stage[+prev+]-lean [+ ENDIF prev +] ; then \
+ echo Skipping rebuild of stage[+id+] ; \
+ else \
+ $(MAKE) stage[+id+]-start; \[+IF lean +]
+ if $(LEAN); then \
+ rm -rf stage[+lean+]-* ; \
+ $(STAMP) stage[+lean+]-lean ; \
+ fi; \[+ ENDIF lean +]
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) all-stage[+id+]; \
+ fi[+ IF compare-target +]
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) [+compare-target+][+ ENDIF compare-target +]
+
+.PHONY: all-stage[+id+] clean-stage[+id+]
+do-clean: clean-stage[+id+]
+
+# FIXME: Will not need to be conditional when toplevel bootstrap is the
+# only possibility, but now it conflicts with no-bootstrap rules
+@if gcc-bootstrap
+[+ IF compare-target +]
+[+compare-target+]:
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ if test -f stage[+prev+]-lean; then \
+ echo Cannot compare object files as stage [+prev+] was deleted. ; \
+ exit 0 ; \
+ fi; \
+ : $(MAKE); $(stage); \
+ rm -f .bad_compare ; \
+ echo Comparing stages [+prev+] and [+id+] ; \
+ cd stage[+id+]-gcc; \
+ files=`find . -name "*$(objext)" -print` ; \
+ cd .. ; \
+ for file in $${files} ; do \
+ f1=$$r/stage[+prev+]-gcc/$$file; f2=$$r/stage[+id+]-gcc/$$file; \
+ @do_compare@ > /dev/null 2>&1; \
+ if test $$? -eq 1; then \
+ case $$file in \
+ ./cc*-checksum$(objext) | ./libgcc/* ) \
+ echo warning: $$file differs ;; \
+ *) \
+ echo $$file differs >> .bad_compare ;; \
+ esac ; \
+ fi ; \
+ done ; \
+ if [ -f .bad_compare ]; then \
+ echo "Bootstrap comparison failure!"; \
+ cat .bad_compare; \
+ exit 1; \
+ else \
+ echo Comparison successful.; \
+ fi ; \
+ $(STAMP) [+compare-target+][+ IF prev +]
+ if $(LEAN); then \
+ rm -rf stage[+prev+]-*; \
+ $(STAMP) stage[+prev+]-lean; \
+ fi[+ ENDIF prev +]
+[+ ENDIF compare-target +]
+
+[+ IF bootstrap-target +]
+.PHONY: [+bootstrap-target+] [+bootstrap-target+]-lean
+[+bootstrap-target+]:
+ echo stage[+id+] > stage_final
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) stage[+id+]-bubble
+ @: $(MAKE); $(unstage)
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ $(MAKE) $(TARGET_FLAGS_TO_PASS) all-host all-target
+
+[+bootstrap-target+]-lean:
+ echo stage[+id+] > stage_final
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) LEAN=: stage[+id+]-bubble
+ @: $(MAKE); $(unstage)
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ $(MAKE) $(TARGET_FLAGS_TO_PASS) all-host all-target
+[+ ENDIF bootstrap-target +]
+
+# Rules to wipe a stage and all the following ones, also used for cleanstrap
+[+ IF prev +]distclean-stage[+prev+]:: distclean-stage[+id+] [+ ENDIF prev +]
+.PHONY: distclean-stage[+id+]
+distclean-stage[+id+]::
+ @: $(MAKE); $(stage)
+ rm -rf stage[+id+]-* [+
+ IF compare-target +][+compare-target+] [+ ENDIF compare-target +]
+
+[+ IF cleanstrap-target +]
+.PHONY: [+cleanstrap-target+]
+[+cleanstrap-target+]: distclean [+bootstrap-target+]
+[+ ENDIF cleanstrap-target +]
+@endif gcc-bootstrap
+
+[+ ENDFOR bootstrap-stage +]
+
+stageprofile-end::
+ $(MAKE) distclean-stagefeedback
+
+stagefeedback-start::
+ @r=`${PWD_COMMAND}`; export r; \
+ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+ for i in prev-*; do \
+ j=`echo $$i | sed s/^prev-//` ; \
+ cd $$r/$$i && \
+ { find . -type d | sort | sed 's,.*,$(SHELL) '"$$s"'/mkinstalldirs "../'$$j'/&",' | $(SHELL) ; } && \
+ { find . -name '*.*da' | sed 's,.*,$(LN) -f "&" "../'$$j'/&",' | $(SHELL) ; } ; \
+ done
+
+@if gcc-bootstrap
+do-distclean: distclean-stage1
+
+# Provide a GCC build when we're building target libraries. This does
+# not work as a dependency, just as the minimum necessary to avoid errors.
+stage_last:
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) stage1-bubble
+
+# Same as unstage, but not phony and defaulting to stage1-start. We place
+# it in the dependency so that for example `make -j3 all-gcc' works.
+stage_current:
+ @if test -f stage_last; then $(unstage); else $(MAKE) stage1-start; fi
+
+.PHONY: restrap
+restrap:
+ @: $(MAKE); $(stage)
+ rm -rf stage1-$(TARGET_SUBDIR) [+ FOR bootstrap-stage +][+ IF prev
+ +]stage[+id+]-* [+ ENDIF prev +][+ ENDFOR bootstrap-stage +]
+ $(MAKE) $(RECURSE_FLAGS_TO_PASS) all
+@endif gcc-bootstrap