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