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