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