Add a fixity environment to InteractiveContext (#2947)
[ghc.git] / ghc.mk
1
2 # -----------------------------------------------------------------------------
3 #
4 # (c) 2009 The University of Glasgow
5 #
6 # This file is part of the GHC build system.
7 #
8 # To understand how the build system works and how to modify it, see
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
10 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
11 #
12 # -----------------------------------------------------------------------------
13
14 # ToDo List.
15 #
16 # * remove old Makefiles, add new stubs for building in subdirs
17 # * docs/Makefile
18 # * docs/docbook-cheat-sheet/Makefile
19 # * docs/man/Makefile
20 # * docs/storage-mgmt/Makefile
21 # * docs/vh/Makefile
22 # * rts/dotnet/Makefile
23 # * utils/Makefile
24 # * add Makefiles for the rest of the utils/ programs that aren't built
25 # by default (need to exclude them from 'make all' too)
26
27 # Possible cleanups:
28 #
29 # * per-source-file dependencies instead of one .depend file?
30 # * eliminate undefined variables, and use --warn-undefined-variables?
31 # * put outputs from different ways in different subdirs of distdir/build,
32 # then we don't have to use -osuf/-hisuf. We would have to install
33 # them in different places too, so we'd need ghc-pkg support for packages
34 # of different ways.
35 # * make PACKAGES_STAGE1 generated by './configure' or './boot'?
36 # * we should use a directory of package.conf files rather than a single
37 # file for the inplace package database, so that we can express
38 # dependencies more accurately. Otherwise it's possible to get into
39 # a state where the package database is out of date, and the build
40 # system doesn't know.
41
42 # Approximate build order.
43 #
44 # The actual build order is defined by dependencies, and the phase
45 # ordering used to ensure correct ordering of makefile-generation; see
46 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
47 #
48 # * With bootstrapping compiler:
49 # o Build utils/ghc-cabal
50 # o Build utils/ghc-pkg
51 # o Build utils/hsc2hs
52 # * For each package:
53 # o configure, generate package-data.mk and inplace-pkg-info
54 # o register each package into inplace/lib/package.conf
55 # * build libffi
56 # * With bootstrapping compiler:
57 # o Build libraries/{filepath,hpc,Cabal}
58 # o Build compiler (stage 1)
59 # * With stage 1:
60 # o Build libraries/*
61 # o Build rts
62 # o Build utils/* (except haddock)
63 # o Build compiler (stage 2)
64 # * With stage 2:
65 # o Build utils/haddock
66 # o Build compiler (stage 3) (optional)
67 # * With haddock:
68 # o libraries/*
69 # o compiler
70
71 .PHONY: default all haddock
72
73 # We need second expansion for the way we handle directories, so that
74 # | $$$$(dir $$$$@)/.
75 # expands to the directory of a rule that uses a % pattern.
76 .SECONDEXPANSION:
77
78 default : all
79
80 # Catch make if it runs away into an infinite loop
81 ifeq "$(MAKE_RESTARTS)" ""
82 else ifeq "$(MAKE_RESTARTS)" "1"
83 else
84 $(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug?)
85 endif
86
87 ifneq "$(CLEANING)" "YES"
88 CLEANING = NO
89 endif
90
91 # -----------------------------------------------------------------------------
92 # Misc GNU make utils
93
94 nothing=
95 space=$(nothing) $(nothing)
96 comma=,
97
98 # Cancel all suffix rules. Ideally we'd like to have 'make -r' turned on
99 # by default, because that disables all the implicit rules, but there doesn't
100 # seem to be a good way to do that. This turns off all the old-style suffix
101 # rules, which does half the job and speeds up make quite a bit:
102 .SUFFIXES:
103
104 # -----------------------------------------------------------------------------
105 # Makefile debugging
106 #
107 # to see the effective value used for a Makefile variable, do
108 # make show VALUE=MY_VALUE
109 #
110
111 show:
112 @echo '$(VALUE)="$($(VALUE))"'
113
114 # -----------------------------------------------------------------------------
115 # Include subsidiary build-system bits
116
117 include mk/tree.mk
118
119 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
120 include mk/config.mk
121 ifeq "$(ProjectVersion)" ""
122 $(error Please run ./configure first)
123 endif
124 endif
125
126 include mk/ways.mk
127
128 # (Optional) build-specific configuration
129 include mk/custom-settings.mk
130
131 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
132 ifeq "$(GhcLibWays)" ""
133 $(error $$(GhcLibWays) is empty, it must contain at least one way)
134 endif
135 endif
136
137 ifeq "$(phase)" ""
138 phase = final
139 endif
140
141 # -----------------------------------------------------------------------------
142 # Utility definitions
143
144 include rules/prof.mk
145 include rules/trace.mk
146 include rules/make-command.mk
147
148 # -----------------------------------------------------------------------------
149 # Macros for standard targets
150
151 include rules/all-target.mk
152 include rules/clean-target.mk
153
154 # -----------------------------------------------------------------------------
155 # The inplace tree
156
157 $(eval $(call clean-target,inplace,,inplace/bin inplace/lib))
158
159 # -----------------------------------------------------------------------------
160 # Whether to build dependencies or not
161
162 # When we're just doing 'make clean' or 'make show', then we don't need
163 # to build dependencies.
164
165 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
166 NO_INCLUDE_DEPS = YES
167 NO_INCLUDE_PKGDATA = YES
168 endif
169 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
170 NO_INCLUDE_DEPS = YES
171 NO_INCLUDE_PKGDATA = YES
172 endif
173 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
174 NO_INCLUDE_DEPS = YES
175 # We want package-data.mk for show
176 endif
177
178 # -----------------------------------------------------------------------------
179 # Ways
180
181 include rules/way-prelims.mk
182
183 $(foreach way,$(ALL_WAYS),\
184 $(eval $(call way-prelims,$(way))))
185
186 # -----------------------------------------------------------------------------
187 # Compilation Flags
188
189 include rules/distdir-way-opts.mk
190
191 # -----------------------------------------------------------------------------
192 # Finding source files and object files
193
194 include rules/hs-sources.mk
195 include rules/c-sources.mk
196 include rules/includes-sources.mk
197 include rules/hs-objs.mk
198 include rules/c-objs.mk
199 include rules/cmm-objs.mk
200
201 # -----------------------------------------------------------------------------
202 # Suffix rules
203
204 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
205 # so we don't make any when cleaning.
206 ifneq "$(CLEANING)" "YES"
207
208 include rules/hs-suffix-rules-srcdir.mk
209 include rules/hs-suffix-rules.mk
210 include rules/hi-rule.mk
211
212 $(foreach way,$(ALL_WAYS),\
213 $(eval $(call hi-rule,$(way))))
214
215 include rules/c-suffix-rules.mk
216 include rules/cmm-suffix-rules.mk
217
218 endif # CLEANING=YES
219
220 # -----------------------------------------------------------------------------
221 # Building package-data.mk files from .cabal files
222
223 include rules/package-config.mk
224
225 # -----------------------------------------------------------------------------
226 # Building dependencies
227
228 include rules/dependencies.mk
229 include rules/build-dependencies.mk
230 include rules/include-dependencies.mk
231
232 # -----------------------------------------------------------------------------
233 # Build package-data.mk files
234
235 include rules/build-package-data.mk
236
237 # -----------------------------------------------------------------------------
238 # Build and install a program
239
240 include rules/build-prog.mk
241 include rules/shell-wrapper.mk
242
243 # -----------------------------------------------------------------------------
244 # Build a perl script
245
246 include rules/build-perl.mk
247
248 # -----------------------------------------------------------------------------
249 # Build a package
250
251 include rules/build-package.mk
252 include rules/build-package-way.mk
253 include rules/haddock.mk
254 include rules/tags-package.mk
255 include rules/extra-packages.mk
256
257 # -----------------------------------------------------------------------------
258 # Registering hand-written package descriptions (used in rts)
259
260 include rules/manual-package-config.mk
261
262 # -----------------------------------------------------------------------------
263 # Docs
264
265 include rules/docbook.mk
266
267 # -----------------------------------------------------------------------------
268 # Making bindists
269
270 include rules/bindist.mk
271
272 # -----------------------------------------------------------------------------
273 # Directories
274
275 # Don't try to delete directories:
276 .PRECIOUS: %/.
277
278 # Create build directories on demand. NB. the | below: this indicates
279 # that $(MKDIRHIER) is an order-only dependency, which means that this
280 # rule fires after building mkdirhier, but we won't try to recreate
281 # directories if mkdirhier changes.
282 %/. : | $(MKDIRHIER)
283 "$(MKDIRHIER)" $@
284
285 # -----------------------------------------------------------------------------
286 # Lax dependencies
287
288 ifeq "$(LAX_DEPENDENCIES)" "YES"
289 LAX_DEPS_FOLLOW = |
290 else
291 LAX_DEPS_FOLLOW =
292 endif
293
294 # This is a bit of a hack. When LAX_DEPS_FOLLOW is | some rules end up
295 # looking like
296 # target: a | b | c
297 # The first | signals the start of the order-only dependencies, but make
298 # treats the second | as a dependency. So we need to tell make how to
299 # build that dependency.
300
301 .PHONY: |
302 | :
303 @:
304
305 # -----------------------------------------------------------------------------
306 # Properties of packages
307
308 # These lists say "if this package is built, here's a property it has"
309 # They do not say "this package will be built"; see $(PACKAGES_xx) for that
310
311 # Packages that are built but not installed
312 PKGS_THAT_ARE_INTREE_ONLY := haskeline mtl terminfo utf8-string xhtml
313
314 PKGS_THAT_ARE_DPH := \
315 dph/dph-base \
316 dph/dph-prim-interface dph/dph-prim-seq dph/dph-prim-par \
317 dph/dph-lifted-base \
318 dph/dph-lifted-boxed dph/dph-lifted-copy dph/dph-lifted-vseg \
319 vector primitive random
320
321 # Packages that, if present, must be built by the stage2 compiler,
322 # because they use TH and/or annotations, or depend on other stage2
323 # packages:
324 PKGS_THAT_BUILD_WITH_STAGE2 := $(PKGS_THAT_ARE_DPH) haskell98 haskell2010
325
326 # Packages that we shouldn't build if we don't have TH (e.g. because
327 # we're building a profiled compiler):
328 PKGS_THAT_USE_TH := $(PKGS_THAT_ARE_DPH)
329
330 # Packages that are built by stage0, in addition to stage1. These
331 # packages are dependencies of GHC, that we do not assume the stage0
332 # compiler already has installed (or up-to-date enough).
333 #
334 # We assume that the stage0 compiler has a suitable bytestring package,
335 # so we don't have to include it below.
336 PKGS_THAT_BUILD_WITH_STAGE0 = Cabal/Cabal hpc binary bin-package-db hoopl
337
338 # $(EXTRA_PACKAGES) is another classification, of packages built but
339 # not installed
340 # It is set in rules/extra-package.mk,
341 # by $(call extra-packages) a little further down
342 # this ghc.mk
343
344
345
346 # ----------------------------------------------------------------------------
347 # Packages to build
348 # The lists of packages that we *actually* going to build in each stage:
349 #
350 # $(PACKAGES_STAGE0)
351 # $(PACKAGES_STAGE1)
352 # $(PACKAGES_STAGE2)
353 #
354 # These are automatically derived from
355 # (a) the set of packages in this source tree
356 # (b) the predicates above, e.g. $(PKGS_THAT_BUILD_WITH_STAGE2)
357 # (c) which platform we're on, and a few other things
358
359
360 # no processing to do on this one: it really is the list of packages
361 # to build with stage 0.
362 PACKAGES_STAGE0 = $(PKGS_THAT_BUILD_WITH_STAGE0)
363
364 define addPackageGeneral
365 # args: $1 = PACKAGES variable, $2 = package, $3 = condition
366 ifeq "$3" ""
367 $1 += $2
368 else
369 ifeq "$$(CLEANING)" "YES"
370 $1 += $2
371 else
372 ifeq $3
373 $1 += $2
374 endif
375 endif
376 endif
377 endef
378
379 define addPackage # args: $1 = package, $2 = condition
380 ifneq "$(filter $1,$(PKGS_THAT_USE_TH)) $(GhcProfiled)" "$1 YES"
381 ifeq "$(filter $1,$(PKGS_THAT_BUILD_WITH_STAGE2))" "$1"
382 ifneq "$(BuildingCrossCompiler)" "YES"
383 $(call addPackageGeneral,PACKAGES_STAGE2,$1,$2)
384 endif
385 else
386 $(call addPackageGeneral,PACKAGES_STAGE1,$1,$2)
387 endif
388 endif
389 endef
390
391 $(eval $(call addPackage,ghc-prim))
392 ifeq "$(CLEANING)" "YES"
393 $(eval $(call addPackage,integer-gmp))
394 $(eval $(call addPackage,integer-simple))
395 else
396 $(eval $(call addPackage,$(INTEGER_LIBRARY)))
397 endif
398 $(eval $(call addPackage,base))
399 $(eval $(call addPackage,filepath))
400 $(eval $(call addPackage,array))
401 $(eval $(call addPackage,deepseq))
402 $(eval $(call addPackage,bytestring))
403 $(eval $(call addPackage,containers))
404
405 $(eval $(call addPackage,Win32,($$(Windows),YES)))
406 $(eval $(call addPackage,unix,($$(Windows),NO)))
407
408 $(eval $(call addPackage,old-locale))
409 $(eval $(call addPackage,old-time))
410 $(eval $(call addPackage,time))
411 $(eval $(call addPackage,directory))
412 $(eval $(call addPackage,process))
413 $(eval $(call addPackage,haskell98))
414 $(eval $(call addPackage,haskell2010))
415 $(eval $(call addPackage,hpc))
416 $(eval $(call addPackage,pretty))
417 $(eval $(call addPackage,template-haskell))
418 $(eval $(call addPackage,Cabal/Cabal))
419 $(eval $(call addPackage,binary))
420 $(eval $(call addPackage,bin-package-db))
421 $(eval $(call addPackage,hoopl))
422 $(eval $(call addPackage,transformers))
423 $(eval $(call addPackage,mtl))
424 $(eval $(call addPackage,utf8-string))
425 $(eval $(call addPackage,xhtml))
426 $(eval $(call addPackage,terminfo,($$(Windows),NO)))
427 $(eval $(call addPackage,haskeline))
428
429 $(eval $(call extra-packages))
430
431 # -------------------------------------------
432 # Dependencies between package-data.mk files
433
434 # We cannot run ghc-cabal to configure a package until we have
435 # configured and registered all of its dependencies. So the following
436 # hack forces all the configure steps to happen in exactly the following order:
437 #
438 # $(PACKAGES_STAGE1) ghc(stage2) $(PACKAGES_STAGE2)
439 #
440 # Ideally we should use the correct dependencies here to allow more
441 # parallelism, but we don't know the dependencies until we've
442 # generated the package-data.mk files.
443 define fixed_pkg_dep
444 libraries/$1/$2/package-data.mk : $$(GHC_PKG_INPLACE) $$(fixed_pkg_prev)
445 fixed_pkg_prev:=libraries/$1/$2/package-data.mk
446 endef
447
448 ifneq "$(BINDIST)" "YES"
449 fixed_pkg_prev=
450 $(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
451
452 # the GHC package doesn't live in libraries/, so we add its dependency manually:
453 compiler/stage2/package-data.mk: $(fixed_pkg_prev)
454 fixed_pkg_prev:=compiler/stage2/package-data.mk
455
456 # and continue with PACKAGES_STAGE2, which depend on GHC:
457 $(foreach pkg,$(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
458
459 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
460 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
461 # haddock depends on ghc and some libraries, but depending on GHC's
462 # package-data.mk is sufficient, as that in turn depends on all the
463 # libraries
464 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
465 utils/ghc-pwd/dist-install/package-data.mk: compiler/stage2/package-data.mk
466 utils/ghc-cabal/dist-install/package-data.mk: compiler/stage2/package-data.mk
467
468 utils/ghc-pkg/dist-install/package-data.mk: compiler/stage2/package-data.mk
469 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
470 utils/compare_sizes/dist-install/package-data.mk: compiler/stage2/package-data.mk
471 utils/runghc/dist-install/package-data.mk: compiler/stage2/package-data.mk
472
473 # add the final package.conf dependency: ghc-prim depends on RTS
474 libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
475 endif
476
477 # --------------------------------
478 # Misc package-related settings
479
480 BOOT_PKG_CONSTRAINTS := \
481 $(foreach d,$(PACKAGES_STAGE0),\
482 $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
483 --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
484
485 # The actual .a and .so/.dll files: needed for dependencies.
486 ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_v_LIB))
487 ifeq "$(BuildSharedLibs)" "YES"
488 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_dyn_LIB))
489 endif
490 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
491
492 # ----------------------------------------
493 # Special magic for the ghc-prim package
494
495 # We want the ghc-prim package to include the GHC.Prim module when it
496 # is registered, but not when it is built, because GHC.Prim is not a
497 # real source module, it is built-in to GHC. The old build system did
498 # this using Setup.hs, but we can't do that here, so we have a flag to
499 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
500 # remains compatible with the old build system for the time being).
501 # GHC.Prim module in the ghc-prim package with a flag:
502 #
503 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
504
505 # And then we strip it out again before building the package:
506 define libraries/ghc-prim_PACKAGE_MAGIC
507 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
508 endef
509
510 PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
511
512 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT) | $$(dir $$@)/.
513 "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
514
515 # Required so that Haddock documents the primops.
516 libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
517
518 # ----------------------------------------
519 # Special magic for the integer package
520
521 ifneq "$(CLEANING)" "YES"
522 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
523 libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple
524 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
525 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
526 else
527 $(error Unknown integer library: $(INTEGER_LIBRARY))
528 endif
529 endif
530
531 # ----------------------------------------------
532 # Checking packages with 'cabal check'
533
534 ifeq "$(phase)" "final"
535 ifeq "$(CHECK_PACKAGES)" "YES"
536 all: check_packages
537 endif
538 endif
539
540 # These packages don't pass the Cabal checks because hs-source-dirs
541 # points outside the source directory. This isn't a real problem in
542 # these cases, so we just skip checking them.
543 # NB. these must come before we include the ghc.mk files below, because
544 # they disable the relevant rules.
545 # In compiler's case, include-dirs points outside of the source tree
546 CHECKED_compiler = YES
547
548 # -----------------------------------------------------------------------------
549 # Include build instructions from all subdirs
550
551 ifneq "$(BINDIST)" "YES"
552 BUILD_DIRS += \
553 $(GHC_MKDIRHIER_DIR)
554 endif
555
556 ifeq "$(Windows)" "YES"
557 BUILD_DIRS += \
558 $(GHC_TOUCHY_DIR)
559 endif
560
561 BUILD_DIRS += \
562 docs/users_guide \
563 docs/man \
564 $(GHC_UNLIT_DIR) \
565 $(GHC_HP2PS_DIR)
566
567 ifneq "$(GhcUnregisterised)" "YES"
568 BUILD_DIRS += \
569 $(GHC_SPLIT_DIR)
570 endif
571
572 ifneq "$(BINDIST)" "YES"
573 BUILD_DIRS += \
574 $(GHC_GENPRIMOP_DIR)
575 endif
576
577 ifeq "$(BuildingCrossCompiler)-$(phase)" "YES-final"
578 MAYBE_GHCI=
579 else
580 MAYBE_GHCI=driver/ghci
581 endif
582
583 BUILD_DIRS += \
584 driver \
585 $(MAYBE_GHCI) \
586 driver/ghc \
587 driver/haddock \
588 libffi \
589 includes \
590 rts
591
592 ifneq "$(BINDIST)" "YES"
593 BUILD_DIRS += \
594 bindisttest \
595 $(GHC_GENAPPLY_DIR)
596 endif
597
598 ifneq "$(CLEANING)" "YES"
599 BUILD_DIRS += \
600 $(patsubst %, libraries/%, $(PACKAGES_STAGE1))
601 endif
602
603 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
604 BUILD_DIRS += libraries/integer-gmp/gmp
605 else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
606 BUILD_DIRS += libraries/integer-gmp/gmp
607 endif
608
609 ifeq "$(BuildingCrossCompiler)-$(phase)" "YES-final"
610 MAYBE_COMPILER=
611 MAYBE_GHCTAGS=
612 MAYBE_HPC=
613 MAYBE_RUNGHC=
614 else
615 MAYBE_COMPILER=compiler
616 MAYBE_GHCTAGS=utils/ghctags
617 MAYBE_HPC=utils/hpc
618 MAYBE_RUNGHC=utils/runghc
619 endif
620
621 BUILD_DIRS += \
622 utils/haddock \
623 utils/haddock/doc \
624 $(MAYBE_COMPILER) \
625 $(GHC_HSC2HS_DIR) \
626 $(GHC_PKG_DIR) \
627 utils/testremove \
628 $(MAYBE_GHCTAGS) \
629 utils/ghc-pwd \
630 $(GHC_CABAL_DIR) \
631 $(MAYBE_HPC) \
632 $(MAYBE_RUNGHC) \
633 ghc
634
635 ifneq "$(BINDIST)" "YES"
636 ifneq "$(BuildingCrossCompiler)-$(phase)" "YES-final"
637 BUILD_DIRS += \
638 utils/mkUserGuidePart
639 endif
640 endif
641
642 BUILD_DIRS += utils/count_lines
643 BUILD_DIRS += utils/compare_sizes
644
645 ifneq "$(CLEANING)" "YES"
646 # After compiler/, because these packages depend on it
647 BUILD_DIRS += \
648 $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
649 endif
650
651 # ----------------------------------------------
652 # Actually include all the sub-ghc.mk's
653
654 # BUILD_DIRS_EXTRA needs to come after BUILD_DIRS, because stuff in
655 # libraries/dph/ghc.mk refers to stuff defined earlier, in particular
656 # things like $(libraries/dph/dph-base_dist-install_GHCI_LIB)
657 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS) $(BUILD_DIRS_EXTRA))
658
659 # A useful pseudo-target (must be after the include above, because it needs
660 # the value of things like $(libraries/base_dist-install_v_LIB).
661 .PHONY: stage1_libs
662 stage1_libs : $(ALL_STAGE1_LIBS)
663
664 # ----------------------------------------------
665 # Per-package compiler flags
666 #
667 # If you want to add per-package compiler flags, this
668 # is the place to do it. Do it like this for package <pkg>
669 #
670 # libraries/<pkg>_dist-boot_HC_OPTS += -Wwarn
671 # libraries/<pkg>_dist-install_HC_OPTS += -Wwarn
672
673 # Add $(GhcLibHcOpts) to all package builds
674 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
675
676 # Add $(GhcBootLibHcOpts) to all stage0 package builds
677 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
678
679 # -----------------------------------------------
680 # Haddock-related bits
681
682 # Don't run Haddock for the package that will not be installed
683 $(foreach p,$(PKGS_THAT_ARE_INTREE_ONLY),$(eval libraries/$p_dist-install_DO_HADDOCK = NO))
684 # We don't haddock the bootstrapping libraries
685 $(foreach p,$(PACKAGES_STAGE0),$(eval libraries/$p_dist-boot_DO_HADDOCK = NO))
686
687 # Build the Haddock contents and index
688 ifeq "$(HADDOCK_DOCS)" "YES"
689 libraries/dist-haddock/index.html: inplace/bin/haddock$(exeext) $(ALL_HADDOCK_FILES)
690 cd libraries && sh gen_contents_index --inplace
691 ifeq "$(phase)" "final"
692 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
693 endif
694 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
695 endif
696
697 # -----------------------------------------------------------------------------
698 # Bootstrapping libraries
699
700 # We need to build a few libraries with the installed GHC, since GHC itself
701 # and some of the tools depend on them:
702
703 ifneq "$(BINDIST)" "YES"
704
705 ifneq "$(BOOTSTRAPPING_CONF)" ""
706 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
707 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
708 endif
709 endif
710
711 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
712
713 # register the boot packages in strict sequence, because running
714 # multiple ghc-pkgs in parallel doesn't work (registrations may get
715 # lost).
716 fixed_pkg_prev=
717 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
718
719 compiler/stage1/package-data.mk : $(fixed_pkg_prev)
720 endif
721
722 ifneq "$(BINDIST)" "YES"
723 # Make sure we have all the GHCi libs by the time we've built
724 # ghc-stage2. DPH includes a bit of Template Haskell which needs the
725 # GHCI libs, and we don't have a better way to express that dependency.
726 #
727 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
728 $(compiler_stage2_GHCI_LIB)
729
730 ifeq "$(UseArchivesForGhci)" "NO"
731 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
732 endif
733
734 ifeq "$(UseArchivesForGhci)" "YES"
735 GHCI_lib_way = v
736 else
737 GHCI_lib_way = GHCI
738 endif
739
740 # Deps for TH uses in libraries
741 $(foreach way, $(GhcLibWays),$(eval \
742 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
743 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
744 ))
745 endif
746
747 # -----------------------------------------------------------------------------
748 # Creating a local mingw copy on Windows
749
750 ifeq "$(Windows)" "YES"
751
752 install : install_mingw
753 .PHONY: install_mingw
754 install_mingw : $(INPLACE_MINGW)
755 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
756
757 install : install_perl
758 .PHONY: install_perl
759 install_perl : $(INPLACE_PERL)
760 "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
761
762 endif # Windows
763
764 ifneq "$(BINDIST)" "YES"
765 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
766 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
767 endif # BINDIST
768
769 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
770 $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) \
771 | $$(dir $$@)/.
772 "$(GENPRIMOP_INPLACE)" --make-haskell-source < $< > $@
773
774 .PHONY: tags
775 tags: tags_compiler
776
777 .PHONY: TAGS
778 TAGS: TAGS_compiler
779
780 # -----------------------------------------------------------------------------
781 # Installation
782
783 install: install_libs install_packages install_libexecs \
784 install_libexec_scripts install_bins install_topdirs
785 ifeq "$(HADDOCK_DOCS)" "YES"
786 install: install_docs
787 endif
788
789 install_bins: $(INSTALL_BINS)
790 $(call INSTALL_DIR,"$(DESTDIR)$(bindir)")
791 for i in $(INSTALL_BINS); do \
792 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(bindir)") ; \
793 done
794
795 install_libs: $(INSTALL_LIBS)
796 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibdir)")
797 for i in $(INSTALL_LIBS); do \
798 case $$i in \
799 *.a) \
800 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibdir)"); \
801 $(RANLIB) $(DESTDIR)$(ghclibdir)/`basename $$i` ;; \
802 *.dll) \
803 $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibdir)") ; \
804 $(STRIP_CMD) "$(DESTDIR)$(ghclibdir)"/$$i ;; \
805 *.so) \
806 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibdir)") ;; \
807 *.dylib) \
808 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibdir)");; \
809 *) \
810 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibdir)"); \
811 esac; \
812 done
813
814 install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
815 ifeq "$(INSTALL_LIBEXEC_SCRIPTS)" ""
816 @:
817 else
818 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibexecdir)")
819 for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
820 $(call INSTALL_SCRIPT,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(ghclibexecdir)"); \
821 done
822 endif
823
824 install_libexecs: $(INSTALL_LIBEXECS)
825 ifeq "$(INSTALL_LIBEXECS)" ""
826 @:
827 else
828 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibexecdir)")
829 for i in $(INSTALL_LIBEXECS); do \
830 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(ghclibexecdir)"); \
831 done
832 # We rename ghc-stage2, so that the right program name is used in error
833 # messages etc.
834 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/ghc"
835 endif
836
837 install_topdirs: $(INSTALL_TOPDIRS)
838 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
839 for i in $(INSTALL_TOPDIRS); do \
840 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(topdir)"); \
841 done
842
843 install_docs: $(INSTALL_DOCS)
844 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)")
845 ifneq "$(INSTALL_DOCS)" ""
846 for i in $(INSTALL_DOCS); do \
847 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)"); \
848 done
849 endif
850 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html")
851 $(call INSTALL_DOC,$(INSTALL_OPTS),docs/index.html,"$(DESTDIR)$(docdir)/html")
852 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
853 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/libraries")
854 for i in $(INSTALL_LIBRARY_DOCS); do \
855 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)/html/libraries/"); \
856 done
857 $(call INSTALL_DATA,$(INSTALL_OPTS),libraries/prologue.txt,"$(DESTDIR)$(docdir)/html/libraries/")
858 $(call INSTALL_SCRIPT,$(INSTALL_OPTS),libraries/gen_contents_index,"$(DESTDIR)$(docdir)/html/libraries/")
859 endif
860 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
861 for i in $(INSTALL_HTML_DOC_DIRS); do \
862 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
863 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i/*,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
864 done
865 endif
866
867 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
868
869 # Install packages in the right order, so that ghc-pkg doesn't complain.
870 # Also, install ghc-pkg first.
871 ifeq "$(Windows)" "NO"
872 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/ghc
873 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/ghc-pkg
874 else
875 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
876 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
877 endif
878
879 INSTALLED_PKG_DIRS := $(addprefix libraries/,$(PACKAGES_STAGE1))
880 ifeq "$(BuildingCrossCompiler)" "NO"
881 INSTALLED_PKG_DIRS := $(INSTALLED_PKG_DIRS) compiler
882 endif
883 INSTALLED_PKG_DIRS := $(INSTALLED_PKG_DIRS) $(addprefix libraries/,$(PACKAGES_STAGE2))
884 ifeq "$(InstallExtraPackages)" "NO"
885 INSTALLED_PKG_DIRS := $(filter-out $(addprefix libraries/,$(EXTRA_PACKAGES)),\
886 $(INSTALLED_PKG_DIRS))
887 endif
888 INSTALLED_PKG_DIRS := $(filter-out $(addprefix libraries/,$(PKGS_THAT_ARE_INTREE_ONLY)),\
889 $(INSTALLED_PKG_DIRS))
890
891 # Set the INSTALL_DISTDIR_p for each package; compiler is special
892 $(foreach p,$(filter-out compiler,$(INSTALLED_PKG_DIRS)),\
893 $(eval INSTALL_DISTDIR_$p = dist-install))
894 INSTALL_DISTDIR_compiler = stage2
895
896 # Now we can do the installation
897 install_packages: install_libexecs
898 install_packages: rts/package.conf.install
899 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
900 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
901 $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
902 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/package.conf.install
903 $(foreach p, $(INSTALLED_PKG_DIRS), \
904 $(call make-command, \
905 CROSS_COMPILE="$(CrossCompilePrefix)" \
906 "$(GHC_CABAL_INPLACE)" install \
907 "$(INSTALLED_GHC_REAL)" \
908 "$(INSTALLED_GHC_PKG_REAL)" \
909 "$(STRIP_CMD)" \
910 "$(DESTDIR)$(topdir)" \
911 $p $(INSTALL_DISTDIR_$p) \
912 '$(DESTDIR)' \
913 '$(prefix)' \
914 '$(ghclibdir)' \
915 '$(docdir)/html/libraries' \
916 $(RelocatableBuild)))
917 # when we install the packages above, ghc-pkg obeys umask when creating
918 # the package.conf files, but for everything else we specify the
919 # permissions. We therefore now fix the permissions of package.cache.
920 # This means "sudo make install" does the right thing even if it runs
921 # with an 077 umask.
922 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
923
924 # -----------------------------------------------------------------------------
925 # Binary distributions
926
927 ifneq "$(CLEANING)" "YES"
928 # This rule seems to hold some files open on Windows which prevents
929 # cleaning, perhaps due to the $(wildcard).
930
931 $(eval $(call bindist,.,\
932 LICENSE \
933 README \
934 INSTALL \
935 configure config.sub config.guess install-sh \
936 settings.in \
937 packages \
938 Makefile \
939 mk/config.mk.in \
940 $(INPLACE_BIN)/mkdirhier \
941 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
942 utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
943 $(BINDIST_WRAPPERS) \
944 $(BINDIST_PERL_SOURCES) \
945 $(BINDIST_LIBS) \
946 $(BINDIST_HI) \
947 $(BINDIST_EXTRAS) \
948 $(includes_H_FILES) \
949 $(includes_DERIVEDCONSTANTS) \
950 $(includes_GHCCONSTANTS) \
951 $(libffi_HEADERS) \
952 $(INSTALL_LIBEXECS) \
953 $(INSTALL_LIBEXEC_SCRIPTS) \
954 $(INSTALL_TOPDIRS) \
955 $(INSTALL_BINS) \
956 $(INSTALL_MANPAGES) \
957 $(INSTALL_DOCS) \
958 $(INSTALL_LIBRARY_DOCS) \
959 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
960 docs/index.html \
961 compiler/stage2/doc \
962 $(wildcard libraries/*/dist-install/doc/) \
963 $(wildcard libraries/*/*/dist-install/doc/) \
964 $(filter-out settings,$(INSTALL_LIBS)) \
965 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
966 mk/project.mk \
967 mk/install.mk.in \
968 bindist.mk \
969 libraries/gen_contents_index \
970 libraries/prologue.txt \
971 $(wildcard libraries/dph/LICENSE \
972 libraries/dph/ghc-packages \
973 libraries/dph/ghc-packages2 \
974 libraries/dph/ghc-stage2-package) \
975 ))
976 endif
977 # mk/project.mk gets an absolute path, so we manually include it in
978 # the bindist with a relative path
979
980 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
981
982 unix-binary-dist-prep:
983 $(call removeTrees,bindistprep/)
984 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
985 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 ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
986 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
987 echo "LATEX_DOCS = $(LATEX_DOCS)" >> $(BIN_DIST_MK)
988 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
989 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
990 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
991 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
992 echo "GHC_CABAL_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal" >> $(BIN_DIST_MK)
993 cd $(BIN_DIST_PREP_DIR) && autoreconf
994 $(call removeFiles,$(BIN_DIST_PREP_TAR))
995 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
996 # tree then we want to include the real file, not a symlink to it
997 cd bindistprep && "$(TAR_CMD)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
998
999 windows-binary-dist-prep:
1000 $(call removeTrees,bindistprep/)
1001 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1002 cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1003
1004 windows-installer:
1005 ifeq "$(ISCC_CMD)" ""
1006 @echo No ISCC_CMD, so not making installer
1007 else
1008 "$(ISCC_CMD)" /O. /Fbindistprep/$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
1009 endif
1010
1011 # tryTimes tries to run its third argument multiple times, until it
1012 # succeeds. Don't call it directly; call try10Times instead.
1013 # The first and second argument to tryTimes are lists of values.
1014 # The length of the first argument is the number of times we have
1015 # already tried. The length of the second argument is the number more
1016 # times we will try.
1017 tryTimes = $(if $2, \
1018 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1019 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1020 )
1021
1022 # Try to run the argument 10 times. If all 10 fail, fail.
1023 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1024
1025 .PHONY: publish-binary-dist
1026 publish-binary-dist:
1027 $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
1028 ifeq "$(mingw32_TARGET_OS)" "1"
1029 $(call try10Times,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
1030 endif
1031
1032 ifeq "$(mingw32_TARGET_OS)" "1"
1033 DOCDIR_TO_PUBLISH = bindisttest/"install dir"/doc
1034 else
1035 DOCDIR_TO_PUBLISH = bindisttest/"install dir"/share/doc/ghc
1036 endif
1037
1038 .PHONY: publish-docs
1039 publish-docs:
1040 $(call try10Times,$(PublishCp) -r $(DOCDIR_TO_PUBLISH)/* $(PublishLocation)/docs)
1041
1042 # -----------------------------------------------------------------------------
1043 # Source distributions
1044
1045 # Do it like this:
1046 #
1047 # $ make
1048 # $ make sdist
1049 #
1050
1051 # A source dist is built from a complete build tree, because we
1052 # require some extra files not contained in a darcs checkout: the
1053 # output from Happy and Alex, for example.
1054 #
1055 # The steps performed by 'make dist' are as follows:
1056 # - create a complete link-tree of the current build tree in /tmp
1057 # - run 'make distclean' on that tree
1058 # - remove a bunch of other files that we know shouldn't be in the dist
1059 # - tar up first the extralibs package, then the main source package
1060
1061 #
1062 # Directory in which we're going to build the src dist
1063 #
1064 SRC_DIST_ROOT = sdistprep
1065 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
1066
1067 SRC_DIST_GHC_NAME = ghc-$(ProjectVersion)-src
1068 SRC_DIST_GHC_ROOT = $(SRC_DIST_ROOT)/ghc
1069 SRC_DIST_GHC_DIR = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
1070 SRC_DIST_GHC_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.bz2
1071
1072 SRC_DIST_TESTSUITE_NAME = ghc-$(ProjectVersion)-testsuite
1073 SRC_DIST_TESTSUITE_ROOT = $(SRC_DIST_ROOT)/testsuite-ghc
1074 SRC_DIST_TESTSUITE_DIR = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
1075 SRC_DIST_TESTSUITE_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.bz2
1076
1077 #
1078 # Files to include in source distributions
1079 #
1080 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
1081 utils docs rts compiler ghc driver libraries ghc-tarballs
1082 SRC_DIST_GHC_FILES += \
1083 configure.ac config.guess config.sub configure \
1084 aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
1085 ghc.spec.in ghc.spec settings.in VERSION \
1086 boot boot-pkgs packages ghc.mk
1087
1088 VERSION :
1089 echo $(ProjectVersion) >VERSION
1090
1091 sdist : VERSION
1092
1093 # Use:
1094 # $(call sdist_ghc_file,compiler,stage2,cmm,Foo/Bar,CmmLex,x)
1095 # to copy the generated file that replaces compiler/cmm/Foo/Bar/CmmLex.x, where
1096 # "stage2" is the dist dir.
1097 define sdist_ghc_file
1098 "$(CP)" $1/$2/build/$4/$5.hs $(SRC_DIST_GHC_DIR)/$1/$3/$4
1099 mv $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6 $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6.source
1100 endef
1101
1102 .PHONY: sdist-ghc-prep
1103 sdist-ghc-prep :
1104 $(call removeTrees,$(SRC_DIST_GHC_ROOT))
1105 $(call removeFiles,$(SRC_DIST_GHC_TARBALL))
1106 -mkdir $(SRC_DIST_ROOT)
1107 mkdir $(SRC_DIST_GHC_ROOT)
1108 mkdir $(SRC_DIST_GHC_DIR)
1109 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_DIRS); do mkdir $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1110 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_FILES); do $(LN_S) $(TOP)/$$i .; done
1111 cd $(SRC_DIST_GHC_DIR) && $(MAKE) distclean
1112 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/tarballs/)
1113 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/stamp/)
1114 $(call removeTrees,$(SRC_DIST_GHC_DIR)/compiler/stage[123])
1115 $(call removeFiles,$(SRC_DIST_GHC_DIR)/mk/build.mk)
1116 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmLex,x)
1117 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmParse,y)
1118 $(call sdist_ghc_file,compiler,stage2,parser,,Lexer,x)
1119 $(call sdist_ghc_file,compiler,stage2,parser,,Parser,y.pp)
1120 $(call sdist_ghc_file,compiler,stage2,parser,,ParserCore,y)
1121 $(call sdist_ghc_file,utils/hpc,dist-install,,,HpcParser,y)
1122 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Lexer,x)
1123 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Parser,y)
1124 $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Lex,x)
1125 $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Parse,y)
1126 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)
1127
1128 .PHONY: sdist-testsuite-prep
1129 sdist-testsuite-prep :
1130 $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
1131 $(call removeFiles,$(SRC_DIST_TESTSUITE_TARBALL))
1132 -mkdir $(SRC_DIST_ROOT)
1133 mkdir $(SRC_DIST_TESTSUITE_ROOT)
1134 mkdir $(SRC_DIST_TESTSUITE_DIR)
1135 mkdir $(SRC_DIST_TESTSUITE_DIR)/testsuite
1136 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && lndir $(TOP)/testsuite
1137 $(call removeTrees,$(SRC_DIST_TESTSUITE_DIR)/testsuite/.git)
1138
1139 .PHONY: sdist
1140 sdist : sdist-ghc-prep sdist-testsuite-prep
1141 cd $(SRC_DIST_GHC_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_GHC_TARBALL)
1142 cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
1143
1144 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
1145 tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1146
1147 # Upload the distribution(s)
1148 # Retrying is to work around buggy firewalls that corrupt large file transfers
1149 # over SSH.
1150 ifneq "$(PublishLocation)" ""
1151 publish-sdist :
1152 $(call try10Times,$(PublishCp) $(SRC_DIST_GHC_TARBALL) $(PublishLocation)/dist)
1153 $(call try10Times,$(PublishCp) $(SRC_DIST_TESTSUITE_TARBALL) $(PublishLocation)/dist)
1154 endif
1155
1156 ifeq "$(BootingFromHc)" "YES"
1157 # In a normal build we use GHC to compile C files (see
1158 # rules/c-suffix-rules.mk), which passes a number of its own options
1159 # to the C compiler. So when bootstrapping we have to provide these
1160 # flags explicitly to C compilations.
1161 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
1162 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
1163 SRC_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
1164 endif
1165
1166 # -----------------------------------------------------------------------------
1167 # sdisting libraries
1168
1169 # Use manually, with e.g.:
1170 # make sdist_directory
1171
1172 sdist_%:
1173 inplace/bin/ghc-cabal sdist libraries/$* dist-install
1174
1175 # -----------------------------------------------------------------------------
1176 # Cleaning
1177
1178 .PHONY: clean
1179
1180 CLEAN_FILES += libraries/bootstrapping.conf
1181 CLEAN_FILES += libraries/integer-gmp/cbits/GmpDerivedConstants.h
1182 CLEAN_FILES += libraries/integer-gmp/cbits/mkGmpDerivedConstants
1183
1184 # These four are no longer generated, but we still clean them for a while
1185 # as they may still be in old GHC trees:
1186 CLEAN_FILES += includes/GHCConstants.h
1187 CLEAN_FILES += includes/DerivedConstants.h
1188 CLEAN_FILES += includes/ghcautoconf.h
1189 CLEAN_FILES += includes/ghcplatform.h
1190
1191 clean : clean_files clean_libraries
1192
1193 .PHONY: clean_files
1194 clean_files :
1195 $(call removeFiles,$(CLEAN_FILES))
1196
1197 .PHONY: clean_libraries
1198 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2))
1199 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(PACKAGES_STAGE0))
1200
1201 clean_libraries:
1202 $(call removeTrees,$(patsubst %, libraries/%/dist, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1203 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/*.buildinfo, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1204 $(call removeFiles,$(patsubst %, libraries/%/config.log, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1205 $(call removeFiles,$(patsubst %, libraries/%/config.status, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1206 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1207
1208 # We have to define a clean target for each library manually, because the
1209 # libraries/*/ghc.mk files are not included when we're cleaning.
1210 ifeq "$(CLEANING)" "YES"
1211 $(foreach lib,$(PACKAGES_STAGE0),\
1212 $(eval $(call clean-target,libraries/$(lib),dist-boot,libraries/$(lib)/dist-boot)))
1213 $(foreach lib,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),\
1214 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1215 endif
1216
1217 clean : clean_haddock_index
1218 .PHONY: clean_haddock_index
1219 clean_haddock_index:
1220 $(call removeTrees,libraries/dist-haddock)
1221
1222 clean : clean_bindistprep
1223 .PHONY: clean_bindistprep
1224 clean_bindistprep:
1225 $(call removeTrees,bindistprep/)
1226
1227 distclean : clean
1228 $(call removeFiles,config.cache config.status config.log mk/config.h mk/stamp-h)
1229 $(call removeFiles,mk/config.mk mk/are-validating.mk mk/project.mk)
1230 $(call removeFiles,mk/config.mk.old mk/project.mk.old)
1231 $(call removeFiles,settings docs/users_guide/ug-book.xml)
1232 $(call removeFiles,compiler/ghc.cabal compiler/ghc.cabal.old)
1233 $(call removeFiles,ghc/ghc-bin.cabal)
1234 $(call removeFiles,libraries/base/include/HsBaseConfig.h)
1235 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
1236 $(call removeFiles,libraries/process/include/HsProcessConfig.h)
1237 $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
1238 $(call removeFiles,libraries/old-time/include/HsTimeConfig.h)
1239 $(call removeTrees,utils/ghc-pwd/dist-boot)
1240 $(call removeTrees,inplace)
1241 $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1242
1243 maintainer-clean : distclean
1244 $(call removeFiles,configure mk/config.h.in)
1245 $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
1246 $(call removeFiles,ghc.spec)
1247 $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
1248 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1249 $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1250 $(call removeFiles,$(patsubst %, libraries/%/configure, \
1251 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1252 $(call removeFiles,libraries/base/include/HsBaseConfig.h.in)
1253 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
1254 $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
1255 $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
1256 $(call removeFiles,libraries/old-time/include/HsTimeConfig.h.in)
1257
1258 .PHONY: all_libraries
1259
1260 .PHONY: bootstrapping-files
1261 bootstrapping-files: $(includes_H_CONFIG)
1262 bootstrapping-files: $(includes_DERIVEDCONSTANTS)
1263 bootstrapping-files: $(includes_GHCCONSTANTS)
1264 bootstrapping-files: $(libffi_HEADERS)
1265
1266 .DELETE_ON_ERROR:
1267
1268 # -----------------------------------------------------------------------------
1269 # Numbered phase targets
1270
1271 .PHONY: phase_0_builds
1272 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1273 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1274 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1275 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1276
1277 .PHONY: phase_1_builds
1278 phase_1_builds: $(PACKAGE_DATA_MKS)
1279