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