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