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