Don't require Parser.y in a source dist
[ghc-hetmet.git] / compiler / Makefile
index 6066385..d64732a 100644 (file)
@@ -55,33 +55,54 @@ stage2 ::
 stage3 ::
        $(MAKE) stage=3
 
+ifeq "$(CLEAN_ALL_STAGES)" "YES"
 clean distclean::
-       -$(CABAL) clean --distpref dist-stage1
-       -$(CABAL) clean --distpref dist-stage2
-       $(RM) -f Makefile-stage1
-       $(RM) -f Makefile-stage2
        $(RM) -f prelude/primops.txt
        $(RM) -f $(PRIMOP_BITS)
        $(RM) -f $(CONFIG_HS)
        $(RM) -f parser/Parser.y
+       $(RM) -rf stage1 stage2plus
+       $(RM) -f $(STAGE3_PACKAGE_CONF)
+endif
+
+ifeq "$(CLEAN_ALL_STAGES)" "YES"
+clean distclean:: clean.stage.1 clean.stage.2 clean.stage.3
+else
+clean distclean:: clean.stage.$(stage)
+endif
+
+ifeq "$(CLEAN_ALL_STAGES)" "YES"
+distclean::
+       $(RM) -f ghc.cabal
+endif
+
+clean.stage.%:
+       $(RM) -f Makefile-stage$*
+# This is a bit naughty. We ought to use:
+#      -$(CABAL) clean --distpref dist-stage$*
+# but that won't work if the Cabal file (a generated file) doesn't
+# exist. So we do this instead:
+       $(RM) -rf dist-stage$*
 
 CONFIGURE_FLAGS_STAGE1 += --flags=stage1
 CONFIGURE_FLAGS_STAGE2 += --flags=-stage1
 
-CONFIGURE_FLAGS_STAGE1 += --flags=-ghci
+ifeq "$(GhcWithNativeCodeGen)" "YES"
+CONFIGURE_FLAGS_STAGE1 += --flags=ncg
+CONFIGURE_FLAGS_STAGE2 += --flags=ncg
+endif
 
 ifeq "$(GhcWithInterpreter)" "YES"
 CONFIGURE_FLAGS_STAGE2 += --flags=ghci
 
+ifeq "$(BuildSharedLibs)" "YES"
+CONFIGURE_FLAGS_STAGE2 += --enable-shared
 # If we are going to use dynamic libraries instead of .o files for ghci,
 # we will need to always retain CAFs in the compiler.
 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
 # function which sets the keepCAFs flag for the RTS before any Haskell
 # code is run.
-ifeq "$(GhcBuildDylibs)" "YES"
 CONFIGURE_FLAGS_STAGE2 += --flags=dynlibs
-else
-CONFIGURE_FLAGS_STAGE2 += --flags=-dynlibs
 endif
 
 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
@@ -97,31 +118,17 @@ ifeq "$(GhciWithDebugger)" "YES"
 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-DDEBUGGER
 endif
 
-# Enable editline if either:
-#   - we're building stage 1 and $(GhcHasEditline)="YES"
+# Enable editline if:
 #   - we're building stage 2/3, and we have built the editline package
 #
 # But we don't enable editline on Windows, as Windows terminals have
 # editline-like support builtin.
 #
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-CONFIGURE_FLAGS_STAGE1 += --flags=-editline
-CONFIGURE_FLAGS_STAGE2 += --flags=-editline
-else
-ifeq "$(GhcHasEditline)" "YES"
-CONFIGURE_FLAGS_STAGE1 += --flags=editline
-else
-CONFIGURE_FLAGS_STAGE1 += --flags=-editline
-endif
+ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
 ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
 CONFIGURE_FLAGS_STAGE2 += --flags=editline
-else
-CONFIGURE_FLAGS_STAGE2 += --flags=-editline
 endif
 endif
-
-else
-CONFIGURE_FLAGS_STAGE2 += --flags=-ghci
 endif
 
 ifeq "$(GhcWithNativeCodeGen)" "NO"
@@ -131,7 +138,7 @@ COMMON_CONFIGURE_FLAGS += --ghc-option=-DOMIT_NATIVE_CODEGEN
 endif
 
 ifeq "$(TargetOS_CPP)" "openbsd"
-COMMON_CONFIGURE_FLAGS += --ld-options="-Xlinker -E"
+COMMON_CONFIGURE_FLAGS += --ld-options=-E
 endif
 
 ifeq "$(GhcUnregisterised)" "NO"
@@ -141,6 +148,24 @@ COMMON_CONFIGURE_FLAGS += --ld-option=-Wl,--relax
 endif
 endif
 
+# We need to turn on profiling either if we have been asked to
+# (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
+# profiling enabled (GhcProfiled = YES).
+ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
+CONFIGURE_FLAGS_STAGE2 += --enable-library-profiling
+# And if we're profiling GHC then we want lots of SCCs.
+# We also don't want to waste time building the non-profiling library,
+# either normally or for ghci. Unfortunately this means that we have to
+# tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
+# exist.
+ifeq "$(GhcProfiled)" "YES"
+CONFIGURE_FLAGS_STAGE2 += --ghc-option=-auto-all
+CONFIGURE_FLAGS_STAGE2 += --disable-library-vanilla
+CONFIGURE_FLAGS_STAGE2 += --disable-library-for-ghci
+CONFIGURE_FLAGS_STAGE2 += --ghc-pkg-option=--force
+endif
+endif
+
 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 # The #include is vital for the via-C route with older compilers, else the C
 # compiler doesn't realise that the stcall foreign imports are indeed
@@ -164,7 +189,14 @@ CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
 CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
 CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
 
-boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) parser/Parser.y
+# In a source dist we don't need to worry about Parser.y(.pp) as we have
+# the .hs file pre-generated
+ifneq "$(wildcard parser/Parser.y.pp)" ""
+PARSER_Y = parser/Parser.y
+endif
+
+boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) $(PARSER_Y)
+       test -f $(STAGE3_PACKAGE_CONF) || echo "[]" > $(STAGE3_PACKAGE_CONF)
        $(CABAL) configure --distpref dist-stage$* \
                           $(CONFIGURE_FLAGS_STAGE$*) \
                           $(INSTALL_DIRS_CONFIGURE_FLAGS) \
@@ -176,18 +208,15 @@ boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) parser/Parser.y
 build.stage.%:
        $(MAKE) -f Makefile-stage$* stage=$*
        $(CABAL) register  --distpref dist-stage$* --inplace
+       $(MAKE) -C ../ghc stage=$*
 
 doc.stage.%:
-       $(CABAL) haddock --distpref dist-stage$*
+       $(CABAL) haddock --distpref dist-stage$* \
+                        --haddock-option=--optghc=-DSTAGE=$* \
+                        --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
 
-# XXX We ought to actually install the (stage 2) library
 install:
-       @:
-
-stage_dirs :
-       $(MKDIRHIER) stage$(stage)
-
-boot :: stage_dirs
+       $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage2
 
 # -----------------------------------------------------------------------------
 # Create compiler configuration
@@ -299,7 +328,8 @@ endif
 
 PLATFORM_H = ghc_boot_platform.h
 
-stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
+stage1/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
+       $(MKDIRHIER) stage1
        @echo "Creating $@..."
        @$(RM) $@
        @echo "#ifndef __PLATFORM_H__"  >$@
@@ -345,7 +375,8 @@ endif
 # For stage2 and above, the BUILD platform is the HOST of stage1, and
 # the HOST platform is the TARGET of stage1.  The TARGET remains the same
 # (stage1 is the cross-compiler, not stage2).
-stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
+stage2plus/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
+       $(MKDIRHIER) stage2plus
        @echo "Creating $@..."
        @$(RM) $@
        @echo "#ifndef __PLATFORM_H__"  >$@
@@ -388,7 +419,11 @@ endif
        @echo "#endif /* __PLATFORM_H__ */"          >> $@
        @echo "Done."
 
-STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
+ifeq "$(stage)" "1"
+STAGE_PLATFORM_H = stage1/$(PLATFORM_H)
+else
+STAGE_PLATFORM_H = stage2plus/$(PLATFORM_H)
+endif
 
 boot :: $(STAGE_PLATFORM_H)
 
@@ -428,25 +463,24 @@ primop-primop-info.hs-incl: prelude/primops.txt
 primop-usage.hs-incl: prelude/primops.txt
        $(GENPRIMOP) --usage              < $< > $@
 
-# XXX:
+html:
+       $(MAKE) doc stage=2
+
+install-docs:
+       @:
+
 #-----------------------------------------------------------------------------
 # binary-dist
 #
-#binary-dist:
-#      $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler
-#      $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler/stage$(stage)
-#      echo "stage=$(stage)"                > $(BIN_DIST_DIR)/compiler/Makefile
-#      cat Makefile                        >> $(BIN_DIST_DIR)/compiler/Makefile
-#      $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/compiler/
-#      set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
-#      set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
-#ifneq "$(INSTALL_LIBS)" ""
-#      set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
-#endif
-#ifneq "$(INSTALL_PROGS)" ""
-#      set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
-#endif
-#ifneq "$(INSTALL_LIBEXECS)" ""
-#      set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
-#endif
+
+# Ideally we'd get these from the Cabal file's Install-Includes:
+BINDIST_EXTRAS += HsVersions.h
+ifeq "$(stage)" "1"
+BINDIST_EXTRAS += stage1/ghc_boot_platform.h
+else
+BINDIST_EXTRAS += stage2plus/ghc_boot_platform.h
+endif
+
+include $(TOP)/mk/bindist.mk
+LIB_DIST_DIR = dist-stage2