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