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