Remove a TODO item that's been done
[ghc-hetmet.git] / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # ToDo List.
14 #
15 #   * finish installation
16 #     * create doc index and contents
17 #     * Windows: should we have ghc-pkg-<version>?
18 #     * should we be stripping things?
19 #     * install libgmp.a, gmp.h
20 #   * need to fix Cabal for new Windows layout, see
21 #     Distribution/Simple/GHC.configureToolchain.
22 #   * remove old Makefiles, add new stubs for building in subdirs
23 #     * docs/Makefile
24 #     * docs/docbook-cheat-sheet/Makefile
25 #     * docs/ext-core/Makefile
26 #     * docs/man/Makefile
27 #     * docs/storage-mgmt/Makefile
28 #     * docs/vh/Makefile
29 #     * rts/dotnet/Makefile
30 #     * utils/Makefile
31 #   * optionally install stage3?
32 #   * add Makefiles for the rest of the utils/ programs that aren't built
33 #     by default (need to exclude them from 'make all' too)
34 #
35 # Tickets we can now close, or fix and close:
36 #
37 #   * 1693 make distclean
38 #   * 3173 make install with DESTDIR
39
40 # Possible cleanups:
41 #
42 #   * per-source-file dependencies instead of one .depend file?
43 #   * eliminate undefined variables, and use --warn-undefined-variables?
44 #   * perhaps we should make all the output dirs in the .depend rule, to
45 #     avoid all these mkdirhier calls?
46 #   * put outputs from different ways in different subdirs of distdir/build,
47 #     then we don't have to use -osuf/-hisuf.  We would have to install
48 #     them in different places too, so we'd need ghc-pkg support for packages
49 #     of different ways.
50 #   * make PACKAGES generated by configure or sh boot?
51 #   * we should use a directory of package.conf files rather than a single
52 #     file for the inplace package database, so that we can express
53 #     dependencies more accurately.  Otherwise it's possible to get into
54 #     a state where the package database is out of date, and the build
55 #     system doesn't know.
56
57 # Approximate build order.
58 #
59 # The actual build order is defined by dependencies, and the phase
60 # ordering used to ensure correct ordering of makefile-generation; see
61 #    http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
62 #
63 #     * With bootstrapping compiler:
64 #           o Build utils/ghc-cabal
65 #           o Build utils/ghc-pkg
66 #           o Build utils/hsc2hs
67 #     * For each package:
68 #           o configure, generate package-data.mk and inplace-pkg-info
69 #           o register each package into inplace/lib/package.conf
70 #     * build libffi
71 #     * With bootstrapping compiler:
72 #           o Build libraries/{filepath,hpc,extensible-exceptions,Cabal}
73 #           o Build compiler (stage 1)
74 #     * With stage 1:
75 #           o Build libraries/*
76 #           o Build rts
77 #           o Build utils/* (except haddock)
78 #           o Build compiler (stage 2)
79 #     * With stage 2:
80 #           o Build utils/haddock
81 #           o Build compiler (stage 3) (optional)
82 #     * With haddock:
83 #           o libraries/*
84 #           o compiler
85
86 .PHONY: default all haddock
87
88 default : all
89
90 # Just bring makefiles up to date:
91 .PHONY: just-makefiles
92 just-makefiles:
93         @:
94
95 # -----------------------------------------------------------------------------
96 # Misc GNU make utils
97
98 nothing=
99 space=$(nothing) $(nothing)
100 comma=,
101
102 # Cancel all suffix rules.  Ideally we'd like to have 'make -r' turned on
103 # by default, because that disables all the implicit rules, but there doesn't
104 # seem to be a good way to do that.  This turns off all the old-style suffix
105 # rules, which does half the job and speeds up make quite a bit:
106 .SUFFIXES:
107
108 # -----------------------------------------------------------------------------
109 #                       Makefile debugging
110 # to see the effective value used for a Makefile variable, do
111 #  make show VALUE=MY_VALUE
112 #
113
114 show:
115         @echo '$(VALUE)="$($(VALUE))"'
116
117 # -----------------------------------------------------------------------------
118 # Include subsidiary build-system bits
119
120 include mk/tree.mk
121
122 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
123 include mk/config.mk
124 ifeq "$(ProjectVersion)" ""
125 $(error Please run ./configure first)
126 endif
127 endif
128
129 # (Optional) build-specific configuration
130 include mk/custom-settings.mk
131
132 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
133 ifeq "$(GhcLibWays)" ""
134 $(error $$(GhcLibWays) is empty, it must contain at least one way)
135 endif
136 endif
137
138 # -----------------------------------------------------------------------------
139 # Macros for standard targets
140
141 include rules/all-target.mk
142 include rules/clean-target.mk
143
144 # -----------------------------------------------------------------------------
145 # The inplace tree
146
147 $(eval $(call clean-target,inplace,,inplace))
148
149 # -----------------------------------------------------------------------------
150 # Whether to build dependencies or not
151
152 # When we're just doing 'make clean' or 'make show', then we don't need
153 # to build dependencies.
154
155 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
156 NO_INCLUDE_DEPS = YES
157 NO_INCLUDE_PKGDATA = YES
158 endif
159 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
160 NO_INCLUDE_DEPS = YES
161 NO_INCLUDE_PKGDATA = YES
162 endif
163 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
164 NO_INCLUDE_DEPS = YES
165 # We want package-data.mk for show
166 endif
167
168 # We don't haddock base3-compat, as it has the same package name as base
169 libraries/base3-compat_dist-install_DO_HADDOCK = NO
170
171 # We don't haddock the bootstrapping libraries
172 libraries/hpc_dist-boot_DO_HADDOCK = NO
173 libraries/Cabal_dist-boot_DO_HADDOCK = NO
174 libraries/extensible-exceptions_dist-boot_DO_HADDOCK = NO
175 libraries/filepath_dist-boot_DO_HADDOCK = NO
176
177 # -----------------------------------------------------------------------------
178 # Ways
179
180 include rules/way-prelims.mk
181
182 $(foreach way,$(ALL_WAYS),\
183   $(eval $(call way-prelims,$(way))))
184
185 # -----------------------------------------------------------------------------
186 # Compilation Flags
187
188 include rules/distdir-opts.mk
189 include rules/distdir-way-opts.mk
190
191 # -----------------------------------------------------------------------------
192 # Finding source files and object files
193
194 include rules/hs-sources.mk
195 include rules/c-sources.mk
196 include rules/includes-sources.mk
197 include rules/hs-objs.mk
198 include rules/c-objs.mk
199 include rules/cmm-objs.mk
200
201 # -----------------------------------------------------------------------------
202 # Suffix rules
203
204 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
205 # so we don't make any when cleaning.
206 ifneq "$(CLEANING)" "YES"
207
208 include rules/hs-suffix-rules-srcdir.mk
209 include rules/hs-suffix-rules.mk
210
211 # -----------------------------------------------------------------------------
212 # Suffix rules for .hi files
213
214 include rules/hi-rule.mk
215
216 $(foreach way,$(ALL_WAYS),\
217   $(eval $(call hi-rule,$(way))))
218
219 #-----------------------------------------------------------------------------
220 # C-related suffix rules
221
222 include rules/c-suffix-rules.mk
223
224 #-----------------------------------------------------------------------------
225 # CMM-related suffix rules
226
227 include rules/cmm-suffix-rules.mk
228
229 endif
230
231 # -----------------------------------------------------------------------------
232 # Building package-data.mk files from .cabal files
233
234 include rules/package-config.mk
235
236 # -----------------------------------------------------------------------------
237 # Building dependencies
238
239 include rules/build-dependencies.mk
240
241 # -----------------------------------------------------------------------------
242 # Build package-data.mk files
243
244 include rules/build-package-data.mk
245
246 # -----------------------------------------------------------------------------
247 # Build and install a program
248
249 include rules/build-prog.mk
250 include rules/shell-wrapper.mk
251
252 # -----------------------------------------------------------------------------
253 # Build a perl script
254
255 include rules/build-perl.mk
256
257 # -----------------------------------------------------------------------------
258 # Build a package
259
260 include rules/build-package.mk
261 include rules/build-package-way.mk
262 include rules/haddock.mk
263
264 # -----------------------------------------------------------------------------
265 # Registering hand-written package descriptions (used in libffi and rts)
266
267 include rules/manual-package-config.mk
268
269 # -----------------------------------------------------------------------------
270 # Docs
271
272 include rules/docbook.mk
273
274 # -----------------------------------------------------------------------------
275 # Making bindists
276
277 include rules/bindist.mk
278
279 # -----------------------------------------------------------------------------
280 # Building libraries
281
282 define addPackage # args: $1 = package, $2 = condition
283     ifneq "$2" ""
284         ifeq "$$(CLEANING)" "YES"
285             PACKAGES += $1
286         else
287             ifeq $2
288                 PACKAGES += $1
289             endif
290         endif
291     else
292         PACKAGES += $1
293     endif
294 endef
295
296 $(eval $(call addPackage,ghc-prim))
297 ifeq "$(CLEANING)" "YES"
298 $(eval $(call addPackage,integer-gmp))
299 $(eval $(call addPackage,integer-simple))
300 else
301 $(eval $(call addPackage,$(INTEGER_LIBRARY)))
302 endif
303 $(eval $(call addPackage,base))
304 $(eval $(call addPackage,filepath))
305 $(eval $(call addPackage,array))
306 $(eval $(call addPackage,bytestring))
307 $(eval $(call addPackage,containers))
308
309 $(eval $(call addPackage,Win32,($$(Windows),YES)))
310 $(eval $(call addPackage,unix,($$(Windows),NO)))
311
312 $(eval $(call addPackage,old-locale))
313 $(eval $(call addPackage,old-time))
314 $(eval $(call addPackage,time))
315 $(eval $(call addPackage,directory))
316 $(eval $(call addPackage,process))
317 $(eval $(call addPackage,random))
318 $(eval $(call addPackage,extensible-exceptions))
319 $(eval $(call addPackage,haskell98))
320 $(eval $(call addPackage,hpc))
321 $(eval $(call addPackage,pretty))
322 $(eval $(call addPackage,syb))
323 $(eval $(call addPackage,template-haskell))
324 $(eval $(call addPackage,base3-compat))
325 $(eval $(call addPackage,Cabal))
326 $(eval $(call addPackage,mtl))
327 $(eval $(call addPackage,utf8-string))
328
329 $(eval $(call addPackage,terminfo,($$(Windows),NO)))
330
331 $(eval $(call addPackage,haskeline))
332
333 ifneq "$(BootingFromHc)" "YES"
334 PACKAGES_STAGE2 += \
335         dph/dph-base \
336         dph/dph-prim-interface \
337         dph/dph-prim-seq \
338         dph/dph-prim-par \
339         dph/dph-seq \
340         dph/dph-par
341 endif
342
343 BOOT_PKGS = Cabal hpc extensible-exceptions
344
345 # The actual .a and .so/.dll files: needed for dependencies.
346 ALL_STAGE1_LIBS  = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
347 ifeq "$(BuildSharedLibs)" "YES"
348 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB))
349 endif
350 BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
351
352 OTHER_LIBS = libffi/libHSffi$(v_libsuf) libffi/HSffi.o
353 ifeq "$(BuildSharedLibs)" "YES"
354 OTHER_LIBS  += libffi/libHSffi$(dyn_libsuf)
355 endif
356
357 # We cannot run ghc-cabal to configure a package until we have
358 # configured and registered all of its dependencies.  So the following
359 # hack forces all the configure steps to happen in exactly the order
360 # given in the PACKAGES variable above.  Ideally we should use the
361 # correct dependencies here to allow more parallelism, but we don't
362 # know the dependencies until we've generated the pacakge-data.mk
363 # files.
364 define fixed_pkg_dep
365 libraries/$1/$2/package-data.mk : $$(GHC_PKG_INPLACE) $$(if $$(fixed_pkg_prev),libraries/$$(fixed_pkg_prev)/$2/package-data.mk)
366 fixed_pkg_prev:=$1
367 endef
368
369 ifneq "$(BINDIST)" "YES"
370 fixed_pkg_prev=
371 $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
372
373 # We assume that the stage2 compiler depends on all the libraries, so
374 # they all get added to the package database before we try to configure
375 # it
376 compiler/stage2/package-data.mk: $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),libraries/$(pkg)/dist-install/package-data.mk)
377 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
378 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
379 # haddock depends on ghc and some libraries, but depending on GHC's
380 # package-data.mk is sufficient, as that in turn depends on all the
381 # libraries
382 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
383
384 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
385
386 # add the final two package.conf dependencies: ghc-prim depends on RTS,
387 # and RTS depends on libffi.
388 libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
389 rts/package.conf.inplace : libffi/package.conf.inplace
390 endif
391
392 # -----------------------------------------------------------------------------
393 # Special magic for the ghc-prim package
394
395 # We want the ghc-prim package to include the GHC.Prim module when it
396 # is registered, but not when it is built, because GHC.Prim is not a
397 # real source module, it is built-in to GHC.  The old build system did
398 # this using Setup.hs, but we can't do that here, so we have a flag to
399 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
400 # remains compatible with the old build system for the time being).
401 # GHC.Prim module in the ghc-prim package with a flag:
402 #
403 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
404
405 # And then we strip it out again before building the package:
406 define libraries/ghc-prim_PACKAGE_MAGIC
407 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
408 endef
409
410 PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
411
412 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
413         "$(MKDIRHIER)" $(dir $@)
414         "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
415
416 libraries/ghc-prim/GHC/Prim.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
417         "$(GENPRIMOP_INPLACE)" --make-haskell-source <$(PRIMOPS_TXT) >$@
418
419
420 # -----------------------------------------------------------------------------
421 # Include build instructions from all subdirs
422
423 # For the rationale behind the build phases, see
424 #   http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
425
426 # Setting foo_dist_DISABLE=YES means "in directory foo, for build
427 # "dist", just read the package-data.mk file, do not build anything".
428
429 # We carefully engineer things so that we can build the
430 # package-data.mk files early on: they depend only on a few tools also
431 # built early.  Having got the package-data.mk files built, we can
432 # restart make with up-to-date information about all the packages
433 # (this is phase 0).  The remaining problem is the .depend files:
434 #
435 #   - .depend files in libraries need the stage 1 compiler to build
436 #   - ghc/stage1/.depend needs compiler/stage1 built
437 #   - compiler/stage1/.depend needs the bootstrap libs built
438 #
439 # GHC 6.11+ can build a .depend file without having built the
440 # dependencies of the package, but we can't rely on the bootstrapping
441 # compiler being able to do this, which is why we have to separate the
442 # three phases above.
443
444 # So this is the final ordering:
445
446 # Phase 0 : all package-data.mk files
447 #           (requires ghc-cabal, ghc-pkg, mkdirhier, dummy-ghc etc.)
448 # Phase 1 : .depend files for bootstrap libs
449 #           (requires hsc2hs)
450 # Phase 2 : compiler/stage1/.depend
451 #           (requires bootstrap libs and genprimopcode)
452 # Phase 3 : ghc/stage1/.depend
453 #           (requires compiler/stage1)
454 #
455 # The rest : libraries/*/dist-install, compiler/stage2, ghc/stage2
456
457 BUILD_DIRS =
458
459 ifneq "$(BINDIST)" "YES"
460 BUILD_DIRS += \
461    $(GHC_MKDEPENDC_DIR) \
462    $(GHC_MKDIRHIER_DIR)
463 endif
464
465 BUILD_DIRS += \
466    docs/users_guide \
467    libraries/Cabal/doc \
468    $(GHC_UNLIT_DIR) \
469    $(GHC_HP2PS_DIR)
470
471 ifneq "$(GhcUnregisterised)" "YES"
472 BUILD_DIRS += \
473    $(GHC_MANGLER_DIR) \
474    $(GHC_SPLIT_DIR)
475 endif
476
477 ifneq "$(BINDIST)" "YES"
478 BUILD_DIRS += \
479    $(GHC_GENPRIMOP_DIR)
480 endif
481
482 BUILD_DIRS += \
483    driver \
484    driver/ghci \
485    driver/ghc \
486    libffi \
487    includes \
488    rts
489
490 ifneq "$(BINDIST)" "YES"
491 BUILD_DIRS += \
492    $(GHC_CABAL_DIR) \
493    $(GHC_GENAPPLY_DIR)
494 endif
495
496 BUILD_DIRS += \
497    utils/haddock \
498    utils/haddock/doc
499
500 ifneq "$(CLEANING)" "YES"
501 BUILD_DIRS += \
502    $(patsubst %, libraries/%, $(PACKAGES) $(PACKAGES_STAGE2))
503 ifneq "$(BootingFromHc)" "YES"
504 BUILD_DIRS += \
505    libraries/dph
506 endif
507 endif
508
509 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
510 BUILD_DIRS += libraries/integer-gmp/gmp
511 endif
512
513 BUILD_DIRS += \
514    compiler \
515    $(GHC_HSC2HS_DIR) \
516    $(GHC_PKG_DIR) \
517    utils/hpc \
518    utils/runghc \
519    ghc
520 ifeq "$(Windows)" "YES"
521 BUILD_DIRS += \
522    $(GHC_TOUCHY_DIR)
523 endif
524
525 # XXX libraries/% must come before any programs built with stage1, see
526 # Note [lib-depends].
527
528 ifeq "$(phase)" "0"
529 $(foreach lib,$(BOOT_PKGS),$(eval \
530   libraries/$(lib)_dist-boot_DISABLE = YES))
531 endif
532
533 ifneq "$(findstring $(phase),0 1)" ""
534 # We can build deps for compiler/stage1 in phase 2
535 compiler_stage1_DISABLE = YES
536 endif
537
538 ifneq "$(findstring $(phase),0 1 2)" ""
539 ghc_stage1_DISABLE = YES
540 endif
541
542 ifneq "$(CLEANING)" "YES"
543 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
544 libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple
545 else
546     ifeq "$(INTEGER_LIBRARY)" "integer-simple"
547         libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
548     else
549 $(error Unknown integer library: $(INTEGER_LIBRARY))
550     endif
551 endif
552 endif
553
554 ifneq "$(findstring $(phase),0 1 2 3)" ""
555 # In phases 0-3, we disable stage2-3, the full libraries and haddock
556 utils/haddock_dist_DISABLE = YES
557 utils/runghc_dist_DISABLE = YES
558 utils/hpc_dist_DISABLE = YES
559 utils/hsc2hs_dist-install_DISABLE = YES
560 utils/ghc-pkg_dist-install_DISABLE = YES
561 compiler_stage2_DISABLE = YES
562 compiler_stage3_DISABLE = YES
563 ghc_stage2_DISABLE = YES
564 ghc_stage3_DISABLE = YES
565 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),$(eval \
566   libraries/$(lib)_dist-install_DISABLE = YES))
567 endif
568
569 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
570
571 # We need -fno-warn-deprecated-flags to avoid failure with -Werror
572 GhcLibHcOpts += -fno-warn-deprecated-flags
573 ifeq "$(ghc_ge_609)" "YES"
574 GhcBootLibHcOpts += -fno-warn-deprecated-flags
575 endif
576
577 # Add $(GhcLibHcOpts) to all library builds
578 $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
579
580 # XXX Hack; remove this
581 $(foreach pkg,$(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += -Wwarn))
582
583 # XXX we configure packages with the bootstrapping compiler (for
584 # dependency reasons, see the phase ordering), which doesn't
585 # necessarily support all the extensions we need, and Cabal filters
586 # out the ones it thinks aren't supported.
587 libraries/base3-compat_dist-install_HC_OPTS += -XPackageImports
588
589 # A useful pseudo-target
590 .PHONY: stage1_libs
591 stage1_libs : $(ALL_STAGE1_LIBS)
592
593 # -----------------------------------------------------------------------------
594 # Bootstrapping libraries
595
596 # We need to build a few libraries with the installed GHC, since GHC itself
597 # and some of the tools depend on them:
598
599 ifneq "$(BINDIST)" "YES"
600
601 ifneq "$(BOOTSTRAPPING_CONF)" ""
602 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
603 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
604 endif
605 endif
606
607 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
608
609 # These three libraries do not depend on each other, so we can build
610 # them straight off:
611
612 $(eval $(call build-package,libraries/hpc,dist-boot,0))
613 $(eval $(call build-package,libraries/extensible-exceptions,dist-boot,0))
614 $(eval $(call build-package,libraries/Cabal,dist-boot,0))
615
616 # register the boot packages in strict sequence, because running
617 # multiple ghc-pkgs in parallel doesn't work (registrations may get
618 # lost).
619 fixed_pkg_prev=
620 $(foreach pkg,$(BOOT_PKGS),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
621
622 compiler/stage1/package-data.mk : \
623     libraries/Cabal/dist-boot/package-data.mk \
624     libraries/hpc/dist-boot/package-data.mk \
625     libraries/extensible-exceptions/dist-boot/package-data.mk
626
627 # These are necessary because the bootstrapping compiler may not know
628 # about cross-package dependencies:
629 $(compiler_stage1_depfile) : $(BOOT_LIBS)
630 $(ghc_stage1_depfile) : $(compiler_stage1_v_LIB)
631
632 $(foreach pkg,$(BOOT_PKGS),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
633
634 endif
635
636 # -----------------------------------------------------------------------------
637 # Creating a local mingw copy on Windows
638
639 ifeq "$(Windows)" "YES"
640
641 # directories don't work well as dependencies, hence a stamp file
642 $(INPLACE)/stamp-mingw : $(MKDIRHIER)
643         $(MKDIRHIER) $(INPLACE_MINGW)/bin
644         GCC=`type -p $(WhatGccIsCalled)`; \
645         GccDir=`dirname $$GCC`; \
646         "$(CP)" -p $$GccDir/{gcc.exe,ar.exe,as.exe,dlltool.exe,dllwrap.exe,windres.exe} $(INPLACE_MINGW)/bin; \
647         "$(CP)" -Rp $$GccDir/../include $(INPLACE_MINGW); \
648         "$(CP)" -Rp $$GccDir/../lib     $(INPLACE_MINGW); \
649         "$(CP)" -Rp $$GccDir/../libexec $(INPLACE_MINGW); \
650         "$(CP)" -Rp $$GccDir/../mingw32 $(INPLACE_MINGW)
651         touch $(INPLACE)/stamp-mingw
652
653 install : install_mingw
654 .PHONY: install_mingw
655 install_mingw : $(INPLACE_MINGW)
656         "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
657
658 $(INPLACE_LIB)/perl.exe $(INPLACE_LIB)/perl56.dll :
659         "$(CP)" $(GhcDir)../{perl.exe,perl56.dll} $(INPLACE_LIB)
660
661 endif # Windows
662
663 libraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock: \
664     libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs \
665     libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs
666
667 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
668                             $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
669         "$(MKDIRHIER)" $(dir $@)
670         "$(GENPRIMOP_INPLACE)" --make-haskell-source < $< > $@
671
672 libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs: \
673                             $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
674         "$(MKDIRHIER)" $(dir $@)
675         "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers < $< > $@
676
677 # -----------------------------------------------------------------------------
678 # Installation
679
680 install: install_packages install_libs install_libexecs install_headers \
681          install_libexec_scripts install_bins install_docs
682
683 install_bins: $(INSTALL_BINS)
684         $(INSTALL_DIR) $(DESTDIR)$(bindir)
685         for i in $(INSTALL_BINS); do \
686                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(bindir) ;  \
687                 if test "$(darwin_TARGET_OS)" = "1"; then \
688                    sh mk/fix_install_names.sh $(libdir) $(DESTDIR)$(bindir)/$$i ; \
689                 fi ; \
690         done
691
692 install_libs: $(INSTALL_LIBS)
693         $(INSTALL_DIR) $(DESTDIR)$(libdir)
694         for i in $(INSTALL_LIBS); do \
695                 case $$i in \
696                   *.a) \
697                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
698                     $(RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
699                   *.dll) \
700                     $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
701                   *.so) \
702                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
703                   *.dylib) \
704                     $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
705                     install_name_tool -id $(DESTDIR)$(libdir)/`basename $$i` $(DESTDIR)$(libdir)/`basename $$i` ;; \
706                   *) \
707                     $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
708                 esac; \
709         done
710
711 install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
712         "$(MKDIRHIER)" $(DESTDIR)$(libexecdir)
713         for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
714                 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libexecdir); \
715         done
716
717 install_libexecs:  $(INSTALL_LIBEXECS)
718         "$(MKDIRHIER)" $(DESTDIR)$(libexecdir)
719         for i in $(INSTALL_LIBEXECS); do \
720                 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(libexecdir); \
721         done
722
723 install_headers: $(INSTALL_HEADERS)
724         $(INSTALL_DIR) $(DESTDIR)$(headerdir)
725         for i in $(INSTALL_HEADERS); do \
726                 $(INSTALL_HEADER) $(INSTALL_OPTS) $$i $(DESTDIR)$(headerdir); \
727         done
728
729 install_docs: $(INSTALL_HEADERS)
730         $(INSTALL_DIR) $(DESTDIR)$(docdir)
731         for i in $(INSTALL_DOCS); do \
732                 $(INSTALL_DOC) $(INSTALL_OPTS) $$i $(DESTDIR)$(docdir); \
733         done
734         $(INSTALL_DIR) $(INSTALL_OPTS) $(DESTDIR)$(docdir)/html; \
735         for i in $(INSTALL_HTML_DOC_DIRS); do \
736                 $(INSTALL_DIR) $(INSTALL_OPTS) $(DESTDIR)$(docdir)/html/`basename $$i`; \
737                 $(INSTALL_DOC) $(INSTALL_OPTS) $$i/* $(DESTDIR)$(docdir)/html/`basename $$i`; \
738         done
739
740 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(libdir)/package.conf
741
742 # Install packages in the right order, so that ghc-pkg doesn't complain.
743 # Also, install ghc-pkg first.
744 ifeq "$(Windows)" "NO"
745 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(libexecdir)/ghc-pkg
746 else
747 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
748 endif
749
750 install_packages: install_libexecs
751 install_packages: libffi/package.conf.install rts/package.conf.install
752         "$(MKDIRHIER)" $(DESTDIR)$(libdir)
753         echo "[]" > $(INSTALLED_PACKAGE_CONF)
754         "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf $(INSTALLED_PACKAGE_CONF) update libffi/package.conf.install
755         "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf $(INSTALLED_PACKAGE_CONF) update rts/package.conf.install
756         $(foreach p, $(PACKAGES) $(PACKAGES_STAGE2),\
757             "$(GHC_CABAL_INPLACE)" install \
758                  $(INSTALLED_GHC_PKG_REAL) \
759                  $(INSTALLED_PACKAGE_CONF) \
760                  libraries/$p dist-install \
761                  '$(DESTDIR)' '$(prefix)' '$(libdir)' '$(docdir)/libraries' &&) true
762         "$(GHC_CABAL_INPLACE)" install \
763                  $(INSTALLED_GHC_PKG_REAL) \
764                  $(INSTALLED_PACKAGE_CONF) \
765                  compiler stage2 \
766                  '$(DESTDIR)' '$(prefix)' '$(libdir)' '$(docdir)/libraries'
767
768 # -----------------------------------------------------------------------------
769 # Binary distributions
770
771 $(eval $(call bindist,.,\
772     LICENSE \
773     configure config.sub config.guess install-sh \
774     extra-gcc-opts.in \
775     Makefile \
776     mk/config.mk.in \
777     $(INPLACE_BIN)/mkdirhier \
778     $(INPLACE_BIN)/ghc-cabal \
779     utils/ghc-pwd/ghc-pwd \
780         $(BINDIST_WRAPPERS) \
781         $(BINDIST_LIBS) \
782         $(BINDIST_HI) \
783         $(BINDIST_EXTRAS) \
784     $(INSTALL_HEADERS) \
785     $(INSTALL_LIBEXECS) \
786     $(INSTALL_LIBEXEC_SCRIPTS) \
787     $(INSTALL_BINS) \
788     $(INSTALL_DOCS) \
789     $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
790     $(filter-out extra-gcc-opts,$(INSTALL_LIBS)) \
791     $(filter-out %/project.mk,$(filter-out mk/config.mk,$(MAKEFILE_LIST))) \
792         mk/fix_install_names.sh \
793         mk/project.mk \
794         bindist.mk \
795         libraries/dph/LICENSE \
796  ))
797 # mk/project.mk gets an absolute path, so we manually include it in
798 # the bindist with a relative path
799
800 BIN_DIST_MK = $(BIN_DIST_NAME)/bindist.mk
801
802 binary-dist:
803         "$(RM)" $(RM_OPTS) -r $(BIN_DIST_NAME)
804         mkdir $(BIN_DIST_NAME)
805         set -e; for i in LICENSE compiler ghc rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh extra-gcc-opts.in ghc.mk inplace; do ln -s ../$$i $(BIN_DIST_NAME)/; done
806         echo "HADDOCK_DOCS       = $(HADDOCK_DOCS)"       >> $(BIN_DIST_MK)
807         echo "LATEX_DOCS         = $(LATEX_DOCS)"         >> $(BIN_DIST_MK)
808         echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
809         echo "BUILD_DOCBOOK_PS   = $(BUILD_DOCBOOK_PS)"   >> $(BIN_DIST_MK)
810         echo "BUILD_DOCBOOK_PDF  = $(BUILD_DOCBOOK_PDF)"  >> $(BIN_DIST_MK)
811         ln -s ../distrib/configure-bin.ac $(BIN_DIST_NAME)/configure.ac
812         cd $(BIN_DIST_NAME) && autoreconf
813         "$(RM)" $(RM_OPTS) $(BIN_DIST_TAR)
814 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
815 # tree then we want to include the real file, not a symlink to it
816         "$(TAR)" hcf - -T $(BIN_DIST_LIST) | bzip2 -c > $(BIN_DIST_TAR_BZ2)
817
818 windows-binary-dist:
819         "$(RM)" $(RM_OPTS) -r $(BIN_DIST_NAME)
820         $(MAKE) prefix=$(BIN_DIST_DIR) install
821         "$(TAR)" cf - $(BIN_DIST_NAME) | bzip2 -c > $(BIN_DIST_TAR_BZ2)
822
823 windows-installer:
824         "$(ISCC)" /O. /F$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
825
826 nTimes = set -e; for i in `seq 1 $(1)`; do echo Try "$$i: $(2)"; if $(2); then break; fi; done
827
828 .PHONY: publish-binary-dist
829 publish-binary-dist:
830         $(call nTimes,10,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
831 ifeq "$(mingw32_TARGET_OS)" "1"
832         $(call nTimes,10,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
833 endif
834
835 .PHONY: publish-docs
836 publish-docs:
837         $(call nTimes,10,$(PublishCp) -r bindisttest/installed/share/doc/ghc/* $(PublishLocation)/docs)
838
839 # -----------------------------------------------------------------------------
840 # Source distributions
841
842 # Do it like this:
843 #
844 #       $ make
845 #       $ make sdist
846 #
847
848 # A source dist is built from a complete build tree, because we
849 # require some extra files not contained in a darcs checkout: the
850 # output from Happy and Alex, for example.
851 #
852 # The steps performed by 'make dist' are as follows:
853 #   - create a complete link-tree of the current build tree in /tmp
854 #   - run 'make distclean' on that tree
855 #   - remove a bunch of other files that we know shouldn't be in the dist
856 #   - tar up first the extralibs package, then the main source package
857
858 #
859 # Directory in which we're going to build the src dist
860 #
861 SRC_DIST_NAME=ghc-$(ProjectVersion)
862 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
863
864 #
865 # Files to include in source distributions
866 #
867 SRC_DIST_DIRS = mk rules docs distrib bindisttest libffi includes utils docs rts compiler ghc driver libraries
868 SRC_DIST_FILES += \
869         configure.ac config.guess config.sub configure \
870         aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
871         ghc.spec.in ghc.spec extra-gcc-opts.in VERSION \
872         boot boot-pkgs packages ghc.mk
873
874 SRC_DIST_TARBALL = $(SRC_DIST_NAME)-src.tar.bz2
875
876 VERSION :
877         echo $(ProjectVersion) >VERSION
878
879 sdist : VERSION
880
881 # Use:
882 #     $(call sdist_file,compiler,stage2,cmm,CmmLex,x)
883 # to copy the generated file that replaces compiler/cmm/CmmLex.x, where
884 # "stage2" is the dist dir.
885 sdist_file = \
886   if test -f $(TOP)/$1/$2/build/$4.hs; then \
887     "$(CP)" $(TOP)/$1/$2/build/$4.hs $1/$3/ ; \
888     mv $1/$3/$4.$5 $1/$3/$4.$5.source ;\
889   else \
890     echo "does not exist: $1/$2//build/$4.hs"; \
891     exit 1; \
892   fi
893
894 .PHONY: sdist-prep
895 sdist-prep :
896         "$(RM)" $(RM_OPTS) -r $(SRC_DIST_DIR)
897         "$(RM)" $(RM_OPTS) $(SRC_DIST_TARBALL)
898         mkdir $(SRC_DIST_DIR)
899         ( cd $(SRC_DIST_DIR) \
900           && for i in $(SRC_DIST_DIRS); do mkdir $$i; (cd $$i && lndir $(TOP)/$$i ); done \
901           && for i in $(SRC_DIST_FILES); do $(LN_S) $(TOP)/$$i .; done \
902           && $(MAKE) distclean \
903           && if test -f $(TOP)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs; then "$(CP)" $(TOP)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs libraries/haskell-src/Language/Haskell/ ; mv libraries/haskell-src/Language/Haskell/Parser.ly libraries/haskell-src/Language/Haskell/Parser.ly.source ; fi \
904           && $(call sdist_file,compiler,stage2,cmm,CmmLex,x) \
905           && $(call sdist_file,compiler,stage2,cmm,CmmParse,y) \
906           && $(call sdist_file,compiler,stage2,main,ParsePkgConf,y) \
907           && $(call sdist_file,compiler,stage2,parser,HaddockLex,x) \
908           && $(call sdist_file,compiler,stage2,parser,HaddockParse,y) \
909           && $(call sdist_file,compiler,stage2,parser,Lexer,x) \
910           && $(call sdist_file,compiler,stage2,parser,Parser,y.pp) \
911           && $(call sdist_file,compiler,stage2,parser,ParserCore,y) \
912           && $(call sdist_file,utils/hpc,dist,,HpcParser,y) \
913           && $(call sdist_file,utils/genprimopcode,dist,,Lexer,x) \
914           && $(call sdist_file,utils/genprimopcode,dist,,Parser,y) \
915           && "$(RM)" $(RM_OPTS) -r compiler/stage[123] mk/build.mk \
916           && "$(FIND)" $(SRC_DIST_DIRS) \( -name _darcs -o -name SRC -o -name "autom4te*" -o -name "*~" -o -name ".cvsignore" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" -o -name "*-darcs-backup*" \) -print | xargs "$(RM)" $(RM_OPTS) -r \
917         )
918
919 .PHONY: sdist
920 sdist : sdist-prep
921         "$(TAR)" chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(TOP)/$(SRC_DIST_TARBALL)
922
923 sdist-manifest : $(SRC_DIST_TARBALL)
924         tar tjf $(SRC_DIST_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
925
926 # Upload the distribution(s)
927 # Retrying is to work around buggy firewalls that corrupt large file transfers
928 # over SSH.
929 ifneq "$(PublishLocation)" ""
930 publish-sdist :
931         $(call nTimes,10,$(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist)
932 endif
933
934 ifeq "$(GhcUnregisterised)" "YES"
935 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
936 endif
937
938 # -----------------------------------------------------------------------------
939 # Cleaning
940
941 .PHONY: clean
942
943 CLEAN_FILES += utils/ghc-pwd/ghc-pwd
944 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.exe
945 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.hi
946 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.o
947 CLEAN_FILES += libraries/bootstrapping.conf
948
949 clean : clean_files clean_libraries
950
951 .PHONY: clean_files
952 clean_files :
953         "$(RM)" $(RM_OPTS) $(CLEAN_FILES)
954
955 .PHONY: clean_libraries
956 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES) $(PACKAGES_STAGE2))
957 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(BOOT_PKGS))
958
959 clean_libraries:
960         "$(RM)" $(RM_OPTS) -r $(patsubst %, libraries/%/dist, $(PACKAGES) $(PACKAGES_STAGE2))
961         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/*.buildinfo, $(PACKAGES) $(PACKAGES_STAGE2))
962
963 # We have to define a clean target for each library manually, because the
964 # libraries/*/ghc.mk files are not included when we're cleaning.
965 ifeq "$(CLEANING)" "YES"
966 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),\
967   $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
968 endif
969
970 distclean : clean
971         "$(RM)" $(RM_OPTS) config.cache config.status config.log mk/config.h mk/stamp-h
972         "$(RM)" $(RM_OPTS) mk/config.mk mk/are-validating.mk mk/project.mk
973         "$(RM)" $(RM_OPTS) mk/config.mk.old mk/project.mk.old
974         "$(RM)" $(RM_OPTS) extra-gcc-opts docs/users_guide/ug-book.xml
975         "$(RM)" $(RM_OPTS) compiler/ghc.cabal compiler/ghc.cabal.old
976         "$(RM)" $(RM_OPTS) ghc/ghc-bin.cabal
977         "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h
978         "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h
979         "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h
980         "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h
981         "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h
982
983         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.log, $(PACKAGES) $(PACKAGES_STAGE2))
984         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.status, $(PACKAGES) $(PACKAGES_STAGE2))
985         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES) $(PACKAGES_STAGE2))
986         "$(RM)" $(RM_OPTS) -r $(patsubst %, libraries/%/autom4te.cache, $(PACKAGES) $(PACKAGES_STAGE2))
987
988 maintainer-clean : distclean
989         "$(RM)" $(RM_OPTS) configure mk/config.h.in
990         "$(RM)" $(RM_OPTS) -r autom4te.cache libraries/*/autom4te.cache
991         "$(RM)" $(RM_OPTS) ghc.spec
992         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/GNUmakefile, \
993                 $(PACKAGES) $(PACKAGES_STAGE2))
994         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/ghc.mk, $(PACKAGES) $(PACKAGES_STAGE2))
995         "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/configure, \
996                 $(PACKAGES) $(PACKAGES_STAGE2))
997         "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h.in
998         "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h.in
999         "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h.in
1000         "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h.in
1001         "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h.in
1002
1003 .PHONY: all_libraries
1004
1005 .PHONY: bootstrapping-files
1006 bootstrapping-files: $(OTHER_LIBS)
1007 bootstrapping-files: includes/ghcautoconf.h
1008 bootstrapping-files: includes/DerivedConstants.h
1009 bootstrapping-files: includes/GHCConstants.h
1010
1011 .DELETE_ON_ERROR:
1012