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