.PHONY: clean distclean install run stop

install:
	set -e ;\
	THSF_DIR=$$(pwd); \
	echo [+] Déploiement dans $$THSF_DIR; \
	python3 -m venv thsf_venv; \
	. thsf_venv/bin/activate; \
	pip3 install -r requirements.txt ;\
	pip3 install . ;\
	pip3 install gunicorn; \

run:
	set -e ;\
	THSF_DIR=$$(pwd); \
	echo [+] Démarrage dans $$THSF_DIR; \
	. thsf_venv/bin/activate; \
	thsf_venv/bin/gunicorn -D -p thsf.pid -w 4 -b 127.0.0.1:8042 'thsf:app'

debug:
	set -e ;\
	THSF_DIR=$$(pwd); \
	echo [+] Démarrage dans $$THSF_DIR; \
	. thsf_venv/bin/activate; \
	thsf_venv/bin/gunicorn -p thsf.pid -w 4 -b 127.0.0.1:8042 'thsf:app'

stop:
	-set -e;\
	THSF_DIR=$$(pwd); \
	echo [+] Arrêt dans $$THSF_DIR; \
	kill -15 $$(cat $$THSF_DIR/thsf.pid); \
	rm thsf.pid

clean:
	-set -e ;\
	THSF_DIR=$$(pwd); \
	echo [+] Nettoyage dans $$THSF_DIR; \
	rm -Rf ./build ./src/thsf.egg-info ./thsf.pid ./thsf.log; \
	. thsf_venv/bin/activate; \
	pip3 uninstall thsf -y

distclean: clean
	rm -Rf thsf_venv/

all: stop clean install run