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 include $(shell echo $(Project) | tr A-Z a-z)/mk/config.mk
26 # -----------------------------------------------------------------------------
27 # Certain targets require that Project is set from the command line.
29 CURRENT_TARGET = $(MAKECMDGOALS)
31 @if [ "$(Project)" = "" ]; then \
32 echo " You need to set \"Project\" in order to make $(CURRENT_TARGET)"; \
33 echo " eg. make $(CURRENT_TARGET) Project=Ghc"; \
37 # -----------------------------------------------------------------------------
38 # Making a binary distribution
40 # To make a particular binary distribution:
41 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
43 # `dist' `binary-dist'
44 # Create a distribution tar file for this program. The tar file
45 # should be set up so that the file names in the tar file start with
46 # a subdirectory name which is the name of the package it is a
47 # distribution for. This name can include the version number.
49 # For example, the distribution tar file of GCC version 1.40 unpacks
50 # into a subdirectory named `gcc-1.40'.
52 # The easiest way to do this is to create a subdirectory
53 # appropriately named, use ln or cp to install the proper files in
54 # it, and then tar that subdirectory.
56 # The dist target should explicitly depend on all non-source files
57 # that are in the distribution, to make sure they are up to date in
58 # the distribution. See Making Releases.
60 # binary-dist is an FPtools addition for binary distributions
63 binary-dist :: project-check
65 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
66 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
69 # list of toplevel directories to include in binary distrib.
71 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
72 BIN_DIST_DIRS=$($(Project)BinDistDirs)
74 binary-dist:: binary-dist-pre
76 BIN_DIST_TOP= distrib/Makefile-bin.in \
77 distrib/configure-bin.in \
79 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
80 $(BIN_DIST_MAIN_DIR)/VERSION \
81 $(BIN_DIST_MAIN_DIR)/LICENSE \
82 $(BIN_DIST_MAIN_DIR)/README \
83 glafp-utils/mkdirhier/mkdirhier \
90 # binary-dist creates a binary bundle, set BIN_DIST_NAME
91 # to package name and do `make binary-dist Project=<project-name>'
92 # (normally this just a thing you would do from the toplevel of fptools)
94 .PHONY: binary-dist-pre binary-dist binary-pack
96 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
97 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
100 ifeq "$(BIN_DIST)" ""
101 echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
103 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
104 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
105 @for i in $(BIN_DIST_DIRS); do \
106 if test -d "$$i"; then \
107 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
108 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
109 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
110 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
111 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
112 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
113 echo $(MAKE) -C $$i $(MFLAGS) install \
114 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
115 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
116 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
117 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
118 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
119 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
120 $(MAKE) -C $$i $(MFLAGS) install \
121 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
122 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
123 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
124 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
125 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
126 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
131 @for i in $(BIN_DIST_TOP); do \
132 if test -f "$$i"; then \
133 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
134 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
137 @echo "Configuring the Makefile for this project..."
138 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
139 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
140 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
141 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
142 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
143 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
144 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
145 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
146 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
147 @echo "Generating a shippable configure script.."
148 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.in $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.in
149 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
150 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
151 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
152 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
154 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
155 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
156 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
159 # binary dist'ing the documentation.
160 # Which documentation to build/install is hardcoded below.
163 BINDIST_DOC_WAYS = html ps
166 @for i in $(BIN_DIST_DIRS); do \
167 if test -d "$$i"; then \
168 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
169 echo $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="html ps" \
170 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
171 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
172 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
173 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
174 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
175 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
176 $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="html ps" \
177 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
178 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
179 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
180 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
181 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
182 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
186 # Rename scripts to $i.prl and $i.sh where necessary.
187 # ToDo: do this in a cleaner way...
189 ifneq "$($(Project)BinDistPrlScripts)" ""
191 @for i in $($(Project)BinDistPrlScripts); do \
192 echo "Renaming $$i to $$i.prl"; \
193 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
197 ifneq "$($(Project)BinDistLibPrlScripts)" ""
199 @for i in $($(Project)BinDistLibPrlScripts); do \
200 echo "Renaming $$i to $$i.prl"; \
201 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
205 ifneq "$($(Project)BinDistShScripts)" ""
207 @for i in $($(Project)BinDistShScripts); do \
208 echo "Renaming $$i to $$i.sh"; \
209 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
214 # Do this separately for now
217 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
220 .PHONY: package-way-dist
222 ( 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 )
223 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
228 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
232 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
234 # -----------------------------------------------------------------------------
235 # Building source distributions
240 # $ make dist Project=Ghc
242 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
248 # Directory in which we're going to build the src dist
250 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
253 # Files to include in source distributions
255 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
257 configure.in config.guess config.sub configure \
258 aclocal.m4 acconfig.h README Makefile Makefile.config install-sh \
260 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
261 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk
263 dist dist-manifest dist-package :: project-check
265 # clean the tree first, leaving certain extra files in place (eg. configure)
269 -rm -rf $(SRC_DIST_DIR)
270 -$(RM) $(SRC_DIST_NAME).tar.gz
271 mkdir $(SRC_DIST_DIR)
272 mkdir $(SRC_DIST_DIR)/mk
273 ( cd $(FPTOOLS_TOP_ABS); $(FIND) $(SRC_DIST_DIRS) -type d \( -name CVS -prune -o -name SRC -prune -o -print \) | sed -e 's!.*!mkdir "$(SRC_DIST_DIR)/&"!' | sh )
274 ( cd $(FPTOOLS_TOP_ABS); $(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 )
276 # Automatic generation of a MANIFEST file for a source distribution
277 # tree that is ready to go.
279 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
281 dist-package :: dist-package-tar-gz
283 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
285 dist-package-tar-gz ::
286 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
289 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
290 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
292 # -----------------------------------------------------------------------------
295 hc-file-bundle : project-check
296 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
297 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
298 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
299 $(ProjectNameShort)-$(ProjectVersion)/ghc/driver \
300 $(ProjectNameShort)-$(ProjectVersion)/libraries \
301 $(ProjectNameShort)-$(ProjectVersion)/hslibs \
302 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
303 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/driver $(ProjectNameShort)-$(ProjectVersion)/libraries $(ProjectNameShort)-$(ProjectVersion)/hslibs -name "*.hsc" -print` ""; do \
304 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
305 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
308 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
309 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/*.hs-incl >> hc-files-to-go
310 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
311 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
312 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
313 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
314 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
316 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
318 # -----------------------------------------------------------------------------
320 DIST_CLEAN_FILES += config.cache config.status
323 # If you've ended up using an in-place version of Happy,
324 # make sure it gets built early on.
326 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
327 build : $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
329 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
330 $(MAKE) -C happy boot all
333 # Build all projects that we know about
335 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
336 for i in $(SUBDIRS); do \
337 if [ -d $$i ]; then \
338 $(MAKE) -C $$i boot; \
339 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
340 $(MAKE) -C $$i all; \
341 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
345 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
350 $(MAKE) -C ghc/compiler boot stage=2
351 $(MAKE) -C ghc/compiler stage=2
354 $(MAKE) -C ghc/compiler boot stage=3
355 $(MAKE) -C ghc/compiler stage=3
357 bootstrap : bootstrap2
358 bootstrap2 : stage1 stage2
359 bootstrap3 : stage1 stage2 stage3
363 # We want to install the stage 2 bootstrapped compiler by default, but we let
364 # the user override this by saying 'make install stage=1', for example.
366 INSTALL_STAGE = stage=2
369 else # Not building GHC
378 @echo "Please use \`make all' only from the top-level, or \`make boot' followed"
379 @echo "by \`make all' in an individual project subdirectory (ghc, hslibs etc.)."
382 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
383 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
384 if [ -d $$i ]; then \
385 $(MAKE) -C $$i $(INSTALL_STAGE) install; \
386 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
391 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
392 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
393 if [ -d $$i ]; then \
394 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
395 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
399 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
402 NO_INSTALL_TARGET=YES
404 include $(TOP)/mk/target.mk
406 # -----------------------------------------------------------------------------