
#===============================
# espresso
#===============================
#
# Makefile for plugins
#

include ../make.sys
include plugins_list
#
# MAIN target
#

EXTLIBS=liblapack libblas libiotk

##########################################################
# LD1
###########################################################
ld1:  uncompress-ld1
	if test -d ../atomic; then \
	cd ../atomic; $(MAKE) all; cd ../bin; ln -fs ../atomic/src/ld1.x . ; fi
	touch make-ld1
uncompress-ld1: touch-dummy
	@(if test ! -s ../archive/$(LD1).tar.gz && test ! -d ../atomic ; then \
	wget -O ../archive/$(LD1).tar.gz $(LD1_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(LD1).tar.gz $(LD1_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download ld1. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
        echo "*** $(LD1).tar.gz from $(LD1_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../atomic; then \
	(gzip -dc ../archive/$(LD1).tar.gz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-ld1
##########################################################
# XSpectra
###########################################################
xspectra:  uncompress-xspectra
	if test -d ../XSpectra; then \
	cd ../XSpectra; $(MAKE) all; cd ../bin; ln -fs ../XSpectra/src/xspectra.x . ; fi
	touch make-xspectra
uncompress-xspectra: touch-dummy
	@(if test ! -s ../archive/$(XSPECTRA).tar.gz && test ! -d ../XSpectra ; then \
	wget -O ../archive/$(XSPECTRA).tar.gz $(XSPECTRA_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(XSPECTRA).tar.gz $(XSPECTRA_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download xspectra. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(XSPECTRA).tar.gz from $(XSPECTRA_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../XSpectra; then \
	(gzip -dc ../archive/$(XSPECTRA).tar.gz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-xspectra
##########################################################
# PWCOND
###########################################################
pwcond:  uncompress-pwcond
	if test -d ../PWCOND; then \
	cd ../PWCOND; $(MAKE) all; cd ../bin; ln -fs ../PWCOND/src/pwcond.x . ; fi
	touch make-pwcond
uncompress-pwcond: touch-dummy
	@(if test ! -s ../archive/$(PWCOND).tar.gz && test ! -d ../PWCOND ; then \
	wget -O ../archive/$(PWCOND).tar.gz $(PWCOND_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(PWCOND).tar.gz $(PWCOND_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download pwcond. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(PWCOND).tar.gz from $(PWCOND_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../PWCOND; then \
	(gzip -dc ../archive/$(PWCOND).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(PWCOND) PWCOND) ; fi 
	touch uncompress-pwcond
##########################################################
# NEB
###########################################################
neb:  uncompress-neb
	if test -d ../NEB; then \
	cd ../NEB; $(MAKE) all; cd ../bin; ln -fs ../NEB/src/neb.x . ; fi
	touch make-neb
uncompress-neb: touch-dummy
	@(if test ! -s ../archive/$(NEB).tar.gz && test ! -d ../NEB ; then \
	wget -O ../archive/$(NEB).tar.gz $(NEB_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(NEB).tar.gz $(NEB_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download neb. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(NEB).tar.gz from $(NEB_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../NEB; then \
	(gzip -dc ../archive/$(NEB).tar.gz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-neb
##########################################################
# TDDFPT
###########################################################
tddfpt:  uncompress-tddfpt
	if test -d ../TDDFPT; then \
	cd ../TDDFPT; $(MAKE) all; cd ../bin; ln -fs ../TDDFPT/src/turbo_lanczos.x . ; \
	ln -fs ../TDDFPT/tools/turbo_spectrum.x . ; fi
	touch make-tddfpt
uncompress-tddfpt: touch-dummy
	@(if test ! -s ../archive/$(TDDFPT).tar.gz && test ! -d ../TDDFPT ; then \
	wget -O ../archive/$(TDDFPT).tar.gz $(TDDFPT_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(TDDFPT).tar.gz $(TDDFPT_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download tddfpt. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(TDDFPT).tar.gz from $(TDDFPT_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../TDDFPT; then \
	(gzip -dc ../archive/$(TDDFPT).tar.gz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-tddfpt
##########################################################
# PHonon
###########################################################
phonon:  uncompress-phonon
	if test -d ../PHonon; then \
	cd ../PHonon; $(MAKE) all; cd ../bin; \
	ln -fs ../PHonon/PH/ph.x . ; \
	ln -fs ../PHonon/PH/dynmat.x . ; \
	ln -fs ../PHonon/PH/matdyn.x . ; \
	ln -fs ../PHonon/PH/q2r.x . ; \
	ln -fs ../PHonon/PH/q2qstar.x . ; \
	ln -fs ../PHonon/PH/lambda.x . ; \
	ln -fs ../PHonon/PH/fqha.x . ; \
	ln -fs ../PHonon/Gamma/phcg.x . ; \
	ln -fs ../PHonon/D3/d3.x . ; \
	fi
	touch make-phonon
uncompress-phonon: touch-dummy
	@(if test ! -s ../archive/$(PHONON).tar.gz && test ! -d ../PHonon ; then \
	wget -O ../archive/$(PHONON).tar.gz $(PHONON_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(PHONON).tar.gz $(PHONON_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download phonon. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(PHONON).tar.gz from $(PHONON_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../PHonon; then \
	(gzip -dc ../archive/$(PHONON).tar.gz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-phonon
##########################################################
# GIPAW
###########################################################
#gipaw:  uncompress-gipaw configure-gipaw
gipaw:  download-gipaw configure-gipaw
	if test -d ../GIPAW; then \
	cd ../GIPAW; $(MAKE) all; cd ../bin; ln -fs ../GIPAW/bin/gipaw.x . ; fi
	touch make-gipaw
download-gipaw:
	@echo "GIPAW 5 is not ready for distribution. Donwloading the development version."
	@echo "This version is not bug free. Please, check if your results make sense."
	svn checkout http://qeforge.qe-forge.org/svn/qe-gipaw/trunk ../GIPAW
uncompress-gipaw: touch-dummy
	@(if test ! -s ../archive/$(GIPAW).tar.gz && test ! -d ../GIPAW ; then \
	wget -O ../archive/$(GIPAW).tar.gz $(GIPAW_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(GIPAW).tar.gz $(GIPAW_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download qe-gipaw. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(GIPAW).tar.gz from $(GIPAW_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../GIPAW; then \
	(gzip -dc ../archive/$(GIPAW).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(GIPAW) GIPAW) ; fi 
	touch uncompress-gipaw
configure-gipaw: touch-dummy
	cd ../GIPAW ; \
	./configure --with-qe-source=${TOPDIR}
	touch ./configure-gipaw
##########################################################
# EPW
###########################################################
epw: 
	if test -d ../EPW; then \
	cd ../EPW; $(MAKE) all; cd ../bin; ln -fs ../EPW/bin/epw.x . ; fi
	touch make-epw

###########################################################
# wannier90
###########################################################

w90: uncompress-w90 configure-w90
	if test -d ../W90; then \
	cd ../W90; $(MAKE) all; cd ../bin; ln -fs ../W90/wannier90.x . ; fi
	-(cd ../bin; ln -fs ../W90/wannier90.x .)
	touch make-w90
uncompress-w90: touch-dummy
	@(if test ! -s ../archive/$(W90).tar.gz && test ! -d ../W90 ; then \
	wget -O ../archive/$(W90).tar.gz $(W90_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(W90).tar.gz $(W90_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download wannier90. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(W90).tar.gz from $(W90_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../W90; then \
	(gzip -dc ../archive/$(W90).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(W90) W90) ; fi 
	touch uncompress-w90

configure-w90: touch-dummy
	cd ../W90 ; \
	if (test -e ../install/make_wannier90.sys) || (test -d ../W90); then \
	(cp ../install/make_wannier90.sys ../W90/make.sys); fi 
	touch ./configure-w90
###########################################################
# WANT
###########################################################

want: extlibs uncompress-want configure-want
	if test -d ../WANT; then \
	cd ../WANT; $(MAKE) all; fi
#	- ( cd ../bin ; ln -sf ../WANT/bin/* . ) 
	touch ./make-want
uncompress-want: touch-dummy
	@(if test ! -s ../archive/$(WANT)-base.tar.gz && test ! -d ../WANT ; then \
	wget -O ../archive/$(WANT)-base.tar.gz $(WANT_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(WANT)-base.tar.gz $(WANT_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download want. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(WANT)-base.tar.gz from $(WANT_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../WANT; then \
	(gzip -dc ../archive/$(WANT)-base.tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(WANT) WANT) ; fi 
	touch uncompress-want

configure-want: touch-dummy
	cd ../WANT ; \
	./conf/configure \
	--with-external-iotk \
	IOTK_LIBS="-L../../S3DE/iotk/src -liotk" \
	IOTK_INCLUDE="$(MOD_FLAG)../../S3DE/iotk/src" \
	CC="$(CC)" \
	F90="$(F90)" \
	MPIF90="$(MPIF90)" \
	F90FLAGS="$(F90FLAGS) $($PRE_FDFLAGS) $(FDFLAGS) $(IFLAGS) $(MODFLAGS)" \
	F77="$(F77)" \
	FFLAGS="$(FFLAGS)" \
	FFLAGS_NOOPT="$(FFLAGS_NOOPT)" \
	LD="$(LD)" \
	LDFLAGS="$(LDFLAGS)" \
	AR="$(AR)" \
	ARFLAGS="$(ARFLAGS)" \
	RANLIB="$(RANLIB)" \
	DFLAGS="$(DFLAGS)" \
	FDFLAGS="$(DFLAGS)" \
	LAPACK_LIBS="$(LAPACK_LIBS)" \
	BLAS_LIBS="$(BLAS_LIBS)" \
	FFT_LIBS="$(FFT_LIBS)" 
	touch ./configure-want

###################################################
# YAMBO
###################################################

yambo: extlibs uncompress-yambo configure-yambo
	if test -d ../YAMBO; then \
	cd ../YAMBO; $(MAKE) all; fi
	touch ./make-yambo
uncompress-yambo: touch-dummy
	@(if test ! -s ../archive/$(YAMBO).tar.gz && test ! -d ../YAMBO ; then \
	wget -O ../archive/$(YAMBO).tar.gz $(YAMBO_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(YAMBO).tar.gz $(YAMBO_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download yambo. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(YAMBO).tar.gz from $(YAMBO_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../YAMBO; then \
	(gzip -dc ../archive/$(YAMBO).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(YAMBO) YAMBO) ; fi 
	touch uncompress-yambo

configure-yambo: touch-dummy
	cd ../YAMBO ; \
	./configure --with-blas="$(BLAS_LIBS)" \
	--with-lapack="$(LAPACK_LIBS)" \
	--with-iotk="$(TOPDIR)/iotk" \
	PFC="$(MPIF90)" \
	FC="$(LD)" \
	FCFLAGS="$(F90FLAGS) $(FDFLAGS) $(IFLAGS) $(MODFLAGS) $(FFLAGS_NOMAIN)"
	F77="$(F77)" \
	FFLAGS="$(FFLAGS)"
	AR="$(AR)" \
	ARFLAGS="$(ARFLAGS)" 
	touch ./configure-yambo
touch-dummy:
	$(dummy-variable)
###########################################################
# plumed
###########################################################

plumed: test-plumed uncompress-plumed patch-plumed
	if test -d ../PLUMED; then \
	cd ../; $(MAKE) pw; $(MAKE) cp; fi
	touch make-plumed
test-plumed: touch-dummy
	@(if test ! -s ../archive/$(PLUMED).tar.gz && test ! -d ../PLUMED; then \
	echo "The release contains no PLUMED package. Trying to download it from qe-forge."; fi) 
	touch ./test-plumed
uncompress-plumed: touch-dummy
	@(if test ! -s ../archive/$(PLUMED).tar.gz && test ! -d ../PLUMED ; then \
	wget -O ../archive/$(PLUMED).tar.gz $(PLUMED_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(PLUMED).tar.gz $(PLUMED_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download plumed. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(PLUMED).tar.gz from $(PLUMED_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../PLUMED; then \
	(gzip -dc ../archive/$(PLUMED).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(PLUMED) PLUMED) ; fi 
	touch uncompress-plumed

patch-plumed: touch-dummy
	if test -d ../PLUMED; then \
	(cd ../PLUMED ; export plumedir="`pwd`" ; \
	cp  patches/plumedpatch_qespresso_5.0.sh ../ ; \
	cd ../ ; ./plumedpatch_qespresso_5.0.sh -patch) ; fi	
	touch ./patch-plumed

##################################
# SaX
##################################

sax: extlibs uncompress-sax configure-sax
	if test -d ../SaX; then \
	cd ../SaX; $(MAKE) sax_all; fi
#	- ( cd ../bin ; ln -sf ../SaX/sax/bin/* . ) 
	touch ./make-sax
uncompress-sax: touch-dummy
	@(if test ! -s ../archive/$(SAX).tar.gz && test ! -d ../SaX ; then \
	wget -O ../archive/$(SAX).tar.gz $(SAX_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(SAX).tar.gz $(SAX_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download SaX. Test whether curl or wget is installed and working." ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(SAX).tar.gz from $(SAX_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../SaX; then \
	(gzip -dc ../archive/$(SAX).tar.gz | (cd ../ ; tar -xvf -)) ; \
	(cd ../ ; ln -s $(SAX) SaX) ; fi 
	touch uncompress-sax

configure-sax: touch-dummy
	cd ../SaX ; \
	./configure \
	--with-external-iotk \
	IOTK_LIBS="-L../../S3DE/iotk/src -liotk" \
	IOTK_INCLUDE="$(MOD_FLAG)../../S3DE/iotk/src" \
	CC="$(CC)" \
	F90="$(F90)" \
	MPIF90="$(MPIF90)" \
	F90FLAGS="$(F90FLAGS) $($PRE_FDFLAGS) $(FDFLAGS) $(IFLAGS) $(MODFLAGS)" \
	F77="$(F77)" \
	FFLAGS="$(FFLAGS)" \
	FFLAGS_NOOPT="$(FFLAGS_NOOPT)" \
	LD="$(LD)" \
	LDFLAGS="$(LDFLAGS)" \
	AR="$(AR)" \
	ARFLAGS="$(ARFLAGS)" \
	RANLIB="$(RANLIB)" \
	DFLAGS="$(DFLAGS)" \
	FDFLAGS="$(DFLAGS)" \
	LAPACK_LIBS="$(LAPACK_LIBS)" \
	BLAS_LIBS="$(BLAS_LIBS)" \
	FFT_LIBS="$(FFT_LIBS)" 
	touch ./configure-sax


##################################
# extlibs
###################################
extlibs:
	test -n "$(EXTLIBS)" && ( cd .. ; $(MAKE) $(MFLAGS) $(EXTLIBS) || exit 1) || :

##########################################################
# GUI
###########################################################
gui:  uncompress-gui
	touch make-gui
uncompress-gui: touch-dummy
	@(if test ! -s ../archive/$(GUI).tgz && test ! -d ../GUI && test ! -d ../$(GUI); then \
	wget -O ../archive/$(GUI).tgz $(GUI_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	curl -o ../archive/$(GUI).tgz $(GUI_URL) > /dev/null 2>&1; \
	if test "`echo $$?`" -ne "0" ; then \
	echo "*** Unable to download pwGUI. Test whether curl or wget is installed and working," ; \
	echo "*** if you have direct access to internet. If not, copy into archive/ the file" ; \
	echo "*** $(GUI).tar.gz from $(GUI_URL)." ; \
	exit 1 ; fi ; fi ; fi) 
	if test ! -d ../GUI && test ! -d ../$(GUI); then \
	(gzip -dc ../archive/$(GUI).tgz | (cd ../ ; tar -xvf -)) ; fi
	touch uncompress-gui

###################################
# cleaning
###################################
# each lib independently
ld1_clean:
	if test -d ../atomic; then (cd ../atomic; \
	$(MAKE) clean); fi
	rm -f ../bin/ld1.x
	rm -rf ./make-ld1 

ld1_veryclean: ld1_clean
# dir is not deleted for compatibility with the repository

xspectra_clean:
	if test -d ../XSpectra; then (cd ../XSpectra; \
	$(MAKE) clean); fi
	rm -f ../bin/xspectra.x
	rm -rf ./make-xspectra

xspectra_veryclean: xspectra_clean
# dir is not deleted for compatibility with the repository

pwcond_clean:
	if test -d ../PWCOND; then (cd ../PWCOND; \
	$(MAKE) clean); fi
	rm -f ../bin/pwcond.x
	rm -rf ./make-pwcond

pwcond_veryclean: pwcond_clean
# dir is not deleted for compatibility with the repository

neb_clean:
	if test -d ../NEB; then (cd ../NEB; \
	$(MAKE) clean); fi
	rm -f ../bin/neb.x
	rm -rf ./make-neb
 
neb_veryclean: neb_clean
# dir is not deleted for compatibility with the repository

tddfpt_clean:
	if test -d ../TDDFPT; then (cd ../TDDFPT; \
	$(MAKE) clean); fi
	rm -f ../bin/turbo_lanczos.x
	rm -f ../bin/turbo_spectrum.x
	rm -rf ./make-tddfpt

tddfpt_veryclean: tddfpt_clean 
# dir is not deleted for compatibility with the repository

phonon_clean:
	if test -d ../PHonon; then (cd ../PHonon; \
	$(MAKE) clean); fi
	rm -rf ../bin/ph.x
	rm -rf ../bin/dynmat.x
	rm -rf ../bin/matdyn.x
	rm -rf ../bin/q2r.x
	rm -rf ../bin/q2qstar.x
	rm -rf ../bin/lambda.x
	rm -rf ../bin/fqha.x
	rm -rf ../bin/phcg.x
	rm -rf ../bin/d3.x
	rm -rf ./make-phonon 

phonon_veryclean: phonon_clean
# dir is not deleted for compatibility with the repository
# exe links to main bin dir are deleted by PHonon Makefile

gipaw_clean:
	if test -d ../GIPAW; then (cd ../GIPAW; \
	$(MAKE) clean); fi
	rm -f ../bin/gipaw.x
	rm -rf ./make-gipaw 

gipaw_veryclean: gipaw_clean
	if test -d ../GIPAW; then (cd ../GIPAW; \
	rm -f config.log config.status ); fi
	rm -rf ./configure-gipaw

epw_clean:
	if test -d ../EPW; then (cd ../EPW; \
	$(MAKE) clean); fi
	rm -f ../bin/epw.x
	rm -rf ./make-epw 
epw_veryclean: epw_clean

w90_clean:
	if test -d ../W90; then (cd ../W90; \
	$(MAKE) veryclean); fi
	rm -f ../bin/wannier90.x
	rm -rf ./make-w90 ./configure-w90
w90_veryclean: w90_clean
	if test -d ../W90; then (rm -R -f ../W90); fi
	if test -d ../$(W90); then (rm -R -f ../$(W90)); fi
	rm -f ../bin/wannier90.x
	rm -rf ./uncompress-w90
want_clean:
	if test -d ../WANT; then (cd ../WANT; \
	$(MAKE) clean); fi
	- rm -rf ./make-want ./configure-want

want_veryclean: want_clean
	if test -d ../WANT; then (rm -R -f ../WANT); fi
	if test -d ../$(WANT); then (rm -R -f ../$(WANT)); fi
	- rm -rf ./uncompress-want
yambo_clean:
	if test -d ../YAMBO; then (cd ../YAMBO; \
	$(MAKE) clean); fi
	- rm -rf ./make-yambo ./configure-yambo

yambo_veryclean: yambo_clean
	if test -d ../YAMBO; then (rm -R -f ../YAMBO); fi
	if test -d ../$(YAMBO); then (rm -R -f ../$(YAMBO)); fi
	- rm -rf ./uncompress-yambo

plumed_clean:
	if test -d ../PLUMED; then (cd ../PLUMED; \
	export plumedir="`pwd`" ; \
	cd ../ ; ./plumedpatch_qespresso_5.0.sh -revert); fi
	cd ../PW ; $(MAKE) clean; cd ../CPV ; $(MAKE) clean
	rm -rf ./make-plumed ./patch-plumed

plumed_veryclean: plumed_clean
	if test -d ../PLUMED; then (rm -R -f ../PLUMED); fi
	if test -d ../$(PLUMED); then (rm -R -f ../$(PLUMED)); fi
	rm -rf ./uncompress-plumed ../plumedpatch_qespresso_5.0.sh

sax_clean:
	if test -d ../SaX; then (cd ../SaX; \
	$(MAKE) clean); fi
	- rm -rf ./make-sax ./configure-sax

sax_veryclean: sax_clean
	if test -d ../SaX; then (rm -R -f ../SaX); fi
	if test -d ../$(SAX); then (rm -R -f ../$(SAX)); fi
	- rm -rf ./uncompress-sax

gui_clean:
	rm -rf ./make-gui 

gui_veryclean: gui_clean
# dir is not deleted for compatibility with the repository

##########################################################
# general cleaning
##########################################################
clean: w90_clean want_clean yambo_clean plumed_clean epw_clean \
	gui_clean phonon_clean tddfpt_clean xspectra_clean neb_clean pwcond_clean \
	ld1_clean gipaw_clean
veryclean: w90_veryclean want_veryclean yambo_veryclean plumed_veryclean epw_veryclean \
	gui_veryclean phonon_veryclean tddfpt_veryclean xspectra_veryclean neb_veryclean \
	pwcond_veryclean ld1_veryclean gipaw_veryclean
