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