Remove fgl from the libraries Makefile
[ghc-hetmet.git] / libraries / Makefile
1
2 # To do a fresh build:
3 #
4 #   make clean
5 #   make boot
6 #   make
7 #
8 # To rebuild a particular library <package>:
9 #
10 #   make clean.library.<package>
11 #   make make.library.<package>
12 #
13 # or the following is equivalent:
14 #
15 #   make remake.library.<package>
16 #
17 # To add a new library to the tree, do
18 #
19 #   darcs get http://darcs.haskell.org/packages/foo
20 #   [ -e foo/configure.ac ] && ( cd foo && autoreconf )
21 #   make make.library.foo
22
23 .PHONY: default_target show
24
25 default_target: all
26
27 show:
28         @echo '$(VALUE)="$($(VALUE))"'
29
30 # make doesn't give us an easy way to get the libraries built in
31 # dependency order the first time, but not rebuild base (for example)
32 # when we want to rebuild another library later.
33 # So for now we just don't do anything in parallel in here.
34 .NOTPARALLEL:
35
36 # Ideally we'd just include something to give us variables
37 # for paths and arguments to tools etc, and those set in mk/build.mk.
38 TOP=..
39 include $(TOP)/mk/boilerplate.mk
40
41 SUBDIRS  = ghc-prim $(INTEGER_LIBRARY) base array packedstring
42 SUBDIRS += containers bytestring old-locale old-time filepath directory
43 ifeq "$(GhcLibsWithUnix)" "YES"
44 SUBDIRS += unix
45 endif
46 ifeq "$(Windows)" "YES"
47 SUBDIRS += $(wildcard Win32)
48 endif
49 SUBDIRS += process pretty hpc template-haskell editline Cabal random haskell98
50
51 # Set GhcBootLibs=YES from the command line to work with just the libraries
52 # needed to bootstrap GHC.
53 ifneq "$(GhcBootLibs)" "YES"
54 SUBDIRS += $(wildcard regex-base)
55 SUBDIRS += $(wildcard regex-posix)
56 SUBDIRS += $(wildcard regex-compat)
57 SUBDIRS += $(wildcard parsec)
58 SUBDIRS += $(wildcard haskell-src)
59 SUBDIRS += $(wildcard html)
60 SUBDIRS += $(wildcard network)
61 SUBDIRS += $(wildcard QuickCheck)
62 SUBDIRS += $(wildcard HUnit)
63 SUBDIRS += $(wildcard mtl)
64 SUBDIRS += $(wildcard time)
65 SUBDIRS += $(wildcard OpenGL)
66 SUBDIRS += $(wildcard GLUT)
67 SUBDIRS += $(wildcard OpenAL)
68 SUBDIRS += $(wildcard ALUT)
69 SUBDIRS += $(wildcard stm)
70 SUBDIRS += $(wildcard xhtml)
71 SUBDIRS += $(wildcard cgi)
72 ifeq "$(GhcLibsWithObjectIO)" "YES"
73 SUBDIRS += $(wildcard ObjectIO)
74 endif
75 SUBDIRS += $(wildcard parallel)
76 SUBDIRS_BUILD += $(wildcard ndp)
77 SUBDIRS_BUILD += $(wildcard dph/dph-base)
78 SUBDIRS_BUILD += $(wildcard dph/dph-prim-interface)
79 SUBDIRS_BUILD += $(wildcard dph/dph-prim-seq)
80 SUBDIRS_BUILD += $(wildcard dph/dph-prim-par)
81 SUBDIRS_BUILD += $(wildcard dph/dph)
82 endif
83
84 SUBDIRS += $(SUBDIRS_BUILD)
85
86 # -----------------------------------------------------------------------------
87
88 empty=
89 space=$(empty) $(empty)
90
91 # -----------------------------------------------------------------------------
92
93 ifeq "$(ghc_ge_609)" "YES"
94 GhcLibHcOpts += -fno-warn-deprecated-flags
95 endif
96
97 ifeq "$(RelocatableBuild)" "YES"
98 # On Windows we want to make moveable bindists, but we need to tell
99 # ghc-pkg where the haddock docs are. Therefore we completely ignore
100 # where the user tells us to put the haddock documentation and put it
101 # somewhere whose relative location we know. When installing we need
102 # to give Cabal a real path, though.
103 iprefix             = $$topdir
104 ibindir             = $$topdir
105 ilibdir             = $$topdir
106 ilibexecdir         = $$topdir
107 idynlibdir          = $$topdir
108 idatadir            = $$topdir
109 idocdir             = $$topdir/doc/libraries/$$pkg
110 ihaddockdir         = $$topdir/doc/libraries/$$pkg
111 ihtmldir            = $$httptopdir/doc/libraries/$$pkg
112 html_installed_root = $(prefix)/doc/libraries
113 else
114 # On non-Windows we can just give absolute paths all the time, and
115 # thus obey the htmldir that we are given.
116 iprefix             = $(prefix)
117 ibindir             = $(bindir)
118 ilibdir             = $(libdir)
119 ilibexecdir         = $(libexecdir)
120 idynlibdir          = $(dynlibdir)
121 idatadir            = $(datadir)
122 idocdir             = $(docdir)/libraries/$$pkg
123 ihaddockdir         = $(htmldir)/libraries/$$pkg
124 ihtmldir            = $(htmldir)/libraries/$$pkg
125 html_installed_root = $(htmldir)/libraries
126 endif
127
128 ifneq "$(DOING_BIN_DIST)" "YES"
129
130 CONFIGURE_OPTS =
131 CONFIGURE_STAMP_EXTRAS :=
132
133 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
134 CONFIGURE_OPTS += --enable-library-profiling
135 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
136 endif
137
138 ifneq "$(findstring $(space)dyn$(space), $(space)$(GhcLibWays)$(space))" ""
139 CONFIGURE_OPTS += --enable-shared
140 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
141 endif
142
143 ifeq "$(SplitObjs)" "YES"
144 CONFIGURE_OPTS += --enable-split-objs
145 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
146 endif
147
148 ifneq "$(HSCOLOUR)" ""
149 CONFIGURE_OPTS += --with-hscolour=$(HSCOLOUR)
150 endif
151
152 ifneq "$(ALEX)" ""
153 CONFIGURE_OPTS += --with-alex=$(ALEX)
154 endif
155
156 ifneq "$(HADDOCK)" ""
157 CONFIGURE_OPTS += --with-haddock=$(HADDOCK)
158 endif
159
160 ifneq "$(HAPPY)" ""
161 CONFIGURE_OPTS += --with-happy=$(HAPPY)
162 endif
163
164 DEPLOYMENT_OPTS = $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS)) \
165                   $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
166
167 .PHONY: subdirs
168
169 subdirs:
170         @echo $(SUBDIRS)
171
172 HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
173
174 IFBUILDABLE=ifBuildable/ifBuildable $(HERE_ABS)/boot-packages
175 CABAL=$(HERE_ABS)/cabal-bin $(GHC) $(HERE_ABS)/bootstrapping.conf
176
177 CABAL_GHC_FLAGS = -Wall
178 ifeq "$(ghc_ge_605)" "NO"
179 CABAL_GHC_FLAGS += -cpp
180 endif
181
182 BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=1,3 -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath
183
184 .PHONY: boot
185
186 boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
187
188 cabal-bin: cabal-bin.hs
189         $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
190
191 bootstrapping.conf: cabal-bin
192         echo "[]" > $@.tmp
193         -cd filepath && $(CABAL) clean     --distpref=dist-bootstrapping
194         cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
195         cd filepath && $(CABAL) build     --distpref=dist-bootstrapping
196         cd filepath && $(CABAL) install   --distpref=dist-bootstrapping --inplace
197         -cd Cabal    && $(CABAL) clean     --distpref=dist-bootstrapping
198         cd Cabal    && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
199         cd Cabal    && $(CABAL) build     --distpref=dist-bootstrapping
200         cd Cabal    && $(CABAL) install   --distpref=dist-bootstrapping --inplace
201         mv $@.tmp $@
202
203 installPackage/installPackage: installPackage.hs
204         -$(RM) -rf installPackage
205         mkdir installPackage
206         $(CP) installPackage.hs installPackage/
207         cd installPackage && $(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
208                                  --make installPackage -o installPackage \
209                                  $(DEPLOYMENT_OPTS)
210
211 ifBuildable/ifBuildable: ifBuildable.hs
212         -$(RM) -rf ifBuildable
213         mkdir ifBuildable
214         $(CP) ifBuildable.hs ifBuildable/
215 ifeq "$(stage)" "2"
216         cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable \
217                                  $(DEPLOYMENT_OPTS)
218 else
219         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
220 endif
221
222 .PHONY: all build configure
223
224 all: build
225
226 ifeq "$(HADDOCK_DOCS)" "YES"
227 all: doc
228 endif
229
230 .PHONY: rebuild.library.%
231 .PHONY: remake.library.%
232
233 $(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
234 rebuild.library.%: clean.library.% build.library.%
235
236 $(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
237 remake.library.%: clean.library.% make.library.%
238
239 # NB. we're depending on make chasing dependencies from left to right here.
240 # This bit goes wrong with 'make -j'.
241 build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)) \
242        installPackage/installPackage
243
244 configure: $(foreach SUBDIR,$(SUBDIRS), \
245              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
246
247 .PHONY: build.library.%
248 .PHONY: make.library.%
249
250 # We should depend on %/%.cabal here (and in other rules), but make
251 # makes that difficult.
252
253 # We put non-existant paths in when configuring, as we require that
254 # builds don't depend on these paths when making bindists.
255
256 # We rely on all the CONFIGURE_ARGS being quoted with '...', and there
257 # being no 's inside the values.
258 FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
259                                  $(space)--configure-option=',\
260                                  $(space)$(CONFIGURE_ARGS))
261
262 ifeq "$(Windows)" "YES"
263 NONEXISTENT=c:/NONEXISTENT
264 else
265 NONEXISTENT=/NONEXISTENT
266 endif
267
268 ALL_CONFIGURE_FLAGS = \
269                    $(CONFIGURE_OPTS) \
270                    --prefix=$(NONEXISTENT) \
271                    --bindir=$(NONEXISTENT) \
272                    --libdir=$(NONEXISTENT) \
273                    --libsubdir='$$pkgid' \
274                    --libexecdir=$(NONEXISTENT) \
275                    --datadir=$(NONEXISTENT) \
276                    --docdir=$(NONEXISTENT) \
277                            --haddockdir=$(NONEXISTENT) \
278                    --htmldir=$(NONEXISTENT) \
279                    --with-compiler=$(FPTOOLS_TOP_ABS)/compiler/stage1/ghc-inplace \
280                    --with-hc-pkg=$(FPTOOLS_TOP_ABS)/utils/ghc-pkg/ghc-pkg-inplace \
281                    --with-hsc2hs=$(FPTOOLS_TOP_ABS)/utils/hsc2hs/hsc2hs-inplace \
282                    --with-ld=$(LD) \
283                    --haddock-options="--use-contents=../index.html \
284                                       --use-index=../doc-index.html" \
285                    $(FLAGGED_CONFIGURE_ARGS) \
286                    --configure-option=--with-cc=$(CC)
287
288 $(foreach SUBDIR,$(SUBDIRS), \
289                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
290 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
291         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
292         $(MKDIRHIER) `dirname $@`
293         ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
294               && touch $@ || touch $*/unbuildable
295 # We don't touch $@ if configure failed as we would prefer to try
296 # configuring it next time round, rather than assuming it'll still fail.
297 # This is particularly important for bootlibs, where failure means the
298 # build dies!
299
300 # Build the library using 'make'
301 # We re-run 'setup makefile' each time, just in case any preprocessing
302 # needs to be done.  However, we're careful not to overwrite GNUmakefile
303 # if it hasn't changed, so that dependency-generation isn't forced
304 # every time.
305 # Packages in $(SUBDIRS_BUILD) need to use the build.* rules instead of
306 # make.*, so filter them out and use an alternate rule below instead.
307 $(foreach SUBDIR,$(filter-out $(SUBDIRS_BUILD),$(SUBDIRS)),make.library.$(SUBDIR)):\
308 make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
309                 cabal-bin ifBuildable/ifBuildable
310         if $(IFBUILDABLE) $*; then \
311           cd $* && \
312           cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
313           mv GNUmakefile GNUmakefile.tmp; \
314           $(CABAL) makefile -f GNUmakefile; \
315           cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
316           $(MAKE) $(MFLAGS) && \
317           $(CABAL) register --inplace; \
318         fi
319
320 MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
321
322 # Alternate rule, as described above
323 $(foreach SUBDIR,$(SUBDIRS_BUILD),make.library.$(SUBDIR)):\
324 make.library.%: build.library.%
325
326 # Build the library using 'setup build' (not the default)
327 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
328 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
329                  cabal-bin ifBuildable/ifBuildable
330         if $(IFBUILDABLE) $*; then \
331           cd $* && \
332           $(CABAL) build $(addprefix --ghc-option=,$(GhcLibHcOpts)); \
333           $(CABAL) register --inplace; \
334         fi
335
336 .PHONY: doc html
337
338 html: doc
339
340 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
341         sh gen_contents_index --inplace
342
343 # Making hyperlinked source only works if we have hscolour
344 ifneq "$(HSCOLOUR)" ""
345 CABAL_HADDOCK_FLAGS=--hyperlink-source
346 endif
347
348 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
349 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
350                cabal-bin ifBuildable/ifBuildable
351         if $(IFBUILDABLE) $*; then \
352           cd $* && $(CABAL) haddock --html-location='../$$pkg' \
353                                     $(CABAL_HADDOCK_FLAGS); \
354         fi
355 ifneq "$(HSCOLOUR)" ""
356 # We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
357 # mismatch
358         if $(IFBUILDABLE) $*; then cp hscolour.css $*/dist/doc/html/*/src/; fi
359 endif
360
361 .PHONY: distclean clean clean.library.%
362
363 distclean: clean
364
365 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
366         -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
367         -cd Cabal    && $(CABAL) clean --distpref=dist-bootstrapping
368         $(RM) -rf bootstrapping/*
369         $(RM) -f bootstrapping.conf     bootstrapping.conf.old
370         $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
371         $(RM) -f cabal-bin cabal-bin.exe
372         $(RM) -rf ifBuildable
373         $(RM) -rf installPackage
374         $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
375         $(RM) -f haddock* *.gif
376
377 distclean:
378         $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
379
380 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
381 clean.library.%:
382         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
383         -cd $* && $(CABAL) clean
384         $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
385         $(RM) $*/GNUmakefile $*/Makefile.local
386 endif
387
388 # -----------------------------------------------------------------------------
389
390 .PHONY: install install-docs install.library.%
391
392 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
393 ifeq "$(HADDOCK_DOCS)" "YES"
394         $(INSTALL_DIR)                                                     $(DESTDIR)$(html_installed_root)
395         $(INSTALL_DATA)   index.html doc-index*.html                       $(DESTDIR)$(html_installed_root)
396         $(INSTALL_SCRIPT) gen_contents_index                               $(DESTDIR)$(html_installed_root)
397         # Hacks:
398         $(INSTALL_DATA)   base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
399         $(INSTALL_DATA)   base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
400         $(INSTALL_DATA)   base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
401 endif
402
403 # Cabal doesn't let us ask to install docs only, so do nothing here
404 install-docs:
405         @:
406
407 # Ideally this would depend on a stamp/build.library.%, but if it does
408 # then we can't change the libraries and then just rerun make.
409 # Thus if you install without building then it will just break.
410
411 # prefix and (on Windows) htmldir use $topdir when configuring, so we
412 # need to tell installPackage the real path to use when installing.
413
414 # We also need to pass all the other directories in, as they can be
415 # overridden when installing a bindist.
416
417 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
418 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
419         if $(IFBUILDABLE) $*; then \
420           cd $* && \
421           $(FPTOOLS_TOP_ABS)/libraries/installPackage/installPackage install '$(GHC_PKG_PROG)' '$(DESTDIR)$(libdir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
422         fi
423
424 .PHONY: binary-dist binary-dist.library.%
425
426 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
427
428 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)) \
429              installPackage/installPackage
430         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
431         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
432         mkdir                               $(BIN_DIST_LIBDIR)/ifBuildable
433         cp        ifBuildable/ifBuildable       $(BIN_DIST_LIBDIR)/ifBuildable
434         cp    Makefile                      $(BIN_DIST_LIBDIR)
435 ifeq "$(HADDOCK_DOCS)" "YES"
436         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
437         cp    index.html                    $(BIN_DIST_LIBDIR)
438         cp    doc-index*.html               $(BIN_DIST_LIBDIR)
439 endif
440         cp -pR stamp                         $(BIN_DIST_LIBDIR)
441
442 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
443 binary-dist.library.%:
444         if $(IFBUILDABLE) $*; then \
445           $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*; \
446           cd $* && \
447           cp    $*.cabal      $(BIN_DIST_LIBDIR)/$* && \
448           cp    LICENSE       $(BIN_DIST_LIBDIR)/$* && \
449           cp -R dist          $(BIN_DIST_LIBDIR)/$* && \
450           $(FIND) . -name "*.buildinfo" -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
451           $(FIND) . -name unbuildable -exec cp {} $(BIN_DIST_LIBDIR)/$* \; && \
452           (cp -RL include      $(BIN_DIST_LIBDIR)/$* || true) && \
453           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
454              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf && \
455           $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
456              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
457              -exec rm {} \; ; \
458         fi
459
460 # Ignore some doc targets that we don't support
461 # The root recurses into us when these targets are made
462 .PHONY: html-no-chunks chm HxS fo dvi ps pdf
463 html-no-chunks chm HxS fo dvi ps pdf:
464         @:
465