#$Id: truemake,v 1.440 2004/04/09 22:01:55 mieg Exp $
#################################################################
############### acedb: R.Durbin and J.Thierry-Mieg ##############
#################################################################
#
# ATTENTION:
#   If you are recompiling the distribution code on your own
#  machine, you should NOT edit the present file. All the machine
#  specific options should be given in your personal *_DEF file
#  in the same directory.
#   If you think you have to touch this file, contact the authors
#        mieg@crbm.cnrs-mop.fr, rd@sanger.ac.uk
#
#   If you add a display module, edit this file, not *_DEF
#
#
#   If you wish to specify one off compiler options such as
#   setting the debug flag (-g) or a preprocessor macro
#   value (-DMY_OWN_COMPILE_FLAG) then rather than editting
#   this file use the USEROPTS make macro like this:
#
#   make USEROPTS='-g -DMY_OWN_COMPILE_FLAG -x -y'
#
#   these will then be included in the flags used to compile
#   the .o files.
#
#
#################################################################
#
# Before running the make command
# setenv ACEDB_MACHINE to indicate one of the predefined
# Machine dependant option files, or write your own.
# These files are called  $(ACEDB_SRC)/wmake/$(ACEDB_MACHINE)_DEF
# For more detail about specifying these flags see the README in
# this directory.
#
# They define at least 4 (and possibly many more) make macros:
#
# NAME, COMPILER, LINKER, LIBS, RANLIB_NEEDED, AR_OPTIONS,
# LIBCC, LIBLDFLAGS, TEST, GTKVER
# COMPILER sets the compiler and its specific flags (cc, gcc ...)
# LIBCC is the compiler used to make glib, GTK, readline etc
# LIBLDFLAGS options to use when linking the test programs which are
# part of the configuration the 3rd party libraries. This needs to
# reflect the linking of the main code
# LINKER sets the linker and its specific flags (cc, gcc ...)
# LIBS the OEM (e.g. gnu) and system libraries (gcc-gnulib -lm etc)
# RANLIB_NEEDED should be set to false if ranlib is not needed, 
# it defaults to true for backward compatibility.
# AR_OPTIONS defaults to rlu for backward compatibility.
# TEST the test command, defaults to "test"
# GTKVER - empty or unset to use GTK 1.2
#          set to "gtk2 glib-2.0 gtk+-2.0" to use GTK2
#          the "gtk2" controls the build system, "glib-2.0 gtk+-2.0"
#          are passed to pkg-config and may need to be updated to
#          select later versions.

# NAME must be selected as follows
#
#
### pick NAME from among this list.
### NAME is used in the source code to conform to the
### target machine. It is used mostly in wh/mystdlib.h,
### wh/mydirent.h but also in a few awkward places, for example
### wh/array.h redefines the stack Macros in a particular way to
### please the xlc compiler of the IBM.
### If you port to a new machine, please let us know.
#
# ALPHA  Daily development platform using OSF1 V4.0    (1998)
# SUN    Tested for Sun Sparc 1, 2, 10 and on SUN3/80  (1997)
# NEXT   Tested on a several Next                      (1994)
# SGI    Used daily, but the sgi OS is very unsatble   (1997)
# ALLIANT  Alliant multiprocessor at MRC-LMB.          (1991)
#
# CONVEX Contributed by Jukka Ukkonen (ukkonen@csc.fi)
#       For make command to work
#	it does not help to
#		setenv ACEDB_MACHINE CONVEX
#	as adviced in the installation document. The
#	make command on Convex does not look in the
#	environment variables to fill in it's internal
#	variables when ACEDB_MACHINE is not defined as
#	a make's internal variable. To circumvent this
#	inconvenience do the make as follows
#		make ACEDB_MACHINE=CONVEX
#	and everything should work nice and easy.
#
# IBM   IBM-risc 6000,
#       We sometime  have difficulties to compile the graph package
#       with xlc -O2
#
# LINUX IBM-PC 386 and compatible, running gcc and the freeware
#       LINUX operating system. This platform is extremely cheap 
#       around 2000$ hardware + disk + sofware and remarkably fast
#
#	We use either gnu-compiler gcc or the native cc compilers
#       This choice is made by the $(ACEDB_MACHINE)_DEF file.
# 
#       On Alliant our 2 steps make does not properly works,
#       so on those ACEDB_MACHINEs:
#       do the following by hand:
#	setenv ACEDB_MACHINE SGI or ALLIANT
#       mkdir database ; mkdir bin
#       cp wmake/truemake bin/makefile
#       cd bin ; make all
#
#### The following machine-dependent options are recognized
#### by the code
#
# -DNO_LEFT_CASTING For compilers which refuse (int*)p++ syntax
#
#################################################################

#################################################################
################## Graphics System Libraries ####################
#################################################################
# The acedb-config script will
# select the local copy of gtk-config here if we have it, otherwise
# gtk-config should be in the path.
# These are overridable by the _DEF file :

XWIN_LIBS = `../w3rdparty/acedb-config $(GTKVER)`

# These two need to be over-rideable for the windows build.
# The order should be gex followed by graph since gex calls
# graph routines but not vice versa.
GRAPHXWIN_DEPEND  = libgex.a libgraph.a libgd.a
GRAPHXWIN_LIBS    = -lgex -lgraph -lgd


# On badly configured machines (e.g. Linux), you may redefine
# these libraries in a more precise way in your
# $(ACEDB_MACHINE)_DEF file

#################################################################
###################### Lex Libraries ############################
#################################################################
# most versions of lex require you to use -ll
# but not Linux - reset LEX_LIBS in $(ACEDB_MACHINE)_DEF file

LEX_LIBS = -ll

#################################################################
################## Source code directory, #######################
#################################################################

# The main include directory for public interface acedb headers.
INCLUDE = wh

# General tools, useful in any C program, growable arrays, stacks etc.
LIBUTIL = w1

# Graphics library and backends for GTK, and drawing stack
# interpreters for interactive windows, GIF-images and PostScript
LIBGRAPH = w2

# Main source files of acedb applications
APPMAIN = w3

# Acedb-kernel: session control etc
ACELIBKERNEL = w4

# Acedb-kernel: database manager / object storage
ACEDBKERNEL = w5

# Graphical ace manager: query, keyset display etc.
XACEMGR = w6

# Biological data displays: gmaps, pmaps etc.
MAPDISPLAYS = w7

# Non graphic applications
W8 = w8

# Miscellaneous applications and display tools, dotter etc..
DISPLAYTOOLS = w9

# misc acetools, acediff etc.
MISCTOOLS = wace

# New code: bindex, acelib, table etc
NEWCODE  = wnq

# zmap
ZMAP = wzmap

# New Ace Query language
AQLMODULE  = waql

# Sockets based version of server
ACESOCK  = wsocket

# code for acembly
ACEMBLY = wabi

# links between modules, system classes
HOOKS = whooks

# Jo's comparative mapping display tools, oxgrids etc.
OXGRIDMODULE = wjo

# GD - package for dynamic creation of gif image drawings
LIBGD = wgd

# MD5 - package for encryption using the MD5 algorithm.
LIBMD5 = wmd5

##############################################################

true = 1
false = 0

# defaults overridable in $(ACEDB_MACHINE)_DEF
RANLIB_NEEDED = true	
AR_OPTIONS = rlu
LEX         = lex
LEX_OPTIONS = 
YACC        = yacc
###YACC_OPTIONS = -dvt
YACC_OPTIONS =
TEST = test

# defaults overridable in $(ACEDB_MACHINE)_DEF
# e.g. different compiler when using purify
CCC = g++
CCCLINK = g++
CCCFLAGS = -O2 -g3 -Wall

ZMAPLDFLAGS = `pkg-config --libs libgnomecanvas-2.0`

RPCGEN_FLAGS = -I -K -1
# -I -K -1  good for alpha
# -b  -I -K -1  good for linux, probably solaris ?

# suppress auto SCCS extraction
.SCCS_GET:

#################################################################
########## Machine dependent compiler modification ##############
############# Are included from an external file ################
#### This is equivalent to, but more portable than $($(CC)) #####
### Edit these rules to adapt the makefile to a new machine #####
# Note that you can keep different DEF files for the same machine
# setting various compiler options
#################################################################
include deffile

#################################################################
#################################################################
# In principle you should not have to edit the rest of this file
#################################################################
#################################################################

FREE_OBJS = freesubs.o freeout.o messubs.o memsubs.o arraysub.o \
	liste.o filsubs.o msort.o \
	heap.o timesubs.o bump.o randsubs.o call.o menu.o dict.o \
	helpsubs.o texthelp.o utils.o  vtxt.o acein.o aceout.o strsubs.o \
	getopt.o getopt1.o chronoexe.o

FREE_TS_OBJS = acein.o  aceout.o  \
	bump.o        dict.o        liste.o       menu.o \
	texthelp.o  msort.o \
	arraysub.o    call.o        heap.o        \
	memsubs.o     randsubs.o    timesubs.o    utils.o  vtxt.o strsubs.o \
	getopt.o getopt1.o

#####################################################################
# Graph library objects.
#

# Graph layer:
#
GRAPH_HDRS =       ../$(INCLUDE)/graph.h
GRAPH_PRIV_HDRS =  ../$(LIBGRAPH)/graph_.h ../$(LIBGRAPH)/graphcolour.h
GRAPH_OBJS = graphcon.o graphsub.o graphps.o graphgdi.o graphselect.o \
	graphascii.o graphprint.o filquery.o graphgif.o \
	colcontrol.o viewedit.o chronodisp.o graphcolour.o \
	graphAcedbInterface.o graphremote.o graphmesglist.o

# GD image drawing code, used across graph package.
#
LIBGD_OBJS = libgd.o gdfont6x9.o gdfont8x13.o gdfont8x13bold.o

# Graph <-> GraphDev interface:
#
GRAPHDEV_HDRS =  ../$(LIBGRAPH)/graphdev.h

#
# GraphDev layer implementation:
#
GRAPHGEX_OBJS = graphgtk.o graphgdk.o graphgdkremote.o gexhelp.o\
		gexramptool.o gex.o 
GRAPHGEX_HDRS = ../$(LIBGRAPH)/graphgtk_.h

#####################################################################
#####################################################################

AQL_OBJS = aql.o aqlparse.o aqlcheck.o aqlrun.o aqlerror.o aqldebug.o

BASE_OBJS = keysetdump.o lexsubs4.o lexalpha.o \
	disknew.o blocksub.o objcache.o \
	idacedb.o idcurate.o

BASE_5_OBJS = bs2block.o adisk.o acache.o

B_OBJS  = bsubs.o bstree.o bstools.o keyset.o \
	bsdumps.o nicedump.o asubs.o bssubs.o check.o \
	dnasubs.o dnacode.o peptide.o matchtable.o \
	basepad.o smap.o

#########################################

## objects for every acedb build, whether graphical or not.
GENERIC_ACE_OBJS = command.o commandmenu.o session.o dbpath.o aceutils.o banner.o \
	queryexe.o tabledefsubs.o  tabledefio.o flag.o \
	$(AQL_OBJS) $(BASE_OBJS) $(BASE_5_OBJS) $(B_OBJS) \
	class.o sysclass.o tags.o model.o \
	longtext.o quovadis.o picksubs.o alignment.o \
	logsubs.o sigsubs.o prefsubs.o status.o \
	bindex.o acelib.o table.o apputils.o

## same as GENERIC_ACE_OBJS, but these are used in -DACEMBLY builds
GENERIC_ACEMBLY_OBJS = command.acm.o session.o dbpath.o aceutils.o banner.o \
	queryexe.o tabledefsubs.o  tabledefio.o flag.o \
	$(AQL_OBJS) $(BASE_OBJS) $(BASE_5_OBJS) $(B_OBJS) \
	class.acm.o sysclass.acm.o tags.acm.o  model.o \
	longtext.o quovadis.o picksubs.o alignment.o \
	logsubs.o sigsubs.o prefsubs.o status.o \
	bindex.o acelib.o table.o apputils.o

## The GENERIC_ACE_(NON)GRAPH_OBJS files still have #ifdef NON_GRAPHIC
## sections which need to be resolved. These objects can then
## move to the GENERIC_ACE_OBJS group.
GENERIC_ACE_GRAPH_OBJS = parse.o dump.o biblio.o

## special verions of these modules for non-graphical builds
GENERIC_ACE_NONGRAPH_OBJS = parse.ng.o dump.ng.o biblio.ng.o

## for now we have to make sure that gifaceserver gets the non-graphical
## version of parse.c, because of the way parse errors are output
## via freeOut (by .ng.o) and messout/graphOut (by .o), in the latter
## case they are swallowed by the gif backend of the graphlib and not 
## shown to the user
GENERIC_GIFACE_GRAPH_OBJS = parse.ng.o dump.o biblio.o

#################################################################
################## GRAPHICAL_ACE_OBJS ###########################
#################################################################
## these are generic modules, that allow graphical browsing and 
## manipluation of any ace-database (these modules should be in w6)
## functionality of these display is NOT database-dependant

## included in graphical builds
GRAPHICAL_ACE_OBJS = mainpick.o display.o update.o \
	newkey.o treedisp.o forest.o ksetdisp.o \
	plot.o plot2d.o sessiondisp.o longtextdisp.o \
	querydisp.o qbedisp.o querybuild.o  \
	tabledisp.o tablemakerdisp.o multimapdisp.o \
	objcachedisp.o action.o layoutdisp.o prefdisp.o \
	acedbgraph.o acdbtest.o gifcommand.o \
	statusdisp.o aqldisp.o

## included in graphical builds
GRAPHICAL_ACEMBLY_OBJS = mainpick.acm.o display.acm.o update.o \
	newkey.acm.o treedisp.o forest.o ksetdisp.o \
	plot.o plot2d.o sessiondisp.o longtextdisp.o \
	querydisp.o qbedisp.o querybuild.o  \
	tabledisp.o tablemakerdisp.o multimapdisp.o \
	objcachedisp.o action.o layoutdisp.o prefdisp.o \
	acedbgraph.o acdbtest.o gifcommand.o \
	statusdisp.o aqldisp.o

###################################################################
###################### GRAPHICAL_BIO_ACE_OBJS ####################
###################################################################
## these modules allow display of specific biological acedb data
## these modules should NOT be in w4/w5/w6
## functionality of these displays is database-dependant

ALL_DISP_OBJS = geldisp.o \
	cmapdisp.o pmapdisp.o pmapconvert.o \
	gmapdisp.o vmapdisp.o vmapdrag.o \
	pepactivezonecol.o alignmentdisp.o \
	dnacpt.o fpdisp.o pepdisp.o pepgifcommand.o pephomolcol.o \
	pepseqcol.o pepfeaturecol.o pepgraphcol.o metab.o \
        gmapconvert.o gmapmarkercol.o gmapintervalcol.o \
        gmaplocuscol.o gmapremarkcol.o drawdisp.o \
	gmapposnegcol.o method.o methodcache.o gmapsubmapcol.o \
        dendrogram.o 

ZMAP_OBJS = zmapcontrol.o zmapcols.o zmapsequence.o seqregion.o \
            stringbucket.o zmapcalls.o zmapbccol.o

# mapcontrol:
#
MAPCONT_HDRS =  ../$(INCLUDE)/map.h
MAPCONT_ACE_OBJS =  mapcontrol.o
MAPCONT_ACEMBLY_OBJS =  mapcontrol.o


# fmap:
#
FMAP_HDRS =       ../$(INCLUDE)/fmap.h
FMAP_PRIV_HDRS =  ../$(MAPDISPLAYS)/fmap_.h
FMAP_ACE_OBJS = fmapsequence.o fmapfeatures.o fmapgene.o \
	fmaposp.o fmapblast.o fmapmenes.o fmapstatus.o \
	fmapcontrol.o smapconvert.o fmapcdna.o fmapcurate.o \
	das.o gff.o
FMAP_ACEMBLY_OBJS = fmapsequence.o fmapfeatures.o fmapgene.o \
	fmaposp.o fmapblast.o fmapmenes.o fmapstatus.o \
	fmapcontrol.acm.o fmapcdna.acm.o

# grid:
#
GRID_HDRS =       ../$(INCLUDE)/grid.h
GRID_PRIV_HDRS =  ../$(MAPDISPLAYS)/grid_.h
GRID_ACE_OBJS = griddisp.o
GRID_ACEMBLY_OBJS = griddisp.o

OTHER_OBJS = embl.o translate.o \
	gmapdata.o gmapdatacol.o vmapdata2.o \
	align.o gmapphys.o vmapphys.o \
	gfcode.acedb.o hexcode.acedb.o 

DOTTER_OBJS = dotter.o dotterKarlin.o blxview.acedb.o 

JO_OBJS = oxgriddisp.o pairmapdisp.o o2m.o oxhomlist.o specg.o

####

GRAPHICAL_BIO_ACE_OBJS = $(ALL_DISP_OBJS) $(MAPCONT_ACE_OBJS) $(FMAP_ACE_OBJS) $(GRID_ACE_OBJS) \
			  $(OTHER_OBJS) $(DOTTER_OBJS) $(JO_OBJS) #$(ZMAP_OBJS)

GRAPHICAL_BIO_ACEMBLY_OBJS = $(ALL_DISP_OBJS) $(MAPCONT_ACE_OBJS) $(FMAP_ACEMBLY_OBJS) $(GRID_ACEMBLY_OBJS) \
			      $(OTHER_OBJS) $(DOTTER_OBJS) $(JO_OBJS)

######################################################################

### linked in by graphical acembly builds
MAPPING_GRAPH_OBJS = topology.o aligntools.o \
	defcpt.o intrinsictree.o \
	dnaalign.o basecallstat.o


### linked in by non-graphical acembly builds 
MAPPING_NONGRAPH_OBJS = topology.o aligntools.o \
	defcpt.ng.o \
	intrinsictree.ng.o \
	dnaalign.ng.o basecallstat.ng.o

### linked in by graphical acembly builds
ABI_GRAPH_OBJS = trace.acedb.o annot.acedb.o  fmaptrace.acm.o blyctrl.o  geneannot.o

####notneeded####ABI_NONGRAPH_OBJS = trace.acedbng.o annot.acedb.o fmaptrace.acm.o blyctrl.o 

### linked in by graphical acembly builds
BASECALL_GRAPH_OBJS = basecall.acedb.o abifix.acedb.o \
	nnbasecall.acedb.o \
	myNetwork.o acemblyhook.o cdnaalign.o saucisse.o 

### linked in by non-graphical acembly builds
BASECALL_NONGRAPH_OBJS = basecall.acedbng.o abifix.acedbng.o \
	nnbasecall.acedb.o \
	myNetwork.o acemblyhook.o cdnaalign.o saucisse.ng.o 



#####################################################################
# Socket based ace server/client objects.
#

# MD5 encryption package used by socket server code.
#
LIBMD5_HDR            = ../$(LIBMD5)/global.h ../$(LIBMD5)/md5.h
LIBMD5_OBJ            = md5c.o
LIBMD5_TEST_HDR       = ../$(LIBMD5)/digcalc.h
LIBMD5_TEST_OBJ       = mddriver.o digcalc.o digtest.o

# Client/server code.
ACESOCK_SOCKET_HDR    = ../$(ACESOCK)/acesocket_.h
ACESOCK_TRANSPORT_HDR = ../$(ACESOCK)/servertransport.h
ACESOCK_SERVER_HDR    = ../$(ACESOCK)/serverace_.h
ACESOCK_CLIENT_HDR    = ../$(ACESOCK)/saceclient_.h
ACESOCK_CLIENTLIB_HDR = ../$(ACESOCK)/sclientlib.h
ACESOCK_UTILS_HDR     = ../$(ACESOCK)/serverclientutils.h

ACESOCK_SOCKET_OBJ    = acesocket.o acesocketlib.o
ACESOCK_SERVER_OBJ    = serverace.o serveracepasswd.o
ACESOCK_CLIENT_OBJ    = saceclient.o sclient.o
ACESOCK_CLIENTLIB_OBJ = sclientlib.o
ACESOCK_UTILS_OBJ     = serverclientutils.o
ACESOCK_XCLIENT_OBJ   = sxclient.o


###########################################################
## Compile Time Variants
## A single source code will produce several object modules
## Rules are given below
###########################################################

# add any new special suffix here - do not have multiple .SUFFIXES lines 
.SUFFIXES: .o .c .ng.o .acedb.o .acedbng.o .acm.o .acmng.o .ng5.o .a5.o .cc

###########################################################
## Source code location
##
## 
LIBUTIL_SOURCES = $(FREE_OBJS:.o=.c)   

LIBGRAPH_SOURCES = $(GRAPH_OBJS:.o=.c) $(GRAPHGEX_OBJS:.o=.c) xremotemain.c
APPMAIN_SOURCES = gifacemain.c tacemain.c xacemain.c xclientmain.c taqlmain.c apputils.c
ACELIBKERNEL_SOURCES =    command.c commandmenu.c gifcommand.c dump.c model.c \
		banner.c aceutils.c \
		queryexe.c parse.c session.c dbpath.c logsubs.c sigsubs.c \
		prefsubs.c longtext.c picksubs.c mainpick.c metadata.c \
		newkey.c status.c update.c alignment.c \
		tabledefsubs.c tabledefio.c
ACEDBKERNEL_SOURCES = $(BASE_OBJS:.o=.c) $(BASE_5_OBJS:.o=.c)
XACEMGR_SOURCES = $(B_OBJS:.o=.c) \
		display.c treedisp.c forest.c ksetdisp.c \
		querydisp.c qbedisp.c querybuild.c \
		tabledisp.c tablemakerdisp.c multimapdisp.c \
		objcachedisp.c sessiondisp.c \
		action.c plot.c plot2d.c longtextdisp.c \
		acedbgraph.c acdbtest.c layoutdisp.c  prefdisp.c \
		statusdisp.c aqldisp.c
MAPDISPLAYS_SOURCES = $(ALL_DISP_OBJS:.o=.c) $(MAPCONT_ACE_OBJS:.o=.c)  biblio.c \
	$(FMAP_ACE_OBJS:.o=.c) $(GRID_ACE_OBJS:.o=.c) coltest.c 

## MAPPING_OBJS
W8_SOURCES = topology.c defcpt.c intrinsictree.c dnaalign.c \
	aligntools.c basecallstat.c

DISPLAYTOOLS_SOURCES = gfcode.c embl.c  \
	dotter.c dotterKarlin.c \
	translate.c blxview.c \
	gmapdata.c  gmapdatacol.c vmapdata2.c \
	align.c gmapphys.c vmapphys.c hexcode.c \
	blxmain.c blxselect.c blxparser.c \
	diskdump.c diskfix.c \
	dotterMain.c readseq.c \
	efetch.c dbidx.c belvu.c


WRPC_SOURCES = rpcace.x xclient.c jade2ace.c aceclient.c aceclientlib.c \
	aceserver.c jadeserver.c rpcace_sp.c jade2sybase.c

LIBMD5_SOURCES =  $(LIBMD5_OBJ:.o=.c) $(LIBMD5_TEST_OBJ:.o=.c)
ACESOCK_SOURCES = $(ACESOCK_SOCKET_OBJ:.o=.c) $(ACESOCK_SERVER_OBJ:.o=.c) \
                  $(ACESOCK_CLIENT_OBJ:.o=.c) $(ACESOCK_CLIENTLIB_OBJ:.o=.c) \
                  $(ACESOCK_UTILS_OBJ:.o=.c) $(ACESOCK_XCLIENT_OBJ:.o=.c)

NEWCODE_SOURCES = bindex.c acelib.c table.c flag.c acelibtest.c tagcount.c aceversion.c

# Just too difficult to make it dependent on the .h files as well. This may not 
# be the right place to put them, but in any case I can't make it work.
ZMAP_SOURCES = zmapcontrol.c zmapcols.c seqregion.c stringbucket.c \
	       zmapcalls.c zmapsequence.c zmapbccol.c

AQLMODULE_SOURCES = aql.c aqlcheck.c aqlrun.c aqlerror.c \
		aqldebug.c aqlparse.y aqlparse.l
MISCTOOLS_SOURCES = pmapace2.c homonym.c acediff.c acediffsorted.c makeUserPasswd.c

ACEMBLY_SOURCES = trace.c fmaptrace.c blyctrl.c annot.c geneannot.c \
	basecall.c abifix.c myNetwork.c nnbasecall.c acemblyhook.c \
	cdnaalign.c saucisse.c \
	intron2.c 

HOOKS_SOURCES = sysclass.c class.c tags.c quovadis.c
LIBGD_SOURCES = $(LIBGD_OBJS:.o=.c)
OXGRIDMODULE_SOURCES = $(JO_OBJS:.o=.c)


###########################################################
##  Compiler and library options
## CC, LIBS, NAME are defined in $(ACEDB_MACHINE)_DEF
##

# NB ACEDB_GTK needed everywhere for the time being: TODO
IDIR = -I.. -I../$(INCLUDE) -I../wstaden -DACEDB_GTK
# Do not use -I/usr/include
# it prevents gcc from picking up its own includes
# (cc goes to /usr/include anyway)

## to undefine any rubbish
CCFLAGS =
GCFLAGS =

## Different platforms use CC or COMPILE.c
#  (USEROPTS - see comments at top of file)
#
CC =        $(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -c
COMPILE.c = $(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -c

###########################################################
## make targets.
##
##
.KEEP_STATE: 

# "all" should always be the first target so that it is the default make action.
all : xace tace  \
	aceserver aceclient xaceclient \
	giface gifaceserver \
	jade2ace jadeserver \
	saceserver saceclient sxaceclient makeUserPasswd \
	acediff acediffsorted xacez

acembly : libstaden.a tacembly xacembly \
	makeSCF scf2ctf ctf2scf \
	gifacemblyserver\
	gnbk gnbkclient 

other : blixem belvu dotter efetch \
	pmapace tagcount diskdump diskfix \
	xtest coltest genefeatures \
	libfree.a \
	libgraph.a libgraphgex.a libgd.a \
	libacecl.a libace.a libxace.a 

tools : makeUserPasswd acediff acediffsorted


$(LIBUTIL_SOURCES):
	$(TEST) -L $@ || ln -s ../$(LIBUTIL)/$@ . 
$(LIBGRAPH_SOURCES):
	$(TEST) -L $@ || ln -s ../$(LIBGRAPH)/$@ . 
$(APPMAIN_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(APPMAIN)/$@ . 
$(ACELIBKERNEL_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(ACELIBKERNEL)/$@ .
$(ACEDBKERNEL_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(ACEDBKERNEL)/$@ .
$(XACEMGR_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(XACEMGR)/$@ .
$(MAPDISPLAYS_SOURCES):
	$(TEST) -L $@ || ln -s ../$(MAPDISPLAYS)/$@ . 
$(W8_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(W8)/$@ . 
$(DISPLAYTOOLS_SOURCES):
	$(TEST) -L $@ || ln -s ../$(DISPLAYTOOLS)/$@ .
$(NEWCODE_SOURCES):
	$(TEST) -L $@ || ln -s ../$(NEWCODE)/$@ .
$(ZMAP_SOURCES):
	$(TEST) -L $@ || ln -s ../$(ZMAP)/$@ .
$(AQLMODULE_SOURCES):
	$(TEST) -L $@ || ln -s ../$(AQLMODULE)/$@ .
$(ACESOCK_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(ACESOCK)/$@ .
$(LIBMD5_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(LIBMD5)/$@ .
$(WRPC_SOURCES): 
	$(TEST) -L $@ || ln -s ../wrpc/$@ .
$(MISCTOOLS_SOURCES):
	$(TEST) -L $@ || ln -s ../$(MISCTOOLS)/$@ .
$(ACEMBLY_SOURCES):
	$(TEST) -L $@ || ln -s ../$(ACEMBLY)/$@ .
$(HOOKS_SOURCES):
	$(TEST) -L $@ || ln -s ../$(HOOKS)/$@ .
$(LIBGD_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(LIBGD)/$@ .
$(OXGRIDMODULE_SOURCES): 
	$(TEST) -L $@ || ln -s ../$(OXGRIDMODULE)/$@ .

#### Compilation of variants ###############

.c.acedb.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DACEDB -c $< -o $@

.c.acedbng.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DNON_GRAPHIC -DACEDB -c $< -o $@

.c.ng.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DNON_GRAPHIC -c $< -o $@

.c.ng5.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DNON_GRAPHIC -DACEDB5 -c $< -o $@

.c.acm.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DACEMBLY -c $< -o $@

.c.acmng.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DNON_GRAPHIC -DACEMBLY -c $< -o $@

.c.a5.o: $<
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -DACEDB5 -c $< -o $@


#############################################################
################## public libraries #########################
#############################################################

########### utilities library #############

$(FREE_OBJS): ../$(INCLUDE)/regular.h ../$(INCLUDE)/mystdlib.h

helpsubs.o texthelp.o: ../$(INCLUDE)/help_.h

libfree.a : $(FREE_OBJS)
	ar $(AR_OPTIONS) libfree.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libfree.a; fi

libfree_clean : 
	rm -f $(FREE_OBJS) libfree.a

########### thread safe  library #############

$(FREE_TS_OBJS): ../$(INCLUDE)/regular.h ../$(INCLUDE)/mystdlib.h

libtsfree.a : $(FREE_TS_OBJS)
	ar $(AR_OPTIONS) libtsfree.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libtsfree.a; fi


########### graphics libraries ################

$(GRAPH_PRIV_HDRS): $(GRAPH_HDRS)
$(GRAPH_OBJS): $(GRAPH_PRIV_HDRS) $(GRAPHDEV_HDRS)
gexhelp.o: ../$(INCLUDE)/help_.h
libgraph.a :  $(GRAPH_OBJS)
	ar $(AR_OPTIONS) libgraph.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libgraph.a; fi


$(GRAPHGEX_OBJS): $(GRAPHGEX_HDRS) $(GRAPHDEV_HDRS)
libgex.a : $(GRAPHGEX_OBJS) 
	ar $(AR_OPTIONS) libgex.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libgex.a; fi


# GIF drawing routines, independent of which version of graph device layer is used.
libgd.a : $(LIBGD_OBJS)
	ar $(AR_OPTIONS) libgd.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libgd.a; fi


libgraph_clean : 
	rm -f  $(GRAPH_OBJS) libgraph.a
	rm -f  $(GRAPHGEX_OBJS)   libgex.a
	rm -f  $(LIBGD_OBJS)   libgd.a



########### MD5 encryption libraries ################

# MD5 library
$(LIBMD5_OBJ): $(LIBMD5_HDR)

libmd5.a : $(LIBMD5_OBJ)
	ar $(AR_OPTIONS) $@ $?
	if ( $(RANLIB_NEEDED) ) then ranlib $@ ; fi

# MD5 test programs
$(LIBMD5_TEST_OBJ) : $(LIBMD5_HDR) $(LIBMD5_TEST_HDR)

md5test : libmd5.a $(LIBMD5_TEST_OBJ) mddriver digtest
	$(LINKER) -o mddriver mddriver.o -L. -lmd5
	$(LINKER) -o digtest digcalc.o digtest.o -L. -lmd5

#########################################
#### public C interface: libace #########
#########################################

########### AQL objects ######################

lex.yy.c: aqlparse.l ../$(AQLMODULE)/aql_.h
	$(LEX) $(LEX_OPTIONS) aqlparse.l

aqlparse.c: lex.yy.c aqlparse.y
	$(YACC) $(YACC_OPTIONS) aqlparse.y
	mv y.tab.c aqlparse.c

$(AQL_OBJS): ../$(AQLMODULE)/aql_.h

#
# In the end we want fmap et al. to be a library that is compiled just the once,
# here is the start of some dependencies for them.
#

# mapcontrol
#
$(MAPCONT_ACE_OBJS): $(MAPCONT_HDRS)
$(MAPCONT_ACEMBLY_OBJS): $(MAPCONT_HDRS)

# fmap
#
$(FMAP_HDRS): $(MAPCONT_HDRS)
$(FMAP_PRIV_HDRS): $(FMAP_HDRS)
$(FMAP_ACE_OBJS): $(FMAP_PRIV_HDRS)
$(FMAP_ACEMBLY_OBJS): $(FMAP_PRIV_HDRS)

# grid
#
$(GRID_HDRS): $(MAPCONT_HDRS)
$(GRID_PRIV_HDRS): $(GRID_HDRS)
$(GRID_ACE_OBJS): $(GRID_PRIV_HDRS)
$(GRID_ACEMBLY_OBJS): $(GRID_PRIV_HDRS)

# 
# aceversion.c is recompiled & rearchived every time one of the
# other libace objects is recompiled. Hence aceversion.c enables
# us to record the link date of the library along with the ACEDB
# version.
# (this is not quite true at the moment because of the graphic/
# non-graphic split in libace, but this will go away)
#
aceversion.o: $(GENERIC_ACE_OBJS) $(GENERIC_ACE_NONGRAPH_OBJS) $(GENERIC_ACE_GRAPH_OBJS)

#
# dependencies of selected .o files upon special includes
#
command.o tabledefio.o tabledefsubs.o: ../$(INCLUDE)/spread_.h

tablemakerdisp.o: ../$(INCLUDE)/spread_.h ../$(INCLUDE)/tabledisp.h

tabledisp.o multimapdisp.o: ../$(INCLUDE)/spread.h ../$(INCLUDE)/table.h ../$(INCLUDE)/tabledisp.h

aqldisp.o: ../$(INCLUDE)/aql.h ../$(INCLUDE)/table.h ../$(INCLUDE)/tabledisp.h

## table.h
$(AQL_OBJS) command.o matchtable.o dnacpt.o fmapcontrol.o smapconvert.o pephomolcol.o table.o xclient.o quovadis.o : ../$(INCLUDE)/table.h

## method.h
method.o methodcache.o fmapcdna.o fmapcontrol.o smapconvert.o fmapfeatures.o fmapsequence.o fmapgene.o pepfeaturecol.o pephomolcol.o: ../$(INCLUDE)/method.h

methodcache.o: ../$(INCLUDE)/methodcache.h

## bump.h
bump.o graphascii.o multimapdisp.o cmapdisp.o fmapcdna.o fmapfeatures.o fmaposp.o fmapstatus.o gmapintervalcol.o gmaplocuscol.o gmapremarkcol.o gmapsubmapcol.o pepfeaturecol.o pephomolcol.o pmapdisp.o vmapdisp.o defcpt.o gmapphys.o vmapphys.o fmaptrace.o: ../$(INCLUDE)/bump.h

## bump_.h - some external files intrude the internals of the bump-package
bump.o graphascii.o pmapdisp.o: ../$(INCLUDE)/bump_.h

## aceio.h - files that use the new AceIO package ACEIN/ACEOUT
acein.o aceout.o gifacemain.o tacemain.o xacemain.o command.o gifcommand.o longtext.o parse.o status.o dump.o bsdumps.o session.o logsubs.o aceutils.o tabledefio.o tablemakerdisp.o keysetdump.o ksetdisp.o dnasubs.o longtextdisp.o matchtable.o peptide.o fmapcontrol.o smapconvert.o fmaposp.o pepdisp.o pepgifcommand.o defcpt.o table.o aceserver.o xclient.o: ../$(INCLUDE)/aceio.h

## command.h
gifacemain.o tacemain.o xacemain.o command.o commandmenu.o gifcommand.o defcpt.o aceserver.o: ../$(INCLUDE)/command.h

## dump.h
dump.o tabledefio.o command.o bssubs.o nicedump.o ksetdisp.o dendrogram.o embl.o xclient.o: ../$(INCLUDE)/dump.h

## dna.h
dnasubs.o alignment.o command.o mainpick.o basepad.o diaplay.o ksetdisp.o peptide.o dendrogram.o dnacpt.o fmapblast.o fmapcdna.o fmapcontrol.o smapconvert.o fmapfeatures.o fmapgene.o fmapmenes.o fmaposp.o fmapsequence.o fmapstatus.o fpdisp.o geldisp.o aligntools.o basecallstat.o defcpt.o dnaalign.o align.o asn.o embl.o quovadis.o acelib.o: ../$(INCLUDE)/dna.h

## peptide.h
alignment.o command.o gifommand.o ksetdisp.o peptide.o dendrogram.o dnacpt.o fmapcontrol.o smapconvert.o fmapfeatures.o fmapgene.o pepdisp.o pepgifcommand.o embl.o quovadis.o: ../$(INCLUDE)/peptide.h

## longtext.h
command.o mainpick.o display.o longtextdisp.o quovadis.o: ../$(INCLUDE)/longtext.h

## matchtable.h
matchtable.o fmapcontrol.o smapconvert.o pephomolcol.o quovadis.o: ../$(INCLUDE)/matchtable.h

## smap.h
../w6/smap_.h fmapcontrol.o smapconvert.o fmapsequence.o pmapconvert.o pmapdisp.o blxview.o: ../$(INCLUDE)/smap.h

## smap_.h
smap.o: ../w6/smap_.h


######################

LIBACE_OBJS = $(GENERIC_ACE_OBJS) $(GENERIC_ACE_NONGRAPH_OBJS) \
		aceversion.o

libace.a :  $(LIBACE_OBJS)
	ar $(AR_OPTIONS) libace.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libace.a; fi

libace_clean : 
	rm -f $(LIBACE_OBJS) libace.a

######## libxace.a is the variant of libace.a that is
######## compiled without the -DNON_GRAPH compiler flag
######## it is used instead of libace.a in graphical builds
######## it will become obsolete once the code groups
######## GENERIC_ACE_OBJS and GENERIC_ACE_(NON)GRAPH_OBJS have merged

LIBXACE_OBJS = $(GENERIC_ACE_OBJS) $(GENERIC_ACE_GRAPH_OBJS) \
		aceversion.o
LIBGIFACE_OBJS = $(GENERIC_ACE_OBJS) $(GENERIC_GIFACE_GRAPH_OBJS) \
		aceversion.o

libxace.a :  $(LIBXACE_OBJS)
	ar $(AR_OPTIONS) libxace.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libxace.a; fi


libgiface.a :  $(LIBGIFACE_OBJS)
	ar $(AR_OPTIONS) libgiface.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libgiface.a; fi

libxace_clean : 
	rm -f $(LIBXACE_OBJS) libxace.a

################################################################
############## graphical ACEDB programs ########################
################################################################

# Xace - acedb version 4:
# New build for xace, xacemain.c gets recompiled every time xace is built,
# this allows to include the build date in xacemain.
#
XACE_OBJS = $(GRAPHICAL_ACE_OBJS) $(GRAPHICAL_BIO_ACE_OBJS)

mainpick.o longtextdisp.o qbedisp.o querydisp.o treedisp.o fmapcontrol.o smapconvert.o ksetdisp.o: ../$(INCLUDE)/keysetdisp.h


xace : libfree.a $(GRAPHXWIN_DEPEND) libxace.a xacemain.c $(XACE_OBJS)
	rm -f display.o
	$(CC) xacemain.c display.c
	$(LINKER) -o xace xacemain.o $(XACE_OBJS) -L. -lxace -lfree $(GRAPHXWIN_LIBS) $(XWIN_LIBS) $(LIBS) $(LEX_LIBS) 

xace_clean :
	rm -f $(XACE_OBJS) xace$(EXE_SUFFIX)


# giface:
## much like xace, but using virtual display instead of interactive
## windows. It is terminal based, window contents can be dumped into
## gif and postscript files.
GIFACE_OBJS = $(GRAPHICAL_ACE_OBJS) $(ALL_DISP_OBJS) \
$(MAPCONT_ACE_OBJS) $(FMAP_ACE_OBJS) $(GRID_ACE_OBJS) $(OTHER_OBJS) $(JO_OBJS)

giface : libfree.a libgd.a libgraph.a libxace.a gifacemain.c $(GIFACE_OBJS)
	$(CC) gifacemain.c
	$(LINKER) -o giface gifacemain.o $(GIFACE_OBJS) -L. -lxace -lgraph -lgd -lfree $(LIBS) $(LEX_LIBS)

xacez : libfree.a $(GRAPHXWIN_DEPEND) libxace.a xacemain.c $(XACE_OBJS) $(ZMAP_OBJS)
	rm -f display.o
	$(CC) -DZMAP xacemain.c display.c
	$(LINKER) -o xacez xacemain.o $(XACE_OBJS) $(ZMAP_OBJS)  -L. -lxace -lfree $(GRAPHXWIN_LIBS) $(XWIN_LIBS) $(LIBS) $(LEX_LIBS) $(ZMAPLDFLAGS)

#####################################

# Xacembly version 4 build:
XACEMBLY_OBJS =  \
	$(GENERIC_ACEMBLY_OBJS) $(GENERIC_ACE_GRAPH_OBJS) aceversion.o \
	$(GRAPHICAL_ACEMBLY_OBJS) \
	$(GRAPHICAL_BIO_ACEMBLY_OBJS) \
	$(ABI_GRAPH_OBJS) $(BASECALL_GRAPH_OBJS) $(MAPPING_GRAPH_OBJS)

xacembly : libfree.a $(GRAPHXWIN_DEPEND) libstaden.a xacemain.c $(XACEMBLY_OBJS)
	$(CC) -DACEMBLY -c xacemain.c -o xacemblymain.o
	$(LINKER) -o xacembly $(XACEMBLY_OBJS) xacemblymain.o -L. -lfree $(GRAPHXWIN_LIBS) -lstaden $(XWIN_LIBS) $(LIBS) $(LEX_LIBS)
	chmod 755 xacembly$(EXE_SUFFIX)

################################################################
############## non-graphical ACEDB programs ####################
################################################################

# genefeatures
genefeatures : gfcode.o readseq.o
	cc -g -o genefeatures gfcode.o readseq.o -lm

readseq.o : readseq.c 
	$(CC) $(CFLAGS) readseq.c

gfcode.o : gfcode.c
	$(CC) $(USEROPTS) $(CFLAGS) gfcode.c 	

# tace
tace :  libfree.a libace.a tacemain.c
	$(CC) tacemain.c
	$(LINKER) -o tace tacemain.o -L. -lace -lfree $(LIBS) $(LEX_LIBS) 
	chmod 755 tace$(EXE_SUFFIX)

tace_clean :
	rm -f tacemain.o tace$(EXE_SUFFIX)

# tacembly - version 4
TACEMBLY_OBJS =  \
	$(GENERIC_ACEMBLY_OBJS) $(GENERIC_ACE_NONGRAPH_OBJS) aceversion.o \
	$(BASECALL_NONGRAPH_OBJS) $(MAPPING_NONGRAPH_OBJS)

tacembly : libfree.a libstaden.a tacemain.c $(TACEMBLY_OBJS)
	$(CC) -DACEMBLY -c tacemain.c -o tacemblymain.o
	$(LINKER) -o tacembly $(TACEMBLY_OBJS) tacemblymain.o -L. -lfree -lstaden $(LIBS) $(LEX_LIBS)
	chmod 755 tacembly$(EXE_SUFFIX)

# tacembly - version 5
TACEMBLY_5_OBJS = tacemain.acm.o command.acm.o banner.acm.o \
	$(NON_GRAPHIC_OBJS) session.ng5.o $(KERNEL_5_OBJS) $(ACE_5_OBJS) acelib.o \
	$(NON_GRAPHIC_MAPPING_OBJS) \
	$(NON_GRAPHIC_BASECALL_OBJS)

tacembly5 : libfree.a libstaden.a $(TACEMBLY_5_OBJS)
	$(LINKER) -o tacembly $(TACEMBLY_5_OBJS) -L. -lfree -lstaden $(LIBS) $(LEX_LIBS)
	chmod 755 tacembly$(EXE_SUFFIX)

######### the AQL test-platform #################

taql :  libfree.a libace.a taqlmain.o 
	$(LINKER) -o taql taqlmain.o -L. -lace -lfree $(LIBS) $(LEX_LIBS) 

#############################################################
### small test programs using purely libace functionality ###

acelibtest : libfree.a libace.a acelibtest.c
	$(CC) acelibtest.c
	$(LINKER) -o acelibtest acelibtest.o -L. -lace -lfree $(LIBS) $(LEX_LIBS)

tagcount : libfree.a libace.a tagcount.c
	$(CC) tagcount.c
	$(LINKER) -o tagcount tagcount.o -L. -lace -lfree $(LIBS) $(LEX_LIBS)


##########################################
## drivers for remote control via XAtoms

xremote : xremotemain.o
	$(LINKER) -o xremote xremotemain.o $(XWIN_LIBS) -lXmu -lXt $(LIBS)

###############################################################################
################## Sockets server/client ACEDB programs #######################
###############################################################################

##################### saceserver, the socket server ###########################
$(ACESOCK_SOCKET_OBJ): $(ACESOCK_TRANSPORT_HDR) $(ACESOCK_SOCKET_HDR)

$(ACESOCK_SERVER_OBJ): $(ACESOCK_TRANSPORT_HDR) $(ACESOCK_SERVER_HDR)

$(ACESOCK_UTILS_OBJ):  $(ACESOCK_UTILS_HDR)

saceserver:  libfree.a libace.a libmd5.a $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) \
             $(ACESOCK_SERVER_OBJ)
	$(LINKER) -o $@  $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) $(ACESOCK_SERVER_OBJ) \
	 -L. -lace -lfree -lmd5 -lm $(LIBS) $(LEX_LIBS) 
	chmod 755 $(@)$(EXE_SUFFIX)

##################### sgifaceserver, graphical - via gifs ###################
SGIFACESERVER_OBJS = \
	$(GRAPHICAL_ACE_OBJS) \
	$(ALL_DISP_OBJS) \
	$(MAPCONT_ACE_OBJS) $(FMAP_ACE_OBJS) $(GRID_ACE_OBJS) \
        $(OTHER_OBJS) $(JO_OBJS)


sgifaceserver:  libfree.a  libgraph.a libgd.a libgiface.a libace.a libmd5.a serverace.c $(SGIFACESERVER_OBJS) $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) \
             $(ACESOCK_SERVER_OBJ)
	$(CC) -DGIFACESERVER -c serverace.c -o sgifaceserver.o 
	$(LINKER) -o $@ sgifaceserver.o  $(SGIFACESERVER_OBJS) \
	$(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) serveracepasswd.o \
	 -L.  -lgiface -lgraph -lgd -lace -lfree -lmd5 -lm $(LIBS) $(LEX_LIBS) 
	chmod 755 $(@)$(EXE_SUFFIX)

##################### saceclient, client version of tace ####################
$(ACESOCK_CLIENT_OBJ): $(ACESOCK_UTILS_HDR) $(ACESOCK_CLIENTLIB_HDR) $(ACESOCK_CLIENT_HDR)

# aceversion included because we don't use basic ace objects in client but want a version string.
saceclient:  libfree.a aceversion.o libmd5.a  $(ACESOCK_SOCKET_OBJ) \
             $(ACESOCK_UTILS_OBJ) $(ACESOCK_CLIENTLIB_OBJ) $(ACESOCK_CLIENT_OBJ)
	$(LINKER) -o $@  $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) $(ACESOCK_CLIENTLIB_OBJ) \
	 $(ACESOCK_CLIENT_OBJ) commandmenu.o aceversion.o -L. -lfree -lmd5 -lm $(LIBS) $(LEX_LIBS)
	chmod 755 $(@)$(EXE_SUFFIX)

##################### sxaceclient, client version of xace ###################
SXACECLIENT_OBJS =  $(ACESOCK_XCLIENT_OBJ) $(ACESOCK_CLIENTLIB_OBJ) \
	$(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) \
	$(GRAPHICAL_ACE_OBJS) \
	$(GRAPHICAL_BIO_ACE_OBJS)

sxaceclient : libfree.a libmd5.a $(GRAPHXWIN_DEPEND) libxace.a xclientmain.c $(SXACECLIENT_OBJS)
	$(CC) xclientmain.c
	$(LINKER) -o sxaceclient xclientmain.o $(SXACECLIENT_OBJS) \
	 -L. -lxace $(GRAPHXWIN_LIBS) -lfree -lmd5 $(XWIN_LIBS) $(LIBS) $(LEX_LIBS)  
	chmod 755 sxaceclient$(EXE_SUFFIX)

######################### clean all socket code. ############################
sace_build : saceserver sgifaceserver saceclient sxaceclient

sace_clean :
	rm -f $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) $(ACESOCK_SERVER_OBJ)
	rm -f saceclient $(ACESOCK_SOCKET_OBJ) $(ACESOCK_UTILS_OBJ) $(ACESOCK_CLIENT_OBJ)
	rm -f $(SXACECLIENT_OBJS) sxaceclient$(EXE_SUFFIX)



######################################################
#### RPC server/client ACEDB programs ################
######################################################


RPCGEN_PRODUCTS = rpcace.h rpcace_xdr.c rpcace_clnt.c rpcace_svc.c

$(RPCGEN_PRODUCTS): rpcace.x
	rpcgen $(RPCGEN_FLAGS) rpcace.x

rpcace_sp.o: rpcace_sp.c rpcace_svc.c

aceclientlib.o: aceclientlib.c rpcace.h
	$(CC) -c $<

RPC_CLIENT_OBJS = aceclientlib.o rpcace_clnt.o rpcace_xdr.o
RPC_SERVER_OBJS = rpcace_sp.o  rpcace_xdr.o 
NET_CLIENT_OBJS = aceclientlib.o rpcace_clnt.o rpcace_xdr.o
RPC_X_CLIENT_OBJS = xclient.o aceclientlib.o rpcace_clnt.o rpcace_xdr.o

libacecl.a : aceclientlib.o rpcace_clnt.o rpcace_xdr.o
	ar $(AR_OPTIONS) libacecl.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libacecl.a; fi


################ aceserver, no graphics #################
ACESERVER_OBJS = $(RPC_SERVER_OBJS) 

aceserver : libfree.a libace.a aceserver.c $(ACESERVER_OBJS) rpcace.x rpcace.h
	$(CC) aceserver.c
	$(LINKER)  -o aceserver aceserver.o $(ACESERVER_OBJS) -L. -lace -lfree $(LIBS) $(LEX_LIBS)
	chmod 755 aceserver
	\rm -f rpc.acedbd
	ln -s aceserver rpc.acedbd

aceserver_clean :
	rm -f $(ACESERVER_OBJS) aceserver$(EXE_SUFFIX)

############# gifaceserver, does gifs of fmap etc. ################

GIFACESERVER_OBJS = \
	$(RPC_SERVER_OBJS) \
	$(GRAPHICAL_ACE_OBJS) \
	$(ALL_DISP_OBJS) \
	$(MAPCONT_ACE_OBJS) $(FMAP_ACE_OBJS) $(GRID_ACE_OBJS) \
        $(OTHER_OBJS) $(JO_OBJS)

gifaceserver : libfree.a libgraph.a libgd.a libgiface.a aceserver.c $(GIFACESERVER_OBJS) rpcace.x rpcace.h
	$(CC) -DGIFACESERVER -c aceserver.c -o gifaceserver.o 
	$(LINKER)  -o gifaceserver gifaceserver.o $(GIFACESERVER_OBJS) -L. -lgiface -lgraph -lgd -lfree $(LIBS) $(LEX_LIBS)
	chmod 755 gifaceserver
	\rm -f rpc.gifacedbd
	ln -s gifaceserver rpc.gifacedbd


############ gifacemblyserver, Jeans sequence assembly variant. ##########################
GIFACEMBLYSERVER_OBJS = \
	$(RPC_SERVER_OBJS) \
	$(GENERIC_ACEMBLY_OBJS) $(GENERIC_ACE_GRAPH_OBJS) aceversion.o  \
	$(GRAPHICAL_ACEMBLY_OBJS) $(GRAPHICAL_BIO_ACEMBLY_OBJS) \
	$(ABI_GRAPH_OBJS) $(BASECALL_GRAPH_OBJS) $(MAPPING_GRAPH_OBJS)


gifacemblyserver : libfree.a libgraph.a libgd.a  libstaden.a aceserver.c $(GIFACEMBLYSERVER_OBJS) rpcace.x rpcace.h
	$(CC) -DGIFACESERVER -c aceserver.c -o gifserver.o 
	$(LINKER)  -o gifacemblyserver gifserver.o $(GIFACEMBLYSERVER_OBJS) -L. -lgraph -lgd -lfree -lstaden $(LIBS) $(LEX_LIBS)
	chmod 755 gifacemblyserver$(EXE_SUFFIX)

gifacemblyserver_clean : 
	rm -f $(GIFACEMBLYSERVER_OBJS) gifacemblyserver$(EXE_SUFFIX)


####### text-based client #############

# aceversion included because we don't use basic ace objects in client but want a version string.
aceclient : libfree.a aceversion.o aceclient.c $(RPC_CLIENT_OBJS) rpcace.x rpcace.h
	$(CC) aceclient.c
	$(LINKER) -o aceclient aceclient.o aceversion.o $(RPC_CLIENT_OBJS) -L. -lfree $(LIBS)
	chmod 755 aceclient$(EXE_SUFFIX)

aceclient_clean :
	rm -f $(RPC_CLIENT_OBJS) aceclient$(EXE_SUFFIX)


####### graphical client ###############

XACECLIENT_OBJS =  $(RPC_X_CLIENT_OBJS) \
	$(GRAPHICAL_ACE_OBJS) \
	$(GRAPHICAL_BIO_ACE_OBJS)

xaceclient : libfree.a $(GRAPHXWIN_DEPEND) libxace.a xclientmain.c $(XACECLIENT_OBJS)
	$(CC) xclientmain.c
	$(LINKER) -o xaceclient xclientmain.o $(XACECLIENT_OBJS) -L. -lxace $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS) $(LEX_LIBS)  
	chmod 755 xaceclient$(EXE_SUFFIX)

xaceclient_clean :
	rm -f $(XACECLIENT_OBJS) xaceclient$(EXE_SUFFIX)




############################################
#### ACEDB-to-JADE programs ################
############################################

jade2ace : libfree.a jade2ace.c $(NET_CLIENT_OBJS) rpcace.x rpcace.h
	$(CC) jade2ace.c
	$(LINKER) -o jade2ace jade2ace.o $(NET_CLIENT_OBJS) -L. -lfree $(LIBS)
	chmod 755 jade2ace
	\rm -f netclient	
	ln -s jade2ace netclient

jade2sybase : libfree.a jade2sybase.o
	$(LINKER) -o jade2sybase jade2sybase.o -L. -lfree $(LIBS)
	chmod 755 jade2sybase

jadeserver : libfree.a libace.a jadeserver.c
	$(CC) jadeserver.c
	$(LINKER) -o jadeserver jadeserver.o -L. -lace -lfree $(LIBS) $(LEX_LIBS)
	chmod 755 jadeserver

###################################################
############## test programs ######################
###################################################

xtest : libfree.a $(GRAPHXWIN_DEPEND) graphtest.o 
	$(LINKER) -o xtest graphtest.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

boxtest : libfree.a $(GRAPHXWIN_DEPEND) graphboxtest.o 
	$(LINKER) -o boxtest graphboxtest.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

giftest : libgraph.a libgd.a graphtest.o 
	$(LINKER) -o giftest graphtest.o -L. -lgraph -lgd -lfree $(LIBS)

coltest : coltest.o $(GRAPHXWIN_DEPEND)
	$(LINKER) -o coltest coltest.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

#### other programs #########################
##
diskdump : libfree.a diskdump.o
	$(LINKER) -o diskdump diskdump.o -L. -lfree $(LIBS)

diskfix : libfree.a diskfix.o
	$(LINKER) -o diskfix diskfix.o -L. -lfree $(LIBS)

blixelect : blxselect.o blxparser.o blixem.o translate.o dotter.o dotterKarlin.o $(GRAPHXWIN_DEPEND)
	$(LINKER) -o blixelect blxselect.o blxparser.o blixem.o dotter.o dotterKarlin.o \
	translate.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

blixem : $(GRAPHXWIN_DEPEND) libfree.a blixem.o blxmain.o blxparser.o translate.o dotter.o dotterKarlin.o 
	$(LINKER) -o blixem blixem.o blxmain.o blxparser.o dotter.o dotterKarlin.o \
	translate.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

blixem.o : blxview.c
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME) -c -o $@ blxview.c

dotter : $(GRAPHXWIN_DEPEND) libfree.a dotter.o dotterMain.o dotterKarlin.o translate.o blxparser.o blixem.o 
	$(LINKER) -o dotter dotter.o dotterKarlin.o dotterMain.o  \
	translate.o blxparser.o blixem.o -L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)


# I have removed this optimisation stuff from dotter for now because you cannot
# debug properly with it, EG
dotter.o: dotter.c
	$(COMPILER) $(USEROPTS) -g $(IDIR) -D$(NAME) -c -o $@ dotter.c

#	$(COMPILER) $(USEROPTS) -O2 -g3 $(IDIR) -D$(NAME) -c -o $@ dotter.c


belvu.o: belvu.c
	$(COMPILER) $(USEROPTS) -O2 -g3 $(IDIR) -D$(NAME) -c -o $@ belvu.c

belvu : $(GRAPHXWIN_DEPEND) libfree.a belvu.o 
	$(LINKER) -o belvu belvu.o \
	-L. $(GRAPHXWIN_LIBS) -lfree $(XWIN_LIBS) $(LIBS)

efetch : efetch.o dbidx.o
	$(LINKER) -o efetch efetch.o dbidx.o

efetch.o: efetch.c
	$(CC) -DMIXDB efetch.c

intron2 : libfree.a intron2.o
	$(LINKER)  -o intron2 intron2.o -L. -lfree $(LIBS)

metacheck : libfree.a libace.a metadata.o
	  $(LINKER) -o metacheck metadata.o -L. -lace -lfree $(LIBS) $(LEX_LIBS) 

makeUserPasswd: makeUserPasswd.c libfree.a libmd5.a 
	$(CC) $@.c
	$(LINKER) -o $@ $@.o -L. -lfree -lmd5 $(LIBS)


#### conversion programs ###################
##
PMAPACE_OBJS  =  pmapace2.o
pmapace : libfree.a $(PMAPACE_OBJS)
	$(LINKER) -o pmapace $(PMAPACE_OBJS) -L. -lfree $(LIBS)

HOMONYM_OBJS  =  homonym.o 
homonym :  $(HOMONYM_OBJS)
	$(LINKER) -o homonym $(HOMONYM_OBJS) -L. -lfree $(LIBS)

acediff : libfree.a acediff.c
	$(CC) acediff.c
	$(LINKER) -o acediff acediff.o -L. -lfree $(LIBS)

# contributed by detlef: acediffs tace outputs
# using the fact that they are naturally sorted

acediffsorted : libfree.a acediffsorted.c
	$(CC) acediffsorted.c
	$(LINKER) -o acediffsorted acediffsorted.o -L. -lfree $(LIBS)


###### genbank indexing program #########################
##
WGNBK = wgnbk # links between modules 

GNBK_OBJS = gnbk.o gnbkserver.o  rpcgnbk_sp.o
GNBK_CLIENT_OBJS = gnbkclient.o gnbkclientlib.o rpcgnbk_clnt.o rpcgnbk_xdr.o

GNBK_SOURCES = rpcgnbk.x gnbk.c gnbkserver.c  rpcgnbk_sp.c \
	 gnbkclient.c gnbkclientlib.c 

$(GNBK_SOURCES) :
	$(TEST) -L $@ || ln -s ../wgnbk/$@ .

RPCGNBK_PRODUCTS = rpcgnbk.h rpcgnbk_xdr.c  rpcgnbk_clnt.c rpcgnbk_svc.c

$(RPCGNBK_PRODUCTS): rpcgnbk.x
	rpcgen  $(RPCGEN_FLAGS) rpcgnbk.x

rpcgnbk_sp.o: rpcgnbk_sp.c  rpcgnbk_svc.c

gnbkserver.o: gnbkserver.c rpcgnbk.h 
	$(COMPILER) $(USEROPTS) $(IDIR) -D$(NAME)  -c $< 

gnbk :  libfree.a gnbkserver.o $(GNBK_OBJS) rpcgnbk_xdr.o 
	$(LINKER)  -o gnbk $(GNBK_OBJS) rpcgnbk_xdr.o -L. -lfree $(LIBS)

gnbkclient : libfree.a  gnbkserver.o $(GNBK_CLIENT_OBJS) rpcgnbk_xdr.o 
	$(LINKER)  -o gnbkclient $(GNBK_CLIENT_OBJS) -L. -lfree $(LIBS)


###########################################################
###### Staden library #####################################
## These modules were copied form Roger Staden distribution
## io_lib-1.7.tar.gz
## with just a modifications to support CTF format
## for example between staden's array.h and acedb array.h

libstaden.a makeSCF scf2ctf ctf2scf : libfree.a makefile.staden
	$(MAKE) -f makefile.staden  $@
	\rm makefile.staden    # to force evaluation each time

makefile.staden:
	cp ../wstaden/makefile.staden .
	chmod 666 makefile.staden

###########################################################
################## Ace C Library ##########################
###########################################################

WAC_SOURCES = acclient.c actable.c acinside.c

$(WAC_SOURCES):
	$(TEST) -L $@ || ln -s ../wac/$@ .

acclient.o:     acclient.c ../wac/acclient_acetcp.c ../wac/acclient_rpc.c \
	../wac/acclient_socket.c


# LINK_ACC_RPC=$(RPC_CLIENT_OBJS)
LINK_ACC_RPC=

LINK_ACC=libaccl.a libfree.a $(LINK_ACC_RPC)
# LINK_ACC is the set of object files needed if you use
# the client version of the new Ace C library
#
# In NCBI AceDB, MUST HAVE libtsfree.a
# In Sanger AceDB, you MUST NOT HAVE libtsfree.a

LINK_ACS=libacs.a libace.a libfree.a libtsfree.a
# LINK_ACS is what to use if you want a standalone Ace C program

LINK_ACI=libacs.a
# LINK_ACI is what to use if you have Ace C inside tace, xace, etc



LIBACCL_RPC_SUPPORT= aceclientlib.o rpcace_clnt.o rpcace_xdr.o
LIBACCL_SOCKET_SUPPORT=md5c.o

libaccl.a: acclient.o actable.o $(LIBACCL_RPC_SUPPORT) $(LIBACCL_SOCKET_SUPPORT)
	ar $(AR_OPTIONS) libaccl.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libaccl.a; fi


libacs.a: acinside.o actable.o
	ar $(AR_OPTIONS) libacs.a $?
	if ( $(RANLIB_NEEDED) ) then ranlib libacs.a; fi




###########################################################
#
# ace command interface, using new Ace C
#       will replace aceclient, works with any Ace C transport
#

accmd.c: ../wac/accmd.c
	$(TEST) -L $@ || ln -s ../wac/accmd.c .

accmd.o:        accmd.c
	$(CC) -I.. -c accmd.c

# The "t" in taceclient stands for "TCP".  This client actually speaks
# any transport protocol known by Ace C.  I originally called it accmd,
# but Jean wanted it named taceclient so it would more resemble aceclient,
# the thing it is replacing.
# Note that taceclient is NOT a drop-in replacement for aceclient.

taceclient accmd: accmd.o $(LINK_ACC)
	$(LINKER) -o taceclient accmd.o $(LINK_ACC) $(LIBS)
	rm -f accmd
	ln taceclient accmd

# saccmd is ac cmd that runs standalone (i.e. without a server)

saccmd: accmd.o $(LINK_ACS)
	$(LINKER) -o $@ accmd.o $(LINK_ACS) $(LIBS) $(LEX_LIBS)

###########################################################
#
# ace client test for new ace C
#

acctest.c: ../wac/acctest.c
	$(TEST) -L $@ || ln -s ../wac/acctest.c .

acctest.o:      acctest.c
	$(CC) -I.. -c acctest.c

acctest: acctest.o $(LINK_ACC)
	$(LINKER) -o acctest acctest.o $(LINK_ACC) $(LIBS)


acstest: acctest.o $(LINK_ACS)
	$(LINKER) -o acstest acctest.o $(LINK_ACS) $(LIBS) $(LEX_LIBS) 


###########################################################
################## installation ###########################
###########################################################

install_bin :
	@echo 'installing' $@ ;
	for target in $(INSTALL_BIN) ; do  \
	echo 'installing' $$target 'for $(ACEDB_MACHINE)' ; \
	cp $$target $(ACEDB)/bin ; \
	done
	cd $(ACEDB)/bin ; chmod 755 $(INSTALL_BIN)

###########################################################
################## distribution ###########################
###########################################################

clean :
	rm -f ../w*/core ../w*/*~
	rm -rf libraries.untarred libraries.install

dist :
	cd ..; rm w*/*~; \
	tar cvf - w* --exclude CVS --exclude .cvsignore --exclude *~ | gzip -c > ace.tar.gz

###########################################################
############## 3rd party libraries ########################
###########################################################

libraries :
	cd ..; w3rdparty/build_all_3rdparty $(GTKVER) $(LIBCC) $(LIBLDFLAGS)

###########################################################
########### end of the acedb truemake file ################
###########################################################