#------------------------------------------------------------------------------
#
#   QUASAR - q-gram Alignment based on Suffix ARrays
#
#   Copyright (C) 1998 Stefan Burkhardt
#   Author: Stefan Burkhardt <stburk@mpi-sb.mpg.de>
#   This file is part of the QUASAR package.
#
#   QUASAR is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Library General Public License as
#   published by the Free Software Foundation; either version 2 of the
#   License, or (at your option) any later version.
#
#   QUASAR is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Library General Public License for more details.
#
#   You should have received a copy of the GNU Library General Public
#   License along with the QUASAR package; see the file copying.  If not,
#   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#   Boston, MA 02111-1307, USA.  or contact the author.
#
# Makefile for quasar
#
# $Revision: 1.9 $
# $Date: Wed, 29 Mar 2000 11:07:45 +0200 $
#
#------------------------------------------------------------------------------

# desired C compiler and flags
CC = gcc
CFLAGS = -O3
BUILD = /KM/usr/stburk/COMP-BIO/QUASAR
INCLUDE = $(BUILD)/INCLUDE
SOURCE = $(BUILD)/SRC
LF64_C =  -D_LARGEFILE64_SOURCE $(getconf LFS64_CFLAGS)
LF64_L = $(getconf LFS64_LDFLAGS) 

# Variables for accessing the NCBI files
NCBI = $(BUILD)/SRC/NCBI
NCBI_INCDIR = $(NCBI)/ncbi/include
NCBI_LIBDIR = $(NCBI)/ncbi/lib
LDFLAGS = -I$(NCBI_INCDIR) -L$(NCBI_LIBDIR)
NCBILIBS = -lncbitool -lncbiobj -lncbi -lm

# Stuff needed for gmake to find the files...
vpath %.h $(INCLUDE)
vpath %.c $(SOURCE)
vpath %.o $(BUILD)

# Object files needed to link quasar
Q_OBJS = q_blast.o q_blocks.o q_headers.o q_hood.o q_index.o q_misc.o q_options.o q_out.o q_parser.o q_sset.o quasar.o
F2Q_OBJS = q_misc.o q_sset.o f2q.o
Q_SA_OBJS = q_misc.o q_sset.o q_sa.o
Q_PRE_OBJS = q_misc.o q_sset.o q_pre.o

# Binaries
BINARIES = quasar f2q q_pre q_sa


#------------------------------------------------------------------------------
all: quasar f2q q_pre q_sa

# main target for quasar
quasar:	$(Q_OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(Q_OBJS) -o quasar $(NCBILIBS)

# main program
quasar.o: quasar.c quasar.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/quasar.c

# debug versions
debug:
	gmake all CFLAGS='-g'
DEBUG: 
	gmake all CFLAGS='-g -DDEBUG'

# quantify version
quant : 
	gmake all CFLAGS='-g -Wall' CC='quantify gcc'

# purify version
pure : 
	gmake all CFLAGS='-g -Wall' CC='purify -cache-dir=/var/tmp/pure_cache gcc'

#------------------------------------------------------------------------------
# fasta to sset converter
f2q: $(F2Q_OBJS)
	$(CC) $(CFLAGS) $(F2Q_OBJS) -o f2q

# main program
f2q.o: f2q.c f2q.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/f2q.c

#------------------------------------------------------------------------------
# suffix array construcion
q_sa: $(Q_SA_OBJS)
	$(CC) $(CFLAGS) $(Q_SA_OBJS) -o q_sa

# main program
q_sa.o: q_sa.c q_sa.h q_defines.h
	$(CC) $(CFLAGS) $(LF64_C) -I$(INCLUDE) -c $(SOURCE)/q_sa.c $(LF64_L)

#------------------------------------------------------------------------------
# search result precomputer
q_pre: $(Q_PRE_OBJS)
	$(CC) $(CFLAGS) $(Q_PRE_OBJS) -o q_pre

# main program
q_pre.o: q_pre.c q_pre.h q_defines.h
	$(CC) $(CFLAGS) $(LF64_C) -I$(INCLUDE) -c $(SOURCE)/q_pre.c $(LF64_L)

#------------------------------------------------------------------------------
# targets for the subcomponents
# blast module
q_blast.o: q_blast.c q_blast.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -I$(NCBI_INCDIR) -c $(SOURCE)/q_blast.c

# block array module
q_blocks.o: q_blocks.c q_blocks.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_blocks.c

# header index module
q_headers.o: q_headers.c q_headers.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_headers.c

# neighbourhood generation
q_hood.o: q_hood.c q_hood.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_hood.c

# index module
q_index.o: q_index.c q_index.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_index.c

# misc. utility functions
q_misc.o: q_misc.c q_misc.h q_defines.h
	$(CC) $(CFLAGS) $(LF64_C) -I$(INCLUDE) -c $(SOURCE)/q_misc.c $(LF64_L)

# option module
q_options.o: q_options.c q_options.h q_defines.h 
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_options.c

# output module
q_out.o: q_out.c q_out.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_out.c

# command line parsing
q_parser.o: q_parser.c q_parser.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_parser.c

# sequence set module
q_sset.o: q_sset.c q_sset.h q_defines.h
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $(SOURCE)/q_sset.c

#------------------------------------------------------------------------------
# ncbi libraries
ncbi :  
	NCBI=/KM/usr/stburk/COMP-BIO/QUASAR/SRC/NCBI
	export NCBI
	cd SRC/NCBI
	$(NCBI)/ncbi/make/makedis.csh - 2>&1 | tee .err
	cd ../../

#------------------------------------------------------------------------------
# utility targets

# clean up .o files and ~ files
clean: 
	@-rm *~
	@-rm *.o
	@-rm $(BINARIES)
	@-rm SRC/*~
	@-rm INCLUDE/*~

# check into prcs
checkin:
	@prcs checkin
	@prcs rekey
	@echo 'Remember to edit the New-Version-Log!!!'

# run lint on the source code
lint:
	lint -I$(INCLUDE) SRC/*.c

# make tarball
tar: clean
	tar cvf /KM/usr/stburk/quasar.tar *
