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