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