Commit 153b9cb9 authored by simonmar's avatar simonmar

[project @ 2005-01-28 12:55:17 by simonmar]

Rationalise the BUILD,HOST,TARGET defines.

Recall that:

  - build is the platform we're building on
  - host is the platform we're running on
  - target is the platform we're generating code for

The change is that now we take these definitions as applying from the
point of view of the particular source code being built, rather than
the point of view of the whole build tree.

For example, in RTS and library code, we were previously testing the
TARGET platform.  But under the new rule, the platform on which this
code is going to run is the HOST platform.  TARGET only makes sense in
the compiler sources.

In practical terms, this means that the values of BUILD, HOST & TARGET
may vary depending on which part of the build tree we are in.

Actual changes:

 - new file: includes/ghcplatform.h contains platform defines for
   the RTS and library code.

 - new file: includes/ghcautoconf.h contains the autoconf settings
   only (HAVE_BLAH).  This is so that we can get hold of these
   settings independently of the platform defines when necessary
   (eg. in GHC).

 - ghcconfig.h now #includes both ghcplatform.h and ghcautoconf.h.

 - MachRegs.h, which is included into both the compiler and the RTS,
   now has to cope with the fact that it might need to test either
   _TARGET_ or _HOST_ depending on the context.

 - the compiler's Makefile now generates
     stage{1,2,3}/ghc_boot_platform.h
   which contains platform defines for the compiler.  These differ
   depending on the stage, of course: in stage2, the HOST is the
   TARGET of stage1.  This was wrong before.

 - The compiler doesn't get platform info from Config.hs any more.
   Previously it did (sometimes), but unless we want to generate
   a new Config.hs for each stage we can't do this.

 - GHC now helpfully defines *_{BUILD,HOST}_{OS,ARCH} automatically
   in CPP'd Haskell source.

 - ghcplatform.h defines *_TARGET_* for backwards compatibility
   (ghcplatform.h is included by ghcconfig.h, which is included by
   config.h, so code which still #includes config.h will get the TARGET
   settings as before).

 - The Users's Guide is updated to mention *_HOST_* rather than
   *_TARGET_*.

 - coding-style.html in the commentary now contains a section on
   platform defines.  There are further doc updates to come.

Thanks to Wolfgang Thaller for pointing me in the right direction.
parent bfdd44b2
......@@ -10,6 +10,18 @@ you will screw up the layout where they are used in case expressions!
#endif
/* Useful in the headers that we share with the RTS */
#define COMPILING_GHC 1
/* Pull in all the platform defines for this build (foo_TARGET_ARCH etc.) */
#include "ghc_boot_platform.h"
/* Pull in the autoconf defines (HAVE_FOO), but don't include
* ghcconfig.h, because that will include ghcplatform.h which has the
* wrong platform settings for the compiler (it has the platform
* settings for the target plat instead). */
#include "../includes/ghcautoconf.h"
#if __GLASGOW_HASKELL__ >= 504
#define CONCURRENT Control.Concurrent
......
......@@ -194,9 +194,6 @@ $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
@echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
@echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
@echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
@echo "cTARGETPLATFORM = \"$(TARGETPLATFORM)\"" >> $(CONFIG_HS)
@echo "cTARGETOS = \"$(TargetOS_CPP)\"" >> $(CONFIG_HS)
@echo "cTARGETARCH = \"$(TargetArch_CPP)\"" >> $(CONFIG_HS)
@echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
@echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
@echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
......@@ -230,6 +227,112 @@ endif
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) : $(FPTOOLS_TOP)/mk/config.mk Makefile
@echo "Creating $@..."
@$(RM) $@
@echo "#ifndef __PLATFORM_H__" >$@
@echo "#define __PLATFORM_H__" >>$@
@echo >> $@
@echo "#define BuildPlatform_TYPE $(BuildPlatform_CPP)" >> $@
@echo "#define HostPlatform_TYPE $(HostPlatform_CPP)" >> $@
@echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
@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) : $(FPTOOLS_TOP)/mk/config.mk Makefile
@echo "Creating $@..."
@$(RM) $@
@echo "#ifndef __PLATFORM_H__" >$@
@echo "#define __PLATFORM_H__" >>$@
@echo >> $@
@echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
@echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
@echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
@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) : stage2/$(PLATFORM_H)
$(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
boot :: stage$(stage)/$(PLATFORM_H)
SRC_HC_OPTS += -Istage$(stage)
# -----------------------------------------------------------------------------
# Set SRCS etc.
#
......
......@@ -98,7 +98,6 @@ module CLabel (
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import CmdLineOpts ( DynFlags, opt_Static, opt_DoTickyProfiling )
import Packages ( isHomeModule, isDllName )
......
......@@ -80,7 +80,6 @@ module MachOp (
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import Constants
import Outputable
......
......@@ -24,8 +24,6 @@ module CgProf (
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
-- Needed by Constants.h
#include "../includes/Constants.h"
-- For LDV_CREATE_MASK, LDV_STATE_USE
-- which are StgWords
......
......@@ -60,9 +60,6 @@ import Char ( ord )
import DATA_BITS
import Maybe ( isNothing )
#include "../includes/ghcconfig.h"
-- For WORDS_BIGENDIAN
-------------------------------------------------------------------------
--
-- Random small functions
......
{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
-- $Id: InteractiveUI.hs,v 1.184 2005/01/26 12:58:09 simonmar Exp $
-- $Id: InteractiveUI.hs,v 1.185 2005/01/28 12:55:23 simonmar Exp $
--
-- GHC Interactive User Interface
--
......@@ -12,7 +12,6 @@ module InteractiveUI (
ghciWelcomeMsg
) where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import CompManager
......
......@@ -20,7 +20,6 @@ module Linker ( HValue, showLinkerState,
linkPackages,
) where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import ObjLink ( loadDLL, loadObj, unloadObj, resolveObjs, initObjLinker )
......
......@@ -348,11 +348,10 @@ data PackageFlag
| IgnorePackage String
defaultHscTarget
| cGhcWithNativeCodeGen == "YES" &&
(prefixMatch "i386" cTARGETPLATFORM ||
prefixMatch "sparc" cTARGETPLATFORM ||
prefixMatch "powerpc" cTARGETPLATFORM) = HscAsm
| otherwise = HscC
#if defined(i386_TARGET_ARCH) || defined(sparc_TARGET_ARCH) || defined(powerpc_TARGET_ARCH)
| cGhcWithNativeCodeGen == "YES" = HscAsm
#endif
| otherwise = HscC
defaultDynFlags = DynFlags {
coreToDo = Nothing, stgToDo = [],
......
......@@ -12,7 +12,6 @@ module Constants (module Constants) where
-- be in trouble.
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
#include "../includes/MachRegs.h"
#include "../includes/Constants.h"
#include "../includes/MachDeps.h"
......
......@@ -18,7 +18,6 @@ module DriverFlags (
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import MkIface ( showIface )
import DriverState
......@@ -639,7 +638,7 @@ setMainIs arg
-- )
machdepCCOpts dflags
| prefixMatch "alpha" cTARGETPLATFORM
#if alpha_TARGET_ARCH
= return ( ["-w", "-mieee"
#ifdef HAVE_THREADED_RTS_SUPPORT
, "-D_REENTRANT"
......@@ -649,12 +648,12 @@ machdepCCOpts dflags
-- register used for global register variable", we simply
-- disable all warnings altogether using the -w flag. Oh well.
| prefixMatch "hppa" cTARGETPLATFORM
#elif hppa_TARGET_ARCH
-- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
-- (very nice, but too bad the HP /usr/include files don't agree.)
= return ( ["-D_HPUX_SOURCE"], [] )
| prefixMatch "m68k" cTARGETPLATFORM
#elif m68k_TARGET_ARCH
-- -fno-defer-pop : for the .hc files, we want all the pushing/
-- popping of args to routines to be explicit; if we let things
-- be deferred 'til after an STGJUMP, imminent death is certain!
......@@ -666,7 +665,7 @@ machdepCCOpts dflags
-- as on iX86, where we *do* steal the frame pointer [%ebp].)
= return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
| prefixMatch "i386" cTARGETPLATFORM
#elif i386_TARGET_ARCH
-- -fno-defer-pop : basically the same game as for m68k
--
-- -fomit-frame-pointer : *must* in .hc files; because we're stealing
......@@ -692,22 +691,22 @@ machdepCCOpts dflags
"-DSTOLEN_X86_REGS="++show n_regs ]
)
| prefixMatch "ia64" cTARGETPLATFORM
#elif ia64_TARGET_ARCH
= return ( [], ["-fomit-frame-pointer", "-G0"] )
| prefixMatch "x86_64" cTARGETPLATFORM
#elif x86_64_TARGET_ARCH
= return ( [], ["-fomit-frame-pointer"] )
| prefixMatch "mips" cTARGETPLATFORM
#elif mips_TARGET_ARCH
= return ( ["-static"], [] )
| prefixMatch "sparc" cTARGETPLATFORM
#elif sparc_TARGET_ARCH
= return ( [], ["-w"] )
-- For now, to suppress the gcc warning "call-clobbered
-- register used for global register variable", we simply
-- disable all warnings altogether using the -w flag. Oh well.
| prefixMatch "powerpc-apple-darwin" cTARGETPLATFORM
#elif powerpc_apple_darwin_TARGET
-- -no-cpp-precomp:
-- Disable Apple's precompiling preprocessor. It's a great thing
-- for "normal" programs, but it doesn't support register variable
......@@ -724,11 +723,12 @@ machdepCCOpts dflags
else return ( ["-no-cpp-precomp", "-mdynamic-no-pic"],
["-mdynamic-no-pic"] )
| prefixMatch "powerpc" cTARGETPLATFORM && opt_PIC
#elif powerpc_TARGET_ARCH
| opt_PIC
= return ( ["-fPIC"], ["-fPIC"] )
| otherwise
= return ( [], [] )
#endif
-----------------------------------------------------------------------------
-- local utils
......
-----------------------------------------------------------------------------
-- $Id: DriverPhases.hs,v 1.32 2005/01/27 10:44:27 simonpj Exp $
-- $Id: DriverPhases.hs,v 1.33 2005/01/28 12:55:33 simonmar Exp $
--
-- GHC Driver
--
......@@ -7,8 +7,6 @@
--
-----------------------------------------------------------------------------
#include "../includes/ghcconfig.h"
module DriverPhases (
HscSource(..), isHsBoot, hscSourceString,
HscTarget(..), Phase(..),
......
......@@ -816,10 +816,12 @@ runPhase cc_phase todo dflags basename suff input_fn get_output_fn maybe_loc
runPhase Mangle todo dflags _basename _suff input_fn get_output_fn maybe_loc
= do let mangler_opts = getOpts dflags opt_m
machdep_opts <- if (prefixMatch "i386" cTARGETPLATFORM)
then do let n_regs = stolen_x86_regs dflags
return [ show n_regs ]
else return []
#if i386_TARGET_ARCH
machdep_opts <- return [ show (stolen_x86_regs dflags) ]
#else
machdep_opts <- return []
#endif
split <- readIORef v_Split_object_files
let next_phase
......@@ -1253,8 +1255,12 @@ doCpp dflags raw include_cc_opts input_fn output_fn = do
| otherwise = SysTools.runCc dflags (SysTools.Option "-E" : args)
let target_defs =
[ "-D" ++ cTARGETOS ++ "_TARGET_OS=1",
"-D" ++ cTARGETARCH ++ "_TARGET_ARCH=1" ]
[ "-D" ++ HOST_OS ++ "BUILD_OS=1",
"-D" ++ HOST_ARCH ++ "BUILD_ARCH=1",
"-D" ++ TARGET_OS ++ "HOST_OS=1",
"-D" ++ TARGET_ARCH ++ "HOST_ARCH=1" ]
-- remember, in code we *compile*, the HOST is the same our TARGET,
-- and BUILD is the same as our HOST.
cpp_prog ([SysTools.Option verb]
++ map SysTools.Option include_paths
......
......@@ -8,7 +8,6 @@
module DriverState where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import CmdLineOpts
......@@ -128,14 +127,19 @@ GLOBAL_VAR(v_Split_info, ("",0), (String,Int))
can_split :: Bool
can_split = prefixMatch "i386" cTARGETPLATFORM
|| prefixMatch "alpha" cTARGETPLATFORM
|| prefixMatch "hppa" cTARGETPLATFORM
|| prefixMatch "m68k" cTARGETPLATFORM
|| prefixMatch "mips" cTARGETPLATFORM
|| prefixMatch "powerpc" cTARGETPLATFORM
|| prefixMatch "rs6000" cTARGETPLATFORM
|| prefixMatch "sparc" cTARGETPLATFORM
can_split =
#if defined(i386_TARGET_ARCH) \
|| defined(alpha_TARGET_ARCH) \
|| defined(hppa_TARGET_ARCH) \
|| defined(m68k_TARGET_ARCH) \
|| defined(mips_TARGET_ARCH) \
|| defined(powerpc_TARGET_ARCH) \
|| defined(rs6000_TARGET_ARCH) \
|| defined(sparc_TARGET_ARCH)
True
#else
False
#endif
-----------------------------------------------------------------------------
-- Compiler output options
......
-----------------------------------------------------------------------------
-- $Id: DriverUtil.hs,v 1.49 2005/01/11 16:21:53 simonmar Exp $
-- $Id: DriverUtil.hs,v 1.50 2005/01/28 12:55:37 simonmar Exp $
--
-- Utils for the driver
--
......@@ -19,7 +19,6 @@ module DriverUtil (
replaceFilenameDirectory, remove_spaces, escapeSpaces,
) where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import Util
......
{-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-}
-----------------------------------------------------------------------------
-- $Id: Main.hs,v 1.143 2005/01/27 10:44:39 simonpj Exp $
-- $Id: Main.hs,v 1.144 2005/01/28 12:55:38 simonmar Exp $
--
-- GHC Driver program
--
......@@ -9,14 +9,10 @@
--
-----------------------------------------------------------------------------
-- with path so that ghc -M can find config.h
#include "../includes/ghcconfig.h"
module Main (main) where
#include "HsVersions.h"
#ifdef GHCI
import InteractiveUI( ghciWelcomeMsg, interactiveUI )
#endif
......
......@@ -34,9 +34,6 @@ module Packages (
)
where
#include "../includes/ghcconfig.h"
-- Needed for mingw32_TARGET_OS defn
#include "HsVersions.h"
import PackageConfig
......@@ -44,7 +41,7 @@ import DriverState ( v_Build_tag, v_RTS_Build_tag, v_Static )
import SysTools ( getTopDir, getPackageConfigPath )
import ParsePkgConf ( loadPackageConfig )
import CmdLineOpts ( DynFlags(..), PackageFlag(..), opt_Static )
import Config ( cTARGETARCH, cTARGETOS, cProjectVersion )
import Config ( cProjectVersion )
import Name ( Name, nameModule_maybe )
import Module ( Module, mkModule )
import UniqFM
......@@ -206,7 +203,7 @@ readPackageConfigs dflags = do
-- (GHC >= 6.3).
appdir <- getAppUserDataDirectory "ghc"
let
pkgconf = appdir ++ '/':cTARGETARCH ++ '-':cTARGETOS
pkgconf = appdir ++ '/':TARGET_ARCH ++ '-':TARGET_OS
++ '-':cProjectVersion ++ "/package.conf"
--
exists <- doesFileExist pkgconf
......
......@@ -84,8 +84,6 @@ import IO ( try, catch,
import Directory ( doesFileExist, removeFile )
import List ( partition )
#include "../includes/ghcconfig.h"
-- GHC <= 4.08 didn't have rawSystem, and runs into problems with long command
-- lines on mingw32, so we disallow it now.
#if __GLASGOW_HASKELL__ < 500
......
......@@ -35,7 +35,6 @@ module MachInstrs (
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import MachRegs
import Cmm
......
......@@ -9,7 +9,7 @@
#ifndef NCG_H
#define NCG_H
#include "../includes/ghcconfig.h"
#include "ghc_boot_platform.h"
#define COMMA ,
......
#include "../includes/ghcconfig.h"
module PositionIndependentCode (
cmmMakeDynamicReference,
needImportedSymbols,
......
......@@ -85,7 +85,6 @@ module RegisterAlloc (
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import PprMach
import MachRegs
......
......@@ -17,7 +17,6 @@ module TcForeign
, tcForeignExports
) where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import HsSyn
......
......@@ -21,7 +21,6 @@ module Panic
) where
#include "HsVersions.h"
#include "../includes/ghcconfig.h"
import Config
import FastTypes
......
......@@ -53,7 +53,6 @@ module Util (
readRational,
) where
#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import Panic ( panic, trace )
......
......@@ -160,7 +160,7 @@ co above).
Avoid conditional code like this:
<pre>
#ifdef solaris_HOST_OS
#ifdef solaris_host_OS
// do something solaris specific
#endif
</pre>
......
......@@ -70,17 +70,55 @@
</dl>
<p>More about what you're allowed to do in the way of CPP
directives later.
<h2>Platform tests</h2>
<p>There are three platforms of interest to GHC:
<ul>
<li>The <b>Build</b> platform. This is the platform on which we
are building GHC.</li>
<li>The <b>Host</b> platform. This is the platform on which we
are going to run this GHC binary, and associated tools.</li>
<li>The <b>Target</b> platform. This is the platform for which
this GHC binary will generate code.</li>
</ul>
<p>At the moment, there is very limited support for having
different values for buil, host, and target. In particular:</p>
<ul>
<li>The build platform is currently always the same as the host
platform. The build process needs to use some of the tools in
the source tree, for example <tt>ghc-pkg</tt> and
<tt>hsc2hs</tt>.</li>
<li>If the target platform differs from the host platform, then
this is generally for the purpose of building <tt>.hc</tt> files
from Haskell source for porting GHC to the target platform.
Full cross-compilation isn't supported (yet).</li>
</ul>
<p>In the compiler's source code, you may make use of the
following CPP symbols:</p>
<ul>
<li><em>xxx</em><tt>_TARGET_ARCH</tt></li>
<li><em>xxx</em><tt>_TARGET_VENDOR</tt></li>
<li><em>xxx</em><tt>_TARGET_OS</tt></li>
<li><em>xxx</em><tt>_HOST_ARCH</tt></li>
<li><em>xxx</em><tt>_HOST_VENDOR</tt></li>
<li><em>xxx</em><tt>_HOST_OS</tt></li>
</ul>
<p>where <em>xxx</em> is the appropriate value:
eg. <tt>i386_TARGET_ARCH</tt>.
<h2>Compiler versions</h2>
<p>GHC must be compilable by every major version of GHC from 4.08
<p>GHC must be compilable by every major version of GHC from 5.02
onwards, and itself. It isn't necessary for it to be compilable
by every intermediate development version (that includes last
week's CVS sources), but we mustn't lose compatibility with 4.08
for the time being, because that's the only version which can be
easily bootstrapped from .hc files.
week's CVS sources).
<p>To maintain compatibility, use <tt>HsVersions.h</tt> (see
below) where possible, and try to avoid using <tt>#ifdef</tt> in
......
......@@ -387,7 +387,7 @@ $ cat foo.hspp</screen>
<varlistentry>
<term>
<constant><replaceable>os</replaceable>_TARGET_OS=1</constant>
<constant><replaceable>os</replaceable>_OS=1</constant>
</term>
<listitem>
<para>This define allows conditional compilation based on
......@@ -400,7 +400,7 @@ $ cat foo.hspp</screen>
<varlistentry>
<term>
<constant><replaceable>arch</replaceable>_TARGET_ARCH=1</constant>
<constant><replaceable>arch</replaceable>_ARCH=1</constant>
</term>
<listitem>
<para>This define allows conditional compilation based on
......
/* -----------------------------------------------------------------------------
* $Id: MachRegs.h,v 1.20 2005/01/19 18:31:07 wolfgang Exp $
* $Id: MachRegs.h,v 1.21 2005/01/28 12:55:51 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -27,6 +27,36 @@
*/
#ifndef NO_REGS
/* NOTE: when testing the platform in this file we must test either
* *_HOST_ARCH and *_TARGET_ARCH, depending on whether COMPILING_GHC
* is set. This is because when we're compiling the RTS and HC code,
* the platform we're running on is the HOST, but when compiling GHC
* we want to know about the register mapping on the TARGET platform.
*/
#ifdef COMPILING_GHC
#define alpha_REGS alpha_TARGET_ARCH
#define hppa1_1_REGS hppa1_1_TARGET_ARCH
#define i386_REGS i386_TARGET_ARCH
#define x86_64_REGS x86_64_TARGET_ARCH
#define m68k_REGS m68k_TARGET_ARCH
#define mips_REGS (mipsel_TARGET_ARCH || mipseb_TARGET_ARCH)
#define powerpc_REGS (powerpc_TARGET_ARCH || powerpc64_TARGET_ARCH || rs6000_TARGET_ARCH)
#define ia64_REGS ia64_TARGET_ARCH
#define sparc_REGS sparc_TARGET_ARCH
#define darwin_REGS darwin_TARGET_OS
#else
#define alpha_REGS alpha_HOST_ARCH
#define hppa1_1_REGS hppa1_1_HOST_ARCH
#define i386_REGS i386_HOST_ARCH
#define x86_64_REGS x86_64_HOST_ARCH
#define m68k_REGS m68k_HOST_ARCH
#define mips_REGS (mipsel_HOST_ARCH || mipseb_HOST_ARCH)
#define powerpc_REGS (powerpc_HOST_ARCH || powerpc64_HOST_ARCH || rs6000_HOST_ARCH)
#define ia64_REGS ia64_HOST_ARCH
#define sparc_REGS sparc_HOST_ARCH
#define darwin_REGS darwin_HOST_OS
#endif
/* ----------------------------------------------------------------------------
Caller saves and callee-saves regs.
......@@ -82,7 +112,7 @@
t12 $27 NCG_reserved
-------------------------------------------------------------------------- */
#if defined(alpha_TARGET_ARCH)
#if alpha_REGS
# define REG(x) __asm__("$" #x)
# define CALLER_SAVES_R2
......@@ -123,7 +153,7 @@
# define NCG_Reserved_F1 f29
# define NCG_Reserved_F2 f30
#endif /* alpha_TARGET_ARCH */
#endif /* alpha_REGS */
/* -----------------------------------------------------------------------------
The HP-PA register mapping
......@@ -146,7 +176,7 @@
\tr{%fr8}--\tr{%fr11} are some available caller-save fl-pt registers.
-------------------------------------------------------------------------- */
#if hppa1_1_TARGET_ARCH
#if hppa1_1_REGS
#define REG(x) __asm__("%" #x)
......@@ -201,7 +231,7 @@
-------------------------------------------------------------------------- */
#if i386_TARGET_ARCH
#if i386_REGS
#define REG(x) __asm__("%" #x)
......@@ -251,7 +281,7 @@
%r15 YES
--------------------------------------------------------------------------- */
#if x86_64_TARGET_ARCH
#if x86_64_REGS
#define REG(x) __asm__("%" #x)
......@@ -302,7 +33