# Generated automatically from Makefile.in by configure.
#  $NetBSD: Makefile,v 1.20 2001/01/05 21:15:49 jdolecek Exp $
#  @(#)Makefile    8.1 (Berkeley) 6/4/93
# modified for Linux port by Oliver Kurth <kurth@innomiate.de>
# modified by Stanislav Malyshev <stas@zend.com>

CC=gcc
prefix = /usr/local
exec_prefix = ${prefix}
MANDIR=${prefix}/man
LIBDIR=${exec_prefix}/lib
INCDIR = ${prefix}/include
INSTALL=/usr/bin/install -c
CFLAGS=-g -O2

srcdir=.
.CURDIR=.

OSRCS=	chared.c common.c el.c emacs.c fcns.c help.c hist.c key.c map.c \
	parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c \
	fgetln.c strlcpy.c

OOBJS=	chared.o common.o el.o emacs.o fcns.o hist.o history.o key.o map.o \
	parse.o prompt.o read.o refresh.o search.o sig.o term.o tokenizer.o \
	tty.o vi.o help.o fgetln.o readline.o strlcpy.o

MAN=	editline.3 editrc.5

MLINKS=	editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
	editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \
	editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_get.3 \
	editline.3 el_source.3 editline.3 el_resize.3 editline.3 el_line.3 \
	editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
	editline.3 history_init.3 editline.3 history_end.3 editline.3 history.3

# For speed and debugging
#SRCS=   ${OSRCS} tokenizer.c history.c readline.c
# For protection
SRCS=	editline.c tokenizer.c history.c readline.c

SRCS+=	common.h emacs.h fcns.h help.h vi.h

LIBEDITDIR?=${.CURDIR}

CLEANFILES+=common.h emacs.h fcns.h help.h vi.h help.c fcns.c editline.c
CLEANFILES+=common.h.tmp editline.c.tmp emacs.h.tmp fcns.c.tmp fcns.h.tmp
CLEANFILES+=help.c.tmp help.h.tmp vi.h.tmp

CFLAGS+=-I. -I${.CURDIR}
CFLAGS+=-g -O0
CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
CFLAGS+=#-DDEBUG_PASTE

AHDR=vi.h emacs.h common.h 
ASRC=${.CURDIR}/vi.c ${.CURDIR}/emacs.c ${.CURDIR}/common.c

# Force serialization here to support -j: dependencies must
# be fully built first. --cpk
#
all: .depend
	$(MAKE) libedit.a
#	$(MAKE) libedit.so

vi.h: vi.c makelist
	sh ${.CURDIR}/makelist -h ${.CURDIR}/vi.c > $@.tmp && \
	  mv $@.tmp $@

emacs.h: emacs.c makelist
	sh ${.CURDIR}/makelist -h ${.CURDIR}/emacs.c > $@.tmp && \
	  mv $@.tmp $@

common.h: common.c makelist
	sh ${.CURDIR}/makelist -h ${.CURDIR}/common.c > $@.tmp && \
	  mv $@.tmp $@

fcns.h: ${AHDR} makelist
	sh ${.CURDIR}/makelist -fh ${AHDR} > $@.tmp && \
	  mv $@.tmp $@

fcns.c: ${AHDR} fcns.h makelist
	sh ${.CURDIR}/makelist -fc ${AHDR} > $@.tmp && \
	  mv $@.tmp $@

help.c: ${ASRC} makelist 
	sh ${.CURDIR}/makelist -bc ${ASRC} > $@.tmp && \
	  mv $@.tmp $@

help.h: ${ASRC} makelist
	sh ${.CURDIR}/makelist -bh ${ASRC} > $@.tmp && \
	  mv $@.tmp $@

editline.c: ${OSRCS}
	sh ${.CURDIR}/makelist -e ${ASRC} > $@.tmp && \
	  mv $@.tmp $@

.depend: vi.h emacs.h common.h fcns.h fcns.c help.h help.c editline.c

test.o:	${LIBEDITDIR}/TEST/test.c

test:	libedit.a test.o 
	${CC} ${CFLAGS} ${LIBEDITDIR}/TEST/test.c -o $@ libedit.a ${LDADD} -lcurses -ltermcap

.c.o:
	${CC} ${CFLAGS} -c $<

libedit.a: ${OOBJS}
	ar -r $@ ${OOBJS}

libedit.so: ${OOBJS}
	${CC} --shared -o $@ ${OOBJS}

# minimal dependency to make "make depend" optional
editline.o editline.po editline.so editline.ln:	\
	common.h emacs.h fcns.c fcns.h help.c help.h vi.h
readline.o readline.po readline.so readline.ln:	\
	common.h emacs.h fcns.h help.h vi.h

install: libedit.a libedit.so
	${INSTALL} -d ${LIBDIR}
	${INSTALL} libedit.a ${LIBDIR}
	${INSTALL} libedit.so ${LIBDIR}
	${INSTALL} -d ${INCDIR}
	${INSTALL} -m 644 histedit.h ${INCDIR}
	${INSTALL} -d ${INCDIR}/readline/
	${INSTALL} -m 644 readline/readline.h ${INCDIR}/readline/
	${INSTALL} -d ${MANDIR}/man3/
	${INSTALL} -m 644 editline.3 ${MANDIR}/man3/
	${INSTALL} -d ${MANDIR}/man5/
	${INSTALL} -m 644 editrc.5 ${MANDIR}/man5/

clean:
	rm -f *.o
	rm -f *~ \#*\#
	rm -f ${CLEANFILES}

distclean: clean
	rm -f *.so *.a config.*

${srcdir}/configure: configure.in
	cd ${srcdir} && autoconf

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

package: distclean
	tar --exclude CVS -cvzf libedit.tar.gz *.[ch35] install-sh *.in configure Makefile TEST/*.[ch] readline/*.[ch] makelist
