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