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