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