TOP=..
include $(TOP)/mk/boilerplate.mk

SUBDIRS      = include

ALL_DIRS     = System/Console
PACKAGE      = readline
VERSION	     = 1.0
PACKAGE_DEPS = base

SRC_HC_OPTS += -Iinclude
SRC_CC_OPTS += -Iinclude
SRC_HSC2HS_OPTS += -Iinclude

SRC_HADDOCK_OPTS += -t "Haskell Hierarchical Libraries ($(PACKAGE) package)"

# yeuch, have to get LibsReadline in through CPP to package.conf.in
empty =
space = $(empty) $(empty)
comma = ,
PACKAGE_CPP_OPTS += -DLibsReadline='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(LibsReadline))))'

# Remove Readline.hs if it is not wanted or headers are not available.
ifeq "$(GhcLibsWithReadline)" "YES"
  ifneq "$(ReadlineIncludePath)" ""
    SRC_HC_OPTS += -I$(ReadlineIncludePath)
    SRC_CC_OPTS += -I$(ReadlineIncludePath)
    SRC_HSC2HS_OPTS += -I$(ReadlineIncludePath)
  endif
ifneq "$(BootingFromHc)" "YES"
  STUBOBJS += System/Console/Readline_stub.$(way_)o
endif
  CLEAN_FILES += System/Console/Readline_stub.[ch] $(STUBOBJS)
else
  EXCLUDED_SRCS += System/Console/Readline.hsc System/Console/Readline_stub.c
endif

ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
#
# The 'readline' library is only supplied in static form with mingw (libreadline.a).
# The GHCi linker isn't capable of slurping in archives, so we're forced to convert
# that library into a relocatable .o (=> and install&bundle it.)
#
readline.o:
	$(word 1,$(AR)) x `$(CC) -print-file-name=libmoldname.a` strcasecmp.o strncasecmp.o
	$(LD) -r -o readline.o --whole-archive `$(CC) -print-file-name=libreadline.a` strcasecmp.o strncasecmp.o
	$(RM) strcasecmp.o strncasecmp.o

INSTALL_LIBS=readline.o
CLEAN_FILES=readline.o
endif

include $(TOP)/mk/target.mk
