[project @ 2003-05-29 14:47:05 by reid]
[ghc-hetmet.git] / mk / package.mk
1 # -----------------------------------------------------------------------------
2 # $Id: package.mk,v 1.29 2003/05/29 14:47:05 reid 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 endif
28
29 package.conf.installed : package.conf.in
30         $(CPP) $(RAWCPP_FLAGS) $(PKGCONF_CPP_EXTRA_OPTS) -DINSTALLING -x c $(PACKAGE_CPP_OPTS) $< \
31                 | sed '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 # Let the package configuration file refer to $(libdir) as
63 # ${pkglibdir}.  Note we can't use ${libdir} because ghc-pkg already
64 # redefines it to point to GHC's libdir (bug or feature?).
65 #
66 install :: package.conf.installed
67         pkglibdir=$(libdir) $(GHC_PKG) --force --update-package <package.conf.installed
68
69 endif # $(STANDALONE_PACKAGE)
70
71 endif # $(way) == ""
72
73 # -----------------------------------------------------------------------------
74 # Building the static library libHS<pkg>.a
75
76 ifeq "$(STANDALONE_PACKAGE)" "NO"
77 HC = $(GHC_INPLACE)
78 endif
79
80 SRC_HSC2HS_OPTS += -I.
81
82 ifeq "$(NON_HS_PACKAGE)" ""
83 SRC_HC_OPTS     += -package-name $(PACKAGE)
84 SRC_HC_OPTS     += $(GhcLibHcOpts)
85 SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
86 endif
87
88 LIBRARY         = libHS$(PACKAGE)$(_way).a
89
90 WAYS            = $(GhcLibWays)
91
92 all :: $(LIBRARY)
93
94 # POSSIBLE alternative version using --make:
95 #
96 # lib : $(HS_SRCS)
97 #       $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
98
99 # $(LIBNAME) : lib
100 #       $(RM) $@
101 #       $(AR) $(AR_OPTS) $@ $(HS_OBJS)
102 #       $(RANLIB) $@
103
104 # %.o : %.hs
105 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
106 # %.o : %.lhs
107 #       $(GHC_INPLACE) $(HC_OPTS) --make $<
108
109 # -----------------------------------------------------------------------------
110 # Installation; need to install .hi files as well as libraries
111
112 ifeq "$(DLLized)" "YES"
113 INSTALL_PROGS += $(DLL_NAME)
114 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
115 endif
116
117 # The interface files are put inside the $(libdir), since they
118 # might (potentially) be platform specific..
119
120 ifeq "$(HIERARCHICAL_LIB)" "YES"
121 ifacedir = $(libdir)/imports
122 else
123 ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
124 endif
125
126 # If the lib consists of a hierachy of modules, we must retain the directory
127 # structure when we install the interfaces.
128 ifeq "$(HIERARCHICAL_LIB)" "YES"
129 INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
130 ifneq "$(ALL_DIRS)" ""
131 install ::
132         @for i in $(ALL_DIRS); do \
133                 $(INSTALL_DIR) $(ifacedir)/$$i; \
134         done
135 endif
136 else
137 INSTALL_IFACES += $(HS_IFACES)
138 endif
139
140 # -----------------------------------------------------------------------------
141 # Dependencies
142
143 ifeq "$(STANDALONE_PACKAGE)" "NO"
144 MKDEPENDHS = $(GHC_INPLACE)
145 endif
146
147 SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
148
149 ifeq "$(STANDALONE_PACKAGE)" "NO"
150 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
151 endif
152
153 endif # $(PACKAGE) /= ""
154
155 # install library (could be implicitly specified or explicitly, like libHS*_cbits.a)
156 INSTALL_LIBS  += $(LIBRARY)
157
158 #--------------------------------------------------------------
159 # Building dynamically-linkable libraries for GHCi
160 #
161 # Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
162 #
163 # Why?  GHCi can only link .o files (at the moment), not .a files
164 # so we have to build libFoo.o as well as libFoo.a
165 #
166 # Furthermore, GHCi currently never loads 
167 # profiling libraries (or other non-std ways)
168
169 ifneq "$(LIBRARY)" ""
170
171 ifeq "$(way)" ""
172 ifeq "$(GhcWithInterpreter)" "YES"
173
174 GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
175
176 INSTALL_LIBS += $(GHCI_LIBRARY)
177 CLEAN_FILES  += $(GHCI_LIBRARY)
178
179 all :: $(GHCI_LIBRARY)
180
181 ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
182 # If you don't want to build GHCI_LIBRARY the 'standard' way,
183 # set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
184 # hslibs/Win32 uses this 'feature', which will go away soon
185 # when we can use a "fixed" ld.
186 #
187 $(GHCI_LIBRARY) : $(LIBOBJS)
188         $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
189
190 endif # DONT_WANT_STD_GHCI_LIB_RULE
191 endif # GhcWithInterpreter
192 endif # way
193
194 # -----------------------------------------------------------------------------
195 # Doc building with Haddock
196
197 ifneq "$(NO_HADDOCK_DOCS)" "YES"
198
199 HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS))))
200
201 HTML_DIR = html
202 HTML_DOC = $(HTML_DIR)/index.html
203
204 ifneq "$(HS_PPS)" ""
205
206 CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
207
208 ifeq "$(HADDOCK)" ""
209 html ::
210         @echo Haddock must be installed in order to build HTML library documentation.
211         @echo Please install Haddock and re-configure.
212         @exit 1
213 endif
214
215 html :: $(HTML_DOC)
216
217 extraclean :: 
218         $(RM) -rf $(HTML_DIR)
219
220 $(HTML_DOC) : $(HS_PPS)
221         @$(INSTALL_DIR) $(HTML_DIR)
222         $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
223                 --dump-interface=$(PACKAGE).haddock \
224                 $(foreach pkg, $(PACKAGE_DEPS), \
225                    --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
226
227 CLEAN_FILES += $(PACKAGE).haddock
228
229 %.raw-hs : %.lhs
230         $(GHC) $(HC_OPTS) -D__HADDOCK__ -E -cpp $< -o $<.tmp && sed -e 's/^#.*//' <$<.tmp >$@
231
232 %.raw-hs : %.hs
233         $(GHC) $(HC_OPTS) -D__HADDOCK__ -E -cpp $< -o $<.tmp && sed -e 's/^#.*//' <$<.tmp >$@
234
235 install-docs :: $(HTML_DOC)
236         @$(INSTALL_DIR) $(datadir)/html/$(PACKAGE)
237         @for i in $(HTML_DIR)/*; do \
238            echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/$(PACKAGE); \
239            $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir)/html/$(PACKAGE); \
240         done
241         $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(datadir)/html/$(PACKAGE)
242
243 endif # HS_PPS
244 endif # NO_HADDOCK_DOCS
245
246 # -----------------------------------------------------------------------------
247
248 endif # $(LIBRARY) /= ""