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