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