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