#
# Makefile for MPQS.  This file contains the Make Rules for a number
# of different platforms.  If you have problems with something, please
# let me know.
#
# Compiled by:	Derek Atkins <warlord@MIT.EDU>
#

# MAILCMD contains the email address of the central site which will be
# collecting relations. 
MAILCMD= -DMAILCMD='"mail factor@hot-spare.mit.edu < %s"'

# 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

# Don't fiddle with MFLAGS unless you know what you're doing.
# The easiest to change are MAILBATCH and REPORT, which govern how many
# relations are batched up before mailing, and how often a status report
# is issued.  The values below are reasonable on typical workstations.
# You may reduce MAXSIEVE (to a minimum of 100000) to reduce memory 
# requirements somewhat, but the siever will run more slowly
#
# To reduce memory requirements even more, set -DNO_SQRTKN=1 in MFLAGS.
# If you do, you will save 2Mb RAM, but at a cost.  The RESTART file
# *must* be present, and it will be read frequently, possibly increasing
# disk IO or network traffic.  mpqs will also run more slowly -- perhaps
# 50% slower.  If you use NO_SQRTKN, you should have MAXSIEVE=300000
# or more -- as big as will fit.  Each 100,000 you add to MAXSIEVE
# increases memory usage by 100k
#
# Some architectures have problems with the getrusage() function (HP-UX
# has been reported as one).  This function is used only to put timing
# data into the output log file and is not vital for mpqs to run.  Add
# the flag -DNO_TIMING to MFLAGS if you don't want, or can't get timing data.

REPORT=10
MAXPOL=100000
MAILBATCH=25
MAXSIEVE=3000000
SIEVEL=10
RISC=-URISC

MFLAGS= -DREPORT=$(REPORT) -DMAXPOL=$(MAXPOL) $(RISC) -DUSEHEX=1 \
	-DMAILBATCH=$(MAILBATCH) -DMAXSIEVE=$(MAXSIEVE) -DSIEVEL=$(SIEVEL)
CFLAGS= -O
MAKE= make
RM= rm -f
CP= cp -p
PROG= mpqs

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

.s.o:
	$(RM) $*.o 
	$(AS) $(ASMFLAGS) -o $*.o $*.s

default:
	@echo "Type make <system>, where <system> is one of:"
	@echo "	DS_mpqs, S4_mpqs, S4a_mpqs, S4S_mpqs, VS_mpqs,"
	@echo "	alpha_mpqs, HP_mpqs, HP_gcc_mpqs, rs6000_mpqs,"
	@echo "	SGI1_mpqs, SGI2_mpqs, linux_mpqs, or Gen_mpqs"

# 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 $(PROG) $(CFLAGS) $(MFLAGS) $(MAILCMD) $(OBJS) -lm $(LIBS)
	touch $(FILE)

# DECstations (R3000) running Ultrix.
#  Do *not* use gcc, it generates markedly worse code.
#
DS_mpqs: mpqs.c lip.c
	$(MAKE) all CFLAGS=-O4 OBJS="mpqs.c lip.c" FILE=made_DS_mpqs

# Sun-4 (Sparc)
# Use gcc if you have it, it's better than Sun's cc
S4_mpqs: mpqs.c lip.c
	$(MAKE) all CC=gcc CFLAGS=-O OBJS="mpqs.o lip.o" FILE=made_S4_mpqs

# Sun-4 with assembler speed-up.  MAXSIEVE=850000 tested on SS10 w/ 1MB
# cache.  This may not be right for you!
S4a_mpqs: sparc-sunos.s mpqs.c lip.c
	$(MAKE) all CC=gcc CFLAGS="-O -DCONTRIBUTION_8" ASMFLAGS="-P -DFPU" \
	OBJS="mpqs.o lip.o sparc-sunos.o" MAXSIEVE=850000 FILE=made_S4a_mpqs

# Sun-4 with assembler, small memory
S4a_mpqs_small: sparc-sunos.s mpqs.c lip.c
	$(MAKE) all CC=gcc CFLAGS="-O -DNO_SQRTKN -DCONTRIBUTION_8" \
	ASMFLAGS="-P -DFPU" OBJS="mpqs.o lip.o sparc-sunos.o" \
	FILE=made_S4a_mpqs_small PROG=mpqs_small MAXSIEVE=300000

# A Sun-4 running SOLARIS, with assembler speed-up
S4S_mpqs: sparc-solaris.s mpqs.c lip.c
	$(MAKE) all CC=gcc CFLAGS="-O -DCONTRIBUTION_8" ASMFLAGS="-P -DFPU" \
	OBJS="mpqs.o lip.o sparc-solaris.o" LIBS=/usr/ucblib/libucb.a \
	FILE=made_S4S_mpqs

# A Vax running BSD.
VS_mpqs: mpqs.c lip.c
	$(MAKE) all CC=gcc CFLAGS=-O6 MAXSIEVE=100000 OBJS="mpqs.o lip.o" \
	FILE=made_VS_mpqs

# An Alpha running OSF/1
alpha_mpqs: mpqs.c lip.c
	$(MAKE) all CFLAGS=-O2 OBJS="mpqs.c lip.c" \
	FILE=made_alpha_mpqs MAXSIEVE=850000

# An RS/6000 running AIX (3.2)
rs6000_mpqs: mpqs.c lip.c
	$(MAKE) all CFLAGS="-O -qmaxmem=10000" OBJS="mpqs.o lip.o" \
	FILE=made_rs6000_mpqs

# HP/UX (You cannot use standard native compiler. You need the spiffy,
# 	expensive one, or use gcc ;-)
HP_mpqs: mpqs.c lip.c
	$(MAKE) all OBJS="mpqs.c lip.c" \
	CFLAGS="-O -Aa -D_HPUX_SOURCE -DNO_TIMING" \
	FILE=made_HP_mpqs

# HP/UX with native, stupid compiler
HP_gcc_mpqs: mpqs.c lip.c
	$(MAKE) all CC=gcc OBJS="mpqs.o lip.o" \
	CFLAGS="-O -D_HPUX_SOURCE -DNO_TIMING" FILE=made_HP_gcc_mpqs

# SGI.  This will compile a more generic (r2000/3000 cmd set) mpqs
SGI1_mpqs: mpqs.c lip.c
	$(MAKE) all CFLAGS="-mips1 -O3 -G16" OBJS="mpqs.c lip.c" \
	FILE=made_SGI1_mpqs

# SGI.  This will compile for the r4000 only
SGI2_mpqs: mpqs.c lip.c
	$(MAKE) all CFLAGS="-mips2 -sopt -O3 -non_shared -G16 -kpicopt" \
	OBJS="mpqs.c lip.c" FILE=made_SGI1_mpqs

# Linux
linux_mpqs: mpqs.c lip.c
	$(MAKE) all OBJS="mpqs.o lip.o" CFLAGS="-O6" \
	FILE=made_linux_mpqs
	@echo "Rebuilding binary with shared libc"
	$(RM) $(PROG)
	$(CC) -o $(PROG) mpqs.o lip.o -lm

# Generic Unix.  Use gcc if you wish.

Gen_mpqs: mpqs.c lip.c
	$(CC) -O $(MFLAGS) $(MAILCMD) -o mpqs mpqs.c lip.c -lm
	touch Gen_mpqs
#
# Set various compiler flags for testing new versions.
#
TFLAGS = -DREPORT=1 -DMAXPOL=10 -DUSEHEX=1 -DSIEVEL=10 \
	-DMAXSIEVE=3000000 

# tester depends on Makefile so we can change TFLAGS alone.

tester: mpqs.c lip.c Makefile
	$(CC) -O2 -URISC $(TFLAGS) $(MAILCMD) -o tester mpqs.c lip.c -lm

#
# This is a crock, but I really don't care.
install:
	$(CP) $(PROG) $(INSTALLDIR)

clean:
	$(RM) $(PROG) *.o *~ *.bak made_*_mpqs
