# Makefile for less.

#### Start of system configuration section. ####

srcdir = @srcdir@
VPATH = @srcdir@

CC = @CC@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

CFLAGS = -O
CFLAGS_COMPILE_ONLY = -c
LDFLAGS = 
O=o

LIBS = @LIBS@

prefix = /usr/local
exec_prefix = $(prefix)

# Where the installed binary goes.
bindir = $(exec_prefix)/bin
binprefix = 

# Where the help file goes.
datadir = $(prefix)/lib

mandir = $(prefix)/man/man$(manext)
manext = 1
manprefix = 

#### End of system configuration section. ####

SHELL = /bin/sh

# This rule allows us to supply the necessary -D options
# in addition to whatever the user asks for.
.c.o:
	$(CC) -I. $(CFLAGS_COMPILE_ONLY) $(CPPFLAGS) $(CFLAGS) $<

SRC =	main.c screen.c brac.c ch.c charset.c cmdbuf.c \
	command.c decode.c edit.c filename.c forwback.c \
	help.c ifile.c input.c jump.c line.c linenum.c \
	lsystem.c mark.c optfunc.c option.c opttbl.c os.c \
	output.c position.c prompt.c search.c signal.c \
	tags.c ttyin.c version.c  
OBJ =	main.$(O) screen.$(O) brac.$(O) ch.$(O) charset.$(O) cmdbuf.$(O) \
	command.$(O) decode.$(O) edit.$(O) filename.$(O) forwback.$(O) \
	help.$(O) ifile.$(O) input.$(O) jump.$(O) line.$(O) linenum.$(O) \
	lsystem.$(O) mark.$(O) optfunc.$(O) option.$(O) opttbl.$(O) os.$(O) \
	output.$(O) position.$(O) prompt.$(O) search.$(O) signal.$(O) \
	tags.$(O) ttyin.$(O) version.$(O)  @REGEX_O@
DISTFILES = ${SRC} regexp.c regexp.h \
	INSTALL Makefile.in Makefile.dos README NEWS \
	configure configure.in doscreen.c acconfig.h lesskey.c \
	cmd.h defines.dos funcs.h less.h option.h position.h \
	install.sh defines.h.in defines.h.top mkinstalldirs \
	less.nro lesskey.nro less.man lesskey.man less.hlp 

all: less lesskey

less: $(OBJ)
	$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)

lesskey: lesskey.$(O)
	$(CC) $(LDFLAGS) -o $@ lesskey.$(O)

$(OBJ): less.h defines.h funcs.h

filename.$(O): filename.c
	${CC} -c -DHELPFILE=\"${datadir}/less.hlp\" -I. ${CPPFLAGS} ${CFLAGS} ${srcdir}/filename.c

install: all less.hlp less.nro installdirs
	${INSTALL_PROGRAM} less ${bindir}/${binprefix}less
	${INSTALL_PROGRAM} lesskey ${bindir}/${binprefix}lesskey
	${INSTALL_DATA} ${srcdir}/less.hlp ${datadir}/less.hlp
	${INSTALL_DATA} ${srcdir}/less.nro ${mandir}/${manprefix}less.${manext}
	${INSTALL_DATA} ${srcdir}/lesskey.nro ${mandir}/${manprefix}lesskey.${manext}

installdirs: mkinstalldirs
	${srcdir}/mkinstalldirs ${bindir} ${datadir} ${mandir}

uninstall:
	rm -f ${bindir}/${binprefix}less ${bindir}/${binprefix}lesskey
	rm -f ${datadir}/less.hlp
	rm -f ${mandir}/less.${manext} ${mandir}/lesskey.${manext}

info:
install-info:
dvi:
check:
installcheck:

TAGS:
	cd ${srcdir} && etags *.c *.h

# config.status might not change defines.h
# Don't rerun config.status if we just configured (so there's no stamp-h).
defines.h: stamp-h
stamp-h: defines.h.in config.status
	test ! -f stamp-h || ./config.status
	touch stamp-h
Makefile: Makefile.in config.status
	./config.status
config.status: configure
	./config.status --recheck

lint:
	lint -I. $(CPPFLAGS) $(SRC)
clean:
	rm -f *.$(O) core less lesskey

mostlyclean: clean

distclean: clean
	rm -f Makefile config.status defines.h stamp-h

realclean: distclean
	rm -f TAGS

dist: ${DISTFILES}
	if [ ! -d release ]; then mkdir release; fi
	@REL=`sed -e '/char version/!d' -e 's/[^0-9.]*\([0-9.]*\).*/less-\1/' -e q version.c`; \
	rm -rf release/$$REL; mkdir release/$$REL; \
	echo "Creating release/$$REL/$$REL.tar.gz"; \
	rm -rf $$REL; mkdir $$REL; \
	for file in ${DISTFILES}; do \
	  ln $$file $$REL || \
	  { echo "cannot link, copying $$file"; cp -p $$file $$REL; }; \
	done; \
	tar -chf - $$REL | gzip -c >release/$$REL/$$REL.tar.gz; \
	rm -rf $$REL; \
	echo "Creating release/$$REL/$$REL.shar.Z"; \
	shar ${DISTFILES} | compress -c >release/$$REL/$$REL.shar.Z
