package.mk 8.93 KB
Newer Older
1
# -----------------------------------------------------------------------------
2
# $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
3 4 5

ifneq "$(PACKAGE)" ""

6 7 8 9 10 11 12
# -----------------------------------------------------------------------------
# Directory layouts, installation etc.

# Here Windows & Unix differ.  On Windows, the value of $(prefix) is known
# to the compiler, and spliced into package.conf in place of $topdir at
# runtime.
#
13
# On Unix, we only use absolute paths in package.conf.
14 15 16 17 18 19 20 21 22
#

ifeq "$(Windows)" "YES"

PKG_LIBDIR  = $$topdir
PKG_DATADIR = $$topdir

else

23 24
PKG_LIBDIR  = $(libdir)
PKG_DATADIR = $(datadir)
25 26 27 28 29 30

endif # Unix

IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
IMPORT_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)

31
INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
32 33 34 35 36 37 38 39 40 41 42 43 44 45
INCLUDE_DIR_INPLACE   = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include

LIB_DIR_INSTALLED    = $(PKG_LIBDIR)
LIB_DIR_INPLACE	     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)

DATA_DIR_INSTALLED   = $(PKG_DATADIR)
DATA_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)

HTML_DIR_INPLACE     = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
HTML_DIR_INSTALLED   = $(PKG_DATADIR)/html/libraries/$(PACKAGE)

HADDOCK_IFACE_INPLACE   = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock

46 47 48
# -----------------------------------------------------------------------------
# Build the package configuration file and tell the compiler about it.

49 50 51
# We want to build two versions of the package configuration: one for use
# in the 

52 53
ifeq "$(way)" ""

54
PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
55

56 57 58
PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
PACKAGE_CPP_OPTS += -DVERSION=${VERSION}

59 60
PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
61

ross's avatar
ross committed
62
package.conf.inplace   : package.conf.in
63 64 65
	$(CPP) $(RAWCPP_FLAGS) -P \
		-DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
		-DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
66 67 68 69
		-DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
		-DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
		-DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
		-DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
70
		-DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
71
		-x c $(PACKAGE_CPP_OPTS) $< | \
72
	grep -v '^#pragma GCC' | \
73
	sed -e 's/""//g' -e 's/:[ 	]*,/: /g' >$@
74

75
install::
76
	$(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
77 78 79 80 81 82 83 84 85 86 87
	       -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
	       -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
	       -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
	       -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
	       -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
	       -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
	       -I../includes \
	       -x c $(PACKAGE_CPP_OPTS) package.conf.in \
	    | grep -v '^#pragma GCC' \
	    | sed -e 's/""//g' -e 's/:[   ]*,/: /g' \
	    | $(bindir)/ghc-pkg update - --force
reid's avatar
reid committed
88

89
# we could be more accurate here and add a dependency on
90
# driver/package.conf, but that doesn't work too well because of
91 92 93 94 95
# make's limited accuracy with modification times: when doing 'make
# boot' in multiple packages, make won't detect that the package
# configuration needs updating if it was updated already in the last
# second.
#
96 97 98 99
# The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
# to 'make clean' in ghc without cleaning in libraries too, the packages
# will be correctly re-installed.
#
100

101
STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
102 103
CLEAN_FILES += $(STAMP_PKG_CONF)

104
ifneq "$(BootingFromHc)" "YES"
105
boot all :: $(STAMP_PKG_CONF)
106
endif
107

108
$(STAMP_PKG_CONF) : package.conf.inplace
109
	$(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
110
	@touch $(STAMP_PKG_CONF)
111

112
CLEAN_FILES += package.conf.inplace 
113 114 115 116 117 118 119 120

endif # $(way) == ""

# -----------------------------------------------------------------------------
# Building the static library libHS<pkg>.a

SRC_HSC2HS_OPTS += -I.

Simon Marlow's avatar
Simon Marlow committed
121
ifneq "$(NO_SET_HC)" "YES"
122
HC = $(GHC_INPLACE)
Simon Marlow's avatar
Simon Marlow committed
123
endif
124
IGNORE_PACKAGE_FLAG = -package-name  $(PACKAGE)-$(VERSION)
125

126
ifeq "$(NON_HS_PACKAGE)" ""
127
SRC_HC_OPTS	+= $(IGNORE_PACKAGE_FLAG)
128 129
SRC_HC_OPTS 	+= $(GhcLibHcOpts)
SRC_HC_OPTS     += $(patsubst %, -package %, $(PACKAGE_DEPS))
130
endif
131

132 133 134 135 136 137 138 139
#	-fgenerics switches on generation of support code for 
#		derivable type classes.  This is now off by default,
#		but we switch it on for the libraries so that we generate
#		the code in case someone importing wants it.
ifeq "$(NON_HS_PACKAGE)" ""
SRC_HC_OPTS	+= -fgenerics
endif

sof's avatar
sof committed
140
ifndef LIBRARY
141 142 143
ifeq "$(_way:%_dyn=YES)" "YES"
LIBRARY      	= libHS$(PACKAGE)$(_way:%_dyn=%)-ghc$(ProjectVersion)$(soext)
else
144
LIBRARY      	= libHS$(PACKAGE)$(_way).a
sof's avatar
sof committed
145
endif
146
endif
147

148 149 150
ifeq "$(WAYS)" ""
WAYS = $(GhcLibWays)
endif
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

all :: $(LIBRARY)

# POSSIBLE alternative version using --make:
#
# lib : $(HS_SRCS)
# 	$(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
# 
# $(LIBNAME) : lib
# 	$(RM) $@
# 	$(AR) $(AR_OPTS) $@ $(HS_OBJS)
# 	$(RANLIB) $@
# 
# %.o : %.hs
# 	$(GHC_INPLACE) $(HC_OPTS) --make $<
# %.o : %.lhs
# 	$(GHC_INPLACE) $(HC_OPTS) --make $<

169 170
# -----------------------------------------------------------------------------
# Installation; need to install .hi files as well as libraries
171 172 173 174 175 176

ifeq "$(DLLized)" "YES"
INSTALL_PROGS += $(DLL_NAME)
INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
endif

177 178
# The interface files are put inside the $(libdir), since they
# might (potentially) be platform specific..
179

180 181 182 183 184
ifeq "$(HIERARCHICAL_LIB)" "YES"
ifacedir = $(libdir)/imports
else
ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
endif
185

186 187 188
# If the lib consists of a hierachy of modules, we must retain the directory
# structure when we install the interfaces.
ifeq "$(HIERARCHICAL_LIB)" "YES"
189
INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
190
ifneq "$(ALL_DIRS)" ""
191 192
install ::
	@for i in $(ALL_DIRS); do \
193
		$(INSTALL_DIR) $(ifacedir)/$$i; \
194
	done
195
endif
196
else
197
INSTALL_IFACES += $(HS_IFACES)
198 199
endif

200 201 202 203
# -----------------------------------------------------------------------------
# Dependencies

MKDEPENDHS = $(GHC_INPLACE)
204 205 206

SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
207

208 209
endif # $(PACKAGE) != ""

210 211 212 213 214 215 216
#--------------------------------------------------------------
# Installation

ifneq "$(NO_INSTALL_LIBRARY)" "YES"
INSTALL_LIBS  += $(LIBRARY) $(GHCI_LIBRARY)
endif

217 218 219
#--------------------------------------------------------------
# Building dynamically-linkable libraries for GHCi
#
220
# Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
221 222 223 224 225 226
#
# Why?  GHCi can only link .o files (at the moment), not .a files
# so we have to build libFoo.o as well as libFoo.a
#
# Furthermore, GHCi currently never loads 
# profiling libraries (or other non-std ways)
227 228

ifneq "$(LIBRARY)" ""
229 230 231 232

ifeq "$(way)" ""
ifeq "$(GhcWithInterpreter)" "YES"

sof's avatar
sof committed
233
ifndef GHCI_LIBRARY
234
GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
sof's avatar
sof committed
235
endif
236

237 238 239 240 241 242 243 244 245 246
CLEAN_FILES  += $(GHCI_LIBRARY)

all :: $(GHCI_LIBRARY)

ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
# If you don't want to build GHCI_LIBRARY the 'standard' way,
# set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
# hslibs/Win32 uses this 'feature', which will go away soon
# when we can use a "fixed" ld.
#
247
$(GHCI_LIBRARY) : $(LIBOBJS)
248
	$(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
249 250 251 252

endif # DONT_WANT_STD_GHCI_LIB_RULE
endif # GhcWithInterpreter
endif # way
253
endif # $(LIBRARY) /= ""
254

255 256 257
# -----------------------------------------------------------------------------
# Doc building with Haddock

258
ifneq "$(PACKAGE)" ""
259
ifeq "$(HADDOCK_DOCS)" "YES"
260

Dinko Tenev's avatar
Dinko Tenev committed
261
HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
262

263
HTML_DIR = ../html-docs/$(PACKAGE)
264
HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
265 266

ifneq "$(HS_PPS)" ""
267

268
CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
269

270 271 272 273 274 275 276
ifeq "$(HADDOCK)" ""
html ::
	@echo Haddock must be installed in order to build HTML library documentation.
	@echo Please install Haddock and re-configure.
	@exit 1
endif

277 278
html :: $(HTML_DOC)

279 280 281
extraclean :: 
	$(RM) -rf $(HTML_DIR)

282 283 284 285 286 287
ifneq "$(findstring $(PACKAGE), $(CorePackages))" ""
HaddockSourceURL = $(CorePackageSourceURL)
else
HaddockSourceURL = $(ExtraPackageSourceURL)
endif

288
$(HTML_DOC) : $(HS_PPS)
289
	@$(INSTALL_DIR) $(HTML_DIR)
290
	$(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
291
		--package=$(PACKAGE) \
292
		--dump-interface=$(PACKAGE).haddock \
293
		--use-index=../doc-index.html --use-contents=../index.html \
294
		--source-module=$(HaddockSourceURL) \
295 296
		$(foreach pkg, $(PACKAGE_DEPS), \
		   --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
297

298 299
CLEAN_FILES += $(PACKAGE).haddock

300
%.raw-hs : %.lhs
301
	$(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
302 303

%.raw-hs : %.hs
304
	$(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
305

306 307
HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)

308
install-docs :: $(HTML_DOC)
309
	@$(INSTALL_DIR) $(HTML_INSTALL_DIR)
310 311 312 313 314
	for i in $(HTML_DIR)/*; do \
	  echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
	  $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
	done; \
	$(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
315 316

endif # HS_PPS
317
endif # HADDOCK_DOCS
318
endif # $(PACKAGE) /= ""
319 320 321

# -----------------------------------------------------------------------------