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; \
125 ifneq "$(SGMLDocWays)" ""
126 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
127 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
128 if [ -d $$i ]; then \
129 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
130 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
135 # -----------------------------------------------------------------------------
136 # Making a binary distribution
138 # To make a particular binary distribution:
139 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
141 # `dist' `binary-dist'
142 # Create a distribution tar file for this program. The tar file
143 # should be set up so that the file names in the tar file start with
144 # a subdirectory name which is the name of the package it is a
145 # distribution for. This name can include the version number.
147 # For example, the distribution tar file of GCC version 1.40 unpacks
148 # into a subdirectory named `gcc-1.40'.
150 # The easiest way to do this is to create a subdirectory
151 # appropriately named, use ln or cp to install the proper files in
152 # it, and then tar that subdirectory.
154 # The dist target should explicitly depend on all non-source files
155 # that are in the distribution, to make sure they are up to date in
156 # the distribution. See Making Releases.
158 # binary-dist is an FPtools addition for binary distributions
161 binary-dist :: project-check
163 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
164 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
167 # list of toplevel directories to include in binary distrib.
169 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
170 BIN_DIST_DIRS=$($(Project)BinDistDirs)
172 binary-dist:: binary-dist-pre
174 BIN_DIST_TOP= distrib/Makefile-bin.in \
175 distrib/configure-bin.ac \
177 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
178 $(BIN_DIST_MAIN_DIR)/VERSION \
179 $(BIN_DIST_MAIN_DIR)/LICENSE \
180 $(BIN_DIST_MAIN_DIR)/README \
181 glafp-utils/mkdirhier/mkdirhier \
188 # binary-dist creates a binary bundle, set BIN_DIST_NAME
189 # to package name and do `make binary-dist Project=<project-name>'
190 # (normally this just a thing you would do from the toplevel of fptools)
192 .PHONY: binary-dist-pre binary-dist binary-pack
194 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
195 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
198 ifeq "$(BIN_DIST)" ""
199 @echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
201 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
202 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
203 -echo "BIN_DIST_DIRS = $(BIN_DIST_DIRS)"
204 @for i in $(BIN_DIST_DIRS); do \
205 if test -d "$$i"; then \
206 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
207 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
208 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
209 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
210 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
211 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
212 echo $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
213 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
214 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
215 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
216 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
217 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
218 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
219 $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
220 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
221 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
222 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
223 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
224 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
225 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
230 @for i in $(BIN_DIST_TOP); do \
231 if test -f "$$i"; then \
232 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
233 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
236 @echo "Configuring the Makefile for this project..."
237 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
238 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
239 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
240 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
241 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
242 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
243 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
244 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
245 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
246 @echo "Generating a shippable configure script.."
247 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.ac $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.ac
248 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
249 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
250 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
251 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
253 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
254 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
255 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
258 # binary dist'ing the documentation.
259 # Which documentation to build/install is hardcoded below.
262 ifneq "$(SGMLDocWays)" ""
263 BINDIST_DOC_WAYS = html ps
268 @for i in $(BIN_DIST_DIRS); do \
269 if test -d "$$i"; then \
270 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
271 echo $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
272 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
273 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
274 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
275 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
276 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
277 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
278 $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
279 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
280 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
281 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
282 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
283 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
284 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
288 # Rename scripts to $i.prl and $i.sh where necessary.
289 # ToDo: do this in a cleaner way...
291 ifneq "$($(Project)BinDistPrlScripts)" ""
293 @for i in $($(Project)BinDistPrlScripts); do \
294 echo "Renaming $$i to $$i.prl"; \
295 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
299 ifneq "$($(Project)BinDistLibPrlScripts)" ""
301 @for i in $($(Project)BinDistLibPrlScripts); do \
302 echo "Renaming $$i to $$i.prl"; \
303 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
307 ifneq "$($(Project)BinDistShScripts)" ""
309 @for i in $($(Project)BinDistShScripts); do \
310 echo "Renaming $$i to $$i.sh"; \
311 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
316 # Do this separately for now
319 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
322 .PHONY: package-way-dist
324 ( 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 )
325 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
330 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
334 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
336 # -----------------------------------------------------------------------------
337 # Building source distributions
342 # $ make dist Project=Ghc
344 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
350 # Directory in which we're going to build the src dist
352 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
355 # Files to include in source distributions
357 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
359 configure.ac config.guess config.sub configure \
360 aclocal.m4 README Makefile Makefile.config install-sh \
362 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
363 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk
365 dist dist-manifest dist-package :: project-check
367 # clean the tree first, leaving certain extra files in place (eg. configure)
371 -rm -rf $(SRC_DIST_DIR)
372 -$(RM) $(SRC_DIST_NAME).tar.gz
373 mkdir $(SRC_DIST_DIR)
374 mkdir $(SRC_DIST_DIR)/mk
375 $(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
376 $(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
378 # Automatic generation of a MANIFEST file for a source distribution
379 # tree that is ready to go.
381 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
383 dist-package :: dist-package-tar-gz
385 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
387 dist-package-tar-gz ::
388 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
391 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
392 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
394 # -----------------------------------------------------------------------------
397 hc-file-bundle : project-check
398 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
399 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
400 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
401 $(ProjectNameShort)-$(ProjectVersion)/ghc/utils \
402 $(ProjectNameShort)-$(ProjectVersion)/libraries -follow \
403 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
404 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/utils $(ProjectNameShort)-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
405 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
406 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
409 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/rts/AutoApply.hc >> hc-files-to-go
410 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
411 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
412 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
413 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
414 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
415 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
417 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
419 # -----------------------------------------------------------------------------
421 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
424 NO_INSTALL_TARGET=YES
426 include $(TOP)/mk/target.mk
428 # -----------------------------------------------------------------------------