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