## -*- text -*- ####################################################
#								   #
# Makefile for the GNU Readline and History Libraries.		   #
#								   #
####################################################################

# This Makefile is hand made from a template file, found in
# ../template.  Each library must provide several Makefile
# targets: `all', `clean', `documentation', `install', and
# `what-tar'.  The `what-tar' target reports the names of the
# files that need to be included in a tarfile to build the full
# code and documentation for this library.

# Please note that the values for INCLUDES, CC, AR, RM, CP,
# RANLIB, and selfdir are passed in from ../Makefile, and do
# not need to be defined here.
srcdir = .
incdir = /usr/include
bindir = /lib
VPATH = .:$(srcdir)

CC=gcc

CP=cp
RM=rm -f

AR=ar
RANLIB=ranlib
STRIP=strip
AS=as

# H.J.Lu says dont use the shared libtermcap and curses anymore as it will
# be detatched from the core libc. So we link in the static functions
# If you have deleted your libtermcap.sa then you may change this to -ltermcap
LIBTERMCAP=/usr/lib/libtermcap.a

# *****************LINUX SPECIFIC DLL STUFF*********************
# Where are your DLL tools ??
DLL_TOOLS_PATH=/usr/bin

# Where is your DLL assembler ??
JUMP_AS_PATH=/usr/bin/jump

GCC_LIB=`$(CC) --print-libgcc-file-name`

JUMP_DIR=jump
JUMP_LIB=libreadline

DLL_VERSION=2.0.3
DLL_LOADADDR=0x60400000

export JUMP_DIR JUMP_LIB

# Here is a rule for making .o files from .c files that doesn't force
# the type of the machine (like -sun3) into the flags.

.c.o:
	$(CC) -S -c $(CFLAGS) $(LOCAL_DEFINES) $(CPPFLAGS) $*.c -o $*.s
# The DLL object
	@$(JUMP_AS_PATH)as -o $(JUMP_DIR)/$*.o $*.s 2>/dev/null
# The static object
	@$(AS) -o $*.o $*.s
	@$(RM) $*.s

#
# See the file STANDALONE for the -D defines that readline understands
#
LOCAL_DEFINES = $(LOCAL_INCLUDES)

# Some systems need to define this (like older NeXT systems) in order
# to prevent namespace conflicts.
CFLAGS =-O2 \
	-DHAVE_CONFIG_H \
	-DHAVE_UNISTD_H \
	-DHAVE_VARARGS_H \
	-DHAVE_STRING_H \
	-DHAVE_DIRENT_H \
	-DHAVE_STDLIB_H \
	-DHAVE_ALLOCA_H \
	#-DSHELL -DSTATIC_MALLOC

# For libraries which include headers from other libraries.
LOCAL_INCLUDES = -I. -I..

# The name of the main library target.
LIBRARY_NAME = libreadline.a

# The C code source files for this library.
CSOURCES = $(srcdir)readline.c $(srcdir)funmap.c $(srcdir)keymaps.c \
	   $(srcdir)vi_mode.c $(srcdir)parens.c $(srcdir)rltty.c \
	   $(srcdir)complete.c $(srcdir)bind.c $(srcdir)isearch.c \
	   $(srcdir)display.c $(srcdir)signals.c $(srcdir)emacs_keymap.c \
	   $(srcdir)vi_keymap.c $(srcdir)history.c $(srcdir)tilde.c \
	   $(srcdir)xmalloc.c

# The header files for this library.
HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h \
	   posixstat.h tilde.h

OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
	  rltty.o complete.o bind.o isearch.o display.o signals.o \
	  history.o tilde.o xmalloc.o

# The texinfo files which document this library.
DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
DOCOBJECT = doc/readline.dvi
DOCSUPPORT = doc/Makefile
DOCUMENTATION = $(DOCSOURCE) $(DOCOBJECT) $(DOCSUPPORT)

SUPPORT = Makefile ChangeLog $(DOCSUPPORT) examples/[-a-z.]*

SOURCES  = $(CSOURCES) $(HSOURCES) $(DOCSOURCE)

THINGS_TO_TAR = $(SOURCES) $(SUPPORT)

##########################################################################

all: libreadline.a libhistory.a $(JUMP_DIR)/$(JUMP_LIB).a

libreadline.a: $(OBJECTS)
	$(RM) -f $@
	$(AR) cq $@ $(OBJECTS)
	-if [ -f "$(RANLIB)" ]; then $(RANLIB) $@; fi

libhistory.a: history.o
	$(RM) -f $@
	$(AR) cq $@ history.o
	-if [ -f "$(RANLIB)" ]; then $(RANLIB) $@; fi

documentation: force
	-mkdir doc
	(if [ -d doc ]; then cd doc; $(MAKE) $(MFLAGS); fi)
force:

# The rule for 'includes' is written funny so that the if statement
# always returns TRUE unless there really was an error installing the
# include files.
install:
	if [ -r $(incdir)/readline ]; then \
	  :; \
	else \
	  mkdir $(incdir)/readline && chmod a+r $(incdir)/readline; \
	fi
	$(CP) readline.h keymaps.h chardefs.h history.h tilde.h $(incdir)/readline/
	-mv /usr/$(bindir)/libreadline.a /usr/$(bindir)/libreadline.old
	-cp libreadline.a /usr/$(bindir)/libreadline.a
	if [ -f /usr/bin/"$(RANLIB)" ]; then $(RANLIB) -t /usr/$(bindir)/libreadline.a; fi
	-cp libreadline.a libreadline.sa /usr/$(bindir)
	-cp *.so.* $(bindir)
	-ldconfig -X

clean:
	rm -f $(OBJECTS) *.a\
		$(JUMP_DIR)/*.o $(JUMP_DIR)/*.a \
		$(JUMP_DIR)/_* $(JUMP_DIR)/jump.[pu]* lib*s[oa]*
	(if [ -d doc ]; then cd doc; $(MAKE) $(MFLAGS) $@; fi)

readline: readline.h rldefs.h chardefs.h
readline: $(OBJECTS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \
	  $(LOCAL_INCLUDES) -DTEST -o readline readline.c vi_mode.o funmap.o \
	  keymaps.o $(LIBTERMCAP)

# ***********NO USER SERVICEABLE PARTS BELOW THIS LINE************

check:
	@if [ ! -d $(JUMP_DIR) ]; then \
		echo *******[ No jump files found ]*******;\
		exit 1;\
	 fi

$(JUMP_DIR)/$(JUMP_LIB).a: $(JUMP_LIB).a
	(cd $(JUMP_DIR); $(AR) cr $(JUMP_LIB).a $(OBJECTS); $(RANLIB) $(JUMP_LIB).a)
	$(DLL_TOOLS_PATH)/mkimage -f -l librl -v $(DLL_VERSION) -a $(DLL_LOADADDR) \
		-g 4096 -j 0x4000 -- $(JUMP_DIR)/$(JUMP_LIB).a \
		$(LIBTERMCAP) -lc $(GCC_LIB) -lc
	$(DLL_TOOLS_PATH)/mkstubs -f -l librl -v $(DLL_VERSION) -a $(DLL_LOADADDR) \
		-g 4096 -j 0x4000 -- $(JUMP_LIB)
	$(STRIP) librl.so.$(DLL_VERSION)
	$(DLL_TOOLS_PATH)/libinfo $(JUMP_LIB).sa

# Dependencies
readline.o: readline.c readline.h rldefs.h rlconf.h chardefs.h
readline.o: keymaps.h history.h
vi_mode.o:  rldefs.h rlconf.h readline.h history.h
funmap.o:   funmap.c readline.h rlconf.h
keymaps.o:  keymaps.c emacs_keymap.c vi_keymap.c keymaps.h chardefs.h rlconf.h
history.o: history.h memalloc.h
isearch.o: memalloc.h readline.h history.h
search.o: memalloc.h readline.h history.h
display.o: readline.h history.h rldefs.h rlconf.h
complete.o: readline.h rldefs.h rlconf.h
rltty.o: rldefs.h rlconf.h readline.h
bind.o: rldefs.h rlconf.h readline.h history.h
signals.o: rldefs.h rlconf.h readline.h history.h
parens.o: readline.h

