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