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