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