# Makefile for "less"
# Generated Thu Sep 22 13:28:32 PDT 1988 by linstall.
#
# Invoked as:
#	make all
#   or	make install
# Plain "make" is equivalent to "make all".
#
# If you add or delete functions, remake funcs.h by doing:
#	make newfuncs
# This depends on the coding convention of function headers looking like:
#	" \t public <function-type> \n <function-name> ( ... ) "
#
# Also provided:
#	make lint	# Runs "lint" on all the sources.
#	make clean	# Removes "less" and the .o files.
#	make clobber	# Pretty much the same as make "clean".

SHELL = /bin/sh


##########################################################################
# Compilation environment.
##########################################################################
l=/usr/lib
# LIBS is the list of libraries needed.
#LIBS = -ltermlib
LIBS = $l/libc.a $l/libtermcap.a
# INSTALL_LESS is a list of the public versions of less.
# INSTALL_KEY is a list of the public versions of lesskey.
# INSTALL_HELP is a list of the public version of the help file.
# INSTALL_LESSMAN is a list of the public versions of the less manual page.
# INSTALL_KEYMAN is a list of the public versions of the lesskey manual page.
INSTALL_LESS =		$(ROOT)/usr/local/bin/less
INSTALL_KEY =		$(ROOT)/usr/local/bin/lesskey
INSTALL_HELP =		$(ROOT)/usr/local/bin/less.help
INSTALL_LESSMAN =	$(ROOT)/usr/man/man1/less.1
INSTALL_KEYMAN =	$(ROOT)/usr/man/man1/lesskey.1
LESS_MANUAL =		less.nro
KEY_MANUAL =		lesskey.nro
HELPFILE =		/usr/local/bin/less.help


# OPTIM is passed to the compiler and the loader.
# It is normally "-O" but may be, for example, "-g".
#OPTIM = -O

#CFLAGS = $(OPTIM)
CFLAGS = -Di8088 -F -i
LDFLAGS = -Di8088 -F -i


##########################################################################
# Files
##########################################################################

SRC1 =	main.c option.c prim.c ch.c position.c input.c linenum.c
SRC2 =	screen.c prompt.c line.c signal.c os.c help.c ttyin.c command.c
SRC3 =	output.c decode.c tags.c version.c regerror.c
SRC =	$(SRC1) $(SRC2) $(SRC3)
OBJ =	main.s option.s prim.s ch.s position.s input.s output.s \
	screen.s prompt.s line.s signal.s os.s help.s ttyin.s \
	decode.s command.s linenum.s tags.s version.s regerror.s


##########################################################################
# Rules for building stuff
##########################################################################

all: less lesskey
install: install_less install_help install_key install_lman install_kman

less: $(OBJ)
	$(CC) $(LDFLAGS) $(OPTIM) -o less $(OBJ) $(LIBS) $(LDLIBS)

lesskey: lesskey.s
	$(CC) $(LDFLAGS) $(OPTIM) -o lesskey lesskey.s $(LDLIBS)

# help.s depends on makefile for the definition of HELPFILE
help.s: makefile
	$(CC) $(CFLAGS) -c -DHELPFILE=\"$(HELPFILE)\" help.c

install_less: less
	for f in $(INSTALL_LESS); do  rm -f $$f; cp less $$f;  done
	touch install_less

install_key: lesskey
	for f in $(INSTALL_KEY); do  rm -f $$f; cp lesskey $$f;  done
	touch install_key

install_help: less.help
	for f in $(INSTALL_HELP); do  rm -f $$f; cp less.help $$f;  done
	touch install_help

install_lman: $(LESS_MANUAL) 
	for f in $(INSTALL_LESSMAN); do  rm -f $$f; cp $(LESS_MANUAL) $$f;  done
	touch install_lman

install_kman: $(KEY_MANUAL)
	for f in $(INSTALL_KEYMAN); do  rm -f $$f; cp $(KEY_MANUAL) $$f;  done
	touch install_kman

##########################################################################
# Maintenance
##########################################################################

lint:
	lint -hp $(SRC)

newfuncs funcs.h:
	if [ -f funcs.h ]; then mv funcs.h funcs.h.OLD; fi
	awk -f mkfuncs.awk $(SRC) >funcs.h

clean:
	rm -f $(OBJ) lesskey.s less lesskey vecho

clobber:
	rm -f *.s less lesskey vecho install_less install_key \
		install_help install_lman install_kman

shar:
	shar -v linstall less.h position.h funcs.h cmd.h \
		vecho.c lesskey.c less.nro lesskey.nro lesskey.man > less.shar.a
	shar -v $(SRC1) > less.shar.b
	shar -v $(SRC2) > less.shar.c
	shar -v $(SRC3) less.man README less.help *.awk >less.shar.d


##########################################################################
# Dependencies
##########################################################################

$(OBJ): less.h funcs.h defines.h position.h
command.s decode.s: cmd.h
lesskey.s: less.h funcs.h defines.h cmd.h

