GHC new build system megapatch
[ghc.git] / Makefile
1
2 ifeq "$(wildcard distrib/)" ""
3
4 # We're in a bindist
5
6 .PHONY: default
7 default:
8 @echo 'Run "make install" to install'
9 @false
10
11 .PHONY: install
12 install:
13 $(MAKE) -r --no-print-directory -f ghc.mk install BINDIST=YES NO_INCLUDE_DEPS=YES
14
15 .PHONY: show
16 show:
17 $(MAKE) -r --no-print-directory -f ghc.mk $@
18
19 else
20
21 # The problem we need to solve is as follows.
22 #
23 # GNU make supports included Makefiles, and it is clever enough to try
24 # to update those Makefiles when they are out-of-date or missing. It
25 # first reads all the Makefiles, and then tries to build each one if
26 # it is out-of-date, using the rules in the Makefiles themselves.
27 # When it has brought all the Makefiles up-to-date, it restarts itself
28 # to read the newly-generated Makefiles.
29 #
30 # This works fine, unless there are dependencies *between* the
31 # Makefiles. For example in the GHC build, for each package we have a
32 # package-data.mk file which is generated by the ghc-cabal program,
33 # and we have a .depend file. The .depend file cannot be generated
34 # until package-data.mk has been generated and make has been restarted
35 # to read in its contents, because it is the package-data.mk file that
36 # tells us which modules are in the package. But make always makes
37 # all the Makefiles before restarting - it doesn't take into account a
38 # dependency between Makefiles and restart itself earlier.
39
40 # Consider the following makefile:
41
42 # --------------------
43 # all :
44 #
45 # include inc1.mk
46 #
47 # inc1.mk : Makefile
48 # echo "X = C" >$@
49 #
50 # include inc2.mk
51 #
52 # inc2.mk : inc1.mk
53 # echo "Y = $(X)" >$@
54 # --------------------
55
56 # Now try it:
57 #
58 # $ make -f fail.mk
59 # fail.mk:3: inc1.mk: No such file or directory
60 # fail.mk:8: inc2.mk: No such file or directory
61 # echo "X = C" >inc1.mk
62 # echo "Y = " >inc2.mk
63 # make: Nothing to be done for `all'.
64
65 # make built both inc1.mk and inc2.mk without restarting itself
66 # between the two (even though we added a dependency on inc1.mk from
67 # inc2.mk).
68 #
69 # The solution we adopt in the GHC build system is essentially this:
70
71 # --------------------
72 # PHASE = 0
73 #
74 # ifeq "$(PHASE)" "0"
75 # all :
76 # $(MAKE) PHASE=1
77 # else
78 # all :
79 # endif
80 #
81 # -include inc1.mk
82 #
83 # inc1.mk : Makefile
84 # echo "X = C" >$@
85 #
86 # ifneq "$(PHASE)" "0"
87 # include inc2.mk
88 #
89 # inc2.mk : inc1.mk
90 # echo "Y = $(X)" >$@
91 # endif
92 #
93 # clean :
94 # rm -f inc1.mk inc2.mk
95 # --------------------
96
97 # That is, every time make is invoked, we force it to update inc1.mk
98 # and then restart. In the GHC build system we need to divide the
99 # build into 4 phases in fact, with a restart between each phase. See
100 # ghc.mk for the details on what happens in each phase and why.
101
102 default : all
103 @:
104
105 # No need to update makefiles for these targets:
106 REALGOALS=$(filter-out clean clean_% distclean maintainer-clean show,$(MAKECMDGOALS))
107
108 # NB. not the same as saying '%: ...', which doesn't do the right thing:
109 # it does nothing if we specify a target that already exists.
110 .PHONY: $(REALGOALS)
111 $(REALGOALS) all:
112 @echo "===--- updating makefiles phase 0"
113 $(MAKE) -r --no-print-directory -f ghc.mk phase=0 just-makefiles
114 @echo "===--- updating makefiles phase 1"
115 $(MAKE) -r --no-print-directory -f ghc.mk phase=1 just-makefiles
116 @echo "===--- updating makefiles phase 2"
117 $(MAKE) -r --no-print-directory -f ghc.mk phase=2 just-makefiles
118 @echo "===--- updating makefiles phase 3"
119 $(MAKE) -r --no-print-directory -f ghc.mk phase=3 just-makefiles
120 @echo "===--- finished updating makefiles"
121 $(MAKE) -r --no-print-directory -f ghc.mk $@
122
123 binary-dist:
124 rm -f bindist-list
125 $(MAKE) -r --no-print-directory -f ghc.mk bindist BINDIST=YES
126 $(MAKE) -r --no-print-directory -f ghc.mk binary-dist
127
128 clean distclean maintainer-clean:
129 $(MAKE) -r --no-print-directory -f ghc.mk $@
130 test ! -d testsuite || $(MAKE) -C testsuite $@
131
132 $(filter clean_%, $(MAKECMDGOALS)) : clean_% :
133 $(MAKE) -r --no-print-directory -f ghc.mk $@
134
135 show:
136 $(MAKE) -r --no-print-directory -f ghc.mk $@
137
138 # If the user says 'make A B', then we don't want to invoke two
139 # instances of the rule above in parallel:
140 .NOTPARALLEL:
141
142 endif
143