# Makefile for SGI IRIX 4.0+
#
# CAUTION:  Make changes to Makefile (not makefile), then run
# "make -f Makefile depend" before running "make all".
#
CC = cc
CCOPT = -xO4 -mt
LIBOPT = -xO4 -mt
#
#***********************************************************************
# SHARED MEMORY
# Shared memory is only an option on systems that have incorporated the UNIX
# System V interprocess communication facilities.  The SYSV_IPC_AVAIL macro
# must be defined in ncbilcl.h for a platform.  Management of database files
# resident in shared memory is accomplished via the 'memfile' program.
#
# Note:  Your UNIX kernel may need to be reconfigured to permit allocation of
# sufficiently large shared memory segments.  For example, the default SunOS
# 4.0 and 4.1 limit on shared memory segment size is 1 MB.  The limit should
# be configured to be at least as large as the largest single file that one
# will need to place in shared memory.
#***********************************************************************
# MEMORY MAPPED FILES
# On many UNIX platforms, memory mapped files are employed when a shared
# memory segment either does not exist for a file or if System V IPC was not
# a compiled-in feature (see above).
#***********************************************************************
# MULTIPROCESSING / MULTITHREADING
# Under SGI IRIX, multiprocessing can be employed by defining MPROC_AVAIL
# at the location indicated in the SGI-specific header, ncbilcl.sgi, which
# gets renamed to ncbilcl.h.  The gish library must be previously compiled
# with the definition in effect.
#
# Similarly for Solaris 2.2+, MPROC_AVAIL may be specified in ncbilcl.sol
# to use Solaris threads.
#
# Support for DCE threads (e.g., DEC OSF/1 threads) is written but untested.
#
# Each of the above platforms requires that applications be linked with
# specialized libraries when multiprocessing/multithreading is to be used.
#
# Operating System      MPLIB make variable
# ================      ======
# SGI IRIX 4.+          -lmpc
# Solaris               -lthread
# DEC OSF/1             -lpthreads
# 
#***********************************************************************
#
# When defined, the CLEAN8MERS compile-time option causes the BLASTN program
# to remove high-frequency (uninformative) 8-mers from the query sequence
# before generating the word list.  The cutoff frequency which defines
# "uninformativeness" threshold is specified at the time the database is
# processed with the pressdb program.
#
REFINED_STATS = -DREFINED_STATS
#CLEAN8MERS = -DCLEAN8MERS
OPTIONS = ${REFINED_STATS} ${CLEAN8MERS}
CFLAGS = ${CCOPT} $(INCDIRS) $(LIBDIRS) ${OPTIONS}
#MKDEPFLAG = -M
# Solaris is different
MKDEPFLAG = -xM

# These links contribute to a general method for inclusion
# of header files by the lib/*.c files.
NCBI = ../ncbi
GISH = ../gish
DFA = ../dfa
LINKS = ncbi gish dfa

# Set -I flag(s) to point to directories containing dfa.h, gish.h, and ncbi.h
INCDIRS = -Iinclude -Idfa -Igish/include -Incbi/include

# Set -L flag(s) to point to directories containing libdfa.a and libgish.a
LIBDIRS = -Llib -Ldfa -Lgish/lib

APPLIB = lib/libapp.a
#MPLIB = -lmpc
LIBS = -lapp -ldfa -lgish ${MPLIB} -lm

PGMS = blastp blastn tblastn blastx blast3 setdb pressdb memfile \
		pam gb2fasta gt2fasta pir2fasta sp2fasta
HDRS = blastapp.h alphabet.h aabet.h ntbet.h karlin.h gcode.h shmutil.h
SRCS = blastn.c blastp.c tblastn.c blastx.c blast3.c out3.c \
		setdb.c pressdb.c pam.c gb2fasta.c gt2fasta.c pir2fasta.c sp2fasta.c
INCSRC = searcha.inc searchn.inc searchx.inc
OBJS = blastn.o blastp.o tblastn.o blastx.o blast3.o out3.o \
		setdb.o pressdb.o pam.o gb2fasta.o gt2fasta.o pir2fasta.o sp2fasta.o

all:	$(LINKS) always $(PGMS)

ncbi:
	ln -s $(NCBI) $@
gish:
	ln -s $(GISH) $@
dfa:
	ln -s $(DFA) $@

blastp: blastp.c $(APPLIB)
	$(CC) $(CFLAGS) -DBLASTP -o $@ $@.c $(LIBS)

blastn: blastn.c $(APPLIB)
	$(CC) $(CFLAGS) -DBLASTN -o $@ $@.c $(LIBS)

tblastn: tblastn.c $(APPLIB)
	$(CC) $(CFLAGS) -DTBLASTN -o $@ $@.c $(LIBS)

blastx: blastx.c $(APPLIB)
	$(CC) $(CFLAGS) -DBLASTX -o $@ $@.c $(LIBS)

blast3: blast3.c out3.c $(APPLIB)
	$(CC) $(CFLAGS) -DBLAST3 -o $@ $@.c out3.c $(LIBS)

# memfile is only useful on systems that support System V UNIX shared memory
memfile: memfile.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ $@.c $(LIBS)

# database preprocessor for blastp, blastx, and blast3
setdb:	setdb.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ $@.c -lapp -lgish ${MPLIB} -lm

# database preprocessor for blastn
pressdb: pressdb.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ $@.c -lapp -lgish ${MPLIB} -lm

# PAM matrix generator
pam: pam.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ pam.c -lapp -lgish ${MPLIB} -lm

# Convert GenBank(R) format to FASTA format (faster than the AWK script)
gb2fasta: gb2fasta.c
	$(CC) $(CFLAGS) -o $@ $@.c -lgish

# Convert GenBank(R) CDS features into FASTA format
gt2fasta: gt2fasta.c
	$(CC) $(CFLAGS) -o $@ $@.c -lgish

# Convert NBRF PIR format to FASTA format (faster than the AWK script)
pir2fasta: pir2fasta.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ $@.c -lapp -lgish ${MPLIB}

# Convert SWISS-PROT format to FASTA format
sp2fasta: sp2fasta.c $(APPLIB)
	$(CC) $(CFLAGS) -o $@ $@.c -lapp -lgish ${MPLIB}

manual: blast.1ps blast3.1ps

# Create PostScript version of the manual page
blast.1ps: blast.1
	psroff -man -t blast.1 > blast.1ps

# Create PostScript version of the manual page
blast3.1ps: blast3.1
	psroff -man -t blast3.1 > blast3.1ps

$(APPLIB): always
always: $(LINKS)
	cd lib; $(MAKE) $(MFLAGS) CC="$(CC)" CCOPT="${LIBOPT}" OPTIONS="${OPTIONS}"

clean:
	@ cd lib; make clean
	@- rm -f $(LINKS)
	@- rm -f makefile makefile.old
	@- rm -f $(PGMS)
	@- rm -f $(OBJS)
	@- rm -f *.u

depend: lib/Makefile Makefile include $(LINKS) $(SRCS) $(INCSRC)
	cd lib; $(MAKE) $(MFLAGS) -f Makefile depend CC="$(CC)" CCOPT="${LIBOPT}" OPTIONS="${OPTIONS}" MKDEPFLAG="${MKDEPFLAG}"
	- mv -f makefile makefile.old
	@ sed -n -e '1,/[D]O NOT MAKE ANY CHANGES/p' Makefile > makefile
	@ echo "" >> makefile
	@ $(CC) $(INCDIRS) ${OPTIONS} ${MKDEPFLAG} $(SRCS) >> makefile

#DO NOT MAKE ANY CHANGES ON OR BELOW THIS LINE
