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