Remove redundant fromIntegral calls
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
3
4 ifneq "$(PACKAGE)" ""
5
6 # -----------------------------------------------------------------------------
7 # Directory layouts, installation etc.
8
9 # Here Windows & Unix differ.  On Windows, the value of $(prefix) is known
10 # to the compiler, and spliced into package.conf in place of $topdir at
11 # runtime.
12 #
13 # On Unix, we only use absolute paths in package.conf.
14 #
15
16 ifeq "$(Windows)" "YES"
17
18 PKG_LIBDIR  = $$topdir
19 PKG_DATADIR = $$topdir
20
21 else
22
23 PKG_LIBDIR  = $(libdir)
24 PKG_DATADIR = $(datadir)
25
26 endif # Unix
27
28 IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
29 IMPORT_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
30
31 INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
32 INCLUDE_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
33
34 LIB_DIR_INSTALLED    = $(PKG_LIBDIR)
35 LIB_DIR_INPLACE      = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
36
37 DATA_DIR_INSTALLED   = $(PKG_DATADIR)
38 DATA_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
39
40 HTML_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
41 HTML_DIR_INSTALLED   = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
42
43 HADDOCK_IFACE_INPLACE   = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
44 HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
45
46 # -----------------------------------------------------------------------------
47 # Build the package configuration file and tell the compiler about it.
48
49 # We want to build two versions of the package configuration: one for use
50 # in the 
51
52 ifeq "$(way)" ""
53
54 PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
55
56 PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
57 PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
58
59 PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
60 PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
61
62 package.conf.inplace   : package.conf.in
63         $(CPP) $(RAWCPP_FLAGS) -P \
64                 -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
65                 -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
66                 -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
67                 -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
68                 -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
69                 -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
70                 -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
71                 -x c $(PACKAGE_CPP_OPTS) $< | \
72         grep -v '^#pragma GCC' | \
73         sed -e 's/""//g' -e 's/:[       ]*,/: /g' >$@
74
75 install::
76         $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
77                -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
78                -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
79                -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
80                -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
81                -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
82                -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
83                -I../includes \
84                -x c $(PACKAGE_CPP_OPTS) package.conf.in \
85             | grep -v '^#pragma GCC' \
86             | sed -e 's/""//g' -e 's/:[   ]*,/: /g' \
87             | $(GHC_PKG_PROG) --global-conf $(DESTDIR)$(libdir)/package.conf update - --force
88
89 # we could be more accurate here and add a dependency on
90 # driver/package.conf, but that doesn't work too well because of
91 # make's limited accuracy with modification times: when doing 'make
92 # boot' in multiple packages, make won't detect that the package
93 # configuration needs updating if it was updated already in the last
94 # second.
95 #
96 # The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
97 # to 'make clean' in ghc without cleaning in libraries too, the packages
98 # will be correctly re-installed.
99 #
100
101 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
102 CLEAN_FILES += $(STAMP_PKG_CONF)
103
104 ifneq "$(BootingFromHc)" "YES"
105 boot all :: $(STAMP_PKG_CONF)
106 endif
107
108 $(STAMP_PKG_CONF) : package.conf.inplace
109         $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
110         @touch $(STAMP_PKG_CONF)
111
112 CLEAN_FILES += package.conf.inplace 
113
114 endif # $(way) == ""
115
116 # -----------------------------------------------------------------------------
117 # Building the static library libHS<pkg>.a
118
119 SRC_HSC2HS_OPTS += -I.
120
121 ifneq "$(NO_SET_HC)" "YES"
122 HC = $(GHC_INPLACE)
123 BOOTSTRAPPING_PACKAGE_CONF_HC_OPTS =
124 endif
125 IGNORE_PACKAGE_FLAG = -package-name  $(PACKAGE)-$(VERSION)
126
127 ifeq "$(NON_HS_PACKAGE)" ""
128 SRC_HC_OPTS     += $(IGNORE_PACKAGE_FLAG)
129 SRC_HC_OPTS     += $(GhcLibHcOpts)
130 SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
131 endif
132
133 #       -XGenerics switches on generation of support code for 
134 #               derivable type classes.  This is now off by default,
135 #               but we switch it on for the libraries so that we generate
136 #               the code in case someone importing wants it.
137 ifeq "$(NON_HS_PACKAGE)" ""
138 SRC_HC_OPTS     += -XGenerics
139 endif
140
141 ifndef LIBRARY
142 ifeq "$(_way:%_dyn=YES)" "YES"
143 LIBRARY         = libHS$(PACKAGE)$(_way:%_dyn=%)-ghc$(ProjectVersion)$(soext)
144 else
145 LIBRARY         = libHS$(PACKAGE)$(_way).a
146 endif
147 endif
148
149 ifeq "$(WAYS)" ""
150 WAYS = $(GhcLibWays)
151 endif
152
153 all :: $(LIBRARY)
154
155 # POSSIBLE alternative version using --make:
156 #
157 # lib : $(HS_SRCS)
158 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
159
160 # $(LIBNAME) : lib
161 #       $(RM) $@
162 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
163 #       $(RANLIB) $@
164
165 # %.o : %.hs
166 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
167 # %.o : %.lhs
168 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
169
170 # -----------------------------------------------------------------------------
171 # Installation; need to install .hi files as well as libraries
172
173 ifeq "$(DLLized)" "YES"
174 INSTALL_PROGS += $(DLL_NAME)
175 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
176 endif
177
178 # The interface files are put inside the $(libdir), since they
179 # might (potentially) be platform specific..
180
181 ifeq "$(HIERARCHICAL_LIB)" "YES"
182 ifacedir = $(libdir)/imports
183 else
184 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
185 endif
186
187 # If the lib consists of a hierachy of modules, we must retain the directory
188 # structure when we install the interfaces.
189 ifeq "$(HIERARCHICAL_LIB)" "YES"
190 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
191 ifneq "$(ALL_DIRS)" ""
192 install ::
193         @for i in $(ALL_DIRS); do \
194                 $(INSTALL_DIR) $(ifacedir)/$$i; \
195         done
196 endif
197 else
198 INSTALL_IFACES += $(HS_IFACES)
199 endif
200
201 # -----------------------------------------------------------------------------
202 # Dependencies
203
204 MKDEPENDHS = $(GHC_INPLACE)
205
206 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
207 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
208
209 endif # $(PACKAGE) != ""
210
211 #--------------------------------------------------------------
212 # Installation
213
214 ifneq "$(NO_INSTALL_LIBRARY)" "YES"
215 INSTALL_LIBS  += $(LIBRARY) $(GHCI_LIBRARY)
216 endif
217
218 #--------------------------------------------------------------
219 # Building dynamically-linkable libraries for GHCi
220 #
221 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
222 #
223 # Why?  GHCi can only link .o files (at the moment), not .a files
224 # so we have to build libFoo.o as well as libFoo.a
225 #
226 # Furthermore, GHCi currently never loads 
227 # profiling libraries (or other non-std ways)
228
229 ifneq "$(LIBRARY)" ""
230
231 ifeq "$(way)" ""
232 ifeq "$(GhcWithInterpreter)" "YES"
233
234 ifndef GHCI_LIBRARY
235 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
236 endif
237
238 CLEAN_FILES  += $(GHCI_LIBRARY)
239
240 all :: $(GHCI_LIBRARY)
241
242 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
243 # If you don't want to build GHCI_LIBRARY the 'standard' way,
244 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
245 # hslibs/Win32 uses this 'feature', which will go away soon
246 # when we can use a "fixed" ld.
247 #
248 $(GHCI_LIBRARY) : $(LIBOBJS)
249         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
250
251 endif # DONT_WANT_STD_GHCI_LIB_RULE
252 endif # GhcWithInterpreter
253 endif # way
254 endif # $(LIBRARY) /= ""
255
256 # -----------------------------------------------------------------------------
257 # Doc building with Haddock
258
259 ifneq "$(PACKAGE)" ""
260 ifeq "$(HADDOCK_DOCS)" "YES"
261
262 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
263
264 HTML_DIR = ../html-docs/$(PACKAGE)
265 HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
266
267 ifneq "$(HS_PPS)" ""
268
269 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
270
271 ifeq "$(HADDOCK)" ""
272 html ::
273         @echo Haddock must be installed in order to build HTML library documentation.
274         @echo Please install Haddock and re-configure.
275         @exit 1
276 endif
277
278 html :: $(HTML_DOC)
279
280 extraclean :: 
281         $(RM) -rf $(HTML_DIR)
282
283 $(HTML_DOC) : $(HS_PPS)
284         @$(INSTALL_DIR) $(HTML_DIR)
285         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
286                 --package=$(PACKAGE) \
287                 --dump-interface=$(PACKAGE).haddock \
288                 --use-index=../doc-index.html --use-contents=../index.html \
289                 --source-module=$(PackageSourceURL) \
290                 $(foreach pkg, $(PACKAGE_DEPS), \
291                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
292
293 CLEAN_FILES += $(PACKAGE).haddock
294
295 %.raw-hs : %.lhs
296         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
297
298 %.raw-hs : %.hs
299         $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
300
301 HTML_INSTALL_DIR = $(DESTDIR)$(htmldir)/libraries/html/$(PACKAGE)
302
303 install-docs :: $(HTML_DOC)
304         @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
305         for i in $(HTML_DIR)/*; do \
306           echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
307           $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
308         done; \
309         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
310
311 endif # HS_PPS
312 endif # HADDOCK_DOCS
313 endif # $(PACKAGE) /= ""
314
315 # -----------------------------------------------------------------------------
316