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