+# We can't 'make boot' in libraries until stage1 is built
+ifeq "$(BootingFromHc)" "YES"
+SUBDIRS_BUILD = gmp includes rts compat compiler docs utils driver
+else
+SUBDIRS_BUILD = gmp includes compat utils driver docs compiler rts
+endif
+
+SUBDIRS = gmp includes compat utils driver docs rts libraries compiler
+
+# Sanity check that all the boot libraries are in the tree, to catch
+# failure to run darcs-all.
+check-packages :
+ @for d in `cat libraries/boot-packages`; do \
+ if test ! -d libraries/$$d; then \
+ echo "Looks like you're missing libraries/$$d,"; \
+ echo "maybe you haven't done './darcs-all get'?"; \
+ exit 1; \
+ fi \
+ done
+ @if test ! -e libraries/base/configure; then \
+ echo "Looks like you're missing base's configure script."; \
+ echo "Did you run 'sh boot' at the top level?"; \
+ exit 1; \
+ fi
+
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(WhatGccIsCalled)" ""
+GCC_LIB_DEP = stamp.inplace-gcc-lib
+endif
+endif
+
+stage1 : $(GCC_LIB_DEP) check-packages
+ $(MAKE) -C utils/mkdependC boot
+ @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
+ for i in $(SUBDIRS_BUILD); do \
+ echo "------------------------------------------------------------------------"; \
+ echo "== $(MAKE) boot $(MFLAGS);"; \
+ echo " in $(shell pwd)/$$i"; \
+ echo "------------------------------------------------------------------------"; \
+ $(MAKE) --no-print-directory -C $$i $(MFLAGS) boot; \
+ if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
+ done; \
+ for i in $(SUBDIRS_BUILD); do \
+ echo "------------------------------------------------------------------------"; \
+ echo "== $(MAKE) all $(MFLAGS);"; \
+ echo " in $(shell pwd)/$$i"; \
+ echo "------------------------------------------------------------------------"; \
+ $(MAKE) --no-print-directory -C $$i $(MFLAGS) all; \
+ if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
+ done
+ $(MAKE) -C libraries boot
+ $(MAKE) -C libraries all
+
+stage2 : check-packages
+ $(MAKE) -C compiler boot stage=2
+ $(MAKE) -C compiler stage=2
+
+stage3 : check-packages
+ $(MAKE) -C compiler boot stage=3
+ $(MAKE) -C compiler stage=3
+
+bootstrap : bootstrap2
+
+bootstrap2 : stage1
+ $(MAKE) stage2
+
+bootstrap3 : bootstrap2
+ $(MAKE) stage3
+
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(WhatGccIsCalled)" ""
+all :: stamp.inplace-gcc-lib
+
+.PHONY: stamp.inplace-gcc-lib
+
+# This is a hack to make Cabal able to find ld when we run tests with
+# the inplace ghc. We should probably install all the gcc stuff in our
+# tree somewhere, and then have install copy it from there rather than
+# from the filesystem.
+stamp.inplace-gcc-lib:
+ $(RM) -r compiler/gcc-lib
+ mkdir compiler/gcc-lib
+ cp $(GccDir)ld.exe compiler/gcc-lib
+ touch $@
+
+clean ::
+ $(RM) -r compiler/gcc-lib
+ $(RM) -f inplace-gcc-lib
+endif
+endif
+
+all :: bootstrap
+
+# -----------------------------------------------------------------------------
+# Installing
+
+# We want to install the stage 2 bootstrapped compiler by default, but we let
+# the user override this by saying 'make install stage=1', for example.
+ifeq "$(stage)" ""
+INSTALL_STAGE = stage=2
+else
+INSTALL_STAGE =
+endif
+
+# Same as default rule, but we pass $(INSTALL_STAGE) to $(MAKE) too
+install :: check-packages
+ @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
+ for i in $(SUBDIRS); do \
+ echo "------------------------------------------------------------------------"; \
+ echo "== $(MAKE) $@ $(MFLAGS);"; \
+ echo " in $(shell pwd)/$$i"; \
+ echo "------------------------------------------------------------------------"; \
+ $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
+ if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
+ done
+
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+# These files need to be in the InstallShield
+# INSTALL_DATAS rather than INSTALL_DOCS is used so these files go
+# in the top-level directory of the distribution
+INSTALL_DATAS += ANNOUNCE LICENSE README
+endif
+
+# If installing on Windows with MinGW32, copy the gcc compiler, headers and libs
+# and the perl interpreter and dll into the GHC prefix directory.
+# Gcc and Perl source locations derived from configuration data.
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifneq "$(WhatGccIsCalled)" ""
+install ::
+ -mkdir $(prefix)/gcc-lib
+ -mkdir $(prefix)/include
+ -mkdir $(prefix)/include/mingw
+ -cp -rp $(GccDir)../include/* $(prefix)/include/mingw
+ -cp -rp $(GccDir)../lib/gcc-lib/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
+ -cp -rp $(GccDir)../lib/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
+ -cp -rp $(GccDir)../libexec/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
+ -cp $(GccDir)../lib/*.* $(prefix)/gcc-lib
+ -cp $(GccDir)gcc.exe $(prefix)
+ -cp $(GccDir)as.exe $(prefix)/gcc-lib
+ -cp $(GccDir)ld.exe $(prefix)/gcc-lib
+ -cp $(GccDir)dllwrap.exe $(prefix)/gcc-lib
+ -cp $(GccDir)dlltool.exe $(prefix)/gcc-lib
+ -cp $(GhcDir)../perl.exe $(prefix)
+ -cp $(GhcDir)../perl56.dll $(prefix)
+endif
+endif
+
+# Install gcc-extra-opts
+install ::
+ $(INSTALL_DIR) $(DESTDIR)$(libdir)
+ $(INSTALL_DATA) $(INSTALL_OPTS) extra-gcc-opts $(DESTDIR)$(libdir)
+
+install-docs ::
+ @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
+ for i in $(SUBDIRS); do \
+ echo "------------------------------------------------------------------------"; \
+ echo "== $(MAKE) $@ $(MFLAGS);"; \
+ echo " in $(shell pwd)/$$i"; \
+ echo "------------------------------------------------------------------------"; \
+ $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
+ if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
+ done
+
+# -----------------------------------------------------------------------------