GPPflags =   -ansi -lg2c -lm -Xlinker -rpath -Xlinker -lpthread 
GPPnl = g++ -c  -Wall -ansi
GPPnlnoansi = g++ -c  -Wall # for use with corr.C since -ansi doesn't like the function lgamma() in the file math.h
F77 = g77 -c -ffree-form  # for Fortran code
F77noff = g77 -c   # for Fortran code, rkbesl doesn't like -ffree-form
DEBUG_FLAG =  -O2 -g # include -g if want to be able to debug
BASE_FILES = mat_pp.h base.h copy.h

# DEBUG_FLAG should be -g to enable debugging, -O2 for optimization
# note that including -g does not seem to slow things down much
# -fsave-memoized -fmemoize-lookups don't seem to help speed code


# executable
nsgp_binom : $(BASE_FILES) regrmod.o generic_functions.o dataset.o parm.o cov_mat.o permtools.o chain.o gasdev.o gsfct.o smbfct.o covariates.o ran1.o transform.o density.o corr.o  rkbesld.o
	g++  -onsgp_binom  regrmod.o generic_functions.o dataset.o parm.o cov_mat.o permtools.o chain.o gasdev.o gsfct.o smbfct.o covariates.o ran1.o transform.o density.o corr.o rkbesld.o $(GPPflags)

# object files
regrmod.o : $(BASE_FILES) regrmod.C dataset.h covariates.h chain.h 
	$(GPPnl) -o regrmod.o regrmod.C $(DEBUG_FLAG)
# contains main

dataset.o : $(BASE_FILES) dataset.C dataset.h covariates.h density.h cov_mat.h permtools.h
	$(GPPnl)  dataset.C $(DEBUG_FLAG)
# likelihood stuff

gsfct.o: $(BASE_FILES) gsfct.f  #.real
	$(F77) gsfct.f -ogsfct.o $(DEBUG_FLAG)
# numeric factorization

smbfct.o: $(BASE_FILES) smbfct.f
	$(F77) smbfct.f $(DEBUG_FLAG)
# symbolic factorization - setting up of sparse matrix structure

covariates.o: $(BASE_FILES) covariates.C covariates.h permtools.h
	$(GPPnl) covariates.C $(DEBUG_FLAG)
# sets up basic covariate stuff - distances, re-ordering, etc.

generic_functions.o : $(BASE_FILES) generic_functions.C generic_functions.h 
	$(GPPnl) generic_functions.C $(DEBUG_FLAG)
# basic generic math and conversion functions

permtools.o: $(BASE_FILES) permtools.C permtools.h 
	$(GPPnl) permtools.C $(DEBUG_FLAG)
# permutation stuff

gasdev.o: $(BASE_FILES) gasdev.C gasdev.h  ran1.h
	$(GPPnl) gasdev.C $(DEBUG_FLAG)
# rnorm(0,1) based on Numerical Recipes in C algorithm

ran1.o: $(BASE_FILES) ran1.C ran1.h
	$(GPPnl) ran1.C $(DEBUG_FLAG)
# runif(0,1) via Numerical Recipes in C algorithm

transform.o: $(BASE_FILES) transform.C transform.h 
	$(GPPnl) transform.C $(DEBUG_FLAG)
# code for various transformations

density.o: $(BASE_FILES) density.C density.h 
	$(GPPnl) density.C $(DEBUG_FLAG)
# calculates various prob density functions

chain.o: $(BASE_FILES) chain.C chain.h parm.h cov_mat.h dataset.h transform.h  covariates.h ran1.h
	$(GPPnl) chain.C $(DEBUG_FLAG)
# initializes and steps through chain, reports results

cov_mat.o: $(BASE_FILES) cov_mat.C cov_mat.h covariates.h gasdev.h corr.h generic_functions.h
	$(GPPnl) cov_mat.C $(DEBUG_FLAG)
# covariance matrix calculations

parm.o: $(BASE_FILES) parm.C parm.h cov_mat.h density.h ran1.h dataset.h gasdev.h transform.h covariates.h
	$(GPPnl) parm.C $(DEBUG_FLAG)
# parameter code and MCMC proposals and updating

corr.o: $(BASE_FILES) corr.C corr.h
	$(GPPnlnoansi) corr.C $(DEBUG_FLAG)
# code for calculating correlation functions

rkbesld.o: rkbesld.f
	$(F77noff) rkbesld.f $(DEBUG_FLAG)
# Bessel K function code used by Matern correlation function

clean :
	rm nsgp_binom regrmod.o generic_functions.o dataset.o parm.o cov_mat.o permtools.o chain.o gasdev.o gsfct.o smbfct.o covariates.o ran1.o transform.o density.o corr.o rkbesld.o






