1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
15 # * finish installation
16 # * Windows: should we have ghc-pkg-<version>?
17 # * should we be stripping things?
18 # * install libgmp.a, gmp.h
19 # * need to fix Cabal for new Windows layout, see
20 # Distribution/Simple/GHC.configureToolchain.
21 # * remove old Makefiles, add new stubs for building in subdirs
23 # * docs/docbook-cheat-sheet/Makefile
24 # * docs/ext-core/Makefile
26 # * docs/storage-mgmt/Makefile
28 # * rts/dotnet/Makefile
30 # * optionally install stage3?
31 # * add Makefiles for the rest of the utils/ programs that aren't built
32 # by default (need to exclude them from 'make all' too)
34 # Tickets we can now close, or fix and close:
36 # * 1693 make distclean
40 # * per-source-file dependencies instead of one .depend file?
41 # * eliminate undefined variables, and use --warn-undefined-variables?
42 # * perhaps we should make all the output dirs in the .depend rule, to
43 # avoid all these mkdirhier calls?
44 # * put outputs from different ways in different subdirs of distdir/build,
45 # then we don't have to use -osuf/-hisuf. We would have to install
46 # them in different places too, so we'd need ghc-pkg support for packages
48 # * make PACKAGES generated by configure or sh boot?
49 # * we should use a directory of package.conf files rather than a single
50 # file for the inplace package database, so that we can express
51 # dependencies more accurately. Otherwise it's possible to get into
52 # a state where the package database is out of date, and the build
53 # system doesn't know.
55 # Approximate build order.
57 # The actual build order is defined by dependencies, and the phase
58 # ordering used to ensure correct ordering of makefile-generation; see
59 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
61 # * With bootstrapping compiler:
62 # o Build utils/ghc-cabal
63 # o Build utils/ghc-pkg
64 # o Build utils/hsc2hs
66 # o configure, generate package-data.mk and inplace-pkg-info
67 # o register each package into inplace/lib/package.conf
69 # * With bootstrapping compiler:
70 # o Build libraries/{filepath,hpc,extensible-exceptions,Cabal}
71 # o Build compiler (stage 1)
75 # o Build utils/* (except haddock)
76 # o Build compiler (stage 2)
78 # o Build utils/haddock
79 # o Build compiler (stage 3) (optional)
84 .PHONY: default all haddock
88 # Catch make if it runs away into an infinite loop
89 ifeq "$(MAKE_RESTARTS)" ""
90 else ifeq "$(MAKE_RESTARTS)" "1"
91 else ifeq "$(MAKE_RESTARTS)" "2"
93 $(error Make has restarted itself $(MAKE_RESTARTS) times; is there a makefile bug?)
96 # Just bring makefiles up to date:
97 .PHONY: just-makefiles
101 # -----------------------------------------------------------------------------
102 # Misc GNU make utils
105 space=$(nothing) $(nothing)
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:
114 # -----------------------------------------------------------------------------
116 # to see the effective value used for a Makefile variable, do
117 # make show VALUE=MY_VALUE
121 @echo '$(VALUE)="$($(VALUE))"'
123 # -----------------------------------------------------------------------------
124 # Include subsidiary build-system bits
128 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
130 ifeq "$(ProjectVersion)" ""
131 $(error Please run ./configure first)
137 # (Optional) build-specific configuration
138 include mk/custom-settings.mk
140 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
141 ifeq "$(GhcLibWays)" ""
142 $(error $$(GhcLibWays) is empty, it must contain at least one way)
146 # -----------------------------------------------------------------------------
147 # Macros for standard targets
149 include rules/all-target.mk
150 include rules/clean-target.mk
152 # -----------------------------------------------------------------------------
155 $(eval $(call clean-target,inplace,,inplace))
157 # -----------------------------------------------------------------------------
158 # Whether to build dependencies or not
160 # When we're just doing 'make clean' or 'make show', then we don't need
161 # to build dependencies.
163 ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
164 NO_INCLUDE_DEPS = YES
165 NO_INCLUDE_PKGDATA = YES
167 ifneq "$(findstring bootstrapping-files,$(MAKECMDGOALS))" ""
168 NO_INCLUDE_DEPS = YES
169 NO_INCLUDE_PKGDATA = YES
171 ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
172 NO_INCLUDE_DEPS = YES
173 # We want package-data.mk for show
176 # We don't haddock the bootstrapping libraries
177 libraries/hpc_dist-boot_DO_HADDOCK = NO
178 libraries/Cabal_dist-boot_DO_HADDOCK = NO
179 libraries/extensible-exceptions_dist-boot_DO_HADDOCK = NO
180 libraries/filepath_dist-boot_DO_HADDOCK = NO
181 libraries/binary_dist-boot_DO_HADDOCK = NO
182 libraries/bin-package-db_dist-boot_DO_HADDOCK = NO
184 # -----------------------------------------------------------------------------
187 include rules/way-prelims.mk
189 $(foreach way,$(ALL_WAYS),\
190 $(eval $(call way-prelims,$(way))))
192 # -----------------------------------------------------------------------------
195 include rules/distdir-way-opts.mk
197 # -----------------------------------------------------------------------------
198 # Finding source files and object files
200 include rules/hs-sources.mk
201 include rules/c-sources.mk
202 include rules/includes-sources.mk
203 include rules/hs-objs.mk
204 include rules/c-objs.mk
205 include rules/cmm-objs.mk
207 # -----------------------------------------------------------------------------
210 # Suffix rules cause "make clean" to fail on Windows (trac #3233)
211 # so we don't make any when cleaning.
212 ifneq "$(CLEANING)" "YES"
214 include rules/hs-suffix-rules-srcdir.mk
215 include rules/hs-suffix-rules.mk
217 # -----------------------------------------------------------------------------
218 # Suffix rules for .hi files
220 include rules/hi-rule.mk
222 $(foreach way,$(ALL_WAYS),\
223 $(eval $(call hi-rule,$(way))))
225 #-----------------------------------------------------------------------------
226 # C-related suffix rules
228 include rules/c-suffix-rules.mk
230 #-----------------------------------------------------------------------------
231 # CMM-related suffix rules
233 include rules/cmm-suffix-rules.mk
237 # -----------------------------------------------------------------------------
238 # Building package-data.mk files from .cabal files
240 include rules/package-config.mk
242 # -----------------------------------------------------------------------------
243 # Building dependencies
245 include rules/build-dependencies.mk
247 # -----------------------------------------------------------------------------
248 # Build package-data.mk files
250 include rules/build-package-data.mk
252 # -----------------------------------------------------------------------------
253 # Build and install a program
255 include rules/build-prog.mk
256 include rules/shell-wrapper.mk
258 # -----------------------------------------------------------------------------
259 # Build a perl script
261 include rules/build-perl.mk
263 # -----------------------------------------------------------------------------
266 include rules/build-package.mk
267 include rules/build-package-way.mk
268 include rules/haddock.mk
270 # -----------------------------------------------------------------------------
271 # Registering hand-written package descriptions (used in libffi and rts)
273 include rules/manual-package-config.mk
275 # -----------------------------------------------------------------------------
278 include rules/docbook.mk
280 # -----------------------------------------------------------------------------
283 include rules/bindist.mk
285 # -----------------------------------------------------------------------------
288 define addPackage # args: $1 = package, $2 = condition
290 ifeq "$$(CLEANING)" "YES"
302 $(eval $(call addPackage,ghc-prim))
303 ifeq "$(CLEANING)" "YES"
304 $(eval $(call addPackage,integer-gmp))
305 $(eval $(call addPackage,integer-simple))
307 $(eval $(call addPackage,$(INTEGER_LIBRARY)))
309 $(eval $(call addPackage,base))
310 $(eval $(call addPackage,filepath))
311 $(eval $(call addPackage,array))
312 $(eval $(call addPackage,bytestring))
313 $(eval $(call addPackage,containers))
315 $(eval $(call addPackage,Win32,($$(Windows),YES)))
316 $(eval $(call addPackage,unix,($$(Windows),NO)))
318 $(eval $(call addPackage,old-locale))
319 $(eval $(call addPackage,old-time))
320 $(eval $(call addPackage,time))
321 $(eval $(call addPackage,directory))
322 $(eval $(call addPackage,process))
323 $(eval $(call addPackage,random))
324 $(eval $(call addPackage,extensible-exceptions))
325 $(eval $(call addPackage,haskell98))
326 $(eval $(call addPackage,hpc))
327 $(eval $(call addPackage,pretty))
328 $(eval $(call addPackage,template-haskell))
329 $(eval $(call addPackage,Cabal))
330 $(eval $(call addPackage,binary))
331 $(eval $(call addPackage,bin-package-db))
332 $(eval $(call addPackage,mtl))
333 $(eval $(call addPackage,utf8-string))
335 $(eval $(call addPackage,terminfo,($$(Windows),NO)))
337 $(eval $(call addPackage,haskeline))
339 ifneq "$(BootingFromHc)" "YES"
342 dph/dph-prim-interface \
349 # We assume that the stage0 compiler has a suitable bytestring package,
350 # so we don't have to include it below.
351 BOOT_PKGS = Cabal hpc extensible-exceptions binary bin-package-db
353 # The actual .a and .so/.dll files: needed for dependencies.
354 ALL_STAGE1_LIBS = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
355 ifeq "$(BuildSharedLibs)" "YES"
356 ALL_STAGE1_LIBS += $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_dyn_LIB))
358 BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
360 OTHER_LIBS = libffi/libHSffi$(v_libsuf) libffi/HSffi.o
361 ifeq "$(BuildSharedLibs)" "YES"
362 OTHER_LIBS += libffi/libHSffi$(dyn_libsuf)
365 # We cannot run ghc-cabal to configure a package until we have
366 # configured and registered all of its dependencies. So the following
367 # hack forces all the configure steps to happen in exactly the order
368 # given in the PACKAGES variable above. Ideally we should use the
369 # correct dependencies here to allow more parallelism, but we don't
370 # know the dependencies until we've generated the pacakge-data.mk
373 libraries/$1/$2/package-data.mk : $$(GHC_PKG_INPLACE) $$(if $$(fixed_pkg_prev),libraries/$$(fixed_pkg_prev)/$2/package-data.mk)
377 ifneq "$(BINDIST)" "YES"
379 $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
381 # We assume that the stage2 compiler depends on all the libraries, so
382 # they all get added to the package database before we try to configure
384 compiler/stage2/package-data.mk: $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),libraries/$(pkg)/dist-install/package-data.mk)
385 ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
386 ghc/stage2/package-data.mk: compiler/stage2/package-data.mk
387 # haddock depends on ghc and some libraries, but depending on GHC's
388 # package-data.mk is sufficient, as that in turn depends on all the
390 utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
392 utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
394 # add the final two package.conf dependencies: ghc-prim depends on RTS,
395 # and RTS depends on libffi.
396 libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
397 rts/package.conf.inplace : libffi/package.conf.inplace
400 # -----------------------------------------------------------------------------
401 # Special magic for the ghc-prim package
403 # We want the ghc-prim package to include the GHC.Prim module when it
404 # is registered, but not when it is built, because GHC.Prim is not a
405 # real source module, it is built-in to GHC. The old build system did
406 # this using Setup.hs, but we can't do that here, so we have a flag to
407 # enable GHC.Prim in the .cabal file (so that the ghc-prim package
408 # remains compatible with the old build system for the time being).
409 # GHC.Prim module in the ghc-prim package with a flag:
411 libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
413 # And then we strip it out again before building the package:
414 define libraries/ghc-prim_PACKAGE_MAGIC
415 libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
418 PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
420 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
421 "$(MKDIRHIER)" $(dir $@)
422 "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
424 libraries/ghc-prim/GHC/Prim.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
425 "$(GENPRIMOP_INPLACE)" --make-haskell-source <$(PRIMOPS_TXT) >$@
428 # -----------------------------------------------------------------------------
429 # Include build instructions from all subdirs
431 # For the rationale behind the build phases, see
432 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture/Idiom/PhaseOrdering
434 # Setting foo_dist_DISABLE=YES means "in directory foo, for build
435 # "dist", just read the package-data.mk file, do not build anything".
437 # We carefully engineer things so that we can build the
438 # package-data.mk files early on: they depend only on a few tools also
439 # built early. Having got the package-data.mk files built, we can
440 # restart make with up-to-date information about all the packages
441 # (this is phase 0). The remaining problem is the .depend files:
443 # - .depend files in libraries need the stage 1 compiler to build
444 # - ghc/stage1/.depend needs compiler/stage1 built
445 # - compiler/stage1/.depend needs the bootstrap libs built
447 # GHC 6.11+ can build a .depend file without having built the
448 # dependencies of the package, but we can't rely on the bootstrapping
449 # compiler being able to do this, which is why we have to separate the
450 # three phases above.
452 # So this is the final ordering:
454 # Phase 0 : all package-data.mk files
455 # (requires ghc-cabal, ghc-pkg, mkdirhier, dummy-ghc etc.)
456 # Phase 1 : .depend files for bootstrap libs
458 # Phase 2 : compiler/stage1/.depend
459 # (requires bootstrap libs and genprimopcode)
460 # Phase 3 : ghc/stage1/.depend
461 # (requires compiler/stage1)
463 # The rest : libraries/*/dist-install, compiler/stage2, ghc/stage2
467 ifneq "$(BINDIST)" "YES"
469 $(GHC_MKDEPENDC_DIR) \
475 libraries/Cabal/doc \
479 ifneq "$(GhcUnregisterised)" "YES"
485 ifneq "$(BINDIST)" "YES"
498 ifneq "$(BINDIST)" "YES"
504 ifneq "$(HADDOCK_DOCS)" "NO"
510 ifneq "$(CLEANING)" "YES"
512 $(patsubst %, libraries/%, $(PACKAGES) $(PACKAGES_STAGE2))
513 ifneq "$(BootingFromHc)" "YES"
519 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
520 BUILD_DIRS += libraries/integer-gmp/gmp
530 ifeq "$(Windows)" "YES"
535 # XXX libraries/% must come before any programs built with stage1, see
536 # Note [lib-depends].
539 $(foreach lib,$(BOOT_PKGS),$(eval \
540 libraries/$(lib)_dist-boot_DISABLE = YES))
543 ifneq "$(findstring $(phase),0 1)" ""
544 # We can build deps for compiler/stage1 in phase 2
545 compiler_stage1_DISABLE = YES
548 ifneq "$(findstring $(phase),0 1 2)" ""
549 ghc_stage1_DISABLE = YES
552 ifneq "$(CLEANING)" "YES"
553 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
554 libraries/base_dist-install_CONFIGURE_OPTS += --flags=-integer-simple
556 ifeq "$(INTEGER_LIBRARY)" "integer-simple"
557 libraries/base_dist-install_CONFIGURE_OPTS += --flags=integer-simple
559 $(error Unknown integer library: $(INTEGER_LIBRARY))
564 ifneq "$(findstring $(phase),0 1 2 3)" ""
565 # In phases 0-3, we disable stage2-3, the full libraries and haddock
566 utils/haddock_dist_DISABLE = YES
567 utils/runghc_dist_DISABLE = YES
568 utils/hpc_dist_DISABLE = YES
569 utils/hsc2hs_dist-install_DISABLE = YES
570 utils/ghc-pkg_dist-install_DISABLE = YES
571 compiler_stage2_DISABLE = YES
572 compiler_stage3_DISABLE = YES
573 ghc_stage2_DISABLE = YES
574 ghc_stage3_DISABLE = YES
575 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),$(eval \
576 libraries/$(lib)_dist-install_DISABLE = YES))
579 # These packages don't pass the Cabal checks because hs-source-dirs
580 # points outside the source directory. This isn't a real problem in
581 # these cases, so we just skip checking them.
582 CHECKED_libraries/dph/dph-seq = YES
583 CHECKED_libraries/dph/dph-par = YES
584 # In compiler's case, include-dirs points outside of the source tree
585 CHECKED_compiler = YES
587 include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
589 # We need -fno-warn-deprecated-flags to avoid failure with -Werror
590 GhcLibHcOpts += -fno-warn-deprecated-flags
591 ifeq "$(ghc_ge_609)" "YES"
592 GhcBootLibHcOpts += -fno-warn-deprecated-flags
595 # Add $(GhcLibHcOpts) to all library builds
596 $(foreach pkg,$(PACKAGES) $(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
598 # XXX Hack; remove this
599 $(foreach pkg,$(PACKAGES_STAGE2),$(eval libraries/$(pkg)_dist-install_HC_OPTS += -Wwarn))
601 # A useful pseudo-target
603 stage1_libs : $(ALL_STAGE1_LIBS)
605 ifeq "$(HADDOCK_DOCS)" "YES"
606 libraries/index.html: $(ALL_HADDOCK_FILES)
607 cd libraries && sh gen_contents_index --inplace
608 $(eval $(call all-target,library_doc_index,libraries/index.html))
609 INSTALL_LIBRARY_DOCS += libraries/*.html libraries/*.gif libraries/*.css libraries/*.js
610 CLEAN_FILES += libraries/doc-index* libraries/haddock*.css \
611 libraries/haddock*.js libraries/index*.html libraries/*.gif
614 ifeq "$(CHECK_PACKAGES)" "YES"
618 # -----------------------------------------------------------------------------
619 # Bootstrapping libraries
621 # We need to build a few libraries with the installed GHC, since GHC itself
622 # and some of the tools depend on them:
624 ifneq "$(BINDIST)" "YES"
626 ifneq "$(BOOTSTRAPPING_CONF)" ""
627 ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
628 $(shell echo "[]" >$(BOOTSTRAPPING_CONF))
632 $(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
634 # These three libraries do not depend on each other, so we can build
637 $(eval $(call build-package,libraries/hpc,dist-boot,0))
638 $(eval $(call build-package,libraries/extensible-exceptions,dist-boot,0))
639 $(eval $(call build-package,libraries/Cabal,dist-boot,0))
640 $(eval $(call build-package,libraries/binary,dist-boot,0))
641 $(eval $(call build-package,libraries/bin-package-db,dist-boot,0))
643 # register the boot packages in strict sequence, because running
644 # multiple ghc-pkgs in parallel doesn't work (registrations may get
647 $(foreach pkg,$(BOOT_PKGS),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
649 compiler/stage1/package-data.mk : \
650 libraries/Cabal/dist-boot/package-data.mk \
651 libraries/hpc/dist-boot/package-data.mk \
652 libraries/extensible-exceptions/dist-boot/package-data.mk \
653 libraries/bin-package-db/dist-boot/package-data.mk
655 # These are necessary because the bootstrapping compiler may not know
656 # about cross-package dependencies:
657 $(compiler_stage1_depfile) : $(BOOT_LIBS)
658 $(ghc_stage1_depfile) : $(compiler_stage1_v_LIB)
660 # A few careful dependencies between bootstrapping packages. When we
661 # can rely on the stage 0 compiler being able to generate
662 # cross-package dependencies with -M (fixed in GHC 6.12.1) we can drop
663 # these, and also some of the phases.
665 # If you miss any out here, then 'make -j8' will probably tell you.
667 libraries/bin-package-db/dist-boot/build/Distribution/InstalledPackageInfo/Binary.$(v_osuf) : libraries/binary/dist-boot/build/Data/Binary.$(v_hisuf) libraries/Cabal/dist-boot/build/Distribution/InstalledPackageInfo.$(v_hisuf)
669 $(foreach pkg,$(BOOT_PKGS),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
673 # -----------------------------------------------------------------------------
674 # Creating a local mingw copy on Windows
676 ifeq "$(Windows)" "YES"
678 # directories don't work well as dependencies, hence a stamp file
679 $(INPLACE)/stamp-mingw : $(MKDIRHIER)
680 $(MKDIRHIER) $(INPLACE_MINGW)/bin
681 GCC=`type -p $(WhatGccIsCalled)`; \
682 GccDir=`dirname $$GCC`; \
683 "$(CP)" -p $$GccDir/{gcc.exe,ar.exe,as.exe,dlltool.exe,dllwrap.exe,windres.exe} $(INPLACE_MINGW)/bin; \
684 "$(CP)" -Rp $$GccDir/../include $(INPLACE_MINGW); \
685 "$(CP)" -Rp $$GccDir/../lib $(INPLACE_MINGW); \
686 "$(CP)" -Rp $$GccDir/../libexec $(INPLACE_MINGW); \
687 "$(CP)" -Rp $$GccDir/../mingw32 $(INPLACE_MINGW)
688 touch $(INPLACE)/stamp-mingw
690 install : install_mingw
691 .PHONY: install_mingw
692 install_mingw : $(INPLACE_MINGW)
693 "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
695 $(INPLACE_LIB)/perl.exe $(INPLACE_LIB)/perl56.dll :
696 "$(CP)" $(GhcDir)../{perl.exe,perl56.dll} $(INPLACE_LIB)
700 libraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock: \
701 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs \
702 libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs
704 libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
705 $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
706 "$(MKDIRHIER)" $(dir $@)
707 "$(GENPRIMOP_INPLACE)" --make-haskell-source < $< > $@
709 libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs: \
710 $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
711 "$(MKDIRHIER)" $(dir $@)
712 "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers < $< > $@
714 # -----------------------------------------------------------------------------
717 install: install_packages install_libs install_libexecs install_headers \
718 install_libexec_scripts install_bins install_docs \
719 install_topdirs install_topdir_scripts
721 install_bins: $(INSTALL_BINS)
722 $(INSTALL_DIR) $(DESTDIR)$(bindir)
723 for i in $(INSTALL_BINS); do \
724 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(bindir) ; \
725 if test "$(darwin_TARGET_OS)" = "1"; then \
726 sh mk/fix_install_names.sh $(ghclibdir) $(DESTDIR)$(bindir)/$$i ; \
730 install_libs: $(INSTALL_LIBS)
731 $(INSTALL_DIR) $(DESTDIR)$(ghclibdir)
732 for i in $(INSTALL_LIBS); do \
735 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibdir); \
736 $(RANLIB) $(DESTDIR)$(ghclibdir)/`basename $$i` ;; \
738 $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibdir) ;; \
740 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibdir) ;; \
742 $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibdir); \
743 install_name_tool -id $(DESTDIR)$(ghclibdir)/`basename $$i` $(DESTDIR)$(ghclibdir)/`basename $$i` ;; \
745 $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibdir); \
749 install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
750 $(INSTALL_DIR) $(DESTDIR)$(ghclibexecdir)
751 for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
752 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghclibexecdir); \
755 install_libexecs: $(INSTALL_LIBEXECS)
756 $(INSTALL_DIR) $(DESTDIR)$(ghclibexecdir)
757 for i in $(INSTALL_LIBEXECS); do \
758 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(ghclibexecdir); \
761 install_topdir_scripts: $(INSTALL_TOPDIR_SCRIPTS)
762 $(INSTALL_DIR) $(DESTDIR)$(topdir)
763 for i in $(INSTALL_TOPDIR_SCRIPTS); do \
764 $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(topdir); \
767 install_topdirs: $(INSTALL_TOPDIRS)
768 $(INSTALL_DIR) $(DESTDIR)$(topdir)
769 for i in $(INSTALL_TOPDIRS); do \
770 $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(topdir); \
773 install_headers: $(INSTALL_HEADERS)
774 $(INSTALL_DIR) $(DESTDIR)$(ghcheaderdir)
775 for i in $(INSTALL_HEADERS); do \
776 $(INSTALL_HEADER) $(INSTALL_OPTS) $$i $(DESTDIR)$(ghcheaderdir); \
779 install_docs: $(INSTALL_HEADERS)
780 $(INSTALL_DIR) $(DESTDIR)$(docdir)
781 for i in $(INSTALL_DOCS); do \
782 $(INSTALL_DOC) $(INSTALL_OPTS) $$i $(DESTDIR)$(docdir); \
784 $(INSTALL_DIR) $(INSTALL_OPTS) $(DESTDIR)$(docdir)/html; \
785 $(INSTALL_DOC) $(INSTALL_OPTS) docs/index.html $(DESTDIR)$(docdir)/html; \
786 for i in $(INSTALL_LIBRARY_DOCS); do \
787 $(INSTALL_DOC) $(INSTALL_OPTS) $$i $(DESTDIR)$(docdir)/html/libraries/; \
789 for i in $(INSTALL_HTML_DOC_DIRS); do \
790 $(INSTALL_DIR) $(INSTALL_OPTS) $(DESTDIR)$(docdir)/html/`basename $$i`; \
791 $(INSTALL_DOC) $(INSTALL_OPTS) $$i/* $(DESTDIR)$(docdir)/html/`basename $$i`; \
794 INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
796 # Install packages in the right order, so that ghc-pkg doesn't complain.
797 # Also, install ghc-pkg first.
798 ifeq "$(Windows)" "NO"
799 INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/ghc-stage2
800 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/ghc-pkg
802 INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
803 INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
806 install_packages: install_libexecs
807 install_packages: libffi/package.conf.install rts/package.conf.install
808 $(INSTALL_DIR) $(DESTDIR)$(topdir)
809 "$(RM)" -r $(RM_OPTS) $(INSTALLED_PACKAGE_CONF)
810 $(INSTALL_DIR) $(INSTALLED_PACKAGE_CONF)
811 "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf $(INSTALLED_PACKAGE_CONF) update libffi/package.conf.install
812 "$(INSTALLED_GHC_PKG_REAL)" --force --global-conf $(INSTALLED_PACKAGE_CONF) update rts/package.conf.install
813 $(foreach p, $(PACKAGES) $(PACKAGES_STAGE2),\
814 "$(GHC_CABAL_INPLACE)" install \
815 $(INSTALLED_GHC_REAL) \
816 $(INSTALLED_GHC_PKG_REAL) \
817 $(DESTDIR)$(topdir) \
818 libraries/$p dist-install \
819 '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries' \
820 $(RelocatableBuild) &&) true
821 "$(GHC_CABAL_INPLACE)" install \
822 $(INSTALLED_GHC_REAL) \
823 $(INSTALLED_GHC_PKG_REAL) \
824 $(DESTDIR)$(topdir) \
826 '$(DESTDIR)' '$(prefix)' '$(ghclibdir)' '$(docdir)/html/libraries' \
829 # -----------------------------------------------------------------------------
830 # Binary distributions
832 ifneq "$(CLEANING)" "YES"
833 # This rule seems to hold some files open on Windows which prevents
834 # cleaning, perhaps due to the $(wildcard).
836 $(eval $(call bindist,.,\
838 configure config.sub config.guess install-sh \
842 $(INPLACE_BIN)/mkdirhier \
843 $(INPLACE_BIN)/ghc-cabal \
844 utils/ghc-pwd/ghc-pwd \
845 $(BINDIST_WRAPPERS) \
849 $(includes_H_CONFIG) \
850 $(includes_H_PLATFORM) \
851 includes/ghcconfig.h \
852 includes/rts/Config.h \
854 $(INSTALL_LIBEXECS) \
855 $(INSTALL_LIBEXEC_SCRIPTS) \
857 $(INSTALL_TOPDIR_SCRIPTS) \
860 $(INSTALL_LIBRARY_DOCS) \
861 $(addsuffix /*,$(INSTALL_HTML_DOC_DIRS)) \
863 $(wildcard libraries/*/dist-install/doc/) \
864 $(filter-out extra-gcc-opts,$(INSTALL_LIBS)) \
865 $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
866 mk/fix_install_names.sh \
870 libraries/dph/LICENSE \
873 # mk/project.mk gets an absolute path, so we manually include it in
874 # the bindist with a relative path
876 BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
878 unix-binary-dist-prep:
879 "$(RM)" $(RM_OPTS) -r bindistprep/*
880 mkdir $(BIN_DIST_PREP_DIR)
881 set -e; for i in LICENSE compiler ghc rts libraries utils 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_PREP_DIR)/; done
882 echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
883 echo "LATEX_DOCS = $(LATEX_DOCS)" >> $(BIN_DIST_MK)
884 echo "BUILD_DOCBOOK_HTML = $(BUILD_DOCBOOK_HTML)" >> $(BIN_DIST_MK)
885 echo "BUILD_DOCBOOK_PS = $(BUILD_DOCBOOK_PS)" >> $(BIN_DIST_MK)
886 echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
887 ln -s ../../distrib/configure-bin.ac $(BIN_DIST_PREP_DIR)/configure.ac
888 cd $(BIN_DIST_PREP_DIR) && autoreconf
889 "$(RM)" $(RM_OPTS) $(BIN_DIST_PREP_TAR)
890 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
891 # tree then we want to include the real file, not a symlink to it
892 cd bindistprep && "$(TAR)" hcf - -T ../$(BIN_DIST_LIST) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
894 windows-binary-dist-prep:
895 "$(RM)" $(RM_OPTS) -r bindistprep/*
896 $(MAKE) prefix=$(TOP)/$(BIN_DIST_PREP_DIR) install
897 cd bindistprep && "$(TAR)" cf - $(BIN_DIST_NAME) | bzip2 -c > ../$(BIN_DIST_PREP_TAR_BZ2)
900 "$(ISCC)" /O. /F$(WINDOWS_INSTALLER_BASE) - < distrib/ghc.iss
902 nTimes = set -e; for i in `seq 1 $(1)`; do echo Try "$$i: $(2)"; if $(2); then break; fi; done
904 .PHONY: publish-binary-dist
906 $(call nTimes,10,$(PublishCp) $(BIN_DIST_TAR_BZ2) $(PublishLocation)/dist)
907 ifeq "$(mingw32_TARGET_OS)" "1"
908 $(call nTimes,10,$(PublishCp) $(WINDOWS_INSTALLER) $(PublishLocation)/dist)
913 $(call nTimes,10,$(PublishCp) -r bindisttest/installed/share/doc/ghc/* $(PublishLocation)/docs)
915 # -----------------------------------------------------------------------------
916 # Source distributions
924 # A source dist is built from a complete build tree, because we
925 # require some extra files not contained in a darcs checkout: the
926 # output from Happy and Alex, for example.
928 # The steps performed by 'make dist' are as follows:
929 # - create a complete link-tree of the current build tree in /tmp
930 # - run 'make distclean' on that tree
931 # - remove a bunch of other files that we know shouldn't be in the dist
932 # - tar up first the extralibs package, then the main source package
935 # Directory in which we're going to build the src dist
937 SRC_DIST_NAME=ghc-$(ProjectVersion)
938 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
941 # Files to include in source distributions
943 SRC_DIST_DIRS = mk rules docs distrib bindisttest libffi includes utils docs rts compiler ghc driver libraries
945 configure.ac config.guess config.sub configure \
946 aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
947 ghc.spec.in ghc.spec extra-gcc-opts.in VERSION \
948 boot boot-pkgs packages ghc.mk
950 SRC_DIST_TARBALL = $(SRC_DIST_NAME)-src.tar.bz2
953 echo $(ProjectVersion) >VERSION
958 # $(call sdist_file,compiler,stage2,cmm,CmmLex,x)
959 # to copy the generated file that replaces compiler/cmm/CmmLex.x, where
960 # "stage2" is the dist dir.
962 if test -f $(TOP)/$1/$2/build/$4.hs; then \
963 "$(CP)" $(TOP)/$1/$2/build/$4.hs $1/$3/ ; \
964 mv $1/$3/$4.$5 $1/$3/$4.$5.source ;\
966 echo "does not exist: $1/$2/build/$4.hs"; \
972 "$(RM)" $(RM_OPTS) -r $(SRC_DIST_DIR)
973 "$(RM)" $(RM_OPTS) $(SRC_DIST_TARBALL)
974 mkdir $(SRC_DIST_DIR)
975 cd $(SRC_DIST_DIR) && for i in $(SRC_DIST_DIRS); do mkdir $$i; ( cd $$i && lndir $(TOP)/$$i ); done
976 cd $(SRC_DIST_DIR) && for i in $(SRC_DIST_FILES); do $(LN_S) $(TOP)/$$i .; done
977 cd $(SRC_DIST_DIR) && $(MAKE) distclean
978 cd $(SRC_DIST_DIR) && 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
979 cd $(SRC_DIST_DIR) && $(call sdist_file,compiler,stage2,cmm,CmmLex,x)
980 cd $(SRC_DIST_DIR) && $(call sdist_file,compiler,stage2,cmm,CmmParse,y)
981 cd $(SRC_DIST_DIR) && $(call sdist_file,compiler,stage2,parser,Lexer,x)
982 cd $(SRC_DIST_DIR) && $(call sdist_file,compiler,stage2,parser,Parser,y.pp)
983 cd $(SRC_DIST_DIR) && $(call sdist_file,compiler,stage2,parser,ParserCore,y)
984 cd $(SRC_DIST_DIR) && $(call sdist_file,utils/hpc,dist,,HpcParser,y)
985 cd $(SRC_DIST_DIR) && $(call sdist_file,utils/genprimopcode,dist,,Lexer,x)
986 cd $(SRC_DIST_DIR) && $(call sdist_file,utils/genprimopcode,dist,,Parser,y)
987 cd $(SRC_DIST_DIR) && "$(RM)" $(RM_OPTS) -r compiler/stage[123] mk/build.mk
988 cd $(SRC_DIST_DIR) && "$(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)" $(RM_OPTS) -r
992 "$(TAR)" chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(TOP)/$(SRC_DIST_TARBALL)
994 sdist-manifest : $(SRC_DIST_TARBALL)
995 tar tjf $(SRC_DIST_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
997 # Upload the distribution(s)
998 # Retrying is to work around buggy firewalls that corrupt large file transfers
1000 ifneq "$(PublishLocation)" ""
1002 $(call nTimes,10,$(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist)
1005 ifeq "$(BootingFromHc)" "YES"
1006 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
1009 # -----------------------------------------------------------------------------
1014 CLEAN_FILES += utils/ghc-pwd/ghc-pwd
1015 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.exe
1016 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.hi
1017 CLEAN_FILES += utils/ghc-pwd/ghc-pwd.o
1018 CLEAN_FILES += libraries/bootstrapping.conf
1019 CLEAN_FILES += libraries/integer-gmp/cbits/GmpDerivedConstants.h
1020 CLEAN_FILES += libraries/integer-gmp/cbits/mkGmpDerivedConstants
1022 clean : clean_files clean_libraries
1026 "$(RM)" $(RM_OPTS) $(CLEAN_FILES)
1028 ifneq "$(NO_CLEAN_GMP)" "YES"
1029 CLEAN_FILES += libraries/integer-gmp/gmp/gmp.h
1030 CLEAN_FILES += libraries/integer-gmp/gmp/libgmp.a
1035 "$(RM)" $(RM_OPTS) -r libraries/integer-gmp/gmp/objs
1036 "$(RM)" $(RM_OPTS) -r libraries/integer-gmp/gmp/gmpbuild
1039 .PHONY: clean_libraries
1040 clean_libraries: $(patsubst %,clean_libraries/%_dist-install,$(PACKAGES) $(PACKAGES_STAGE2))
1041 clean_libraries: $(patsubst %,clean_libraries/%_dist-boot,$(BOOT_PKGS))
1044 "$(RM)" $(RM_OPTS) -r $(patsubst %, libraries/%/dist, $(PACKAGES) $(PACKAGES_STAGE2))
1045 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/*.buildinfo, $(PACKAGES) $(PACKAGES_STAGE2))
1047 # We have to define a clean target for each library manually, because the
1048 # libraries/*/ghc.mk files are not included when we're cleaning.
1049 ifeq "$(CLEANING)" "YES"
1050 $(foreach lib,$(PACKAGES) $(PACKAGES_STAGE2),\
1051 $(eval $(call clean-target,libraries/$(lib),dist-install,libraries/$(lib)/dist-install)))
1055 "$(RM)" $(RM_OPTS) config.cache config.status config.log mk/config.h mk/stamp-h
1056 "$(RM)" $(RM_OPTS) mk/config.mk mk/are-validating.mk mk/project.mk
1057 "$(RM)" $(RM_OPTS) mk/config.mk.old mk/project.mk.old
1058 "$(RM)" $(RM_OPTS) extra-gcc-opts docs/users_guide/ug-book.xml
1059 "$(RM)" $(RM_OPTS) compiler/ghc.cabal compiler/ghc.cabal.old
1060 "$(RM)" $(RM_OPTS) ghc/ghc-bin.cabal
1061 "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h
1062 "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h
1063 "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h
1064 "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h
1065 "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h
1067 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.log, $(PACKAGES) $(PACKAGES_STAGE2))
1068 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/config.status, $(PACKAGES) $(PACKAGES_STAGE2))
1069 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/include/Hs*Config.h, $(PACKAGES) $(PACKAGES_STAGE2))
1070 "$(RM)" $(RM_OPTS) -r $(patsubst %, libraries/%/autom4te.cache, $(PACKAGES) $(PACKAGES_STAGE2))
1072 maintainer-clean : distclean
1073 "$(RM)" $(RM_OPTS) configure mk/config.h.in
1074 "$(RM)" $(RM_OPTS) -r autom4te.cache libraries/*/autom4te.cache
1075 "$(RM)" $(RM_OPTS) ghc.spec
1076 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/GNUmakefile, \
1077 $(PACKAGES) $(PACKAGES_STAGE2))
1078 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/ghc.mk, $(PACKAGES) $(PACKAGES_STAGE2))
1079 "$(RM)" $(RM_OPTS) $(patsubst %, libraries/%/configure, \
1080 $(PACKAGES) $(PACKAGES_STAGE2))
1081 "$(RM)" $(RM_OPTS) libraries/base/include/HsBaseConfig.h.in
1082 "$(RM)" $(RM_OPTS) libraries/directory/include/HsDirectoryConfig.h.in
1083 "$(RM)" $(RM_OPTS) libraries/process/include/HsProcessConfig.h.in
1084 "$(RM)" $(RM_OPTS) libraries/unix/include/HsUnixConfig.h.in
1085 "$(RM)" $(RM_OPTS) libraries/old-time/include/HsTimeConfig.h.in
1087 .PHONY: all_libraries
1089 .PHONY: bootstrapping-files
1090 bootstrapping-files: $(OTHER_LIBS)
1091 bootstrapping-files: includes/ghcautoconf.h
1092 bootstrapping-files: includes/DerivedConstants.h
1093 bootstrapping-files: includes/GHCConstants.h