# Compile BindingEnergy


.PHONY: clean exit 


# Choose a compiler (no spaces after compiler name, hence #):
FORT = gfortran#           # Use GNU Fortran compiler (reads ~3x slower from disc than ifort!)
#FORT = g95#                # Use g95 Fortran compiler
#FORT = ifort#              # Use Intel Fortran compiler

#WARN = yes#                # to compile with compile-time warnings
#RUNCHECK = yes#            # to compile with runtime-check options
#OPTIMISE = yes#            # to compile with some extra run-time optimisation (sets RUNCHECK=no)



#General:
CFLAGS = -O2
LFLAGS = 



# Directories for the source, object, module, libary and executable files:
SRCDIR = src
OBJDIR = obj
MODDIR = mod
EXEDIR = .




# gfortran options:
ifeq ($(FORT),gfortran)
   ifeq ($(RUNCHECK),yes)
      CFLAGS = -O0 -fcheck=all
   endif
   CFLAGS += -fbacktrace
   ifeq ($(OPTIMISE),yes)
      CFLAGS = -O3 
   endif
   ifeq ($(WARN),yes)
      CFLAGS += -Wall
   endif
   CFLAGS += -I$(MODDIR) -J$(MODDIR)
   CFLAGS += -fmax-errors=10
endif



#g95 options:
ifeq ($(FORT),g95)
   ifeq ($(RUNCHECK),yes)
      CFLAGS = -O0 -fbounds-check -ftrace=full
   endif

   ifeq ($(WARN),yes)
      CFLAGS += -Wall -Wextra -Wno=102,112,136,140,165
   endif

   CFLAGS += -I$(MODDIR) -fmod=$(MODDIR)
endif



# ifort options:
ifeq ($(FORT),ifort)
   ifeq ($(RUNCHECK),yes)
      CFLAGS = -O0 -check all -check noarg_temp_created
   endif
   CFLAGS += -traceback 
   ifeq ($(OPTIMISE),yes)
      CFLAGS = -O3
   endif
   ifeq ($(WARN),yes)
      CFLAGS += -warn all
   endif
   CFLAGS += -vec-report0
   CFLAGS += -module $(MODDIR) -I$(MODDIR)

   CFLAGS += -nogen-interfaces  # For ifort v.11
endif











STDOBJ = $(OBJDIR)/binding_energy.o

$(OBJDIR)/%.o: $(SRCDIR)/%.f90 Makefile
	$(FORT) $(CFLAGS) -c $< -o $@


all:

exit:

all: example_program



example_program: $(STDOBJ) ${OBJDIR}/example_program.o
	$(FORT) -o $(EXEDIR)/example_program $(LFLAGS) $(STDOBJ) ${OBJDIR}/example_program.o



clean:
	rm -f $(OBJDIR)/*.o $(MODDIR)/*.mod example_program

