Fix dynamically linked GHC on Windows
[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 # Run Haddock for the packages that will be installed. We need to handle
504 # compiler specially due to the different dist directory name.
505 $(foreach p,$(INSTALL_PACKAGES),$(eval $p_dist-install_DO_HADDOCK = YES))
506 compiler_stage2_DO_HADDOCK = YES
507
508 BOOT_PKG_CONSTRAINTS := \
509 $(foreach d,$(PACKAGES_STAGE0),\
510 $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
511 --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
512
513 # The actual .a and .so/.dll files: needed for dependencies.
514 ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_v_LIB))
515 ifeq "$(BuildSharedLibs)" "YES"
516 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_dyn_LIB))
517 endif
518 BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB))
519
520 # ----------------------------------------
521 # Special magic for the ghc-prim package
522
523 # We want the ghc-prim package to include the GHC.Prim module when it
524 # is registered, but not when it is built, because GHC.Prim is not a
525 # real source module, it is built-in to GHC. The old build system did
526 # this using Setup.hs, but we can't do that here, so we have a flag to
527 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
528 # remains compatible with the old build system for the time being).
529 # GHC.Prim module in the ghc-prim package with a flag:
530 #
531 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
532
533 # And then we strip it out again before building the package:
534 define libraries/ghc-prim_PACKAGE_MAGIC
535 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
536 endef
537
538 PRIMOPS_TXT_STAGE1 = compiler/stage1/build/primops.txt
539
540 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $$(genprimopcode_INPLACE) $(PRIMOPS_TXT_STAGE1) | $$(dir $$@)/.
541 "$(genprimopcode_INPLACE)" --make-haskell-wrappers < $(PRIMOPS_TXT_STAGE1) >$@
542
543 # Required so that Haddock documents the primops.
544 libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
545
546 # ----------------------------------------
547 # Special magic for the integer package
548
549 ifneq "$(CLEANING)" "YES"
550 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
551 libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple
552 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
553 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
554 else
555 $(error Unknown integer library: $(INTEGER_LIBRARY))
556 endif
557 endif
558
559 # ----------------------------------------
560 # Special magic for the packages which link to the RTS
561 # This is a rather ugly hack to fix dynamically linked GHC on Windows.
562 # If GHC is linked with -threaded, then it links against libHSrts_thr.
563 # But if base is linked against libHSrts, then both end up getting
564 # loaded, and things go wrong. We therefore link the libraries that
565 # link against the RTS with the same RTS flags that we link GHC with.
566 ifeq "$(GhcThreaded)" "YES"
567 libraries/ghc-prim_dist-install_MORE_HC_OPTS += -threaded
568 libraries/integer-gmp_dist-install_MORE_HC_OPTS += -threaded
569 libraries/base_dist-install_MORE_HC_OPTS += -threaded
570 endif
571 ifeq "$(GhcDebugged)" "YES"
572 libraries/ghc-prim_dist-install_MORE_HC_OPTS += -debug
573 libraries/integer-gmp_dist-install_MORE_HC_OPTS += -debug
574 libraries/base_dist-install_MORE_HC_OPTS += -debug
575 endif
576
577 # ----------------------------------------
578 # Workarounds for problems building DLLs on Windows
579
580 ifeq "$(TargetOS_CPP)" "mingw32"
581 # We don't build the GHC package the dyn way on Windows, so
582 # we can't build these packages the dyn way either. See trac #5987
583 libraries/dph/dph-lifted-base_dist-install_EXCLUDED_WAYS := dyn
584 libraries/dph/dph-lifted-boxed_dist-install_EXCLUDED_WAYS := dyn
585 libraries/dph/dph-lifted-copy_dist-install_EXCLUDED_WAYS := dyn
586 libraries/dph/dph-lifted-vseg_dist-install_EXCLUDED_WAYS := dyn
587 endif
588
589 # -----------------------------------------------------------------------------
590 # Include build instructions from all subdirs
591
592 ifneq "$(BINDIST)" "YES"
593 BUILD_DIRS += utils/mkdirhier
594 endif
595
596 ifeq "$(Windows_Host)" "YES"
597 BUILD_DIRS += utils/touchy
598 endif
599
600 BUILD_DIRS += utils/unlit
601 BUILD_DIRS += utils/hp2ps
602
603 ifneq "$(GhcUnregisterised)" "YES"
604 BUILD_DIRS += driver/split
605 endif
606
607 ifneq "$(BINDIST)" "YES"
608 BUILD_DIRS += utils/genprimopcode
609 endif
610
611 BUILD_DIRS += driver
612 BUILD_DIRS += driver/ghci
613 BUILD_DIRS += driver/ghc
614 BUILD_DIRS += driver/haddock
615 BUILD_DIRS += libffi
616 BUILD_DIRS += utils/deriveConstants
617 BUILD_DIRS += includes
618 BUILD_DIRS += rts
619
620 ifneq "$(BINDIST)" "YES"
621 BUILD_DIRS += bindisttest
622 BUILD_DIRS += utils/genapply
623 endif
624
625 ifneq "$(CLEANING)" "YES"
626 # These are deliberately in reverse order, so as to ensure that
627 # there is no need to have them in dependency order. That's important
628 # because it's tricky to ensure that they are in dependency order when
629 # cross-compiling, as some packages may only be in PACKAGES_STAGE0
630 # or PACKAGES_STAGE1.
631 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE2))
632 BUILD_DIRS += $(patsubst %, libraries/%, $(PACKAGES_STAGE1))
633 BUILD_DIRS += $(patsubst %, libraries/%, $(filter-out $(PACKAGES_STAGE1),$(PACKAGES_STAGE0)))
634 BUILD_DIRS += $(wildcard libraries/dph)
635 endif
636
637
638 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
639 BUILD_DIRS += libraries/integer-gmp/gmp
640 BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
641 else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
642 BUILD_DIRS += libraries/integer-gmp/gmp
643 BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
644 endif
645
646 BUILD_DIRS += utils/haddock
647 BUILD_DIRS += utils/haddock/doc
648 BUILD_DIRS += compiler
649 BUILD_DIRS += utils/hsc2hs
650 BUILD_DIRS += utils/ghc-pkg
651 BUILD_DIRS += utils/testremove
652 BUILD_DIRS += utils/ghctags
653 BUILD_DIRS += utils/dll-split
654 BUILD_DIRS += utils/ghc-pwd
655 BUILD_DIRS += utils/ghc-cabal
656 BUILD_DIRS += utils/hpc
657 BUILD_DIRS += utils/runghc
658 BUILD_DIRS += ghc
659
660 ifneq "$(BINDIST)" "YES"
661 ifneq "$(CrossCompiling)-$(phase)" "YES-final"
662 BUILD_DIRS += utils/mkUserGuidePart
663 endif
664 endif
665
666 BUILD_DIRS += docs/users_guide
667 BUILD_DIRS += docs/man
668 BUILD_DIRS += utils/count_lines
669 BUILD_DIRS += utils/compare_sizes
670
671 # ----------------------------------------------
672 # Actually include all the sub-ghc.mk's
673
674 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
675
676 # A useful pseudo-target (must be after the include above, because it needs
677 # the value of things like $(libraries/base_dist-install_v_LIB).
678 .PHONY: stage1_libs
679 stage1_libs : $(ALL_STAGE1_LIBS)
680
681 # ----------------------------------------------
682 # Per-package compiler flags
683 #
684 # If you want to add per-package compiler flags, this
685 # is the place to do it. Do it like this for package <pkg>
686 #
687 # libraries/<pkg>_dist-boot_HC_OPTS += -Wwarn
688 # libraries/<pkg>_dist-install_HC_OPTS += -Wwarn
689
690 # Add $(GhcLibHcOpts) to all package builds
691 $(foreach pkg,$(PACKAGES_STAGE1) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
692
693 # Add $(GhcBootLibHcOpts) to all stage0 package builds
694 $(foreach pkg,$(PACKAGES_STAGE0),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
695
696 # -----------------------------------------------------------------------------
697 # Bootstrapping libraries
698
699 # We need to build a few libraries with the installed GHC, since GHC itself
700 # and some of the tools depend on them:
701
702 ifneq "$(BINDIST)" "YES"
703
704 ifneq "$(BOOTSTRAPPING_CONF)" ""
705 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
706 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
707 endif
708 endif
709
710 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
711
712 # register the boot packages in strict sequence, because running
713 # multiple ghc-pkgs in parallel doesn't work (registrations may get
714 # lost).
715 fixed_pkg_prev=
716 $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
717 utils/ghc-pkg/dist/package-data.mk: $(fixed_pkg_prev)
718 compiler/stage1/package-data.mk: $(fixed_pkg_prev)
719 endif
720
721 ifneq "$(BINDIST)" "YES"
722 # Make sure we have all the GHCi libs by the time we've built
723 # ghc-stage2. DPH includes a bit of Template Haskell which needs the
724 # GHCi libs, and we don't have a better way to express that dependency.
725 #
726 GHCI_LIBS = $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_GHCI_LIB)) \
727 $(compiler_stage2_GHCI_LIB)
728
729 ifeq "$(UseArchivesForGhci)" "NO"
730 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(GHCI_LIBS)
731 endif
732
733 ifeq "$(UseArchivesForGhci)" "YES"
734 GHCI_lib_way = v
735 else
736 GHCI_lib_way = GHCI
737 endif
738
739 # Deps for TH uses in libraries
740 $(foreach way, $(GhcLibWays),$(eval \
741 libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.$($(way)_osuf): \
742 $(libraries/primitive_dist-install_$(GHCI_lib_way)_LIB) \
743 ))
744 endif
745
746 # -----------------------------------------------
747 # Haddock-related bits
748
749 # Build the Haddock contents and index
750 ifeq "$(HADDOCK_DOCS)" "YES"
751 libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
752 cd libraries && sh gen_contents_index --intree
753 ifeq "$(phase)" "final"
754 $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
755 endif
756 INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
757 endif
758
759 # -----------------------------------------------------------------------------
760 # Creating a local mingw copy on Windows
761
762 ifeq "$(Windows_Host)" "YES"
763
764 install : install_mingw
765 .PHONY: install_mingw
766 install_mingw : $(INPLACE_MINGW)
767 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
768
769 install : install_perl
770 .PHONY: install_perl
771 install_perl : $(INPLACE_PERL)
772 "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
773
774 endif # Windows_Host
775
776 ifneq "$(BINDIST)" "YES"
777 $(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
778 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
779 endif # BINDIST
780
781 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
782 $(PRIMOPS_TXT_STAGE1) $$(genprimopcode_INPLACE) \
783 | $$(dir $$@)/.
784 "$(genprimopcode_INPLACE)" --make-haskell-source < $< > $@
785
786 .PHONY: tags
787 tags: tags_compiler
788
789 .PHONY: TAGS
790 TAGS: TAGS_compiler
791
792 # -----------------------------------------------------------------------------
793 # Installation
794
795 install: install_libs install_packages install_libexecs \
796 install_bins install_topdirs
797 ifeq "$(HADDOCK_DOCS)" "YES"
798 install: install_docs
799 endif
800
801 define installLibsTo
802 # $1 = libraries to install
803 # $2 = directory to install to
804 $(call INSTALL_DIR,$2)
805 for i in $1; do \
806 case $$i in \
807 *.a) \
808 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
809 $(RANLIB) $2/`basename $$i` ;; \
810 *.dll) \
811 $(call INSTALL_PROGRAM,$(INSTALL_OPTS),$$i,$2) ; \
812 $(STRIP_CMD) $2/`basename $$i` ;; \
813 *.so) \
814 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2) ;; \
815 *.dylib) \
816 $(call INSTALL_SHLIB,$(INSTALL_OPTS),$$i,$2);; \
817 *) \
818 $(call INSTALL_DATA,$(INSTALL_OPTS),$$i,$2); \
819 esac; \
820 done
821 endef
822
823 install_bins: $(INSTALL_BINS)
824 $(call INSTALL_DIR,"$(DESTDIR)$(bindir)")
825 for i in $(INSTALL_BINS); do \
826 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(bindir)") ; \
827 done
828
829 install_libs: $(INSTALL_LIBS)
830 $(call installLibsTo, $(INSTALL_LIBS), "$(DESTDIR)$(ghclibdir)")
831
832 install_libexecs: $(INSTALL_LIBEXECS)
833 ifeq "$(INSTALL_LIBEXECS)" ""
834 @:
835 else
836 $(call INSTALL_DIR,"$(DESTDIR)$(ghclibexecdir)/bin")
837 for i in $(INSTALL_LIBEXECS); do \
838 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(ghclibexecdir)/bin"); \
839 done
840 # We rename ghc-stage2, so that the right program name is used in error
841 # messages etc.
842 "$(MV)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc-stage$(INSTALL_GHC_STAGE)" "$(DESTDIR)$(ghclibexecdir)/bin/ghc"
843 endif
844
845 install_topdirs: $(INSTALL_TOPDIRS)
846 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
847 for i in $(INSTALL_TOPDIRS); do \
848 $(call INSTALL_PROGRAM,$(INSTALL_BIN_OPTS),$$i,"$(DESTDIR)$(topdir)"); \
849 done
850
851 install_docs: $(INSTALL_DOCS)
852 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)")
853 ifneq "$(INSTALL_DOCS)" ""
854 for i in $(INSTALL_DOCS); do \
855 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)"); \
856 done
857 endif
858 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html")
859 $(call INSTALL_DOC,$(INSTALL_OPTS),docs/index.html,"$(DESTDIR)$(docdir)/html")
860 ifneq "$(INSTALL_LIBRARY_DOCS)" ""
861 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/libraries")
862 for i in $(INSTALL_LIBRARY_DOCS); do \
863 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i,"$(DESTDIR)$(docdir)/html/libraries/"); \
864 done
865 $(call INSTALL_DATA,$(INSTALL_OPTS),libraries/prologue.txt,"$(DESTDIR)$(docdir)/html/libraries/")
866 $(call INSTALL_SCRIPT,$(INSTALL_OPTS),libraries/gen_contents_index,"$(DESTDIR)$(docdir)/html/libraries/")
867 endif
868 ifneq "$(INSTALL_HTML_DOC_DIRS)" ""
869 for i in $(INSTALL_HTML_DOC_DIRS); do \
870 $(call INSTALL_DIR,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
871 $(call INSTALL_DOC,$(INSTALL_OPTS),$$i/*,"$(DESTDIR)$(docdir)/html/`basename $$i`"); \
872 done
873 endif
874
875 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
876
877 # Install packages in the right order, so that ghc-pkg doesn't complain.
878 # Also, install ghc-pkg first.
879 ifeq "$(Windows_Host)" "NO"
880 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
881 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
882 else
883 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
884 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
885 endif
886
887 # Set the INSTALL_DISTDIR_p for each package; compiler is special
888 $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
889 $(eval INSTALL_DISTDIR_$p = dist-install))
890 INSTALL_DISTDIR_compiler = stage2
891
892 # Now we can do the installation
893 install_packages: install_libexecs
894 install_packages: rts/package.conf.install
895 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)")
896 $(call removeTrees,"$(INSTALLED_PACKAGE_CONF)")
897 $(call INSTALL_DIR,"$(INSTALLED_PACKAGE_CONF)")
898 $(call INSTALL_DIR,"$(DESTDIR)$(topdir)/rts-1.0")
899 $(call installLibsTo, $(RTS_INSTALL_LIBS), "$(DESTDIR)$(topdir)/rts-1.0")
900 $(foreach p, $(INSTALL_DYNLIBS), \
901 $(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)"))
902 $(foreach p, $(INSTALL_PACKAGES), \
903 $(call make-command, \
904 "$(ghc-cabal_INPLACE)" copy \
905 "$(STRIP_CMD)" \
906 $p $(INSTALL_DISTDIR_$p) \
907 '$(DESTDIR)' \
908 '$(prefix)' \
909 '$(ghclibdir)' \
910 '$(docdir)/html/libraries'))
911 "$(INSTALLED_GHC_PKG_REAL)" --force --global-package-db "$(INSTALLED_PACKAGE_CONF)" update rts/package.conf.install
912 $(foreach p, $(INSTALL_PACKAGES), \
913 $(call make-command, \
914 "$(ghc-cabal_INPLACE)" register \
915 "$(INSTALLED_GHC_REAL)" \
916 "$(INSTALLED_GHC_PKG_REAL)" \
917 "$(DESTDIR)$(topdir)" \
918 $p $(INSTALL_DISTDIR_$p) \
919 '$(DESTDIR)' \
920 '$(prefix)' \
921 '$(ghclibdir)' \
922 '$(docdir)/html/libraries' \
923 $(RelocatableBuild)))
924 # when we install the packages above, ghc-pkg obeys umask when creating
925 # the package.conf files, but for everything else we specify the
926 # permissions. We therefore now fix the permissions of package.cache.
927 # This means "sudo make install" does the right thing even if it runs
928 # with an 077 umask.
929 for f in '$(INSTALLED_PACKAGE_CONF)'/*; do $(CREATE_DATA) "$$f"; done
930
931 # -----------------------------------------------------------------------------
932 # Binary distributions
933
934 ifneq "$(CLEANING)" "YES"
935 # This rule seems to hold some files open on Windows which prevents
936 # cleaning, perhaps due to the $(wildcard).
937
938 $(eval $(call bindist,.,\
939 LICENSE \
940 README \
941 INSTALL \
942 configure config.sub config.guess install-sh \
943 settings.in \
944 packages \
945 Makefile \
946 mk/config.mk.in \
947 $(INPLACE_BIN)/mkdirhier \
948 utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
949 utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
950 $(BINDIST_WRAPPERS) \
951 $(BINDIST_PERL_SOURCES) \
952 $(BINDIST_LIBS) \
953 $(BINDIST_HI) \
954 $(BINDIST_EXTRAS) \
955 $(includes_H_FILES) \
956 $(includes_DERIVEDCONSTANTS) \
957 $(includes_GHCCONSTANTS) \
958 $(libffi_HEADERS) \
959 $(INSTALL_LIBEXECS) \
960 $(INSTALL_LIBEXEC_SCRIPTS) \
961 $(INSTALL_TOPDIRS) \
962 $(INSTALL_BINS) \
963 $(INSTALL_MANPAGES) \
964 $(INSTALL_DOCS) \
965 $(INSTALL_LIBRARY_DOCS) \
966 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
967 docs/index.html \
968 compiler/stage2/doc \
969 $(wildcard libraries/*/dist-install/doc/) \
970 $(wildcard libraries/*/*/dist-install/doc/) \
971 $(filter-out settings,$(INSTALL_LIBS)) \
972 $(RTS_INSTALL_LIBS) \
973 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
974 mk/project.mk \
975 mk/install.mk.in \
976 bindist.mk \
977 libraries/gen_contents_index \
978 libraries/prologue.txt \
979 $(wildcard libraries/dph/LICENSE \
980 libraries/dph/ghc-packages \
981 libraries/dph/ghc-packages2 \
982 libraries/dph/ghc-stage2-package) \
983 ))
984 endif
985 # mk/project.mk gets an absolute path, so we manually include it in
986 # the bindist with a relative path
987
988 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
989
990 unix-binary-dist-prep:
991 $(call removeTrees,bindistprep/)
992 "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
993 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
994 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
995 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
996 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
997 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
998 echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
999 echo "override ghc-cabal_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
1000 echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
1001 cd $(BIN_DIST_PREP_DIR) && autoreconf
1002 $(call removeFiles,$(BIN_DIST_PREP_TAR))
1003 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
1004 # tree then we want to include the real file, not a symlink to it
1005 cd bindistprep && "$(TAR_CMD)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1006
1007 windows-binary-dist-prep:
1008 $(call removeTrees,bindistprep/)
1009 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
1010 cd bindistprep && "$(TAR_CMD)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
1011
1012 # tryTimes tries to run its third argument multiple times, until it
1013 # succeeds. Don't call it directly; call try10Times instead.
1014 # The first and second argument to tryTimes are lists of values.
1015 # The length of the first argument is the number of times we have
1016 # already tried. The length of the second argument is the number more
1017 # times we will try.
1018 tryTimes = $(if $2, \
1019 { echo 'Try $(words x $1): $3' ; $3 ; } || \
1020 $(call tryTimes,x $1,$(wordlist 2,$(words $2),$2),$3), \
1021 )
1022
1023 # Try to run the argument 10 times. If all 10 fail, fail.
1024 try10Times = $(call tryTimes,,x x x x x x x x x x,$1) { echo Failed; false; }
1025
1026 .PHONY: publish-binary-dist
1027 publish-binary-dist:
1028 $(call try10Times,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
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 git 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 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 # In phase 1, we'll be building dependency files for most things
1288 # built by the bootstrapping compiler while make is 'include'ing
1289 # makefiles. But in order to build dependency files, we'll need to
1290 # build any automatically generated .hs files, which means that
1291 # we'll need to be able to build any tools that generate .hs files
1292 # etc. But in order to do that, we need to already know the
1293 # dependencies for those tools, so we build their dependency files
1294 # here.
1295 .PHONY: phase_0_builds
1296 # hsc2hs is needed, e.g. to make the .hs files for hpc.
1297 phase_0_builds: $(utils/hsc2hs_dist_depfile_haskell)
1298 phase_0_builds: $(utils/hsc2hs_dist_depfile_c_asm)
1299 # genprimopcode is needed to make the .hs-incl files that are in the
1300 # ghc package.
1301 phase_0_builds: $(utils/genprimopcode_dist_depfile_haskell)
1302 phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
1303 # deriveConstants is used to create header files included in the
1304 # ghc package.
1305 phase_0_builds: $(utils/deriveConstants_dist_depfile_haskell)
1306 phase_0_builds: $(utils/deriveConstants_dist_depfile_c_asm)
1307
1308 .PHONY: phase_1_builds
1309 phase_1_builds: $(PACKAGE_DATA_MKS)
1310