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