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