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