#  Main body of the installation makefile for the GALAHAD SILS package

#  Nick Gould, for GALAHAD productions
#  This version: 2021-04-29

#  include standard GALAHAD makefile defaults before package-specifics

include $(GALAHAD)/src/makedefs/defaults

#  ===========================================================================
#  ====================  package-dependent parts  ============================
#  ===========================================================================

#  package name

package = sils
PACKAGE = SILS

#  auxiliary packages that current package depends on (prepend with make_)

DEPENDENCIES = make_dummy make_zd11 make_smt make_ma27

#  other packages that depend on package

DEPENDS = ir sls psls mdchl lancelot_types qpd fdc superb

#  auxiliary packages that the C interface to the current package depends
#  on (prepend with make_ciface_)

CDEPENDENCIES = make_ciface_common

#  other C interface packages that depend on current interface package

CDEPENDS = sls psls mdchl

#  auxiliary packages that are needed for tests (prepend with make_)

TESTDEPS = make_sort make_lmt make_qpt make_space make_specfile

#  tests to be performed (preprend with test_)

TESTS = test_full test_cutest

#  CUTEst example for tests

CUTEST_EXAMPLE = QPBAND.SIF

#  ===========================================================================
#  =================  end of package-dependent parts  ========================
#  ===========================================================================

#  include standard GALAHAD makefile definitions

include $(GALAHAD)/src/makedefs/definitions

#  include compilation and run instructions

include $(GALAHAD)/src/makedefs/instructions

#  non-standard package compilation

$(package).o: $(LG)($(package)_$(PRECIS).o)

$(LG)($(package)_$(PRECIS).o): ../$(package)/$(package).F90
	@printf ' %-9s %-15s\t\t' "Compiling" "$(package)"
	$(CP) ../$(package)/$(package).F90 $(OBJ)/$(package).F90
	cd $(OBJ); $(FORTRAN) -o $(package)_$(PRECIS).o $(FFLAGS) \
                     $(package).F90 \
                || ( printf ' %-26s' "=> Disabling optimization " ; \
                   $(FORTRAN) -o $(package)_$(PRECIS).o \
                     $(FFLAGSN) $(package).F90 )
	cd $(OBJ); $(ARR) $(package)_$(PRECIS).o; \
                     $(RM) $(package).F90 $(package)_$(PRECIS).o
	$(MVMODS)
	@printf '[ OK ]\n'

#  package C interface compilation

$(package)_ciface.o: $(LG)($(package)_$(PRECIS).o) \
                     $(CLG)($(package)_ciface_$(PRECIS).o)

$(CLG)($(package)_ciface_$(PRECIS).o): ../$(package)/C/$(package)_ciface.F90
	@printf ' %-9s %-15s\t\t' "Compiling" "$(package)_ciface"
	$(CP) ../$(package)/C/$(package)_ciface.F90 $(OBJ)/$(package)_ciface.F90
	cd $(OBJ); $(FORTRAN) -o $(package)_ciface_$(PRECIS).o \
           $(FFLAGSS) $(package)_ciface.F90 \
            || ( printf ' %-26s' "=> Disabling optimization " ; \
           $(FORTRAN) -o $(package)_ciface_$(PRECIS).o \
             $(FFLAGSN) $(package)_ciface.F90 )
	cd $(OBJ); $(CARR) $(package)_ciface_$(PRECIS).o
	cd $(OBJ); $(RM) $(package)_ciface.F90 $(package)_ciface_$(PRECIS).o
	$(MVMODS)
	@printf '[ OK ]\n'

#  package python interface compilation

$(package)_pyiface.o: $(LG)($(package)_$(PRECIS).o) \
                        $(CLG)($(package)_ciface_$(PRECIS).o) \
                        $(PYLG)($(package)_pyiface.o)

$(PYLG)($(package)_pyiface.o): ../$(package)/Python/$(package)_pyiface.c
	@printf ' %-9s %-15s\t\t' "Compiling" "$(package)_pyiface"
	$(SED) -f $(CISEDS) ../$(package)/Python/$(package)_pyiface.c \
           > $(OBJ)/$(package)_pyiface.c
	cd $(OBJ); $(CC) -o $(package)_pyiface.o $(CFLAGS) \
           $(package)_pyiface.c $(PYINCLUDES) \
            || ( printf ' %-26s' "=> Disabling optimization " ; \
           $(CC) -o $(package)_pyiface.o $(CFLAGSN) $(package)_pyiface.c \
            $(PYINCLUDES) )
	cd $(OBJ); $(PYARR) $(package)_pyiface.o
	cd $(OBJ); $(RM) $(package)_pyiface.c
	$(PYRMARFILES) $(PYDEPENDS)
	cd $(OBJ); CC=$(CC) FORTRAN=$(FORTRAN) OPTIMIZATION=$(OPTIMIZATION) \
                   SHARED=$(SHARED) DLEXT=$(DLEXT) LOADALL=$(LOADALL) \
                   LOADNONE=$(LOADNONE) \
                   $(BINSHELL) $(GALAHAD)/bin/create_shared
#	export ARCH=$(VERSION) ; pip install $(GALAHAD)/bin/
	$(MKDIR) -p  $(PYSITEPACKDIR)/galahad
	cd $(OBJ) ; $(CC) $(SHARED) $(OPTIMIZATION) -pthread \
          -Wl,-O1  -Wl,-Bsymbolic-functions $(OBJ)/$(package)_pyiface.o \
          -L$(OBJ)/shared -lgalahad_py -lgalahad_c -lhsl_c \
          -lgalahad -lgalahad_cutest_dummy $(HSL) $(MKL_PARDISO) \
          $(PARDISO) $(WSMP) $(PASTIX) $(MUMPS) $(MPI) $(UMFPACK) \
          $(METIS4ND) $(METIS5ND) $(LAPACK) $(BLAS) -lgfortran \
          -o $(PYSITEPACKDIR)/galahad/$(package).$(SOABI).$(DLEXT) \
          -Wl,-rpath=$(OBJ)/shared $(MOMP)
	cd $(OBJ); $(RM) $(package)_pyiface.o
	@printf '[ OK ]\n'

#  test programs for specification document

$(package)s.o: $(OBJ)/$(package)s_$(PRECIS).o

$(OBJ)/$(package)s_$(PRECIS).o: ../$(package)/$(package)s.f90
	@printf ' %-9s %-15s\t\t' "Compiling" "$(package)s  "
	$(SED) -f $(SEDS) \
           ../$(package)/$(package)s.f90 > $(OBJ)/$(package)s.f90
	cd $(OBJ) ; $(FORTRAN) -o $(package)s_$(PRECIS).o \
                      $(FFLAGS) $(package)s.f90
	rm $(OBJ)/*.f90
	@printf '[ OK ]\n'

#  comprehensive test programs

$(package)t.o: $(OBJ)/$(package)t_$(PRECIS).o

$(OBJ)/$(package)t_$(PRECIS).o: ../$(package)/$(package)t.F90
	@printf ' %-9s %-15s\t\t' "Compiling" "$(package)t  "
	$(CP) ../$(package)/$(package)t.F90 $(OBJ)/$(package)t.F90
	cd $(OBJ) ; $(FORTRAN) -o $(package)t_$(PRECIS).o \
                      $(FFLAGSS) $(package)t.F90
	rm $(OBJ)/*.F90
	@printf '[ OK ]\n'

#  CUTEst/AMPL interfaces

use$(package).o: $(CULG)(use$(package)_$(PRECIS).o)

$(CULG)(use$(package)_$(PRECIS).o): ../$(package)/use$(package).F90
	@printf ' %-9s %-15s\t\t' "Compiling" "use$(package)   "
	$(CP) ../$(package)/use$(package).F90 $(OBJ)/use$(package).F90
	cd $(OBJ); \
          $(FORTRAN) -o use$(package)_$(PRECIS).o \
            $(FFLAGSOMP) use$(package).F90 \
                || ( printf ' %-26s' "=> Disabling optimization " ; \
                   $(FORTRAN) -o use$(package)_$(PRECIS).o \
                     $(FFLAGSN) use$(package).F90 )
	cd $(OBJ); $(CUARR) use$(package)_$(PRECIS).o ; \
                   $(RM) use$(package).F90 use$(package)_$(PRECIS).o
	$(RMOBFILE) run$(package)_sif.o
	$(MVMODS)
	@printf '[ OK ]\n'

#  include required package intermediaries

include $(GALAHAD)/src/makedefs/intermediaries
