Check that make supports eval
[ghc-hetmet.git] / Makefile
1 ############################################################################
2 #
3 #               This is the top-level Makefile for GHC
4 #
5 # Targets: 
6 #
7 #       bootstrap (DEFAULT)
8 #               Builds GHC, then builds the libraries,
9 #               then uses this GHC ("stage 1") to build itself
10 #               ("stage 2").
11 #
12 #       bootstrap2
13 #               Same as bootstrap
14 #
15 #       bootstrap3
16 #               bootstrap2 + we build GHC one more time ("stage 3")
17 #
18 #       stage1
19 #               Just build up to stage 1
20 #
21 #       stage2
22 #               Just build stage 2 (stage 1 must be built)
23 #
24 #       stage3
25 #               Just build stage 3 (stage 2 must be built)
26 #
27 #       all
28 #               Same as bootstrap
29 #
30 #       install
31 #               Install everything, including stage 2 compiler by default
32 #               (override with stage=3, for example).
33 #
34 #       dist
35 #               Make a source dist (WARNING: runs 'make distclean' first)
36 #
37 #       binary-dist
38 #               Builds a binary distribution
39 #
40 #       framework-pkg  [MacOS only]
41 #               Builds /Library/Frameworks/GHC.framework wrapped into a Mac
42 #               installer package
43 #
44 #       framework-binary-dist  [MacOS only]
45 #               Builds GHC.framework encapsulating a binary distribution
46 #               (to give a relocatable framework)
47 #
48 #       hc-file-bundle
49 #               Builds an HC-file bundle, for bootstrapping
50 #
51 #       clean, distclean, maintainer-clean
52 #               Increasing levels of cleanliness
53 #
54 ############################################################################
55
56 TOP=.
57 include $(TOP)/mk/boilerplate.mk
58
59 #
60 # Order is important! It's e.g. necessary to descend into include/
61 # before the rest to have a config.h, etc.
62 #
63 # If we're booting from .hc files, swap the order
64 # we descend into subdirs - to boot utils must be before driver.
65 #
66 .PHONY: stage1 stage2 stage3 bootstrap bootstrap2 bootstrap3
67
68 # We can't 'make boot' in libraries until stage1 is built
69 ifeq "$(BootingFromHc)" "YES"
70 SUBDIRS_BUILD = includes compiler docs utils driver
71 else
72 SUBDIRS_BUILD = includes utils driver docs compiler libraries/Cabal/doc
73 endif
74
75 SUBDIRS = gmp libffi includes utils docs rts compiler ghc driver libraries libraries/Cabal/doc
76
77 check-all: check-packages check-tools
78
79 # Sanity check that all the boot libraries are in the tree, to catch
80 # failure to run darcs-all.
81 check-packages :
82         @ds=`grep "^[^# ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*$$" packages | sed "s/ .*//"`;\
83         for d in $$ds; do \
84           if test ! -d $$d; then \
85              echo "Looks like you're missing $$d,"; \
86              echo "maybe you haven't done './darcs-all get'?"; \
87              exit 1; \
88           fi \
89         done
90         @if test ! -f libraries/base/configure; then \
91             echo "Looks like you're missing base's configure script."; \
92             echo "Did you run 'sh boot' at the top level?"; \
93             exit 1; \
94         fi
95
96 HAVE_EVAL := NO
97 $(eval HAVE_EVAL := YES)
98
99 check-tools:
100 ifeq "$(HSCOLOUR_SRCS) $(HSCOLOUR)" "YES "
101         @echo "HsColour needed but wasn't found."
102         @echo "Set HSCOLOUR_SRCS=NO if you don't want to use it"
103         exit 1
104 endif
105 ifeq "$(HAVE_EVAL)" "NO"
106         @echo "Your make doesn't support eval. You need GNU make >= 3.80"
107         exit 1
108 endif
109         @:
110
111 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
112 ifneq "$(WhatGccIsCalled)" ""
113 GCC_LIB_DEP = stamp.inplace-gcc-lib
114 endif
115 endif
116
117 stage1 : $(GCC_LIB_DEP) check-all
118         $(MAKE) -C libraries boot
119         $(MAKE) -C gmp       all
120         $(MAKE) -C utils/mkdependC boot
121         $(MAKE) -C utils with-bootstrapping-compiler
122         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
123         for i in $(SUBDIRS_BUILD); do \
124           echo "------------------------------------------------------------------------"; \
125           echo "== $(MAKE) boot $(MFLAGS);"; \
126           echo " in $(shell pwd)/$$i"; \
127           echo "------------------------------------------------------------------------"; \
128           $(MAKE) --no-print-directory -C $$i $(MFLAGS) boot; \
129           if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
130         done; \
131         for i in $(SUBDIRS_BUILD); do \
132           echo "------------------------------------------------------------------------"; \
133           echo "== $(MAKE) all $(MFLAGS);"; \
134           echo " in $(shell pwd)/$$i"; \
135           echo "------------------------------------------------------------------------"; \
136           $(MAKE) --no-print-directory -C $$i $(MFLAGS) all; \
137           if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
138         done
139         $(MAKE) -C libffi    all
140         $(MAKE) -C rts boot
141         $(MAKE) -C rts
142         $(MAKE) -C libraries all
143
144 # When making distributions (i.e., whether with binary-dist or using the 
145 # vanilla install target to create an installer package), we can have problems
146 # if some things (e.g. ghc-pkg) are compiled with the bootstrapping compiler 
147 # and some (e.g. the stage 2 compiler) with the stage1 compiler. See #1860 for
148 # an example.  Thus, we explicitly build a second version with the stage 1 
149 # compiler of all utils that get installed and of all extra support binaries
150 # includes in binary dists.
151 stage2 : check-all
152         $(MAKE) -C compiler stage=2 boot
153         $(MAKE) -C compiler stage=2
154         $(MAKE) -C utils with-stage-2
155 ifeq "$(HADDOCK_DOCS)" "YES"
156         $(MAKE) -C libraries doc
157         $(MAKE) -C compiler  doc stage=2
158 endif
159
160 stage3 : check-all
161         $(MAKE) -C compiler stage=3 boot
162         $(MAKE) -C compiler stage=3
163
164 bootstrap  : bootstrap2
165
166 bootstrap2 : stage1
167         $(MAKE) stage2
168
169 bootstrap3 : bootstrap2
170         $(MAKE) stage3
171
172 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
173 ifneq "$(WhatGccIsCalled)" ""
174 all :: stamp.inplace-gcc-lib
175
176 .PHONY: stamp.inplace-gcc-lib
177
178 # This is a hack to make Cabal able to find ld when we run tests with
179 # the inplace ghc. We should probably install all the gcc stuff in our
180 # tree somewhere, and then have install copy it from there rather than
181 # from the filesystem.
182 stamp.inplace-gcc-lib:
183         $(RM) -r ghc/gcc-lib
184         mkdir ghc/gcc-lib
185         cp $(LD) ghc/gcc-lib
186         touch $@
187
188 clean ::
189         $(RM) -r ghc/gcc-lib
190         $(RM) -f inplace-gcc-lib
191 endif
192 endif
193
194 all :: bootstrap
195
196 # -----------------------------------------------------------------------------
197 # Installing
198
199 # We want to install the stage 2 bootstrapped compiler by default, but we let
200 # the user override this by saying 'make install stage=1', for example.
201 ifeq "$(stage)" ""
202 INSTALL_STAGE = stage=2
203 else
204 INSTALL_STAGE =
205 endif
206
207 install-strip:
208         $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
209
210 # Same as default rule, but we pass $(INSTALL_STAGE) to $(MAKE) too
211 install :: check-packages
212         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
213         for i in $(SUBDIRS); do \
214           echo "------------------------------------------------------------------------"; \
215           echo "== $(MAKE) $@ $(MFLAGS);"; \
216           echo " in $(shell pwd)/$$i"; \
217           echo "------------------------------------------------------------------------"; \
218           $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
219           if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
220         done
221
222 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
223 # These files need to be in the InstallShield
224 # INSTALL_DATAS rather than INSTALL_DOCS is used so these files go
225 # in the top-level directory of the distribution
226 INSTALL_DATAS += ANNOUNCE LICENSE README
227 endif
228
229 # If installing on Windows with MinGW32, copy the gcc compiler, headers and libs
230 # and the perl interpreter and dll into the GHC prefix directory.
231 # Gcc and Perl source locations derived from configuration data.
232 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
233 ifneq "$(WhatGccIsCalled)" ""
234 install ::
235         -mkdir $(prefix)/gcc-lib
236         -mkdir $(prefix)/include
237         -mkdir $(prefix)/include/mingw
238         -cp -rp $(GccDir)../include/* $(prefix)/include/mingw
239         -cp -rp $(GccDir)../lib/gcc-lib/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
240         -cp -rp $(GccDir)../lib/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
241         -cp -rp $(GccDir)../libexec/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
242         -cp $(GccDir)../lib/*.* $(prefix)/gcc-lib
243         -cp $(GccDir)gcc.exe $(prefix)
244         -cp $(GccDir)as.exe $(prefix)/gcc-lib
245         -cp $(GccDir)ld.exe $(prefix)/gcc-lib
246         -cp $(GccDir)dllwrap.exe $(prefix)/gcc-lib
247         -cp $(GccDir)dlltool.exe $(prefix)/gcc-lib
248         -cp $(GhcDir)../perl.exe $(prefix)
249         -cp $(GhcDir)../perl56.dll $(prefix)
250 endif
251 endif
252
253 # Install gcc-extra-opts
254 install ::
255         $(INSTALL_DIR) $(DESTDIR)$(libdir)
256         $(INSTALL_DATA) $(INSTALL_OPTS) extra-gcc-opts $(DESTDIR)$(libdir)
257
258 install-docs ::
259         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
260         for i in $(SUBDIRS); do \
261           echo "------------------------------------------------------------------------"; \
262           echo "== $(MAKE) $@ $(MFLAGS);"; \
263           echo " in $(shell pwd)/$$i"; \
264           echo "------------------------------------------------------------------------"; \
265           $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
266           if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
267         done
268
269 # -----------------------------------------------------------------------------
270 # Making a binary distribution
271 #
272 # `dist' `binary-dist'
273 #      Create a distribution tar file for this program. The tar file
274 #      should be set up so that the file names in the tar file start with
275 #      a subdirectory name which is the name of the package it is a
276 #      distribution for. This name can include the version number.
277 #
278 #      For example, the distribution tar file of GCC version 1.40 unpacks
279 #      into a subdirectory named `gcc-1.40'.
280
281 #      The easiest way to do this is to create a subdirectory
282 #      appropriately named, use ln or cp to install the proper files in
283 #      it, and then tar that subdirectory.
284
285 #      The dist target should explicitly depend on all non-source files
286 #      that are in the distribution, to make sure they are up to date in
287 #      the distribution. See Making Releases.
288 #
289 #       binary-dist is a GHC addition for binary distributions
290
291
292 binary-dist::
293         -rm -rf $(BIN_DIST_DIR)
294         -$(RM) $(BIN_DIST_TAR_BZ2)
295
296 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
297
298 binary-dist::
299         $(MAKE) prefix=$(BIN_DIST_DIR) install
300         $(MAKE) prefix=$(BIN_DIST_DIR) install-docs
301
302 binary-dist::
303         cd $(BIN_DIST_DIR) && $(SHELL) ../distrib/prep-bin-dist-mingw
304
305 binary-dist::
306         $(MKDIRHIER) $(BIN_DIST_DIR)/icons
307         cp distrib/hsicon.ico $(BIN_DIST_DIR)/icons
308
309 # Tar up the distribution and build a manifest
310 binary-dist :: tar-binary-dist
311
312 .PHONY: tar-binary-dist
313 tar-binary-dist:
314         ( cd $(BIN_DIST_TOPDIR_ABS); $(TAR) cf - $(BIN_DIST_NAME) | bzip2 > $(BIN_DIST_TAR_BZ2) )
315         ( cd $(BIN_DIST_TOPDIR_ABS); bunzip2 -c $(BIN_DIST_TAR_BZ2) | $(TAR) tf - | sed "s/^ghc-$(ProjectVersion)/fptools/" | sort >$(FPTOOLS_TOP_ABS)/bin-manifest-$(ProjectVersion) )
316
317 else
318
319 .PHONY: binary-dist
320
321 BIN_DIST_VARFILE=$(BIN_DIST_PREP)/Makefile-vars.in
322
323 WHERE_AM_I = $(BIN_DIST_NAME)
324
325 binary-dist::
326 # For the most part we will be putting filenames in $(BIN_DIST_LIST),
327 # and telling tar to tar all of those files up. So to start with we
328 # remove $(BIN_DIST_LIST) so that we can start with an empty slate
329         $(RM) -f $(BIN_DIST_LIST)
330 # Now we add a few files from mk/ to $(BIN_DIST_LIST)
331         echo $(WHERE_AM_I)/mk/package.mk     >> $(BIN_DIST_LIST)
332         echo $(WHERE_AM_I)/mk/install.mk     >> $(BIN_DIST_LIST)
333         echo $(WHERE_AM_I)/mk/recurse.mk     >> $(BIN_DIST_LIST)
334         echo $(WHERE_AM_I)/mk/cabal.mk       >> $(BIN_DIST_LIST)
335         echo $(WHERE_AM_I)/mk/cabal-flags.mk >> $(BIN_DIST_LIST)
336         echo $(WHERE_AM_I)/mk/fptools.css    >> $(BIN_DIST_LIST)
337         echo $(WHERE_AM_I)/ANNOUNCE          >> $(BIN_DIST_LIST)
338         echo $(WHERE_AM_I)/LICENSE           >> $(BIN_DIST_LIST)
339         echo $(WHERE_AM_I)/install-sh        >> $(BIN_DIST_LIST)
340         echo $(WHERE_AM_I)/extra-gcc-opts.in >> $(BIN_DIST_LIST)
341         echo $(WHERE_AM_I)/config.guess      >> $(BIN_DIST_LIST)
342         echo $(WHERE_AM_I)/config.sub        >> $(BIN_DIST_LIST)
343 # Now we recurse into various subdirectories and tell them to add and
344 # files that they want into $(BIN_DIST_LIST)
345 # XXX Ug, this duplication of "-C foo WHERE_AM_I=.../foo" isn't nice.
346         $(MAKE) -C gmp                 binary-dist WHERE_AM_I=$(WHERE_AM_I)/gmp
347         $(MAKE) -C includes            binary-dist WHERE_AM_I=$(WHERE_AM_I)/includes
348         $(MAKE) -C compiler            binary-dist WHERE_AM_I=$(WHERE_AM_I)/compiler $(INSTALL_STAGE)
349         $(MAKE) -C ghc                 binary-dist WHERE_AM_I=$(WHERE_AM_I)/ghc      $(INSTALL_STAGE)
350         $(MAKE) -C rts                 binary-dist WHERE_AM_I=$(WHERE_AM_I)/rts
351         $(MAKE) -C driver              binary-dist WHERE_AM_I=$(WHERE_AM_I)/driver
352         $(MAKE) -C utils               binary-dist WHERE_AM_I=$(WHERE_AM_I)/utils
353         $(MAKE) -C docs                binary-dist WHERE_AM_I=$(WHERE_AM_I)/docs
354         $(MAKE) -C libffi              binary-dist WHERE_AM_I=$(WHERE_AM_I)/libffi
355         $(MAKE) -C libraries           binary-dist WHERE_AM_I=$(WHERE_AM_I)/libraries
356         $(MAKE) -C libraries/Cabal/doc binary-dist WHERE_AM_I=$(WHERE_AM_I)/libraries/Cabal/doc
357 # Now thinks get messier. Some files we need to move around, rename or
358 # generate. We do this under $(BIN_DIST_PREP).
359         $(RM) -rf    $(BIN_DIST_PREP_DIR)
360         $(MKDIRHIER) $(BIN_DIST_PREP)/mk
361         echo 'include $$(TOP)/Makefile-vars' >  $(BIN_DIST_PREP)/mk/boilerplate.mk
362         echo 'include $$(TOP)/mk/package.mk' >  $(BIN_DIST_PREP)/mk/target.mk
363         echo 'include $$(TOP)/mk/install.mk' >> $(BIN_DIST_PREP)/mk/target.mk
364         echo 'include $$(TOP)/mk/recurse.mk' >> $(BIN_DIST_PREP)/mk/target.mk
365         touch                                   $(BIN_DIST_PREP)/mk/bindist.mk
366 ifeq "$(darwin_TARGET_OS)" "1"
367         cp mk/fix_install_names.sh $(BIN_DIST_PREP)/mk
368 endif
369
370         cp distrib/Makefile         $(BIN_DIST_PREP)
371         cp distrib/INSTALL          $(BIN_DIST_PREP)
372         cp distrib/README           $(BIN_DIST_PREP)
373         cp distrib/configure-bin.ac $(BIN_DIST_PREP)/configure.ac
374 # We can't just list aclocal.m4 in $(BIN_DIST_LIST), as it needs to be
375 # next to configure.ac when we run autoreconf
376         cp aclocal.m4               $(BIN_DIST_PREP)
377         cd $(BIN_DIST_PREP) && autoreconf
378 # We need to copy the pwd program that was built with stage1 to where
379 # the build system expects to find it, i.e. the location the pwd built
380 # with the bootstrapping compiler normally occupies
381         $(MKDIRHIER) $(BIN_DIST_PREP)/utils/pwd
382         cp utils/pwd/dist-install/build/pwd/pwd $(BIN_DIST_PREP)/utils/pwd
383 # And likewise the installPackage program
384         $(MKDIRHIER) $(BIN_DIST_PREP)/utils/installPackage/install-inplace/bin
385         cp utils/installPackage/dist-install/build/installPackage/installPackage \
386            $(BIN_DIST_PREP)/utils/installPackage/install-inplace/bin
387
388         echo "package = ghc"                              >> $(BIN_DIST_VARFILE)
389         echo "version = $(ProjectVersion)"                >> $(BIN_DIST_VARFILE)
390         echo "ProjectVersion = $(ProjectVersion)"         >> $(BIN_DIST_VARFILE)
391         echo "HaveLibGmp = $(HaveLibGmp)"                 >> $(BIN_DIST_VARFILE)
392         echo "GhcLibsWithUnix = $(GhcLibsWithUnix)"       >> $(BIN_DIST_VARFILE)
393         echo "GhcWithInterpreter = $(GhcWithInterpreter)" >> $(BIN_DIST_VARFILE)
394         echo "GhcHasEditline = $(GhcHasEditline)"         >> $(BIN_DIST_VARFILE)
395         echo "BootingFromHc = $(BootingFromHc)"           >> $(BIN_DIST_VARFILE)
396         echo "XMLDocWays = $(XMLDocWays)"                 >> $(BIN_DIST_VARFILE)
397 # We won't actually use xsltproc, but we need to know if it's "" or not
398         echo "XSLTPROC = $(XSLTPROC)"                     >> $(BIN_DIST_VARFILE)
399         echo "TARGETPLATFORM = $(TARGETPLATFORM)"         >> $(BIN_DIST_VARFILE)
400         echo "HADDOCK_DOCS = $(HADDOCK_DOCS)"             >> $(BIN_DIST_VARFILE)
401         echo "LATEX_DOCS = $(LATEX_DOCS)"                 >> $(BIN_DIST_VARFILE)
402         echo "INTEGER_LIBRARY = $(INTEGER_LIBRARY)"       >> $(BIN_DIST_VARFILE)
403         cat distrib/Makefile-bin-vars.in                  >> $(BIN_DIST_VARFILE)
404
405 # With that done, we can now build the actual tarball
406
407         $(RM) -f $(BIN_DIST_NAME)
408         ln -s . $(BIN_DIST_NAME)
409 # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
410 # tree then we want to include the real file, not a symlink to it
411         $(TAR) hcf $(BIN_DIST_TAR) -T $(BIN_DIST_LIST)
412         cd $(BIN_DIST_PREP_DIR) && $(TAR) rf $(BIN_DIST_TAR) $(BIN_DIST_NAME)
413         bzip2 < $(BIN_DIST_TAR) > $(BIN_DIST_TAR_BZ2)
414         $(TAR) tf $(BIN_DIST_TAR) | sort > bin-manifest-$(ProjectVersion)
415 endif
416
417 PUBLISH_FILES = $(BIN_DIST_TAR_BZ2)
418
419 # Upload the distribution and documentation
420 ifneq "$(ISCC)" ""
421 WINDOWS_INSTALLER_BASE = ghc-$(ProjectVersion)-$(TARGETPLATFORM)
422 WINDOWS_INSTALLER = $(WINDOWS_INSTALLER_BASE)$(exeext)
423
424 PUBLISH_FILES += $(WINDOWS_INSTALLER)
425
426 binary-dist :: generate-windows-installer
427
428 .PHONY: generate-windows-installer
429 generate-windows-installer ::
430         $(SED) "s/@VERSION@/$(ProjectVersion)/" distrib/ghc.iss | $(ISCC) /O. /F$(WINDOWS_INSTALLER_BASE) -
431 endif
432
433 # Upload the distribution and documentation
434 ifneq "$(PublishLocation)" ""
435 publish ::
436         make publish-binary-dist 'prefix=$(BIN_DIST_INST_DIR)'
437 endif
438
439 nTimes = set -e; for i in `seq 1 $(1)`; do echo Try "$$i: $(2)"; if $(2); then break; fi; done
440
441 .PHONY: publish-binary-dist
442 publish-binary-dist ::
443         @for f in $(PUBLISH_FILES); \
444             do $(call nTimes,10,$(PublishCp) $$f $(PublishLocation)/dist); \
445         done
446
447 # You need to "make binddisttest" before publishing the docs, as it
448 # works by publish setting $(prefix) to inside the binddisttest
449 # directory so $(docdir) points to the right place.
450
451 # We assume that Windows means Cygwin, as we can't just use docdir
452 # unchanged or rsync (really SSH?) thinks that c:/foo means /foo on
453 # the machine c.
454
455 ifeq "$(Windows)" "YES"
456 PUBLISH_DOCDIR = $(shell cygpath --unix $(docdir))
457 else
458 PUBLISH_DOCDIR = $(docdir)
459 endif
460
461 publish-binary-dist ::
462         $(call nTimes,10,$(PublishCp) -r "$(PUBLISH_DOCDIR)"/* $(PublishLocation)/docs)
463
464 binary-dist::
465         @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
466
467 # -----------------------------------------------------------------------------
468 # Building MacOS installer packages
469 #
470 # 'framework-pkg'
471 #       Create an installer package for /Library/Frameworks/GHC.framework
472 #
473 # 'framework-binary-dist'
474 #       Create an installer package for GHC.framework encapsulating a
475 #       binary-dist to make it relocatable
476 #       FIXME: This is only partially implemented so far
477
478 ifeq "$(darwin_TARGET_OS)" "1"
479
480 .PHONY: framework-pkg framework-binary-dist
481
482 framework-pkg:
483         $(MAKE) -C distrib/MacOS framework-pkg
484
485 framework-binary-dist:
486         $(MAKE) -C distrib/MacOS framework-binary-dist
487
488 endif
489
490 # -----------------------------------------------------------------------------
491 # Building source distributions
492 #
493 # Do it like this: 
494 #
495 #       $ make
496 #       $ make dist
497 #
498 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
499 #
500
501 .PHONY: dist
502
503 #
504 # Directory in which we're going to build the src dist
505 #
506 SRC_DIST_NAME=ghc-$(ProjectVersion)
507 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
508
509 #
510 # Files to include in source distributions
511 #
512 SRC_DIST_DIRS += mk docs distrib bindisttest $(filter-out docs distrib libraries/Cabal/doc,$(SUBDIRS))
513 SRC_DIST_FILES += \
514         configure.ac config.guess config.sub configure \
515         aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
516         ghc.spec.in ghc.spec extra-gcc-opts.in VERSION boot
517
518 # -----------------------------------------------------------------------------
519 # Source distributions
520
521 # A source dist is built from a complete build tree, because we
522 # require some extra files not contained in a darcs checkout: the
523 # output from Happy and Alex, for example.
524
525 # The steps performed by 'make dist' are as follows:
526 #   - create a complete link-tree of the current build tree in /tmp
527 #   - run 'make distclean' on that tree
528 #   - remove a bunch of other files that we know shouldn't be in the dist
529 #   - tar up first the extralibs package, then the main source package
530
531 EXTRA_LIBS=$(patsubst %, $(SRC_DIST_NAME)/%, $(shell grep -E "extralibs|dph" packages | grep -v "^\#" | sed "s/ .*//"))
532
533 SRC_DIST_TARBALL = ghc-$(ProjectVersion)-src.tar.bz2
534 SRC_DIST_EXTRALIBS_TARBALL = ghc-$(ProjectVersion)-src-extralibs.tar.bz2
535
536 VERSION :
537         echo $(ProjectVersion) >VERSION
538
539 dist :: VERSION
540
541 # Use:
542 #     $(call copy_generated_compiler_file,cmm,CmmLex,x)
543 # to copy the generated file that replaces compiler/cmm/CmmLex.x
544 # XXX Should this be unconditional? Do we want to support making a src dist
545 # from an unbuilt tree?
546 copy_generated_compiler_file = \
547   if test -f $(FPTOOLS_TOP_ABS)/compiler/dist-stage2/build/$2.hs; \
548   then \
549     $(CP) $(FPTOOLS_TOP_ABS)/compiler/dist-stage2/build/$2.hs compiler/$1/ ; \
550     mv compiler/$1/$2.$3 compiler/$1/$2.$3.source ; \
551   fi
552 copy_generated_util_file = \
553   if test -f $(FPTOOLS_TOP_ABS)/utils/$1/dist-install/build/$1/$1-tmp/$2.hs; \
554   then \
555     $(CP) $(FPTOOLS_TOP_ABS)/utils/$1/dist-install/build/$1/$1-tmp/$2.hs utils/$1/ ; \
556     mv utils/$1/$2.$3 utils/$1/$2.$3.source ; \
557   fi
558
559 dist ::
560         $(RM) -rf $(SRC_DIST_DIR)
561         $(RM) $(SRC_DIST_NAME).tar.gz
562         mkdir $(SRC_DIST_DIR)
563         ( cd $(SRC_DIST_DIR) \
564           && for i in $(SRC_DIST_DIRS); do mkdir $$i; (cd $$i && lndir $(FPTOOLS_TOP_ABS)/$$i ); done \
565           && for i in $(SRC_DIST_FILES); do $(LN_S) $(FPTOOLS_TOP_ABS)/$$i .; done \
566           && $(MAKE) distclean \
567           && if test -f $(FPTOOLS_TOP_ABS)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs; then $(CP) $(FPTOOLS_TOP_ABS)/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 \
568           && $(call copy_generated_compiler_file,cmm,CmmLex,x) \
569           && $(call copy_generated_compiler_file,cmm,CmmParse,y) \
570           && $(call copy_generated_compiler_file,main,ParsePkgConf,y) \
571           && $(call copy_generated_compiler_file,parser,HaddockLex,x) \
572           && $(call copy_generated_compiler_file,parser,HaddockParse,y) \
573           && $(call copy_generated_compiler_file,parser,Lexer,x) \
574           && $(call copy_generated_compiler_file,parser,Parser,y.pp) \
575           && $(call copy_generated_compiler_file,parser,ParserCore,y) \
576           && $(call copy_generated_util_file,hpc,HpcParser,y) \
577           && $(RM) -rf compiler/stage[123] mk/build.mk \
578           && $(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" \) -print | xargs $(RM) -rf \
579         )
580         $(TAR) chf - $(EXTRA_LIBS) | bzip2 >$(FPTOOLS_TOP_ABS)/$(SRC_DIST_EXTRALIBS_TARBALL)
581         $(RM) -rf $(EXTRA_LIBS)
582         $(TAR) chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(FPTOOLS_TOP_ABS)/$(SRC_DIST_TARBALL)
583
584 # Upload the distribution(s)
585 # Retrying is to work around buggy firewalls that corrupt large file transfers
586 # over SSH.
587 ifneq "$(PublishLocation)" ""
588 dist ::
589         @for i in 0 1 2 3 4 5 6 7 8 9; do \
590                 echo "Try $$i: $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist"; \
591                 if $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist; then break; fi; \
592         done
593         @for i in 0 1 2 3 4 5 6 7 8 9; do \
594                 echo "Try $$i: $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist"; \
595                 if $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist; then break; fi; \
596         done
597 endif
598
599 # -----------------------------------------------------------------------------
600 # HC file bundles
601
602 hc-file-bundle :
603         $(RM) -r ghc-$(ProjectVersion)
604         $(LN_S) . ghc-$(ProjectVersion)
605         $(FIND) ghc-$(ProjectVersion)/compiler \
606              ghc-$(ProjectVersion)/utils \
607              ghc-$(ProjectVersion)/libraries -follow \
608           \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
609         for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/utils ghc-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
610              if test "x$$f" != "x" && test -f `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
611                 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
612              fi; \
613         done;
614         for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/rts -name "*.cmm" -follow -print` ""; do \
615              if test "x$$f" != "x"; then \
616                 echo `echo "$$f" | sed 's/cmm$$/hc/g' ` >> hc-files-to-go ; \
617              fi; \
618         done;
619         echo ghc-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
620         echo ghc-$(ProjectVersion)/compiler/parser/Parser.hs >> hc-files-to-go
621         echo ghc-$(ProjectVersion)/compiler/parser/ParserCore.hs >> hc-files-to-go
622         echo ghc-$(ProjectVersion)/compiler/main/ParsePkgConf.hs >> hc-files-to-go
623         echo ghc-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
624         $(TAR) czf ghc-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
625
626 # -----------------------------------------------------------------------------
627 # Cleaning
628
629 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
630
631 DIST_CLEAN_FILES += config.cache config.status mk/config.h mk/stamp-h \
632         docs/users_guide/ug-book.xml extra-gcc-opts
633
634 # don't clean config.mk: it's needed when cleaning stuff later on
635 LATE_DIST_CLEAN_FILES += mk/config.mk mk/are-validating.mk
636
637 # VERSION is shipped in a source dist
638 MAINTAINER_CLEAN_FILES += VERSION
639
640 extraclean::
641         $(RM) -rf autom4te.cache
642
643 clean distclean ::
644         $(RM) -rf inplace-datadir
645
646 clean distclean ::
647         $(MAKE) -C bindisttest $@
648         if test -d testsuite; then $(MAKE) -C testsuite $@; fi
649
650 # -----------------------------------------------------------------------------
651
652 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
653 NO_BOOT_TARGET=YES
654 NO_ALL_TARGET=YES
655 NO_INSTALL_TARGET=YES
656
657 include $(TOP)/mk/target.mk
658
659 # -----------------------------------------------------------------------------
660