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