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