
# --------------------------------------------------------------
#
#	gmake
#	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 -O 
LDFLAGS = -lV77
endif
#
# libraries for linux 
#
ifeq ($(ARCH),linux)
FC = gfortran
FFLAGS = -O 
endif
#
# libraries for sgi 
#
ifeq ($(ARCH),irix)
FC = f77
FFLAGS = -O 
endif
#
#-------------------------- libraries for darwin
#
ifeq ($(ARCH),darwin)
FC = gfortran
FFLAGS =  
endif
#**************************************************************

.SUFFIXES:
.SUFFIXES: .c .f .F .o .do

all: us 

#  US executables (elliptical undulator)
us : us.o brighte.o hunt.o
	$(FC) -o $@ us.o brighte.o hunt.o $(LDFLAGS)

usd : $(OBJD_US) $(LIBNAME)
	$(LD) -o $@ $(LDFLAGS) $(OBJD_US) $(LIBRARIES)

#  TBRIGHT executables
tb : $(OBJ_TB) $(LIBNAME)
	$(LD) -o $@ $(LDFLAGS) $(OBJ_TB) $(LIBRARIES)

tbd : $(OBJD_TB) $(LIBNAME)
	$(LD) -o $@ $(LDFLAGS) $(OBJD_TB) $(LIBRARIES)

#  Fortran files
.f.o:
	$(FC) -c $(FFLAGS) $(INCLUDES) $<
.F.o:
	$(FC) -c $(FFLAGS) $(INCLUDES) $<
.f.do:
	$(FC) -c $(FFLAGSD) $(INCLUDES) -o $@ $<

#  Clean up
clean:
	$(RM) -rf us usd $(OBJ_US) $(OBJD_US) core *~ *.o *.trace

install:
	/bin/cp us ../../../bin.$(ARCH)/us
