56ab9908af226d432375f91d95b4ccfff61f7725
[ghc-hetmet.git] / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 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/ext-core/Makefile
19 #     * docs/man/Makefile
20 #     * docs/storage-mgmt/Makefile
21 #     * docs/vh/Makefile
22 #     * rts/dotnet/Makefile
23 #     * utils/Makefile
24 #   * add Makefiles for the rest of the utils/ programs that aren't built
25 #     by default (need to exclude them from 'make all' too)
26
27 # Possible cleanups:
28 #
29 #   * per-source-file dependencies instead of one .depend file?
30 #   * eliminate undefined variables, and use --warn-undefined-variables?
31 #   * put outputs from different ways in different subdirs of distdir/build,
32 #     then we don't have to use -osuf/-hisuf.  We would have to install
33 #     them in different places too, so we'd need ghc-pkg support for packages
34 #     of different ways.
35 #   * make PACKAGES generated by './configure' or './boot'?
36 #   * we should use a directory of package.conf files rather than a single
37 #     file for the inplace package database, so that we can express
38 #     dependencies more accurately.  Otherwise it's possible to get into
39 #     a state where the package database is out of date, and the build
40 #     system doesn't know.
41
42 # Approximate build order.
43 #
44 # The actual build order is defined by dependencies, and the phase
45 # ordering used to ensure correct ordering of makefile-generation; see
46 #    http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
47 #
48 #     * With bootstrapping compiler:
49 #           o Build utils/ghc-cabal
50 #           o Build utils/ghc-pkg
51 #           o Build utils/hsc2hs
52 #     * For each package:
53 #           o configure, generate package-data.mk and inplace-pkg-info
54 #           o register each package into inplace/lib/package.conf
55 #     * build libffi
56 #     * With bootstrapping compiler:
57 #           o Build libraries/{filepath,hpc,extensible-exceptions,Cabal}
58 #           o Build compiler (stage 1)
59 #     * With stage 1:
60 #           o Build libraries/*
61 #           o Build rts
62 #           o Build utils/* (except haddock)
63 #           o Build compiler (stage 2)
64 #     * With stage 2:
65 #           o Build utils/haddock
66 #           o Build compiler (stage 3) (optional)
67 #     * With haddock:
68 #           o libraries/*
69 #           o compiler
70
71 .PHONY: default all haddock
72
73 # We need second expansion for the way we handle directories, so that
74 #     | $$$$(dir $$$$@)/.
75 # expands to the directory of a rule that uses a % pattern.
76 .SECONDEXPANSION:
77
78 default : all
79
80 # Catch make if it runs away into an infinite loop
81 ifeq      "$(MAKE_RESTARTS)" ""
82 else ifeq "$(MAKE_RESTARTS)" "1"
83 else ifeq "$(MAKE_RESTARTS)" "2"
84 else
85 $(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug?)
86 endif
87
88 # Just bring makefiles up to date:
89 .PHONY: just-makefiles
90 just-makefiles:
91         @:
92
93 ifneq "$(CLEANING)" "YES"
94 CLEANING = NO
95 endif
96
97 # -----------------------------------------------------------------------------
98 # Misc GNU make utils
99
100 nothing=
101 space=$(nothing) $(nothing)
102 comma=,
103
104 # Cancel all suffix rules.  Ideally we'd like to have 'make -r' turned on
105 # by default, because that disables all the implicit rules, but there doesn't
106 # seem to be a good way to do that.  This turns off all the old-style suffix
107 # rules, which does half the job and speeds up make quite a bit:
108 .SUFFIXES:
109
110 # -----------------------------------------------------------------------------
111 # Makefile debugging
112 #
113 # to see the effective value used for a Makefile variable, do
114 #  make show VALUE=MY_VALUE
115 #
116
117 show:
118         @echo '$(VALUE)="$($(VALUE))"'
119
120 # -----------------------------------------------------------------------------
121 # Include subsidiary build-system bits
122
123 include mk/tree.mk
124
125 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
126 include mk/config.mk
127 ifeq "$(ProjectVersion)" ""
128 $(error Please run ./configure first)
129 endif
130 endif
131
132 include mk/ways.mk
133
134 # (Optional) build-specific configuration
135 include mk/custom-settings.mk
136
137 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
138 ifeq "$(GhcLibWays)" ""
139 $(error $$(GhcLibWays) is empty, it must contain at least one way)
140 endif
141 endif
142
143 # -----------------------------------------------------------------------------
144 # Utility definitions
145
146 include rules/trace.mk
147 include rules/make-command.mk
148
149 # -----------------------------------------------------------------------------
150 # Macros for standard targets
151
152 include rules/all-target.mk
153 include rules/clean-target.mk
154
155 # -----------------------------------------------------------------------------
156 # The inplace tree
157
158 $(eval $(call clean-target,inplace,,inplace))
159
160 # -----------------------------------------------------------------------------
161 # Whether to build dependencies or not
162
163 # When we're just doing 'make clean' or 'make show', then we don't need
164 # to build dependencies.
165
166 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
167 NO_INCLUDE_DEPS = YES
168 NO_INCLUDE_PKGDATA = YES
169 endif
170 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
171 NO_INCLUDE_DEPS = YES
172 NO_INCLUDE_PKGDATA = YES
173 endif
174 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
175 NO_INCLUDE_DEPS = YES
176 # We want package-data.mk for show
177 endif
178
179 # -----------------------------------------------------------------------------
180 # Ways
181
182 include rules/way-prelims.mk
183
184 $(foreach way,$(ALL_WAYS),\
185   $(eval $(call way-prelims,$(way))))
186
187 # -----------------------------------------------------------------------------
188 # Compilation Flags
189
190 include rules/distdir-way-opts.mk
191
192 # -----------------------------------------------------------------------------
193 # Finding source files and object files
194
195 include rules/hs-sources.mk
196 include rules/c-sources.mk
197 include rules/includes-sources.mk
198 include rules/hs-objs.mk
199 include rules/c-objs.mk
200 include rules/cmm-objs.mk
201
202 # -----------------------------------------------------------------------------
203 # Suffix rules
204
205 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
206 # so we don't make any when cleaning.
207 ifneq "$(CLEANING)" "YES"
208
209 include rules/hs-suffix-rules-srcdir.mk
210 include rules/hs-suffix-rules.mk
211 include rules/hi-rule.mk
212
213 $(foreach way,$(ALL_WAYS),\
214   $(eval $(call hi-rule,$(way))))
215
216 include rules/c-suffix-rules.mk
217 include rules/cmm-suffix-rules.mk
218
219 endif # CLEANING=YES
220
221 # -----------------------------------------------------------------------------
222 # Building package-data.mk files from .cabal files
223
224 include rules/package-config.mk
225
226 # -----------------------------------------------------------------------------
227 # Building dependencies
228
229 include rules/build-dependencies.mk
230
231 # -----------------------------------------------------------------------------
232 # Build package-data.mk files
233
234 include rules/build-package-data.mk
235
236 # -----------------------------------------------------------------------------
237 # Build and install a program
238
239 include rules/build-prog.mk
240 include rules/shell-wrapper.mk
241
242 # -----------------------------------------------------------------------------
243 # Build a perl script
244
245 include rules/build-perl.mk
246
247 # -----------------------------------------------------------------------------
248 # Build a package
249
250 include rules/build-package.mk
251 include rules/build-package-way.mk
252 include rules/haddock.mk
253 include rules/tags-package.mk
254 include rules/extra-packages.mk
255
256 # -----------------------------------------------------------------------------
257 # Registering hand-written package descriptions (used in libffi and rts)
258
259 include rules/manual-package-config.mk
260
261 # -----------------------------------------------------------------------------
262 # Docs
263
264 include rules/docbook.mk
265
266 # -----------------------------------------------------------------------------
267 # Making bindists
268
269 include rules/bindist.mk
270
271 # -----------------------------------------------------------------------------
272 # Directories
273
274 # Don't try to delete directories:
275 .PRECIOUS: %/.
276
277 # Create build directories on demand.  NB. the | below: this indicates
278 # that $(MKDIRHIER) is an order-only dependency, which means that this
279 # rule fires after building mkdirhier, but we won't try to recreate
280 # directories if mkdirhier changes.
281 %/. : | $(MKDIRHIER)
282         "$(MKDIRHIER)" $@
283
284 # -----------------------------------------------------------------------------
285 # Packages
286
287 # --------------------------------
288 # Subsets of packages
289
290 # Packages that are built but not installed
291 INTREE_ONLY_PACKAGES := haskeline mtl terminfo utf8-string xhtml
292
293 # Packages that, if present, must be built by the stage2 compiler,
294 # because they use TH and/or annotations, or depend on other stage2
295 # packages.
296 STAGE2_PACKAGES := dph/dph-base dph/dph-prim-interface dph/dph-prim-seq \
297                    dph/dph-common dph/dph-prim-par dph/dph-par dph/dph-seq
298
299 # Packages that are built by stage0, in addition to stage1.  These
300 # packages are dependencies of GHC, that we do not assume the stage0
301 # compiler already has installed (or up-to-date enough).
302 #
303 # We assume that the stage0 compiler has a suitable bytestring package,
304 # so we don't have to include it below.
305 STAGE0_PACKAGES = Cabal hpc extensible-exceptions binary bin-package-db
306
307 # --------------------------------
308 # Building the lists of packages
309
310 # We need to build two lists:
311
312 #  $(PACKAGES)          A list of directories relative to libraries/ containing
313 #                       packages that will be built by stage1, in dependency
314 #                       order.
315 #
316 #  $(PACKAGES_STAGE2)   Ditto, for stage2.
317 #
318
319 define addPackageGeneral
320 # args: $1 = PACKAGES variable, $2 = package, $3 = condition
321     ifeq "$3" ""
322         $1 += $2
323     else
324         ifeq "$$(CLEANING)" "YES"
325             $1 += $2
326         else
327             ifeq $3
328                 $1 += $2
329             endif
330         endif
331     endif
332 endef
333
334 define addPackage # args: $1 = package, $2 = condition
335 ifeq "$(filter $1,$(STAGE2_PACKAGES))" "$1"
336 $(call addPackageGeneral,PACKAGES_STAGE2,$1,$2)
337 else
338 $(call addPackageGeneral,PACKAGES,$1,$2)
339 endif
340 endef
341
342 $(eval $(call addPackage,ghc-prim))
343 ifeq "$(CLEANING)" "YES"
344 $(eval $(call addPackage,integer-gmp))
345 $(eval $(call addPackage,integer-simple))
346 else
347 $(eval $(call addPackage,$(INTEGER_LIBRARY)))
348 endif
349 $(eval $(call addPackage,base))
350 $(eval $(call addPackage,filepath))
351 $(eval $(call addPackage,array))
352 $(eval $(call addPackage,bytestring))
353 $(eval $(call addPackage,containers))
354
355 $(eval $(call addPackage,Win32,($$(Windows),YES)))
356 $(eval $(call addPackage,unix,($$(Windows),NO)))
357
358 $(eval $(call addPackage,old-locale))
359 $(eval $(call addPackage,old-time))
360 $(eval $(call addPackage,time))
361 $(eval $(call addPackage,directory))
362 $(eval $(call addPackage,process))
363 $(eval $(call addPackage,random))
364 $(eval $(call addPackage,extensible-exceptions))
365 $(eval $(call addPackage,haskell98))
366 $(eval $(call addPackage,haskell2010))
367 $(eval $(call addPackage,hpc))
368 $(eval $(call addPackage,pretty))
369 $(eval $(call addPackage,template-haskell))
370 $(eval $(call addPackage,Cabal))
371 $(eval $(call addPackage,binary))
372 $(eval $(call addPackage,bin-package-db))
373 $(eval $(call addPackage,mtl))
374 $(eval $(call addPackage,utf8-string))
375 $(eval $(call addPackage,xhtml))
376
377 $(eval $(call addPackage,terminfo,($$(Windows),NO)))
378
379 $(eval $(call addPackage,haskeline))
380
381 $(eval $(call extra-packages))
382
383 # -------------------------------------------
384 # Dependencies between package-data.mk files
385
386 # We cannot run ghc-cabal to configure a package until we have
387 # configured and registered all of its dependencies.  So the following
388 # hack forces all the configure steps to happen in exactly the following order:
389 #
390 #  $(PACKAGES) ghc(stage2) $(PACKAGES_STAGE2)
391 #
392 # Ideally we should use the correct dependencies here to allow more
393 # parallelism, but we don't know the dependencies until we've
394 # generated the pacakge-data.mk files.
395 define fixed_pkg_dep
396 libraries/$1/$2/package-data.mk : $$(GHC_PKG_INPLACE) $$(fixed_pkg_prev)
397 fixed_pkg_prev:=libraries/$1/$2/package-data.mk
398 endef
399
400 ifneq "$(BINDIST)" "YES"
401 fixed_pkg_prev=
402 $(foreach pkg,$(PACKAGES),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
403
404 # the GHC package doesn't live in libraries/, so we add its dependency manually:
405 compiler/stage2/package-data.mk: $(fixed_pkg_prev)
406 fixed_pkg_prev:=compiler/stage2/package-data.mk
407
408 # and continue with PACKAGES_STAGE2, which depend on GHC:
409 $(foreach pkg,$(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
410
411 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
412 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
413 # haddock depends on ghc and some libraries, but depending on GHC's
414 # package-data.mk is sufficient, as that in turn depends on all the
415 # libraries
416 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
417
418 utils/ghc-pkg/dist-install/package-data.mk: compiler/stage2/package-data.mk
419 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
420 utils/compare_sizes/dist/package-data.mk: compiler/stage2/package-data.mk
421
422 # add the final two package.conf dependencies: ghc-prim depends on RTS,
423 # and RTS depends on libffi.
424 libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
425 rts/package.conf.inplace : libffi/package.conf.inplace
426 endif
427
428 # --------------------------------
429 # Misc package-related settings
430
431 BOOT_PKG_CONSTRAINTS := $(foreach p,$(STAGE0_PACKAGES),--constraint "$p == $(shell grep -i "^Version:" libraries/$p/$p.cabal | sed "s/[^0-9.]//g")")
432
433 # The actual .a and .so/.dll files: needed for dependencies.
434 ALL_STAGE1_LIBS  = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
435 ifeq "$(BuildSharedLibs)" "YES"
436 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB))
437 endif
438 BOOT_LIBS = $(foreach lib,$(STAGE0_PACKAGES),$(libraries/$(lib)_dist-boot_v_LIB))
439 # A useful pseudo-target
440 .PHONY: stage1_libs
441 stage1_libs : $(ALL_STAGE1_LIBS)
442
443 OTHER_LIBS = libffi/dist-install/build/libHSffi$(v_libsuf) libffi/dist-install/build/HSffi.o
444 ifeq "$(BuildSharedLibs)" "YES"
445 OTHER_LIBS  += libffi/dist-install/build/libHSffi$(dyn_libsuf)
446 endif
447
448 # ----------------------------------------
449 # Special magic for the ghc-prim package
450
451 # We want the ghc-prim package to include the GHC.Prim module when it
452 # is registered, but not when it is built, because GHC.Prim is not a
453 # real source module, it is built-in to GHC.  The old build system did
454 # this using Setup.hs, but we can't do that here, so we have a flag to
455 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
456 # remains compatible with the old build system for the time being).
457 # GHC.Prim module in the ghc-prim package with a flag:
458 #
459 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
460
461 # And then we strip it out again before building the package:
462 define libraries/ghc-prim_PACKAGE_MAGIC
463 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
464 endef
465
466 PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
467
468 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT) | $$(dir $$@)/.
469         "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
470
471 # Required so that Haddock documents the primops.
472 libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
473
474 # ----------------------------------------
475 # Special magic for the integer package
476
477 ifneq "$(CLEANING)" "YES"
478 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
479 libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple
480 else
481     ifeq "$(INTEGER_LIBRARY)" "integer-simple"
482         libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
483     else
484 $(error Unknown integer library: $(INTEGER_LIBRARY))
485     endif
486 endif
487 endif
488
489 # -----------------------------------------------------------------------------
490 # Include build instructions from all subdirs
491
492 # For the rationale behind the build phases, see
493 #   http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
494
495 # Setting foo_dist_DISABLE=YES means "in directory foo, for build
496 # "dist", just read the package-data.mk file, do not build anything".
497
498 # We carefully engineer things so that we can build the
499 # package-data.mk files early on: they depend only on a few tools also
500 # built early.  Having got the package-data.mk files built, we can
501 # restart make with up-to-date information about all the packages
502 # (this is phase 0).  The remaining problem is the .depend files:
503 #
504 #   - .depend files in libraries need the stage 1 compiler to build
505 #   - ghc/stage1/.depend needs compiler/stage1 built
506 #   - compiler/stage1/.depend needs the bootstrap libs built
507 #
508 # GHC 6.11+ can build a .depend file without having built the
509 # dependencies of the package, but we can't rely on the bootstrapping
510 # compiler being able to do this, which is why we have to separate the
511 # three phases above.
512
513 # So this is the final ordering:
514
515 # Phase 0 : all package-data.mk files
516 #           (requires ghc-cabal, ghc-pkg, mkdirhier, dummy-ghc etc.)
517 # Phase 1 : .depend files for bootstrap libs
518 #           (requires hsc2hs)
519 # Phase 2 : compiler/stage1/.depend
520 #           (requires bootstrap libs and genprimopcode)
521 # Phase 3 : ghc/stage1/.depend
522 #           (requires compiler/stage1)
523 #
524 # The rest : libraries/*/dist-install, compiler/stage2, ghc/stage2
525
526 ifneq "$(BINDIST)" "YES"
527 BUILD_DIRS += \
528    $(GHC_MKDIRHIER_DIR)
529 endif
530
531 BUILD_DIRS += \
532    docs/users_guide \
533    docs/ext-core \
534    docs/man \
535    libraries/Cabal/doc \
536    $(GHC_UNLIT_DIR) \
537    $(GHC_HP2PS_DIR)
538
539 ifneq "$(GhcUnregisterised)" "YES"
540 BUILD_DIRS += \
541    $(GHC_MANGLER_DIR) \
542    $(GHC_SPLIT_DIR)
543 endif
544
545 ifneq "$(BINDIST)" "YES"
546 BUILD_DIRS += \
547    $(GHC_GENPRIMOP_DIR)
548 endif
549
550 BUILD_DIRS += \
551    driver \
552    driver/ghci \
553    driver/ghc \
554    driver/haddock \
555    libffi \
556    includes \
557    rts
558
559 ifneq "$(BINDIST)" "YES"
560 BUILD_DIRS += \
561    bindisttest \
562    $(GHC_CABAL_DIR) \
563    $(GHC_GENAPPLY_DIR)
564 endif
565
566 BUILD_DIRS += \
567    utils/haddock \
568    utils/haddock/doc
569
570 ifneq "$(CLEANING)" "YES"
571 BUILD_DIRS += \
572    $(patsubst %, libraries/%, $(PACKAGES))
573 endif
574
575 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
576 BUILD_DIRS += libraries/integer-gmp/gmp
577 endif
578
579 BUILD_DIRS += \
580    compiler \
581    $(GHC_HSC2HS_DIR) \
582    $(GHC_PKG_DIR) \
583    utils/testremove \
584    utils/ghctags \
585    utils/hpc \
586    utils/runghc \
587    ghc
588 ifeq "$(Windows)" "YES"
589 BUILD_DIRS += \
590    $(GHC_TOUCHY_DIR)
591 endif
592
593 ifneq "$(BINDIST)" "YES"
594 BUILD_DIRS += \
595    utils/mkUserGuidePart
596 endif
597
598 BUILD_DIRS += utils/count_lines
599 BUILD_DIRS += utils/compare_sizes
600
601 ifneq "$(CLEANING)" "YES"
602 # After compiler/, because these packages depend on it
603 BUILD_DIRS += \
604    $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
605 endif
606
607 # XXX libraries/% must come before any programs built with stage1, see
608 # Note [lib-depends].
609
610 ifeq "$(phase)" "0"
611 $(foreach lib,$(STAGE0_PACKAGES),$(eval \
612   libraries/$(lib)_dist-boot_DISABLE = YES))
613 endif
614
615 ifneq "$(findstring $(phase),0 1)" ""
616 # We can build deps for compiler/stage1 in phase 2
617 compiler_stage1_DISABLE = YES
618 endif
619
620 ifneq "$(findstring $(phase),0 1 2)" ""
621 ghc_stage1_DISABLE = YES
622 endif
623
624 ifneq "$(findstring $(phase),0 1 2 3)" ""
625 # In phases 0-3, we disable stage2-3, the full libraries and haddock
626 utils/haddock_dist_DISABLE = YES
627 utils/runghc_dist_DISABLE = YES
628 utils/ghctags_dist_DISABLE = YES
629 utils/hpc_dist_DISABLE = YES
630 utils/hsc2hs_dist-install_DISABLE = YES
631 utils/ghc-pkg_dist-install_DISABLE = YES
632 utils/mkUserGuidePart_dist_DISABLE = YES
633 utils/compare_sizes_dist_DISABLE = YES
634 compiler_stage2_DISABLE = YES
635 compiler_stage3_DISABLE = YES
636 ghc_stage2_DISABLE = YES
637 ghc_stage3_DISABLE = YES
638 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),$(eval \
639   libraries/$(lib)_dist-install_DISABLE = YES))
640 endif
641
642 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
643
644 # ----------------------------------------------
645 # Per-package compiler flags
646
647 # If you want to add per-package compiler flags, this 
648 # is the place to do it.  Do it like this for package <pkg>
649 #   
650 #   libraries/<pkg>_dist-boot_HC_OPTS += -Wwarn
651 #   libraries/<pkg>_dist-install_HC_OPTS += -Wwarn
652
653 # Add $(GhcLibHcOpts) to all package builds
654 $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
655
656 # Add $(GhcBootLibHcOpts) to all stage0 package builds
657 $(foreach pkg,$(STAGE0_PACKAGES),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
658
659 # ----------------------------------------------
660 # Checking packages with 'cabal check'
661
662 ifeq "$(CHECK_PACKAGES)" "YES"
663 all: check_packages
664 endif
665
666 # These packages don't pass the Cabal checks because hs-source-dirs
667 # points outside the source directory. This isn't a real problem in
668 # these cases, so we just skip checking them.
669 CHECKED_libraries/dph/dph-seq = YES
670 CHECKED_libraries/dph/dph-par = YES
671 # In compiler's case, include-dirs points outside of the source tree
672 CHECKED_compiler = YES
673
674 # -----------------------------------------------
675 # Haddock-related bits
676
677 # Don't run Haddock for the package that will not be installed
678 $(foreach p,$(INTREE_ONLY_PACKAGES),$(eval libraries/$p_dist-install_DO_HADDOCK = NO))
679 # We don't haddock the bootstrapping libraries
680 $(foreach p,$(STAGE0_PACKAGES),$(eval libraries/$p_dist-boot_DO_HADDOCK = NO))
681
682 # Build the Haddock contents and index
683 ifeq "$(HADDOCK_DOCS)" "YES"
684 libraries/index.html: $(ALL_HADDOCK_FILES)
685         cd libraries && sh gen_contents_index --inplace
686 $(eval $(call all-target,library_doc_index,libraries/index.html))
687 INSTALL_LIBRARY_DOCS += libraries/*.html libraries/*.gif libraries/*.css libraries/*.js
688 CLEAN_FILES += libraries/doc-index* libraries/haddock*.css \
689                libraries/haddock*.js libraries/index*.html libraries/*.gif
690 endif
691
692 # -----------------------------------------------------------------------------
693 # Bootstrapping libraries
694
695 # We need to build a few libraries with the installed GHC, since GHC itself
696 # and some of the tools depend on them:
697
698 ifneq "$(BINDIST)" "YES"
699
700 ifneq "$(BOOTSTRAPPING_CONF)" ""
701 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
702 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
703 endif
704 endif
705
706 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
707
708 # These three libraries do not depend on each other, so we can build
709 # them straight off:
710
711 $(eval $(call build-package,libraries/hpc,dist-boot,0))
712 $(eval $(call build-package,libraries/extensible-exceptions,dist-boot,0))
713 $(eval $(call build-package,libraries/Cabal,dist-boot,0))
714 $(eval $(call build-package,libraries/binary,dist-boot,0))
715 $(eval $(call build-package,libraries/bin-package-db,dist-boot,0))
716
717 # register the boot packages in strict sequence, because running
718 # multiple ghc-pkgs in parallel doesn't work (registrations may get
719 # lost).
720 fixed_pkg_prev=
721 $(foreach pkg,$(STAGE0_PACKAGES),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
722
723 compiler/stage1/package-data.mk : \
724     libraries/Cabal/dist-boot/package-data.mk \
725     libraries/hpc/dist-boot/package-data.mk \
726     libraries/extensible-exceptions/dist-boot/package-data.mk \
727     libraries/bin-package-db/dist-boot/package-data.mk
728
729 # These are necessary because the bootstrapping compiler may not know
730 # about cross-package dependencies:
731 $(compiler_stage1_depfile_haskell) : $(BOOT_LIBS)
732 $(ghc_stage1_depfile_haskell) : $(compiler_stage1_v_LIB)
733
734 # A few careful dependencies between bootstrapping packages.  When we
735 # can rely on the stage 0 compiler being able to generate
736 # cross-package dependencies with -M (fixed in GHC 6.12.1) we can drop
737 # these, and also some of the phases.
738 #
739 # If you miss any out here, then 'make -j8' will probably tell you.
740 #
741 libraries/bin-package-db/dist-boot/build/Distribution/InstalledPackageInfo/Binary.$(v_osuf) : libraries/binary/dist-boot/build/Data/Binary.$(v_hisuf) libraries/Cabal/dist-boot/build/Distribution/InstalledPackageInfo.$(v_hisuf)
742
743 # Make sure we have all the GHCi libs by the time we've built
744 # ghc-stage2.  DPH includes a bit of Template Haskell which needs the
745 # GHCI libs, and we don't have a better way to express that dependency.
746 #
747 GHCI_LIBS = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
748             $(compiler_stage2_GHCI_LIB)
749
750 ifeq "$(UseArchivesForGhci)" "NO"
751 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
752 endif
753
754 endif
755
756 # -----------------------------------------------------------------------------
757 # Creating a local mingw copy on Windows
758
759 ifeq "$(Windows)" "YES"
760
761 install : install_mingw
762 .PHONY: install_mingw
763 install_mingw : $(INPLACE_MINGW)
764         "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
765
766 install : install_perl
767 .PHONY: install_perl
768 install_perl : $(INPLACE_PERL)
769         "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
770
771 endif # Windows
772
773 ifneq "$(BINDIST)" "YES"
774 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
775     libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs \
776     libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs
777 endif # BINDIST
778
779 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
780                             $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) \
781                           | $$(dir $$@)/.
782         "$(GENPRIMOP_INPLACE)" --make-haskell-source < $< > $@
783
784 libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs: \
785                             $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) \
786                           | $$(dir $$@)/.
787         "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers < $< > $@
788
789 .PHONY: tags
790 tags: tags_compiler
791
792 .PHONY: TAGS
793 TAGS: TAGS_compiler
794
795 # -----------------------------------------------------------------------------
796 # Installation
797
798 install: install_packages install_libs install_libexecs install_headers \
799          install_libexec_scripts install_bins install_topdirs
800 ifeq "$(HADDOCK_DOCS)" "YES"
801 install: install_docs
802 endif
803
804 install_bins: $(INSTALL_BINS)
805         $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
806         for i in $(INSTALL_BINS); do \
807                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(bindir)" ;  \
808         done
809
810 install_libs: $(INSTALL_LIBS)
811         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)"
812         for i in $(INSTALL_LIBS); do \
813                 case $$i in \
814                   *.a) \
815                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)"; \
816                     $(RANLIB) $(DESTDIR)$(ghclibdir)/`basename $$i` ;; \
817                   *.dll) \
818                     $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)" ;; \
819                   *.so) \
820                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)" ;; \
821                   *.dylib) \
822                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)";; \
823                   *) \
824                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibdir)"; \
825                 esac; \
826         done
827
828 install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
829 ifeq "$(INSTALL_LIBEXEC_SCRIPTS)" ""
830         @:
831 else
832         $(INSTALL_DIR) "$(DESTDIR)$(ghclibexecdir)"
833         for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
834                 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghclibexecdir)"; \
835         done
836 endif
837
838 install_libexecs:  $(INSTALL_LIBEXECS)
839 ifeq "$(INSTALL_LIBEXECS)" ""
840         @:
841 else
842         $(INSTALL_DIR) "$(DESTDIR)$(ghclibexecdir)"
843         for i in $(INSTALL_LIBEXECS); do \
844                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(ghclibexecdir)"; \
845         done
846 # We rename ghc-stage2, so that the right program name is used in error
847 # messages etc.
848         "$(MV)" "$(DESTDIR)$(ghclibexecdir)/ghc-stage2" "$(DESTDIR)$(ghclibexecdir)/ghc"
849 endif
850
851 install_topdirs: $(INSTALL_TOPDIRS)
852         $(INSTALL_DIR) "$(DESTDIR)$(topdir)"
853         for i in $(INSTALL_TOPDIRS); do \
854                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i "$(DESTDIR)$(topdir)"; \
855         done
856
857 install_headers: $(INSTALL_HEADERS)
858         $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
859         for i in $(INSTALL_HEADERS); do \
860                 $(INSTALL_HEADER) $(INSTALL_OPTS) $$i "$(DESTDIR)$(ghcheaderdir)"; \
861         done
862
863 install_docs: $(INSTALL_DOCS)
864         $(INSTALL_DIR) "$(DESTDIR)$(docdir)"
865 ifneq "$(INSTALL_DOCS)" ""
866         for i in $(INSTALL_DOCS); do \
867                 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)"; \
868         done
869 endif
870         $(INSTALL_DIR) $(INSTALL_OPTS) "$(DESTDIR)$(docdir)/html"
871         $(INSTALL_DOC) $(INSTALL_OPTS) docs/index.html "$(DESTDIR)$(docdir)/html"
872 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
873         $(INSTALL_DIR) $(INSTALL_OPTS) "$(DESTDIR)$(docdir)/html/libraries"
874         for i in $(INSTALL_LIBRARY_DOCS); do \
875                 $(INSTALL_DOC) $(INSTALL_OPTS) $$i "$(DESTDIR)$(docdir)/html/libraries/"; \
876         done
877         $(INSTALL_DATA) $(INSTALL_OPTS) libraries/prologue.txt "$(DESTDIR)$(docdir)/html/libraries/"
878         $(INSTALL_SCRIPT) $(INSTALL_OPTS) libraries/gen_contents_index "$(DESTDIR)$(docdir)/html/libraries/"
879 endif
880 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
881         for i in $(INSTALL_HTML_DOC_DIRS); do \
882                 $(INSTALL_DIR) $(INSTALL_OPTS) "$(DESTDIR)$(docdir)/html/`basename $$i`"; \
883                 $(INSTALL_DOC) $(INSTALL_OPTS) $$i/* "$(DESTDIR)$(docdir)/html/`basename $$i`"; \
884         done
885 endif
886
887 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
888
889 # Install packages in the right order, so that ghc-pkg doesn't complain.
890 # Also, install ghc-pkg first.
891 ifeq "$(Windows)" "NO"
892 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/ghc
893 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/ghc-pkg
894 else
895 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
896 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
897 endif
898
899 INSTALLED_PACKAGES := $(filter-out $(INTREE_ONLY_PACKAGES),$(PACKAGES))
900 ifeq "$(InstallExtraPackages)" "NO"
901 INSTALLED_PACKAGES := $(filter-out $(EXTRA_PACKAGES), $(INSTALLED_PACKAGES))
902 endif
903
904 HIDDEN_PACKAGES = binary
905
906 define set_INSTALL_DISTDIR
907 # $1 = libraries/base, $2 = dist-install
908 # =>
909 # INSTALL_DISTDIR_libraries/base = dist-install
910 INSTALL_DISTDIR_$1 = $2
911 endef
912
913 $(eval $(foreach p,$(INSTALLED_PACKAGES) $(PACKAGES_STAGE2),\
914 $(call set_INSTALL_DISTDIR,libraries/$p,dist-install)))
915 INSTALL_DISTDIR_compiler = stage2
916
917 ALL_INSTALLED_PACKAGES = $(addprefix libraries/,$(INSTALLED_PACKAGES)) \
918                          compiler \
919                          $(addprefix libraries/,$(PACKAGES_STAGE2))
920
921 install_packages: install_libexecs
922 install_packages: libffi/package.conf.install rts/package.conf.install
923         $(INSTALL_DIR) "$(DESTDIR)$(topdir)"
924         "$(RM)" $(RM_OPTS_REC) "$(INSTALLED_PACKAGE_CONF)"
925         $(INSTALL_DIR) "$(INSTALLED_PACKAGE_CONF)"
926         "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf "$(INSTALLED_PACKAGE_CONF)" update libffi/package.conf.install
927         "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf "$(INSTALLED_PACKAGE_CONF)" update rts/package.conf.install
928         $(foreach p, $(ALL_INSTALLED_PACKAGES),                       \
929             $(call make-command,                                      \
930                    "$(GHC_CABAL_INPLACE)" install                     \
931                                           "$(INSTALLED_GHC_REAL)"     \
932                                           "$(INSTALLED_GHC_PKG_REAL)" \
933                                           "$(STRIP_CMD)"              \
934                                           "$(DESTDIR)$(topdir)"       \
935                                           $p $(INSTALL_DISTDIR_$p)    \
936                                           '$(DESTDIR)'                \
937                                           '$(prefix)'                 \
938                                           '$(ghclibdir)'              \
939                                           '$(docdir)/html/libraries'  \
940                                           $(RelocatableBuild)))
941         $(foreach p, $(HIDDEN_PACKAGES),                                   \
942             $(call make-command,                                           \
943                    "$(INSTALLED_GHC_PKG_REAL)"                             \
944                        --global-conf "$(INSTALLED_PACKAGE_CONF)" hide $p))
945
946 # -----------------------------------------------------------------------------
947 # Binary distributions
948
949 ifneq "$(CLEANING)" "YES"
950 # This rule seems to hold some files open on Windows which prevents
951 # cleaning, perhaps due to the $(wildcard).
952
953 $(eval $(call bindist,.,\
954     LICENSE \
955     README \
956     INSTALL \
957     configure config.sub config.guess install-sh \
958     extra-gcc-opts.in \
959     packages \
960     Makefile \
961     mk/config.mk.in \
962     $(INPLACE_BIN)/mkdirhier \
963     $(INPLACE_BIN)/ghc-cabal \
964     utils/ghc-pwd/ghc-pwd \
965         $(BINDIST_WRAPPERS) \
966         $(BINDIST_PERL_SOURCES) \
967         $(BINDIST_LIBS) \
968         $(BINDIST_HI) \
969         $(BINDIST_EXTRAS) \
970         $(includes_H_CONFIG) \
971         $(includes_H_PLATFORM) \
972     $(includes_H_FILES) \
973         includes/ghcconfig.h \
974         includes/rts/Config.h \
975     $(INSTALL_HEADERS) \
976     $(INSTALL_LIBEXECS) \
977     $(INSTALL_LIBEXEC_SCRIPTS) \
978     $(INSTALL_TOPDIRS) \
979     $(INSTALL_BINS) \
980     $(INSTALL_MANPAGES) \
981     $(INSTALL_DOCS) \
982     $(INSTALL_LIBRARY_DOCS) \
983     $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
984         docs/index.html \
985         compiler/stage2/doc \
986         $(wildcard libraries/*/dist-install/doc/) \
987         $(wildcard libraries/*/*/dist-install/doc/) \
988     $(filter-out extra-gcc-opts,$(INSTALL_LIBS)) \
989     $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
990         mk/project.mk \
991         mk/install.mk.in \
992         bindist.mk \
993         libraries/gen_contents_index \
994         libraries/prologue.txt \
995         libraries/dph/LICENSE \
996         libraries/dph/ghc-packages \
997         libraries/dph/ghc-packages2 \
998         libraries/dph/ghc-stage2-package \
999  ))
1000 endif
1001 # mk/project.mk gets an absolute path, so we manually include it in
1002 # the bindist with a relative path
1003
1004 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
1005
1006 unix-binary-dist-prep:
1007         "$(RM)" $(RM_OPTS_REC) bindistprep/
1008         "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
1009         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 extra-gcc-opts.in ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
1010         echo "HADDOCK_DOCS       = $(HADDOCK_DOCS)"       >> $(BIN_DIST_MK)
1011         echo "LATEX_DOCS         = $(LATEX_DOCS)"         >> $(BIN_DIST_MK)
1012         echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
1013         echo "BUILD_DOCBOOK_PS   = $(BUILD_DOCBOOK_PS)"   >> $(BIN_DIST_MK)
1014         echo "BUILD_DOCBOOK_PDF  = $(BUILD_DOCBOOK_PDF)"  >> $(BIN_DIST_MK)
1015         echo "BUILD_MAN          = $(BUILD_MAN)"          >> $(BIN_DIST_MK)
1016         cd $(BIN_DIST_PREP_DIR) && autoreconf
1017         "$(RM)" $(RM_OPTS) $(BIN_DIST_PREP_TAR)
1018 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1019 # tree then we want to include the real file, not a symlink to it
1020         cd bindistprep && "$(TAR_CMD)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1021
1022 windows-binary-dist-prep:
1023         "$(RM)" $(RM_OPTS_REC) bindistprep/
1024         $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1025         cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1026
1027 windows-installer:
1028 ifeq "$(ISCC_CMD)" ""
1029         @echo No ISCC_CMD, so not making installer
1030 else
1031         "$(ISCC_CMD)" /O. /Fbindistprep/$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
1032 endif
1033
1034 # tryTimes tries to run its third argument multiple times, until it
1035 # succeeds. Don't call it directly; call try10Times instead.
1036 # The first and second argument to tryTimes are lists of values.
1037 # The length of the first argument is the number of times we have
1038 # already tried. The length of the second argument is the number more
1039 # times we will try.
1040 tryTimes = $(if $2, \
1041                 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1042                 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1043                 )
1044
1045 # Try to run the argument 10 times. If all 10 fail, fail.
1046 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1047
1048 .PHONY: publish-binary-dist
1049 publish-binary-dist:
1050         $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
1051 ifeq "$(mingw32_TARGET_OS)" "1"
1052         $(call try10Times,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
1053 endif
1054
1055 .PHONY: publish-docs
1056 publish-docs:
1057         $(call try10Times,$(PublishCp) -r bindisttest/installed/share/doc/ghc/* $(PublishLocation)/docs)
1058
1059 # -----------------------------------------------------------------------------
1060 # Source distributions
1061
1062 # Do it like this:
1063 #
1064 #       $ make
1065 #       $ make sdist
1066 #
1067
1068 # A source dist is built from a complete build tree, because we
1069 # require some extra files not contained in a darcs checkout: the
1070 # output from Happy and Alex, for example.
1071 #
1072 # The steps performed by 'make dist' are as follows:
1073 #   - create a complete link-tree of the current build tree in /tmp
1074 #   - run 'make distclean' on that tree
1075 #   - remove a bunch of other files that we know shouldn't be in the dist
1076 #   - tar up first the extralibs package, then the main source package
1077
1078 #
1079 # Directory in which we're going to build the src dist
1080 #
1081 SRC_DIST_NAME=ghc-$(ProjectVersion)
1082 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
1083
1084 #
1085 # Files to include in source distributions
1086 #
1087 SRC_DIST_DIRS = mk rules docs distrib bindisttest libffi includes utils docs rts compiler ghc driver libraries ghc-tarballs
1088 SRC_DIST_FILES += \
1089         configure.ac config.guess config.sub configure \
1090         aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
1091         ghc.spec.in ghc.spec extra-gcc-opts.in VERSION \
1092         boot boot-pkgs packages ghc.mk
1093
1094 SRC_DIST_TARBALL = $(SRC_DIST_NAME)-src.tar.bz2
1095
1096 VERSION :
1097         echo $(ProjectVersion) >VERSION
1098
1099 sdist : VERSION
1100
1101 # Use:
1102 #     $(call sdist_file,compiler,stage2,cmm,Foo/Bar,CmmLex,x)
1103 # to copy the generated file that replaces compiler/cmm/Foo/Bar/CmmLex.x, where
1104 # "stage2" is the dist dir.
1105 define sdist_file
1106         "$(CP)" $1/$2/build/$4/$5.hs $(SRC_DIST_DIR)/$1/$3/$4
1107         mv $(SRC_DIST_DIR)/$1/$3/$4/$5.$6 $(SRC_DIST_DIR)/$1/$3/$4/$5.$6.source
1108 endef
1109
1110 .PHONY: sdist-prep
1111 sdist-prep :
1112         "$(RM)" $(RM_OPTS_REC) $(SRC_DIST_DIR)
1113         "$(RM)" $(RM_OPTS) $(SRC_DIST_TARBALL)
1114         mkdir $(SRC_DIST_DIR)
1115         cd $(SRC_DIST_DIR) && for i in $(SRC_DIST_DIRS); do mkdir $$i; ( cd $$i && lndir $(TOP)/$$i ); done
1116         cd $(SRC_DIST_DIR) && for i in $(SRC_DIST_FILES); do $(LN_S) $(TOP)/$$i .; done
1117         cd $(SRC_DIST_DIR) && $(MAKE) distclean
1118         rm -rf $(SRC_DIST_DIR)/libraries/tarballs/
1119         rm -rf $(SRC_DIST_DIR)/libraries/stamp/
1120         $(call sdist_file,compiler,stage2,cmm,,CmmLex,x)
1121         $(call sdist_file,compiler,stage2,cmm,,CmmParse,y)
1122         $(call sdist_file,compiler,stage2,parser,,Lexer,x)
1123         $(call sdist_file,compiler,stage2,parser,,Parser,y.pp)
1124         $(call sdist_file,compiler,stage2,parser,,ParserCore,y)
1125         $(call sdist_file,utils/hpc,dist,,,HpcParser,y)
1126         $(call sdist_file,utils/genprimopcode,dist,,,Lexer,x)
1127         $(call sdist_file,utils/genprimopcode,dist,,,Parser,y)
1128         $(call sdist_file,utils/haddock,dist,src,Haddock,Lex,x)
1129         $(call sdist_file,utils/haddock,dist,src,Haddock,Parse,y)
1130         cd $(SRC_DIST_DIR) && "$(RM)" $(RM_OPTS_REC) compiler/stage[123] mk/build.mk
1131         cd $(SRC_DIST_DIR) && "$(FIND)" $(SRC_DIST_DIRS) \( -name _darcs -o -name SRC -o -name "autom4te*" -o -name "*~" -o -name ".cvsignore" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" -o -name "*-darcs-backup*" \) -print | "$(XARGS)" $(XARGS_OPTS) "$(RM)" $(RM_OPTS_REC)
1132
1133 .PHONY: sdist
1134 sdist : sdist-prep
1135         "$(TAR_CMD)" chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(TOP)/$(SRC_DIST_TARBALL)
1136
1137 sdist-manifest : $(SRC_DIST_TARBALL)
1138         tar tjf $(SRC_DIST_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
1139
1140 # Upload the distribution(s)
1141 # Retrying is to work around buggy firewalls that corrupt large file transfers
1142 # over SSH.
1143 ifneq "$(PublishLocation)" ""
1144 publish-sdist :
1145         $(call try10Times,$(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist)
1146 endif
1147
1148 ifeq "$(BootingFromHc)" "YES"
1149 # In a normal build we use GHC to compile C files (see
1150 # rules/c-suffix-rules.mk), which passes a number of its own options
1151 # to the C compiler.  So when bootstrapping we have to provide these
1152 # flags explicitly to C compilations.
1153 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
1154 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
1155 SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR)
1156 endif
1157
1158 # -----------------------------------------------------------------------------
1159 # sdisting libraries
1160
1161 # Use manually, with e.g.:
1162 #     make sdist_directory
1163
1164 sdist_%:
1165         inplace/bin/ghc-cabal sdist libraries/$* dist-install
1166
1167 # -----------------------------------------------------------------------------
1168 # Cleaning
1169
1170 .PHONY: clean
1171
1172 CLEAN_FILES += utils/ghc-pwd/ghc-pwd
1173 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.exe
1174 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.hi
1175 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.o
1176 CLEAN_FILES += libraries/bootstrapping.conf
1177 CLEAN_FILES += libraries/integer-gmp/cbits/GmpDerivedConstants.h
1178 CLEAN_FILES += libraries/integer-gmp/cbits/mkGmpDerivedConstants
1179
1180 clean : clean_files clean_libraries
1181
1182 .PHONY: clean_files
1183 clean_files :
1184         "$(RM)" $(RM_OPTS) $(CLEAN_FILES)
1185
1186 ifneq "$(NO_CLEAN_GMP)" "YES"
1187 CLEAN_FILES += libraries/integer-gmp/gmp/gmp.h
1188 CLEAN_FILES += libraries/integer-gmp/gmp/libgmp.a
1189
1190 clean : clean_gmp
1191 .PHONY: clean_gmp
1192 clean_gmp:
1193         "$(RM)" $(RM_OPTS_REC) libraries/integer-gmp/gmp/objs
1194         "$(RM)" $(RM_OPTS_REC) libraries/integer-gmp/gmp/gmpbuild
1195 endif
1196
1197 .PHONY: clean_libraries
1198 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES) $(PACKAGES_STAGE2))
1199 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(STAGE0_PACKAGES))
1200
1201 clean_libraries:
1202         "$(RM)" $(RM_OPTS_REC) $(patsubst %, libraries/%/dist, $(PACKAGES) $(PACKAGES_STAGE2))
1203         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/*.buildinfo, $(PACKAGES) $(PACKAGES_STAGE2))
1204
1205 # We have to define a clean target for each library manually, because the
1206 # libraries/*/ghc.mk files are not included when we're cleaning.
1207 ifeq "$(CLEANING)" "YES"
1208 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),\
1209   $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1210 endif
1211
1212 clean : clean_bindistprep
1213 .PHONY: clean_bindistprep
1214 clean_bindistprep:
1215         "$(RM)" $(RM_OPTS_REC) bindistprep/
1216
1217 distclean : clean
1218         "$(RM)" $(RM_OPTS) config.cache config.status config.log mk/config.h mk/stamp-h
1219         "$(RM)" $(RM_OPTS) mk/config.mk mk/are-validating.mk mk/project.mk
1220         "$(RM)" $(RM_OPTS) mk/config.mk.old mk/project.mk.old
1221         "$(RM)" $(RM_OPTS) extra-gcc-opts docs/users_guide/ug-book.xml
1222         "$(RM)" $(RM_OPTS) compiler/ghc.cabal compiler/ghc.cabal.old
1223         "$(RM)" $(RM_OPTS) ghc/ghc-bin.cabal
1224         "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h
1225         "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h
1226         "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h
1227         "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h
1228         "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h
1229
1230         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.log, $(PACKAGES) $(PACKAGES_STAGE2))
1231         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.status, $(PACKAGES) $(PACKAGES_STAGE2))
1232         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES) $(PACKAGES_STAGE2))
1233         "$(RM)" $(RM_OPTS_REC) $(patsubst %, libraries/%/autom4te.cache, $(PACKAGES) $(PACKAGES_STAGE2))
1234
1235 maintainer-clean : distclean
1236         "$(RM)" $(RM_OPTS) configure mk/config.h.in
1237         "$(RM)" $(RM_OPTS_REC) autom4te.cache libraries/*/autom4te.cache
1238         "$(RM)" $(RM_OPTS) ghc.spec
1239         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/GNUmakefile, \
1240                 $(PACKAGES) $(PACKAGES_STAGE2))
1241         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/ghc.mk, $(PACKAGES) $(PACKAGES_STAGE2))
1242         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/configure, \
1243                 $(PACKAGES) $(PACKAGES_STAGE2))
1244         "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h.in
1245         "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h.in
1246         "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h.in
1247         "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h.in
1248         "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h.in
1249
1250 .PHONY: all_libraries
1251
1252 .PHONY: bootstrapping-files
1253 bootstrapping-files: $(OTHER_LIBS)
1254 bootstrapping-files: includes/ghcautoconf.h
1255 bootstrapping-files: includes/DerivedConstants.h
1256 bootstrapping-files: includes/GHCConstants.h
1257
1258 .DELETE_ON_ERROR:
1259