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