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