[project @ 2003-11-11 10:05:11 by simonmar]
[ghc.git] / Makefile
1 ############################################################################
2 #
3 # fptools/Makefile
4 #
5 # This is the main Makefile for fptools.
6 #
7 ############################################################################
8
9 TOP=.
10 include $(TOP)/mk/boilerplate.mk
11
12 # find the projects that actually exist...
13 ProjectsThatExist = $(filter $(patsubst %/, %, $(wildcard */)), $(AllProjects))
14
15 # and filter only those that the user requested, if necessary
16 ifeq "$(ProjectsToBuild)" ""
17 SUBDIRS = $(ProjectsThatExist)
18 else
19 SUBDIRS = $(filter $(ProjectsToBuild), $(ProjectsThatExist))
20 endif
21
22 ifneq "$(Project)" ""
23 ifeq "$(Project)" "GreenCard"
24 ProjectDirectory=greencard
25 else
26 ifeq "$(Project)" "HaskellDirect"
27 ProjectDirectory=hdirect
28 else
29 ProjectDirectory=$(Project)
30 endif
31 endif
32 include $(shell echo $(ProjectDirectory) | tr A-Z a-z)/mk/config.mk
33 endif
34
35 # -----------------------------------------------------------------------------
36 # Certain targets require that Project is set from the command line.
37
38 CURRENT_TARGET = $(MAKECMDGOALS)
39 project-check :
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"; \
43 exit 1; \
44 fi
45
46 # -----------------------------------------------------------------------------
47 # Targets: all, stage1, stage2, stage3
48
49 DIST_CLEAN_FILES += config.cache config.status
50
51 extraclean::
52 $(RM) -rf autom4te.cache
53
54 #
55 # If you've ended up using an in-place version of Happy,
56 # make sure it gets built early on.
57 #
58 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
59 build : $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
60
61 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
62 $(MAKE) -C happy boot all
63 endif
64
65 # Build all projects that we know about
66 build :
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 \
69 if [ -d $$i ]; then \
70 $(MAKE) -C $$i boot; \
71 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
72 $(MAKE) -C $$i all; \
73 if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
74 fi; \
75 done
76
77 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
78
79 stage1 : build
80
81 stage2 :
82 $(MAKE) -C ghc/compiler boot stage=2
83 $(MAKE) -C ghc/compiler stage=2
84
85 stage3 :
86 $(MAKE) -C ghc/compiler boot stage=3
87 $(MAKE) -C ghc/compiler stage=3
88
89 bootstrap : bootstrap2
90 bootstrap2 : stage1 stage2
91 bootstrap3 : stage1 stage2 stage3
92
93 all :: bootstrap
94
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.
97 ifeq "$(stage)" ""
98 INSTALL_STAGE = stage=2
99 else
100 INSTALL_STAGE =
101 endif
102
103 else # Not building GHC
104
105 all :: build
106
107 INSTALL_STAGE =
108
109 endif
110
111 boot ::
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.)."
114
115 install ::
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; \
121 fi; \
122 done
123
124 install-docs ::
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; \
130 fi; \
131 done
132
133 # -----------------------------------------------------------------------------
134 # Making a binary distribution
135 #
136 # To make a particular binary distribution:
137 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
138
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.
144 #
145 # For example, the distribution tar file of GCC version 1.40 unpacks
146 # into a subdirectory named `gcc-1.40'.
147 #
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.
151 #
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.
155 #
156 # binary-dist is an FPtools addition for binary distributions
157 #
158
159 binary-dist :: project-check
160
161 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
162 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
163
164 #
165 # list of toplevel directories to include in binary distrib.
166 #
167 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
168 BIN_DIST_DIRS=$($(Project)BinDistDirs)
169
170 binary-dist:: binary-dist-pre
171
172 BIN_DIST_TOP= distrib/Makefile-bin.in \
173 distrib/configure-bin.ac \
174 distrib/INSTALL \
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 \
180 install-sh \
181 config.guess \
182 config.sub \
183 aclocal.m4
184
185 #
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)
189 #
190 .PHONY: binary-dist-pre binary-dist binary-pack
191
192 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
193 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
194
195 binary-dist-pre::
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
198 endif
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; \
224 fi; \
225 done
226
227 binary-dist::
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); \
232 fi; \
233 done;
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) ; \
250 fi
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) ; \
254 fi
255 #
256 # binary dist'ing the documentation.
257 # Which documentation to build/install is hardcoded below.
258 #
259
260 BINDIST_DOC_WAYS = html ps
261 # BINDIST_DOC_WAYS =
262
263 binary-dist ::
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; \
281 fi \
282 done
283
284 # Rename scripts to $i.prl and $i.sh where necessary.
285 # ToDo: do this in a cleaner way...
286
287 ifneq "$($(Project)BinDistPrlScripts)" ""
288 binary-dist::
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; \
292 done
293 endif
294
295 ifneq "$($(Project)BinDistLibPrlScripts)" ""
296 binary-dist::
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; \
300 done
301 endif
302
303 ifneq "$($(Project)BinDistShScripts)" ""
304 binary-dist::
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; \
308 done
309 endif
310
311 #
312 # Do this separately for now
313 #
314 binary-pack::
315 ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
316
317 ifneq "$(way)" ""
318 .PHONY: package-way-dist
319 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
322 endif
323
324 ifneq "$(way)" ""
325 remove-way-dist::
326 ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
327 endif
328
329 binary-dist::
330 @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
331
332 # -----------------------------------------------------------------------------
333 # Building source distributions
334 #
335 # Do it like this:
336 #
337 # $ make
338 # $ make dist Project=Ghc
339 #
340 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
341 #
342
343 .PHONY: dist
344
345 #
346 # Directory in which we're going to build the src dist
347 #
348 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
349
350 #
351 # Files to include in source distributions
352 #
353 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
354 SRC_DIST_FILES += \
355 configure.ac config.guess config.sub configure \
356 aclocal.m4 README Makefile Makefile.config install-sh \
357 mk/bootstrap.mk \
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
360
361 dist dist-manifest dist-package :: project-check
362
363 # clean the tree first, leaving certain extra files in place (eg. configure)
364 dist :: distclean
365
366 dist ::
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
373
374 # Automatic generation of a MANIFEST file for a source distribution
375 # tree that is ready to go.
376 dist-manifest ::
377 cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
378
379 dist-package :: dist-package-tar-gz
380
381 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
382
383 dist-package-tar-gz ::
384 $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
385
386 dist-package-zip ::
387 cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
388 $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
389
390 # -----------------------------------------------------------------------------
391 # HC file bundles
392
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 ; \
403 fi; \
404 done;
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`
412
413 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
414
415 # -----------------------------------------------------------------------------
416
417 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
418 NO_BOOT_TARGET=YES
419 NO_ALL_TARGET=YES
420 NO_INSTALL_TARGET=YES
421
422 include $(TOP)/mk/target.mk
423
424 # -----------------------------------------------------------------------------
425