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