#############################################################################
# File:		Makefile
#
# Author:	Rhett "Jonzy" Jones
#		jonzy@cc.utah.edu
#
# Date:		February 17, 1993
#
# Modified:	March 27, 1993, by Rhett "Jonzy" Jones.
#		Consolidated various #defines from the source files into
#		this Makefile to ease the portability of jughead.
#
#		March 28, 1993, by Rhett "Jonzy" Jones.
#		Now use THEVERSION as part of the compressed tar files
#		name.  Example: if THEVERSION = 0.3_beta the resultant
#		tar file will have the name jughead.0.3_beta.tar.Z
#
#		March 30, 1993, by Rhett "Jonzy" Jones.
#		Added the ability for the user to specify the inclusion
#		of <varargs.h> if VARARGS is uncommented, otherwise <stdarg.h>
#		will be used.  Some compilers have vsprintf() return an int,
#		and others a char*, so depending on which VSPRINTTYPE is
#		is uncommented will determine which type is returned by this
#		routine.  Also allowed the ability to use prototypes by
#		uncommenting PROTOTYPES, the use of NOWARNINGS and the
#		OPTIMIZATION flags.
#
# Description:	Contains various make directives and source defines.  The
#		particular make directives supported here are:
#			make all
#			make install
#			make realclean
#			make clean
#			make semiclean
#			make tar
#			make viewman
#
# Copyright:	Copyright 1993, University of Utah Computer Center.
#		This source may be freely distributed as long as this copyright
# 		notice remains intact, and is in no way used for any monetary
# 		gain, by any institution, business, person, or persons.
#############################################################################

#----------------------------------------------------------------------------
# These are the defines you will need to edit if need be.

# The version of this program.
THEVERSION	= 0.5_beta

# The cat system command to use.
THECATCOMMAND	= "cat %s >> %s"

# The delete, remove, or unlink system command to use.
THERMCOMMAND	= "rm -f %s"

# This is the system dependent call to "sort".  It needs to be a call to sort
# such that we only sort on text after the first tab character.  In this sort
# command the first "%s" is the name of the resultant sorted file, and the
# second "%s" is the name of the file to have sorted.  The "-T /tmp" says
# to use /tmp as the place for any temporary files.  You may want to have
# the temporary files written to /tmp.  The use of sort isnot to sort the data
# but to remove any duplicates that may have been written to the file.
THESORTCOMMAND	= "sort -d -f -u -o %s -t'	' -T /tmp +1.0 %s"

# The temporary files name.
THETMPFILENAME	= /tmp/jughead.tmp

# The port to fire the search engine under.
THEPORT2USE	= 3000

# This is where the executable goes.
DESTDIR 	= /usr/local/bin

# This is where the man page goes.
DESTMAN 	= /usr/man/man

# Uncomment the following if you do not have <stdarg.h>.
#VARARGS	= -DUSE_VARARGS_H

# Uncomment the type which vsprintf() returns.
VSPRINTTYPE	= -DVSPRINTF_RETURNS_INT
#VSPRINTTYPE	= -DVSPRINTF_RETURNS_STR

# Comment the following if your complier does not support prototypes.
PROTOTYPES	= -DUSEPROTOTYPES

# Uncomment the following if you don't want warning messages printed.
NOWARNINGS	= -w

# Set any optimizatoin flags you here.
OPTIMIZATION	=

# End of the defines you need to edit.
#----------------------------------------------------------------------------

# The C compiler to use.
CC	= /bin/cc

# The #define flags to set.
CFLAGS	= -DVERSION=\"$(THEVERSION)\"		\
	  -DCATCOMMAND=\"$(THECATCOMMAND)\"	\
	  -DRMCOMMAND=\"$(THERMCOMMAND)\"	\
	  -DSORTCOMMAND=\"$(THESORTCOMMAND)\"	\
	  -DTMPFILENAME=\"$(THETMPFILENAME)\"	\
	  -DPORT2USE=$(THEPORT2USE)		\
	  $(VARARGS)				\
	  $(VSPRINTTYPE)			\
	  $(PROTOTYPES)				\
	  $(NOWARNINGS)				\
	  $(OPTIMIZATION)

# The objects requred to create jughead.
OBJS	= dirTree.o jughead.o search.o sockets.o tree.o utils.o

# The manual suffix.
MANSUFF = 1

# List of files to have tar'ed and compressed.
TARFILES= dirTree.c jughead.c search.c sockets.c tree.c utils.c	\
	  dirTree.h tree.h utils.h				\
	  Makefile jughead.1

# The name of the tar'ed and compressed file.
TARNAME	= jughead.$(THEVERSION).tar.Z

all: jughead

jughead:$(OBJS)
	$(CC) $(CFLAGS) -o jughead $(OBJS)
	echo "Are you sure $(THEVERSION) is the correct version of jughead?"

dirTree.o:	dirTree.c dirTree.h utils.h
jughead.o:	jughead.c dirTree.h tree.h utils.h
search.o:	search.c tree.h utils.h
sockets.o:	sockets.c utils.h
tree.o:		tree.c tree.h
utils.o:	utils.c

install:jughead
	cp jughead $(DESTDIR)/jughead
	chown root $(DESTDIR)/jughead
	chmod 4755 $(DESTDIR)/jughead
	cp jughead.1 $(DESTMAN)$(MANSUFF)/jughead.$(MANSUFF)
	chown root $(DESTMAN)$(MANSUFF)/jughead.$(MANSUFF)
	chmod 4755 $(DESTMAN)$(MANSUFF)/jughead.$(MANSUFF)

realclean:clean
	rm -f $(DESTDIR)/jughead
	rm -f $(DESTMAN)$(MANSUFF)/jughead.$(MANSUFF)

clean:semiclean
	rm -f jughead

semiclean:
	rm -f *.o
	rm -f *~

tar:
	/bin/tar -cvf - $(TARFILES) | compress -c > $(TARNAME)

viewman:
	nroff -man jughead.1 | more
