[ typo ] 'castFloatToWord32' -> 'castFloatToWord64'
[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 # https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
9 # https://gitlab.haskell.org/ghc/ghc/wikis/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 # https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture/idiom/phase-ordering
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 https://gitlab.haskell.org/ghc/ghc/wikis/building/troubleshooting#make-has-restarted-itself-3-times-is-there-a-makefile-bug 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://gitlab.haskell.org/ghc/ghc/wikis/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://gitlab.haskell.org/ghc/ghc/wikis/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://gitlab.haskell.org/ghc/ghc/wikis/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 endif # CLEANING
207
208 # -----------------------------------------------------------------------------
209
210 ifeq "$(phase)" ""
211 phase = final
212 endif
213
214 # -----------------------------------------------------------------------------
215 # Utility definitions
216
217 include rules/prof.mk
218 include rules/trace.mk
219 include rules/library-path.mk
220 include rules/add-dependency.mk
221 include rules/make-command.mk
222 include rules/pretty_commands.mk
223
224 # -----------------------------------------------------------------------------
225 # Macros for standard targets
226
227 include rules/all-target.mk
228 include rules/clean-target.mk
229
230 # -----------------------------------------------------------------------------
231 # The inplace tree
232
233 $(eval $(call clean-target,root,inplace,inplace/bin inplace/lib))
234
235 # -----------------------------------------------------------------------------
236 # Whether to build dependencies or not
237
238 # When we're just doing 'make clean' or 'make show', then we don't need
239 # to build dependencies.
240
241 ifeq "$(CLEANING)" "YES"
242 NO_INCLUDE_DEPS = YES
243 NO_INCLUDE_PKGDATA = YES
244 endif
245 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
246 NO_INCLUDE_DEPS = YES
247 NO_INCLUDE_PKGDATA = YES
248 endif
249 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
250 NO_INCLUDE_DEPS = YES
251 # We want package-data.mk for show
252 endif
253
254 # -----------------------------------------------------------------------------
255 # Ways
256
257 include rules/way-prelims.mk
258
259 $(foreach way,$(ALL_WAYS),\
260 $(eval $(call way-prelims,$(way))))
261
262 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
263 GHCI_WAY = dyn
264 HADDOCK_WAY = dyn
265 else
266 GHCI_WAY = v
267 HADDOCK_WAY = v
268 endif
269
270 WINDOWS_DYN_PROG_RTS := rts
271 ifeq "$(GhcThreaded)" "YES"
272 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_thr
273 endif
274 ifeq "$(GhcDebugged)" "YES"
275 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_debug
276 endif
277 WINDOWS_DYN_PROG_RTS := $(WINDOWS_DYN_PROG_RTS)_dyn_LIB_FILE
278
279 # -----------------------------------------------------------------------------
280 # Compilation Flags
281
282 include rules/distdir-opts.mk
283 include rules/distdir-way-opts.mk
284
285 # -----------------------------------------------------------------------------
286 # Finding source files and object files
287
288 include rules/hs-sources.mk
289 include rules/c-sources.mk
290 include rules/includes-sources.mk
291 include rules/hs-objs.mk
292 include rules/c-objs.mk
293 include rules/cmm-objs.mk
294
295 # -----------------------------------------------------------------------------
296 # Suffix rules
297
298 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
299 # so we don't make any when cleaning.
300 ifneq "$(CLEANING)" "YES"
301 include rules/hs-suffix-rules-srcdir.mk
302 include rules/hs-suffix-way-rules-srcdir.mk
303 include rules/hs-suffix-way-rules.mk
304 include rules/hi-rule.mk
305 include rules/c-suffix-rules.mk
306 include rules/cmm-suffix-rules.mk
307 endif
308
309 # -----------------------------------------------------------------------------
310 # Building package-data.mk files from .cabal files
311
312 include rules/package-config.mk
313
314 # -----------------------------------------------------------------------------
315 # Building dependencies
316
317 include rules/dependencies.mk
318 include rules/build-dependencies.mk
319 include rules/include-dependencies.mk
320
321 # -----------------------------------------------------------------------------
322 # Build package-data.mk files
323
324 include rules/build-package-data.mk
325
326 # -----------------------------------------------------------------------------
327 # Build and install a program
328
329 include rules/build-prog.mk
330 include rules/shell-wrapper.mk
331
332 # -----------------------------------------------------------------------------
333 # Build a package
334
335 include rules/build-package.mk
336 include rules/build-package-way.mk
337 include rules/haddock.mk
338 include rules/foreachLibrary.mk
339
340 # -----------------------------------------------------------------------------
341 # Registering hand-written package descriptions (used in rts)
342
343 include rules/manual-package-config.mk
344
345 # -----------------------------------------------------------------------------
346 # Docs
347
348 include rules/sphinx.mk
349
350 # -----------------------------------------------------------------------------
351 # Making bindists and sdists
352
353 include rules/bindist.mk
354 include rules/sdist-ghc-file.mk
355
356 # -----------------------------------------------------------------------------
357 # Directories
358
359 # Don't try to delete directories:
360 .PRECIOUS: %/.
361
362 # Create build directories on demand. NB. the | below: this indicates
363 # that $(MKDIRHIER) is an order-only dependency, which means that this
364 # rule fires after building mkdirhier, but we won't try to recreate
365 # directories if mkdirhier changes.
366 %/. : | $(MKDIRHIER)
367 "$(MKDIRHIER)" $@
368
369 # -----------------------------------------------------------------------------
370 # Lax dependencies
371
372 ifeq "$(LAX_DEPENDENCIES)" "YES"
373 LAX_DEPS_FOLLOW = |
374 else
375 LAX_DEPS_FOLLOW =
376 endif
377
378 # This is a bit of a hack. When LAX_DEPS_FOLLOW is | some rules end up
379 # looking like
380 # target: a | b | c
381 # The first | signals the start of the order-only dependencies, but make
382 # treats the second | as a dependency. So we need to tell make how to
383 # build that dependency.
384
385 .PHONY: |
386 | :
387 @:
388
389 # -----------------------------------------------------------------------------
390 # Packages to build
391 # The lists of packages that we *actually* going to build in each stage:
392 #
393 # $(PACKAGES_STAGE0)
394 # $(PACKAGES_STAGE1)
395 # $(PACKAGES_STAGE2)
396 #
397 # Note that we need to add them to these variables in dependency
398 # order, as this is the order that they get configured in.
399
400 ifeq "$(CLEANING)" "YES"
401
402 define addLibraryForCleaning
403 # We just add all packages to both the stage 0 and stage 1 lists.
404 # Stage 2 gets cleaned in the same way as stage 1, so no need to
405 # add it there.
406 PACKAGES_STAGE0 += $1
407 PACKAGES_STAGE1 += $1
408 endef
409 $(eval $(call foreachLibrary,addLibraryForCleaning))
410
411 else # CLEANING
412
413 # Packages that are built by stage0. These packages are dependencies of
414 # programs such as GHC and ghc-pkg, that we do not assume the stage0
415 # compiler already has installed (or up-to-date enough).
416
417 PACKAGES_STAGE0 = binary text transformers mtl parsec Cabal/Cabal hpc ghc-boot-th ghc-boot template-haskell ghc-heap ghci
418 ifeq "$(Windows_Host)" "NO"
419 PACKAGES_STAGE0 += terminfo
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_Target)" "YES"
432 PACKAGES_STAGE1 += Win32
433 endif
434 PACKAGES_STAGE1 += time
435 ifeq "$(Windows_Target)" "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 += text
445 PACKAGES_STAGE1 += transformers
446 PACKAGES_STAGE1 += mtl
447 PACKAGES_STAGE1 += parsec
448 PACKAGES_STAGE1 += Cabal/Cabal
449 PACKAGES_STAGE1 += ghc-boot-th
450 PACKAGES_STAGE1 += ghc-boot
451 PACKAGES_STAGE1 += template-haskell
452 PACKAGES_STAGE1 += ghc-compact
453 PACKAGES_STAGE1 += ghc-heap
454
455 ifeq "$(HADDOCK_DOCS)" "YES"
456 PACKAGES_STAGE1 += xhtml
457 endif
458
459 ifeq "$(WITH_TERMINFO)" "YES"
460 PACKAGES_STAGE1 += terminfo
461 else
462 libraries/haskeline_CONFIGURE_OPTS += --flags=-terminfo
463 endif
464
465 PACKAGES_STAGE1 += stm
466 PACKAGES_STAGE1 += haskeline
467 PACKAGES_STAGE1 += ghci
468 PACKAGES_STAGE1 += libiserv
469
470 # See Note [No stage2 packages when CrossCompiling or Stage1Only].
471 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
472 ifeq "$(CrossCompiling) $(Stage1Only)" "NO NO"
473 define addExtraPackage
474 ifeq "$2" "-"
475 # Do nothing; this package is already handled above
476 else ifeq "$2" "extra"
477 ifeq "$$(BUILD_EXTRA_PKGS)" "YES"
478 PACKAGES_STAGE2 += $1
479 endif
480 else
481 $$(error Unknown package tag: $2)
482 endif
483 endef
484 $(eval $(call foreachLibrary,addExtraPackage))
485 endif
486
487 # We install all packages that we build.
488 INSTALL_PACKAGES := $(addprefix libraries/,$(PACKAGES_STAGE1))
489 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
490 ifneq "$(Stage1Only)" "YES"
491 INSTALL_PACKAGES += compiler
492 endif
493 INSTALL_PACKAGES += $(addprefix libraries/,$(PACKAGES_STAGE2))
494
495 endif # CLEANING
496
497 # -------------------------------------------
498 # Note [Dependencies between package-data.mk files].
499
500 # We cannot run ghc-cabal to configure a package until we have
501 # configured and registered all of its dependencies. So the following
502 # hack forces all the configure steps to happen in exactly the following order:
503 #
504 # $(PACKAGES_STAGE1) ghc(stage2) $(PACKAGES_STAGE2)
505 #
506 # Ideally we should use the correct dependencies here to allow more
507 # parallelism, but we don't know the dependencies until we've
508 # generated the package-data.mk files.
509 define fixed_pkg_dep
510 libraries/$1/$2/package-data.mk : $$(fixed_pkg_prev)
511 fixed_pkg_prev:=libraries/$1/$2/package-data.mk
512 endef
513
514 ifneq "$(BINDIST)" "YES"
515 fixed_pkg_prev=
516 $(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
517
518 # Intermezzo: utils that we build with the stage1 compiler. They depend on
519 # the stage1 packages, so we have to make sure those packages get configured
520 # and registered before we can start with these. Note that they don't depend on
521 # eachother, so we can configure them in parallel.
522 utils/ghc-cabal/dist-install/package-data.mk: $(fixed_pkg_prev)
523 utils/hpc/dist-install/package-data.mk: $(fixed_pkg_prev)
524 utils/ghc-pkg/dist-install/package-data.mk: $(fixed_pkg_prev)
525 utils/hsc2hs/dist-install/package-data.mk: $(fixed_pkg_prev)
526 utils/compare_sizes/dist-install/package-data.mk: $(fixed_pkg_prev)
527 utils/runghc/dist-install/package-data.mk: $(fixed_pkg_prev)
528 utils/iserv/stage2/package-data.mk: $(fixed_pkg_prev)
529 utils/iserv/stage2_p/package-data.mk: $(fixed_pkg_prev)
530 utils/iserv/stage2_dyn/package-data.mk: $(fixed_pkg_prev)
531 ifeq "$(Windows_Host)" "YES"
532 utils/gen-dll/dist-install/package-data.mk: $(fixed_pkg_prev)
533 endif
534
535 # the GHC package doesn't live in libraries/, so we add its dependency manually:
536 compiler/stage2/package-data.mk: $(fixed_pkg_prev)
537
538 # and continue with PACKAGES_STAGE2, which depend on GHC:
539 fixed_pkg_prev:=compiler/stage2/package-data.mk
540 $(foreach pkg,$(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
541
542 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
543 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
544
545 # Utils that we build with the stage2 compiler.
546 # They depend on the ghc library and some other libraries, but depending on
547 # the ghc library's package-data.mk is sufficient, as that in turn depends on
548 # all the other libraries' package-data.mk files.
549 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
550 utils/check-api-annotations/dist-install/package-data.mk: compiler/stage2/package-data.mk
551 utils/check-ppr/dist-install/package-data.mk: compiler/stage2/package-data.mk
552
553 # add the final package.conf dependency: ghc-prim depends on RTS
554 libraries/ghc-prim/dist-install/package-data.mk : rts/dist/package.conf.inplace
555 endif
556
557 # --------------------------------
558 # Misc package-related settings
559
560 # Run Haddock for the packages that will be installed. We need to handle
561 # compiler specially due to the different dist directory name.
562 $(foreach p,$(INSTALL_PACKAGES),$(eval $p_dist-install_DO_HADDOCK = YES))
563 compiler_stage2_DO_HADDOCK = YES
564
565 BOOT_PKG_CONSTRAINTS := \
566 $(foreach d,$(PACKAGES_STAGE0),\
567 $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
568 --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
569
570 # The actual .a and .so/.dll files: needed for dependencies.
571 $(foreach way,$(GhcLibWays),$(eval ALL_STAGE1_$(way)_LIBS = $$(foreach lib,$$(PACKAGES_STAGE1),$$(libraries/$$(lib)_dist-install_$(way)_LIB))))
572
573 ALL_STAGE1_LIBS = $(ALL_STAGE1_v_LIBS)
574
575 ifeq "$(BuildSharedLibs)" "YES"
576 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_dyn_LIB))
577 endif
578 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
579
580 # Only build internal interpreter support for the stage2 ghci lib
581 libraries/ghci_dist-install_CONFIGURE_OPTS += --flags=ghci
582
583 # ----------------------------------------
584 # Special magic for the ghc-prim package
585
586 # We want the ghc-prim package to include the GHC.Prim module when it
587 # is registered, but not when it is built, because GHC.Prim is not a
588 # real source module, it is built-in to GHC.
589
590 # Strip it out again before building the package:
591 define libraries/ghc-prim_PACKAGE_MAGIC
592 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
593 endef
594
595 PRIMOPS_TXT_STAGE1 = compiler/stage1/build/primops.txt
596
597 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $$(genprimopcode_INPLACE) $(PRIMOPS_TXT_STAGE1) | $$(dir $$@)/.
598 "$(genprimopcode_INPLACE)" --make-haskell-wrappers < $(PRIMOPS_TXT_STAGE1) >$@
599
600 # Required so that Haddock documents the primops.
601 libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
602
603 # ----------------------------------------
604 # Special magic for the integer package
605
606 ifneq "$(CLEANING)" "YES"
607 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
608 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-gmp
609 compiler_stage2_CONFIGURE_OPTS += --flags=integer-gmp
610 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
611 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
612 compiler_stage2_CONFIGURE_OPTS += --flags=integer-simple
613 else
614 $(error Unknown integer library: $(INTEGER_LIBRARY))
615 endif
616 endif
617
618 # -----------------------------------------------------------------------------
619 # Include build instructions from all subdirs
620 BUILD_DIRS += utils/mkdirhier
621 BUILD_DIRS += utils/touchy
622 BUILD_DIRS += utils/unlit
623 BUILD_DIRS += utils/hp2ps
624 BUILD_DIRS += utils/genprimopcode
625 BUILD_DIRS += driver
626 BUILD_DIRS += driver/ghci
627 BUILD_DIRS += driver/ghc
628 BUILD_DIRS += driver/haddock
629 BUILD_DIRS += libffi
630 BUILD_DIRS += utils/deriveConstants
631 BUILD_DIRS += includes
632 BUILD_DIRS += rts
633 BUILD_DIRS += bindisttest
634 BUILD_DIRS += utils/genapply
635 ifeq "$(Windows_Host)" "YES"
636 BUILD_DIRS += utils/gen-dll
637 endif
638
639 # When cleaning, don't add any library packages to BUILD_DIRS. We include
640 # ghc.mk files for all BUILD_DIRS, but they don't exist until after running
641 # `./boot`. Running `make clean` before anything else, as well as running
642 # `make maintainer-clean` twice, should work.
643 ifneq "$(CLEANING)" "YES"
644 # These are deliberately in reverse order, so as to ensure that
645 # there is no need to have them in dependency order. That's important
646 # because it's tricky to ensure that they are in dependency order when
647 # cross-compiling, as some packages may only be in PACKAGES_STAGE0
648 # or PACKAGES_STAGE1.
649 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
650 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE1))
651 BUILD_DIRS += $(patsubst %, libraries/%, $(filter-out $(PACKAGES_STAGE1),$(PACKAGES_STAGE0)))
652 endif
653
654 BUILD_DIRS += libraries/integer-gmp/gmp
655 BUILD_DIRS += utils/haddock
656 BUILD_DIRS += utils/haddock/doc
657 BUILD_DIRS += compiler
658 BUILD_DIRS += utils/hsc2hs
659 BUILD_DIRS += utils/ghc-pkg
660 BUILD_DIRS += utils/testremove
661 BUILD_DIRS += utils/check-api-annotations
662 BUILD_DIRS += utils/check-ppr
663 BUILD_DIRS += utils/ghc-cabal
664 BUILD_DIRS += utils/hpc
665 BUILD_DIRS += utils/runghc
666 BUILD_DIRS += ghc
667 BUILD_DIRS += docs/users_guide
668 BUILD_DIRS += utils/compare_sizes
669 BUILD_DIRS += utils/iserv
670
671 # ----------------------------------------------
672 # Actually include the sub-ghc.mk's
673
674 ifeq "$(CLEANING)" "YES"
675 # Don't exclude any BUILD_DIRS when cleaning. When you for example build
676 # haddock once, but later set HADDOCK_DOCS back to NO, then 'make clean'
677 # should still clean the haddock directory.
678 else # CLEANING
679 ifeq "$(BINDIST)" "YES"
680 BUILD_DIRS := $(filter-out utils/mkdirhier,$(BUILD_DIRS))
681 BUILD_DIRS := $(filter-out utils/genprimopcode,$(BUILD_DIRS))
682 BUILD_DIRS := $(filter-out bindisttest,$(BUILD_DIRS))
683 BUILD_DIRS := $(filter-out utils/genapply,$(BUILD_DIRS))
684 endif
685 ifeq "$(HADDOCK_DOCS)" "NO"
686 BUILD_DIRS := $(filter-out utils/haddock,$(BUILD_DIRS))
687 BUILD_DIRS := $(filter-out utils/haddock/doc,$(BUILD_DIRS))
688 endif
689 ifeq "$(BUILD_SPHINX_HTML) $(BUILD_SPHINX_PDF)" "NO NO"
690 BUILD_DIRS := $(filter-out docs/users_guide,$(BUILD_DIRS))
691 # Don't to build this little utility if we're not building the User's Guide.
692 endif
693 ifeq "$(Windows_Host)" "NO"
694 BUILD_DIRS := $(filter-out utils/touchy,$(BUILD_DIRS))
695 endif
696 ifeq "$(GhcWithInterpreter)" "NO"
697 # runghc is just GHCi in disguise
698 BUILD_DIRS := $(filter-out utils/runghc,$(BUILD_DIRS))
699 endif
700 ifneq "$(INTEGER_LIBRARY)" "integer-gmp"
701 BUILD_DIRS := $(filter-out libraries/integer-gmp/gmp,$(BUILD_DIRS))
702 endif
703 ifneq "$(CrossCompiling) $(Stage1Only)" "NO NO"
704 # See Note [No stage2 packages when CrossCompiling or Stage1Only].
705 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
706 BUILD_DIRS := $(filter-out utils/check-api-annotations,$(BUILD_DIRS))
707 BUILD_DIRS := $(filter-out utils/check-ppr,$(BUILD_DIRS))
708 endif
709 endif # CLEANING
710
711 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
712
713 # A useful pseudo-target (must be after the include above, because it needs
714 # the value of things like $(libraries/base_dist-install_v_LIB).
715 .PHONY: stage1_libs
716 stage1_libs : $(ALL_STAGE1_LIBS)
717
718 # We need this extra dependency when building our own libffi, because
719 # GHCi.FFI.hs #includes ffi.h
720 ifneq "$(UseSystemLibFFI)" "YES"
721 libraries/ghci/dist-install/build/GHCi/FFI.hs : $(libffi_HEADERS)
722 endif
723
724 # ----------------------------------------------
725 # Per-package compiler flags
726 #
727 # If you want to add per-package compiler flags, see `mk/warnings.mk`.
728
729 # Add $(GhcLib(Extra)HcOpts) to all package builds
730 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
731 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_EXTRA_HC_OPTS += $$(GhcLibExtraHcOpts)))
732
733 # Add $(GhcBootLib(Extra)HcOpts) to all stage0 package builds
734 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
735 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_EXTRA_HC_OPTS += $$(GhcBootLibExtraHcOpts)))
736
737 # -----------------------------------------------------------------------------
738 # Bootstrapping libraries
739
740 # We need to build a few libraries with the installed GHC, since GHC itself
741 # and some of the tools depend on them:
742
743 ifneq "$(BINDIST)" "YES"
744
745 ifneq "$(BOOTSTRAPPING_CONF)" ""
746 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
747 $(shell "$(GHC_PKG)" init $(BOOTSTRAPPING_CONF))
748 endif
749 endif
750
751 $(eval $(call clean-target,root,bootstrapping_conf,$(BOOTSTRAPPING_CONF)))
752
753 # register the boot packages in strict sequence, because running
754 # multiple ghc-pkgs in parallel doesn't work (registrations may get
755 # lost).
756 fixed_pkg_prev=
757 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
758 # ghc-pkg, unlike other utils that we build with the stage0 compiler (TODO: is
759 # this really true?), depends on several boot packages (e.g. Cabal and
760 # ghc-boot). They need to be configured before ghc-pkg, so we add a
761 # dependency between their package-data.mk files. See also Note
762 # [Dependencies between package-data.mk files].
763 utils/ghc-pkg/dist/package-data.mk: $(fixed_pkg_prev)
764 compiler/stage1/package-data.mk: $(fixed_pkg_prev)
765 endif
766
767 ifneq "$(BINDIST)" "YES"
768 # Make sure we have all the GHCi libs by the time we've built
769 # ghc-stage2.
770 #
771 GHCI_LIBS = \
772 $(foreach way,$(GhcLibWays),\
773 $(foreach lib,$(PACKAGES_STAGE1),\
774 $(libraries/$(lib)_dist-install_$(way)_GHCI_LIB)) \
775 $(compiler_stage2_$(way)_GHCI_LIB))
776
777 ifeq "$(UseArchivesForGhci)" "NO"
778 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
779 endif
780
781 ifeq "$(UseArchivesForGhci)" "YES"
782 GHCI_lib_way = v
783 else
784 GHCI_lib_way = GHCI
785 endif
786
787 # Deps for TH uses in libraries
788 $(foreach way, $(GhcLibWays),$(eval \
789 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
790 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
791 ))
792 endif
793
794 # -----------------------------------------------
795 # Haddock-related bits
796
797 # Build the Haddock contents and index
798 ifeq "$(HADDOCK_DOCS)" "YES"
799 libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
800 cd libraries && sh gen_contents_index --intree
801 ifeq "$(phase)" "final"
802 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
803 endif
804 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
805 endif
806
807 # -----------------------------------------------------------------------------
808 # Creating a local mingw copy on Windows
809
810 ifeq "$(Windows_Host)" "YES"
811
812 install : install_mingw
813 .PHONY: install_mingw
814 install_mingw : $(INPLACE_MINGW)
815 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
816
817 endif # Windows_Host
818
819 ifneq "$(BINDIST)" "YES"
820 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
821 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
822 endif # BINDIST
823
824 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
825 $(PRIMOPS_TXT_STAGE1) $$(genprimopcode_INPLACE) \
826 | $$(dir $$@)/.
827 "$(genprimopcode_INPLACE)" --make-haskell-source < $< > $@
828
829 # -----------------------------------------------------------------------------
830 # Installation
831
832 install: install_libs install_packages install_libexecs \
833 install_bins install_libexec_scripts
834 ifeq "$(HADDOCK_DOCS)" "YES"
835 install: install_docs
836 endif
837
838 define installLibsTo
839 # $1 = libraries to install
840 # $2 = directory to install to
841 #
842 # The .dll case calls STRIP_CMD explicitly, instead of `install -s`, because
843 # on Win64, "install -s" calls a strip that doesn't understand 64bit binaries.
844 # For some reason, this means the DLLs end up non-executable, which means
845 # executables that use them just segfault.
846 $(INSTALL_DIR) $2
847 for i in $1; do \
848 case $$i in \
849 *.a) \
850 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $2; \
851 $(RANLIB_CMD) $2/`basename $$i` ;; \
852 *.dll) \
853 $(INSTALL_PROGRAM) $(INSTALL_OPTS) $$i $2 ; \
854 $(STRIP_CMD) $2/`basename $$i` ;; \
855 *.so) \
856 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $2 ;; \
857 *.dylib) \
858 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $2;; \
859 *) \
860 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $2; \
861 esac; \
862 done
863 endef
864
865 install_bins: $(INSTALL_BINS) $(INSTALL_SCRIPTS)
866 $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
867 ifneq "$(INSTALL_BINS)" ""
868 for i in $(INSTALL_BINS); do \
869 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(bindir)" ; \
870 done
871 endif
872 ifneq "$(INSTALL_SCRIPTS)" ""
873 for i in $(INSTALL_SCRIPTS); do \
874 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i "$(DESTDIR)$(bindir)" ; \
875 done
876 endif
877
878 install_libs: $(INSTALL_LIBS)
879 $(call installLibsTo, $(INSTALL_LIBS), "$(DESTDIR)$(ghclibdir)")
880
881 # We rename ghc-stage2, so that the right program name is used in error
882 # messages etc. But not on windows.
883 RENAME_LIBEXEC_GHC_STAGE_TO_GHC = YES
884 ifeq "$(Stage1Only) $(Windows_Host)" "YES YES"
885 # resulting ghc-stage1 is built to run on windows
886 RENAME_LIBEXEC_GHC_STAGE_TO_GHC = NO
887 endif
888 ifeq "$(Stage1Only) $(Windows_Target)" "NO YES"
889 # resulting ghc-stage1 is built to run on windows
890 RENAME_LIBEXEC_GHC_STAGE_TO_GHC = NO
891 endif
892
893 install_libexecs: $(INSTALL_LIBEXECS)
894 ifneq "$(INSTALL_LIBEXECS)" ""
895 $(INSTALL_DIR) "$(DESTDIR)$(ghclibexecdir)/bin"
896 for i in $(INSTALL_LIBEXECS); do \
897 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(ghclibexecdir)/bin"; \
898 done
899 ifeq "$(RENAME_LIBEXEC_GHC_STAGE_TO_GHC)" "YES"
900 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc"
901 endif
902 endif
903
904 install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
905 ifneq "$(INSTALL_LIBEXEC_SCRIPTS)" ""
906 $(INSTALL_DIR) "$(DESTDIR)$(ghclibexecdir)/bin"
907 for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
908 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibexecdir)/bin"; \
909 done
910 endif
911
912 install_docs: $(INSTALL_DOCS)
913 $(INSTALL_DIR) "$(DESTDIR)$(docdir)"
914 ifneq "$(INSTALL_DOCS)" ""
915 for i in $(INSTALL_DOCS); do \
916 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)"; \
917 done
918 endif
919 $(INSTALL_DIR) "$(DESTDIR)$(docdir)/html"
920 $(INSTALL_DOC) $(INSTALL_OPTS) docs/index.html "$(DESTDIR)$(docdir)/html"
921 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
922 $(INSTALL_DIR) "$(DESTDIR)$(docdir)/html/libraries"
923 for i in $(INSTALL_LIBRARY_DOCS); do \
924 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)/html/libraries/"; \
925 done
926 $(INSTALL_DATA) $(INSTALL_OPTS) libraries/prologue.txt "$(DESTDIR)$(docdir)/html/libraries/"
927 $(INSTALL_SCRIPT) $(INSTALL_OPTS) libraries/gen_contents_index "$(DESTDIR)$(docdir)/html/libraries/"
928 endif
929 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
930 for i in $(INSTALL_HTML_DOC_DIRS); do \
931 $(CP) -Rp $$i "$(DESTDIR)$(docdir)/html"; \
932 done
933 endif
934
935 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
936
937 ifeq "$(BINDIST) $(CrossCompiling)" "NO YES"
938 # when installing ghc-stage2 we can't run target's
939 # 'ghc-pkg' and 'ghc-stage2' but those are needed for registration.
940 INSTALLED_GHC_REAL=$(TOP)/inplace/bin/ghc-stage1
941 INSTALLED_GHC_PKG_REAL=$(TOP)/$(ghc-pkg_DIST_BINARY)
942 else # CrossCompiling
943 # Install packages in the right order, so that ghc-pkg doesn't complain.
944 # Also, install ghc-pkg first.
945 ifeq "$(Windows_Host)" "NO"
946 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
947 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
948 else
949 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
950 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
951 endif
952 endif # CrossCompiling
953
954 # Set the INSTALL_DISTDIR_p for each package; compiler is special
955 $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
956 $(eval INSTALL_DISTDIR_$p = dist-install))
957 INSTALL_DISTDIR_compiler = stage2
958
959 # Now we can do the installation
960 install_packages: install_libexecs
961 install_packages: rts/dist/package.conf.install
962 $(INSTALL_DIR) "$(DESTDIR)$(topdir)"
963 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
964 $(INSTALL_DIR) "$(INSTALLED_PACKAGE_CONF)"
965 $(INSTALL_DIR) "$(DESTDIR)$(topdir)/rts"
966 $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts")
967 $(foreach p, $(INSTALL_PACKAGES), \
968 $(call make-command, \
969 "$(ghc-cabal_INPLACE)" copy \
970 $p $(INSTALL_DISTDIR_$p) \
971 "$(STRIP_CMD)" \
972 '$(DESTDIR)' \
973 '$(prefix)' \
974 '$(ghclibdir)' \
975 '$(docdir)/html/libraries' \
976 '$(GhcLibWays)'))
977 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/dist/package.conf.install
978 $(foreach p, $(INSTALL_PACKAGES), \
979 $(call make-command, \
980 "$(ghc-cabal_INPLACE)" register \
981 $p $(INSTALL_DISTDIR_$p) \
982 "$(INSTALLED_GHC_REAL)" \
983 "$(INSTALLED_GHC_PKG_REAL)" \
984 "$(DESTDIR)$(topdir)" \
985 '$(DESTDIR)' \
986 '$(prefix)' \
987 '$(ghclibdir)' \
988 '$(docdir)/html/libraries' \
989 $(RelocatableBuild)))
990 # when we install the packages above, ghc-pkg obeys umask when creating
991 # the package.conf files, but for everything else we specify the
992 # permissions. We therefore now fix the permissions of package.cache.
993 # This means "sudo make install" does the right thing even if it runs
994 # with an 077 umask.
995 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
996
997 # Finally, update package.cache to ensure it's newer than the registration
998 # files. This avoids #13375.
999 "$(INSTALLED_GHC_PKG_REAL)" --global-package-db "$(INSTALLED_PACKAGE_CONF)" recache
1000
1001 # -----------------------------------------------------------------------------
1002 # Binary distributions
1003
1004 ifneq "$(CLEANING)" "YES"
1005 # This rule seems to hold some files open on Windows which prevents
1006 # cleaning, perhaps due to the $(wildcard).
1007
1008 $(eval $(call bindist-list,.,\
1009 LICENSE \
1010 README \
1011 INSTALL \
1012 configure config.sub config.guess install-sh \
1013 llvm-targets \
1014 llvm-passes \
1015 packages \
1016 Makefile \
1017 mk/config.mk.in \
1018 $(INPLACE_BIN)/mkdirhier \
1019 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
1020 $(BINDIST_WRAPPERS) \
1021 $(BINDIST_LIBS) \
1022 $(BINDIST_HI) \
1023 $(BINDIST_EXTRAS) \
1024 $(includes_H_FILES) \
1025 $(includes_DERIVEDCONSTANTS) \
1026 $(includes_GHCCONSTANTS) \
1027 $(libffi_HEADERS) \
1028 $(INSTALL_LIBEXECS) \
1029 $(INSTALL_LIBEXEC_SCRIPTS) \
1030 $(INSTALL_BINS) \
1031 $(INSTALL_SCRIPTS) \
1032 $(INSTALL_MANPAGES) \
1033 $(INSTALL_DOCS) \
1034 $(INSTALL_LIBRARY_DOCS) \
1035 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
1036 docs/index.html \
1037 $(wildcard compiler/stage2/doc) \
1038 $(wildcard libraries/*/dist-install/doc/) \
1039 $(wildcard libraries/*/*/dist-install/doc/) \
1040 $(filter-out settings llvm-targets llvm-passes,$(INSTALL_LIBS)) \
1041 $(RTS_INSTALL_LIBS) \
1042 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
1043 mk/project.mk \
1044 mk/install.mk.in \
1045 bindist.mk \
1046 libraries/gen_contents_index \
1047 libraries/prologue.txt \
1048 ))
1049 endif
1050 # mk/project.mk gets an absolute path, so we manually include it in
1051 # the bindist with a relative path
1052
1053 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
1054
1055 # Note [Persist CrossCompiling in binary distributions]
1056 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1057 #
1058 # The build system uses the CrossCompiling variable to decide whether or not we
1059 # should build various packages that must be built using the compiler.
1060 # Consequently, it is important that we persist its value in the binary
1061 # distribution so we know during `make install` not to go looking for files that
1062 # would have been built for these packages. Failing to do this causes #13325.
1063 #
1064 # See Note [No stage2 packages when CrossCompiling or Stage1Only].
1065
1066 unix-binary-dist-prep:
1067 $(call removeTrees,bindistprep/)
1068 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
1069 set -e; for i in packages LICENSE compiler ghc rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh llvm-targets llvm-passes ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
1070 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
1071 echo "BUILD_SPHINX_HTML = $(BUILD_SPHINX_HTML)" >> $(BIN_DIST_MK)
1072 echo "BUILD_SPHINX_PDF = $(BUILD_SPHINX_PDF)" >> $(BIN_DIST_MK)
1073 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
1074 echo "override ghc-cabal_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
1075 echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
1076 # See Note [Persist CrossCompiling in binary distributions]
1077 echo "CrossCompiling = $(CrossCompiling)" >> $(BIN_DIST_MK)
1078 cd $(BIN_DIST_PREP_DIR) && autoreconf
1079 $(call removeFiles,$(BIN_DIST_PREP_TAR))
1080 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1081 # tree then we want to include the real file, not a symlink to it
1082 sort bindist-list | uniq > bindist-list.uniq
1083 cd bindistprep && "$(TAR_CMD)" hcf - -T ../bindist-list.uniq | $(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 llvm-targets llvm-passes 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 .PHONY: sdist-ghc-prep-tree
1193 sdist-ghc-prep-tree :
1194 $(call removeTrees,$(SRC_DIST_GHC_ROOT))
1195 $(call removeFiles,$(SRC_DIST_GHC_TARBALL))
1196 mkdir -p $(SRC_DIST_ROOT)
1197 mkdir -p $(SRC_DIST_GHC_ROOT)
1198 mkdir -p $(SRC_DIST_GHC_DIR)
1199 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_DIRS); do mkdir -p $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1200 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_FILES); do $(LN_S) $(TOP)/$$i .; done
1201 cd $(SRC_DIST_GHC_DIR) && $(MAKE) distclean
1202 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/tarballs/)
1203 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/stamp/)
1204 $(call removeTrees,$(SRC_DIST_GHC_DIR)/compiler/stage[123])
1205 $(call removeFiles,$(SRC_DIST_GHC_DIR)/mk/build.mk)
1206 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)
1207
1208 # Add files generated by alex and happy.
1209 # These rules depend on sdist-ghc-prep-tree.
1210 $(eval $(call sdist-ghc-file,compiler,stage2,cmm,CmmLex,x))
1211 $(eval $(call sdist-ghc-file,compiler,stage2,cmm,CmmParse,y))
1212 $(eval $(call sdist-ghc-file,compiler,stage2,parser,Lexer,x))
1213 $(eval $(call sdist-ghc-file,compiler,stage2,parser,Parser,y))
1214 $(eval $(call sdist-ghc-file,utils/hpc,dist-install,,HpcParser,y))
1215 $(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Lexer,x))
1216 $(eval $(call sdist-ghc-file,utils/genprimopcode,dist,,Parser,y))
1217
1218 # Recent Cabal library versions have a pre-generated Lexer.hs in the source
1219 # repo, and have moved Lexer.x out of the way, so trying to generate it from
1220 # here no longer works, and is no longer necessary.
1221 # According to https://github.com/haskell/cabal/issues/4633 however, this is
1222 # only a temporary solution, so we will probably have to adjust to whatever
1223 # the proper solution is going to be once there is one.
1224 #
1225 # $(eval $(call sdist-ghc-file2,libraries/Cabal/Cabal,dist-install,Distribution/Parsec,Lexer,x))
1226
1227 .PHONY: sdist-ghc-prep
1228 sdist-ghc-prep : sdist-ghc-prep-tree
1229
1230 .PHONY: sdist-windows-tarballs-prep
1231 sdist-windows-tarballs-prep :
1232 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_ROOT))
1233 $(call removeFiles,$(SRC_DIST_WINDOWS_TARBALLS_TARBALL))
1234 mkdir -p $(SRC_DIST_ROOT)
1235 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_ROOT)
1236 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)
1237 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs
1238 cd $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs && lndir $(TOP)/ghc-tarballs
1239 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs/.git)
1240
1241 .PHONY: sdist-testsuite-prep
1242 sdist-testsuite-prep :
1243 $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
1244 $(call removeFiles,$(SRC_DIST_TESTSUITE_TARBALL))
1245 mkdir -p $(SRC_DIST_ROOT)
1246 mkdir -p $(SRC_DIST_TESTSUITE_ROOT)
1247 mkdir -p $(SRC_DIST_TESTSUITE_DIR)
1248 mkdir -p $(SRC_DIST_TESTSUITE_DIR)/testsuite
1249 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && lndir $(TOP)/testsuite
1250 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && $(MAKE) distclean
1251
1252 .PHONY: sdist-ghc
1253 sdist-ghc: sdist-ghc-prep
1254 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)
1255
1256 .PHONY: sdist-windows-tarballs
1257 sdist-windows-tarballs: sdist-windows-tarballs-prep
1258 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)
1259
1260 .PHONY: sdist-testsuite
1261 sdist-testsuite: sdist-testsuite-prep
1262 cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> testsuite_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
1263
1264
1265 .PHONY: sdist
1266 sdist : sdist-ghc sdist-windows-tarballs sdist-testsuite
1267
1268 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
1269 tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1270
1271 # Upload the distribution(s)
1272 # Retrying is to work around buggy firewalls that corrupt large file transfers
1273 # over SSH.
1274 ifneq "$(PublishLocation)" ""
1275 publish-sdist :
1276 $(call try10Times,$(PublishCp) $(SRC_DIST_GHC_TARBALL) $(PublishLocation)/dist)
1277 $(call try10Times,$(PublishCp) $(SRC_DIST_TESTSUITE_TARBALL) $(PublishLocation)/dist)
1278 endif
1279
1280 # -----------------------------------------------------------------------------
1281 # sdisting libraries
1282
1283 # Use manually, with e.g.:
1284 # make sdist_directory
1285
1286 sdist_%:
1287 inplace/bin/ghc-cabal sdist libraries/$* dist-install
1288
1289 # -----------------------------------------------------------------------------
1290 # Cleaning
1291
1292 .PHONY: clean
1293
1294 CLEAN_FILES += libraries/integer-gmp/include/HsIntegerGmp.h
1295 CLEAN_FILES += libraries/base/include/EventConfig.h
1296 CLEAN_FILES += mk/config.mk.old
1297 CLEAN_FILES += mk/project.mk.old
1298 CLEAN_FILES += compiler/ghc.cabal.old
1299
1300 # These are no longer generated, but we still clean them for a while
1301 # as they may still be in old GHC trees:
1302 CLEAN_FILES += includes/GHCConstants.h
1303 CLEAN_FILES += includes/DerivedConstants.h
1304 CLEAN_FILES += includes/ghcautoconf.h
1305 CLEAN_FILES += includes/ghcplatform.h
1306 CLEAN_FILES += includes/ghcversion.h
1307 CLEAN_FILES += utils/ghc-pkg/Version.hs
1308 CLEAN_FILES += compiler/prelude/primops.txt
1309 CLEAN_FILES += $(wildcard compiler/primop*incl)
1310
1311 clean : clean_files clean_libraries
1312
1313 .PHONY: clean_files
1314 clean_files :
1315 $(call removeFiles,$(CLEAN_FILES))
1316 # this is here since CLEAN_FILES can't handle folders
1317 $(call removeTrees,includes/dist-derivedconstants)
1318 $(call removeTrees,inplace/bin)
1319 $(call removeTrees,inplace/lib)
1320 $(call removeTrees,libraries/bootstrapping.conf)
1321 # Clean the files that ./validate creates.
1322 $(call removeFiles,mk/are-validating.mk)
1323
1324 .PHONY: clean_libraries
1325 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2))
1326 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(PACKAGES_STAGE0))
1327
1328 clean_libraries:
1329 $(call removeTrees,$(patsubst %, libraries/%/dist, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1330 $(call removeFiles,$(wildcard $(patsubst %.in, %, $(wildcard $(patsubst %, libraries/%/*.buildinfo.in, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))))
1331 $(call removeFiles,$(patsubst %, libraries/%/config.log, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1332 $(call removeFiles,$(patsubst %, libraries/%/config.status, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1333 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1334
1335 # We have to define a clean target for each library manually, because the
1336 # libraries/*/ghc.mk files are not included when we're cleaning.
1337 ifeq "$(CLEANING)" "YES"
1338 $(foreach lib,$(PACKAGES_STAGE0),\
1339 $(eval $(call clean-target,libraries/$(lib),dist-boot,libraries/$(lib)/dist-boot)))
1340 $(foreach lib,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),\
1341 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1342 endif
1343
1344 clean : clean_haddock_index
1345 .PHONY: clean_haddock_index
1346 clean_haddock_index:
1347 $(call removeTrees,libraries/dist-haddock)
1348
1349 clean : clean_bindistprep
1350 .PHONY: clean_bindistprep
1351 clean_bindistprep:
1352 $(call removeTrees,bindistprep/)
1353
1354 distclean : clean
1355 # Clean the files that we ask ./configure to create.
1356 $(call removeFiles,mk/config.mk)
1357 $(call removeFiles,mk/install.mk)
1358 $(call removeFiles,mk/project.mk)
1359 $(call removeFiles,compiler/ghc.cabal)
1360 $(call removeFiles,ghc/ghc-bin.cabal)
1361 $(call removeFiles,libraries/ghci/ghci.cabal)
1362 $(call removeFiles,utils/runghc/runghc.cabal)
1363 $(call removeFiles,utils/gen-dll/gen-dll.cabal)
1364 $(call removeFiles,settings)
1365 $(call removeFiles,docs/users_guide/ug-book.xml)
1366 $(call removeFiles,docs/users_guide/ug-ent.xml)
1367 $(call removeFiles,docs/users_guide/ghc_config.py)
1368 $(call removeFiles,docs/index.html)
1369 $(call removeFiles,libraries/prologue.txt)
1370 $(call removeFiles,distrib/configure.ac)
1371 $(call removeFiles,ch01.html ch02.html index.html)
1372
1373 # ./configure also makes these.
1374 $(call removeFiles,mk/config.h)
1375
1376 # Internal files generated by ./configure for itself.
1377 $(call removeFiles,config.cache config.status config.log)
1378
1379 # The root Makefile makes .old versions of some files that configure
1380 # generates, so we clean those too.
1381 $(call removeFiles,mk/config.mk.old)
1382 $(call removeFiles,mk/project.mk.old)
1383 $(call removeFiles,compiler/ghc.cabal.old)
1384
1385 # Clean the *Config.h files generated by library configure scripts
1386 $(call removeFiles,libraries/base/include/HsBaseConfig.h)
1387 $(call removeFiles,libraries/base/include/EventConfig.h)
1388 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
1389 $(call removeFiles,libraries/process/include/HsProcessConfig.h)
1390 $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
1391 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h)
1392
1393 # The library configure scripts also like creating autom4te.cache
1394 # directories, so clean them all up.
1395 $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1396
1397 # We make these when making or testing bindists
1398 $(call removeFiles,bindist-list)
1399 $(call removeFiles,bindist-list.uniq)
1400 $(call removeTrees,bindisttest/a)
1401
1402 # Not sure why this is being cleaned here.
1403 $(call removeTrees,includes/dist-derivedconstants)
1404
1405 # Also clean Windows-only inplace directories.
1406 # Don't delete 'inplace' itself, it contains source files.
1407 $(call removeTrees,inplace/mingw)
1408
1409 # Remove the fs utilities.
1410 $(call removeFiles,utils/lndir/fs.h)
1411 $(call removeFiles,utils/lndir/fs.c)
1412 $(call removeFiles,utils/unlit/fs.h)
1413 $(call removeFiles,utils/unlit/fs.c)
1414 $(call removeFiles,rts/fs.h)
1415 $(call removeFiles,rts/fs.c)
1416 $(call removeFiles,libraries/base/include/fs.h)
1417 $(call removeFiles,libraries/base/cbits/fs.c)
1418
1419 maintainer-clean : distclean
1420 $(call removeFiles,configure mk/config.h.in)
1421 $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
1422 $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
1423 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1424 $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1425 $(call removeFiles,$(patsubst %, libraries/%/configure, \
1426 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1427 $(call removeFiles,libraries/base/include/HsBaseConfig.h.in)
1428 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
1429 $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
1430 $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
1431 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h.in)
1432
1433 .PHONY: all_libraries
1434
1435 .PHONY: bootstrapping-files
1436 # See https://gitlab.haskell.org/ghc/ghc/wikis/building/porting
1437 bootstrapping-files: $(includes_H_CONFIG)
1438 bootstrapping-files: $(includes_DERIVEDCONSTANTS)
1439 bootstrapping-files: $(includes_GHCCONSTANTS)
1440 bootstrapping-files: $(libffi_HEADERS)
1441
1442 .DELETE_ON_ERROR:
1443
1444 # -----------------------------------------------------------------------------
1445
1446 ifeq "$(HADDOCK_DOCS)" "YES"
1447 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
1448 endif
1449 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
1450 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
1451 else
1452 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
1453 endif
1454 BINDIST_LIBRARY_FLAGS += --disable-library-prof
1455
1456 .PHONY: validate_build_xhtml
1457 validate_build_xhtml:
1458 cd libraries/xhtml && "$(BINDIST_PREFIX)/bin/ghc" --make Setup
1459 cd libraries/xhtml && ./Setup configure --with-ghc="$(BINDIST_PREFIX)/bin/ghc" $(BINDIST_HADDOCK_FLAG) $(BINDIST_LIBRARY_FLAGS) --global --builddir=dist-bindist --prefix="$(BINDIST_PREFIX)"
1460 cd libraries/xhtml && ./Setup build --builddir=dist-bindist
1461 ifeq "$(HADDOCK_DOCS)" "YES"
1462 cd libraries/xhtml && ./Setup haddock -v0 --ghc-options=-optP-P --builddir=dist-bindist
1463 endif
1464 cd libraries/xhtml && ./Setup install --builddir=dist-bindist
1465 cd libraries/xhtml && ./Setup clean --builddir=dist-bindist
1466 cd libraries/xhtml && rm -f Setup Setup.exe Setup.hi Setup.o
1467
1468 # Note [No stage2 packages when CrossCompiling or Stage1Only]
1469 #
1470 # (first read Note [CrossCompiling vs Stage1Only] and
1471 # Note [Stage1Only vs stage=1] in mk/config.mk.in)
1472 #
1473 # When either CrossCompiling=YES or Stage1Only=YES, we have to exclude the
1474 # following packages from the build:
1475 # * packages that we build with ghc-stage2 [1]
1476 # * packages that depend on the ghc library [2]
1477 #
1478 # Here's why:
1479 # - first of all, ghc-stage1 can't use stage0's ghc library (it's too old)
1480 # - neither do we register the ghc library (compiler/stage1) that we build
1481 # with stage0. TODO Why not? We do build it...
1482 # - as a result, we need to a) use ghc-stage2 to build packages that depend on
1483 # the ghc library and b) exclude those packages when ghc-stage2 is not
1484 # available.
1485 # - when Stage1Only=YES, it's clear that ghc-stage2 is not available (we just
1486 # said we didn't want it), so we have to exclude the stage2 packages from
1487 # the build. This includes the case where Stage1Only=YES is combined with
1488 # CrossCompiling=YES (Building GHC as a cross-compiler [3]).
1489 # - when CrossCompiling=YES, but Stage1Only=NO (Cross-compiling GHC itself
1490 # [3]), we can not use ghc-stage2 either. The reason is that stage2 doesn't
1491 # run on the host platform at all; it is built to run on $(TARGETPLATFORM)"
1492 # [4]. Therefore in this case we also have to exclude the stage2 packages
1493 # from the build.
1494 #
1495 # Because we omit certain packages from the build when CrossCompiling=YES,
1496 # it is important that we remember the value of CrossCompiling in binary
1497 # distributions that we produce. See Note [Persist CrossCompiling in binary
1498 # distributions].
1499 #
1500 # [1] find utils -name ghc.mk | xargs grep -l 'build-prog.*,2'
1501 #
1502 # [2]
1503 # find utils -name package-data.mk | xargs grep -l 'DEP_NAMES =.* ghc\($\| \)'
1504 #
1505 # [3] https://gitlab.haskell.org/ghc/ghc/wikis/building/cross-compiling
1506 #
1507 # [4] * bc31dbe8ee22819054df60f5ef219fed393a1c54
1508 # "Disable any packages built with stage 2 when cross-compiling
1509 # Since we can't run stage 2 on the host."
1510 #
1511 # * 72995160b0b190577b5c0cb8d7bd0426cc455b05
1512 # "We cannot use the stage 2 compiler, it runs on $(TARGETPLATFORM)"
1513
1514 # -----------------------------------------------------------------------------
1515 # Numbered phase targets
1516
1517 # In phase 1, we'll be building dependency files for most things
1518 # built by the bootstrapping compiler while make is 'include'ing
1519 # makefiles. But in order to build dependency files, we'll need to
1520 # build any automatically generated .hs files, which means that
1521 # we'll need to be able to build any tools that generate .hs files
1522 # etc. But in order to do that, we need to already know the
1523 # dependencies for those tools, so we build their dependency files
1524 # here.
1525 .PHONY: phase_0_builds
1526 # hsc2hs is needed, e.g. to make the .hs files for hpc.
1527 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1528 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1529 # genprimopcode is needed to make the .hs-incl files that are in the
1530 # ghc package.
1531 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1532 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1533 # deriveConstants is used to create header files included in the
1534 # ghc package.
1535 phase_0_builds: $(utils/deriveConstants_dist_depfile_haskell)
1536 phase_0_builds: $(utils/deriveConstants_dist_depfile_c_asm)
1537
1538 .PHONY: phase_1_builds
1539 phase_1_builds: $(PACKAGE_DATA_MKS)