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