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