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