Move more flags from the Makefile into pragmas
[ghc-hetmet.git] / compiler / Makefile
index 221c603..96057bc 100644 (file)
@@ -52,9 +52,6 @@ count :
 #  - for stage N, object files and .hi files are placed inside 
 #    the directory stageN, in subdirectories as per the sources.
 #
-#  - .hi-boot files are *linked* into the stageN tree, because in GHC 5.05+
-#    the .hi-boot file must reside in the same place as the .hi file.
-#
 #  - we use explicit -o and -ohi options to direct the output from C & 
 #    Haskell compilations.
 #
@@ -80,8 +77,8 @@ count :
 #  There are other plausible designs that might work, but each has different
 #  problems:
 #
-#  - using -odir and -hidir: GHC <= 4.08 doesn't support -hidir, and
-#    anyway -odir puts all the objects in one directory (strips off the
+#  - using -odir and -hidir:
+#    -odir puts all the objects in one directory (strips off the
 #    subdirectory part), which eventually forces us to use VPATH to find
 #    the sources.  I have a really bad feeling about VPATH.
 #
@@ -95,9 +92,6 @@ ifeq "$(stage)" ""
 stage=1
 endif
 
-# XXX DQ is now the same on all platforms, so get rid of it
-DQ = \"
-
 .DUMMY: stage_dir
 stage_dirs :
        $(MKDIRHIER) stage$(stage)
@@ -116,27 +110,6 @@ endif
 endif
 
 boot :: stage_dirs
-# On Windows, we can't use symbolic links for the -hi-boot files
-# because GHC itself is a Mingw program and does not understand
-# symbolic links.  So we have to copy the files instead of link them.
-# That means that if you modify a .hi-boot file in Windows, you
-# have to to say 'make boot' again.
-#
-# PS: 'ln -s foo baz' takes 'foo' relative to the path to 'baz'
-#     whereas 'cp foo baz' treats the two paths independently.
-#     Hence the "../.." in the ln command line
-ifeq "$(UsingHsBoot)" "NO"
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-       for i in */*hi-boot*; do \
-           cp -u -f $$i stage$(stage)/$$i; \
-       done
-else
-       for i in */*hi-boot*; do \
-           ($(RM) -f stage$(stage)/$$i \
-              && $(LN_S) ../../$$i stage$(stage)/$$i) || true ; \
-       done
-endif
-endif
 
 ifeq "$(stage)" "1"
 HC=$(GHC)
@@ -163,12 +136,7 @@ odir=stage$(stage)
 
 SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
 
-SRC_HC_OPTS += -Wall -fno-warn-name-shadowing
-# Turn off orphan warnings, but only if the flag exists (i.e. not if we
-# are building stage 1 and using GHC < 6.3).
-ifneq "$(stage)" "1 NO"
-SRC_HC_OPTS += -fno-warn-orphans
-endif
+SRC_HC_OPTS += -Wall -fno-warn-name-shadowing -fno-warn-orphans
 
 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
@@ -219,7 +187,6 @@ boot :: $(CONFIG_HS)
 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
        @$(RM) -f $(CONFIG_HS)
        @echo "Creating $(CONFIG_HS) ... "
-       @echo "{-# OPTIONS -w #-}" >>$(CONFIG_HS)
        @echo "module Config where" >>$(CONFIG_HS)
        @echo "cProjectName          :: String" >> $(CONFIG_HS)
        @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
@@ -261,8 +228,6 @@ $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
        @echo "cLdIsGNULd            = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
        @echo "cLD_X                 :: String" >> $(CONFIG_HS)
        @echo "cLD_X                 = \"$(LD_X)\"" >> $(CONFIG_HS)
-       @echo "cPROJECT_DIR          :: String" >> $(CONFIG_HS)
-       @echo "cPROJECT_DIR          = \"$(PROJECT_DIR)\"" >> $(CONFIG_HS)
        @echo "cGHC_DRIVER_DIR_REL   :: String" >> $(CONFIG_HS)
        @echo "cGHC_DRIVER_DIR_REL   = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
        @echo "cGHC_TOUCHY_PGM       :: String" >> $(CONFIG_HS)
@@ -289,12 +254,6 @@ $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
        @echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
        @echo "cGHC_PERL             :: String" >> $(CONFIG_HS)
        @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
-ifeq ($(GhcWithIlx),YES)
-       @echo "cILX2IL               :: String" >> $(CONFIG_HS)
-       @echo "cILX2IL               = \"$(ILX2IL)\"" >> $(CONFIG_HS)
-       @echo "cILASM                :: String" >> $(CONFIG_HS)
-       @echo "cILASM                = \"$(ILASM)\"" >> $(CONFIG_HS)
-endif
        @echo "cEnableWin32DLLs      :: String" >> $(CONFIG_HS)
        @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
        @echo "cCONTEXT_DIFF         :: String" >> $(CONFIG_HS)
@@ -312,7 +271,7 @@ else
        @echo "cRelocatableBuild     = False"                 >> $(CONFIG_HS)
 endif
        @echo "cLibFFI               :: Bool"                 >> $(CONFIG_HS)
-ifeq "$(UseLibFFI)" "YES"
+ifeq "$(UseLibFFIForAdjustors)" "YES"
        @echo "cLibFFI               = True"                  >> $(CONFIG_HS)
 else
        @echo "cLibFFI               = False"                 >> $(CONFIG_HS)
@@ -437,7 +396,7 @@ SRC_HC_OPTS += -Istage$(stage)
 ALL_DIRS = \
   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
   vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
-  profiling parser cprAnalysis ndpFlatten iface cmm
+  profiling parser cprAnalysis iface cmm
 
 # Make sure we include Config.hs even if it doesn't exist yet...
 ALL_SRCS += $(CONFIG_HS)
@@ -451,21 +410,6 @@ else
 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
 endif
 
-ifeq ($(GhcWithIlx),YES)
-ALL_DIRS += ilxGen
-SRC_HC_OPTS += -DILX
-endif
-
-ifeq ($(GhcWithJavaGen),YES)
-ALL_DIRS += javaGen
-SRC_HC_OPTS += -DJAVA
-endif
-
-ifeq ($(UseLibFFI),YES)
-SRC_HC_OPTS += -DUSE_LIBFFI
-SRC_HSC2HS_OPTS += -DUSE_LIBFFI
-endif
-
 ifeq "$(BootingFromHc)" "YES"
 # HC files are always from a self-booted compiler
 bootstrapped = YES
@@ -477,6 +421,15 @@ bootstrapped = NO
 endif
 endif
 
+# Beyond stage 1, honour any Mac OS X depolyment target options.  If we use 
+# these options in stage 1 we get a linker error if the bootstrap compiler is
+#  for a more recent OS version
+ifneq "$(findstring $(stage), 2 3)" ""
+SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
+SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
+SRC_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
+endif
+
 # -----------------------------------------------------------------------------
 # Building a compiler with interpreter support
 #
@@ -485,10 +438,13 @@ endif
 # the interpreter is supported on this platform.
 
 ifeq "$(bootstrapped)" "YES"
-SRC_HC_OPTS += -package hpc -package bytestring
-PKG_DEPENDS += hpc bytestring
+SRC_HC_OPTS += -package bytestring
+PKG_DEPENDS += bytestring
 endif
 
+SRC_HC_OPTS += -package hpc
+PKG_DEPENDS += hpc
+
 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
 
 # Yes, include the interepreter and Template Haskell extensions
@@ -512,6 +468,9 @@ ifeq "$(GhcDebugged)" "YES"
 SRC_LD_OPTS += -debug
 endif
 
+SRC_HC_OPTS     += -I$(FPTOOLS_TOP)/libffi/build/include
+SRC_HSC2HS_OPTS += -I$(FPTOOLS_TOP)/libffi/build/include
+
 ALL_DIRS += ghci
 
 # If we are going to use dynamic libraries instead of .o files for ghci,
@@ -524,23 +483,23 @@ else
 EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
 endif
 
-# Enable readline if either:
-#   - we're building stage 1 and $(GhcHasReadline)="YES"
-#   - we're building stage 2/3, and we have built the readline package
+# Enable editline if either:
+#   - we're building stage 1 and $(GhcHasEditline)="YES"
+#   - we're building stage 2/3, and we have built the editline package
 #
-# But we don't enable readline on Windows, because readline is fairly
-# broken there.
+# But we don't enable editline on Windows, as Windows terminals have
+# editline-like support builtin.
 #
 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
 ifeq "$(stage)" "1"
-ifeq "$(GhcHasReadline)" "YES"
-SRC_HC_OPTS += -package readline -DUSE_READLINE
-PKG_DEPENDS += readline
+ifeq "$(GhcHasEditline)" "YES"
+SRC_HC_OPTS += -package editline -DUSE_EDITLINE
+PKG_DEPENDS += editline
 endif
 else
-ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/readline/unbuildable)" ""
-SRC_HC_OPTS += -package readline -DUSE_READLINE
-PKG_DEPENDS += readline
+ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
+SRC_HC_OPTS += -package editline -DUSE_EDITLINE
+PKG_DEPENDS += editline
 endif
 endif # stage=1
 endif # not windows
@@ -567,9 +526,13 @@ SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
 # -----------------------------------------------------------------------------
 #              Haskell compilations
 
-SRC_HC_OPTS += \
-  -cpp -fglasgow-exts -fno-generics -Rghc-timing \
-  -I. -Iparser
+SRC_HC_OPTS += -cpp -fglasgow-exts -Rghc-timing -I. -Iparser -Iutil
+
+ifeq "$(ghc_ge_609)" "NO"
+SRC_HC_OPTS += -fno-generics
+else
+SRC_HC_OPTS += -XNoGenerics
+endif
 
 # Omitted:     -I$(GHC_INCLUDE_DIR)
 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
@@ -580,11 +543,6 @@ SRC_HC_OPTS += \
 # Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
 # include files.   For the moment we've reverted to using
 # an explicit path in the .hs sources
-#
-# For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
-# when generating dependencies. (=> it gets passed onto mkdependHS,
-# which needs it).
-SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
 
 # We need System.Posix (or Posix when ghc < 6.2)
 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
@@ -593,20 +551,12 @@ SRC_HC_OPTS += -package Win32
 PKG_DEPENDS += Win32
 endif
 else
-ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO"
-SRC_HC_OPTS += -package posix
-else
 SRC_HC_OPTS += -package unix
 PKG_DEPENDS += unix
 endif
-endif
 
-# We use the Cabal package in stages 2/3 only; in stage 1 we're using
-# the libcompat library which provides the Cabal modules.
-ifneq "$(stage)" "1"
 SRC_HC_OPTS += -package Cabal
 PKG_DEPENDS += Cabal
-endif
 
 # Ignore lang, to avoid potential clash with the Generics module if
 # lang happens to be a dependency of some exposed package in the local
@@ -614,48 +564,19 @@ endif
 SRC_HC_OPTS += -ignore-package lang
 
 SRC_CC_OPTS += -Iparser -I. -O
-SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
+SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
 SRC_HC_OPTS += -H16M
 
 ifeq "$(BootingFromHc)" "YES"
 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
 endif
 
-#      Special flags for particular modules
-#      The standard suffix rule for compiling a Haskell file
-#      adds these flags to the command line
-
-# There used to be a -no-recomp flag on PrimOp, but why?
-# It's an expensive module to recompile!
-prelude/PrimOp_HC_OPTS                 = -H80m
-
-
-main/ParsePkgConf_HC_OPTS      += -fno-warn-incomplete-patterns
-parser/Parser_HC_OPTS          += -fno-warn-incomplete-patterns
-
-# Careful optimisation of the parser: we don't want to throw everything
-# at it, because that takes too long and doesn't buy much, but we do want
-# to inline certain key external functions, so we instruct GHC not to
-# throw away inlinings as it would normally do in -Onot mode:
-parser/Parser_HC_OPTS          += -Onot -fno-ignore-interface-pragmas
-
 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
 rename/RnMonad_HC_OPTS                 =  -O2 -O2-for-C
 endif
 
-utils/Digraph_HC_OPTS          = -fglasgow-exts 
-
 # basicTypes/SrcLoc_HC_OPTS    = -funbox-strict-fields
 
-# We always optimise some low-level modules, otherwise performance of
-# a non-optimised compiler is severely affected.
-main/BinIface_HC_OPTS          += -O
-utils/Binary_HC_OPTS           += -O -funbox-strict-fields
-utils/FastMutInt_HC_OPTS       += -O
-utils/Encoding_HC_OPTS         += -O
-utils/StringBuffer_HC_OPTS     += -O -funbox-strict-fields
-utils/FastString_HC_OPTS       += -O -funbox-strict-fields
-
 # ---- Profiling ----
 #simplCore/Simplify_HC_OPTS = -auto-all
 #simplCore/SimplEnv_HC_OPTS = -auto-all
@@ -680,12 +601,14 @@ ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 main/SysTools_HC_OPTS          += '-\#include <windows.h>' '-\#include <process.h>'
 endif
 
-parser/Lexer_HC_OPTS += -funbox-strict-fields
-
 # ghc_strlen percolates through so many modules that it is easier to get its
 # prototype via a global option instead of a myriad of per-file OPTIONS
 SRC_HC_OPTS += '-\#include "cutils.h"'
 
+ifeq "$(ghc_ge_605)" "NO"
+utils/LazyUniqFM_HC_OPTS += -fallow-undecidable-instances
+endif
+
 # ----------------------------------------------------------------------------
 #              Generate supporting stuff for prelude/PrimOp.lhs 
 #              from prelude/primops.txt
@@ -757,14 +680,12 @@ primop-usage.hs-incl: prelude/primops.txt
 #-----------------------------------------------------------------------------
 #              Linking
 
-# Include libghccompat in stage1 only.  In stage2 onwards, all these
-# libraries will be available from the main libraries.
-
-ifeq "$(stage)" "1"
-include $(GHC_COMPAT_DIR)/compat.mk
+ifeq "$(GhcUnregisterised)" "NO"
+ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
+# needed for generating proper relocation in large binaries: trac #856
+SRC_LD_OPTS += -optl-Wl,--relax
+endif
 endif
-
-SRC_LD_OPTS += -no-link-chk
 
 # -----------------------------------------------------------------------------
 # create ghc-inplace, a convenient way to run ghc from the build tree...
@@ -854,7 +775,6 @@ endif
 # typecheck/TcUnify_HC_OPTS += -auto-all
 
 # coreSyn/CorePrep_HC_OPTS += -auto-all
-# parser/Parser_HC_OPTS += -fasm
 
 #-----------------------------------------------------------------------------
 # Building the GHC package
@@ -876,6 +796,8 @@ LIB_LD_OPTS += $(foreach pkg,$(PKG_DEPENDS),-package $(pkg))
 # We have to expand each package dependency with its version, which we
 # can do by calling "ghc-pkg list $pkg --simple-output".
 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(foreach pkg,$(PKG_DEPENDS),$(shell $(GHC_PKG_INPLACE) latest --global $(pkg)))'
+# We want to define STAGE to be like "2" in the Haskell code, so we need
+# to quote the "s so that they don't get interpreted by the shell.
 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
 
 # Omit Main from the library, the client will want to plug their own Main in
@@ -986,7 +908,7 @@ ifeq "$(BUILD_GHC_PACKAGE)" "YES"
 all :: $(GHC_PROG)
 endif
 
-$(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE=$(DQ)$(stage)$(DQ)
+$(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE='"$(stage)"'
 
 ifneq "$(findstring $(stage), 2 3)" ""
 $(warning LIBRARY is $(LIBRARY))
@@ -1034,7 +956,7 @@ endif
 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
 
 # Aargh, these don't work properly anyway, because GHC's recompilation checker
-# just reports "compilation NOT required".  Do we have to add -no-recomp for each
+# just reports "compilation NOT required".  Do we have to add -fforce-recomp for each
 # of these .hs files?  I haven't done anything about this yet.
 
 $(odir)/codeGen/Bitmap.$(way_)o                :  ../includes/MachDeps.h
@@ -1083,12 +1005,8 @@ ifneq "$(BootingFromHc)" "YES"
        $(MKDEPENDHS) -M -optdep-f -optdep.depend-BASE $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) $(HS_SRCS)
 endif
        $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
-       $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g; s@^.*/compat.*$$@@g;' <.depend-BASE >.depend-$(stage)
+       $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g;' <.depend-BASE >.depend-$(stage)
 # The binmode stuff tells perl not to add stupid ^M's to the output
-#
-# The /lib/compat replacement is to workaround a bug in the
-# -optdep--exclude-module flag in GHC 6.4.  It is not required for any
-# other version of GHC, but doesn't do any harm.
 
 ifeq "$(MakefileDeps)" "YES"
 $(CONFIG_HS) : Makefile