## $Header: /noc/network/netlog/src/RCS/Makefile,v 2.3 1992/06/01 19:34:58 aggarwal Exp $

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
# DISCLAIMER for further information.
#

## YOU CAN ALSO SPECIFY THE 'TOPDIR' WHILE INVOKING MAKE LIKE:
##	make TOPDIR=/home/netlog

## 1.
##
# The installation structure assumes a TOPDIR, and the following subdirs
# that are created below: bin/, etc/, locks/, logs/
# You can just define TOPDIR, and the rest are defined automatically, else
# you can define each subdirectory location here.
#
TOPDIR =	/usr/netlog

##
##
# Owner and group of the programs. It is advised to create a unique
# userid (netlog) and a unique group (netlog).
#
# Only I_OWNER will be allowed to run the 'netlog-indexer' indexing program.
#
# All directories will be installed as writable by I_GROUP. Also, the program
# is installed with the 'gid' bit set (2751). The program checks to see if
# the person running the program belongs to one of 'OKGROUPS'- if so, then
# it runs as group 'I_GROUP'.
# Users will then be allowed to perform those functions as allowed
# by the standard Unix file permissions on the various directories.
#
# NETLOGOWNER is set to I_OWNER and NETLOGGROUP is set to I_GROUP in the
# compile time definitions.
I_OWNER =		netlog
I_GROUP =		netlog

##
##
# Location of the man pages and their extension (n or l). The admin man page
# will be installed under $(MANDIR)/man8/netlog.8. 
MANDIR =	/usr/man
MANEXT =	"n"

##
##
# Set the SYSDEFS to one or more of the following options:
#	-DNFS			To use "fcntl" instead of "flock"
#	-DDEBUG			To permit debugging from command line
SYSDEFS =	-DNFS -DDEBUG

##
##
# The library function putenv() does not exist on murky BSD 4.3 but
# does on SUN and Ultrix systems. If your library has it, then set
# ENVOBJS to null, else it will use the one supplied (the GNU version).
#ENVOBJS  =	putenv.o
ENVOBJS   = 

##
##
# The various compile options.
# 
CC  =		cc
LIBS =		-lcurses -ltermcap
CFLAGS =	-g

##
##
###### Rest can be left alone.
##

BINDIR =	$(TOPDIR)/bin
ETCDIR =	$(TOPDIR)/etc
LOCKDIR = 	$(TOPDIR)/locks
LOGDIR =	$(TOPDIR)/logs

# Define DIRDEFS to the directories that need to be defined in the program.
# The program cd's to the topdir when executing.
DIRDEFS =	-DTOPDIR=\"$(TOPDIR)\" \
		-DBINDIR=\"$(BINDIR)\" \
		-DETCDIR=\"$(ETCDIR)\" \
		-DLOCKDIR=\"$(LOCKDIR)\" \
		-DLOGDIR=\"$(LOGDIR)\"

## Compile time options
DEFS =		$(SYSDEFS) $(DIRDEFS) \
		 -DNETLOGOWNER=\"$(I_OWNER)\" \
		 -DNETLOGGROUP=\"$(I_GROUP)\"

DISTRIBUTIONS = Makefile BUGS DISCLAIMER INSTALL HISTORY README \
		*.c *.h *.y netlog.man netlog.8 \
		greprec \
		cookie-jar netlog-header nroff-header initials

OBJS = 		cookie.o create_entry.o edit_log.o \
		init.o indexing.o \
		list_open_tkts.o menu.o \
		netlog.o process_tickets.o \
		read_log.o search_logs.o utils.o
INDEXOBJS =	netlog_indexer.o indexing.o menu.o utils.o

INCLUDES =	netlog.h


all:	Makefile netlog netlog-indexer grep_record

Makefile:
	@echo "Rebuilding since Makefile was updated..."

netlog:		$(OBJS) $(ENVOBJS)
	$(CC)  $(CFLAGS) $(OBJS) $(ENVOBJS) $(LIBS) -o netlog

netlog-indexer netlog_indexer:	$(INDEXOBJS)
	$(CC) $(CFLAGS) $(INDEXOBJS) $(LIBS) -o netlog-indexer

grep_record:
	( cd greprec ; make all CFLAGS=$(CFLAGS) )

man:	netlog.1

netlog.1:  Makefile netlog.h netlog.man
	@( OKG=`awk '/^#define.*WRITE_GROUPS/ \
		{ for (i = 3 ; i <= NF ; ++i) printf $$i " " }' netlog.h` ;\
	 sed -e "s/WRITE_GROUPS/$${OKG}/g" \
		-e "s/I_OWNER/$(I_OWNER)/g" netlog.man >netlog.1 )
	
$(OBJS) $(INDEXOBJS) $(ENVOBJS):	$(INCLUDES) Makefile

.c.o:
	$(CC) -c $(CFLAGS) $(DEFS)  $<

##
# Test programs

test:	menu

menu:
	yacc menu.y
	$(CC) $(CFLAGS) -DTEST y.tab.c -o menu $(LIBS)
	/bin/rm -f y.tab.c

install:	netlog netlog-indexer man grep_record
	@echo "INSTALLING IN $(TOPDIR)"
	@[ `whoami` = $(I_OWNER) ] || \
	   { echo "PLEASE INSTALL AS $(I_OWNER) TO AVOID PROBLEMS"; exit 1 ; }
#	#####
#	Dont need to install these directories for group access
	@( if [ ! -d $(TOPDIR) ]; then  mkdir $(TOPDIR) ; else : ; fi ;\
	   if [ ! -d $(BINDIR) ]; then  mkdir $(BINDIR) ; else : ; fi)
#	#####
#	Install these dirs with g+s and group writable
	@for d in  $(LOCKDIR) $(ETCDIR) $(LOGDIR) ; \
	  do \
		( if [ ! -d $$d ]; then mkdir $$d ; fi ;\
		  chgrp -f $(I_GROUP) $$d ; \
		  chmod 0775 $$d ; chmod g=rwxs $$d); \
	 done
	@ (cd greprec ; make install BINDIR="$(BINDIR)" )
	@echo "Installing 'netlog' with group ID bit set (2xxx)"
	@for f in netlog netlog-indexer ; \
	  do \
	     ( install -c -o $(I_OWNER) -g $(I_GROUP) -m 2751 $$f $(BINDIR)/;\
	       chmod g=rxs $(BINDIR)/$$f && ls -lg $(BINDIR)/$$f) ;\
	  done
#	####
	@for f in netlog-header nroff-header initials cookie-jar ;\
	  do \
	     if [ ! -f $(ETCDIR)/$$f ]; then \
	       install -c -o $(I_OWNER) -g $(I_GROUP) -m 0444 $$f $(ETCDIR)/ ;\
	     else \
		chgrp $(I_GROUP) $(ETCDIR)/$$f ;\
	     fi ;\
	  done
	@/bin/rm -f null.file ; > null.file
	@for f in index open-tickets open-tickets-summary prev-tkt ;\
	  do \
	     if [ ! -f $(ETCDIR)/$$f ]; then \
		install -c -o $(I_OWNER) -g $(I_GROUP) -m 0664 null.file $(ETCDIR)/$$f ;\
	     else \
		chgrp $(I_GROUP) $(ETCDIR)/$$f ;\
	     fi ;\
	  done
	@if [ ! -s $(ETCDIR)/prev-tkt ]; then echo "0" > $(ETCDIR)/prev-tkt ;fi
	@echo "" ; echo "  netlog INSTALLED UNDER $(TOPDIR)." ; echo ""
#	####
	@echo "  Update the '$(ETCDIR)/initials' file with your site usernames"
	@echo "  Update 'prev-tkt', rebuild 'index'
	@echo "  Check group of old LOG files if I_GROUP is new"
#	####
	@echo "  Installing man pages..."
	-install -c -m 644 netlog.1 $(MANDIR)/man$(MANEXT)/netlog.$(MANEXT)
	-install -c -m 644 netlog.8 $(MANDIR)/man8/netlog.8
	
	
clean:
	/bin/rm -f core *.o menu netlog netlog-indexer grep_record netlog.1
	( cd greprec ; make clean CFLAGS=$(CFLAGS) )


tar: netlog.tar
	@ls -l netlog.tar

netlog.tar:	$(DISTRIBUTIONS)
	@(mkdir /var/tmp/t /var/tmp/t/netlog ;\
	 cp -r $(DISTRIBUTIONS) /var/tmp/t/netlog ;\
	 cd /var/tmp/t ; tar cf netlog.tar netlog)
	@mv -f /var/tmp/t/netlog.tar . ; rm -rf /var/tmp/t
	@tar tf netlog.tar
	@echo "CREATED TAR FILE IN netlog.tar"
	
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
