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