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