#############################################################################
# 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.
#
#		April 29, 1993, by Rhett "Jonzy" Jones.
#		Added POSIXSOURCE for use when compiling under A/UX, and
#		commented what variables should be used for various operating
#		systems to assist in the porting of jughead.
#
#		May 11, 1993, by Rhett "Jonzy" Jones.
#		make install now installs jughead and the manpage with 755
#		permissions.  make semiclean now removes anything ending in a
#		percent character, '%'.  This was done to support textedit on
#		a sun.
#
#		May 14, 1993, by Rhett "Jonzy" Jones.
#		Changed some of the comments to assist those porting to
#		ultrix4.2.
#
#		May 15, 1993, by Rhett "Jonzy" Jones.
#		Moved "$(NOWARNINGS)" from the macro CFLAGS to the target
#		jughead, and added "%.o:= CFLAGS += $(NOWARNINGS)" to support
#		the use of the lint target, which does not like -w.  This was
#		done so both the targets jughead and lint can utilize the CFLAGS
#		macro.  Added support for lint.  And attempted to give better
#		directions when porting the code.
#
#		May 20, 1993, by Rhett "Jonzy" Jones.
#		Included the source files getargs.c, and jughead.h.
#
#		May 22, 1993, by Rhett "Jonzy" Jones.
#		Added DEFAULTBOOLOP to the Makefile to allow one to alter
#		the default boolean operation if none is given seperating
#		words to search on.  Thank danj@welchgate.welch.jhu.edu
#		for this one.
#
#		May 22, 1993, by Rhett "Jonzy" Jones.
#		Changed DEFAULTBOOLOP to DEFBOOLOP.  So the compiler
#		wouldn't get a null string.  Oops.  Thank you
#		doyle@liberty.uc.wlu.edu for informing of this problem.
#
#		May 23, 1993, by Rhett "Jonzy" Jones.
#		Added JUGHEADHELPDOC to supports some special commands
#		when jughead is a search engine.  Also added searchCmnds.c
#		as a dependency.  Added THEHOST, which should be the
#		fully qualified name of the machine running jughead.
#
#		May 24, 1993, by Rhett "Jonzy" Jones.
#		Utermann@Uni-Augsburg.DE reported a problem with make
#		on a RS6000, so I tweeked the Makefile a bit, and added
#		the macro DFLAGS, which is the -D macros for use with
#		lint.
#
# 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
#			make lint
#
# 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.
#############################################################################

# jughead has been successfuly ported to A/UX, AIX, SunOS 4.1.2,
# ultrix, and ultrix4.2.

#----------------------------------------------------------------------------
# These are the defines you will need to edit if need be.  If you get any
# make errors or segmentation faults, I suggest you first make sure you
# verify the VARARGS macro, and the proper VSPRINTTYPE macro.  For more
# information on these macros see the comments immediatly above the macro.

# The version of this program.
THEVERSION	= 0.9

# This is the name of the machine jughead is running on.
THEHOST	= soar.cc.utah.edu

# This is the gopher information stating where the "About.jughead" document
# is located.  What this string consists of is a tab followed by the
# selector string or Path, with another tab, the host, tab, and finaly the port.
# If you don't want any of this information displayed use the definition that
# is commented out.
#JUGHEADHELPDOC	= "\t\terror.host\t-1"
JUGHEADHELPDOC	= "\t0/About the U of U Gopher/About jughead\tsns.utah.edu\t70\r\n"

# If you wish to alter the characters that delimit a word when doing a
# search, refer to the following line in "search.c".
# #define DELIMITERS	" \t\n\f\r !\"#$%&\'()+,-./:;<=>?@[\\]^_`{|}~"

# This is the default boolean operation to perform when searching, when
# there exists no boolean operator between words.  It can be one of
# "AND", "OR", "NOT", but I have no idea why you would select "NOT".
DEFBOOLOP	= "AND"

# 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.  The use of sort is not 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

# The manual suffix.
MANSUFF = 1

# This is where the executable goes.
# Note: in versions prior to 0.9 this was /usr/local/bin
DESTDIR 	= /usr/local/etc

# This is where the man page goes.
DESTMAN 	= /usr/local/man/man$(MANSUFF)

# What permissions do you want for jughead?
PERMISSIONS	= 750

# Uncomment the following if you do not have <stdarg.h>.
# You want this uncommented if you don't have an ANSI C compiler
# such as the compiler for the sun, or ultrix4.2. You can check
# this by doing "ls /usr/include/stdarg.h", if it is not found
# you will need to uncomment this macro.  Furthermore, you can
# determine if this is needed by doing a "man vsprintf" and
# determining which include is needed.
VARARGS	= -DUSE_VARARGS_H

# Uncomment the type which vsprintf() returns.  You can determine
# this by doing a "man vsprintf", if it says "int vsprintf(...)" 
# vsprintf returns an int, if is says "char *vsprintf(...)" it
# returns a str.
#VSPRINTTYPE	= -DVSPRINTF_RETURNS_INT	# AIX:RS6000, ultrix4.2:DEC.
VSPRINTTYPE	= -DVSPRINTF_RETURNS_STR	# SunOs:sun, ultrix:DEC.

# Comment the following if your complier does not support prototypes.
# You want this commented out if you don't have an ANSI C compiler
# such as the standard compiler for the sun, and a DEC.
#PROTOTYPES	= -DUSEPROTOTYPES

# The following should be uncommented if compiling under A/UX.
# Thank you hagberg@cumc.cornell.edu for this one.
#POSIXSOURCE	= -D_POSIX_SOURCE

# Uncomment the following if you don't want warning messages printed.
# This should be commented out if on a DEC.  But can be used with
# ultrix4.2.
NOWARNINGS	= -w

# Set any optimization or debugging flags you want here.
OPTIMIZATION	=

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

# The location of lint.
LINT	= /bin/lint

# Any lint flags you want to use go here.
LINTFLAGS =

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

# The #define flags to set.
DFLAGS	= -DVERSION=\"$(THEVERSION)\"		\
	  -DHOSTNAME=\"$(THEHOST)\"		\
	  -DJUGHEADHELP=\"$(JUGHEADHELPDOC)\"	\
	  -DDEFAULTBOOLOP=\"$(DEFBOOLOP)\"	\
	  -DCATCOMMAND=\"$(THECATCOMMAND)\"	\
	  -DRMCOMMAND=\"$(THERMCOMMAND)\"	\
	  -DSORTCOMMAND=\"$(THESORTCOMMAND)\"	\
	  -DTMPFILENAME=\"$(THETMPFILENAME)\"	\
	  -DPORT2USE=$(THEPORT2USE)		\
	  $(VARARGS)				\
	  $(VSPRINTTYPE)			\
	  $(PROTOTYPES)				\
	  $(POSIXSOURCE)

CFLAGS	= $(DFLAGS)				\
	  $(OPTIMIZATION)			\
	  $(NOWARNINGS)


# The sources for use with lint.
SRC	= dirTree.c getargs.c jughead.c searchCmnds.c search.c sockets.c tree.c utils.c

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

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

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

all: jughead

# This is the default target, which will make jughead.
jughead:$(OBJS)
	$(CC) $(CFLAGS) -o jughead $(OBJS)
#	echo "Are you sure $(THEVERSION) is the correct version of jughead?"

# The various objects and their dependencies.
dirTree.o:	dirTree.c dirTree.h utils.h
jughead.o:	jughead.c jughead.h dirTree.h tree.h
searchCmnds.o:	searchCmnds.c
search.o:	search.c tree.h utils.h
sockets.o:	sockets.c utils.h
tree.o:		tree.c tree.h
utils.o:	utils.c
getargs.o:	getargs.c jughead.h
jughead.h:	utils.h

# Make jughead if need be and install jughead and the man page.
# Note: you need to be root for this one.
install:jughead
	cp jughead $(DESTDIR)/jughead
	chown root $(DESTDIR)/jughead
	chmod $(PERMISSIONS) $(DESTDIR)/jughead
	cp jughead.1 $(DESTMAN)/jughead.$(MANSUFF)
	chown root $(DESTMAN)/jughead.$(MANSUFF)
	chmod 755 $(DESTMAN)/jughead.$(MANSUFF)

# Clean everything up including the installed jughead and man page.
# Note: you need to be root for this one too.
realclean:clean
	rm -f $(DESTDIR)/jughead
	rm -f $(DESTMAN)/jughead.$(MANSUFF)

# Clean everything up except for the installed jughead and man page.
clean:semiclean
	rm -f jughead

# Just remove the objects and any backup files created from an editor.
semiclean:
	rm -f *.o
	rm -f *~		# emacs backup files.
	rm -f *%		# Sun textedit backup files.
	rm -f lint.doc		# The lint document if its around.

# Tar the sources up into a tar'ed and compressed file.
# Note: This does not do anything with the jughead.ReadMe file.
tar:
	/bin/tar -cvf - $(TARFILES) | compress -c > $(TARNAME)

# Display the man page even though it hasn't been installed.
viewman:
	nroff -man jughead.1 | more

# Have lint report on the programmers ability to write C code.
lint:$(SRC)
	$(LINT) $(LINTFLAGS) $(DFLAGS) $(SRC) > lint.doc
	more lint.doc

