default_target: all

Downloads/irpf90.tar.gz: 
	wget --no-check-certificate \
	"https://gitlab.com/scemama/irpf90/-/archive/v2.0.0/irpf90-v2.0.0.tar.gz" \
	-O $@.tmp -o /dev/null && mv $@.tmp $@

Downloads/ezfio.tar.gz:
	wget --no-check-certificate \
	"https://gitlab.com/scemama/EZFIO/-/archive/master/EZFIO-master.tar.gz" \
	-O $@.tmp -o /dev/null && mv $@.tmp $@

Downloads/zmq.tar.gz:
	wget --no-check-certificate \
	"http://github.com/zeromq/libzmq/releases/download/v4.2.5/zeromq-4.2.5.tar.gz" \
	-O $@.tmp -o /dev/null && mv $@.tmp $@

Downloads/f77_zmq.tar.gz:
	wget --no-check-certificate \
	"https://github.com/scemama/f77_zmq/archive/v4.2.5.tar.gz" \
	-O $@.tmp -o /dev/null && mv $@.tmp $@

Downloads/opam_installer.sh:
	wget --no-check-certificate \
	"https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh" \
	-O $@.tmp -o /dev/null && mv $@.tmp $@

_build/irpf90.ok ../bin/irpman ../bin/irpf90: Downloads/irpf90.tar.gz
	export target=irpf90 ; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log


_build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h: Downloads/zmq.tar.gz
	export target=zmq ; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log

_build/ezfio.ok: Downloads/ezfio.tar.gz
	export target=ezfio ; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log

_build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so: Downloads/f77_zmq.tar.gz  _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
	export target=f77_zmq ; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log

_build/qmcchemrc.ok ../qmcchemrc: _build/irpf90.ok ../bin/irpman ../bin/irpf90 _build/ezfio.ok
	export target=qmcchemrc; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log

_build/ocaml.ok ../bin/opam: Downloads/opam_installer.sh  _build/qmcchemrc.ok ../qmcchemrc
	which opam && touch _build/$${target}.ok ../bin/opam || \
	( export target=ocaml; \
	  ./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	  touch _build/$${target}.ok || cat _build/$${target}.log ;\
	)

_build/ocaml_zmq.ok: ../bin/opam ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/ocaml.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h
	export target=ocaml_zmq; \
	./scripts/install_$${target}.sh > _build/$${target}.log 2>&1 &&\
	touch _build/$${target}.ok || cat _build/$${target}.log



all: _build/ocaml_zmq.ok _build/ocaml.ok ../bin/opam _build/qmcchemrc.ok ../qmcchemrc _build/f77_zmq.ok ../src/ZMQ/f77_zmq.h ../lib/libf77zmq.a ../lib/libf77zmq.so _build/ezfio.ok _build/zmq.ok ../lib/libzmq.a ../lib/libzmq.so.5 ../lib/libzmq.so ../lib/zmq.h ../lib/zmq_utils.h _build/irpf90.ok ../bin/irpman ../bin/irpf90
	@echo "Now, source again the qmcchemrc file"
	@echo "source $$QMCCHEM_PATH/qmcchemrc"