-# Main compiler Makefile
-
-# Targets:
-#
-# all builds stage1 compiler
-#
-# boot stage=N generate build dirs and dependencies for stage N.
-# NB. Must be done before 'make stageN'.
-# NB. Cannot 'make boot stage=2' until stage1 has
-# been built (similarly for stage3).
-#
-# stage1 (or stage=1) builds stage1 compiler
-# stage2 (or stage=2) builds stage2 compiler
-# stage3 (or stage=3) builds stage3 compiler
-#
-
-TOP = ..
-
-# Use GHC for compiling C bits (NB. must be before boilerplate include)
-#
-UseGhcForCc = YES
-
-# We don't want to compile stage1 in multiple ways
-ifeq "$(findstring $(stage), 2 3)" ""
-WAYS=
-endif
-
-include $(TOP)/mk/boilerplate.mk
-
-ifeq "$(GhcThreaded)$(GhcProfiled)" "YESYES"
-$(error Cannot make GHC both threaded and profiled)
-endif
-
-
-#-----------------------------------------------------------------------------
-# Counting source code lines
-
-USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
-count :
- ./count_lines $(USER_SRCS)
-
-# -----------------------------------------------------------------------------
-# Bootstrapping
-
-# The stage1/stage2/stage3 business is quite delicate. Here's how it works:
-#
-# - the variable $(stage) holds the current stage number. To build a
-# particular stage, you say 'make stage=N' where N is 1, 2, or 3.
-# N defaults to 1.
-#
-# - for stage N, object files and .hi files are placed inside
-# the directory stageN, in subdirectories as per the sources.
-#
-# - we use explicit -o and -ohi options to direct the output from C &
-# Haskell compilations.
-#
-# - we generate a different .depend file for each build. They need to be
-# different, because each stage might include different files: stage1
-# might not include GHCi, for example. For each stage, a normal .depend
-# file is generated, and then post-processed to add the correct stageN/
-# prefix to each object and .hi filename. The resulting .depend file
-# is named .depend-$(stage). See the end of this Makefile for details.
-#
-# - normal implicit rules don't work any more, because they're of the form
-#
-# %.o : %.hs
-#
-# whereas we really need
-#
-# stageN/%.o : %.hs
-#
-# so suffix.mk now defines the appropriate suffix rules when
-# $(odir) is set to a non-empty value. Here we set $(odir) to
-# stage1, stage2, or stage3.
-#
-# There are other plausible designs that might work, but each has different
-# problems:
-#
-# - 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.
-#
-# - invoke make in the stageN subdirectory. This probably requires VPATH
-# too.
-#
-# - create a link tree. The problem with requiring link trees is that
-# Windows doesn't support symbolic links.
-
-ifeq "$(stage)" ""
-stage=1
-endif
-
-.DUMMY: stage_dir
-stage_dirs :
- $(MKDIRHIER) stage$(stage)
- for i in $(ALL_DIRS); do \
- $(MKDIRHIER) stage$(stage)/$$i; \
- done
-
-ifeq "$(stage)" "1"
-UsingHsBoot = YES
-else
-ifneq "$(findstring $(stage), 2 3)" ""
-UsingHsBoot = YES
-else
-UsingHsBoot = NO
-endif
-endif
-
-boot :: stage_dirs
-
-ifeq "$(stage)" "1"
-HC=$(GHC)
-endif
-
-ifeq "$(stage)" "2"
-HC=$(GHC_STAGE1)
-endif
-
-ifeq "$(stage)" "3"
-HC=$(GHC_STAGE2)
-endif
-
-stage1 ::
- $(MAKE) stage=1
-
-stage2 ::
- $(MAKE) stage=2
-
-stage3 ::
- $(MAKE) stage=3
-
-odir=stage$(stage)
-
-SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
-
-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))))
-
-# Our standard cleaning rules don't know that we're doing our output
-# into $(odir), so we have to augment CLEAN_FILES appropriateliy.
-
-CLEAN_FILES += $(odir)/*/*.$(way_)hi $(odir)/*/*.$(way_)hi-boot $(odir)/*/*.$(way_)o-boot
-
-ifeq "$(UsingHsBoot)" "YES"
-CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
-endif
-
-ifeq "$(stage)" "1"
-mostlyclean clean distclean maintainer-clean ::
- $(MAKE) $@ stage=2
- $(MAKE) $@ stage=3
-endif
-
-# -----------------------------------------------------------------------------
-# Set HS_PROG
-
-# Note: there have been reports of people running up against the ARG_MAX limit
-# when linking ghc with all its constituent object files. The likely source of
-# the problem is that the environment is a bit too big, so a workaround could
-# be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
-# equivalent of `env' if it doesn't exist locally).
-#
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
-else
-GHC_PROG=$(odir)/ghc$(_way)
-endif
-
-ifeq "$(stage)" "1"
-HS_PROG = $(GHC_PROG)
-endif
-
-# -----------------------------------------------------------------------------
-# Create compiler configuration
-#
-# The 'echo' commands simply spit the values of various make variables
-# into Config.hs, whence they can be compiled and used by GHC itself
-
-CONFIG_HS = main/Config.hs
-boot :: $(CONFIG_HS)
-
-$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
- @$(RM) -f $(CONFIG_HS)
- @echo "Creating $(CONFIG_HS) ... "
- @echo "module Config where" >>$(CONFIG_HS)
- @echo "cProjectName :: String" >> $(CONFIG_HS)
- @echo "cProjectName = \"$(ProjectName)\"" >> $(CONFIG_HS)
- @echo "cProjectVersion :: String" >> $(CONFIG_HS)
- @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
- @echo "cProjectVersionInt :: String" >> $(CONFIG_HS)
- @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
- @echo "cProjectPatchLevel :: String" >> $(CONFIG_HS)
- @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
- @echo "cBooterVersion :: String" >> $(CONFIG_HS)
- @echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
- @echo "cStage :: String" >> $(CONFIG_HS)
- @echo "cStage = STAGE" >> $(CONFIG_HS)
- @echo "cHscIfaceFileVersion :: String" >> $(CONFIG_HS)
- @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
- @echo "cSplitObjs :: String" >> $(CONFIG_HS)
- @echo "cSplitObjs = \"$(SplitObjs)\"" >> $(CONFIG_HS)
- @echo "cGhcWithInterpreter :: String" >> $(CONFIG_HS)
- @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
- @echo "cGhcWithNativeCodeGen :: String" >> $(CONFIG_HS)
- @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
- @echo "cGhcWithSMP :: String" >> $(CONFIG_HS)
- @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
- @echo "cGhcRTSWays :: String" >> $(CONFIG_HS)
- @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
- @echo "cGhcUnregisterised :: String" >> $(CONFIG_HS)
- @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
- @echo "cGhcEnableTablesNextToCode :: String" >> $(CONFIG_HS)
- @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
- @echo "cLeadingUnderscore :: String" >> $(CONFIG_HS)
- @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
- @echo "cRAWCPP_FLAGS :: String" >> $(CONFIG_HS)
- @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
- @echo "cGCC :: String" >> $(CONFIG_HS)
- @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
- @echo "cMKDLL :: String" >> $(CONFIG_HS)
- @echo "cMKDLL = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
- @echo "cLdIsGNULd :: String" >> $(CONFIG_HS)
- @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
- @echo "cLD_X :: String" >> $(CONFIG_HS)
- @echo "cLD_X = \"$(LD_X)\"" >> $(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)
- @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_DIR_REL = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_DIR_REL = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_DIR_REL = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_DIR_REL = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_DIR_REL = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
- @echo "cGHC_CP :: String" >> $(CONFIG_HS)
- @echo "cGHC_CP = \"$(GHC_CP)\"" >> $(CONFIG_HS)
- @echo "cGHC_PERL :: String" >> $(CONFIG_HS)
- @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
- @echo "cEnableWin32DLLs :: String" >> $(CONFIG_HS)
- @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
- @echo "cCONTEXT_DIFF :: String" >> $(CONFIG_HS)
- @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
- @echo "cUSER_WAY_NAMES :: String" >> $(CONFIG_HS)
- @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
- @echo "cUSER_WAY_OPTS :: String" >> $(CONFIG_HS)
- @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR :: String" >> $(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
- @echo "cRelocatableBuild :: Bool" >> $(CONFIG_HS)
-ifeq "$(RelocatableBuild)" "YES"
- @echo "cRelocatableBuild = True" >> $(CONFIG_HS)
-else
- @echo "cRelocatableBuild = False" >> $(CONFIG_HS)
-endif
- @echo "cLibFFI :: Bool" >> $(CONFIG_HS)
-ifeq "$(UseLibFFIForAdjustors)" "YES"
- @echo "cLibFFI = True" >> $(CONFIG_HS)
-else
- @echo "cLibFFI = False" >> $(CONFIG_HS)
-endif
- @echo done.
-
-CLEAN_FILES += $(CONFIG_HS)
-
-# -----------------------------------------------------------------------------
-# Create platform includes
-
-# Here we generate a little header file containing CPP symbols that GHC
-# uses to determine which platform it is building on/for. The platforms
-# can differ between stage1 and stage2 if we're cross-compiling, so we
-# need one of these header files per stage.
-
-PLATFORM_H = ghc_boot_platform.h
-
-stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
- @echo "Creating $@..."
- @$(RM) $@
- @echo "#ifndef __PLATFORM_H__" >$@
- @echo "#define __PLATFORM_H__" >>$@
- @echo >> $@
- @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
- @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo >> $@
- @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
- @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
- @echo >> $@
- @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
- @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
- @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
- @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo >> $@
- @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
- @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
- @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
- @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
-ifeq "$(HostOS_CPP)" "irix"
- @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
- @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
- @echo "#endif " >> $@
-endif
- @echo >> $@
- @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
- @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
- @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
- @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo >> $@
- @echo "#endif /* __PLATFORM_H__ */" >> $@
- @echo "Done."
-
-# 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
- @echo "Creating $@..."
- @$(RM) $@
- @echo "#ifndef __PLATFORM_H__" >$@
- @echo "#define __PLATFORM_H__" >>$@
- @echo >> $@
- @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
- @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo >> $@
- @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
- @echo >> $@
- @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
- @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
- @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo >> $@
- @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
- @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
- @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
-ifeq "$(HostOS_CPP)" "irix"
- @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
- @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
- @echo "#endif " >> $@
-endif
- @echo >> $@
- @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
- @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
- @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo >> $@
- @echo "#endif /* __PLATFORM_H__ */" >> $@
- @echo "Done."
-
-stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
- $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
-
-STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
-
-boot :: $(STAGE_PLATFORM_H)
-
-SRC_HC_OPTS += -Istage$(stage)
-
-# -----------------------------------------------------------------------------
-# Set SRCS etc.