De-tab compiler/nativeGen/PPC/Instr.hs.
[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 BUILD_DIRS += \
622 driver \
623 $(MAYBE_GHCI) \
624 driver/ghc \
625 driver/haddock \
626 libffi \
627 includes \
628 rts
629
630 ifneq "$(BINDIST)" "YES"
631 BUILD_DIRS += \
632 bindisttest \
633 $(GHC_GENAPPLY_DIR)
634 endif
635
636 ifneq "$(CLEANING)" "YES"
637 BUILD_DIRS += \
638 $(patsubst %, libraries/%, $(PACKAGES_STAGE1))
639 endif
640
641 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
642 BUILD_DIRS += libraries/integer-gmp/gmp
643 else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
644 BUILD_DIRS += libraries/integer-gmp/gmp
645 endif
646
647 ifeq "$(BuildingCrossCompiler)-$(phase)" "YES-final"
648 MAYBE_COMPILER=
649 MAYBE_GHCTAGS=
650 MAYBE_HPC=
651 MAYBE_RUNGHC=
652 else
653 MAYBE_COMPILER=compiler
654 MAYBE_GHCTAGS=utils/ghctags
655 MAYBE_HPC=utils/hpc
656 MAYBE_RUNGHC=utils/runghc
657 endif
658
659 BUILD_DIRS += \
660 utils/haddock \
661 utils/haddock/doc \
662 $(MAYBE_COMPILER) \
663 $(GHC_HSC2HS_DIR) \
664 $(GHC_PKG_DIR) \
665 utils/deriveConstants \
666 utils/testremove \
667 $(MAYBE_GHCTAGS) \
668 utils/ghc-pwd \
669 $(GHC_CABAL_DIR) \
670 $(MAYBE_HPC) \
671 $(MAYBE_RUNGHC) \
672 ghc
673
674 ifneq "$(BINDIST)" "YES"
675 ifneq "$(BuildingCrossCompiler)-$(phase)" "YES-final"
676 BUILD_DIRS += \
677 utils/mkUserGuidePart
678 endif
679 endif
680
681 BUILD_DIRS += utils/count_lines
682 BUILD_DIRS += utils/compare_sizes
683
684 ifneq "$(CLEANING)" "YES"
685 # After compiler/, because these packages depend on it
686 BUILD_DIRS += \
687 $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
688 endif
689
690 # ----------------------------------------------
691 # Actually include all the sub-ghc.mk's
692
693 # BUILD_DIRS_EXTRA needs to come after BUILD_DIRS, because stuff in
694 # libraries/dph/ghc.mk refers to stuff defined earlier, in particular
695 # things like $(libraries/dph/dph-base_dist-install_GHCI_LIB)
696 ifeq "$(GhcProfiled)" "YES"
697 BUILD_DIRS_EXTRA := $(filter-out libraries/dph,$(BUILD_DIRS_EXTRA))
698 endif
699 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS) $(BUILD_DIRS_EXTRA))
700
701 # A useful pseudo-target (must be after the include above, because it needs
702 # the value of things like $(libraries/base_dist-install_v_LIB).
703 .PHONY: stage1_libs
704 stage1_libs : $(ALL_STAGE1_LIBS)
705
706 # ----------------------------------------------
707 # Per-package compiler flags
708 #
709 # If you want to add per-package compiler flags, this
710 # is the place to do it. Do it like this for package <pkg>
711 #
712 # libraries/<pkg>_dist-boot_HC_OPTS += -Wwarn
713 # libraries/<pkg>_dist-install_HC_OPTS += -Wwarn
714
715 # Add $(GhcLibHcOpts) to all package builds
716 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
717
718 # Add $(GhcBootLibHcOpts) to all stage0 package builds
719 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
720
721 # -----------------------------------------------
722 # Haddock-related bits
723
724 # Don't run Haddock for the package that will not be installed
725 $(foreach p,$(PKGS_THAT_ARE_INTREE_ONLY),$(eval libraries/$p_dist-install_DO_HADDOCK = NO))
726 # We don't haddock the bootstrapping libraries
727 $(foreach p,$(PACKAGES_STAGE0),$(eval libraries/$p_dist-boot_DO_HADDOCK = NO))
728
729 # Build the Haddock contents and index
730 ifeq "$(HADDOCK_DOCS)" "YES"
731 libraries/dist-haddock/index.html: inplace/bin/haddock$(exeext) $(ALL_HADDOCK_FILES)
732 cd libraries && sh gen_contents_index --inplace
733 ifeq "$(phase)" "final"
734 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
735 endif
736 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
737 endif
738
739 # -----------------------------------------------------------------------------
740 # Bootstrapping libraries
741
742 # We need to build a few libraries with the installed GHC, since GHC itself
743 # and some of the tools depend on them:
744
745 ifneq "$(BINDIST)" "YES"
746
747 ifneq "$(BOOTSTRAPPING_CONF)" ""
748 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
749 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
750 endif
751 endif
752
753 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
754
755 # register the boot packages in strict sequence, because running
756 # multiple ghc-pkgs in parallel doesn't work (registrations may get
757 # lost).
758 fixed_pkg_prev=
759 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
760
761 compiler/stage1/package-data.mk : $(fixed_pkg_prev)
762 endif
763
764 ifneq "$(BINDIST)" "YES"
765 # Make sure we have all the GHCi libs by the time we've built
766 # ghc-stage2. DPH includes a bit of Template Haskell which needs the
767 # GHCI libs, and we don't have a better way to express that dependency.
768 #
769 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
770 $(compiler_stage2_GHCI_LIB)
771
772 ifeq "$(UseArchivesForGhci)" "NO"
773 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
774 endif
775
776 ifeq "$(UseArchivesForGhci)" "YES"
777 GHCI_lib_way = v
778 else
779 GHCI_lib_way = GHCI
780 endif
781
782 # Deps for TH uses in libraries
783 $(foreach way, $(GhcLibWays),$(eval \
784 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
785 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
786 ))
787 endif
788
789 # -----------------------------------------------------------------------------
790 # Creating a local mingw copy on Windows
791
792 ifeq "$(Windows)" "YES"
793
794 install : install_mingw
795 .PHONY: install_mingw
796 install_mingw : $(INPLACE_MINGW)
797 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
798
799 install : install_perl
800 .PHONY: install_perl
801 install_perl : $(INPLACE_PERL)
802 "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
803
804 endif # Windows
805
806 ifneq "$(BINDIST)" "YES"
807 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
808 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
809 endif # BINDIST
810
811 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
812 $(PRIMOPS_TXT_STAGE1) $(GENPRIMOP_INPLACE) \
813 | $$(dir $$@)/.
814 "$(GENPRIMOP_INPLACE)" --make-haskell-source < $< > $@
815
816 .PHONY: tags
817 tags: tags_compiler
818
819 .PHONY: TAGS
820 TAGS: TAGS_compiler
821
822 # -----------------------------------------------------------------------------
823 # Installation
824
825 install: install_libs install_packages install_libexecs \
826 install_bins install_topdirs
827 ifeq "$(HADDOCK_DOCS)" "YES"
828 install: install_docs
829 endif
830
831 define installLibsTo
832 # $1 = libraries to install
833 # $2 = directory to install to
834 $(call INSTALL_DIR,$2)
835 for i in $1; do \
836 case $$i in \
837 *.a) \
838 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
839 $(RANLIB) $2/`basename $$i` ;; \
840 *.dll) \
841 $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,$2) ; \
842 $(STRIP_CMD) $2/`basename $$i` ;; \
843 *.so) \
844 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2) ;; \
845 *.dylib) \
846 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2);; \
847 *) \
848 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
849 esac; \
850 done
851 endef
852
853 install_bins: $(INSTALL_BINS)
854 $(call INSTALL_DIR,"$(DESTDIR)$(bindir)")
855 for i in $(INSTALL_BINS); do \
856 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(bindir)") ; \
857 done
858
859 install_libs: $(INSTALL_LIBS)
860 $(call installLibsTo, $(INSTALL_LIBS), "$(DESTDIR)$(ghclibdir)")
861
862 install_libexecs: $(INSTALL_LIBEXECS)
863 ifeq "$(INSTALL_LIBEXECS)" ""
864 @:
865 else
866 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibexecdir)/bin")
867 for i in $(INSTALL_LIBEXECS); do \
868 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(ghclibexecdir)/bin"); \
869 done
870 # We rename ghc-stage2, so that the right program name is used in error
871 # messages etc.
872 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc"
873 endif
874
875 install_topdirs: $(INSTALL_TOPDIRS)
876 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
877 for i in $(INSTALL_TOPDIRS); do \
878 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(topdir)"); \
879 done
880
881 install_docs: $(INSTALL_DOCS)
882 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)")
883 ifneq "$(INSTALL_DOCS)" ""
884 for i in $(INSTALL_DOCS); do \
885 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)"); \
886 done
887 endif
888 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html")
889 $(call INSTALL_DOC,$(INSTALL_OPTS),docs/index.html,"$(DESTDIR)$(docdir)/html")
890 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
891 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/libraries")
892 for i in $(INSTALL_LIBRARY_DOCS); do \
893 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)/html/libraries/"); \
894 done
895 $(call INSTALL_DATA,$(INSTALL_OPTS),libraries/prologue.txt,"$(DESTDIR)$(docdir)/html/libraries/")
896 $(call INSTALL_SCRIPT,$(INSTALL_OPTS),libraries/gen_contents_index,"$(DESTDIR)$(docdir)/html/libraries/")
897 endif
898 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
899 for i in $(INSTALL_HTML_DOC_DIRS); do \
900 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
901 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i/*,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
902 done
903 endif
904
905 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
906
907 # Install packages in the right order, so that ghc-pkg doesn't complain.
908 # Also, install ghc-pkg first.
909 ifeq "$(Windows)" "NO"
910 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
911 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
912 else
913 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
914 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
915 endif
916
917 INSTALLED_PKG_DIRS := $(addprefix libraries/,$(PACKAGES_STAGE1))
918 ifeq "$(BuildingCrossCompiler)" "NO"
919 INSTALLED_PKG_DIRS := $(INSTALLED_PKG_DIRS) compiler
920 endif
921 INSTALLED_PKG_DIRS := $(INSTALLED_PKG_DIRS) $(addprefix libraries/,$(PACKAGES_STAGE2))
922 ifeq "$(InstallExtraPackages)" "NO"
923 INSTALLED_PKG_DIRS := $(filter-out $(addprefix libraries/,$(EXTRA_PACKAGES)),\
924 $(INSTALLED_PKG_DIRS))
925 endif
926 INSTALLED_PKG_DIRS := $(filter-out $(addprefix libraries/,$(PKGS_THAT_ARE_INTREE_ONLY)),\
927 $(INSTALLED_PKG_DIRS))
928
929 # Set the INSTALL_DISTDIR_p for each package; compiler is special
930 $(foreach p,$(filter-out compiler,$(INSTALLED_PKG_DIRS)),\
931 $(eval INSTALL_DISTDIR_$p = dist-install))
932 INSTALL_DISTDIR_compiler = stage2
933
934 # Now we can do the installation
935 install_packages: install_libexecs
936 install_packages: rts/package.conf.install
937 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
938 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
939 $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
940 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)/rts-1.0")
941 $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts-1.0")
942 ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
943 $(foreach p, $(PKGS_THAT_ARE_INTREE_ONLY), \
944 $(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)"))
945 endif
946 $(foreach p, $(INSTALLED_PKG_DIRS), \
947 $(call make-command, \
948 CROSS_COMPILE="$(CrossCompilePrefix)" \
949 "$(GHC_CABAL_INPLACE)" copy \
950 "$(STRIP_CMD)" \
951 $p $(INSTALL_DISTDIR_$p) \
952 '$(DESTDIR)' \
953 '$(prefix)' \
954 '$(ghclibdir)' \
955 '$(docdir)/html/libraries'))
956 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/package.conf.install
957 $(foreach p, $(INSTALLED_PKG_DIRS), \
958 $(call make-command, \
959 CROSS_COMPILE="$(CrossCompilePrefix)" \
960 "$(GHC_CABAL_INPLACE)" register \
961 "$(INSTALLED_GHC_REAL)" \
962 "$(INSTALLED_GHC_PKG_REAL)" \
963 "$(DESTDIR)$(topdir)" \
964 $p $(INSTALL_DISTDIR_$p) \
965 '$(DESTDIR)' \
966 '$(prefix)' \
967 '$(ghclibdir)' \
968 '$(docdir)/html/libraries' \
969 $(RelocatableBuild)))
970 # when we install the packages above, ghc-pkg obeys umask when creating
971 # the package.conf files, but for everything else we specify the
972 # permissions. We therefore now fix the permissions of package.cache.
973 # This means "sudo make install" does the right thing even if it runs
974 # with an 077 umask.
975 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
976
977 # -----------------------------------------------------------------------------
978 # Binary distributions
979
980 ifneq "$(CLEANING)" "YES"
981 # This rule seems to hold some files open on Windows which prevents
982 # cleaning, perhaps due to the $(wildcard).
983
984 $(eval $(call bindist,.,\
985 LICENSE \
986 README \
987 INSTALL \
988 configure config.sub config.guess install-sh \
989 settings.in \
990 packages \
991 Makefile \
992 mk/config.mk.in \
993 $(INPLACE_BIN)/mkdirhier \
994 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
995 utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
996 $(BINDIST_WRAPPERS) \
997 $(BINDIST_PERL_SOURCES) \
998 $(BINDIST_LIBS) \
999 $(BINDIST_HI) \
1000 $(BINDIST_EXTRAS) \
1001 $(includes_H_FILES) \
1002 $(includes_DERIVEDCONSTANTS) \
1003 $(includes_GHCCONSTANTS) \
1004 $(libffi_HEADERS) \
1005 $(INSTALL_LIBEXECS) \
1006 $(INSTALL_LIBEXEC_SCRIPTS) \
1007 $(INSTALL_TOPDIRS) \
1008 $(INSTALL_BINS) \
1009 $(INSTALL_MANPAGES) \
1010 $(INSTALL_DOCS) \
1011 $(INSTALL_LIBRARY_DOCS) \
1012 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
1013 docs/index.html \
1014 compiler/stage2/doc \
1015 $(wildcard libraries/*/dist-install/doc/) \
1016 $(wildcard libraries/*/*/dist-install/doc/) \
1017 $(filter-out settings,$(INSTALL_LIBS)) \
1018 $(RTS_INSTALL_LIBS) \
1019 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
1020 mk/project.mk \
1021 mk/install.mk.in \
1022 bindist.mk \
1023 libraries/gen_contents_index \
1024 libraries/prologue.txt \
1025 $(wildcard libraries/dph/LICENSE \
1026 libraries/dph/ghc-packages \
1027 libraries/dph/ghc-packages2 \
1028 libraries/dph/ghc-stage2-package) \
1029 ))
1030 endif
1031 # mk/project.mk gets an absolute path, so we manually include it in
1032 # the bindist with a relative path
1033
1034 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
1035
1036 unix-binary-dist-prep:
1037 $(call removeTrees,bindistprep/)
1038 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
1039 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
1040 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
1041 echo "LATEX_DOCS = $(LATEX_DOCS)" >> $(BIN_DIST_MK)
1042 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
1043 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
1044 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
1045 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
1046 echo "GHC_CABAL_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
1047 echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
1048 cd $(BIN_DIST_PREP_DIR) && autoreconf
1049 $(call removeFiles,$(BIN_DIST_PREP_TAR))
1050 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1051 # tree then we want to include the real file, not a symlink to it
1052 cd bindistprep && "$(TAR_CMD)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1053
1054 windows-binary-dist-prep:
1055 $(call removeTrees,bindistprep/)
1056 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1057 cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1058
1059 windows-installer:
1060 ifeq "$(ISCC_CMD)" ""
1061 @echo No ISCC_CMD, so not making installer
1062 else
1063 "$(ISCC_CMD)" /O. /Fbindistprep/$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
1064 endif
1065
1066 # tryTimes tries to run its third argument multiple times, until it
1067 # succeeds. Don't call it directly; call try10Times instead.
1068 # The first and second argument to tryTimes are lists of values.
1069 # The length of the first argument is the number of times we have
1070 # already tried. The length of the second argument is the number more
1071 # times we will try.
1072 tryTimes = $(if $2, \
1073 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1074 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1075 )
1076
1077 # Try to run the argument 10 times. If all 10 fail, fail.
1078 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1079
1080 .PHONY: publish-binary-dist
1081 publish-binary-dist:
1082 $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
1083 ifeq "$(mingw32_TARGET_OS)" "1"
1084 $(call try10Times,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
1085 endif
1086
1087 ifeq "$(mingw32_TARGET_OS)" "1"
1088 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/doc
1089 else
1090 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/share/doc/ghc
1091 endif
1092
1093 .PHONY: publish-docs
1094 publish-docs:
1095 $(call try10Times,$(PublishCp) -r $(DOCDIR_TO_PUBLISH)/* $(PublishLocation)/docs)
1096
1097 # -----------------------------------------------------------------------------
1098 # Source distributions
1099
1100 # Do it like this:
1101 #
1102 # $ make
1103 # $ make sdist
1104 #
1105
1106 # A source dist is built from a complete build tree, because we
1107 # require some extra files not contained in a darcs checkout: the
1108 # output from Happy and Alex, for example.
1109 #
1110 # The steps performed by 'make dist' are as follows:
1111 # - create a complete link-tree of the current build tree in /tmp
1112 # - run 'make distclean' on that tree
1113 # - remove a bunch of other files that we know shouldn't be in the dist
1114 # - tar up first the extralibs package, then the main source package
1115
1116 #
1117 # Directory in which we're going to build the src dist
1118 #
1119 SRC_DIST_ROOT = sdistprep
1120 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
1121
1122 SRC_DIST_GHC_NAME = ghc-$(ProjectVersion)-src
1123 SRC_DIST_GHC_ROOT = $(SRC_DIST_ROOT)/ghc
1124 SRC_DIST_GHC_DIR = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
1125 SRC_DIST_GHC_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.bz2
1126
1127 SRC_DIST_TESTSUITE_NAME = ghc-$(ProjectVersion)-testsuite
1128 SRC_DIST_TESTSUITE_ROOT = $(SRC_DIST_ROOT)/testsuite-ghc
1129 SRC_DIST_TESTSUITE_DIR = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
1130 SRC_DIST_TESTSUITE_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.bz2
1131
1132 #
1133 # Files to include in source distributions
1134 #
1135 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
1136 utils docs rts compiler ghc driver libraries ghc-tarballs
1137 SRC_DIST_GHC_FILES += \
1138 configure.ac config.guess config.sub configure \
1139 aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
1140 ghc.spec.in ghc.spec settings.in VERSION \
1141 boot boot-pkgs packages ghc.mk
1142
1143 VERSION :
1144 echo $(ProjectVersion) >VERSION
1145
1146 sdist : VERSION
1147
1148 # Use:
1149 # $(call sdist_ghc_file,compiler,stage2,cmm,Foo/Bar,CmmLex,x)
1150 # to copy the generated file that replaces compiler/cmm/Foo/Bar/CmmLex.x, where
1151 # "stage2" is the dist dir.
1152 define sdist_ghc_file
1153 "$(CP)" $1/$2/build/$4/$5.hs $(SRC_DIST_GHC_DIR)/$1/$3/$4
1154 mv $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6 $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6.source
1155 endef
1156
1157 .PHONY: sdist-ghc-prep
1158 sdist-ghc-prep :
1159 $(call removeTrees,$(SRC_DIST_GHC_ROOT))
1160 $(call removeFiles,$(SRC_DIST_GHC_TARBALL))
1161 -mkdir $(SRC_DIST_ROOT)
1162 mkdir $(SRC_DIST_GHC_ROOT)
1163 mkdir $(SRC_DIST_GHC_DIR)
1164 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_DIRS); do mkdir $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1165 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_FILES); do $(LN_S) $(TOP)/$$i .; done
1166 cd $(SRC_DIST_GHC_DIR) && $(MAKE) distclean
1167 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/tarballs/)
1168 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/stamp/)
1169 $(call removeTrees,$(SRC_DIST_GHC_DIR)/compiler/stage[123])
1170 $(call removeFiles,$(SRC_DIST_GHC_DIR)/mk/build.mk)
1171 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmLex,x)
1172 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmParse,y)
1173 $(call sdist_ghc_file,compiler,stage2,parser,,Lexer,x)
1174 $(call sdist_ghc_file,compiler,stage2,parser,,Parser,y.pp)
1175 $(call sdist_ghc_file,compiler,stage2,parser,,ParserCore,y)
1176 $(call sdist_ghc_file,utils/hpc,dist-install,,,HpcParser,y)
1177 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Lexer,x)
1178 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Parser,y)
1179 $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Lex,x)
1180 $(call sdist_ghc_file,utils/haddock,dist,src,Haddock,Parse,y)
1181 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)
1182
1183 .PHONY: sdist-testsuite-prep
1184 sdist-testsuite-prep :
1185 $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
1186 $(call removeFiles,$(SRC_DIST_TESTSUITE_TARBALL))
1187 -mkdir $(SRC_DIST_ROOT)
1188 mkdir $(SRC_DIST_TESTSUITE_ROOT)
1189 mkdir $(SRC_DIST_TESTSUITE_DIR)
1190 mkdir $(SRC_DIST_TESTSUITE_DIR)/testsuite
1191 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && lndir $(TOP)/testsuite
1192 $(call removeTrees,$(SRC_DIST_TESTSUITE_DIR)/testsuite/.git)
1193
1194 .PHONY: sdist
1195 sdist : sdist-ghc-prep sdist-testsuite-prep
1196 cd $(SRC_DIST_GHC_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_GHC_TARBALL)
1197 cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | bzip2 > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
1198
1199 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
1200 tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1201
1202 # Upload the distribution(s)
1203 # Retrying is to work around buggy firewalls that corrupt large file transfers
1204 # over SSH.
1205 ifneq "$(PublishLocation)" ""
1206 publish-sdist :
1207 $(call try10Times,$(PublishCp) $(SRC_DIST_GHC_TARBALL) $(PublishLocation)/dist)
1208 $(call try10Times,$(PublishCp) $(SRC_DIST_TESTSUITE_TARBALL) $(PublishLocation)/dist)
1209 endif
1210
1211 ifeq "$(BootingFromHc)" "YES"
1212 # In a normal build we use GHC to compile C files (see
1213 # rules/c-suffix-rules.mk), which passes a number of its own options
1214 # to the C compiler. So when bootstrapping we have to provide these
1215 # flags explicitly to C compilations.
1216 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
1217 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
1218 SRC_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
1219 endif
1220
1221 # -----------------------------------------------------------------------------
1222 # sdisting libraries
1223
1224 # Use manually, with e.g.:
1225 # make sdist_directory
1226
1227 sdist_%:
1228 inplace/bin/ghc-cabal sdist libraries/$* dist-install
1229
1230 # -----------------------------------------------------------------------------
1231 # Cleaning
1232
1233 .PHONY: clean
1234
1235 CLEAN_FILES += libraries/bootstrapping.conf
1236 CLEAN_FILES += libraries/integer-gmp/cbits/GmpDerivedConstants.h
1237 CLEAN_FILES += libraries/integer-gmp/cbits/mkGmpDerivedConstants
1238
1239 # These are no longer generated, but we still clean them for a while
1240 # as they may still be in old GHC trees:
1241 CLEAN_FILES += includes/GHCConstants.h
1242 CLEAN_FILES += includes/DerivedConstants.h
1243 CLEAN_FILES += includes/ghcautoconf.h
1244 CLEAN_FILES += includes/ghcplatform.h
1245 CLEAN_FILES += utils/ghc-pkg/Version.hs
1246 CLEAN_FILES += compiler/parser/Parser.y
1247 CLEAN_FILES += compiler/prelude/primops.txt
1248 CLEAN_FILES += $(wildcard compiler/primop*incl)
1249
1250 clean : clean_files clean_libraries
1251
1252 .PHONY: clean_files
1253 clean_files :
1254 $(call removeFiles,$(CLEAN_FILES))
1255
1256 .PHONY: clean_libraries
1257 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2))
1258 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(PACKAGES_STAGE0))
1259
1260 clean_libraries:
1261 $(call removeTrees,$(patsubst %, libraries/%/dist, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1262 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/*.buildinfo, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1263 $(call removeFiles,$(patsubst %, libraries/%/config.log, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1264 $(call removeFiles,$(patsubst %, libraries/%/config.status, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1265 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1266
1267 # We have to define a clean target for each library manually, because the
1268 # libraries/*/ghc.mk files are not included when we're cleaning.
1269 ifeq "$(CLEANING)" "YES"
1270 $(foreach lib,$(PACKAGES_STAGE0),\
1271 $(eval $(call clean-target,libraries/$(lib),dist-boot,libraries/$(lib)/dist-boot)))
1272 $(foreach lib,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),\
1273 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1274 endif
1275
1276 clean : clean_haddock_index
1277 .PHONY: clean_haddock_index
1278 clean_haddock_index:
1279 $(call removeTrees,libraries/dist-haddock)
1280
1281 clean : clean_bindistprep
1282 .PHONY: clean_bindistprep
1283 clean_bindistprep:
1284 $(call removeTrees,bindistprep/)
1285
1286 distclean : clean
1287 $(call removeFiles,config.cache config.status config.log mk/config.h mk/stamp-h)
1288 $(call removeFiles,mk/config.mk mk/are-validating.mk mk/project.mk)
1289 $(call removeFiles,mk/config.mk.old mk/project.mk.old)
1290 $(call removeFiles,settings docs/users_guide/ug-book.xml)
1291 $(call removeFiles,compiler/ghc.cabal compiler/ghc.cabal.old)
1292 $(call removeFiles,ghc/ghc-bin.cabal)
1293 $(call removeFiles,libraries/base/include/HsBaseConfig.h)
1294 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
1295 $(call removeFiles,libraries/process/include/HsProcessConfig.h)
1296 $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
1297 $(call removeFiles,libraries/old-time/include/HsTimeConfig.h)
1298 $(call removeTrees,utils/ghc-pwd/dist-boot)
1299 $(call removeTrees,includes/dist-derivedconstants)
1300 $(call removeTrees,inplace)
1301 $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1302
1303 maintainer-clean : distclean
1304 $(call removeFiles,configure mk/config.h.in)
1305 $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
1306 $(call removeFiles,ghc.spec)
1307 $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
1308 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1309 $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1310 $(call removeFiles,$(patsubst %, libraries/%/configure, \
1311 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1312 $(call removeFiles,libraries/base/include/HsBaseConfig.h.in)
1313 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
1314 $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
1315 $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
1316 $(call removeFiles,libraries/old-time/include/HsTimeConfig.h.in)
1317
1318 .PHONY: all_libraries
1319
1320 .PHONY: bootstrapping-files
1321 bootstrapping-files: $(includes_H_CONFIG)
1322 bootstrapping-files: $(includes_DERIVEDCONSTANTS)
1323 bootstrapping-files: $(includes_GHCCONSTANTS)
1324 bootstrapping-files: $(libffi_HEADERS)
1325
1326 .DELETE_ON_ERROR:
1327
1328 # -----------------------------------------------------------------------------
1329
1330 ifeq "$(HADDOCK_DOCS)" "YES"
1331 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
1332 endif
1333 ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
1334 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
1335 else
1336 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
1337 endif
1338 BINDIST_LIBRARY_FLAGS += --disable-library-prof
1339
1340 .PHONY: validate_build_transformers
1341 validate_build_transformers:
1342 cd libraries/transformers && "$(BINDIST_PREFIX)/bin/ghc" --make Setup
1343 cd libraries/transformers && ./Setup configure --with-ghc="$(BINDIST_PREFIX)/bin/ghc" $(BINDIST_HADDOCK_FLAG) $(BINDIST_LIBRARY_FLAGS) --global --builddir=dist-bindist --prefix="$(BINDIST_PREFIX)"
1344 cd libraries/transformers && ./Setup build --builddir=dist-bindist
1345 ifeq "$(HADDOCK_DOCS)" "YES"
1346 cd libraries/transformers && ./Setup haddock --builddir=dist-bindist
1347 endif
1348 cd libraries/transformers && ./Setup install --builddir=dist-bindist
1349 cd libraries/transformers && ./Setup clean --builddir=dist-bindist
1350 cd libraries/transformers && rm -f Setup Setup.exe Setup.hi Setup.o
1351
1352 # -----------------------------------------------------------------------------
1353 # Numbered phase targets
1354
1355 .PHONY: phase_0_builds
1356 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1357 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1358 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1359 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1360
1361 .PHONY: phase_1_builds
1362 phase_1_builds: $(PACKAGE_DATA_MKS)
1363