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=green-card
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 # Making a binary distribution
49 # To make a particular binary distribution:
50 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
52 # `dist' `binary-dist'
53 # Create a distribution tar file for this program. The tar file
54 # should be set up so that the file names in the tar file start with
55 # a subdirectory name which is the name of the package it is a
56 # distribution for. This name can include the version number.
58 # For example, the distribution tar file of GCC version 1.40 unpacks
59 # into a subdirectory named `gcc-1.40'.
61 # The easiest way to do this is to create a subdirectory
62 # appropriately named, use ln or cp to install the proper files in
63 # it, and then tar that subdirectory.
65 # The dist target should explicitly depend on all non-source files
66 # that are in the distribution, to make sure they are up to date in
67 # the distribution. See Making Releases.
69 # binary-dist is an FPtools addition for binary distributions
72 binary-dist :: project-check
74 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
75 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
78 # list of toplevel directories to include in binary distrib.
80 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
81 BIN_DIST_DIRS=$($(Project)BinDistDirs)
83 binary-dist:: binary-dist-pre
85 BIN_DIST_TOP= distrib/Makefile-bin.in \
86 distrib/configure-bin.in \
88 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
89 $(BIN_DIST_MAIN_DIR)/VERSION \
90 $(BIN_DIST_MAIN_DIR)/LICENSE \
91 $(BIN_DIST_MAIN_DIR)/README \
92 glafp-utils/mkdirhier/mkdirhier \
99 # binary-dist creates a binary bundle, set BIN_DIST_NAME
100 # to package name and do `make binary-dist Project=<project-name>'
101 # (normally this just a thing you would do from the toplevel of fptools)
103 .PHONY: binary-dist-pre binary-dist binary-pack
105 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
106 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
109 ifeq "$(BIN_DIST)" ""
110 echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
112 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
113 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
114 -echo "BIN_DIST_DIRS = $(BIN_DIST_DIRS)"
115 @for i in $(BIN_DIST_DIRS); do \
116 if test -d "$$i"; then \
117 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
118 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
119 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
120 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
121 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
122 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
123 echo $(MAKE) -C $$i $(MFLAGS) install \
124 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
125 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
126 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
127 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
128 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
129 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
130 $(MAKE) -C $$i $(MFLAGS) install \
131 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
132 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
133 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
134 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
135 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
136 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
141 @for i in $(BIN_DIST_TOP); do \
142 if test -f "$$i"; then \
143 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
144 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
147 @echo "Configuring the Makefile for this project..."
148 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
149 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
150 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
151 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
152 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
153 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
154 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
155 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
156 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
157 @echo "Generating a shippable configure script.."
158 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.in $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.in
159 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
160 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
161 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
162 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
164 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
165 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
166 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
169 # binary dist'ing the documentation.
170 # Which documentation to build/install is hardcoded below.
173 BINDIST_DOC_WAYS = html ps
177 @for i in $(BIN_DIST_DIRS); do \
178 if test -d "$$i"; then \
179 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
180 echo $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
181 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
182 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
183 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
184 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
185 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
186 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
187 $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
188 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
189 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
190 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
191 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
192 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
193 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
197 # Rename scripts to $i.prl and $i.sh where necessary.
198 # ToDo: do this in a cleaner way...
200 ifneq "$($(Project)BinDistPrlScripts)" ""
202 @for i in $($(Project)BinDistPrlScripts); do \
203 echo "Renaming $$i to $$i.prl"; \
204 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
208 ifneq "$($(Project)BinDistLibPrlScripts)" ""
210 @for i in $($(Project)BinDistLibPrlScripts); do \
211 echo "Renaming $$i to $$i.prl"; \
212 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
216 ifneq "$($(Project)BinDistShScripts)" ""
218 @for i in $($(Project)BinDistShScripts); do \
219 echo "Renaming $$i to $$i.sh"; \
220 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
225 # Do this separately for now
228 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
231 .PHONY: package-way-dist
233 ( 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 )
234 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
239 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
243 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
245 # -----------------------------------------------------------------------------
246 # Building source distributions
251 # $ make dist Project=Ghc
253 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
259 # Directory in which we're going to build the src dist
261 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
264 # Files to include in source distributions
266 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
268 configure.in config.guess config.sub configure \
269 aclocal.m4 acconfig.h README Makefile Makefile.config install-sh \
271 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
272 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk
274 dist dist-manifest dist-package :: project-check
276 # clean the tree first, leaving certain extra files in place (eg. configure)
280 -rm -rf $(SRC_DIST_DIR)
281 -$(RM) $(SRC_DIST_NAME).tar.gz
282 mkdir $(SRC_DIST_DIR)
283 mkdir $(SRC_DIST_DIR)/mk
284 $(FIND) $(SRC_DIST_DIRS) -type d \( -name CVS -prune -o -name SRC -prune -o -print \) | sed -e 's!.*!mkdir "$(SRC_DIST_DIR)/&"!' | sh
285 $(FIND) $(SRC_DIST_DIRS) $(SRC_DIST_FILES) -name CVS -prune -o -name SRC -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
287 # Automatic generation of a MANIFEST file for a source distribution
288 # tree that is ready to go.
290 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
292 dist-package :: dist-package-tar-gz
294 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
296 dist-package-tar-gz ::
297 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
300 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
301 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
303 # -----------------------------------------------------------------------------
306 hc-file-bundle : project-check
307 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
308 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
309 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
310 $(ProjectNameShort)-$(ProjectVersion)/ghc/driver \
311 $(ProjectNameShort)-$(ProjectVersion)/libraries \
312 $(ProjectNameShort)-$(ProjectVersion)/hslibs \
313 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
314 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/driver $(ProjectNameShort)-$(ProjectVersion)/libraries $(ProjectNameShort)-$(ProjectVersion)/hslibs -name "*.hsc" -print` ""; do \
315 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
316 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
319 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
320 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/*.hs-incl >> hc-files-to-go
321 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
322 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
323 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
324 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
325 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
327 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
329 # -----------------------------------------------------------------------------
331 DIST_CLEAN_FILES += config.cache config.status
334 # If you've ended up using an in-place version of Happy,
335 # make sure it gets built early on.
337 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
338 build : $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
340 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
341 $(MAKE) -C happy boot all
344 # Build all projects that we know about
346 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
347 for i in $(SUBDIRS); do \
348 if [ -d $$i ]; then \
349 $(MAKE) -C $$i boot; \
350 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
351 $(MAKE) -C $$i all; \
352 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
356 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
361 $(MAKE) -C ghc/compiler boot stage=2
362 $(MAKE) -C ghc/compiler stage=2
365 $(MAKE) -C ghc/compiler boot stage=3
366 $(MAKE) -C ghc/compiler stage=3
368 bootstrap : bootstrap2
369 bootstrap2 : stage1 stage2
370 bootstrap3 : stage1 stage2 stage3
374 # We want to install the stage 2 bootstrapped compiler by default, but we let
375 # the user override this by saying 'make install stage=1', for example.
377 INSTALL_STAGE = stage=2
380 else # Not building GHC
389 @echo "Please use \`make all' only from the top-level, or \`make boot' followed"
390 @echo "by \`make all' in an individual project subdirectory (ghc, hslibs etc.)."
393 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
394 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
395 if [ -d $$i ]; then \
396 $(MAKE) -C $$i $(INSTALL_STAGE) install; \
397 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
402 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
403 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
404 if [ -d $$i ]; then \
405 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
406 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
410 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
413 NO_INSTALL_TARGET=YES
415 include $(TOP)/mk/target.mk
417 # -----------------------------------------------------------------------------