#    Copyright (c) 2004, Menaka Lashitha Bandara <lashi@optusnet.com.au>
#
#    Makefile.
#
#    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


USERFLAGS=

# Compiler
CC = gcc

# Optimisations
OPT=-O2
#OPT=-ggdb3 -O
#OPT=-ggdb3

# Our export Flags
CFLAGS = -Wall -Wstrict-prototypes $(OPT) -I../include/ -I./include/ -L../lib $(MFLAGS) $(USERFLAGS)

# Don't touch below this!

# Mandatory FLAGS
MFLAGS= -DVERSION="$(RELEASE)" -DCCINFO="$(CCV)" -DOPTS="$(OPT)"

CCV=`$(CC) -v 2>&1 | grep version`
RELEASE=1.0

# Don't touch!
LIBDIR=../lib
MONO_LIBNAME=monograph
EXCEPTION_LIBNAME=exception
GENERATOR_LIBNAME=generator
ALG_LIBNAME=algorithm

BUILD_LOG=build.log

export CC CFLAGS RELEASE USERFLAGS BUILD_LOG LIBDIR\
	MONO_LIBNAME EXCEPTION_LIBNAME ALG_LIBNAME GENERATOR_LIBNAME

all: all2 program

all2:
	@echo -e "\n\n*** Using Compiler:\n\t$(CCV)"
	@echo -e "*** Enabling flags:\n\t$(CFLAGS)\n"

doc:
	@echo -e "\t[Building Documentation]"
	@make -sC documentation

exception:
	@echo -e  "\t[Building Exception Handler]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC exception

monograph: exception
	@echo -e  "\t[Building MonoGraph Libraries]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC monograph
	
algorithm: monograph
	@echo -e  "\t[Building Algorithms]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC algorithm

generator: monograph
	@echo -e  "\t[Buliding Graph Generator]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC generator

testing: generator algorithm
	@echo -e  "\t[Building Testing Binaries]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC testing

program: generator algorithm
	@echo -e  "\t[Building Program Binaries]"
	@rm -rf $@/$(BUILD_LOG)
	@make -sC program

clean:
	@echo -e "[Cleaning Source Tree]..."
	@make -sC algorithm clean 
	@make -sC monograph clean
	@make -sC exception clean
	@make -sC generator clean
	@make -sC testing clean
	@make -sC program clean 
	@rm -rf lib/*

.PHONY: monograph exception algorithm testing generator doc program
