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