[project @ 2003-02-12 10:32:38 by simonmar]
[ghc-hetmet.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=green-card
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 # Making a binary distribution
48 #
49 # To make a particular binary distribution: 
50 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
51
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.
57 #
58 #      For example, the distribution tar file of GCC version 1.40 unpacks
59 #      into a subdirectory named `gcc-1.40'.
60
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.
64
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.
68 #
69 #       binary-dist is an FPtools addition for binary distributions
70
71
72 binary-dist :: project-check
73
74 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
75 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
76
77 #
78 # list of toplevel directories to include in binary distrib.
79 #
80 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
81 BIN_DIST_DIRS=$($(Project)BinDistDirs)
82
83 binary-dist:: binary-dist-pre
84
85 BIN_DIST_TOP= distrib/Makefile-bin.in \
86               distrib/configure-bin.in \
87               distrib/INSTALL \
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 \
93               install-sh \
94               config.guess \
95               config.sub   \
96               aclocal.m4
97
98 #
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)
102 #
103 .PHONY: binary-dist-pre binary-dist binary-pack
104
105 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
106 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
107
108 binary-dist-pre::
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
111 endif
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; \
137           fi; \
138         done
139
140 binary-dist::
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); \
145           fi; \
146         done;
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) ; \
163         fi
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) ; \
167         fi
168 #
169 # binary dist'ing the documentation.  
170 # Which documentation to build/install is hardcoded below.
171 #
172
173 BINDIST_DOC_WAYS = html ps
174 # BINDIST_DOC_WAYS =
175
176 binary-dist ::
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; \
194           fi \
195         done
196
197 # Rename scripts to $i.prl and $i.sh where necessary.
198 # ToDo: do this in a cleaner way...
199
200 ifneq "$($(Project)BinDistPrlScripts)" ""
201 binary-dist::
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; \
205         done
206 endif
207
208 ifneq "$($(Project)BinDistLibPrlScripts)" ""
209 binary-dist::
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; \
213         done
214 endif
215
216 ifneq "$($(Project)BinDistShScripts)" ""
217 binary-dist::
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; \
221         done
222 endif
223
224 #
225 # Do this separately for now
226
227 binary-pack::
228         ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
229
230 ifneq "$(way)" ""
231 .PHONY: package-way-dist
232 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
235 endif
236
237 ifneq "$(way)" ""
238 remove-way-dist::
239         ( cd $(BIN_DIST_TMPDIR); $(FIND) $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec $(RM) {} \; )
240 endif
241
242 binary-dist::
243         @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
244
245 # -----------------------------------------------------------------------------
246 # Building source distributions
247 #
248 # Do it like this: 
249 #
250 #       $ make
251 #       $ make dist Project=Ghc
252 #
253 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
254 #
255
256 .PHONY: dist
257
258 #
259 # Directory in which we're going to build the src dist
260 #
261 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
262
263 #
264 # Files to include in source distributions
265 #
266 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
267 SRC_DIST_FILES += \
268         configure.in config.guess config.sub configure \
269         aclocal.m4 acconfig.h README Makefile Makefile.config install-sh \
270         mk/bootstrap.mk \
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
273
274 dist dist-manifest dist-package :: project-check
275
276 # clean the tree first, leaving certain extra files in place (eg. configure)
277 dist :: distclean
278
279 dist ::
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
286
287 # Automatic generation of a MANIFEST file for a source distribution
288 # tree that is ready to go.
289 dist-manifest ::
290         cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST
291
292 dist-package :: dist-package-tar-gz
293
294 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
295
296 dist-package-tar-gz ::
297         $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
298
299 dist-package-zip ::
300         cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
301                $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
302
303 # -----------------------------------------------------------------------------
304 # HC file bundles
305
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 ; \
317              fi; \
318         done;
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`
326
327 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
328
329 # -----------------------------------------------------------------------------
330
331 DIST_CLEAN_FILES += config.cache config.status
332
333 #
334 # If you've ended up using an in-place version of Happy,
335 # make sure it gets built early on.
336 #
337 ifeq "$(HAPPY)" "$(FPTOOLS_TOP_ABS)/happy/src/happy-inplace"
338 build : $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace
339
340 $(FPTOOLS_TOP_ABS)/happy/src/happy-inplace : glafp-utils
341         $(MAKE) -C happy boot all
342 endif
343
344 # Build all projects that we know about
345 build :
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; \
353               fi; \
354         done
355
356 ifeq "$(findstring ghc, $(SUBDIRS))" "ghc"
357
358 stage1 : build
359
360 stage2 :
361         $(MAKE) -C ghc/compiler boot stage=2
362         $(MAKE) -C ghc/compiler stage=2
363
364 stage3 :
365         $(MAKE) -C ghc/compiler boot stage=3
366         $(MAKE) -C ghc/compiler stage=3
367
368 bootstrap  : bootstrap2
369 bootstrap2 : stage1 stage2
370 bootstrap3 : stage1 stage2 stage3
371
372 all :: bootstrap
373
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.
376 ifeq "$(stage)" ""
377 INSTALL_STAGE = stage=2
378 endif
379
380 else # Not building GHC
381
382 all :: build
383
384 INSTALL_STAGE =
385
386 endif
387
388 boot ::
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.)."
391
392 install ::
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; \
398               fi; \
399         done
400
401 install-docs ::
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; \
407               fi; \
408         done
409
410 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
411 NO_BOOT_TARGET=YES
412 NO_ALL_TARGET=YES
413 NO_INSTALL_TARGET=YES
414
415 include $(TOP)/mk/target.mk
416
417 # -----------------------------------------------------------------------------
418