Implement ifBuildable
[ghc-hetmet.git] / libraries / Makefile
1
2 .PHONY: default_target
3
4 default_target: build
5
6 ifeq "$(IN_BIN_DIST)" "1"
7 include ../Makefile-vars
8 else
9 # Ideally we'd just include something to give us variables
10 # for paths and arguments to tools etc, and those set in mk/build.mk.
11 TOP=.
12 include $(TOP)/mk/boilerplate.mk
13 endif
14
15 SUBDIRS = base filepath haskell98 template-haskell readline Cabal
16
17 ifeq "$(GhcLibsWithUnix)" "YES"
18 SUBDIRS += unix
19 endif
20 ifeq "$(Windows)" "YES"
21 SUBDIRS += $(wildcard Win32)
22 endif
23
24 # Set GhcBootLibs=YES from the command line to work with just the libraries
25 # needed to bootstrap GHC.
26 ifneq "$(GhcBootLibs)" "YES"
27 SUBDIRS += $(wildcard regex-base)
28 SUBDIRS += $(wildcard regex-posix)
29 SUBDIRS += $(wildcard regex-compat)
30 SUBDIRS += $(wildcard parsec)
31 SUBDIRS += $(wildcard haskell-src)
32 SUBDIRS += $(wildcard html)
33 SUBDIRS += $(wildcard network)
34 SUBDIRS += $(wildcard QuickCheck)
35 SUBDIRS += $(wildcard HUnit)
36 SUBDIRS += $(wildcard mtl)
37 SUBDIRS += $(wildcard fgl)
38 SUBDIRS += $(wildcard X11)
39 SUBDIRS += $(wildcard time)
40 ifeq "$(Windows)" "NO"
41 # HGL is not working on Win32, so omit it for now.  Better not to ship it
42 # at all than to ship a broken version.
43 SUBDIRS += $(wildcard HGL)
44 endif
45 SUBDIRS += $(wildcard OpenGL)
46 SUBDIRS += $(wildcard GLUT)
47 SUBDIRS += $(wildcard OpenAL)
48 SUBDIRS += $(wildcard ALUT)
49 SUBDIRS += $(wildcard stm)
50 SUBDIRS += $(wildcard xhtml)
51 SUBDIRS += $(wildcard cgi)
52 ifeq "$(GhcLibsWithObjectIO)" "YES"
53 SUBDIRS += $(wildcard ObjectIO)
54 endif
55 endif
56
57 # -----------------------------------------------------------------------------
58
59 empty=
60 space=$(empty) $(empty)
61
62 ifeq "$(Windows)" "YES"
63 dot_bat=.bat
64 else
65 dot_bat=
66 endif
67
68 CONFIGURE_OPTS =
69 CONFIGURE_STAMP_EXTRAS :=
70
71 ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
72 CONFIGURE_OPTS += --enable-library-profiling
73 CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
74 endif
75
76 BOOTSTRAPPING_CABAL = bootstrapping.cabal
77
78 .PHONY: subdirs
79
80 subdirs:
81         @echo $(SUBDIRS)
82
83 .PHONY: boot
84
85 boot: ifBuildable/ifBuildable \
86           $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup)
87         # XXX Hideous hacks:
88         $(GENPRIMOP) --make-haskell-source < ../compiler/prelude/primops.txt > base/GHC/Prim.hs
89         $(GENPRIMOP) --make-haskell-wrappers < ../compiler/prelude/primops.txt > base/GHC/PrimopWrappers.hs
90
91 # We build the Setup program in a setup subdirectory to stop it trying
92 # to use bits of base and Cabal when we build those packages.
93 # This also makes it slightly easier to clean.
94
95 # We ought to be depending on %/Setup.*hs, but make makes that difficult.
96
97 $(foreach SUBDIR,$(SUBDIRS),$(SUBDIR)/setup/Setup): \
98 %/setup/Setup: stamp/$(BOOTSTRAPPING_CABAL)
99         -$(RM) -rf $*/setup
100         mkdir $*/setup
101         $(CP) $*/Setup.*hs $*/setup
102         cd $*/setup && $(GHC) -Wall --make -i../../$(BOOTSTRAPPING_CABAL) Setup.*hs -o Setup
103
104 ifBuildable/ifBuildable: ifBuildable.hs stamp/$(BOOTSTRAPPING_CABAL)
105         -$(RM) -rf ifBuildable
106         mkdir ifBuildable
107         $(CP) ifBuildable.hs ifBuildable/
108         cd ifBuildable && $(GHC) -Wall --make -i../$(BOOTSTRAPPING_CABAL) \
109                                  ifBuildable -o ifBuildable
110
111 stamp/$(BOOTSTRAPPING_CABAL):
112         $(RM) -rf $(BOOTSTRAPPING_CABAL)
113         $(CP) -R Cabal $(BOOTSTRAPPING_CABAL)
114         $(FIND) $(BOOTSTRAPPING_CABAL) \( -name "*.o" -o -name "*.hi" \) -exec $(RM) -f {} \;
115         touch $@
116
117 .PHONY: all build configure
118
119 all: build
120
121 ifneq "$(NO_HADDOCK_DOCS)" "YES"
122 all: doc
123 endif
124
125 build: $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR))
126
127 configure: $(foreach SUBDIR,$(SUBDIRS), \
128              stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
129
130 .PHONY: build.library.%
131
132 # We should depend on %/%.cabal here (and in other rules), but make
133 # makes that difficult.
134
135 $(foreach SUBDIR,$(SUBDIRS), \
136                   stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
137 stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
138         -$(RM) -f stamp/configure.library.*.$*
139         cd $* && setup/Setup configure \
140                              $(CONFIGURE_OPTS) \
141                              --prefix=$(prefix) \
142                              --with-compiler=../../compiler/ghc-inplace$(dot_bat) \
143                              --with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
144                              --with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
145                              --with-ld=$(LD) \
146                              --datasubdir=ghc \
147                              --haddock-args="--use-contents=../index.html --use-index=../doc-index.html" \
148                              --configure-option=--with-cc=$(CC)
149         touch $@
150
151 $(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
152 build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
153                  %/setup/Setup
154         cd $* && ../ifBuildable/ifBuildable setup/Setup build \
155                                         $(addprefix --ghc-option=,$(GhcLibHcOpts))
156         cd $* && ../ifBuildable/ifBuildable setup/Setup register --inplace
157
158 .PHONY: doc
159
160 DOC_SUBDIRS = $(filter-out haskell98,$(SUBDIRS))
161
162 doc: $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR))
163         sh gen_contents_index
164
165 $(foreach SUBDIR,$(SUBDIRS),doc.library.$(SUBDIR)):\
166 doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
167                %/setup/Setup
168         cd $* && setup/Setup haddock
169
170 .PHONY: install install-docs install.library.%
171
172 INSTALL_DIR=$(prefix)/share/ghc/doc/html/
173
174 install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
175         $(INSTALL_DATA)   index.html doc-index.html                       $(INSTALL_DIR)
176         $(INSTALL_SCRIPT) gen_contents_index                                      $(INSTALL_DIR)
177         # Hacks:
178         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
179         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.js  $(INSTALL_DIR)
180         $(INSTALL_DATA)   $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
181
182 # Cabal doesn't let us ask to install docs only, so do nothing here
183 install-docs:
184         @:
185
186 # Ideally this would depend on a stamp/build.library.%, but if it does
187 # then we can't change the libraries and then just rerun make.
188 # Thus if you install without building then it will just break.
189 $(foreach SUBDIR,$(SUBDIRS),stamp/configure.library.install.$(SUBDIR)): \
190 stamp/configure.library.install.%: %/setup/Setup
191         -$(RM) -f stamp/configure.library.*.$*
192         cd $* && ../ifBuildable/ifBuildable setup/Setup configure \
193                                             $(CONFIGURE_OPTS) \
194                                             --prefix=$(prefix) \
195                                             --with-compiler=$(bindir)/ghc \
196                                             --datasubdir=ghc
197         touch $@
198
199 # We need to reconfigure as we now need to register with the normal ghc-pkg
200 $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
201 install.library.%: stamp/configure.library.install.% %/setup/Setup
202         cd $* && ../ifBuildable/ifBuildable setup/Setup install
203
204 .PHONY: clean clean.library.%
205
206 clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
207         $(RM) -f stamp/$(BOOTSTRAPPING_CABAL)
208         $(RM) -rf $(BOOTSTRAPPING_CABAL)
209         $(RM) -rf ifBuildable
210         $(RM) -f libraries.txt index.html doc-index.html
211
212 $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)): \
213 clean.library.%:
214         $(RM) -f stamp/configure.library.*.$*
215         -cd $* && setup/Setup clean
216         $(RM) -rf $*/setup
217