Make -fPIC a dynamic flag
[ghc.git] / compiler / iface / FlagChecker.hs
1 {-# LANGUAGE RecordWildCards #-}
2
3 -- | This module manages storing the various GHC option flags in a modules
4 -- interface file as part of the recompilation checking infrastructure.
5 module FlagChecker (
6 fingerprintDynFlags
7 ) where
8
9 import Binary
10 import BinIface ()
11 import DynFlags
12 import HscTypes
13 import Module
14 import Name
15 import Fingerprint
16 -- import Outputable
17 import StaticFlags
18
19 import qualified Data.IntSet as IntSet
20 import System.FilePath (normalise)
21
22 -- | Produce a fingerprint of a @DynFlags@ value. We only base
23 -- the finger print on important fields in @DynFlags@ so that
24 -- the recompilation checker can use this fingerprint.
25 fingerprintDynFlags :: DynFlags -> Module -> (BinHandle -> Name -> IO ())
26 -> IO Fingerprint
27
28 fingerprintDynFlags dflags@DynFlags{..} this_mod nameio =
29 let mainis = if mainModIs == this_mod then Just mainFunIs else Nothing
30 -- see #5878
31 -- pkgopts = (thisPackage dflags, sort $ packageFlags dflags)
32 safeHs = setSafeMode safeHaskell
33 -- oflags = sort $ filter filterOFlags $ flags dflags
34
35 -- *all* the extension flags and the language
36 lang = (fmap fromEnum language,
37 IntSet.toList $ extensionFlags)
38
39 -- -I, -D and -U flags affect CPP
40 cpp = (map normalise includePaths, opt_P dflags ++ picPOpts dflags)
41 -- normalise: eliminate spurious differences due to "./foo" vs "foo"
42
43 -- Note [path flags and recompilation]
44 paths = [ hcSuf ]
45
46 -- -fprof-auto etc.
47 prof = if opt_SccProfilingOn then fromEnum profAuto else 0
48
49 in -- pprTrace "flags" (ppr (mainis, safeHs, lang, cpp, paths)) $
50 computeFingerprint nameio (mainis, safeHs, lang, cpp, paths, prof)
51
52
53 {- Note [path flags and recompilation]
54
55 There are several flags that we deliberately omit from the
56 recompilation check; here we explain why.
57
58 -osuf, -odir, -hisuf, -hidir
59 If GHC decides that it does not need to recompile, then
60 it must have found an up-to-date .hi file and .o file.
61 There is no point recording these flags - the user must
62 have passed the correct ones. Indeed, the user may
63 have compiled the source file in one-shot mode using
64 -o to specify the .o file, and then loaded it in GHCi
65 using -odir.
66
67 -stubdir
68 We omit this one because it is automatically set by -outputdir, and
69 we don't want changes in -outputdir to automatically trigger
70 recompilation. This could be wrong, but only in very rare cases.
71
72 -i (importPaths)
73 For the same reason as -osuf etc. above: if GHC decides not to
74 recompile, then it must have already checked all the .hi files on
75 which the current module depends, so it must have found them
76 successfully. It is occasionally useful to be able to cd to a
77 different directory and use -i flags to enable GHC to find the .hi
78 files; we don't want this to force recompilation.
79
80 The only path-related flag left is -hcsuf.
81 -}