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