# --------------------------------------------------------------
#
# Works automatically for Sun,hp and Linux systems
#
# Usage:
#	gmake            [to create the executable crystal_ml]
#	gmake install	 [to install  it in the correct directory]
#	gmake clean	 [to clean the source directory]
#
#
# --------------------------------------------------------------
#
# System definition (architecture)
#
ARCH := $(shell ./../../xop_uname)
CPP = cpp


#************* PLATFORM DEPENDENT VARIABLES *****************
# libraries for sun5 
#
ifeq ($(ARCH),sun5)
FC = f77
FFLAGS =  -Bstatic
endif
#
# libraries for linux 
#
ifeq ($(ARCH),linux)
FC = g77
FFLAGS = -O  -Wall
endif
#
#-------------------------- libraries for darwin
#
ifeq ($(ARCH),darwin)
FC = g95
FFLAGS = -freal-loops 
endif

all: cryst_ml cryst_pp cryst_tt cryst_za

# mac:
# 	$(CPP) -P cryst_ml.F cryst_ml.fmac
# 	$(CPP) -P cryst_za.F cryst_za.fmac
# 	$(CPP) -P cryst_pp.F cryst_pp.fmac
# 	$(CPP) -P cryst_tt.F cryst_tt.fmac
# lahey:
# 	$(CPP) -P -Dlahey cryst_za.F cryst_za.flahey
# 	$(CPP) -P -Dlahey cryst_ml.F cryst_ml.flahey
# 	$(CPP) -P -Dlahey cryst_pp.F cryst_pp.flahey
# 	$(CPP) -P -Dlahey cryst_tt.F cryst_tt.flahey

cryst_pp:  cryst_pp.F
	$(FC) $(FFLAGS) -o cryst_pp cryst_pp.F iblank2.f crystal_fh.F

cryst_ml: cryst_ml.F  iblank2.f crystal_fh.F
	$(FC) $(FFLAGS) -o cryst_ml cryst_ml.F iblank2.f crystal_fh.F

cryst_tt: cryst_tt.F
	$(FC) $(FFLAGS) -o cryst_tt cryst_tt.F iblank2.f crystal_fh.F

cryst_za: cryst_za.o io_shadow.o vector.o iblank2.o
	$(FC) $(FFLAGS) -o cryst_za cryst_za.o \
	io_shadow.o  vector.o iblank2.o crystal_fh.F

.F.o:
	$(FC) $(FFLAGS) -c $<
.f.o:
	$(FC) $(FFLAGS) -c $<

clean: 
	/bin/rm -f *.trace *.o cryst_{ml,pp,tt,za}.dat \
	cryst_{ml,pp,tt,za}.info  cryst_{ml,pp,tt,za} \
	cryst_?? *.flahey *.fmac

install:
	cp cryst_ml ./../../bin.$(ARCH)/cryst_ml
	cp cryst_pp ./../../bin.$(ARCH)/cryst_pp
	cp cryst_tt ./../../bin.$(ARCH)/cryst_tt
	cp cryst_za ./../../bin.$(ARCH)/cryst_za

