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