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