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
35 # -----------------------------------------------------------------------------
36 # Certain targets require that Project is set from the command line.
38 CURRENT_TARGET = $(MAKECMDGOALS)
40 @if [ "$(Project)" = "" ]; then \
41 echo " You need to set \"Project\" in order to make $(CURRENT_TARGET)"; \
42 echo " eg. make $(CURRENT_TARGET) Project=Ghc"; \
46 # -----------------------------------------------------------------------------
47 # Targets: all, stage1, stage2, stage3
49 DIST_CLEAN_FILES += config.cache config.status
52 $(RM) -rf autom4te.cache
55 # If you've ended up using an in-place version of Happy,
56 # make sure it gets built early on.
58 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
59 build :: $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
61 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
62 $(MAKE) -C happy boot all
65 # Build all projects that we know about
67 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
68 for i in $(SUBDIRS); do \
70 $(MAKE) -C $$i boot; \
71 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
73 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
77 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
82 $(MAKE) -C ghc/compiler boot stage=2
83 $(MAKE) -C ghc/compiler stage=2
86 $(MAKE) -C ghc/compiler boot stage=3
87 $(MAKE) -C ghc/compiler stage=3
89 bootstrap : bootstrap2
90 bootstrap2 : stage1 stage2
91 bootstrap3 : stage1 stage2 stage3
95 # We want to install the stage 2 bootstrapped compiler by default, but we let
96 # the user override this by saying 'make install stage=1', for example.
98 INSTALL_STAGE = stage=2
103 else # Not building GHC
112 @echo "Please use \`make all' only from the top-level, or \`make boot' followed"
113 @echo "by \`make all' in an individual project subdirectory (ghc, hslibs etc.)."
116 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
117 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
118 if [ -d $$i ]; then \
119 $(MAKE) -C $$i $(INSTALL_STAGE) install; \
120 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
124 # If installing on Windows with MinGW32, copy the gcc compiler, headers and libs
125 # and the perl interpreter and dll into the GHC prefix directory.
126 # Gcc and Perl source locations derived from configuration data.
127 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
128 ifneq "$(WhatGccIsCalled)" ""
130 -mkdir $(prefix)/gcc-lib
131 -mkdir $(prefix)/include
132 -mkdir $(prefix)/include/mingw
133 -cp -rp $(GccDir)../include/* $(prefix)/include/mingw
134 -cp -rp $(GccDir)../lib/gcc-lib/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
135 -cp $(GccDir)../lib/*.* $(prefix)/gcc-lib
136 -cp $(GccDir)gcc.exe $(prefix)
137 -cp $(GccDir)as.exe $(prefix)/gcc-lib
138 -cp $(GccDir)ld.exe $(prefix)/gcc-lib
139 -cp $(GccDir)dllwrap.exe $(prefix)/gcc-lib
140 -cp $(GccDir)dlltool.exe $(prefix)/gcc-lib
141 -cp $(GhcDir)../perl.exe $(prefix)
142 -cp $(GhcDir)../perl56.dll $(prefix)
147 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
148 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
149 if [ -d $$i ]; then \
150 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
151 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
155 # -----------------------------------------------------------------------------
156 # Making a binary distribution
158 # To make a particular binary distribution:
159 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
161 # `dist' `binary-dist'
162 # Create a distribution tar file for this program. The tar file
163 # should be set up so that the file names in the tar file start with
164 # a subdirectory name which is the name of the package it is a
165 # distribution for. This name can include the version number.
167 # For example, the distribution tar file of GCC version 1.40 unpacks
168 # into a subdirectory named `gcc-1.40'.
170 # The easiest way to do this is to create a subdirectory
171 # appropriately named, use ln or cp to install the proper files in
172 # it, and then tar that subdirectory.
174 # The dist target should explicitly depend on all non-source files
175 # that are in the distribution, to make sure they are up to date in
176 # the distribution. See Making Releases.
178 # binary-dist is an FPtools addition for binary distributions
181 binary-dist :: project-check
183 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
184 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
187 # list of toplevel directories to include in binary distrib.
189 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
190 BIN_DIST_DIRS=$($(Project)BinDistDirs)
192 binary-dist:: binary-dist-pre
194 BIN_DIST_TOP= distrib/Makefile-bin.in \
195 distrib/configure-bin.ac \
197 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
198 $(BIN_DIST_MAIN_DIR)/VERSION \
199 $(BIN_DIST_MAIN_DIR)/LICENSE \
200 $(BIN_DIST_MAIN_DIR)/README \
201 glafp-utils/mkdirhier/mkdirhier \
208 # binary-dist creates a binary bundle, set BIN_DIST_NAME
209 # to package name and do `make binary-dist Project=<project-name>'
210 # (normally this just a thing you would do from the toplevel of fptools)
212 .PHONY: binary-dist-pre binary-dist binary-pack
214 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
215 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
218 ifeq "$(BIN_DIST)" ""
219 @echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
221 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
222 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
223 -echo "BIN_DIST_DIRS = $(BIN_DIST_DIRS)"
224 @for i in $(BIN_DIST_DIRS); do \
225 if test -d "$$i"; then \
226 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
227 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
228 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
229 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
230 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
231 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
232 echo $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
233 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
234 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
235 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
236 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
237 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
238 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
239 $(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; \
250 @for i in $(BIN_DIST_TOP); do \
251 if test -f "$$i"; then \
252 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
253 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
256 @echo "Configuring the Makefile for this project..."
257 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
258 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
259 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
260 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
261 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
262 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
263 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
264 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
265 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
266 @echo "Generating a shippable configure script.."
267 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.ac $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.ac
268 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
269 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
270 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
271 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
273 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
274 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
275 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
278 # binary dist'ing the documentation.
279 # Which documentation to build/install is hardcoded below.
282 BINDIST_DOC_WAYS = html ps
286 ifneq "$(DOCBOOK_CATALOG)" ""
287 @for i in $(BIN_DIST_DIRS); do \
288 if test -d "$$i"; then \
289 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
290 echo $(MAKE) -C $$i $(MFLAGS) install-docs XMLDocWays="$(BINDIST_DOC_WAYS)" \
291 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
292 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
293 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
294 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
295 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
296 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
297 $(MAKE) -C $$i $(MFLAGS) install-docs XMLDocWays="$(BINDIST_DOC_WAYS)" \
298 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
299 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
300 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
301 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
302 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
303 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
308 # Rename scripts to $i.prl and $i.sh where necessary.
309 # ToDo: do this in a cleaner way...
311 ifneq "$($(Project)BinDistPrlScripts)" ""
313 @for i in $($(Project)BinDistPrlScripts); do \
314 echo "Renaming $$i to $$i.prl"; \
315 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
319 ifneq "$($(Project)BinDistLibPrlScripts)" ""
321 @for i in $($(Project)BinDistLibPrlScripts); do \
322 echo "Renaming $$i to $$i.prl"; \
323 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
327 ifneq "$($(Project)BinDistShScripts)" ""
329 @for i in $($(Project)BinDistShScripts); do \
330 echo "Renaming $$i to $$i.sh"; \
331 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
336 # Do this separately for now
339 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
342 .PHONY: package-way-dist
344 ( 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 )
345 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
350 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
354 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
356 # -----------------------------------------------------------------------------
357 # Building source distributions
362 # $ make dist Project=Ghc
364 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
370 # Directory in which we're going to build the src dist
372 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
375 # Files to include in source distributions
377 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
379 configure.ac config.guess config.sub configure \
380 aclocal.m4 README Makefile Makefile.config install-sh \
382 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
383 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk
385 dist dist-manifest dist-package :: project-check
387 # clean the tree first, leaving certain extra files in place (eg. configure)
391 -rm -rf $(SRC_DIST_DIR)
392 -$(RM) $(SRC_DIST_NAME).tar.gz
393 mkdir $(SRC_DIST_DIR)
394 mkdir $(SRC_DIST_DIR)/mk
395 $(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
396 $(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
398 # Automatic generation of a MANIFEST file for a source distribution
399 # tree that is ready to go.
401 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
403 dist-package :: dist-package-tar-gz
405 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
407 dist-package-tar-gz ::
408 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
411 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
412 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
414 # -----------------------------------------------------------------------------
417 hc-file-bundle : project-check
418 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
419 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
420 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
421 $(ProjectNameShort)-$(ProjectVersion)/ghc/utils \
422 $(ProjectNameShort)-$(ProjectVersion)/libraries -follow \
423 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
424 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/utils $(ProjectNameShort)-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
425 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
426 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
429 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/rts/AutoApply.hc >> hc-files-to-go
430 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
431 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
432 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
433 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
434 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
435 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
437 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
439 # -----------------------------------------------------------------------------
441 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
444 NO_INSTALL_TARGET=YES
446 include $(TOP)/mk/target.mk
448 # -----------------------------------------------------------------------------