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 @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
126 for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
127 if [ -d $$i ]; then \
128 $(MAKE) -C $$i $(INSTALL_STAGE) install-docs; \
129 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
133 # -----------------------------------------------------------------------------
134 # Making a binary distribution
136 # To make a particular binary distribution:
137 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
139 # `dist' `binary-dist'
140 # Create a distribution tar file for this program. The tar file
141 # should be set up so that the file names in the tar file start with
142 # a subdirectory name which is the name of the package it is a
143 # distribution for. This name can include the version number.
145 # For example, the distribution tar file of GCC version 1.40 unpacks
146 # into a subdirectory named `gcc-1.40'.
148 # The easiest way to do this is to create a subdirectory
149 # appropriately named, use ln or cp to install the proper files in
150 # it, and then tar that subdirectory.
152 # The dist target should explicitly depend on all non-source files
153 # that are in the distribution, to make sure they are up to date in
154 # the distribution. See Making Releases.
156 # binary-dist is an FPtools addition for binary distributions
159 binary-dist :: project-check
161 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
162 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
165 # list of toplevel directories to include in binary distrib.
167 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
168 BIN_DIST_DIRS=$($(Project)BinDistDirs)
170 binary-dist:: binary-dist-pre
172 BIN_DIST_TOP= distrib/Makefile-bin.in \
173 distrib/configure-bin.ac \
175 $(BIN_DIST_MAIN_DIR)/ANNOUNCE \
176 $(BIN_DIST_MAIN_DIR)/VERSION \
177 $(BIN_DIST_MAIN_DIR)/LICENSE \
178 $(BIN_DIST_MAIN_DIR)/README \
179 glafp-utils/mkdirhier/mkdirhier \
186 # binary-dist creates a binary bundle, set BIN_DIST_NAME
187 # to package name and do `make binary-dist Project=<project-name>'
188 # (normally this just a thing you would do from the toplevel of fptools)
190 .PHONY: binary-dist-pre binary-dist binary-pack
192 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
193 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
196 ifeq "$(BIN_DIST)" ""
197 echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in your build.mk" && exit 1
199 -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
200 -$(RM) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
201 -echo "BIN_DIST_DIRS = $(BIN_DIST_DIRS)"
202 @for i in $(BIN_DIST_DIRS); do \
203 if test -d "$$i"; then \
204 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
205 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
206 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
207 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
208 echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
209 $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
210 echo $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
211 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
212 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
213 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
214 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
215 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
216 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
217 $(MAKE) -C $$i $(MFLAGS) $(INSTALL_STAGE) install \
218 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
219 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
220 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
221 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
222 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
223 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
228 @for i in $(BIN_DIST_TOP); do \
229 if test -f "$$i"; then \
230 echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
231 cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
234 @echo "Configuring the Makefile for this project..."
235 touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
236 echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
237 echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
238 echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
239 echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
240 echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
241 echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
242 echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
243 cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
244 @echo "Generating a shippable configure script.."
245 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.ac $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.ac
246 ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
247 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
248 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
249 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
251 if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
252 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
253 $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
256 # binary dist'ing the documentation.
257 # Which documentation to build/install is hardcoded below.
260 BINDIST_DOC_WAYS = html ps
264 @for i in $(BIN_DIST_DIRS); do \
265 if test -d "$$i"; then \
266 $(MAKE) -C $$i $(MFLAGS) $(BINDIST_DOC_WAYS); \
267 echo $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
268 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
269 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
270 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
271 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
272 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
273 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
274 $(MAKE) -C $$i $(MFLAGS) install-docs SGMLDocWays="$(BINDIST_DOC_WAYS)" \
275 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
276 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
277 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
278 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
279 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
280 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
284 # Rename scripts to $i.prl and $i.sh where necessary.
285 # ToDo: do this in a cleaner way...
287 ifneq "$($(Project)BinDistPrlScripts)" ""
289 @for i in $($(Project)BinDistPrlScripts); do \
290 echo "Renaming $$i to $$i.prl"; \
291 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
295 ifneq "$($(Project)BinDistLibPrlScripts)" ""
297 @for i in $($(Project)BinDistLibPrlScripts); do \
298 echo "Renaming $$i to $$i.prl"; \
299 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
303 ifneq "$($(Project)BinDistShScripts)" ""
305 @for i in $($(Project)BinDistShScripts); do \
306 echo "Renaming $$i to $$i.sh"; \
307 $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
312 # Do this separately for now
315 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
318 .PHONY: package-way-dist
320 ( 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 )
321 gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
326 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
330 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
332 # -----------------------------------------------------------------------------
333 # Building source distributions
338 # $ make dist Project=Ghc
340 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
346 # Directory in which we're going to build the src dist
348 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
351 # Files to include in source distributions
353 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
355 configure.ac config.guess config.sub configure \
356 aclocal.m4 README Makefile Makefile.config install-sh \
358 mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
359 mk/paths.mk mk/package.mk mk/suffix.mk mk/target.mk
361 dist dist-manifest dist-package :: project-check
363 # clean the tree first, leaving certain extra files in place (eg. configure)
367 -rm -rf $(SRC_DIST_DIR)
368 -$(RM) $(SRC_DIST_NAME).tar.gz
369 mkdir $(SRC_DIST_DIR)
370 mkdir $(SRC_DIST_DIR)/mk
371 $(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
372 $(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
374 # Automatic generation of a MANIFEST file for a source distribution
375 # tree that is ready to go.
377 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
379 dist-package :: dist-package-tar-gz
381 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
383 dist-package-tar-gz ::
384 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
387 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
388 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
390 # -----------------------------------------------------------------------------
393 hc-file-bundle : project-check
394 $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
395 $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
396 $(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
397 $(ProjectNameShort)-$(ProjectVersion)/ghc/utils \
398 $(ProjectNameShort)-$(ProjectVersion)/libraries -follow \
399 \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
400 for f in `$(FIND) $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler $(ProjectNameShort)-$(ProjectVersion)/ghc/utils $(ProjectNameShort)-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
401 if test "x$$f" != "x" && test -e `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
402 echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
405 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/rts/AutoApply.hc >> hc-files-to-go
406 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
407 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/Parser.hs >> hc-files-to-go
408 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/parser/ParserCore.hs >> hc-files-to-go
409 echo $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler/main/ParsePkgConf.hs >> hc-files-to-go
410 echo $(ProjectNameShort)-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
411 tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
413 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
415 # -----------------------------------------------------------------------------
417 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
420 NO_INSTALL_TARGET=YES
422 include $(TOP)/mk/target.mk
424 # -----------------------------------------------------------------------------