[project @ 2001-11-15 15:04:36 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    include $(shell echo $(Project) | tr A-Z a-z)/mk/config.mk
24 endif
25
26 # -----------------------------------------------------------------------------
27 # Certain targets require that Project is set from the command line.
28
29 CURRENT_TARGET = $(MAKECMDGOALS)
30 project-check :
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"; \
34                 exit 1; \
35         fi
36
37 # -----------------------------------------------------------------------------
38 # Making a binary distribution
39 #
40 # To make a particular binary distribution: 
41 # set $(Project) to the name of the project, capitalised (eg. Ghc or Happy).
42
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.
48 #
49 #      For example, the distribution tar file of GCC version 1.40 unpacks
50 #      into a subdirectory named `gcc-1.40'.
51
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.
55
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.
59 #
60 #       binary-dist is an FPtools addition for binary distributions
61
62
63 binary-dist :: project-check
64
65 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
66 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
67
68 #
69 # list of toplevel directories to include in binary distrib.
70 #
71 BIN_DIST_MAIN_DIR=$($(Project)MainDir)
72 BIN_DIST_DIRS=$($(Project)BinDistDirs)
73
74 binary-dist:: binary-dist-pre
75
76 BIN_DIST_TOP= distrib/Makefile-bin.in \
77               distrib/configure-bin.in \
78               distrib/INSTALL \
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 \
84               install-sh \
85               config.guess \
86               config.sub   \
87               aclocal.m4
88
89 #
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)
93 #
94 .PHONY: binary-dist-pre binary-dist binary-pack
95
96 BIN_DIST_NAME=$(ProjectNameShort)-$(ProjectVersion)
97 BIN_DIST_TMPDIR=$(FPTOOLS_TOP_ABS)
98
99 binary-dist-pre::
100         -rm -rf $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)
101         -rm -f $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME).tar.gz
102         @for i in $(BIN_DIST_DIRS); do                   \
103           if test -d "$$i"; then                         \
104            echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
105            $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM); \
106            echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
107            $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM); \
108            echo $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
109            $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
110            echo $(MAKE) -C $$i $(MFLAGS) install \
111                 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
112                 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
113                 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
114                 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
115                 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
116                 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
117            $(MAKE) -C $$i $(MFLAGS) install \
118                 prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
119                 exec_prefix=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) \
120                 bindir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM) \
121                 libdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
122                 libexecdir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM) \
123                 datadir=$(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/share; \
124           fi; \
125         done
126
127 binary-dist::
128         @for i in $(BIN_DIST_TOP); do \
129           if test -f "$$i"; then \
130              echo cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
131              cp $$i $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); \
132           fi; \
133         done;
134         @echo "Configuring the Makefile for this project..."
135         touch $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
136         echo "package = $(ProjectNameShort)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
137         echo "version = $(ProjectVersion)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
138         echo "PACKAGE_SH_SCRIPTS = $($(Project)BinDistShScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
139         echo "PACKAGE_PRL_SCRIPTS = $($(Project)BinDistPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
140         echo "PACKAGE_LIB_PRL_SCRIPTS = $($(Project)BinDistLibPrlScripts)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
141         echo "PACKAGE_BINS = $($(Project)BinDistBins)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
142         echo "PACKAGE_LINKS = $($(Project)BinDistLinks)" >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
143         cat $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile-bin.in >> $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/Makefile.in
144         @echo "Generating a shippable configure script.."
145         $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure-bin.in $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/configure.in 
146         ( cd $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME); autoconf )
147         if test -x $(BIN_DIST_MAIN_DIR)/mk/post-install-script ; then \
148                 cp $(BIN_DIST_MAIN_DIR)/mk/post-install-script \
149                         $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
150         fi
151         if test -x $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script ; then \
152                 cp $(BIN_DIST_MAIN_DIR)/mk/post-inplace-script \
153                         $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME) ; \
154         fi
155 #
156 # binary dist'ing the documentation.  
157 # Which documentation to build/install is hardcoded below.
158 #
159
160 BINDIST_DOCS = $($(Project)BinDistDocs)
161 BINDIST_DOCS_WAYS = html ps
162
163 binary-dist ::
164         @for way in $(BINDIST_DOCS_WAYS); do \
165            $(MKDIRHIER) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/$$way; \
166            for dir in $(BINDIST_DOCS); do \
167              echo Making $$way documentation in $$dir && \
168              $(MAKE) -C $$dir --no-print-directory $(MFLAGS) $$way >.doclog  2>&1 && \
169              if [ "$$way" = "html" ]; then \
170                 for subdir in `perl -n -e '/output will be in ([_\-A-Za-z0-9]*)/ && do { print "$$1 "; };' <.doclog`; do \
171                    echo Copying HTML docs from $$subdir...; \
172                    cp -Rf $$dir/$$subdir $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/$$way; \
173                 done \
174              else \
175                 cp -f $$dir/*.$$way $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/$$way; \
176              fi && \
177              echo "Done."; \
178            done; \
179         done
180         @rm -f .doclog
181
182 # Rename scripts to $i.prl and $i.sh where necessary.
183 # ToDo: do this in a cleaner way...
184
185 ifneq "$($(Project)BinDistPrlScripts)" ""
186 binary-dist::
187         @for i in $($(Project)BinDistPrlScripts); do \
188              echo "Renaming $$i to $$i.prl"; \
189             $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i  $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.prl; \
190         done
191 endif
192
193 ifneq "$($(Project)BinDistLibPrlScripts)" ""
194 binary-dist::
195         @for i in $($(Project)BinDistLibPrlScripts); do \
196              echo "Renaming $$i to $$i.prl"; \
197             $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i  $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/lib/$(TARGETPLATFORM)/$$i.prl; \
198         done
199 endif
200
201 ifneq "$($(Project)BinDistShScripts)" ""
202 binary-dist::
203         @for i in $($(Project)BinDistShScripts); do \
204              echo "Renaming $$i to $$i.sh"; \
205             $(MV) $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i  $(BIN_DIST_TMPDIR)/$(BIN_DIST_NAME)/bin/$(TARGETPLATFORM)/$$i.sh; \
206         done
207 endif
208
209 #
210 # Do this separately for now
211
212 binary-pack::
213         ( cd $(BIN_DIST_TMPDIR); $(TAR) chzf $(BIN_DIST_NAME).tar.gz $(BIN_DIST_NAME) )
214
215 ifneq "$(way)" ""
216 package-way-dist::
217         ( 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 )
218         gzip $(BIN_DIST_TMPDIR)/ghc-$(ProjectVersion)-$(way)-$(TARGETPLATFORM).tar
219 endif
220
221 ifneq "$(way)" ""
222 remove-way-dist::
223         ( cd $(BIN_DIST_TMPDIR); find $(BIN_DIST_NAME)/ \( -name "*$(_way).a" -o -name "*.$(way_)hi" \) -print -exec rm -f {} \; )
224 endif
225
226 binary-dist::
227         @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
228
229 # -----------------------------------------------------------------------------
230 # Building source distributions
231 #
232 # Do it like this: 
233 #
234 #       $ make
235 #       $ make dist Project=Ghc
236 #
237 # WARNING: `make dist' calls `make distclean' before tarring up the tree.
238 #
239
240 .PHONY: dist
241
242 #
243 # Directory in which we're going to build the src dist
244 #
245 SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
246
247 #
248 # Files to include in source distributions
249 #
250 SRC_DIST_DIRS += docs distrib $(SUBDIRS)
251 SRC_DIST_FILES += \
252         configure.in config.guess config.sub configure \
253         aclocal.m4 acconfig.h README Makefile Makefile.config install-sh \
254         mk/bootstrap.mk \
255         mk/boilerplate.mk mk/config.h.in mk/config.mk.in mk/opts.mk \
256         mk/paths.mk mk/suffix.mk mk/target.mk
257
258 dist dist-manifest dist-package :: project-check
259
260 # clean the tree first, leaving certain extra files in place (eg. configure)
261 dist :: distclean
262
263 dist ::
264         -rm -rf $(SRC_DIST_DIR)
265         -rm -f $(SRC_DIST_NAME).tar.gz
266         mkdir $(SRC_DIST_DIR)
267         mkdir $(SRC_DIST_DIR)/mk
268         ( 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 )
269         ( cd $(FPTOOLS_TOP_ABS); $(FIND) $(SRC_DIST_DIRS) $(SRC_DIST_FILES) -name CVS -prune -o -name SRC -prune -o -name tests -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 )
270
271 # Automatic generation of a MANIFEST file for a source distribution
272 # tree that is ready to go.
273 dist-manifest ::
274         cd $(SRC_DIST_DIR); $(FIND) . \( -type l -o -type f \) -exec ls -lLG {} \; | sed -e 's/\.\///' > MANIFEST.tmp ; mv MANIFEST.tmp MANIFEST
275
276 dist-package :: dist-package-tar-gz
277
278 SRC_DIST_PATHS = $(patsubst %, $(SRC_DIST_NAME)/%, $(SRC_DIST_FILES) $(SRC_DIST_DIRS))
279
280 dist-package-tar-gz ::
281         $(TAR) chzf $(SRC_DIST_NAME)-src.tar.gz $(SRC_DIST_NAME)
282
283 dist-package-zip ::
284         cd ..; $(LN_S) $(FPTOOLS_TOP_ABS) $(SRC_DIST_NAME) && \
285                $(ZIP) $(ZIP_OPTS) -r $(SRC_DIST_NAME)-src.zip $(SRC_DIST_PATHS)
286
287 # -----------------------------------------------------------------------------
288 # HC file bundles
289
290 hc-file-bundle : project-check
291         $(RM) -r $(ProjectNameShort)-$(ProjectVersion)
292         $(LN_S) . $(ProjectNameShort)-$(ProjectVersion)
293         find $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
294              $(ProjectNameShort)-$(ProjectVersion)/ghc/driver \
295              $(ProjectNameShort)-$(ProjectVersion)/ghc/lib \
296              $(ProjectNameShort)-$(ProjectVersion)/hslibs \
297           -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" > hc-files-to-go
298         find $(ProjectNameShort)-$(ProjectVersion)/ghc/compiler \
299              $(ProjectNameShort)-$(ProjectVersion)/ghc/driver \
300              $(ProjectNameShort)-$(ProjectVersion)/ghc/lib \
301              $(ProjectNameShort)-$(ProjectVersion)/hslibs \
302           -name "*.hsc" | sed 's/hsc$$/hs/g' >> hc-files-to-go
303         tar czf $(ProjectNameShort)-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
304
305 CLEAN_FILES += hc-files-to-go *-hc.tar.gz
306
307 # -----------------------------------------------------------------------------
308
309 DIST_CLEAN_FILES += config.cache config.status
310
311 all ::
312         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
313         for i in $(SUBDIRS); do \
314            if [ -d $$i ]; then \
315               $(MAKE) -C $$i boot all; \
316               if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
317               fi; \
318         done
319
320 boot ::
321         @echo "Please use \`make all' only from the top-level, or \`make boot' followed"
322         @echo "by \`make all' in an individual project subdirectory (ghc, hslibs etc.)."
323
324 install ::
325         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
326         for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
327            if [ -d $$i ]; then \
328               $(MAKE) -C $$i install; \
329               if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
330               fi; \
331         done
332
333 install-docs ::
334         @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
335         for i in $(filter-out $(ProjectsDontInstall), $(SUBDIRS)); do \
336            if [ -d $$i ]; then \
337               $(MAKE) -C $$i install-docs; \
338               if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
339               fi; \
340         done
341
342 # Turn off target.mk's rules for 'all', 'boot' and 'install'.
343 NO_BOOT_TARGET=YES
344 NO_ALL_TARGET=YES
345 NO_INSTALL_TARGET=YES
346
347 include $(TOP)/mk/target.mk
348
349 # -----------------------------------------------------------------------------
350