## -*- text -*- ####################################################
#								   #
# Makefile for readline and history libraries.			   #
#								   #
####################################################################

# 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) -c $(CFLAGS) $(LOCAL_INCLUDES) $(CPPFLAGS) $*.c

# Destination installation directory.  The libraries are copied to DESTDIR
# when you do a `make install', and the header files to INCDIR/readline/*.h.
DESTDIR = /usr/local/lib
INCDIR = /usr/local/include

# Define TYPES as -DVOID_SIGHANDLER if your operating system uses
# a return type of "void" for signal handlers.
# TYPES = -DVOID_SIGHANDLER

# Define USG as -DUSG if you are using a System V operating system.
USG = #-DUSG

# HP-UX compilation requires the BSD library.
#LOCAL_LIBS = -lBSD

# Xenix compilation requires -ldir -lx
#LOCAL_LIBS = -ldir -lx

# Comment out "-DVI_MODE" if you don't think that anyone will ever desire
# the vi line editing mode and features.
READLINE_DEFINES = $(TYPES) # -DVI_MODE

# If you don't have alloca
ALLOCA=     # alloca.o
# If not defined above
# OPT = # -O behaves wierd on irix and some others. !
DEBUG_FLAGS =  # -g
LDFLAGS = $(DEBUG_FLAGS) -lmalloc
#-cckr -DBSD_COMPAT -DBSD_SIGNALS
CFLAGS = $(DEBUG_FLAGS) $(USG) $(OTH_CFLAGS)

# A good alternative is gcc -traditional.
#CC = gcc # -traditional
CC = cc
RANLIB = /usr/bin/ranlib
AR = ar
RM = rm
CP = cp

CSOURCES = readline.c history.c funmap.c keymaps.c vi_mode.c \
	   emacs_keymap.c vi_keymap.c alloca.c

HSOURCES = readline.h chardefs.h history.h keymaps.h
SOURCES  = $(CSOURCES) $(HSOURCES)

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

libreadline.a:	readline.o history.o funmap.o keymaps.o $(ALLOCA)
	$(RM) -f libreadline.a
	$(AR) clq libreadline.a readline.o history.o funmap.o keymaps.o $(ALLOCA)
	-if [ -f $(RANLIB) ]; then $(RANLIB) libreadline.a; fi

readline.o:	readline.c readline.h chardefs.h  keymaps.h history.h vi_mode.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) $*.c

history.o:	history.c history.h
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) $*.c

funmap.o:	funmap.c readline.h
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) $*.c

keymaps.o:	keymaps.c emacs_keymap.c vi_keymap.c keymaps.h chardefs.h
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) $*.c

test:
	$(CC) -g -c -DUSG -D_BSD_COMPAT history.c 
	$(CC) -g -c -DUSG -D_BSD_COMPAT funmap.c 
	$(CC) -g -c -DUSG -D_BSD_COMPAT keymaps.c 
	$(CC) -g -o test -DUSG -D_BSD_COMPAT -DTEST readline.c \
	history.o funmap.o keymaps.o -ltermcap

clean:
	rm -f *.o *.a test core

