3b383723535385777480e60180f1144451cf9c6d
[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 ifeq "$(GhcWithInterpreter)" "YES"
665 BUILD_DIRS += utils/runghc
666 else ifeq "$(CLEANING)" "YES"
667 BUILD_DIRS += utils/runghc
668 endif
669 BUILD_DIRS += ghc
670
671 ifneq "$(BINDIST)" "YES"
672 ifneq "$(CrossCompiling)-$(phase)" "YES-final"
673 BUILD_DIRS += utils/mkUserGuidePart
674 endif
675 endif
676
677 BUILD_DIRS += docs/users_guide
678 BUILD_DIRS += docs/man
679 BUILD_DIRS += utils/count_lines
680 BUILD_DIRS += utils/compare_sizes
681
682 # ----------------------------------------------
683 # Actually include all the sub-ghc.mk's
684
685 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
686
687 # A useful pseudo-target (must be after the include above, because it needs
688 # the value of things like $(libraries/base_dist-install_v_LIB).
689 .PHONY: stage1_libs
690 stage1_libs : $(ALL_STAGE1_LIBS)
691
692 # ----------------------------------------------
693 # Per-package compiler flags
694 #
695 # If you want to add per-package compiler flags, see `mk/warnings.mk`.
696
697 # Add $(GhcLib(Extra)HcOpts) to all package builds
698 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
699 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_EXTRA_HC_OPTS += $$(GhcLibExtraHcOpts)))
700
701 # Add $(GhcBootLib(Extra)HcOpts) to all stage0 package builds
702 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
703 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_EXTRA_HC_OPTS += $$(GhcBootLibExtraHcOpts)))
704
705 # -----------------------------------------------------------------------------
706 # Bootstrapping libraries
707
708 # We need to build a few libraries with the installed GHC, since GHC itself
709 # and some of the tools depend on them:
710
711 ifneq "$(BINDIST)" "YES"
712
713 ifneq "$(BOOTSTRAPPING_CONF)" ""
714 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
715 $(shell $(GHC_PKG) init $(BOOTSTRAPPING_CONF))
716 endif
717 endif
718
719 $(eval $(call clean-target,root,bootstrapping_conf,$(BOOTSTRAPPING_CONF)))
720
721 # register the boot packages in strict sequence, because running
722 # multiple ghc-pkgs in parallel doesn't work (registrations may get
723 # lost).
724 fixed_pkg_prev=
725 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
726 utils/ghc-pkg/dist/package-data.mk: $(fixed_pkg_prev)
727 compiler/stage1/package-data.mk: $(fixed_pkg_prev)
728 endif
729
730 ifneq "$(BINDIST)" "YES"
731 # Make sure we have all the GHCi libs by the time we've built
732 # ghc-stage2. DPH includes a bit of Template Haskell which needs the
733 # GHCi libs, and we don't have a better way to express that dependency.
734 #
735 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
736 $(compiler_stage2_GHCI_LIB)
737
738 ifeq "$(UseArchivesForGhci)" "NO"
739 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
740 endif
741
742 ifeq "$(UseArchivesForGhci)" "YES"
743 GHCI_lib_way = v
744 else
745 GHCI_lib_way = GHCI
746 endif
747
748 # Deps for TH uses in libraries
749 $(foreach way, $(GhcLibWays),$(eval \
750 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
751 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
752 ))
753 endif
754
755 # -----------------------------------------------
756 # Haddock-related bits
757
758 # Build the Haddock contents and index
759 ifeq "$(HADDOCK_DOCS)" "YES"
760 libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
761 cd libraries && sh gen_contents_index --intree
762 ifeq "$(phase)" "final"
763 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
764 endif
765 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
766 endif
767
768 # -----------------------------------------------------------------------------
769 # Creating a local mingw copy on Windows
770
771 ifeq "$(Windows_Host)" "YES"
772
773 install : install_mingw
774 .PHONY: install_mingw
775 install_mingw : $(INPLACE_MINGW)
776 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
777
778 install : install_perl
779 .PHONY: install_perl
780 install_perl : $(INPLACE_PERL)
781 "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
782
783 endif # Windows_Host
784
785 ifneq "$(BINDIST)" "YES"
786 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
787 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
788 endif # BINDIST
789
790 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
791 $(PRIMOPS_TXT_STAGE1) $$(genprimopcode_INPLACE) \
792 | $$(dir $$@)/.
793 "$(genprimopcode_INPLACE)" --make-haskell-source < $< > $@
794
795 .PHONY: tags
796 tags: tags_compiler
797
798 .PHONY: TAGS
799 TAGS: TAGS_compiler
800
801 # -----------------------------------------------------------------------------
802 # Installation
803
804 install: install_libs install_packages install_libexecs \
805 install_bins install_topdirs
806 ifeq "$(HADDOCK_DOCS)" "YES"
807 install: install_docs
808 endif
809
810 define installLibsTo
811 # $1 = libraries to install
812 # $2 = directory to install to
813 $(call INSTALL_DIR,$2)
814 for i in $1; do \
815 case $$i in \
816 *.a) \
817 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
818 $(RANLIB_CMD) $2/`basename $$i` ;; \
819 *.dll) \
820 $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,$2) ; \
821 $(STRIP_CMD) $2/`basename $$i` ;; \
822 *.so) \
823 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2) ;; \
824 *.dylib) \
825 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2);; \
826 *) \
827 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
828 esac; \
829 done
830 endef
831
832 install_bins: $(INSTALL_BINS)
833 $(call INSTALL_DIR,"$(DESTDIR)$(bindir)")
834 for i in $(INSTALL_BINS); do \
835 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(bindir)") ; \
836 done
837
838 install_libs: $(INSTALL_LIBS)
839 $(call installLibsTo, $(INSTALL_LIBS), "$(DESTDIR)$(ghclibdir)")
840
841 install_libexecs: $(INSTALL_LIBEXECS)
842 ifeq "$(INSTALL_LIBEXECS)" ""
843 @:
844 else
845 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibexecdir)/bin")
846 for i in $(INSTALL_LIBEXECS); do \
847 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(ghclibexecdir)/bin"); \
848 done
849 # We rename ghc-stage2, so that the right program name is used in error
850 # messages etc.
851 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc"
852 endif
853
854 install_topdirs: $(INSTALL_TOPDIRS)
855 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
856 for i in $(INSTALL_TOPDIRS); do \
857 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(topdir)"); \
858 done
859
860 install_docs: $(INSTALL_DOCS)
861 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)")
862 ifneq "$(INSTALL_DOCS)" ""
863 for i in $(INSTALL_DOCS); do \
864 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)"); \
865 done
866 endif
867 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html")
868 $(call INSTALL_DOC,$(INSTALL_OPTS),docs/index.html,"$(DESTDIR)$(docdir)/html")
869 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
870 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/libraries")
871 for i in $(INSTALL_LIBRARY_DOCS); do \
872 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)/html/libraries/"); \
873 done
874 $(call INSTALL_DATA,$(INSTALL_OPTS),libraries/prologue.txt,"$(DESTDIR)$(docdir)/html/libraries/")
875 $(call INSTALL_SCRIPT,$(INSTALL_OPTS),libraries/gen_contents_index,"$(DESTDIR)$(docdir)/html/libraries/")
876 endif
877 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
878 for i in $(INSTALL_HTML_DOC_DIRS); do \
879 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
880 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i/*,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
881 done
882 endif
883
884 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
885
886 # Install packages in the right order, so that ghc-pkg doesn't complain.
887 # Also, install ghc-pkg first.
888 ifeq "$(Windows_Host)" "NO"
889 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
890 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
891 else
892 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
893 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
894 endif
895
896 # Set the INSTALL_DISTDIR_p for each package; compiler is special
897 $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
898 $(eval INSTALL_DISTDIR_$p = dist-install))
899 INSTALL_DISTDIR_compiler = stage2
900
901 # Now we can do the installation
902 install_packages: install_libexecs
903 install_packages: rts/dist/package.conf.install
904 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
905 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
906 $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
907 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)/rts")
908 $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts")
909 $(foreach p, $(INSTALL_DYNLIBS), \
910 $(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)"))
911 $(foreach p, $(INSTALL_PACKAGES), \
912 $(call make-command, \
913 "$(ghc-cabal_INPLACE)" copy \
914 $p $(INSTALL_DISTDIR_$p) \
915 "$(STRIP_CMD)" \
916 '$(DESTDIR)' \
917 '$(prefix)' \
918 '$(ghclibdir)' \
919 '$(docdir)/html/libraries' \
920 '$(GhcLibWays)'))
921 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/dist/package.conf.install
922 $(foreach p, $(INSTALL_PACKAGES), \
923 $(call make-command, \
924 "$(ghc-cabal_INPLACE)" register \
925 $p $(INSTALL_DISTDIR_$p) \
926 "$(INSTALLED_GHC_REAL)" \
927 "$(INSTALLED_GHC_PKG_REAL)" \
928 "$(DESTDIR)$(topdir)" \
929 '$(DESTDIR)' \
930 '$(prefix)' \
931 '$(ghclibdir)' \
932 '$(docdir)/html/libraries' \
933 $(RelocatableBuild)))
934 # when we install the packages above, ghc-pkg obeys umask when creating
935 # the package.conf files, but for everything else we specify the
936 # permissions. We therefore now fix the permissions of package.cache.
937 # This means "sudo make install" does the right thing even if it runs
938 # with an 077 umask.
939 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
940
941 # -----------------------------------------------------------------------------
942 # Binary distributions
943
944 ifneq "$(CLEANING)" "YES"
945 # This rule seems to hold some files open on Windows which prevents
946 # cleaning, perhaps due to the $(wildcard).
947
948 $(eval $(call bindist,.,\
949 LICENSE \
950 README \
951 INSTALL \
952 configure config.sub config.guess install-sh \
953 settings.in \
954 packages \
955 Makefile \
956 mk/config.mk.in \
957 $(INPLACE_BIN)/mkdirhier \
958 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
959 utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
960 $(BINDIST_WRAPPERS) \
961 $(BINDIST_PERL_SOURCES) \
962 $(BINDIST_LIBS) \
963 $(BINDIST_HI) \
964 $(BINDIST_EXTRAS) \
965 $(includes_H_FILES) \
966 $(includes_DERIVEDCONSTANTS) \
967 $(includes_GHCCONSTANTS) \
968 $(libffi_HEADERS) \
969 $(INSTALL_LIBEXECS) \
970 $(INSTALL_LIBEXEC_SCRIPTS) \
971 $(INSTALL_TOPDIRS) \
972 $(INSTALL_BINS) \
973 $(INSTALL_MANPAGES) \
974 $(INSTALL_DOCS) \
975 $(INSTALL_LIBRARY_DOCS) \
976 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
977 docs/index.html \
978 compiler/stage2/doc \
979 $(wildcard libraries/*/dist-install/doc/) \
980 $(wildcard libraries/*/*/dist-install/doc/) \
981 $(filter-out settings,$(INSTALL_LIBS)) \
982 $(RTS_INSTALL_LIBS) \
983 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
984 mk/project.mk \
985 mk/install.mk.in \
986 bindist.mk \
987 libraries/gen_contents_index \
988 libraries/prologue.txt \
989 $(wildcard libraries/dph/LICENSE \
990 libraries/dph/ghc-packages \
991 libraries/dph/ghc-packages2 \
992 libraries/dph/ghc-stage2-package) \
993 ))
994 endif
995 # mk/project.mk gets an absolute path, so we manually include it in
996 # the bindist with a relative path
997
998 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
999
1000 unix-binary-dist-prep:
1001 $(call removeTrees,bindistprep/)
1002 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
1003 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
1004 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
1005 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
1006 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
1007 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
1008 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
1009 echo "override ghc-cabal_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
1010 echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
1011 cd $(BIN_DIST_PREP_DIR) && autoreconf
1012 $(call removeFiles,$(BIN_DIST_PREP_TAR))
1013 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1014 # tree then we want to include the real file, not a symlink to it
1015 cd bindistprep && "$(TAR_CMD)" hcf - -T ../bindist-list | $(TAR_COMP_CMD) -c > ../$(BIN_DIST_PREP_TAR_COMP)
1016
1017 windows-binary-dist-prep:
1018 $(call removeTrees,bindistprep/)
1019 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1020 cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | $(TAR_COMP_CMD) -c > ../$(BIN_DIST_PREP_TAR_COMP)
1021
1022 # tryTimes tries to run its third argument multiple times, until it
1023 # succeeds. Don't call it directly; call try10Times instead.
1024 # The first and second argument to tryTimes are lists of values.
1025 # The length of the first argument is the number of times we have
1026 # already tried. The length of the second argument is the number more
1027 # times we will try.
1028 tryTimes = $(if $2, \
1029 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1030 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1031 )
1032
1033 # Try to run the argument 10 times. If all 10 fail, fail.
1034 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1035
1036 .PHONY: publish-binary-dist
1037 publish-binary-dist:
1038 $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_COMP) $(PublishLocation)/dist)
1039
1040 ifeq "$(mingw32_TARGET_OS)" "1"
1041 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/doc
1042 else
1043 DOCDIR_TO_PUBLISH = $(BIN_DIST_INST_DIR)/share/doc/ghc
1044 endif
1045
1046 .PHONY: publish-docs
1047 publish-docs:
1048 $(call try10Times,$(PublishCp) -r $(DOCDIR_TO_PUBLISH)/* $(PublishLocation)/docs)
1049
1050 # -----------------------------------------------------------------------------
1051 # Source distributions
1052
1053 # Do it like this:
1054 #
1055 # $ make
1056 # $ make sdist
1057 #
1058
1059 # A source dist is built from a complete build tree, because we
1060 # require some extra files not contained in a git checkout: the
1061 # output from Happy and Alex, for example.
1062 #
1063 # The steps performed by 'make dist' are as follows:
1064 # - create a complete link-tree of the current build tree in /tmp
1065 # - run 'make distclean' on that tree
1066 # - remove a bunch of other files that we know shouldn't be in the dist
1067 # - tar up first the extralibs package, then the main source package
1068
1069 #
1070 # Directory in which we're going to build the src dist
1071 #
1072 SRC_DIST_ROOT = sdistprep
1073 SRC_DIST_BASE_NAME = ghc-$(ProjectVersion)
1074
1075 SRC_DIST_GHC_NAME = ghc-$(ProjectVersion)-src
1076 SRC_DIST_GHC_ROOT = $(SRC_DIST_ROOT)/ghc
1077 SRC_DIST_GHC_DIR = $(SRC_DIST_GHC_ROOT)/$(SRC_DIST_BASE_NAME)
1078 SRC_DIST_GHC_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_GHC_NAME).tar.$(TAR_COMP_EXT)
1079
1080 SRC_DIST_WINDOWS_TARBALLS_NAME = ghc-$(ProjectVersion)-windows-extra-src
1081 SRC_DIST_WINDOWS_TARBALLS_ROOT = $(SRC_DIST_ROOT)/windows-tarballs
1082 SRC_DIST_WINDOWS_TARBALLS_DIR = $(SRC_DIST_WINDOWS_TARBALLS_ROOT)/$(SRC_DIST_BASE_NAME)
1083 SRC_DIST_WINDOWS_TARBALLS_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_WINDOWS_TARBALLS_NAME).tar.$(TAR_COMP_EXT)
1084
1085 SRC_DIST_TESTSUITE_NAME = ghc-$(ProjectVersion)-testsuite
1086 SRC_DIST_TESTSUITE_ROOT = $(SRC_DIST_ROOT)/testsuite-ghc
1087 SRC_DIST_TESTSUITE_DIR = $(SRC_DIST_TESTSUITE_ROOT)/$(SRC_DIST_BASE_NAME)
1088 SRC_DIST_TESTSUITE_TARBALL = $(SRC_DIST_ROOT)/$(SRC_DIST_TESTSUITE_NAME).tar.$(TAR_COMP_EXT)
1089
1090 #
1091 # Files to include in source distributions
1092 #
1093 SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
1094 utils docs rts compiler ghc driver libraries libffi-tarballs
1095 SRC_DIST_GHC_FILES += \
1096 configure.ac config.guess config.sub configure \
1097 aclocal.m4 README.md ANNOUNCE HACKING.md INSTALL.md LICENSE Makefile \
1098 install-sh settings.in VERSION GIT_COMMIT_ID \
1099 boot packages ghc.mk MAKEHELP.md
1100
1101 .PHONY: VERSION
1102 VERSION:
1103 @if test -f $@ && test "`cat $@`" = "$(ProjectVersion)"; \
1104 then echo "$@ needs no update"; \
1105 else echo "update $@ ($(ProjectVersion))"; echo "$(ProjectVersion)" > $@; fi
1106
1107 .PHONY: GIT_COMMIT_ID
1108 GIT_COMMIT_ID:
1109 @if test -d .git && test "`git rev-parse HEAD`" != "$(ProjectGitCommitId)"; then \
1110 echo "******************************************************************************"; \
1111 echo "Stale ProjectGitCommitId (=$(ProjectGitCommitId)) detected!"; \
1112 echo "'git rev-parse HEAD' says: `git rev-parse HEAD`"; \
1113 echo "Please re-run './configure' before creating source-distribution"; \
1114 echo "******************************************************************************"; \
1115 exit 1; \
1116 fi
1117 @if test -f $@ && test "`cat $@`" = "$(ProjectGitCommitId)"; \
1118 then echo "$@ needs no update"; \
1119 else echo "update $@ ($(ProjectGitCommitId))"; echo -n "$(ProjectGitCommitId)" > $@; fi
1120
1121 sdist-ghc-prep : VERSION GIT_COMMIT_ID
1122
1123 # Use:
1124 # $(call sdist_ghc_file,compiler,stage2,cmm,Foo/Bar,CmmLex,x)
1125 # to copy the generated file that replaces compiler/cmm/Foo/Bar/CmmLex.x, where
1126 # "stage2" is the dist dir.
1127 define sdist_ghc_file
1128 "$(CP)" $1/$2/build/$4/$5.hs $(SRC_DIST_GHC_DIR)/$1/$3/$4
1129 mv $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6 $(SRC_DIST_GHC_DIR)/$1/$3/$4/$5.$6.source
1130 endef
1131
1132 # Extra packages which shouldn't be in the source distribution: see #8801
1133 EXTRA_PACKAGES=parallel stm random primitive vector dph
1134
1135 .PHONY: sdist-ghc-prep
1136 sdist-ghc-prep :
1137 $(call removeTrees,$(SRC_DIST_GHC_ROOT))
1138 $(call removeFiles,$(SRC_DIST_GHC_TARBALL))
1139 mkdir -p $(SRC_DIST_ROOT)
1140 mkdir -p $(SRC_DIST_GHC_ROOT)
1141 mkdir -p $(SRC_DIST_GHC_DIR)
1142 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_DIRS); do mkdir -p $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1143 cd $(SRC_DIST_GHC_DIR) && for i in $(SRC_DIST_GHC_FILES); do $(LN_S) $(TOP)/$$i .; done
1144 cd $(SRC_DIST_GHC_DIR) && $(MAKE) distclean
1145 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/tarballs/)
1146 $(call removeTrees,$(SRC_DIST_GHC_DIR)/libraries/stamp/)
1147 $(call removeTrees,$(SRC_DIST_GHC_DIR)/compiler/stage[123])
1148 $(call removeFiles,$(SRC_DIST_GHC_DIR)/mk/build.mk)
1149 for i in $(EXTRA_PACKAGES); do $(RM) $(RM_OPTS_REC) $(SRC_DIST_GHC_DIR)/libraries/$$i/; done
1150 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmLex,x)
1151 $(call sdist_ghc_file,compiler,stage2,cmm,,CmmParse,y)
1152 $(call sdist_ghc_file,compiler,stage2,parser,,Lexer,x)
1153 $(call sdist_ghc_file,compiler,stage2,parser,,Parser,y)
1154 $(call sdist_ghc_file,utils/hpc,dist-install,,,HpcParser,y)
1155 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Lexer,x)
1156 $(call sdist_ghc_file,utils/genprimopcode,dist,,,Parser,y)
1157 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)
1158
1159 .PHONY: sdist-windows-tarballs-prep
1160 sdist-windows-tarballs-prep :
1161 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_ROOT))
1162 $(call removeFiles,$(SRC_DIST_WINDOWS_TARBALLS_TARBALL))
1163 mkdir -p $(SRC_DIST_ROOT)
1164 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_ROOT)
1165 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)
1166 mkdir -p $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs
1167 cd $(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs && lndir $(TOP)/ghc-tarballs
1168 $(call removeTrees,$(SRC_DIST_WINDOWS_TARBALLS_DIR)/ghc-tarballs/.git)
1169
1170 .PHONY: sdist-testsuite-prep
1171 sdist-testsuite-prep :
1172 $(call removeTrees,$(SRC_DIST_TESTSUITE_ROOT))
1173 $(call removeFiles,$(SRC_DIST_TESTSUITE_TARBALL))
1174 mkdir -p $(SRC_DIST_ROOT)
1175 mkdir -p $(SRC_DIST_TESTSUITE_ROOT)
1176 mkdir -p $(SRC_DIST_TESTSUITE_DIR)
1177 mkdir -p $(SRC_DIST_TESTSUITE_DIR)/testsuite
1178 cd $(SRC_DIST_TESTSUITE_DIR)/testsuite && lndir $(TOP)/testsuite
1179
1180 .PHONY: sdist-ghc
1181 sdist-ghc: sdist-ghc-prep
1182 cd $(SRC_DIST_GHC_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> src_ghc_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_GHC_TARBALL)
1183
1184 .PHONY: sdist-windows-tarballs
1185 sdist-windows-tarballs: sdist-windows-tarballs-prep
1186 cd $(SRC_DIST_WINDOWS_TARBALLS_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> windows_extra_src_ghc_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_WINDOWS_TARBALLS_TARBALL)
1187
1188 .PHONY: sdist-testsuite
1189 sdist-testsuite: sdist-testsuite-prep
1190 cd $(SRC_DIST_TESTSUITE_ROOT) && "$(TAR_CMD)" chf - $(SRC_DIST_BASE_NAME) 2> testsuite_log | $(TAR_COMP_CMD) -c > $(TOP)/$(SRC_DIST_TESTSUITE_TARBALL)
1191
1192
1193 .PHONY: sdist
1194 sdist : sdist-ghc sdist-windows-tarballs sdist-testsuite
1195
1196 sdist-manifest : $(SRC_DIST_GHC_TARBALL)
1197 tar tjf $(SRC_DIST_GHC_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1198
1199 # Upload the distribution(s)
1200 # Retrying is to work around buggy firewalls that corrupt large file transfers
1201 # over SSH.
1202 ifneq "$(PublishLocation)" ""
1203 publish-sdist :
1204 $(call try10Times,$(PublishCp) $(SRC_DIST_GHC_TARBALL) $(PublishLocation)/dist)
1205 $(call try10Times,$(PublishCp) $(SRC_DIST_TESTSUITE_TARBALL) $(PublishLocation)/dist)
1206 endif
1207
1208 # -----------------------------------------------------------------------------
1209 # sdisting libraries
1210
1211 # Use manually, with e.g.:
1212 # make sdist_directory
1213
1214 sdist_%:
1215 inplace/bin/ghc-cabal sdist libraries/$* dist-install
1216
1217 # -----------------------------------------------------------------------------
1218 # Cleaning
1219
1220 .PHONY: clean
1221
1222 CLEAN_FILES += libraries/integer-gmp/include/HsIntegerGmp.h
1223 CLEAN_FILES += libraries/base/include/EventConfig.h
1224 CLEAN_FILES += mk/config.mk.old
1225 CLEAN_FILES += mk/project.mk.old
1226 CLEAN_FILES += compiler/ghc.cabal.old
1227
1228 # These are no longer generated, but we still clean them for a while
1229 # as they may still be in old GHC trees:
1230 CLEAN_FILES += includes/GHCConstants.h
1231 CLEAN_FILES += includes/DerivedConstants.h
1232 CLEAN_FILES += includes/ghcautoconf.h
1233 CLEAN_FILES += includes/ghcplatform.h
1234 CLEAN_FILES += includes/ghcversion.h
1235 CLEAN_FILES += utils/ghc-pkg/Version.hs
1236 CLEAN_FILES += compiler/prelude/primops.txt
1237 CLEAN_FILES += $(wildcard compiler/primop*incl)
1238
1239 clean : clean_files clean_libraries
1240
1241 .PHONY: clean_files
1242 clean_files :
1243 $(call removeFiles,$(CLEAN_FILES))
1244 # this is here since CLEAN_FILES can't handle folders
1245 $(call removeTrees,includes/dist-derivedconstants)
1246 $(call removeTrees,inplace/bin)
1247 $(call removeTrees,inplace/lib)
1248 $(call removeTrees,libraries/bootstrapping.conf)
1249
1250 .PHONY: clean_libraries
1251 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2))
1252 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(PACKAGES_STAGE0))
1253
1254 clean_libraries:
1255 $(call removeTrees,$(patsubst %, libraries/%/dist, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1256 $(call removeFiles,$(wildcard $(patsubst %.in, %, $(wildcard $(patsubst %, libraries/%/*.buildinfo.in, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))))
1257 $(call removeFiles,$(patsubst %, libraries/%/config.log, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1258 $(call removeFiles,$(patsubst %, libraries/%/config.status, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1259 $(call removeFiles,$(wildcard $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2))))
1260
1261 # We have to define a clean target for each library manually, because the
1262 # libraries/*/ghc.mk files are not included when we're cleaning.
1263 ifeq "$(CLEANING)" "YES"
1264 $(foreach lib,$(PACKAGES_STAGE0),\
1265 $(eval $(call clean-target,libraries/$(lib),dist-boot,libraries/$(lib)/dist-boot)))
1266 $(foreach lib,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),\
1267 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1268 endif
1269
1270 clean : clean_haddock_index
1271 .PHONY: clean_haddock_index
1272 clean_haddock_index:
1273 $(call removeTrees,libraries/dist-haddock)
1274
1275 clean : clean_bindistprep
1276 .PHONY: clean_bindistprep
1277 clean_bindistprep:
1278 $(call removeTrees,bindistprep/)
1279
1280 distclean : clean
1281 # Clean the files that ./validate creates.
1282 $(call removeFiles,mk/are-validating.mk)
1283
1284 # Clean the files that we ask ./configure to create.
1285 $(call removeFiles,mk/config.mk)
1286 $(call removeFiles,mk/install.mk)
1287 $(call removeFiles,mk/project.mk)
1288 $(call removeFiles,compiler/ghc.cabal)
1289 $(call removeFiles,ghc/ghc-bin.cabal)
1290 $(call removeFiles,utils/runghc/runghc.cabal)
1291 $(call removeFiles,settings)
1292 $(call removeFiles,docs/users_guide/ug-book.xml)
1293 $(call removeFiles,docs/users_guide/ug-ent.xml)
1294 $(call removeFiles,docs/index.html)
1295 $(call removeFiles,libraries/prologue.txt)
1296 $(call removeFiles,distrib/configure.ac)
1297 $(call removeFiles,ch01.html ch02.html index.html)
1298
1299 # ./configure also makes these.
1300 $(call removeFiles,mk/config.h)
1301
1302 # Internal files generated by ./configure for itself.
1303 $(call removeFiles,config.cache config.status config.log)
1304
1305 # ./configure build ghc-pwd in utils/ghc-pwd/dist-boot, so clean it up.
1306 $(call removeTrees,utils/ghc-pwd/dist-boot)
1307
1308 # The root Makefile makes .old versions of some files that configure
1309 # generates, so we clean those too.
1310 $(call removeFiles,mk/config.mk.old)
1311 $(call removeFiles,mk/project.mk.old)
1312 $(call removeFiles,compiler/ghc.cabal.old)
1313
1314 # Clean the *Config.h files generated by library configure scripts
1315 $(call removeFiles,libraries/base/include/HsBaseConfig.h)
1316 $(call removeFiles,libraries/base/include/EventConfig.h)
1317 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h)
1318 $(call removeFiles,libraries/process/include/HsProcessConfig.h)
1319 $(call removeFiles,libraries/unix/include/HsUnixConfig.h)
1320 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h)
1321
1322 # The library configure scripts also like creating autom4te.cache
1323 # directories, so clean them all up.
1324 $(call removeTrees,$(patsubst %, libraries/%/autom4te.cache, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1325
1326 # We make these when making or testing bindists
1327 $(call removeFiles,bindist-list)
1328 $(call removeTrees,bindisttest/a)
1329
1330 # Not sure why this is being cleaned here.
1331 $(call removeTrees,includes/dist-derivedconstants)
1332
1333 # Finally, clean the inplace tree.
1334 $(call removeTrees,inplace)
1335
1336 maintainer-clean : distclean
1337 $(call removeFiles,configure mk/config.h.in)
1338 $(call removeTrees,autom4te.cache $(wildcard libraries/*/autom4te.cache))
1339 $(call removeFiles,$(patsubst %, libraries/%/GNUmakefile, \
1340 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1341 $(call removeFiles,$(patsubst %, libraries/%/ghc.mk, $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1342 $(call removeFiles,$(patsubst %, libraries/%/configure, \
1343 $(PACKAGES_STAGE1) $(PACKAGES_STAGE2)))
1344 $(call removeFiles,libraries/base/include/HsBaseConfig.h.in)
1345 $(call removeFiles,libraries/directory/include/HsDirectoryConfig.h.in)
1346 $(call removeFiles,libraries/process/include/HsProcessConfig.h.in)
1347 $(call removeFiles,libraries/unix/include/HsUnixConfig.h.in)
1348 $(call removeFiles,libraries/time/lib/include/HsTimeConfig.h.in)
1349
1350 .PHONY: all_libraries
1351
1352 .PHONY: bootstrapping-files
1353 bootstrapping-files: $(includes_H_CONFIG)
1354 bootstrapping-files: $(includes_DERIVEDCONSTANTS)
1355 bootstrapping-files: $(includes_GHCCONSTANTS)
1356 bootstrapping-files: $(libffi_HEADERS)
1357
1358 .DELETE_ON_ERROR:
1359
1360 # -----------------------------------------------------------------------------
1361
1362 ifeq "$(HADDOCK_DOCS)" "YES"
1363 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
1364 endif
1365 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
1366 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
1367 else
1368 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
1369 endif
1370 BINDIST_LIBRARY_FLAGS += --disable-library-prof
1371
1372 .PHONY: validate_build_xhtml
1373 validate_build_xhtml:
1374 cd libraries/xhtml && "$(BINDIST_PREFIX)/bin/ghc" --make Setup
1375 cd libraries/xhtml && ./Setup configure --with-ghc="$(BINDIST_PREFIX)/bin/ghc" $(BINDIST_HADDOCK_FLAG) $(BINDIST_LIBRARY_FLAGS) --global --builddir=dist-bindist --prefix="$(BINDIST_PREFIX)"
1376 cd libraries/xhtml && ./Setup build --builddir=dist-bindist
1377 ifeq "$(HADDOCK_DOCS)" "YES"
1378 cd libraries/xhtml && ./Setup haddock -v0 --ghc-options=-optP-P --builddir=dist-bindist
1379 endif
1380 cd libraries/xhtml && ./Setup install --builddir=dist-bindist
1381 cd libraries/xhtml && ./Setup clean --builddir=dist-bindist
1382 cd libraries/xhtml && rm -f Setup Setup.exe Setup.hi Setup.o
1383
1384 # -----------------------------------------------------------------------------
1385 # Numbered phase targets
1386
1387 # In phase 1, we'll be building dependency files for most things
1388 # built by the bootstrapping compiler while make is 'include'ing
1389 # makefiles. But in order to build dependency files, we'll need to
1390 # build any automatically generated .hs files, which means that
1391 # we'll need to be able to build any tools that generate .hs files
1392 # etc. But in order to do that, we need to already know the
1393 # dependencies for those tools, so we build their dependency files
1394 # here.
1395 .PHONY: phase_0_builds
1396 # hsc2hs is needed, e.g. to make the .hs files for hpc.
1397 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1398 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1399 # genprimopcode is needed to make the .hs-incl files that are in the
1400 # ghc package.
1401 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1402 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1403 # deriveConstants is used to create header files included in the
1404 # ghc package.
1405 phase_0_builds: $(utils/deriveConstants_dist_depfile_haskell)
1406 phase_0_builds: $(utils/deriveConstants_dist_depfile_c_asm)
1407
1408 .PHONY: phase_1_builds
1409 phase_1_builds: $(PACKAGE_DATA_MKS)
1410