# Makefile for hgrep

# CONFIGURE: the directory you want the executables installed into
BINDIR =	/usr/local/bin

# CONFIGURE: the directory tree you want the man pages installed into
MANDIR =	/usr/local/man/man1

# CONFIGURE: your favorite C compiler
#CC =		cc
CC =		gcc -ansi -pedantic -fpcc-struct-return

# CONFIGURE: your favorite C flags
CFLAGS =	-O
#CFLAGS =	-g -O

# CONFIGURE: your favorite loader flags
LDFLAGS =	-s
#LDFLAGS =	

# CONFIGURE: If you're a System V site, set this.
#DSYSV =	-DSYSV

DEFINES =	$(DSYSV)
LINTFLAGS =	-hxz

SRCS =		hgrep.c
OBJS =		hgrep.o
EXES =		hgrep
MANS =		hgrep

INCLUDES =	
ALLCFLAGS =	$(CFLAGS) $(DEFINES) $(INCLUDES)
ALLLINTFLAGS =	$(LINTFLAGS) $(DEFINES) $(INCLUDES)

all:		$(EXES)

hgrep:		$(OBJS)
	$(CC) $(ALLCFLAGS) $(OBJS) -ltermcap $(LDFLAGS) -o hgrep

hgrep.o:	hgrep.c
	$(CC) $(ALLCFLAGS) -c hgrep.c 

lint:
	for i in $(SRCS) ; do \
	    echo $$i ; \
	    lint $(ALLLINTFLAGS) $$i | sed -e '/but never used or defined/d' -e '/but not defined/d' -e '/but never used/d' -e '/constant in conditional context/d' ; \
	done

install:	install.bin install.man

install.bin:	all
	for i in $(EXES) ; do \
	    rm -f $(BINDIR)/$$i ; \
	    cp $$i $(BINDIR) ; \
	done
	for l in a e f n ; do \
	    rm -f $(BINDIR)/h$${l}grep ; \
	    ln -s $(BINDIR)/hgrep $(BINDIR)/h$${l}grep ; \
	done

install.man:
	for i in $(MANS) ; do \
	    rm -f $(MANDIR)/$$i.1 ; \
	    cp $$i.1 $(MANDIR) ; \
	done

clean:
	rm -f $(EXES) *.o a.out core
