########################################################################
# AUTHOR: Srikanta Bedathur
# DESCRIPTION: Top level makefile
#              1. Whenever possible, try to 'make clean' before 
#                 building
#              2. Read the Compile Instructions in the README file to 
#                 learn more about the flags.
# Copyright (C) 2004 Database Systems Lab, Supercomputer Education and
# Research Centre, Indian Institute of Science, Bangalore, INDIA.
# http://dsl.serc.iisc.ernet.in
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
########################################################################
SRCDIR=src
INCLDIR=incl
OBJDIR=obj
OBJ=defines.o suffix.o malloc.o construct.o \
	sfxnode.o sfxnode_ll.o sfxintnode.o sfxintnode_ll.o \
	smartref.o smartref_priv.o \
	options.o search.o seqiter.o alphabet.o
INC=allocator.h construct.h defines.h \
	key.h malloc.h options.h page.h \
	sfxnode.h s_man.h smartref.h s_pagerec.h \
	timings.h ram_storage.h disk_storage.h alphabet.h \
	s_man_lru.h s_man_topq.h search.h seqiter.h

COMMONFLAGS=-O3 -fexpensive-optimizations 
IMPLFLAGS=-DLINKEDLIST
STATFLAGS=-DSTATS -DFILESTATS -DSMSTATS
PAGESIZEFLAG=-DSMALLPAGE
TRACEFLAG=-DGENTRACE

CXXFLAGS=$(COMMONFLAGS) $(STATFLAGS) -I$(INCLDIR)

suffix: $(OBJDIR)/.dep $(OBJ:%.o=$(OBJDIR)/%.o)
	g++ $(CXXFLAGS) -o $@ $(OBJ:%.o=$(OBJDIR)/%.o)

include $(OBJDIR)/.dep

$(OBJDIR)/%.o:
	g++ $(CXXFLAGS) -c -o $@ $(@:$(OBJDIR)/%.o=$(SRCDIR)/%.C)

$(OBJDIR)/.dep: $(OBJ:%.o=$(SRCDIR)/%.C) $(INC:%.h=$(INCLDIR)/%.h)
	@set -e; \
	for i in $(OBJ:%.o=$(SRCDIR)/%.C); do \
		g++ $(CXXFLAGS) -M $$i >> $@; \
	done
clean: 
	rm -f suffix $(OBJ:%.o=$(OBJDIR)/%.o)

distclean:
	rm -f suffix  $(OBJ:%.o=$(OBJDIR)/%.o) $(OBJDIR)/.dep

