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