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