#  Main body of the installation makefile for the SIFDECODE select package

#  N. Gould, D. Orban and Ph. L. Toint.
#  This version: 05 XIII 2012

SHELL = /bin/$(BINSHELL)

#  compiler flags

FFLAGS    = $(BASIC) $(OPTIMIZATION) $(DEBUG) $(MODULES) $(F90) $(USUAL)
FFLAGSS   = $(BASIC) $(OPTIMIZATION) $(DEBUG) $(MODULES) $(F90) $(SPECIAL)
FFLAGSN   = $(BASIC) $(NOOPTIMIZATION) $(DEBUG) $(MODULES) $(F90)
FFLAGS77  = $(BASIC) $(OPTIMIZATION) $(DEBUG) $(MODULES) $(F77) $(USUAL)
FFLAGS77N = $(BASIC) $(NOOPTIMIZATION) $(DEBUG) $(MODULES) $(F77)
FFLAGS77S = $(BASIC) $(OPTIMIZATION) $(DEBUG) $(MODULES) $(F77) $(SPECIAL)
RUNFFLAGS =          $(OPTIMIZATION) $(DEBUG) $(MODULES)

#  names of random libraries

LS  =
LSS =
LSD =

#  Libraries used

LIBS =
PLIBS = $(LIBS)

#  Archive manipulation strings

ARR = $(AR) $(ARREPFLAGS) $(LS)
RMARFILE = $(SIFDECODER)/bin/rmarfile $(AR) $(GREP) $(LS)
RMOBFILE = $(SIFDECODER)/bin/rmobfile $(RM) $(OBJ)

#  sed scripts

#  compilation agenda

SELECTS = $(OBJS)/slct.o $(OBJS)/clsf.o
SELECTD = $(OBJD)/slct.o $(OBJD)/clsf.o

SUCC = precision version) compiled successfully

#  main compilations and runs

all: basics

#  basic packages

select_silent: select_silent_$(PRECIS)
select_silent_single: $(SELECTS)
select_silent_double: $(SELECTD)

select: select_$(PRECIS)
	@printf ' %-21s\n' "select: packages ($(PRECIS) $(SUCC)"
select_single: $(SELECTS)
select_double: $(SELECTD)

#  individual compilations

slct: $(OBJ)/slct.o

$(OBJ)/slct.o: ../select/slct.f
	@printf ' %-9s %-15s\t\t' "Compiling" "slct"
	$(SED) -f $(SEDS) ../select/slct.f > $(OBJ)/slct.f
	cd $(OBJ); $(FORTRAN) -o slct.o $(FFLAGS77) slct.f \
                || ( printf ' %-26s' "=> Disabling optimization " ; \
                   $(FORTRAN) -o slct.o $(FFLAGS77N) slct.f )
	cd $(OBJ); $(FORTRAN) -o slct $(RUNFFLAGS) slct.o
	cd $(OBJ); $(RM) slct.f slct.o
	@printf '[ OK ]\n'

clsf: $(OBJ)/clsf.o

$(OBJ)/clsf.o: ../select/clsf.f
	@printf ' %-9s %-15s\t\t' "Compiling" "clsf"
	$(SED) -f $(SEDS) ../select/clsf.f > $(OBJ)/clsf.f
	cd $(OBJ); $(FORTRAN) -o clsf.o $(FFLAGS77) clsf.f \
                || ( printf ' %-26s' "=> Disabling optimization " ; \
                   $(FORTRAN) -o clsf.o $(FFLAGS77N) clsf.f )
	cd $(OBJ); $(FORTRAN) -o clsf $(RUNFFLAGS) clsf.o
	cd $(OBJ); $(RM) clsf.f clsf.o
	@printf '[ OK ]\n'

#  book keeping

clean:
	@printf ' %-9s\t\t' "Cleaning"
	$(RM) $(OBJ)/*
	@printf '[ OK ]\n'

cleanall:
	@printf ' %-14s\t\t' \
          "Removing all $(PRECIS) precision object and module files"
	$(RM) $(OBJ)/* $(MOD)/*
	@printf '[ OK ]\n'
