#
# makefile for runfactor, a C program to run the mpqs program
# and to stop and restart it as the load on the machine requires.
#
# Makefile written by:	Derek Atkins <warlord@MIT.EDU>
#

# This is the directory in which to copy the binary when you "make install"
# (Warning, make install will not create the binary as you would think
# it should, as there is no dependency, and I don't know how to easily
# make one!
INSTALLDIR=/afs/sipb.mit.edu/project/factoring/.bin/@sys

# The default sleep time is 60 seconds.  If you want to change
# the default time to sleep between checks, uncomment this line
# and set the value appropriately.
#DEF_SLEEP=-DDEFAULT_SLEEP=60

# If the mpqs executable is not in the current working directory, then
# you will have to uncomment and define the location of the mpqs binary:
MPQS=-DMPQS=\"/afs/sipb.mit.edu/project/factoring/bin/mpqs\"

# If the RESTART file is not in the current working directory, then you
# will need to fix that here:
RESTART=-DRESTART=\"/afs/sipb.mit.edu/project/factoring/rsa129/RESTART\"

# Where the TASTLIST is held, if not CWD.  Uncomment and fix if
# this is not correct for you.
TASKFILE=-DTASKLIST=\"/afs/sipb.mit.edu/project/factoring/rsa129/mit/TASKLIST\"

# This is the TEMPLATE file.  The default location is in the current
# working directory.  This this is not where your TEMPLATE file it,
# then uncomment and correct this.
TEMPLATE=-DTEMPLATE=\"/afs/sipb.mit.edu/project/factoring/rsa129/mit/TEMPLATE\"

# Directory where the PID information is stored.  The default is
# the directory "/usr/local/etc/mpqs".  If this is not correct, then
# fix it here.
PIDDIR=-DPIDDIR=\"/usr/tmp\"

# Directory where the log is stored.  The default is in the current
# workig directory.  If this is incorrect, fix it here.
LOGDIR=-DLOGDIR=\"/afs/sipb.mit.edu/project/factoring/rsa129/log\"

# If the program "uptime" is not in /usr/bin/uptime, then you 
# should uncomment this line and set it properly:
LOADST=-DLOADST=\"/usr/ucb/uptime\"

# This is the program "sed".  If it is not in /bin/sed, then uncomment
# and correct this location.
#SED=-DSEDPROG=\"/bin/sed\"

# If utmp is not /etc/utmp, then uncomment and change this line:
#UTMP=-DUTMP_FILE=\"/etc/utmp\"

#################################################################
# End Likely Site Specific Definitions
#################################################################

# Some definitions that need to be created
MAKE= make
RM= rm -f
CP= cp -p
DBG= -O

# Warning: There MUST be something on the last line here, otherwise
# this will not work properly.  Therefore, $DBG has been put in there,
# and it should ALWAYS have something defined in it!
CFLAGS= $(LOADST) $(DEF_SLEEP) $(PIDDIR) $(TASKFILE) $(LOGDIR) \
	$(SED) $(TEMPLATE) $(UTMP) $(MPQS) $(RESTART) $(DBG)

OBJS=	checkpid.o fileactivity.o getloadav.o getnum.o \
	pid-job.o runfactor.o startmpqs.o subsjobno.o \
	ttyactivity.o sendit.o file-name.o
SRCS=	checkpid.c fileactivity.c getloadav.c getnum.c \
	pid-job.c runfactor.c startmpqs.c subsjobno.c \
	ttyactivity.c sendit.c file-name.c

.c.o:
	$(RM) $*.o
	$(CC) -c $(CFLAGS) $(AFLAGS) $*.c

default:
	@echo "Type \"make <system>\", where <system> is one of:"
	@echo "	alpha, decmips, hp700, hp700gcc, rs6000, sun4gcc, sun4sol"

# This is the all-encompasing rule to make the program.  This should
# work for all platforms, and let you know how you made it.
all:	$(OBJS)
	$(CC) -o runfactor $(CFLAGS) $(AFLAGS) $(OBJS) $(LIBS)

hp700:	$(SRCS)
	$(MAKE) all AFLAGS="-Aa -D_HPUX_SOURCE -Dhp700"

hp700gcc:	$(SRCS)
	$(MAKE) all CC=gcc AFLAGS="-D_HPUX_SOURCE -Dhp700" LOADST=

decmips:	$(SRCS)
	$(MAKE) all CC=gcc

rs6000:	$(SRCS)
	$(MAKE) all 

sun4gcc:	$(SRCS)
	$(MAKE) all CC=gcc 

sun4sol:	$(SRCS)
	$(MAKE) all CC=gcc LIBS="-lucb -lsocket -lnsl -lelf"

alpha:	$(SRCS)
	$(MAKE) all UTMP=-DUTMP_FILE=\\\"/var/adm/utmp\\\"

clean:
	$(RM) *.o *~ *.bak core runfactor testgn testfa testta testgla testpj

install:
	$(CP) runfactor $(INSTALLDIR)	

#
# Below here are test programs, not really supported here, but left
# in, just in case someone wants to try to use them for some strange
# reason.
testpj: testpj.o pid-job.o
	$(CC) $(CFLAGS) -o testpj testpj.o pid-job.o

testgn:	testgn.o getnum.o
	$(CC) $(CFLAGS) -o testgn testgn.o getnum.o

getnum.o: getnum.h

testfa:	testfa.o fileactivity.o
	$(CC) $(CFLAGS) -o testfa testfa.o fileactivity.o

testta:	testta.o ttyactivity.o
	$(CC) $(CFLAGS) -o testta testta.o ttyactivity.o
	
testta2: testta2.o tty2.o
	$(CC) $(CFLAGS) -o testta2 testta2.o tty2.o

testgla:	testgla.o getloadav.o
	$(CC) $(CFLAGS) -o testgla testgla.o getloadav.o

