[project @ 2005-02-04 17:24:01 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / DriverFlags.hs
index 55c8e54..c4eea5e 100644 (file)
@@ -13,12 +13,12 @@ module DriverFlags (
        addCmdlineHCInclude,
        buildStaticHscOpts, 
        machdepCCOpts,
+        picCCOpts,
 
        processArgs, OptKind(..), -- for DriverMkDepend only
   ) where
 
 #include "HsVersions.h"
-#include "../includes/ghcconfig.h"
 
 import MkIface         ( showIface )
 import DriverState
@@ -183,7 +183,7 @@ static_flags =
   ,  ( "S"             , PassFlag (setMode (StopBefore As)))
   ,  ( "-make"         , PassFlag (setMode DoMake))
   ,  ( "-interactive"  , PassFlag (setMode DoInteractive))
-  ,  ( "-mk-dll"       , PassFlag (setMode DoMkDLL))
+  ,  ( "-mk-dll"       , NoArg (writeIORef v_GhcLink NoLink))
   ,  ( "e"              , HasArg   (\s -> setMode (DoEval s) "-e"))
 
        -- -fno-code says to stop after Hsc but don't generate any code.
@@ -195,10 +195,6 @@ static_flags =
   ,  ( "ignore-dot-ghci", NoArg (writeIORef v_Read_DotGHCi False) )
   ,  ( "read-dot-ghci"  , NoArg (writeIORef v_Read_DotGHCi True) )
 
-       ------- recompilation checker --------------------------------------
-  ,  ( "recomp"                , NoArg (setRecompFlag True) )
-  ,  ( "no-recomp"     , NoArg (setRecompFlag False) )
-
        ------- ways --------------------------------------------------------
   ,  ( "prof"          , NoArg (addNoDups v_Ways       WayProf) )
   ,  ( "unreg"         , NoArg (addNoDups v_Ways       WayUnreg) )
@@ -297,8 +293,8 @@ static_flags =
   ,  ( "optdll"                , HasArg (add v_Opt_dll) )
 
        ----- Linker --------------------------------------------------------
-  ,  ( "c"             , NoArg (writeIORef v_NoLink True) )
-  ,  ( "no-link"       , NoArg (writeIORef v_NoLink True) )    -- Deprecated
+  ,  ( "c"             , NoArg (writeIORef v_GhcLink NoLink) )
+  ,  ( "no-link"       , NoArg (writeIORef v_GhcLink NoLink) ) -- Deprecated
   ,  ( "static"        , NoArg (writeIORef v_Static True) )
   ,  ( "dynamic"        , NoArg (writeIORef v_Static False) )
   ,  ( "rdynamic"       , NoArg (return ()) ) -- ignored for compat w/ gcc
@@ -340,6 +336,10 @@ dynamic_flags = [
   ,  ( "opti",         HasArg (addOpt_i) )
 #endif
 
+       ------- recompilation checker --------------------------------------
+  ,  ( "recomp"                , NoArg (setRecompFlag True) )
+  ,  ( "no-recomp"     , NoArg (setRecompFlag False) )
+
         ------- Packages ----------------------------------------------------
   ,  ( "package-conf"   , HasArg extraPkgConf_ )
   ,  ( "no-user-package-conf", NoArg noUserPkgConf_ )
@@ -639,7 +639,7 @@ setMainIs arg
 --                    )
 
 machdepCCOpts dflags
-   | prefixMatch "alpha"   cTARGETPLATFORM  
+#if alpha_TARGET_ARCH
        = return ( ["-w", "-mieee"
 #ifdef HAVE_THREADED_RTS_SUPPORT
                    , "-D_REENTRANT"
@@ -649,12 +649,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 +666,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,43 +692,54 @@ 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
       --     declarations.
+        = return ( [], ["-no-cpp-precomp"] )
+#else
+       = return ( [], [] )
+#endif
+
+picCCOpts dflags
+#if darwin_TARGET_OS
+      -- Apple prefers to do things the other way round.
+      -- PIC is on by default.
       -- -mdynamic-no-pic:
-      --     Turn off PIC code generation to save space and time.
+      --     Turn off PIC code generation.
       -- -fno-common:
       --     Don't generate "common" symbols - these are unwanted
       --     in dynamic libraries.
 
-        = if opt_PIC
-            then return ( ["-no-cpp-precomp", "-fno-common"],
-                          ["-fno-common"] )
-            else return ( ["-no-cpp-precomp", "-mdynamic-no-pic"],
-                          ["-mdynamic-no-pic"] )
-
-   | prefixMatch "powerpc" cTARGETPLATFORM && opt_PIC
-        = return ( ["-fPIC"], ["-fPIC"] )
-  
-   | otherwise
-       = return ( [], [] )
+    | opt_PIC
+        = return ["-fno-common"]
+    | otherwise
+        = return ["-mdynamic-no-pic"]
+#elif mingw32_TARGET_OS
+      -- no -fPIC for Windows
+        = return []
+#else
+    | opt_PIC
+        = return ["-fPIC"]
+    | otherwise
+        = return []
+#endif
 
 -----------------------------------------------------------------------------
 -- local utils