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