update submodules for GHC.HetMet.GArrow -> Control.GArrow renaming
[ghc-hetmet.git] / rules / hi-rule.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13
14 # Here's an interesting rule!
15
16 # The .hi file may or may not change when we compile the corresponding
17 # .hs file.  If GHC figures out that the .hi file has not changed, it
18 # doesn't touch it.  This is a useful optimisation, because it means
19 # some modules may not get recompiled if the .hi files of the modules
20 # they depend on have not changed.
21 #
22 # See:
23 #   http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/RecompilationAvoidance
24 #
25 # So how do we express this dependency to make?  The exact form of
26 # this rule is quite fragile.  Here are some versions that don't work
27 # very well:
28 #
29 # %.hi : %.o
30 #       @if [ ! -f $@ ] ; then \
31 #           echo Panic! $< exists, but $@ does not.; \
32 #           exit 1; \
33 #       fi
34 #
35 # This version adds a useful sanity check; but it is also expensive on
36 # Windows where spawning a shell takes a while (about 0.3s).  We'd
37 # like to avoid the shell if necessary.  This also hides the message
38 # "nothing to be done for 'all'", since make thinks it has actually done
39 # something.
40 #
41 # %.hi : %.o
42 #
43 # This version doesn't work: GNU make knows it has't done anything to
44 # update the .hi file, so even if the .o file has been updated, it
45 # won't rebuild anything that depends on the .hi file.  So you might
46 # think a more correct way is to change the .hs rule:
47 #
48 # %.hi %.o : %.hs
49 #       $(HC) ...
50 #
51 # this says "compiling %.hs updates both %.hi and %.o", but that's not
52 # true, since compiling the .hs file might not update the .hi file, if
53 # the .hi file didn't change.  And if we use this version, then make
54 # will keep trying to rebuild %.hi if it is out of date with respect
55 # to %.hs.
56 #
57 # Using this form seems to be the best compromise:
58 #
59 # %.hi : %.o ;
60 #
61 # the ';' at the end signifies an "empty command" (see the GNU make
62 # documentation).  An empty command is enough to get GNU make to think
63 # it has updated %.hi, but without actually spawning a shell to do so.
64
65 define hi-rule # $1 = way
66
67 %.$$($1_hisuf) : %.$$($1_osuf) ;
68
69 %.$$($1_way_)hi-boot : %.$$($1_way_)o-boot ;
70
71 endef
72