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