ApplicativeDo transformation
[ghc.git] / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009-2013 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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # ToDo List.
14 #
15 # * remove old Makefiles, add new stubs for building in subdirs
16 # * docs/Makefile
17 # * docs/docbook-cheat-sheet/Makefile
18 # * docs/man/Makefile
19 # * docs/storage-mgmt/Makefile
20 # * docs/vh/Makefile
21 # * rts/dotnet/Makefile
22 # * utils/Makefile
23 # * add Makefiles for the rest of the utils/ programs that aren't built
24 # by default (need to exclude them from 'make all' too)
25
26 # Possible cleanups:
27 #
28 # * per-source-file dependencies instead of one .depend file?
29 # * eliminate undefined variables, and use --warn-undefined-variables?
30 # * put outputs from different ways in different subdirs of distdir/build,
31 # then we don't have to use -osuf/-hisuf. We would have to install
32 # them in different places too, so we'd need ghc-pkg support for packages
33 # of different ways.
34 # * make PACKAGES_STAGE1 generated by './configure' or './boot'?
35 # * we should use a directory of package.conf files rather than a single
36 # file for the inplace package database, so that we can express
37 # dependencies more accurately. Otherwise it's possible to get into
38 # a state where the package database is out of date, and the build
39 # system doesn't know.
40
41 # Approximate build order.
42 #
43 # The actual build order is defined by dependencies, and the phase
44 # ordering used to ensure correct ordering of makefile-generation; see
45 # http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
46 #
47 # * With bootstrapping compiler:
48 # o Build utils/ghc-cabal
49 # o Build utils/ghc-pkg
50 # o Build utils/hsc2hs
51 # o Build utils/genprimopcode
52 # o Build utils/deriveConstants
53 # * For each package:
54 # o configure, generate package-data.mk and inplace-pkg-config
55 # o register each package into inplace/lib/package.conf
56 # * build libffi (if not disabled by --with-system-libffi)
57 # * With bootstrapping compiler:
58 # o Build libraries/{filepath,hpc,Cabal}
59 # o Build compiler (stage 1)
60 # * With stage 1 compiler:
61 # o Build libraries/*
62 # o Build rts
63 # o Build utils/* (except haddock)
64 # o Build compiler (stage 2)
65 # * With stage 2 compiler:
66 # o Build utils/haddock
67 # o Build compiler (stage 3) (optional)
68 # * With haddock:
69 # o libraries/*
70 # o compiler
71
72 .PHONY: default all haddock
73
74 # We need second expansion for the way we handle directories, so that
75 # | $$$$(dir $$$$@)/.
76 # expands to the directory of a rule that uses a % pattern.
77 .SECONDEXPANSION:
78
79 default : all
80
81
82 ##################################################
83 # Check that we have a new enough 'make'
84
85 HAVE_EVAL := NO
86 $(eval HAVE_EVAL := YES)
87
88 ifeq "$(HAVE_EVAL)" "NO"
89 $(error Your make does not support eval. You need GNU make >= 3.81)
90 endif
91
92 ifeq "$(abspath /)" ""
93 $(error Your make does not support abspath. You need GNU make >= 3.81)
94 endif
95 ##################################################
96
97
98 # Catch make if it runs away into an infinite loop
99 ifeq "$(MAKE_RESTARTS)" ""
100 else ifeq "$(MAKE_RESTARTS)" "1"
101 else
102 $(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug? See http://ghc.haskell.org/trac/ghc/wiki/Building/Troubleshooting#Makehasrestarteditself3timesisthereamakefilebug for details)
103 endif
104
105 # -----------------------------------------------------------------------------
106 # Misc GNU make utils
107
108 nothing=
109 space=$(nothing) $(nothing)
110 comma=,
111
112 # -----------------------------------------------------------------------------
113 # Makefile debugging
114 #
115 # to see the effective value used for a Makefile variable, do
116 # make show VALUE=MY_VALUE
117 #
118
119 show:
120 @echo '$(VALUE)="$($(VALUE))"'
121
122 # echo is used by the nightly builders to query the build system for
123 # information.
124 # Using printf means that we don't get a trailing newline. We escape
125 # backslashes and double quotes in the string to protect them from the
126 # shell, and percent signs to protect them from printf.
127 echo:
128 @printf "$(subst %,%%,$(subst ",\",$(subst \,\\\\,$($(VALUE)))))"
129
130 # -----------------------------------------------------------------------------
131 # Include subsidiary build-system bits
132
133 include mk/tree.mk
134
135 ifneq "$(CLEANING)" "YES"
136 include mk/config.mk
137 ifeq "$(ProjectVersion)" ""
138 $(error Please run ./configure first)
139 endif
140 endif
141
142 include mk/ways.mk
143 include mk/warnings.mk
144
145 # (Optional) build-specific configuration
146 include mk/custom-settings.mk
147 SRC_CC_OPTS += $(WERROR)
148 SRC_HC_OPTS += $(WERROR)
149
150 # -----------------------------------------------------------------------------
151 # Check for inconsistent settings, after reading mk/build.mk.
152 # Although mk/config.mk should always contain consistent settings (set by
153 # configure), mk/build.mk can contain pretty much anything.
154
155 ifneq "$(CLEANING)" "YES"
156
157 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
158 ifeq "$(findstring dyn,$(GhcLibWays))" ""
159 $(error dyn is not in $$(GhcLibWays), but $$(DYNAMIC_GHC_PROGRAMS) is YES)
160 endif
161 else
162 ifeq "$(findstring v,$(GhcLibWays))" ""
163 $(error v is not in $$(GhcLibWays), and $$(DYNAMIC_GHC_PROGRAMS) is not YES)
164 endif
165 endif
166
167 ifeq "$(GhcProfiled)" "YES"
168 ifeq "$(findstring p,$(GhcLibWays))" ""
169 $(error p is not in $$(GhcLibWays), and $$(GhcProfiled) is YES)
170 endif
171 endif
172
173 ifeq "$(BUILD_DOCBOOK_HTML)" "YES"
174 ifeq "$(XSLTPROC)" ""
175 $(error BUILD_DOCBOOK_HTML=YES, but `xsltproc` was not found. \
176 Install `xsltproc`, then rerun `./configure`. \
177 See https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation)
178 endif
179 ifeq "$(HAVE_DOCBOOK_XSL)" "NO"
180 $(error BUILD_DOCBOOK_HTML=YES, but DocBook XSL stylesheets were not found. \
181 Install `docbook-xsl`, then rerun `./configure`. \
182 See https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation)
183 endif
184 endif
185
186 ifneq "$(BUILD_DOCBOOK_PS) $(BUILD_DOCBOOK_PDF)" "NO NO"
187 ifeq "$(DBLATEX)" ""
188 $(error BUILD_DOCBOOK_PS or BUILD_DOCBOOK_PDF=YES, but `dblatex` was not found. \
189 Install `dblatex`, then rerun `./configure`. \
190 See https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation)
191 endif
192 endif
193
194 ifeq "$(HSCOLOUR_SRCS)" "YES"
195 ifeq "$(HSCOLOUR_CMD)" ""
196 $(error HSCOLOUR_SRCS=YES, but HSCOLOUR_CMD is empty. \
197 Run `cabal install hscolour`, then rerun `./configure`. \
198 See https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation)
199 endif
200 endif
201
202 endif # CLEANING
203
204 # -----------------------------------------------------------------------------
205
206 ifeq "$(phase)" ""
207 phase = final
208 endif
209
210 # -----------------------------------------------------------------------------
211 # Utility definitions
212
213 include rules/prof.mk
214 include rules/trace.mk
215 include rules/library-path.mk
216 include rules/add-dependency.mk
217 include rules/make-command.mk
218 include rules/pretty_commands.mk
219
220 # -----------------------------------------------------------------------------
221 # Macros for standard targets
222
223 include rules/all-target.mk
224 include rules/clean-target.mk
225
226 # -----------------------------------------------------------------------------
227 # The inplace tree
228
229 $(eval $(call clean-target,root,inplace,inplace/bin inplace/lib))
230
231 # -----------------------------------------------------------------------------
232 # Whether to build dependencies or not
233
234 # When we're just doing 'make clean' or 'make show', then we don't need
235 # to build dependencies.
236
237 ifeq "$(CLEANING)" "YES"
238 NO_INCLUDE_DEPS = YES
239 NO_INCLUDE_PKGDATA = YES
240 endif
241 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
242 NO_INCLUDE_DEPS = YES
243 NO_INCLUDE_PKGDATA = YES
244 endif
245 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
246 NO_INCLUDE_DEPS = YES
247 # We want package-data.mk for show
248 endif
249
250 # -----------------------------------------------------------------------------
251 # Ways
252
253 include rules/way-prelims.mk
254
255 $(foreach way,$(ALL_WAYS),\
256 $(eval $(call way-prelims,$(way))))
257
258 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
259 GHCI_WAY = dyn
260 HADDOCK_WAY = dyn
261 else
262 GHCI_WAY = v
263 HADDOCK_WAY = v
264 endif
265
266 WINDOWS_DYN_PROG_RTS := rts
267 ifeq "$(GhcThreaded)" "YES"
268 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_thr
269 endif
270 ifeq "$(GhcDebugged)" "YES"
271 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_debug
272 endif
273 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_dyn_LIB_FILE
274
275 # -----------------------------------------------------------------------------
276 # Compilation Flags
277
278 include rules/distdir-opts.mk
279 include rules/distdir-way-opts.mk
280
281 # -----------------------------------------------------------------------------
282 # Finding source files and object files
283
284 include rules/hs-sources.mk
285 include rules/c-sources.mk
286 include rules/includes-sources.mk
287 include rules/hs-objs.mk
288 include rules/c-objs.mk
289 include rules/cmm-objs.mk
290
291 # -----------------------------------------------------------------------------
292 # Suffix rules
293
294 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
295 # so we don't make any when cleaning.
296 ifneq "$(CLEANING)" "YES"
297 include rules/hs-suffix-rules-srcdir.mk
298 include rules/hs-suffix-way-rules-srcdir.mk
299 include rules/hs-suffix-way-rules.mk
300 include rules/hi-rule.mk
301 include rules/c-suffix-rules.mk
302 include rules/cmm-suffix-rules.mk
303 endif
304
305 # -----------------------------------------------------------------------------
306 # Building package-data.mk files from .cabal files
307
308 include rules/package-config.mk
309
310 # -----------------------------------------------------------------------------
311 # Building dependencies
312
313 include rules/dependencies.mk
314 include rules/build-dependencies.mk
315 include rules/include-dependencies.mk
316
317 # -----------------------------------------------------------------------------
318 # Build package-data.mk files
319
320 include rules/build-package-data.mk
321
322 # -----------------------------------------------------------------------------
323 # Build and install a program
324
325 include rules/build-prog.mk
326 include rules/shell-wrapper.mk
327
328 # -----------------------------------------------------------------------------
329 # Build a perl script
330
331 include rules/build-perl.mk
332
333 # -----------------------------------------------------------------------------
334 # Build a package
335
336 include rules/build-package.mk
337 include rules/build-package-way.mk
338 include rules/haddock.mk
339 include rules/tags-package.mk
340 include rules/foreachLibrary.mk
341
342 # -----------------------------------------------------------------------------
343 # Registering hand-written package descriptions (used in rts)
344
345 include rules/manual-package-config.mk
346
347 # -----------------------------------------------------------------------------
348 # Docs
349
350 include rules/docbook.mk
351
352 # -----------------------------------------------------------------------------
353 # Making bindists and sdists
354
355 include rules/bindist.mk
356 include rules/sdist-ghc-file.mk
357
358 # -----------------------------------------------------------------------------
359 # Directories
360
361 # Don't try to delete directories:
362 .PRECIOUS: %/.
363
364 # Create build directories on demand. NB. the | below: this indicates
365 # that $(MKDIRHIER) is an order-only dependency, which means that this
366 # rule fires after building mkdirhier, but we won't try to recreate
367 # directories if mkdirhier changes.
368 %/. : | $(MKDIRHIER)
369 "$(MKDIRHIER)" $@
370
371 # -----------------------------------------------------------------------------
372 # Lax dependencies
373
374 ifeq "$(LAX_DEPENDENCIES)" "YES"
375 LAX_DEPS_FOLLOW = |
376 else
377 LAX_DEPS_FOLLOW =
378 endif
379
380 # This is a bit of a hack. When LAX_DEPS_FOLLOW is | some rules end up
381 # looking like
382 # target: a | b | c
383 # The first | signals the start of the order-only dependencies, but make
384 # treats the second | as a dependency. So we need to tell make how to
385 # build that dependency.
386
387 .PHONY: |
388 | :
389 @:
390
391 # -----------------------------------------------------------------------------
392 # Packages to build
393 # The lists of packages that we *actually* going to build in each stage:
394 #
395 # $(PACKAGES_STAGE0)
396 # $(PACKAGES_STAGE1)
397 # $(PACKAGES_STAGE2)
398 #
399 # Note that we need to add them to these variables in dependency
400 # order, as this is the order that they get configured in.
401
402 ifeq "$(CLEANING)" "YES"
403
404 define addLibraryForCleaning
405 # We just add all packages to both the stage 0 and stage 1 lists.
406 # Stage 2 gets cleaned in the same way as stage 1, so no need to
407 # add it there.
408 PACKAGES_STAGE0 += $1
409 PACKAGES_STAGE1 += $1
410 endef
411 $(eval $(call foreachLibrary,addLibraryForCleaning))
412
413 else # CLEANING
414
415 # Packages that are built by stage0. These packages are dependencies of
416 # programs such as GHC and ghc-pkg, that we do not assume the stage0
417 # compiler already has installed (or up-to-date enough).
418
419 PACKAGES_STAGE0 = binary Cabal/Cabal hpc bin-package-db hoopl transformers template-haskell
420 ifeq "$(Windows_Host)" "NO"
421 ifneq "$(HostOS_CPP)" "ios"
422 PACKAGES_STAGE0 += terminfo
423 endif
424 endif
425
426 PACKAGES_STAGE1 += ghc-prim
427 PACKAGES_STAGE1 += $(INTEGER_LIBRARY)
428 PACKAGES_STAGE1 += base
429 PACKAGES_STAGE1 += filepath
430 PACKAGES_STAGE1 += array
431 PACKAGES_STAGE1 += deepseq
432 PACKAGES_STAGE1 += bytestring
433 PACKAGES_STAGE1 += containers
434
435 ifeq "$(Windows_Host)" "YES"
436 PACKAGES_STAGE1 += Win32
437 endif
438 PACKAGES_STAGE1 += time
439 ifeq "$(Windows_Host)" "NO"
440 PACKAGES_STAGE1 += unix
441 endif
442
443 PACKAGES_STAGE1 += directory
444 PACKAGES_STAGE1 += process
445 PACKAGES_STAGE1 += hpc
446 PACKAGES_STAGE1 += pretty
447 PACKAGES_STAGE1 += template-haskell
448 PACKAGES_STAGE1 += binary
449 PACKAGES_STAGE1 += Cabal/Cabal
450 PACKAGES_STAGE1 += bin-package-db
451 PACKAGES_STAGE1 += hoopl
452 PACKAGES_STAGE1 += transformers
453
454 ifeq "$(HADDOCK_DOCS)" "YES"
455 PACKAGES_STAGE1 += xhtml
456 endif
457
458 ifeq "$(Windows_Target)" "NO"
459 ifneq "$(TargetOS_CPP)" "ios"
460 PACKAGES_STAGE1 += terminfo
461 endif
462 endif
463 PACKAGES_STAGE1 += haskeline
464
465 # See Note [No stage2 packages when CrossCompiling or Stage1Only].
466 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
467 ifeq "$(CrossCompiling) $(Stage1Only)" "NO NO"
468 define addExtraPackage
469 ifeq "$2" "-"
470 # Do nothing; this package is already handled above
471 else ifeq "$2" "dph"
472 ifeq "$$(BUILD_DPH) $$(GhcProfiled)" "YES NO"
473 # The DPH packages need TH, which is incompatible with a profiled GHC.
474 PACKAGES_STAGE2 += $1
475 endif
476 else ifeq "$2" "extra"
477 ifeq "$$(BUILD_EXTRA_PKGS)" "YES"
478 PACKAGES_STAGE2 += $1
479 endif
480 else
481 $$(error Unknown package tag: $2)
482 endif
483 endef
484 $(eval $(call foreachLibrary,addExtraPackage))
485 endif
486
487 # We install all packages that we build.
488 INSTALL_PACKAGES := $(addprefix libraries/,$(PACKAGES_STAGE1))
489 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
490 ifneq "$(Stage1Only)" "YES"
491 INSTALL_PACKAGES += compiler
492 endif
493 INSTALL_PACKAGES += $(addprefix libraries/,$(PACKAGES_STAGE2))
494
495 endif # CLEANING
496
497 # -------------------------------------------
498 # Note [Dependencies between package-data.mk files].
499
500 # We cannot run ghc-cabal to configure a package until we have
501 # configured and registered all of its dependencies. So the following
502 # hack forces all the configure steps to happen in exactly the following order:
503 #
504 # $(PACKAGES_STAGE1) ghc(stage2) $(PACKAGES_STAGE2)
505 #
506 # Ideally we should use the correct dependencies here to allow more
507 # parallelism, but we don't know the dependencies until we've
508 # generated the package-data.mk files.
509 define fixed_pkg_dep
510 libraries/$1/$2/package-data.mk : $$(fixed_pkg_prev)
511 fixed_pkg_prev:=libraries/$1/$2/package-data.mk
512 endef
513
514 ifneq "$(BINDIST)" "YES"
515 fixed_pkg_prev=
516 $(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
517
518 # Intermezzo: utils that we build with the stage1 compiler. They depend on
519 # the stage1 packages, so we have to make sure those packages get configured
520 # and registered before we can start with these. Note that they don't depend on
521 # eachother, so we can configure them in parallel.
522 utils/ghc-pwd/dist-install/package-data.mk: $(fixed_pkg_prev)
523 utils/ghc-cabal/dist-install/package-data.mk: $(fixed_pkg_prev)
524 utils/dll-split/dist-install/package-data.mk: $(fixed_pkg_prev)
525 utils/hpc/dist-install/package-data.mk: $(fixed_pkg_prev)
526 utils/ghc-pkg/dist-install/package-data.mk: $(fixed_pkg_prev)
527 utils/hsc2hs/dist-install/package-data.mk: $(fixed_pkg_prev)
528 utils/compare_sizes/dist-install/package-data.mk: $(fixed_pkg_prev)
529 utils/runghc/dist-install/package-data.mk: $(fixed_pkg_prev)
530
531 # the GHC package doesn't live in libraries/, so we add its dependency manually:
532 compiler/stage2/package-data.mk: $(fixed_pkg_prev)
533
534 # and continue with PACKAGES_STAGE2, which depend on GHC:
535 fixed_pkg_prev:=compiler/stage2/package-data.mk
536 $(foreach pkg,$(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
537
538 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
539 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
540
541 # Utils that we build with the stage2 compiler.
542 # They depend on the ghc library and some other libraries, but depending on
543 # the ghc library's package-data.mk is sufficient, as that in turn depends on
544 # all the other libraries' package-data.mk files.
545 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
546 utils/ghctags/dist-install/package-data.mk: compiler/stage2/package-data.mk
547 utils/mkUserGuidePart/dist/package-data.mk: compiler/stage2/package-data.mk
548
549 # add the final package.conf dependency: ghc-prim depends on RTS
550 libraries/ghc-prim/dist-install/package-data.mk : rts/dist/package.conf.inplace
551 endif
552
553 # --------------------------------
554 # Misc package-related settings
555
556 # Run Haddock for the packages that will be installed. We need to handle
557 # compiler specially due to the different dist directory name.
558 $(foreach p,$(INSTALL_PACKAGES),$(eval $p_dist-install_DO_HADDOCK = YES))
559 compiler_stage2_DO_HADDOCK = YES
560
561 BOOT_PKG_CONSTRAINTS := \
562 $(foreach d,$(PACKAGES_STAGE0),\
563 $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
564 --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
565
566 # The actual .a and .so/.dll files: needed for dependencies.
567 ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_v_LIB))
568 ifeq "$(BuildSharedLibs)" "YES"
569 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_dyn_LIB))
570 endif
571 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
572
573 # ----------------------------------------
574 # Special magic for the ghc-prim package
575
576 # We want the ghc-prim package to include the GHC.Prim module when it
577 # is registered, but not when it is built, because GHC.Prim is not a
578 # real source module, it is built-in to GHC. The old build system did
579 # this using Setup.hs, but we can't do that here, so we have a flag to
580 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
581 # remains compatible with the old build system for the time being).
582 # GHC.Prim module in the ghc-prim package with a flag:
583 #
584 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
585
586 # And then we strip it out again before building the package:
587 define libraries/ghc-prim_PACKAGE_MAGIC
588 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
589 endef
590
591 PRIMOPS_TXT_STAGE1 = compiler/stage1/build/primops.txt
592
593 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $$(genprimopcode_INPLACE) $(PRIMOPS_TXT_STAGE1) | $$(dir $$@)/.
594 "$(genprimopcode_INPLACE)" --make-haskell-wrappers < $(PRIMOPS_TXT_STAGE1) >$@
595
596 # Required so that Haddock documents the primops.
597 libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
598
599 # ----------------------------------------
600 # Special magic for the integer package
601
602 ifneq "$(CLEANING)" "YES"
603 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
604 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-gmp
605 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
606 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
607 else
608 $(error Unknown integer library: $(INTEGER_LIBRARY))
609 endif
610 endif
611
612 # -----------------------------------------------------------------------------
613 # Include build instructions from all subdirs
614 BUILD_DIRS += utils/mkdirhier
615 BUILD_DIRS += utils/touchy
616 BUILD_DIRS += utils/unlit
617 BUILD_DIRS += utils/hp2ps
618 BUILD_DIRS += driver/split
619 BUILD_DIRS += utils/genprimopcode
620 BUILD_DIRS += driver
621 BUILD_DIRS += driver/ghci
622 BUILD_DIRS += driver/ghc
623 BUILD_DIRS += driver/haddock
624 BUILD_DIRS += libffi
625 BUILD_DIRS += utils/deriveConstants
626 BUILD_DIRS += includes
627 BUILD_DIRS += rts
628 BUILD_DIRS += bindisttest
629 BUILD_DIRS += utils/genapply
630
631 # When cleaning, don't add any library packages to BUILD_DIRS. We include
632 # ghc.mk files for all BUILD_DIRS, but they don't exist until after running
633 # `./boot`. Running `make clean` before anything else, as well as running
634 # `make maintainer-clean` twice, should work.
635 ifneq "$(CLEANING)" "YES"
636 # These are deliberately in reverse order, so as to ensure that
637 # there is no need to have them in dependency order. That's important
638 # because it's tricky to ensure that they are in dependency order when
639 # cross-compiling, as some packages may only be in PACKAGES_STAGE0
640 # or PACKAGES_STAGE1.
641 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
642 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE1))
643 BUILD_DIRS += $(patsubst %, libraries/%, $(filter-out $(PACKAGES_STAGE1),$(PACKAGES_STAGE0)))
644 ifeq "$(BUILD_DPH)" "YES"
645 # Note: `$(eval $(call foreachLibrary,addExtraPackage))` above adds the
646 # packages listed in `libraries/dph/ghc-packages` (e.g. dph-base) to
647 # PACKAGES_STAGE2. But not 'libraries/dph' itself (it doesn't have a cabal
648 # file). Since it does have a ghc.mk file, we add it to BUILD_DIRS here.
649 BUILD_DIRS += $(wildcard libraries/dph)
650 endif
651 endif
652
653 BUILD_DIRS += libraries/integer-gmp/gmp
654 BUILD_DIRS += utils/haddock
655 BUILD_DIRS += utils/haddock/doc
656 BUILD_DIRS += compiler
657 BUILD_DIRS += utils/hsc2hs
658 BUILD_DIRS += utils/ghc-pkg
659 BUILD_DIRS += utils/testremove
660 BUILD_DIRS += utils/ghctags
661 BUILD_DIRS += utils/dll-split
662 BUILD_DIRS += utils/ghc-pwd
663 BUILD_DIRS += utils/ghc-cabal
664 BUILD_DIRS += utils/hpc
665 BUILD_DIRS += utils/runghc
666 BUILD_DIRS += ghc
667 BUILD_DIRS += utils/mkUserGuidePart
668 BUILD_DIRS += docs/users_guide
669 BUILD_DIRS += docs/man
670 BUILD_DIRS += utils/count_lines
671 BUILD_DIRS += utils/compare_sizes
672
673 # ----------------------------------------------
674 # Actually include the sub-ghc.mk's
675
676 ifeq "$(CLEANING)" "YES"
677 # Don't exclude any BUILD_DIRS when cleaning. When you for example build
678 # haddock once, but later set HADDOCK_DOCS back to NO, then 'make clean'
679 # should still clean the haddock directory.
680 else # CLEANING
681 ifeq "$(BINDIST)" "YES"
682 BUILD_DIRS := $(filter-out utils/mkdirhier,$(BUILD_DIRS))
683 BUILD_DIRS := $(filter-out utils/genprimopcode,$(BUILD_DIRS))
684 BUILD_DIRS := $(filter-out bindisttest,$(BUILD_DIRS))
685 BUILD_DIRS := $(filter-out utils/genapply,$(BUILD_DIRS))
686 BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
687 endif
688 ifeq "$(HADDOCK_DOCS)" "NO"
689 BUILD_DIRS := $(filter-out utils/haddock,$(BUILD_DIRS))
690 BUILD_DIRS := $(filter-out utils/haddock/doc,$(BUILD_DIRS))
691 endif
692 ifeq "$(BUILD_DOCBOOK_HTML) $(BUILD_DOCBOOK_PS) $(BUILD_DOCBOOK_PDF)" "NO NO NO"
693 # Don't to build this little utility if we're not building the User's Guide.
694 BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
695 endif
696 ifeq "$(Windows_Host)" "NO"
697 BUILD_DIRS := $(filter-out utils/touchy,$(BUILD_DIRS))
698 endif
699 ifeq "$(GhcUnregisterised)" "YES"
700 BUILD_DIRS := $(filter-out driver/split,$(BUILD_DIRS))
701 endif
702 ifeq "$(GhcWithInterpreter)" "NO"
703 # runghc is just GHCi in disguise
704 BUILD_DIRS := $(filter-out utils/runghc,$(BUILD_DIRS))
705 endif
706 ifneq "$(INTEGER_LIBRARY)" "integer-gmp"
707 BUILD_DIRS := $(filter-out libraries/integer-gmp/gmp,$(BUILD_DIRS))
708 endif
709 ifneq "$(CrossCompiling) $(Stage1Only)" "NO NO"
710 # See Note [No stage2 packages when CrossCompiling or Stage1Only].
711 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
712 BUILD_DIRS := $(filter-out utils/haddock,$(BUILD_DIRS))
713 BUILD_DIRS := $(filter-out utils/haddock/doc,$(BUILD_DIRS))
714 BUILD_DIRS := $(filter-out utils/ghctags,$(BUILD_DIRS))
715 BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
716 endif
717 endif # CLEANING
718
719 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
720
721 # A useful pseudo-target (must be after the include above, because it needs
722 # the value of things like $(libraries/base_dist-install_v_LIB).
723 .PHONY: stage1_libs
724 stage1_libs : $(ALL_STAGE1_LIBS)
725
726 # ----------------------------------------------
727 # Per-package compiler flags
728 #
729 # If you want to add per-package compiler flags, see `mk/warnings.mk`.
730
731 # Add $(GhcLib(Extra)HcOpts) to all package builds
732 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
733 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_EXTRA_HC_OPTS += $$(GhcLibExtraHcOpts)))
734
735 # Add $(GhcBootLib(Extra)HcOpts) to all stage0 package builds
736 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
737 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_EXTRA_HC_OPTS += $$(GhcBootLibExtraHcOpts)))
738
739 # -----------------------------------------------------------------------------
740 # Bootstrapping libraries
741
742 # We need to build a few libraries with the installed GHC, since GHC itself
743 # and some of the tools depend on them:
744
745 ifneq "$(BINDIST)" "YES"
746
747 ifneq "$(BOOTSTRAPPING_CONF)" ""
748 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
749 $(shell $(GHC_PKG) init $(BOOTSTRAPPING_CONF))
750 endif
751 endif
752
753 $(eval $(call clean-target,root,bootstrapping_conf,$(BOOTSTRAPPING_CONF)))
754
755 # register the boot packages in strict sequence, because running
756 # multiple ghc-pkgs in parallel doesn't work (registrations may get
757 # lost).
758 fixed_pkg_prev=
759 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
760 # ghc-pkg, unlike other utils that we build with the stage0 compiler (TODO: is
761 # this really true?), depends on several boot packages (e.g. Cabal and
762 # bin-package-db). They need to be configured before ghc-pkg, so we add a
763 # dependency between their package-data.mk files. See also Note
764 # [Dependencies between package-data.mk files].
765 utils/ghc-pkg/dist/package-data.mk: $(fixed_pkg_prev)
766 compiler/stage1/package-data.mk: $(fixed_pkg_prev)
767 endif
768
769 ifneq "$(BINDIST)" "YES"
770 # Make sure we have all the GHCi libs by the time we've built
771 # ghc-stage2. DPH includes a bit of Template Haskell which needs the
772 # GHCi libs, and we don't have a better way to express that dependency.
773 #
774 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
775 $(compiler_stage2_GHCI_LIB)
776
777 ifeq "$(UseArchivesForGhci)" "NO"
778 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
779 endif
780
781 ifeq "$(UseArchivesForGhci)" "YES"
782 GHCI_lib_way = v
783 else
784 GHCI_lib_way = GHCI
785 endif
786
787 # Deps for TH uses in libraries
788 $(foreach way, $(GhcLibWays),$(eval \
789 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
790 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
791 ))
792 endif
793
794 # -----------------------------------------------
795 # Haddock-related bits
796
797 # Build the Haddock contents and index
798 ifeq "$(HADDOCK_DOCS)" "YES"
799 libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
800 cd libraries && sh gen_contents_index --intree
801 ifeq "$(phase)" "final"
802 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
803 endif
804 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
805 endif
806
807 # -----------------------------------------------------------------------------
808 # Creating a local mingw copy on Windows
809
810 ifeq "$(Windows_Host)" "YES"
811
812 install : install_mingw
813 .PHONY: install_mingw
814 install_mingw : $(INPLACE_MINGW)
815 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
816
817 install : install_perl
818 .PHONY: install_perl
819 install_perl : $(INPLACE_PERL)
820 "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
821
822 endif # Windows_Host
823
824 ifneq "$(BINDIST)" "YES"
825 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
826 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
827 endif # BINDIST
828
829 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
830 $(PRIMOPS_TXT_STAGE1) $$(genprimopcode_INPLACE) \
831 | $$(dir $$@)/.
832 "$(genprimopcode_INPLACE)" --make-haskell-source < $< > $@
833
834 .PHONY: tags
835 tags: tags_compiler
836
837 .PHONY: TAGS
838 TAGS: TAGS_compiler
839
840 # -----------------------------------------------------------------------------
841 # Installation
842
843 install: install_libs install_packages install_libexecs \
844 install_bins install_topdirs
845 ifeq "$(HADDOCK_DOCS)" "YES"
846 install: install_docs
847 endif
848
849 define installLibsTo
850 # $1 = libraries to install
851 # $2 = directory to install to
852 #
853 # The .dll case calls STRIP_CMD explicitly, instead of `install -s`, because
854 # on Win64, "install -s" calls a strip that doesn't understand 64bit binaries.
855 # For some reason, this means the DLLs end up non-executable, which means
856 # executables that use them just segfault.
857 $(INSTALL_DIR) $2
858 for i in $1; do \
859 case $$i in \
860 *.a) \
861 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $2; \
862 $(RANLIB_CMD) $2/`basename $$i` ;; \
863 *.dll) \
864 $(INSTALL_PROGRAM) $(INSTALL_OPTS) $$i $2 ; \
865 $(STRIP_CMD) $2/`basename $$i` ;; \
866 *.so) \
867 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $2 ;; \
868 *.dylib) \
869 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $2;; \
870 *) \
871 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $2; \
872 esac; \
873 done
874 endef
875
876 install_bins: $(INSTALL_BINS) $(INSTALL_SCRIPTS)
877 $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
878 for i in $(INSTALL_BINS); do \
879 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(bindir)" ; \
880 done
881 for i in $(INSTALL_SCRIPTS); do \
882 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i "$(DESTDIR)$(bindir)" ; \
883 done
884
885 install_libs: $(INSTALL_LIBS)
886 $(call installLibsTo, $(INSTALL_LIBS), "$(DESTDIR)$(ghclibdir)")
887
888 install_libexecs: $(INSTALL_LIBEXECS)
889 ifeq "$(INSTALL_LIBEXECS)" ""
890 @:
891 else
892 $(INSTALL_DIR) "$(DESTDIR)$(ghclibexecdir)/bin"
893 for i in $(INSTALL_LIBEXECS); do \
894 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(ghclibexecdir)/bin"; \
895 done
896 # We rename ghc-stage2, so that the right program name is used in error
897 # messages etc.
898 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc"
899 endif
900
901 install_topdirs: $(INSTALL_TOPDIR_BINS) $(INSTALL_TOPDIR_SCRIPTS)
902 $(INSTALL_DIR) "$(DESTDIR)$(topdir)"
903 for i in $(INSTALL_TOPDIR_BINS); do \
904 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(topdir)"; \
905 done
906 for i in $(INSTALL_TOPDIR_SCRIPTS); do \
907 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i "$(DESTDIR)$(topdir)"; \
908 done
909
910 install_docs: $(INSTALL_DOCS)
911 $(INSTALL_DIR) "$(DESTDIR)$(docdir)"
912 ifneq "$(INSTALL_DOCS)" ""
913 for i in $(INSTALL_DOCS); do \
914 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)"; \
915 done
916 endif
917 $(INSTALL_DIR) "$(DESTDIR)$(docdir)/html"
918 $(INSTALL_DOC) $(INSTALL_OPTS) docs/index.html "$(DESTDIR)$(docdir)/html"
919 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
920 $(INSTALL_DIR) "$(DESTDIR)$(docdir)/html/libraries"
921 for i in $(INSTALL_LIBRARY_DOCS); do \
922 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)/html/libraries/"; \
923 done
924 $(INSTALL_DATA) $(INSTALL_OPTS) libraries/prologue.txt "$(DESTDIR)$(docdir)/html/libraries/"
925 $(INSTALL_SCRIPT) $(INSTALL_OPTS) libraries/gen_contents_index "$(DESTDIR)$(docdir)/html/libraries/"
926 endif
927 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
928 for i in $(INSTALL_HTML_DOC_DIRS); do \
929 $(INSTALL_DIR) "$(DESTDIR)$(docdir)/html/`basename $$i`"; \
930 $(INSTALL_DOC) $(INSTALL_OPTS) $$i/* "$(DESTDIR)$(docdir)/html/`basename $$i`"; \
931 done
932 endif
933
934 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
935
936 # Install packages in the right order, so that ghc-pkg doesn't complain.
937 # Also, install ghc-pkg first.
938 ifeq "$(Windows_Host)" "NO"
939 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
940 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
941 else
942 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
943 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
944 endif
945
946 # Set the INSTALL_DISTDIR_p for each package; compiler is special
947 $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
948 $(eval INSTALL_DISTDIR_$p = dist-install))
949 INSTALL_DISTDIR_compiler = stage2
950
951 # Now we can do the installation
952 install_packages: install_libexecs
953 install_packages: rts/dist/package.conf.install
954 $(INSTALL_DIR) "$(DESTDIR)$(topdir)"
955 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
956 $(INSTALL_DIR) "$(INSTALLED_PACKAGE_CONF)"
957 $(INSTALL_DIR) "$(DESTDIR)$(topdir)/rts"
958 $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts")
959 $(foreach p, $(INSTALL_PACKAGES), \
960 $(call make-command, \
961 "$(ghc-cabal_INPLACE)" copy \
962 $p $(INSTALL_DISTDIR_$p) \
963 "$(STRIP_CMD)" \
964 '$(DESTDIR)' \
965 '$(prefix)' \
966 '$(ghclibdir)' \
967 '$(docdir)/html/libraries' \
968 '$(GhcLibWays)'))
969 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/dist/package.conf.install
970 $(foreach p, $(INSTALL_PACKAGES), \
971 $(call make-command, \
972 "$(ghc-cabal_INPLACE)" register \
973 $p $(INSTALL_DISTDIR_$p) \
974 "$(INSTALLED_GHC_REAL)" \
975 "$(INSTALLED_GHC_PKG_REAL)" \
976 "$(DESTDIR)$(topdir)" \
977 '$(DESTDIR)' \
978 '$(prefix)' \
979 '$(ghclibdir)' \
980 '$(docdir)/html/libraries' \
981 $(RelocatableBuild)))
982 # when we install the packages above, ghc-pkg obeys umask when creating
983 # the package.conf files, but for everything else we specify the
984 # permissions. We therefore now fix the permissions of package.cache.
985 # This means "sudo make install" does the right thing even if it runs
986 # with an 077 umask.
987 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
988
989 # -----------------------------------------------------------------------------
990 # Binary distributions
991
992 ifneq "$(CLEANING)" "YES"
993 # This rule seems to hold some files open on Windows which prevents
994 # cleaning, perhaps due to the $(wildcard).
995
996 $(eval $(call bindist-list,.,\
997 LICENSE \
998 README \
999 INSTALL \
1000 configure config.sub config.guess install-sh \
1001 settings.in \
1002 packages \
1003 Makefile \
1004 mk/config.mk.in \
1005 $(INPLACE_BIN)/mkdirhier \
1006 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
1007 utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
1008 $(BINDIST_WRAPPERS) \
1009 $(BINDIST_PERL_SOURCES) \
1010 $(BINDIST_LIBS) \
1011 $(BINDIST_HI) \
1012 $(BINDIST_EXTRAS) \
1013 $(includes_H_FILES) \
1014 $(includes_DERIVEDCONSTANTS) \
1015 $(includes_GHCCONSTANTS) \
1016 $(libffi_HEADERS) \
1017 $(INSTALL_LIBEXECS) \
1018 $(INSTALL_LIBEXEC_SCRIPTS) \
1019 $(INSTALL_TOPDIR_BINS) \
1020 $(INSTALL_TOPDIR_SCRIPTS) \
1021 $(INSTALL_BINS) \
1022 $(INSTALL_SCRIPTS) \
1023 $(INSTALL_MANPAGES) \
1024 $(INSTALL_DOCS) \
1025 $(INSTALL_LIBRARY_DOCS) \
1026 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
1027 docs/index.html \
1028 compiler/stage2/doc \
1029 $(wildcard libraries/*/dist-install/doc/) \
1030 $(wildcard libraries/*/*/dist-install/doc/) \
1031 $(filter-out settings,$(INSTALL_LIBS)) \
1032 $(RTS_INSTALL_LIBS) \
1033 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
1034 mk/project.mk \
1035 mk/install.mk.in \
1036 bindist.mk \
1037 libraries/gen_contents_index \
1038 libraries/prologue.txt \
1039 $(wildcard libraries/dph/LICENSE \
1040 libraries/dph/ghc-packages \
1041 libraries/dph/ghc-packages2 \
1042 libraries/dph/ghc-stage2-package) \
1043 ))
1044 endif
1045 # mk/project.mk gets an absolute path, so we manually include it in
1046 # the bindist with a relative path
1047
1048 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
1049
1050 unix-binary-dist-prep:
1051 $(call removeTrees,bindistprep/)
1052 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
1053 set -e; for i in packages LICENSE compiler ghc rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh settings.in ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
1054 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
1055 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
1056 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
1057 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
1058 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
1059 echo "override ghc-cabal_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
1060 echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
1061 cd $(BIN_DIST_PREP_DIR) && autoreconf
1062 $(call removeFiles,$(BIN_DIST_PREP_TAR))
1063 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1064 # tree then we want to include the real file, not a symlink to it
1065 cd bindistprep && "$(TAR_CMD)" hcf - -T ../bindist-list | $(TAR_COMP_CMD) -c > ../$(BIN_DIST_PREP_TAR_COMP)
1066
1067 windows-binary-dist-prep:
1068 $(call removeTrees,bindistprep/)
1069 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1070 cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | $(TAR_COMP_CMD) -c > ../$(BIN_DIST_PREP_TAR_COMP)
1071
1072 # tryTimes tries to run its third argument multiple times, until it
1073 # succeeds. Don't call it directly; call try10Times instead.
1074 # The first and second argument to tryTimes are lists of values.
1075 # The length of the first argument is the number of times we have
1076 # already tried. The length of the second argument is the number more
1077 # times we will try.
1078 tryTimes = $(if $2, \
1079 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1080 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1081 )
1082
1083 # Try to run the argument 10 times. If all 10 fail, fail.
1084 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1085
1086 .PHONY: publish-binary-dist
1087 publish-binary-dist:
1088 $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_COMP) $(PublishLocation)/dist)
1089
1090 ifeq "$(mingw32_TARGET_OS)" "1"
1091 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/doc
1092 else
1093 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/share/doc/ghc
1094 endif
1095
1096 .PHONY: publish-docs
1097 publish-docs:
1098 $(call try10Times,$(PublishCp) -r $(DOCDIR_TO_PUBLISH)/* $(PublishLocation)/docs)
1099
1100 # -----------------------------------------------------------------------------
1101 # Source distributions
1102
1103 # Do it like this:
1104 #
1105 # $ ./boot
1106 # $ ./configure
1107 # $ make sdist
1108 #
1109
1110 # A source dist is built from a (partial) build tree, because we
1111 # require some extra files not contained in a git checkout: the
1112 # output from Happy and Alex, for example.
1113 #
1114 # The steps performed by 'make sdist' are as follows:
1115 # - build those extra files
1116 # - create a complete link-tree of the current build tree in /tmp
1117 # - run 'make distclean' on that tree
1118 # - remove a bunch of other files that we know shouldn't be in the dist
1119
1120 #
1121 # Directory in which we're going to build the src dist
1122 #
1123 SRC_DIST_ROOT = sdistprep
1124 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
1125
1126 SRC_DIST_GHC_NAME = ghc-$(ProjectVersion)-src
1127 SRC_DIST_GHC_ROOT = $(SRC_DIST_ROOT)/ghc
1128 SRC_DIST_GHC_DIR = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
1129 SRC_DIST_GHC_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.$(TAR_COMP_EXT)
1130
1131 SRC_DIST_WINDOWS_TARBALLS_NAME = ghc-$(ProjectVersion)-windows-extra-src
1132 SRC_DIST_WINDOWS_TARBALLS_ROOT = $(SRC_DIST_ROOT)/windows-tarballs
1133 SRC_DIST_WINDOWS_TARBALLS_DIR = $(SRC_DIST_WINDOWS_TARBALLS_ROOT)/$(SRC_DIST_BASE_NAME)
1134 SRC_DIST_WINDOWS_TARBALLS_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_WINDOWS_TARBALLS_NAME).tar.$(TAR_COMP_EXT)
1135
1136 SRC_DIST_TESTSUITE_NAME = ghc-$(ProjectVersion)-testsuite
1137 SRC_DIST_TESTSUITE_ROOT = $(SRC_DIST_ROOT)/testsuite-ghc
1138 SRC_DIST_TESTSUITE_DIR = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
1139 SRC_DIST_TESTSUITE_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.$(TAR_COMP_EXT)
1140
1141 #
1142 # Files to include in source distributions
1143 #
1144 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
1145 utils docs rts compiler ghc driver libraries libffi-tarballs
1146 SRC_DIST_GHC_FILES += \
1147 configure.ac config.guess config.sub configure \
1148 aclocal.m4 README.md ANNOUNCE HACKING.md INSTALL.md LICENSE Makefile \
1149 install-sh settings.in VERSION GIT_COMMIT_ID \
1150 boot packages ghc.mk MAKEHELP.md
1151
1152 .PHONY: VERSION
1153 VERSION:
1154 @if test -f $@ && test "`cat $@`" = "$(ProjectVersion)"; \
1155 then echo "$@ needs no update"; \
1156 else echo "update $@ ($(ProjectVersion))"; echo "$(ProjectVersion)" > $@; fi
1157
1158 .PHONY: GIT_COMMIT_ID
1159 GIT_COMMIT_ID:
1160 @if test -d .git && test "`git rev-parse HEAD`" != "$(ProjectGitCommitId)"; then \
1161 echo "******************************************************************************"; \
1162 echo "Stale ProjectGitCommitId (=$(ProjectGitCommitId)) detected!"; \
1163 echo "'git rev-parse HEAD' says: `git rev-parse HEAD`"; \
1164 echo "Please re-run './configure' before creating source-distribution"; \
1165 echo "******************************************************************************"; \
1166 exit 1; \
1167 fi
1168 @if test -f $@ && test "`cat $@`" = "$(ProjectGitCommitId)"; \
1169 then echo "$@ needs no update"; \
1170 else echo "update $@ ($(ProjectGitCommitId))"; echo -n "$(ProjectGitCommitId)" > $@; fi
1171
1172 sdist-ghc-prep-tree : VERSION GIT_COMMIT_ID
1173
1174 # Extra packages which shouldn't be in the source distribution: see #8801
1175 EXTRA_PACKAGES=parallel stm random primitive vector dph
1176
1177 .PHONY: sdist-ghc-prep-tree
1178 sdist-ghc-prep-tree :
1179 $(call removeTrees,$(SRC_DIST_GHC_ROOT))
1180 $(call removeFiles,$(SRC_DIST_GHC_TARBALL))
1181 mkdir -p $(SRC_DIST_ROOT)
1182 mkdir -p $(SRC_DIST_GHC_ROOT)
1183 mkdir -p $(SRC_DIST_GHC_DIR)
1184 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_DIRS); do mkdir -p $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1185 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_FILES); do $(LN_S) $(TOP)/$$i .; done
1186 cd $(SRC_DIST_GHC_DIR) && $(MAKE) distclean
1187 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/tarballs/)
1188 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/stamp/)
1189 $(call removeTrees,$(SRC_DIST_GHC_DIR)/compiler/stage[123])
1190 $(call removeFiles,$(SRC_DIST_GHC_DIR)/mk/build.mk)
1191 for i in $(EXTRA_PACKAGES); do $(RM) $(RM_OPTS_REC) $(SRC_DIST_GHC_DIR)/libraries/$$i/; done
1192 cd $(SRC_DIST_GHC_DIR) && "$(FIND)" $(SRC_DIST_GHC_DIRS) \( -name .git -o -name "autom4te*" -o -name "*~" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" \) -print | "$(XARGS)" $(XARGS_OPTS) "$(RM)" $(RM_OPTS_REC)
1193
1194 # Add files generated by alex and happy.
1195 # These rules depend on sdist-ghc-prep-tree.
1196 $(eval $(call sdist-ghc-file,compiler,stage2,cmm,CmmLex,x))
1197 $(eval $(call sdist-ghc-file,compiler,stage2,cmm,CmmParse,y))
1198 $(eval $(call sdist-ghc-file,compiler,stage2,parser,Lexer,x))
1199 $(eval $(call sdist-ghc-file,compiler,stage2,parser,Parser,y))
1200 $(eval $(call sdist-ghc-file,utils/hpc,dist-install,,HpcParser,y))
1201 $(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Lexer,x))
1202 $(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Parser,y))
1203
1204 .PHONY: sdist-ghc-prep
1205 sdist-ghc-prep : sdist-ghc-prep-tree
1206
1207 .PHONY: sdist-windows-tarballs-prep
1208 sdist-windows-tarballs-prep :
1209 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_ROOT))
1210 $(call removeFiles,$(SRC_DIST_WINDOWS_TARBALLS_TARBALL))
1211 mkdir -p $(SRC_DIST_ROOT)
1212 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_ROOT)
1213 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)
1214 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs
1215 cd $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs && lndir $(TOP)/ghc-tarballs
1216 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs/.git)
1217
1218 .PHONY: sdist-testsuite-prep
1219 sdist-testsuite-prep :
1220 $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
1221 $(call removeFiles,$(SRC_DIST_TESTSUITE_TARBALL))
1222 mkdir -p $(SRC_DIST_ROOT)
1223 mkdir -p $(SRC_DIST_TESTSUITE_ROOT)
1224 mkdir -p $(SRC_DIST_TESTSUITE_DIR)
1225 mkdir -p $(SRC_DIST_TESTSUITE_DIR)/testsuite
1226 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && lndir $(TOP)/testsuite
1227 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && $(MAKE) distclean
1228
1229 .PHONY: sdist-ghc
1230 sdist-ghc: sdist-ghc-prep
1231 cd $(SRC_DIST_GHC_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_GHC_TARBALL)
1232
1233 .PHONY: sdist-windows-tarballs
1234 sdist-windows-tarballs: sdist-windows-tarballs-prep
1235 cd $(SRC_DIST_WINDOWS_TARBALLS_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> windows_extra_src_ghc_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_WINDOWS_TARBALLS_TARBALL)
1236
1237 .PHONY: sdist-testsuite
1238 sdist-testsuite: sdist-testsuite-prep
1239 cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> testsuite_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
1240
1241
1242 .PHONY: sdist
1243 sdist : sdist-ghc sdist-windows-tarballs sdist-testsuite
1244
1245 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
1246 tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1247
1248 # Upload the distribution(s)
1249 # Retrying is to work around buggy firewalls that corrupt large file transfers
1250 # over SSH.
1251 ifneq "$(PublishLocation)" ""
1252 publish-sdist :
1253 $(call try10Times,$(PublishCp) $(SRC_DIST_GHC_TARBALL) $(PublishLocation)/dist)
1254 $(call try10Times,$(PublishCp) $(SRC_DIST_TESTSUITE_TARBALL) $(PublishLocation)/dist)
1255 endif
1256
1257 # -----------------------------------------------------------------------------
1258 # sdisting libraries
1259
1260 # Use manually, with e.g.:
1261 # make sdist_directory
1262
1263 sdist_%:
1264 inplace/bin/ghc-cabal sdist libraries/$* dist-install
1265
1266 # -----------------------------------------------------------------------------
1267 # Cleaning
1268
1269 .PHONY: clean
1270
1271 CLEAN_FILES += libraries/integer-gmp/include/HsIntegerGmp.h
1272 CLEAN_FILES += libraries/base/include/EventConfig.h
1273 CLEAN_FILES += mk/config.mk.old
1274 CLEAN_FILES += mk/project.mk.old
1275 CLEAN_FILES += compiler/ghc.cabal.old
1276
1277 # These are no longer generated, but we still clean them for a while
1278 # as they may still be in old GHC trees:
1279 CLEAN_FILES += includes/GHCConstants.h
1280 CLEAN_FILES += includes/DerivedConstants.h
1281 CLEAN_FILES += includes/ghcautoconf.h
1282 CLEAN_FILES += includes/ghcplatform.h
1283 CLEAN_FILES += includes/ghcversion.h
1284 CLEAN_FILES += utils/ghc-pkg/Version.hs
1285 CLEAN_FILES += compiler/prelude/primops.txt
1286 CLEAN_FILES += $(wildcard compiler/primop*incl)
1287
1288 clean : clean_files clean_libraries
1289
1290 .PHONY: clean_files
1291 clean_files :
1292 $(call removeFiles,$(CLEAN_FILES))
1293 # this is here since CLEAN_FILES can't handle folders
1294 $(call removeTrees,includes/dist-derivedconstants)
1295 $(call removeTrees,inplace/bin)
1296 $(call removeTrees,inplace/lib)
1297 $(call removeTrees,libraries/bootstrapping.conf)
1298
1299 .PHONY: clean_libraries
1300 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2))
1301 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(PACKAGES_STAGE0))
1302
1303 clean_libraries:
1304 $(call removeTrees,$(patsubst %, libraries/%/dist, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1305 $(call removeFiles,$(wildcard $(patsubst %.in, %, $(wildcard $(patsubst %, libraries/%/*.buildinfo.in, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))))
1306 $(call removeFiles,$(patsubst %, libraries/%/config.log, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1307 $(call removeFiles,$(patsubst %, libraries/%/config.status, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1308 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1309
1310 # We have to define a clean target for each library manually, because the
1311 # libraries/*/ghc.mk files are not included when we're cleaning.
1312 ifeq "$(CLEANING)" "YES"
1313 $(foreach lib,$(PACKAGES_STAGE0),\
1314 $(eval $(call clean-target,libraries/$(lib),dist-boot,libraries/$(lib)/dist-boot)))
1315 $(foreach lib,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),\
1316 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1317 endif
1318
1319 clean : clean_haddock_index
1320 .PHONY: clean_haddock_index
1321 clean_haddock_index:
1322 $(call removeTrees,libraries/dist-haddock)
1323
1324 clean : clean_bindistprep
1325 .PHONY: clean_bindistprep
1326 clean_bindistprep:
1327 $(call removeTrees,bindistprep/)
1328
1329 distclean : clean
1330 # Clean the files that ./validate creates.
1331 $(call removeFiles,mk/are-validating.mk)
1332
1333 # Clean the files that we ask ./configure to create.
1334 $(call removeFiles,mk/config.mk)
1335 $(call removeFiles,mk/install.mk)
1336 $(call removeFiles,mk/project.mk)
1337 $(call removeFiles,compiler/ghc.cabal)
1338 $(call removeFiles,ghc/ghc-bin.cabal)
1339 $(call removeFiles,utils/runghc/runghc.cabal)
1340 $(call removeFiles,settings)
1341 $(call removeFiles,docs/users_guide/ug-book.xml)
1342 $(call removeFiles,docs/users_guide/ug-ent.xml)
1343 $(call removeFiles,docs/index.html)
1344 $(call removeFiles,libraries/prologue.txt)
1345 $(call removeFiles,distrib/configure.ac)
1346 $(call removeFiles,ch01.html ch02.html index.html)
1347
1348 # ./configure also makes these.
1349 $(call removeFiles,mk/config.h)
1350
1351 # Internal files generated by ./configure for itself.
1352 $(call removeFiles,config.cache config.status config.log)
1353
1354 # ./configure build ghc-pwd in utils/ghc-pwd/dist-boot, so clean it up.
1355 $(call removeTrees,utils/ghc-pwd/dist-boot)
1356
1357 # The root Makefile makes .old versions of some files that configure
1358 # generates, so we clean those too.
1359 $(call removeFiles,mk/config.mk.old)
1360 $(call removeFiles,mk/project.mk.old)
1361 $(call removeFiles,compiler/ghc.cabal.old)
1362
1363 # Clean the *Config.h files generated by library configure scripts
1364 $(call removeFiles,libraries/base/include/HsBaseConfig.h)
1365 $(call removeFiles,libraries/base/include/EventConfig.h)
1366 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
1367 $(call removeFiles,libraries/process/include/HsProcessConfig.h)
1368 $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
1369 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h)
1370
1371 # The library configure scripts also like creating autom4te.cache
1372 # directories, so clean them all up.
1373 $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1374
1375 # We make these when making or testing bindists
1376 $(call removeFiles,bindist-list)
1377 $(call removeTrees,bindisttest/a)
1378
1379 # Not sure why this is being cleaned here.
1380 $(call removeTrees,includes/dist-derivedconstants)
1381
1382 # Finally, clean the inplace tree.
1383 $(call removeTrees,inplace)
1384
1385 maintainer-clean : distclean
1386 $(call removeFiles,configure mk/config.h.in)
1387 $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
1388 $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
1389 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1390 $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1391 $(call removeFiles,$(patsubst %, libraries/%/configure, \
1392 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1393 $(call removeFiles,libraries/base/include/HsBaseConfig.h.in)
1394 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
1395 $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
1396 $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
1397 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h.in)
1398
1399 .PHONY: all_libraries
1400
1401 .PHONY: bootstrapping-files
1402 # See https://ghc.haskell.org/trac/ghc/wiki/Building/Porting
1403 bootstrapping-files: $(includes_H_CONFIG)
1404 bootstrapping-files: $(includes_DERIVEDCONSTANTS)
1405 bootstrapping-files: $(includes_GHCCONSTANTS)
1406 bootstrapping-files: $(libffi_HEADERS)
1407
1408 .DELETE_ON_ERROR:
1409
1410 # -----------------------------------------------------------------------------
1411
1412 ifeq "$(HADDOCK_DOCS)" "YES"
1413 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
1414 endif
1415 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
1416 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
1417 else
1418 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
1419 endif
1420 BINDIST_LIBRARY_FLAGS += --disable-library-prof
1421
1422 .PHONY: validate_build_xhtml
1423 validate_build_xhtml:
1424 cd libraries/xhtml && "$(BINDIST_PREFIX)/bin/ghc" --make Setup
1425 cd libraries/xhtml && ./Setup configure --with-ghc="$(BINDIST_PREFIX)/bin/ghc" $(BINDIST_HADDOCK_FLAG) $(BINDIST_LIBRARY_FLAGS) --global --builddir=dist-bindist --prefix="$(BINDIST_PREFIX)"
1426 cd libraries/xhtml && ./Setup build --builddir=dist-bindist
1427 ifeq "$(HADDOCK_DOCS)" "YES"
1428 cd libraries/xhtml && ./Setup haddock -v0 --ghc-options=-optP-P --builddir=dist-bindist
1429 endif
1430 cd libraries/xhtml && ./Setup install --builddir=dist-bindist
1431 cd libraries/xhtml && ./Setup clean --builddir=dist-bindist
1432 cd libraries/xhtml && rm -f Setup Setup.exe Setup.hi Setup.o
1433
1434 # Note [No stage2 packages when CrossCompiling or Stage1Only]
1435 #
1436 # (first read Note [CrossCompiling vs Stage1Only] and
1437 # Note [Stage1Only vs stage=1] in mk/config.mk.in)
1438 #
1439 # When either CrossCompiling=YES or Stage1Only=YES, we have to exclude the
1440 # following packages from the build:
1441 # * packages that we build with ghc-stage2 [1]
1442 # * packages that depend on the ghc library [2]
1443 #
1444 # Here's why:
1445 # - first of all, ghc-stage1 can't use stage0's ghc library (it's too old)
1446 # - neither do we register the ghc library (compiler/stage1) that we build
1447 # with stage0. TODO Why not? We do build it...
1448 # - as a result, we need to a) use ghc-stage2 to build packages that depend on
1449 # the ghc library (e.g. ghctags [4] and mkUserGuidePart) and b) exclude
1450 # those packages when ghc-stage2 is not available.
1451 # - when Stage1Only=YES, it's clear that ghc-stage2 is not available (we just
1452 # said we didn't want it), so we have to exclude the stage2 packages from
1453 # the build. This includes the case where Stage1Only=YES is combined with
1454 # CrossCompiling=YES (Building GHC as a cross-compiler [3]).
1455 # - when CrossCompiling=YES, but Stage1Only=NO (Cross-compiling GHC itself
1456 # [3]), we can not use ghc-stage2 either. The reason is that stage2 doesn't
1457 # run on the host platform at all; it is built to run on $(TARGETPLATFORM)"
1458 # [5]. Therefore in this case we also have to exclude the stage2 packages
1459 # from the build.
1460 #
1461 # [1] find utils -name ghc.mk | xargs grep -l 'build-prog.*,2'
1462 #
1463 # [2]
1464 # find utils -name package-data.mk | xargs grep -l 'DEP_NAMES =.* ghc\($\| \)'
1465 #
1466 # [3] https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling
1467 #
1468 # [4] 5fb72555f7b7ab67a33583f33ad9160761ca434f
1469 # "ghctags needs the stage2 compiler, since it uses the GHC API."
1470 #
1471 # [5] * bc31dbe8ee22819054df60f5ef219fed393a1c54
1472 # "Disable any packages built with stage 2 when cross-compiling
1473 # Since we can't run stage 2 on the host."
1474 #
1475 # * 72995160b0b190577b5c0cb8d7bd0426cc455b05
1476 # "We cannot use the stage 2 compiler, it runs on $(TARGETPLATFORM)"
1477
1478 # -----------------------------------------------------------------------------
1479 # Numbered phase targets
1480
1481 # In phase 1, we'll be building dependency files for most things
1482 # built by the bootstrapping compiler while make is 'include'ing
1483 # makefiles. But in order to build dependency files, we'll need to
1484 # build any automatically generated .hs files, which means that
1485 # we'll need to be able to build any tools that generate .hs files
1486 # etc. But in order to do that, we need to already know the
1487 # dependencies for those tools, so we build their dependency files
1488 # here.
1489 .PHONY: phase_0_builds
1490 # hsc2hs is needed, e.g. to make the .hs files for hpc.
1491 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1492 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1493 # genprimopcode is needed to make the .hs-incl files that are in the
1494 # ghc package.
1495 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1496 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1497 # deriveConstants is used to create header files included in the
1498 # ghc package.
1499 phase_0_builds: $(utils/deriveConstants_dist_depfile_haskell)
1500 phase_0_builds: $(utils/deriveConstants_dist_depfile_c_asm)
1501
1502 .PHONY: phase_1_builds
1503 phase_1_builds: $(PACKAGE_DATA_MKS)
1504