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