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