Obj    = Obj/
Lib    = Obj/
Src    = Src/

LIB      = -L$(Lib) -lC -lm -lcomplex -lgreen -lnag -lM77 -lF77


###########################
# -pto: static link (sun c++)
TEMPLATE = -pto

###########################
# Definitions of the directorys containing the header files
# I2: complex definition if no "Complex" (with big "C") type is defined in the
#     standart lib 

I2 = -I$(Src)Complex/
INCLUDE = $(I2)

###########################
# Definition of the extern defined constants
# D2 put an underscore after the name of the Fortran or C function called from
#    C++ (sun c++)
# D3 to be used if the nag library is not installed in the system. The 
#    programms work as long as no function of the nag library is called

D2 = -DFortranCallWithUnderscore
#D3 = -DNoNag

###########################
# Definition of the flags
# F1 more warinig (sun c++)
# F2 debug

#F1 = +w
F2 = -O

CCFlags =  $(F1) $(F2) $(D1) $(D2) $(D3)

###########################
# Definition of the compilers and linker
#
# if g++ is used
#CPLUSPLUS = g++
# if CC is used
CPLUSPLUS = CC 

CCOMPILER  = $(CPLUSPLUS) $(TEMPLATE) $(CCFlags) $(INCLUDE) 
CCOMPILERO = $(CPLUSPLUS) $(TEMPLATE) $(CCFlags) $(INCLUDE)
LINKER     = $(CPLUSPLUS) $(TEMPLATE) $(CCFlags)

#FCOMPILER  = f77 -O
FCOMPILER  = f77 -g

PRECOMP    = /usr/ccs/lib/cpp

CCC     = $(CCOMPILER)  -c 
CCCO    = $(CCOMPILERO) -c
F77     = $(FCOMPILER)  -c
LDD     = $(LINKER)
CPP     = $(PRECOMP) $(INCLUDE) -P

lib     : $(Lib)libgreen.a
 
all     : lib cgreen fgreen

clean   : 
	rm $(Obj)*.o

GreenLib  =  $(Obj)Error.o  $(Obj)Object.o    $(Obj)Math.o     $(Obj)Vect.o  \
             $(Obj)Tensor.o $(Obj)Triplet.o   $(Obj)NAG.o      $(Obj)Green.o \
             $(Obj)integr.o $(Obj)Integrate.o $(Obj)Symmetry.o $(Obj)F77Green.o
          
ObjectDEP    = $(Src)Object.h     
ErrorDEP     = $(Src)Error.h  $(ObjectDEP)
MathDEP      = $(ErrorDEP)    $(Src)Math.h     $(Src)Const.h      $(Src)NAG.h
TripletDEP   = $(ErrorDEP)    $(Src)Triplet.h  $(Src)TripletTPL.h
VectDEP      = $(MathDEP)     $(Src)Vect.h  
TensorDEP    = $(VectDEP)     $(Src)Tensor.h
SymmDEP      = $(TensorDEP)   $(TripletDEP)    $(Src)Symmetry.h
GreenDEP     = $(SymmDEP)     $(Src)Green.h 
LibDEP       = $(GreenDEP) 


#Object files of the Library libgreen.a

$(Obj)Error.o    : $(ErrorDEP) $(Src)Error.c
	$(CCCO) $(Src)Error.c -o $@ 

$(Obj)Object.o    : $(ObjectDEP) $(Src)Object.c
	$(CCCO) $(Src)Object.c -o $@ 

$(Obj)Math.o        : $(MathDEP)   $(Src)Math.c
	$(CCCO) $(Src)Math.c -o $@ 

$(Obj)NAG.o        : $(MathDEP)   $(Src)NAG.c
	$(CCCO) $(Src)NAG.c -o $@ 

$(Obj)Vect.o        : $(VectDEP)   $(Src)Vect.c
	$(CCCO) $(Src)Vect.c -o $@ 

$(Obj)Triplet.o        : $(TripletDEP)   $(Src)Triplet.c
	$(CCCO) $(Src)Triplet.c -o $@ 

$(Obj)Tensor.o    : $(TensorDEP) $(Src)Tensor.c
	$(CCCO) $(Src)Tensor.c -o $@ 

$(Obj)Integrate.o    : $(IntDEP)   $(Src)Integrate.c
	$(CCCO) $(Src)Integrate.c -o $@ 

$(Src)integrR.f   :       $(Src)integr.f $(Src)integr.def
	$(CPP)  $(Src)integr.def $@ 

$(Obj)integr.o    :       $(Src)integrR.f
	$(F77) $(Src)integrR.f -o $@ 

$(Obj)Green.o     : $(GreenDEP)   $(Src)Green.c $(Src)Green.h
	$(CCCO) $(Src)Green.c -o $@ 

$(Obj)F77Green.o     : $(GreenDEP)   $(Src)F77Green.c $(Src)Green.h
	$(CCC) $(Src)F77Green.c -o $@ 

$(Obj)Symmetry.o      : $(SymmDEP)  $(Src)Symmetry.c
	$(CCC) $(Src)Symmetry.c -o $@ 

#TestFiles of the Library
#########################

all : lib fgreen cgreen

$(Obj)fgreen.o    :       $(Src)fgreen.f
	$(F77) $(Src)fgreen.f -o $@ 

$(Obj)cgreen.o    :       $(Src)cgreen.c $(LibDEP)
	$(CCC) $(Src)cgreen.c -o $@ 

$(Lib)libgreen.a : $(GreenLib)
	ar vcr $(Lib)libgreen.a  $(GreenLib)
	ranlib $(Lib)libgreen.a  


#Dipole-Dipoles Application
###########################

cgreen : $(Obj)cgreen.o Makefile $(Lib)libgreen.a 
	CC $(Obj)cgreen.o $(LIB) -o $@

fgreen : $(Obj)fgreen.o Makefile $(Lib)libgreen.a
	CC $(Obj)fgreen.o $(LIB) -o $@
