Make ghc -dynamic imply -fPIC for C code
[ghc-hetmet.git] / ghc.mk
diff --git a/ghc.mk b/ghc.mk
index 329e76f..59b5ee8 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -1,3 +1,15 @@
+# -----------------------------------------------------------------------------
+#
+# (c) 2009 The University of Glasgow
+#
+# This file is part of the GHC build system.
+#
+# To understand how the build system works and how to modify it, see
+#      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
+#      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
+#
+# -----------------------------------------------------------------------------
+
 # ToDo List.
 #
 # Before we can merge the new build system into HEAD:
 #   * need to fix Cabal for new Windows layout, see
 #     Distribution/Simple/GHC.configureToolchain.
 #
-# As we merge the new build system into HEAD:
+# Once the new build system is in HEAD, and before 6.12:
 #
+#   * separate the logic of whether to do something from the test for
+#     existence of the tool to do it. For example, rather than checking
+#     if $DIR_DOCBOOK_XSL or $XSLTPROC is "", we should have a variable
+#     for controlling the building of the docs.
 #   * remove old Makefiles, add new stubs for building in subdirs
 #     * utils/hsc2hs/Makefile
 #     * utils/haddock/Makefile
-#     * mk/oldconfig.mk.in
-#
-# Once the new build system is in HEAD, and before 6.12:
-#
-#   * docbook PDFs, e.g. "dblatex -T db2latex users_guide.xml"
+#     * docs/Makefile
+#     * docs/docbook-cheat-sheet/Makefile
+#     * docs/ext-core/Makefile
+#     * docs/man/Makefile
+#     * docs/storage-mgmt/Makefile
+#     * docs/vh/Makefile
+#     * driver/Makefile
+#     * rts/dotnet/Makefile
+#     * utils/Makefile
 #   * GhcProfiled
 #   * optionally install stage3?
-#   * why does so much stuff get rebuilt after re-configuring?
 #   * shared libraries, way dyn
-#   * add pointers to wiki docs from the build system source
 #   * get HC bootstrapping working
 #   * add Makefiles for the rest of the utils/ programs that aren't built
 #     by default (need to exclude them from 'make all' too)
 #
 # Tickets we can now close, or fix and close:
 #
-#   * 912  build system doesn't have enough dependencies (it does now!)
-#   * 2744 check for presence of hsc2hs in ./configure
 #   * 2966 make sure --with-gcc does the right thing (#2966)
-#   * 3115 make ghc.cabal read-only
-#   * 2107 install the docs by default
 #   * 1693 make distclean
 #   * 2689 make maintainer-clean
-#   * 2619  bootstrapping using a newer GHC shouldn't fail
-#     for bogus reasons (picking the wrong version of the ghc package)
-#   * 2770 check which version of gcc we require
 #   * 3173 make install with DESTDIR
 
 # Possible cleanups:
 #     a state where the package database is out of date, and the build
 #     system doesn't know.
 
-# NOTES on how to debug:
-#   make --debug=b --debug=m  shows dependencies
-#   make -p                   prints all generated makefile rules and variables
-#   make show VALUE=VAR       prints the value of VAR
-#   $(warning stuff)          prints stuff when reading the makefile
-
-# BUILD ORDER
+# Approximate build order.
+#
+# The actual build order is defined by dependencies, and the phase
+# ordering used to ensure correct ordering of makefile-generation; see
+#    http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
 #
 #     * With bootstrapping compiler:
-#           o Build libraries/{hpc,extensible-exceptions,Cabal}
-#           o Build utils/ghc-pkg
 #           o Build utils/ghc-cabal
-#     * With bootstrapping compiler and ghc-cabal:
+#           o Build utils/ghc-pkg
 #           o Build utils/hsc2hs
-#           o Build libraries/hpc
-#           o Build compiler (stage 1)
 #     * For each package:
-#          o generate package-data.mk and inplace-pkg-info
+#          o configure, generate package-data.mk and inplace-pkg-info
 #           o register each package into inplace/lib/package.conf
-#           o generate .depend for each package
+#     * build libffi
+#     * With bootstrapping compiler:
+#          o Build libraries/{filepath,hpc,extensible-exceptions,Cabal}
+#           o Build compiler (stage 1)
 #     * With stage 1:
 #           o Build libraries/*
+#          o Build rts
 #           o Build utils/* (except haddock)
 #           o Build compiler (stage 2)
 #     * With stage 2:
 #           o Build utils/haddock
-#           o Build compiler (stage 3)
+#           o Build compiler (stage 3) (optional)
 #     * With haddock:
 #           o libraries/*
 #           o compiler
@@ -155,8 +164,6 @@ $(eval $(call clean-target,inplace,,inplace))
 # When we're just doing 'make clean' or 'make show', then we don't need
 # to build dependencies.
 
-NO_INCLUDE_DEPS = NO
-NO_INCLUDE_PKGDATA = NO
 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
 NO_INCLUDE_DEPS = YES
 NO_INCLUDE_PKGDATA = YES
@@ -298,15 +305,39 @@ PACKAGES += \
        syb \
        template-haskell \
        base3-compat \
-       Cabal
+       Cabal \
+       mtl \
+       utf8-string
+
+ifneq "$(Windows)" "YES"
+PACKAGES += terminfo
+endif
+
+PACKAGES += haskeline
+
+ifneq "$(wildcard libraries/dph)" ""
+PACKAGES += \
+       dph/dph-base \
+       dph/dph-prim-interface \
+       dph/dph-prim-seq \
+       dph/dph-prim-par \
+       dph/dph-seq \
+       dph/dph-par
+endif
 
 BOOT_PKGS = Cabal hpc extensible-exceptions
 
-# The actual .a files: needed for dependencies.
+# The actual .a and .so/.dll files: needed for dependencies.
 ALL_LIBS  = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
+ifeq "$(BuildSharedLibs)" "YES"
+ALL_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB))
+endif
 BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
 
-OTHER_LIBS = libffi/libHSffi.a libffi/HSffi.o
+OTHER_LIBS = libffi/libHSffi$(v_libsuf) libffi/HSffi.o
+ifeq "$(BuildSharedLibs)" "YES"
+OTHER_LIBS  += libffi/libHSffi$(dyn_libsuf)
+endif
 ifeq "$(HaveLibGmp)" "NO"
 OTHER_LIBS += gmp/libgmp.a
 endif
@@ -375,8 +406,8 @@ libraries/ghc-prim/GHC/Prim.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
 # -----------------------------------------------------------------------------
 # Include build instructions from all subdirs
 
-# See commentary in the top-level Makefile for why we divide the build
-# into phases.
+# For the rationale behind the build phases, see
+#   http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
 
 # Setting foo_dist_DISABLE=YES means "in directory foo, for build
 # "dist", just read the package-data.mk file, do not build anything".
@@ -447,6 +478,7 @@ endif
 
 BUILD_DIRS += \
    utils/haddock \
+   utils/haddock/doc \
    $(patsubst %, libraries/%, $(PACKAGES)) \
    compiler \
    $(GHC_HSC2HS_DIR) \
@@ -493,6 +525,9 @@ $(foreach lib,$(PACKAGES),$(eval \
   libraries/$(lib)_dist-install_DISABLE = YES))
 endif
 
+ifneq "$(wildcard libraries/dph)" ""
+include libraries/dph/ghc.mk
+endif
 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
 
 # We need -fno-warn-deprecated-flags to avoid failure with -Werror
@@ -677,13 +712,13 @@ install_packages: libffi/package.conf.install rts/package.conf.install
 
 $(eval $(call bindist,.,\
     LICENSE \
-    configure config.sub config.guess \
+    configure config.sub config.guess install-sh \
     extra-gcc-opts.in \
     Makefile \
     mk/config.mk.in \
     $(INPLACE_BIN)/mkdirhier \
     $(INPLACE_BIN)/ghc-cabal \
-    utils/pwd/pwd \
+    utils/ghc-pwd/ghc-pwd \
        $(BINDIST_WRAPPERS) \
        $(BINDIST_LIBS) \
        $(BINDIST_HI) \
@@ -703,14 +738,19 @@ $(eval $(call bindist,.,\
 binary-dist:
        $(RM) -rf $(BIN_DIST_NAME)
        mkdir $(BIN_DIST_NAME)
-       set -e; for i in LICENSE compiler ghc rts libraries utils gmp docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess extra-gcc-opts.in ghc.mk inplace; do ln -s ../$$i $(BIN_DIST_NAME)/; done
+       set -e; for i in LICENSE compiler ghc rts libraries utils gmp docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh extra-gcc-opts.in ghc.mk inplace; do ln -s ../$$i $(BIN_DIST_NAME)/; done
        ln -s ../distrib/configure-bin.ac $(BIN_DIST_NAME)/configure.ac
        cd $(BIN_DIST_NAME) && autoreconf
        $(RM) -f $(BIN_DIST_TAR)
 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
 # tree then we want to include the real file, not a symlink to it
-       $(TAR) hcf $(BIN_DIST_TAR) -T $(BIN_DIST_LIST)
-       bzip2 < $(BIN_DIST_TAR) > $(BIN_DIST_TAR_BZ2)
+       $(TAR) hcf - -T $(BIN_DIST_LIST) | bzip2 -c >$(BIN_DIST_TAR_BZ2)
+
+nTimes = set -e; for i in `seq 1 $(1)`; do echo Try "$$i: $(2)"; if $(2); then break; fi; done
+
+.PHONY: publish-binary-dist
+publish-binary-dist:
+       $(call nTimes,10,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
 
 # -----------------------------------------------------------------------------
 # Source distributions
@@ -808,14 +848,12 @@ sdist-manifest : $(SRC_DIST_TARBALL)
 # over SSH.
 ifneq "$(PublishLocation)" ""
 publish-sdist :
-       @for i in 0 1 2 3 4 5 6 7 8 9; do \
-               echo "Try $$i: $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist"; \
-               if $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist; then break; fi; \
-       done
-       @for i in 0 1 2 3 4 5 6 7 8 9; do \
-               echo "Try $$i: $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist"; \
-               if $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist; then break; fi; \
-       done
+       $(call nTimes,10,$(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist)
+       $(call nTimes,10,$(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist)
+endif
+
+ifeq "$(GhcUnregisterised)" "YES"
+SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
 endif
 
 # -----------------------------------------------------------------------------
@@ -823,6 +861,11 @@ endif
 
 .PHONY: clean
 
+CLEAN_FILES += utils/ghc-pwd/ghc-pwd
+CLEAN_FILES += utils/ghc-pwd/ghc-pwd.exe
+CLEAN_FILES += utils/ghc-pwd/ghc-pwd.hi
+CLEAN_FILES += utils/ghc-pwd/ghc-pwd.o
+
 clean : clean_files
 .PHONY: clean_files
 clean_files :
@@ -830,12 +873,25 @@ clean_files :
 
 distclean : clean
        $(RM) config.cache config.status config.log mk/config.h mk/stamp-h
-       $(RM) mk/config.mk mk/are-validating.mk
+       $(RM) mk/config.mk mk/are-validating.mk mk/project.mk
        $(RM) extra-gcc-opts docs/users_guide/ug-book.xml
        $(RM) compiler/ghc.cabal ghc/ghc-bin.cabal
        $(RM) libraries/base/include/HsBaseConfig.h
        $(RM) libraries/directory/include/HsDirectoryConfig.h
+       $(RM) libraries/process/include/HsProcessConfig.h
+       $(RM) libraries/unix/include/HsUnixConfig.h
+       $(RM) libraries/old-time/include/HsTimeConfig.h
 
 maintainer-clean : distclean
+       $(RM) configure mk/config.h.in
+       $(RM) -r autom4te.cache libraries/*/autom4te.cache
        $(RM) ghc.spec
-       $(RM) libraries/*/GNUmakefile
+       $(RM) libraries/*/GNUmakefile libraries/*/ghc.mk libraries/*/configure 
+       $(RM) libraries/base/include/HsBaseConfig.h.in
+       $(RM) libraries/directory/include/HsDirectoryConfig.h.in
+       $(RM) libraries/process/include/HsProcessConfig.h.in
+       $(RM) libraries/unix/include/HsUnixConfig.h.in
+       $(RM) libraries/old-time/include/HsTimeConfig.h.in
+
+.PHONY: all_libraries
+