+# Building HsLibs libraries.
+#
+# Inputs:
+# $(PACKAGE) is the name of the library to build
+# $(IS_CBITS_LIB) should be "YES" for a "cbits" library
+#
+# Outputs:
+# $(LIBRARY) the name of the library.a
+# $(GHIC_LIBRARY) the name of the library.o (for GHCi)
+# $(LIBOBJS) objects to put in library
+# $(STUBOBJS) more objects to put in library
+#
+# $(LIBOBJS) is set to $(HS_OBJS) or $(C_OBJS) depending
+# on whether or not it's a "cbits" library. But you can
+# override this by setting $(LIBOBJS) yourself
+
+ifneq "$(PACKAGE)" ""
+
+# add syslib dependencies and current package name
+SRC_HC_OPTS += -package-name $(PACKAGE)
+SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
+
+ifeq "$(IS_CBITS_LIB)" "YES"
+_cbits := _cbits
+STUBOBJS += $(HSC_C_OBJS)
+# Add _hsc.c files to the cbits library
+C_SRCS += $(wildcard ../*_hsc.c)
+# Make .hsc.h include files from the directory above visible
+# (and the cbits/ library too).
+SRC_CC_OPTS += -I.. -I.
+endif
+
+ifneq "$(way)" "i"
+LIBRARY = libHS$(PACKAGE)$(_cbits)$(_way).a
+GHCI_LIBRARY = HS$(PACKAGE)$(_cbits)$(_way).o
+else
+LIBRARY = $(PACKAGE).dll
+endif
+
+ifneq "$(IS_CBITS_LIB)" "YES"
+WAYS=$(GhcLibWays)
+endif
+
+ifeq "$(LIBOBJS)" ""
+ ifeq "$(IS_CBITS_LIB)" "YES"
+ LIBOBJS = $(C_OBJS)
+ else
+ LIBOBJS = $(HS_OBJS)
+ endif
+endif
+
+ifeq "$(IS_CBITS_LIB)" "YES"
+override datadir:=$(libdir)/include
+INSTALL_DATAS += Hs$(shell perl -e 'print ucfirst "$(PACKAGE)"').h
+else
+SRC_CC_OPTS += -Icbits
+endif
+
+endif # PACKAGE
+
+#----------------------------------------