[project @ 2004-03-27 09:57:57 by panne]
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.38 2004/03/27 09:57:58 panne Exp $
3
4 ifneq "$(PACKAGE)" ""
5
6 ifeq "$(STANDALONE_PACKAGE)" ""
7 ifeq "$(ProjectNameShort)" "ghc"
8 STANDALONE_PACKAGE = NO
9 else
10 STANDALONE_PACKAGE = YES
11 endif
12 endif
13
14 # -----------------------------------------------------------------------------
15 # Build the package configuration file and tell the compiler about it.
16
17 ifeq "$(way)" ""
18
19 ifeq "$(STANDALONE_PACKAGE)" "NO"
20 PKGCONF_CPP_EXTRA_OPTS = -I$(GHC_INCLUDE_DIR)
21 else
22 PKGCONF_CPP_EXTRA_OPTS =
23 endif
24
25 package.conf.inplace   : package.conf.in
26         $(CPP) $(RAWCPP_FLAGS) -P $(PKGCONF_CPP_EXTRA_OPTS) -x c $(PACKAGE_CPP_OPTS) $< | \
27         sed -e 's/""//g' -e 's/\[ *,/[ /g' >$@
28
29 package.conf.installed : package.conf.in
30         $(CPP) $(RAWCPP_FLAGS) -P $(PKGCONF_CPP_EXTRA_OPTS) -DINSTALLING -x c $(PACKAGE_CPP_OPTS) $< | \
31         sed -e 's/""//g' -e 's/\[ *,/[ /g' >$@
32
33 # we could be more accurate here and add a dependency on
34 # ghc/driver/package.conf, but that doesn't work too well because of
35 # make's limited accuracy with modification times: when doing 'make
36 # boot' in multiple packages, make won't detect that the package
37 # configuration needs updating if it was updated already in the last
38 # second.
39 #
40 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
41 # to 'make clean' in ghc without cleaning in libraries too, the packages
42 # will be correctly re-installed.
43 #
44 ifeq "$(STANDALONE_PACKAGE)" "NO"
45
46 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
47 CLEAN_FILES += $(STAMP_PKG_CONF)
48
49 ifneq "$(BootingFromHc)" "YES"
50 boot all :: $(STAMP_PKG_CONF)
51 endif
52
53 $(STAMP_PKG_CONF) : package.conf.inplace package.conf.installed
54         $(GHC_PKG_INPLACE) --update-package <package.conf.inplace
55         $(GHC_PKG_INPLACE)  -f $(GHC_DRIVER_DIR)/package.conf --update-package <package.conf.installed
56         @touch $(STAMP_PKG_CONF)
57
58 CLEAN_FILES += package.conf.installed package.conf.inplace 
59
60 else # $(STANDALONE_PACKAGE) == "YES"
61
62 PACKAGE_CPP_OPTS += -DPACKAGE=\"${PACKAGE}\"
63 PACKAGE_CPP_OPTS += -DPACKAGE_DEPS='$(patsubst %,"%"$(comma),$(PACKAGE_DEPS))'
64 PACKAGE_CPP_OPTS += -DLIBRARY=\"HS$(PACKAGE)\"
65 PACKAGE_CPP_OPTS += -DLIBDIR=\"$(libdir)\"
66 PACKAGE_CPP_OPTS += -DFPTOOLS_TOP_ABS=\"${FPTOOLS_TOP_ABS}\"
67
68 # Let the package configuration file refer to $(libdir) as
69 # ${pkglibdir}.  Note we can't use ${libdir} because ghc-pkg already
70 # redefines it to point to GHC's libdir (bug or feature?).
71 #
72 install :: package.conf.installed
73         $(GHC_PKG) --force --update-package <package.conf.installed
74
75 # Invoke this rule by hand in order to use the package in-place
76 install-inplace-pkg : package.conf.inplace
77         $(GHC_PKG) --force --update-package <package.conf.inplace
78
79 endif # $(STANDALONE_PACKAGE)
80
81 endif # $(way) == ""
82
83 # -----------------------------------------------------------------------------
84 # Building the static library libHS<pkg>.a
85
86 ifeq "$(STANDALONE_PACKAGE)" "NO"
87 HC = $(GHC_INPLACE)
88 endif
89
90 SRC_HSC2HS_OPTS += -I.
91
92 ifeq "$(NON_HS_PACKAGE)" ""
93 SRC_HC_OPTS     += -package-name $(PACKAGE)
94 SRC_HC_OPTS     += $(GhcLibHcOpts)
95 SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
96 endif
97
98 LIBRARY         = libHS$(PACKAGE)$(_way).a
99
100 ifeq "$(WAYS)" ""
101 WAYS = $(GhcLibWays)
102 endif
103
104 all :: $(LIBRARY)
105
106 # POSSIBLE alternative version using --make:
107 #
108 # lib : $(HS_SRCS)
109 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
110
111 # $(LIBNAME) : lib
112 #       $(RM) $@
113 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
114 #       $(RANLIB) $@
115
116 # %.o : %.hs
117 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
118 # %.o : %.lhs
119 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
120
121 # -----------------------------------------------------------------------------
122 # Installation; need to install .hi files as well as libraries
123
124 ifeq "$(DLLized)" "YES"
125 INSTALL_PROGS += $(DLL_NAME)
126 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
127 endif
128
129 # The interface files are put inside the $(libdir), since they
130 # might (potentially) be platform specific..
131
132 ifeq "$(HIERARCHICAL_LIB)" "YES"
133 ifacedir = $(libdir)/imports
134 else
135 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
136 endif
137
138 # If the lib consists of a hierachy of modules, we must retain the directory
139 # structure when we install the interfaces.
140 ifeq "$(HIERARCHICAL_LIB)" "YES"
141 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
142 ifneq "$(ALL_DIRS)" ""
143 install ::
144         @for i in $(ALL_DIRS); do \
145                 $(INSTALL_DIR) $(ifacedir)/$$i; \
146         done
147 endif
148 else
149 INSTALL_IFACES += $(HS_IFACES)
150 endif
151
152 # -----------------------------------------------------------------------------
153 # Dependencies
154
155 ifeq "$(STANDALONE_PACKAGE)" "NO"
156 MKDEPENDHS = $(GHC_INPLACE)
157 endif
158
159 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
160
161 ifeq "$(STANDALONE_PACKAGE)" "NO"
162 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
163 endif
164
165 endif # $(PACKAGE) /= ""
166
167 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
168 INSTALL_LIBS  += $(LIBRARY)
169
170 #--------------------------------------------------------------
171 # Building dynamically-linkable libraries for GHCi
172 #
173 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
174 #
175 # Why?  GHCi can only link .o files (at the moment), not .a files
176 # so we have to build libFoo.o as well as libFoo.a
177 #
178 # Furthermore, GHCi currently never loads 
179 # profiling libraries (or other non-std ways)
180
181 ifneq "$(LIBRARY)" ""
182
183 ifeq "$(way)" ""
184 ifeq "$(GhcWithInterpreter)" "YES"
185
186 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
187
188 INSTALL_LIBS += $(GHCI_LIBRARY)
189 CLEAN_FILES  += $(GHCI_LIBRARY)
190
191 all :: $(GHCI_LIBRARY)
192
193 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
194 # If you don't want to build GHCI_LIBRARY the 'standard' way,
195 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
196 # hslibs/Win32 uses this 'feature', which will go away soon
197 # when we can use a "fixed" ld.
198 #
199 $(GHCI_LIBRARY) : $(LIBOBJS)
200         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
201
202 endif # DONT_WANT_STD_GHCI_LIB_RULE
203 endif # GhcWithInterpreter
204 endif # way
205
206 # -----------------------------------------------------------------------------
207 # Doc building with Haddock
208
209 ifneq "$(NO_HADDOCK_DOCS)" "YES"
210
211 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
212
213 HTML_DIR = html
214 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
215
216 ifneq "$(HS_PPS)" ""
217
218 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
219
220 ifeq "$(HADDOCK)" ""
221 html ::
222         @echo Haddock must be installed in order to build HTML library documentation.
223         @echo Please install Haddock and re-configure.
224         @exit 1
225 endif
226
227 html :: $(HTML_DOC)
228
229 extraclean :: 
230         $(RM) -rf $(HTML_DIR)
231
232 $(HTML_DOC) : $(HS_PPS)
233         @$(INSTALL_DIR) $(HTML_DIR)
234         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
235                 --package=$(PACKAGE) \
236                 --dump-interface=$(PACKAGE).haddock \
237                 --use-index=../doc-index.html --use-contents=../index.html \
238                 $(foreach pkg, $(PACKAGE_DEPS), \
239                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
240
241 CLEAN_FILES += $(PACKAGE).haddock
242
243 %.raw-hs : %.lhs
244         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
245
246 %.raw-hs : %.hs
247         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
248
249 install-docs :: $(HTML_DOC)
250         @$(INSTALL_DIR) $(datadir)/html/libraries/$(PACKAGE)
251         @for i in $(HTML_DIR)/*; do \
252            echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
253            $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
254         done
255         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/libraries/$(PACKAGE)
256
257 endif # HS_PPS
258 endif # NO_HADDOCK_DOCS
259
260 # -----------------------------------------------------------------------------
261
262 endif # $(LIBRARY) /= ""