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