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