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