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