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