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