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