# Makefile for staden X programs (Silicon Graphics version)
# ---------------------------------------------------------

SHELL=/bin/sh

# This makefile generates the following staden programs which
# run under xterm (normal, `N') and those which run directly under X.
NPROGS=      mep  nip   pip   bap  sap  sip   splitp1 splitp2 splitp3 sethelp convert_project
LPROGS=           nipl  pip             sipl
XPROGS=     xmep xnip  xpip  xbap xsap xsip
PROGS= $(NPROGS) $(LPROGS) $(XPROGS)








#
# ``Interesting'' suffices that make needs to know about
#
.SUFFIXES: .a $(SUFFIXES)


#
# Directories
#
SRC=.
STADENSRC=$(SRC)/../staden
STADENBIN=$(STADENSRC)
TEDSRC=$(SRC)/../ted
TEDBIN=$(STADENBIN)
OSPSRC=$(SRC)/osp-bits
OSPBIN=$(OSPSRC)
MISCSRC=$(SRC)/../Misc
MISCBIN=$(MISCSRC)
# Use the ted sources compiled for staden executables
INCLUDES= -I$(SRC) -I$(STADENSRC) -I$(TEDSRC) -I$(OSPSRC) -I$(MISCSRC)


#
# Compilers and flags
#
CC= cc
CFLAGS= -g -ansi -prototypes $(INCLUDES)
F77= f77
FFLAGS= -g -c -old_rl

FLIBS= -lF77 -lU77 -lm -lI77 -lisam
XLIBS= -lXaw -lXt -lXmu -lXext -lX11
LFLAGS= $(FLIBS)
XLFLAGS= $(XLIBS) $(FLIBS)
LDFLAGS= -g

LD = cc
LDFLAGS = -g 

#
# Avoid compilation of objects in remote directories
#
$(STADENBIN)/%.o : $(STADENSRC)/%.f
$(STADENBIN)/%.o : $(STADENSRC)/%.c
$(TEDBIN)/%.o : $(TEDSRC)/%.f
$(TEDBIN)/%.o : $(TEDSRC)/%.c

#
# Sequence library handling routines
#
SEQLIB=\
	$(STADENBIN)/seqlibsubs.o



#
# The C objects, needed by every X program
#
CCORE=\
	$(STADENBIN)/postscript.o\
	$(STADENBIN)/Graph.o\
	$(STADENBIN)/plotLog.o\
	$(STADENBIN)/help.o\
	$(STADENBIN)/dialogues.o\
	$(STADENBIN)/userfacecom.o\
	$(STADENBIN)/xmenu.o\
	$(STADENBIN)/locks.o\
	$(STADENBIN)/mcspec.o\
	$(STADENBIN)/helpnmenu.o\
	$(STADENBIN)/FtoC.o

COBJS=\
	$(STADENBIN)/main.o\
	$(CCORE)

COBJS2=\
	xbapmain.o\
	$(CCORE)


#
# Common objects, needed by every program
#
COMMONOBJSB=\
	$(STADENBIN)/fmain.o\
	$(STADENBIN)/seeme-sg.o\
	$(STADENBIN)/nxspec.o\
	$(STADENBIN)/userface.o\
	$(STADENBIN)/userfacecom.o\
	$(STADENBIN)/nxhelpmenu.o\
	$(STADENBIN)/helpnmenu.o\
	$(STADENBIN)/FtoC.o\
	$(STADENBIN)/subs89.a

COMMONOBJS=\
	$(COMMONOBJSB)\
	$(STADENBIN)/postscript.o

SCOMMONOBJS=\
	$(COMMONOBJSB)

XCOMMONOBJS=\
	$(STADENBIN)/seeme-sg.o\
	$(STADENBIN)/xspec.o\
	$(STADENBIN)/subs89.a\
	$(COBJS)

XCOMMONOBJS2=\
	$(STADENBIN)/seeme-sg.o\
	$(STADENBIN)/xspec.o\
	$(STADENBIN)/subs89.a\
	$(COBJS2)


#
# Building the programs
# This should be just a linking phase because all of the object
# files and library files are generated using implicit rules.
# We use the fortran compiler to do linking.
#
GIP=\
	$(STADENBIN)/gip.o

GIPOBJS=\
	$(GIP)\
	$(SCOMMONOBJS)

gip: $(GIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(GIPOBJS) $(LFLAGS)




MEP=\
	$(STADENBIN)/mep.o\
	$(STADENBIN)/mepsub.o\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a

MEPOBJS=\
	$(MEP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

XMEPOBJS=\
	$(MEP)\
	$(STADENBIN)/xmepSpec.o\
	$(XCOMMONOBJS)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o 

mep: $(MEPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(MEPOBJS)  $(LFLAGS)

xmep: $(XMEPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XMEPOBJS) $(XLFLAGS)




NIP=\
	$(STADENBIN)/nip.o\
	$(STADENBIN)/patternn.a\
	$(STADENBIN)/patternnc.a\
	$(STADENBIN)/anals89.a\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a $(SEQLIB)

NIPOBJS=\
	$(NIP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

XNIPOBJS=\
	$(NIP)\
	$(STADENBIN)/xnipSpec.o\
	$(XCOMMONOBJS)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o 

nip: $(NIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(NIPOBJS) $(LFLAGS)

xnip: $(XNIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XNIPOBJS) $(XLFLAGS)




NIPL=\
	$(STADENBIN)/nipl.o\
	$(STADENBIN)/patternnc.a\
	$(STADENBIN)/anals89.a\
	$(STADENBIN)/asubs89.a\
	$(SEQLIB)

NIPLOBJS=\
	$(NIPL)\
	$(SCOMMONOBJS)

nipl: $(NIPLOBJS)
	$(LD) $(LDFLAGS) -o $@ $(NIPLOBJS) $(LFLAGS)




PIP=\
	$(STADENBIN)/pip.o\
	$(STADENBIN)/analps89.a\
	$(STADENBIN)/patternp.a\
	$(STADENBIN)/patternpc.a\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a\
	$(SEQLIB)

PIPOBJS=\
	$(PIP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

XPIPOBJS=\
	$(PIP)\
	$(STADENBIN)/xpipSpec.o\
	$(XCOMMONOBJS)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o 

pip: $(PIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(PIPOBJS)  $(LFLAGS)

xpip:$(XPIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XPIPOBJS) $(XLFLAGS)




PIPL=\
	$(STADENBIN)/pipl.o\
	$(STADENBIN)/patternpc.a\
	$(STADENBIN)/analps89.a\
	$(STADENBIN)/asubs89.a\
	$(SEQLIB)

PIPLOBJS=\
	$(PIPL)\
	$(SCOMMONOBJS)

pipl: $(PIPLOBJS)
	$(LD) $(LDFLAGS) -o $@ $(PIPLOBJS)  $(LFLAGS)



#
# Trace manager objects
#
STDTEDFILES=\
	$(TEDBIN)/seq.o\
	$(TEDBIN)/seqIOABI.o\
	$(TEDBIN)/seqIOALF.o\
	$(TEDBIN)/seqIOSCF.o\
	$(TEDBIN)/seqIOPlain.o\
	$(TEDBIN)/opp.o\
	$(TEDBIN)/fpoint.o\
	$(TEDBIN)/mach-io.o

TMANOBJS=\
	$(STADENBIN)/tman_main.o\
	$(STADENBIN)/tman_display.o\
	$(STADENBIN)/tman_traceDisplay.o\
	$(STADENBIN)/tman_basesDisplay.o\
	$(STADENBIN)/tman_context.o\
	$(STADENBIN)/tman_gadgets.o\
	$(STDTEDFILES)

OSPOBJS=\
	$(OSPBIN)/analysis.o\
	$(OSPBIN)/our_allo.o\
	$(OSPBIN)/paramIOX.o\
	$(OSPBIN)/paramIO.o\
	$(OSPBIN)/get_scores.o\
	$(OSPBIN)/utils.o\
	mess.o\
	$(GNULIB)

XHACK=\
	$(STADENBIN)/SmeLine.o

EDITOR=\
	$(XHACK)\
	$(STADENBIN)/xsapConEdit.o\
	contigEditor.o\
	edUtils.o\
	$(STADENBIN)/undo.o\
	$(STADENBIN)/Sheet.o\
	$(STADENBIN)/select.o\
	$(STADENBIN)/extend.o\
	$(STADENBIN)/searchUtils.o\
	edMenu.o\
	oligo.o\
	oligocom.o\
	subclone.o\
	myparams.o\
	$(STADENBIN)/trans.o\
	$(MISCBIN)/misc.a

TAGEDITOR=\
	$(STADENBIN)/tagEditor.o\
	$(STADENBIN)/tagdbparse.o\
	tagU2.o\
	$(STADENBIN)/tagU1.o

BAP=\
	bap.o\
	dbsysnew.o\
	dbsyscommon.o\
	actf.o\
	dstrand.o\
	oligo_sel.o\
	llin.o\
	guk.o\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a

BAPOBJS=\
	$(BAP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o\
	$(STADENBIN)/conEdit.o\
	tagU2.o\
	$(OSPBIN)/analysis.o\
	$(OSPBIN)/our_allo.o\
	$(OSPBIN)/get_scores.o\
	$(OSPBIN)/utils.o\
	mess.o\
	baponly.o\
	oligocom.o

XBAPOBJS=\
	$(BAP)\
	$(XCOMMONOBJS2)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o\
	$(EDITOR)\
	$(TMANOBJS)\
	$(TAGEDITOR)\
	$(OSPOBJS)

bap:	$(BAPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(BAPOBJS) $(LFLAGS)

xbap:	$(XBAPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XBAPOBJS) $(XLFLAGS)

convert_project: $(STADENBIN)/cvt.o
	$(CC) $(CFLAGS) -o $@ $(STADENBIN)/cvt.o

SAP=\
	sap.o\
	dbsyscommon.o\
	dbsysold.o\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a

SAPOBJS=\
	$(SAP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

XSAPOBJS=\
	$(SAP)\
	$(STADENBIN)/xsapSpec.o\
	$(XCOMMONOBJS)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o 

sap: $(SAPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(SAPOBJS) $(LFLAGS)

xsap: $(XSAPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XSAPOBJS) $(XLFLAGS)




SAPF=\
	$(STADENBIN)/sapf.o\
	$(STADENBIN)/dbsyscommon.o\
	$(STADENBIN)/dbsysold.o\
	$(STADENBIN)/asubs89.a\
	$(STADENBIN)/plot92.a

SAPFOBJS=\
	$(SAPF)\
	$(STADENBIN)/sapmen.o\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

sapf: $(SAPFOBJS)
	$(LD) $(LDFLAGS) -o $@ $(SAPFOBJS) $(LFLAGS)






SIP=\
	$(STADENBIN)/sip.o\
	$(STADENBIN)/dias89.a\
	$(STADENBIN)/plot92.a\
	$(SEQLIB)

SIPOBJS=\
	$(SIP)\
	$(COMMONOBJS)\
	$(STADENBIN)/pl4010.o

XSIPOBJS=\
	$(SIP)\
	$(STADENBIN)/xsipSpec.o\
	$(XCOMMONOBJS)\
	$(STADENBIN)/plX.o\
	$(STADENBIN)/textOutput.o 

sip: $(SIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(SIPOBJS) $(LFLAGS)

xsip: $(XSIPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(XSIPOBJS) $(XLFLAGS)




SIPL=\
	$(STADENBIN)/sipl.o\
	$(STADENBIN)/dias89.a\
	$(SEQLIB)

SIPLOBJS=\
	$(SIPL)\
	$(SCOMMONOBJS)

sipl: $(SIPLOBJS)
	$(LD) $(LDFLAGS) -o $@ $(SIPLOBJS) $(LFLAGS)




SETHELP=\
	$(STADENBIN)/sethelp.o

SETHELPOBJS=\
	$(SETHELP)\
	$(SCOMMONOBJS)

sethelp: $(SETHELPOBJS)
	$(LD) $(LDFLAGS) -o $@ $(SETHELPOBJS) $(LFLAGS)




SPLITP1=\
	$(STADENBIN)/splitp1.o
SPLITP1OBJS=\
	$(SPLITP1)\
	$(SCOMMONOBJS)

splitp1: $(SPLITP1OBJS)
	$(LD) $(LDFLAGS) -o $@ $(SPLITP1OBJS) $(LFLAGS)




SPLITP2=\
	$(STADENBIN)/splitp2.o
SPLITP2OBJS=\
	$(SPLITP2)\
	$(SCOMMONOBJS)

splitp2: $(SPLITP2OBJS)
	$(LD) $(LDFLAGS) -o $@ $(SPLITP2OBJS) $(LFLAGS)





SPLITP3=\
	$(STADENBIN)/splitp3.o
SPLITP3OBJS=\
	$(SPLITP3)\
	$(SCOMMONOBJS)

splitp3: $(SPLITP3OBJS)
	$(LD) $(LDFLAGS) -o $@ $(SPLITP3OBJS) $(LFLAGS)





#
# Files requiring simple FORTRAN compilation (thing.f -> thing.o)
# 
%.o: $(SRC)/%.f
	$(F77) $(FFLAGS) -c $<


#
# Files requiring simple C compilation (thing.c -> thing.o)
# 
%.o: %.c
	$(CC) $(CFLAGS) -c $<
%.o: $(SRC)/%.c
	$(CC) $(CFLAGS) -c $<




#
# The UNIX library (archive) mechanism is fairly weak so the following
# procedure is used to generate libraries.
#   * split the source file up into files which each contain
#     a single function or subroutine
#   * compile each of those files
#   * insert the object files individually into the library
# Each library is built by using a temporary directory.
# The fortran compilations must be done sequentially in order to
# avoid filling up the (small on this machine) /tmp directory
# with compiler debugging information.
#
%.a: $(SRC)/%.f
	BINDIR=`pwd`; \
	cd $(SRC); \
	SRCDIR=`pwd`; \
	TMPDIR=/tmp/staden$$$$; \
	if test ! -d $$TMPDIR; \
	then mkdir $$TMPDIR; \
	fi; \
	cd $$TMPDIR; \
	rm -f *.f *.o; \
	fsplit $$SRCDIR/`expr $< : '.*/\(.*\)' \| $<`; \
	$(F77) $(FFLAGS) -c *.f; \
	rm *.f; \
	rm -f $$BINDIR/$@; \
	ar rcv $$BINDIR/$@ *.o; \
	ranlib $$BINDIR/$@; \
	rm *.o; \
	cd $$BINDIR; \
	rm -r $$TMPDIR






all: $(NPROGS) $(XPROGS) $(LPROGS)

nprogs: $(NPROGS)

xprogs: $(XPROGS)

lprogs: $(LPROGS)

clean:
	rm -f $(PROGS) *.o *.a *~
