# Makefile to create a main program that tests ReLaTIve on a Laplace Transforms Database
# Version 1.0

#***********************************************************************
#   Authors:                                                            
#       	Luisa D'Amore - University of Naples, Federico II	           
#		Rosanna Campagna - University of Naples, Federico II	        
#		Valeria Mele - University of Naples, Federico II	            
#		Almerico Murli - SPACI - NAPLES                   	            
# 		Mariarosaria Rizzardi - University of Naples, Parthenope        
#************************************************************************

ifneq ($(CC),gcc)
CC     = gcc
endif

ifndef rootdir 
rootdir  = ..
endif

ifndef RELdir
RELdir  =  $(rootdir)/SRC
endif

ifndef dbdir
dbdir  =  ./database
endif

ifndef utildir
utildir  =  ./utility
endif

## CHECK
#############################################################################################################
### GSL building directory:                                                                               ###	
ifndef gsllib																							  
gsllib=/usr/local
endif
#############################################################################################################
### change them if you know that they are different in your envirmoment                                   ###

# GSL include directory #
ifndef gsldirinc
gsldirinc   = $(gsllib)/include
endif

# GSL libraries directory #
ifndef gsldirlib
gsldirlib = $(gsllib)/lib
endif

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

LD_LIBRARY_PATH = $(gsldirlib)
export LD_LIBRARY_PATH

ifndef CFLAGS
CFLAGS 	= -Wall -ansi -pedantic 
endif

ifndef RM
RM     = rm -f -r
endif


LIBS	= -Wl,-rpath,$(gsldirlib) -L. -lrelative -L$(dbdir) -ldatabase -L$(utildir) -lutil  -L$(gsldirlib) -lgsl -lgslcblas -lm 

OBJ		= Driver-ArticleTests.o 
BIN		= Driver

all: $(BIN) 

util: $(gsldirinc)/gsl 
	@echo
	@echo
	@echo "############################################################################"
	@echo "ReLaTIve ARTICLE TEST DRIVER: creating utility library"
	@echo "############################################################################"
	@$(MAKE) -C $(utildir) 
	
db: util
	@echo
	@echo
	@echo "############################################################################"
	@echo "ReLaTIve ARTICLE TEST DRIVER: creating Transform/Inverse Databases library"
	@echo "############################################################################"
	@$(MAKE) -C $(dbdir) 
	
rel: $(RELdir)/ck_calc.c $(RELdir)/ReLaTIve.h $(RELdir)/ReLaTIve.c
	@echo
	@echo
	@echo "############################################################################"
	@echo "ReLaTIve ARTICLE TEST DRIVER: creating ReLaTIve library"
	@echo "############################################################################"
	@$(MAKE) -f Makefile_REL 

$(OBJ): Driver-ArticleTests.c rel db
	@echo
	@echo
	@echo "############################################################################"
	@echo "ReLaTIve ARTICLE TEST DRIVER: compiling main program to test ReLaTIve on database..."
	@echo "############################################################################"
	@$(CC) $(CFLAGS) -I$(dbdir) -I$(gsldirinc) -I$(RELdir) -I$(utildir) -c Driver-ArticleTests.c
	
$(BIN): $(OBJ) 
	@echo
	@echo
	@echo "############################################################################"
	@echo "ReLaTIve ARTICLE TEST DRIVER: linking main program to test ReLaTIve on database..."
	@echo "############################################################################"
	@$(CC) $(CFLAGS) -o $(BIN) $(OBJ) $(LIBS)
	@${RM} $(OBJ) 
	@echo
	@echo
	@echo "############################################################################"
	@echo "############################################################################"
	@echo "############################################################################"
	@echo "############################################################################"
	@echo "Test driver installed!!!"
	@echo "Now you can run the program $(BIN) or a script in this directory."
	@echo "(Consult the DRIVER_userguide.pdf file to know about the arguments)"
	@echo "############################################################################"
	@echo "############################################################################"
	@echo "############################################################################"
	@echo "############################################################################"

clean: 
	@echo "ReLaTIve ARTICLE TEST DRIVER: deleting existing executable and output files..."
	@${RM} $(BIN) *.txt 
	@$(MAKE) clean -C $(dbdir) 
	@$(MAKE) clean -C $(utildir)
	@$(MAKE) clean -f Makefile_REL 







	
	
