[project @ 2004-02-07 14:08:57 by panne]
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.36 2004/02/07 14:08:57 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 WAYS            = $(GhcLibWays)
101
102 all :: $(LIBRARY)
103
104 # POSSIBLE alternative version using --make:
105 #
106 # lib : $(HS_SRCS)
107 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
108
109 # $(LIBNAME) : lib
110 #       $(RM) $@
111 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
112 #       $(RANLIB) $@
113
114 # %.o : %.hs
115 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
116 # %.o : %.lhs
117 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
118
119 # -----------------------------------------------------------------------------
120 # Installation; need to install .hi files as well as libraries
121
122 ifeq "$(DLLized)" "YES"
123 INSTALL_PROGS += $(DLL_NAME)
124 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
125 endif
126
127 # The interface files are put inside the $(libdir), since they
128 # might (potentially) be platform specific..
129
130 ifeq "$(HIERARCHICAL_LIB)" "YES"
131 ifacedir = $(libdir)/imports
132 else
133 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
134 endif
135
136 # If the lib consists of a hierachy of modules, we must retain the directory
137 # structure when we install the interfaces.
138 ifeq "$(HIERARCHICAL_LIB)" "YES"
139 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
140 ifneq "$(ALL_DIRS)" ""
141 install ::
142         @for i in $(ALL_DIRS); do \
143                 $(INSTALL_DIR) $(ifacedir)/$$i; \
144         done
145 endif
146 else
147 INSTALL_IFACES += $(HS_IFACES)
148 endif
149
150 # -----------------------------------------------------------------------------
151 # Dependencies
152
153 ifeq "$(STANDALONE_PACKAGE)" "NO"
154 MKDEPENDHS = $(GHC_INPLACE)
155 endif
156
157 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
158
159 ifeq "$(STANDALONE_PACKAGE)" "NO"
160 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
161 endif
162
163 endif # $(PACKAGE) /= ""
164
165 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
166 INSTALL_LIBS  += $(LIBRARY)
167
168 #--------------------------------------------------------------
169 # Building dynamically-linkable libraries for GHCi
170 #
171 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
172 #
173 # Why?  GHCi can only link .o files (at the moment), not .a files
174 # so we have to build libFoo.o as well as libFoo.a
175 #
176 # Furthermore, GHCi currently never loads 
177 # profiling libraries (or other non-std ways)
178
179 ifneq "$(LIBRARY)" ""
180
181 ifeq "$(way)" ""
182 ifeq "$(GhcWithInterpreter)" "YES"
183
184 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
185
186 INSTALL_LIBS += $(GHCI_LIBRARY)
187 CLEAN_FILES  += $(GHCI_LIBRARY)
188
189 all :: $(GHCI_LIBRARY)
190
191 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
192 # If you don't want to build GHCI_LIBRARY the 'standard' way,
193 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
194 # hslibs/Win32 uses this 'feature', which will go away soon
195 # when we can use a "fixed" ld.
196 #
197 $(GHCI_LIBRARY) : $(LIBOBJS)
198         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
199
200 endif # DONT_WANT_STD_GHCI_LIB_RULE
201 endif # GhcWithInterpreter
202 endif # way
203
204 # -----------------------------------------------------------------------------
205 # Doc building with Haddock
206
207 ifneq "$(NO_HADDOCK_DOCS)" "YES"
208
209 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
210
211 HTML_DIR = html
212 HTML_DOC = $(HTML_DIR)/haddock.css
213
214 ifneq "$(HS_PPS)" ""
215
216 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
217
218 ifeq "$(HADDOCK)" ""
219 html ::
220         @echo Haddock must be installed in order to build HTML library documentation.
221         @echo Please install Haddock and re-configure.
222         @exit 1
223 endif
224
225 html :: $(HTML_DOC)
226
227 extraclean :: 
228         $(RM) -rf $(HTML_DIR)
229
230 $(HTML_DOC) : $(HS_PPS)
231         @$(INSTALL_DIR) $(HTML_DIR)
232         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
233                 --package=$(PACKAGE) \
234                 --dump-interface=$(PACKAGE).haddock \
235                 --use-index=../doc-index.html --use-contents=../index.html \
236                 $(foreach pkg, $(PACKAGE_DEPS), \
237                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
238
239 CLEAN_FILES += $(PACKAGE).haddock
240
241 %.raw-hs : %.lhs
242         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
243
244 %.raw-hs : %.hs
245         $(HC) $(HC_OPTS) -D__HADDOCK__ -E -optP-P $< -o $@
246
247 install-docs :: $(HTML_DOC)
248         @$(INSTALL_DIR) $(datadir)/html/libraries/$(PACKAGE)
249         @for i in $(HTML_DIR)/*; do \
250            echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
251            $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/libraries/$(PACKAGE); \
252         done
253         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/libraries/$(PACKAGE)
254
255 endif # HS_PPS
256 endif # NO_HADDOCK_DOCS
257
258 # -----------------------------------------------------------------------------
259
260 endif # $(LIBRARY) /= ""