#  Main body of the installation makefile for the WSMP stub

#  N. Gould, D. Orban and Ph. L. Toint.
#  This version: 2024-11-14

#  include standard GALAHAD makefile definitions

include $(GALAHAD)/src/makedefs/definitions

#  Libraries used

LIBS = -lgalahad $(WSMP) $(LAPACK) $(BLAS)
PLIBS = $(LIBS) -lgalahad_problem

#  compilation agenda

BASICZ = blas lapack symbols dummy blas_inter lapack_inter

WSMPS = $(BASICSZ) $(WLGS)(wsmp.o)
WSMPD = $(BASICSZ) $(WLGD)(wsmp.o)
WSMPQ = $(BASICSZ) $(WLGQ)(wsmp.o)
WSMPS64 = $(BASICSZ) $(WLGS64)(wsmp.o)
WSMPD64 = $(BASICSZ) $(WLGD64)(wsmp.o)
WSMPQ64 = $(BASICSZ) $(WLGQ64)(wsmp.o)

WSMPST = $(WSMPS) $(OBJ)/wsmpt.o
WSMPDT = $(WSMPD) $(OBJ)/wsmpt.o
WSMPQT = $(WSMPQ) $(OBJ)/wsmpt.o

RWSMPST = $(OBJ)/wsmpt.o -L$(OBJ) $(LIBS)
RWSMPDT = $(OBJ)/wsmpt.o -L$(OBJ) $(LIBS)
RWSMPQT = $(OBJ)/wsmpt.o -L$(OBJ) $(LIBS)

#  wsmp

wsmp_silent: wsmp_$(PRECIS)
wsmp: wsmp_$(PRECIS)
	@printf ' %-21s\n' "GALAHAD: $(WSMP) ($(PRECIS) $(SUCC)"
wsmp_single: $(WSMPS)
	$(RANLIB) $(WLGS)
wsmp_double: $(WSMPD)
	$(RANLIB) $(WLGD)
wsmp_quadruple: $(WSMPQ)
	$(RANLIB) $(WLGQ)
wsmp_single_64: $(WSMPS64)
	$(RANLIB) $(WLGS64)
wsmp_double_64: $(WSMPD64)
	$(RANLIB) $(WLGD64)
wsmp_quadruple_64: $(WSMPQ64)
	$(RANLIB) $(WLGQ64)

#  tests

wsmpst: $(WSMPST)
	echo " Exhaustive test of subroutine interface to wsmp"
	cd ../wsmp ; $(FORTRAN) $(RUNFFLAGSOMP) $(SPECIAL) -o run_wsmp \
                         $(RWSMPST)
	- ../wsmp/run_wsmp > ../wsmp/wsmpt.output 2>&1
	cat ../wsmp/wsmpt.output
	rm ../wsmp/run_wsmp

wsmpdt: $(WSMPDT)
	echo " Exhaustive test of subroutine interface to wsmp"
	cd ../wsmp ; $(FORTRAN) $(RUNFFLAGSOMP) $(SPECIAL) -o run_wsmp \
                         $(RWSMPDT)
	- ../wsmp/run_wsmp > ../wsmp/wsmpdt.output 2>&1
	cat ../wsmp/wsmpdt.output
#	- ../wsmp/run_wsmp
	rm ../wsmp/run_wsmp

wsmpqt: $(WSMPQT)
	echo " Exhaustive test of subroutine interface to wsmp"
	cd ../wsmp ; $(FORTRAN) $(RUNFFLAGSOMP) $(SPECIAL) -o run_wsmp \
                         $(RWSMPQT)
	- ../wsmp/run_wsmp > ../wsmp/wsmpqt.output 2>&1
	cat ../wsmp/wsmpqt.output
	rm ../wsmp/run_wsmp

#  blas and lapack generic packages and interfaces

blas:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            blas_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

lapack:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            lapack_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

symbols:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            symbols_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

dummy:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            dummy_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

blas_inter:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            blas_inter_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

lapack_inter:
	( cd ../../general ; $(MAKE) -f $(GALAHAD)/makefiles/$(VERSION) \
            lapack_inter_silent PRECIS=$(PRECIS) PWD=$(PWD)/../../general )

#  individual compilations

wsmp.o: $(WLG)(wsmp.o)

$(WLG)(wsmp.o): ../../dum/wsmp.F90
	@printf ' %-9s %-15s\t\t' "Compiling" "wsmp  "
	$(CP) ../../dum/wsmp.F90 $(OBJ)/wsmp.F90
	cd $(OBJ); $(FORTRAN) -o wsmp.o $(FFLAGS) wsmp.F90
	cd $(OBJ); $(WARR) wsmp.o ; $(RM) wsmp.F90 wsmp.o
	$(RANLIB) $(WLG)
	@printf '[ OK ]\n'

#  test programs

wsmpt.o: $(OBJ)/wsmpt.o

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

#  book keeping

clean:
	@printf ' %-9s\t\t' "Cleaning"
	$(RM) $(WLG) $(OBJ)/wsmps.o $(OBJ)/wsmpt.o
	@printf '[ OK ]\n'

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