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