1 ############################################################################
5 # This is the main Makefile for fptools.
7 ############################################################################
10 include $(TOP)/mk/boilerplate.mk
12 # find the projects that actually exist...
13 ProjectsThatExist = $(filter $(patsubst %/, %, $(wildcard */)), $(AllProjects))
15 # and filter only those that the user requested, if necessary
16 ifeq "$(ProjectsToBuild)" ""
17 SUBDIRS = $(ProjectsThatExist)
19 SUBDIRS = $(filter $(ProjectsToBuild), $(ProjectsThatExist))
23 ifeq "$(Project)" "GreenCard"
24 ProjectDirectory=greencard
26 ifeq "$(Project)" "HaskellDirect"
27 ProjectDirectory=hdirect
29 ProjectDirectory=$(Project)
32 -include $(shell echo $(ProjectDirectory) | tr A-Z a-z)/mk/config.mk
33 -include $(shell echo $(ProjectDirectory) | tr A-Z a-z)/mk/version.mk
36 # -----------------------------------------------------------------------------
37 # Certain targets require that Project is set from the command line.
39 CURRENT_TARGET = $(MAKECMDGOALS)
41 @if [ "$(Project)" = "" ]; then \
42 echo " You need to set \"Project\" in order to make $(CURRENT_TARGET)"; \
43 echo " eg. make $(CURRENT_TARGET) Project=Ghc"; \
47 # -----------------------------------------------------------------------------
48 # Targets: all, stage1, stage2, stage3
50 DIST_CLEAN_FILES += config.cache config.status
53 $(RM) -rf autom4te.cache
56 # If you've ended up using an in-place version of Happy,
57 # make sure it gets built early on.
59 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
60 build :: $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
62 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
63 $(MAKE) -C happy boot all
66 # Build all projects that we know about
68 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
69 for i in $(SUBDIRS); do \
71 $(MAKE) -C $$i boot; \
72 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
74 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
78 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
80 .PHONY: stage1 stage2 stage3 bootstrap bootstrap2 bootstrap3
85 $(MAKE) -C ghc/compiler boot stage=2
86 $(MAKE) -C ghc/compiler stage=2
89 $(MAKE) -C ghc/compiler boot stage=3
90 $(MAKE) -C ghc/compiler stage=3
92 bootstrap : bootstrap2
97 bootstrap3 : bootstrap2
102 # We want to install the stage 2 bootstrapped compiler by default, but we let
103 # the user override this by saying 'make install stage=1', for example.
105 INSTALL_STAGE = stage=2
110 else # Not building GHC
119 @echo "Please use \`make all' only from the top-level, or \`make boot' followed"
120 @echo "by \`make all' in an individual project subdirectory (ghc, hslibs etc.)."
123 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
124 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
125 if [ -d $$i ]; then \
126 $(MAKE) -C $$i $(INSTALL_STAGE) install; \
127 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
131 # If installing on Windows with MinGW32, copy the gcc compiler, headers and libs
132 # and the perl interpreter and dll into the GHC prefix directory.
133 # Gcc and Perl source locations derived from configuration data.
134 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
135 ifneq "$(WhatGccIsCalled)" ""
137 -mkdir $(prefix)/gcc-lib
138 -mkdir $(prefix)/include
139 -mkdir $(prefix)/include/mingw
140 -cp -rp $(GccDir)../include/* $(prefix)/include/mingw
141 -cp -rp $(GccDir)../lib/gcc-lib/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
142 -cp $(GccDir)../lib/*.* $(prefix)/gcc-lib
143 -cp $(GccDir)gcc.exe $(prefix)
144 -cp $(GccDir)as.exe $(prefix)/gcc-lib
145 -cp $(GccDir)ld.exe $(prefix)/gcc-lib
146 -cp $(GccDir)dllwrap.exe $(prefix)/gcc-lib
147 -cp $(GccDir)dlltool.exe $(prefix)/gcc-lib
148 -cp $(GhcDir)../perl.exe $(prefix)
149 -cp $(GhcDir)../perl56.dll $(prefix)
154 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
155 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
156 if [ -d $$i ]; then \
157 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
158 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
162 # -----------------------------------------------------------------------------
163 # Making a binary distribution
165 # To make a particular binary distribution:
166 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
168 # `dist' `binary-dist'
169 # Create a distribution tar file for this program. The tar file
170 # should be set up so that the file names in the tar file start with
171 # a subdirectory name which is the name of the package it is a
172 # distribution for. This name can include the version number.
174 # For example, the distribution tar file of GCC version 1.40 unpacks
175 # into a subdirectory named `gcc-1.40'.
177 # The easiest way to do this is to create a subdirectory
178 # appropriately named, use ln or cp to install the proper files in
179 # it, and then tar that subdirectory.
181 # The dist target should explicitly depend on all non-source files
182 # that are in the distribution, to make sure they are up to date in
183 # the distribution. See Making Releases.
185 # binary-dist is an FPtools addition for binary distributions
188 binary-dist :: project-check
190 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
191 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
194 # list of toplevel directories to include in binary distrib.
196 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
197 BIN_DIST_DIRS=$($(Project)BinDistDirs)
199 binary-dist:: binary-dist-pre
201 BIN_DIST_TOP= distrib/Makefile-bin.in \
202 distrib/configure-bin.ac \
204 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
205 $(BIN_DIST_MAIN_DIR)/VERSION \
206 $(BIN_DIST_MAIN_DIR)/LICENSE \
207 $(BIN_DIST_MAIN_DIR)/README \
208 glafp-utils/mkdirhier/mkdirhier \
215 # binary-dist creates a binary bundle, set BIN_DIST_NAME
216 # to package name and do `make binary-dist Project=<project-name>'
217 # (normally this just a thing you would do from the toplevel of fptools)
219 .PHONY: binary-dist-pre binary-dist binary-pack
221 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
222 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
225 ifeq "$(BIN_DIST)" ""
226 @echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
228 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
229 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
230 -echo "BIN_DIST_DIRS = $(BIN_DIST_DIRS)"
231 @for i in $(BIN_DIST_DIRS); do \
232 if test -d "$$i"; then \
233 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
234 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
235 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
236 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
237 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
238 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
239 echo $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
240 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
241 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
242 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
243 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
244 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
245 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
246 $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
247 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
248 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
249 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
250 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
251 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
252 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
257 @for i in $(BIN_DIST_TOP); do \
258 if test -f "$$i"; then \
259 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
260 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
263 @echo "Configuring the Makefile for this project..."
264 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
265 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
266 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
267 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
268 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
269 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
270 echo "PACKAGE_LIB_SPLICED_FILES = $($(Project)BinDistLibSplicedFiles)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
271 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
272 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
273 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
274 @echo "Generating a shippable configure script.."
275 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.ac $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.ac
276 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
277 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
278 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
279 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
281 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
282 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
283 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
286 # binary dist'ing the documentation.
287 # Which documentation to build/install is hardcoded below.
290 BINDIST_DOC_WAYS = html ps
294 ifneq "$(DIR_DOCBOOK_XSL)" ""
295 @for i in $(BIN_DIST_DIRS); do \
296 if test -d "$$i"; then \
297 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
298 echo $(MAKE) -C $$i $(MFLAGS) install-docs XMLDocWays="$(BINDIST_DOC_WAYS)" \
299 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
300 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
301 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
302 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
303 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
304 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
305 $(MAKE) -C $$i $(MFLAGS) install-docs XMLDocWays="$(BINDIST_DOC_WAYS)" \
306 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
307 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
308 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
309 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
310 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
311 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
316 # Rename scripts to $i.prl and $i.sh where necessary.
317 # ToDo: do this in a cleaner way...
319 ifneq "$($(Project)BinDistPrlScripts)" ""
321 @for i in $($(Project)BinDistPrlScripts); do \
322 echo "Renaming $$i to $$i.prl"; \
323 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
327 ifneq "$($(Project)BinDistLibPrlScripts)" ""
329 @for i in $($(Project)BinDistLibPrlScripts); do \
330 echo "Renaming $$i to $$i.prl"; \
331 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
335 ifneq "$($(Project)BinDistShScripts)" ""
337 @for i in $($(Project)BinDistShScripts); do \
338 if test -x $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i ; then \
339 echo "Renaming $$i to $$i.sh"; \
340 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
346 # Do this separately for now
349 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
352 .PHONY: package-way-dist
354 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print | xargs tar cvf $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar )
355 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
360 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
364 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
366 # -----------------------------------------------------------------------------
367 # Building source distributions
372 # $ make dist Project=Ghc
374 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
380 # Directory in which we're going to build the src dist
382 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
385 # Files to include in source distributions
387 SRC_DIST_DIRS += docs distrib $(filter-out docs distrib,$(SUBDIRS))
389 configure.ac config.guess config.sub configure \
390 aclocal.m4 README Makefile install-sh \
392 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
393 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk \
396 dist dist-manifest dist-package :: project-check
398 # clean the tree first, leaving certain extra files in place (eg. configure)
402 -rm -rf $(SRC_DIST_DIR)
403 -$(RM) $(SRC_DIST_NAME).tar.gz
404 mkdir $(SRC_DIST_DIR)
405 mkdir $(SRC_DIST_DIR)/mk
406 $(FIND) $(SRC_DIST_DIRS) -type d \( -name CVS -prune -o -name SRC -prune -o -name "autom4te*" -prune -o -print \) | sed -e 's!.*!mkdir "$(SRC_DIST_DIR)/&"!' | sh
407 $(FIND) $(SRC_DIST_DIRS) $(SRC_DIST_FILES) -name CVS -prune -o -name SRC -prune -o -name "autom4te*" -prune -o -name "*~" -prune -o -name ".cvsignore" -prune -o -name "\#*" -prune -o -name ".\#*" -prune -o -name "log" -prune -o -name "*-SAVE" -prune -o -name "*.orig" -prune -o -name "*.rej" -prune -o ! -type d -print | sed -e 's!.*!$(LN_S) "$(FPTOOLS_TOP_ABS)/&" "$(SRC_DIST_DIR)/&"!' | sh
409 # Automatic generation of a MANIFEST file for a source distribution
410 # tree that is ready to go.
412 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
414 dist-package :: dist-package-tar-gz
416 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
418 dist-package-tar-bz2 ::
419 BZIP2=-9 $(TAR) chjf $(SRC_DIST_NAME)-src.tar.bz2 $(SRC_DIST_NAME) || $(RM) $(SRC_DIST_NAME)-src.tar.bz2
421 dist-package-tar-gz ::
422 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME) || $(RM) $(SRC_DIST_NAME)-src.tar.gz
425 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
426 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
428 # -----------------------------------------------------------------------------
431 hc-file-bundle : project-check
432 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
433 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
434 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
435 $(ProjectNameShort)-$(ProjectVersion)/ghc/utils \
436 $(ProjectNameShort)-$(ProjectVersion)/ghc/lib \
437 $(ProjectNameShort)-$(ProjectVersion)/libraries -follow \
438 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
439 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/utils $(ProjectNameShort)-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
440 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
441 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
444 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/rts -name "*.cmm" -follow -print` ""; do \
445 if test "x$$f" != "x"; then \
446 echo `echo "$$f" | sed 's/cmm$$/hc/g' ` >> hc-files-to-go ; \
449 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
450 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
451 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
452 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
453 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
454 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
456 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
458 # -----------------------------------------------------------------------------
460 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
463 NO_INSTALL_TARGET=YES
465 include $(TOP)/mk/target.mk
467 # -----------------------------------------------------------------------------