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