#
# Copyright (C) 2021-2022 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of QWeeChat, a Qt remote GUI for WeeChat.
#
# QWeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# QWeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with QWeeChat.  If not, see <http://www.gnu.org/licenses/>.
#
# to run the tests, run make PASS=controllerpassword test

PREFIX=/usr/local
PYTHON_EXE_MSYS=${PREFIX}/bin/python3.sh
PIP_EXE_MSYS=${PREFIX}/bin/pip3.sh
LOCAL_DOCTEST=${PREFIX}/bin/toxcore_run_doctest3.bash
DOCTEST=${LOCAL_DOCTEST}
PYTHON_MINOR=`python3 --version 2>&1 | sed -e 's@^.* @@' -e 's@\.[0-9]*$$@@'`
MOD=qweechat

all: check

check::
	sh ${PYTHON_EXE_MSYS} -c "import ${MOD}"
	sh ${PYTHON_EXE_MSYS} -c "from ${MOD} import config"

lint:: flake8 pylint bandit

flake8:
	flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
	flake8 . --count --exit-zero --max-complexity=10 --statistics

pylint:
	pylint qweechat

bandit:
	bandit -r qweechat

rsync::
	bash .rsync.sh

install:: install-pip

install-setup::
# deprecated
	${PYTHON_EXE_MSYS} -W ignore::DeprecationWarning \
		setup.py install \
		--prefix ${PREFIX}

install-pip::
# we install --nodeps because pip is installing stuff we already have in the OS
	${PIP_EXE_MSYS} --python ${PYTHON_EXE_MSYS} install \
		--no-deps \
		--target ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/ \
		--upgrade .
	sed -i -e "1s@/usr/bin/python${PYTHON_MINOR}@${PYTHON_EXE_MSYS}@" \
		${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/bin/*

veryclean:: clean
	rm -rf build dist $(MOD).egg-info

clean::
	find . -type f -name \*~ -delete