2664d364616c2d67d79b2ca85ace0e23030c0361
[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 build.library.<package>
12
13 .PHONY: default_target
14
15 default_target: build
16
17 ifeq "$(IN_BIN_DIST)" "1"
18 include ../Makefile-vars
19 else
20 # Ideally we'd just include something to give us variables
21 # for paths and arguments to tools etc, and those set in mk/build.mk.
22 TOP=.
23 include $(TOP)/mk/boilerplate.mk
24 endif
25
26 SUBDIRS = base old-time directory filepath pretty template-haskell \
27           readline Cabal random haskell98
28
29 ifeq "$(GhcLibsWithUnix)" "YES"
30 SUBDIRS += unix
31 endif
32 ifeq "$(Windows)" "YES"
33 SUBDIRS += $(wildcard Win32)
34 endif
35
36 # Set GhcBootLibs=YES from the command line to work with just the libraries
37 # needed to bootstrap GHC.
38 ifneq "$(GhcBootLibs)" "YES"
39 SUBDIRS += $(wildcard regex-base)
40 SUBDIRS += $(wildcard regex-posix)
41 SUBDIRS += $(wildcard regex-compat)
42 SUBDIRS += $(wildcard parsec)
43 SUBDIRS += $(wildcard haskell-src)
44 SUBDIRS += $(wildcard html)
45 SUBDIRS += $(wildcard network)
46 SUBDIRS += $(wildcard QuickCheck)
47 SUBDIRS += $(wildcard HUnit)
48 SUBDIRS += $(wildcard mtl)
49 SUBDIRS += $(wildcard fgl)
50 SUBDIRS += $(wildcard X11)
51 SUBDIRS += $(wildcard time)
52 ifeq "$(Windows)" "NO"
53 # HGL is not working on Win32, so omit it for now.  Better not to ship it
54 # at all than to ship a broken version.
55 SUBDIRS += $(wildcard HGL)
56 endif
57 SUBDIRS += $(wildcard OpenGL)
58 SUBDIRS += $(wildcard GLUT)
59 SUBDIRS += $(wildcard OpenAL)
60 SUBDIRS += $(wildcard ALUT)
61 SUBDIRS += $(wildcard stm)
62 SUBDIRS += $(wildcard xhtml)
63 SUBDIRS += $(wildcard cgi)
64 SUBDIRS += $(wildcard arrows)
65 ifeq "$(GhcLibsWithObjectIO)" "YES"
66 SUBDIRS += $(wildcard ObjectIO)
67 endif
68 SUBDIRS += $(wildcard parallel)
69 endif
70
71 # -----------------------------------------------------------------------------
72
73 empty=
74 space=$(empty) $(empty)
75
76 ifeq "$(Windows)" "YES"
77 dot_bat=.bat
78 else
79 dot_bat=
80 endif
81
82 CONFIGURE_OPTS =
83 CONFIGURE_STAMP_EXTRAS :=
84
85 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
86 CONFIGURE_OPTS += --enable-library-profiling
87 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
88 endif
89
90 ifeq "$(SplitObjs)" "YES"
91 CONFIGURE_OPTS += --enable-split-objs
92 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
93 endif
94
95 BOOTSTRAPPING_STAMPS = $(addprefix stamp/bootstrapping.,Cabal filepath pretty)
96
97 .PHONY: subdirs
98
99 subdirs:
100         @echo $(SUBDIRS)
101
102 .PHONY: boot
103
104 boot: $(BOOTSTRAPPING_STAMPS) ifBuildable/ifBuildable \
105           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup) \
106           installPackage/installPackage
107
108 # We build the Setup program in a setup subdirectory to stop it trying
109 # to use bits of base and Cabal when we build those packages.
110 # This also makes it slightly easier to clean.
111
112 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
113
114 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
115 %/setup/Setup: $(BOOTSTRAPPING_STAMPS)
116         -$(RM) -rf $*/setup
117         mkdir $*/setup
118         $(CP) $*/Setup.*hs $*/setup
119         cd $*/setup && $(GHC) -i../../bootstrapping.Cabal \
120                               -i../../bootstrapping.filepath \
121                               -i../../bootstrapping.pretty \
122                               -Wall -cpp --make Setup.*hs -o Setup
123
124 installPackage/installPackage: installPackage.hs $(BOOTSTRAPPING_STAMPS)
125         -$(RM) -rf installPackage
126         mkdir installPackage
127         $(CP) installPackage.hs installPackage/
128         cd installPackage && $(GHC) -Wall -cpp \
129                                     --make installPackage -o installPackage \
130                               -i../bootstrapping.Cabal \
131                               -i../bootstrapping.filepath \
132                               -i../bootstrapping.pretty
133
134 ifBuildable/ifBuildable: ifBuildable.hs
135         -$(RM) -rf ifBuildable
136         mkdir ifBuildable
137         $(CP) ifBuildable.hs ifBuildable/
138         cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
139
140 $(BOOTSTRAPPING_STAMPS): stamp/bootstrapping.%:
141         $(RM) -rf bootstrapping.$*
142         $(CP) -R $* bootstrapping.$*
143         $(FIND) bootstrapping.$* \( -name "*.o" -o -name "*.hi" \) \
144                                  -exec $(RM) -f {} \;
145         touch $@
146
147 .PHONY: all build configure
148
149 all: build
150
151 ifneq "$(NO_HADDOCK_DOCS)" "YES"
152 all: doc
153 endif
154
155 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
156 build: installPackage/installPackage
157
158 configure: $(foreach SUBDIR,$(SUBDIRS), \
159              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
160
161 .PHONY: build.library.%
162
163 # We should depend on %/%.cabal here (and in other rules), but make
164 # makes that difficult.
165
166 $(foreach SUBDIR,$(SUBDIRS), \
167                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
168 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
169         -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
170         ( cd $* && setup/Setup configure \
171                    $(CONFIGURE_OPTS) \
172                    --prefix=$(prefix) \
173                    --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
174                    --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
175                    --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
176                    --with-ld=$(LD) \
177                    --datasubdir=ghc \
178                    --haddock-args="--use-contents=../index.html \
179                                    --use-index=../doc-index.html" \
180                    $(addprefix --configure-option=,$(CONFIGURE_ARGS)) \
181                    --configure-option=--with-cc=$(CC) ) \
182               && touch $@ || touch $*/unbuildable
183 # We don't touch $@ if configure failed as we would prefer to try
184 # configuring it next time round, rather than assuming it'll still fail.
185 # This is particularly important for corelibs, where failure means the
186 # build dies!
187
188 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
189 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
190                  %/setup/Setup ifBuildable/ifBuildable
191         ifBuildable/ifBuildable $* setup/Setup build \
192                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
193         ifBuildable/ifBuildable $* setup/Setup register --inplace
194
195 .PHONY: doc
196
197 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
198
199 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
200         sh gen_contents_index
201
202 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
203 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
204                %/setup/Setup ifBuildable/ifBuildable
205         ifBuildable/ifBuildable $* setup/Setup haddock
206
207 .PHONY: install install-docs install.library.%
208
209 INSTALL_DIR=$(prefix)/share/ghc/doc/html/
210
211 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
212 ifneq "$(NO_HADDOCK_DOCS)" "YES"
213         $(INSTALL_DATA)   index.html doc-index.html                       $(INSTALL_DIR)
214         $(INSTALL_SCRIPT) gen_contents_index                                      $(INSTALL_DIR)
215         # Hacks:
216         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
217         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
218         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
219 endif
220
221 # Cabal doesn't let us ask to install docs only, so do nothing here
222 install-docs:
223         @:
224
225 # Ideally this would depend on a stamp/build.library.%, but if it does
226 # then we can't change the libraries and then just rerun make.
227 # Thus if you install without building then it will just break.
228 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
229 install.library.%: installPackage/installPackage ifBuildable/ifBuildable
230         ifBuildable/ifBuildable $* ../installPackage/installPackage
231
232 .PHONY: binary-dist binary-dist.library.%
233
234 BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
235
236 binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
237         mkdir                               $(BIN_DIST_LIBDIR)/installPackage
238         cp        installPackage/installPackage $(BIN_DIST_LIBDIR)/installPackage
239         cp    Makefile                      $(BIN_DIST_LIBDIR)
240         cp    gen_contents_index            $(BIN_DIST_LIBDIR)
241         cp    index.html                    $(BIN_DIST_LIBDIR)
242         cp    doc-index.html                $(BIN_DIST_LIBDIR)
243         cp -a stamp                         $(BIN_DIST_LIBDIR)
244
245 $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
246 binary-dist.library.%:
247         $(MKDIRHIER) $(BIN_DIST_LIBDIR)/$*
248         ifBuildable/ifBuildable $* cp    $*.cabal      $(BIN_DIST_LIBDIR)/$*
249         ifBuildable/ifBuildable $* cp -a dist          $(BIN_DIST_LIBDIR)/$*
250         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
251              \( -name "*_split" -o -name "autogen" \) | xargs rm -rf
252         ifBuildable/ifBuildable $* $(FIND) $(BIN_DIST_LIBDIR)/$*/dist \
253              \( \( -name "*.o" -o -name "*.p_o" \) -a ! -name "HS*" \) \
254              -exec rm {} \;
255
256 .PHONY: distclean clean clean.library.%
257
258 distclean: clean
259
260 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
261         $(RM) -f stamp/bootstrapping.*
262         $(RM) -rf bootstrapping.*
263         $(RM) -rf ifBuildable
264         $(RM) -f libraries.txt index.html doc-index.html
265
266 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
267 clean.library.%:
268         $(RM) -f stamp/configure.library.*.$* $*/unbuildable
269         -cd $* && setup/Setup clean
270         $(RM) -rf $*/setup
271