Skip to content
Snippets Groups Projects
Makefile 7.79 KiB
#-------------------------------------------------------------------------------
# MASTER MAKEFILE FOR MENTAT-NG PROJECT
#
# Copyright (C) since 2016, CESNET, z. s. p. o.
# Author: Jan Mach <jan.mach@cesnet.cz>
# Use of this source is governed by an MIT license, see LICENSE file.
#-------------------------------------------------------------------------------

DIR_BIN = bin
DIR_DOC = doc
DIR_LIB = lib

DIR_LIB_HAWAT = lib/hawat

BIN_FILES := $(wildcard bin/mentat-*.py)
LIB_FILES := $(shell find $(DIR_LIB) -name '*.py' | grep -v 'test_')

#
# Color code definitions for colored terminal output
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
#
RED=\033[0;31m
GREEN=\033[0;32m
ORANGE=\033[0;33m
BLUE=\033[0;34m
PURPLE=\033[0;35m
CYAN=\033[0;36m
NC=\033[0m

#-------------------------------------------------------------------------------

#
# Default make target, alias for 'help', you must explicitly choose the target.
#
default: help

#
# Check the project code.
#
check: pyflakes pylint test

#-------------------------------------------------------------------------------

help:
	@echo ""
	@echo " ${GREEN}─────────────────────────────────────────────────${NC}"
	@echo " ${GREEN}              LIST OF MAKE TARGETS${NC}"
	@echo " ${GREEN}─────────────────────────────────────────────────${NC}"
	@echo ""
	@echo "  * ${GREEN}default${NC}: alias for help, you have to pick a target"
	@echo "  * ${GREEN}help${NC}: print this help message and exit"
	@echo "  * ${GREEN}show-version${NC}: show current project version"
	@echo "  * ${GREEN}deps${NC}: install various dependencies"
	@echo "     = ${ORANGE}deps-python${NC}: install Python dependencies with pip3"
	@echo "     = ${ORANGE}deps-geoip${NC}: install geolocation databases"
	@echo "     = ${ORANGE}deps-negistry${NC}: install negistry whois database"
	@echo "     = ${ORANGE}deps-postgresql${NC}: install and configure PostgreSQL database"
	@echo "  * ${GREEN}docs${NC}: generate local project documentation"
	@echo "     = ${ORANGE}docs-sync${NC}: synchronize documentation from submodules"
	@echo "     = ${ORANGE}docs-sphinx${NC}: generate local project documentation"
	@echo "  * ${GREEN}pybabel-patch${NC}: patch babel library"
	@echo "  * ${GREEN}pybabel-extract${NC}: extract Hawat user interface translations"
	@echo "  * ${GREEN}pybabel-update${NC}: update Hawat user interface translations"
	@echo "  * ${GREEN}pybabel-pull${NC}: extract and update Hawat user interface translations"
	@echo "  * ${GREEN}pybabel-compile${NC}: compile Hawat user interface translations"
	@echo "  * ${GREEN}check${NC}: perform extensive project checking"
	@echo "     = ${ORANGE}pyflakes${NC}: check project with pyflakes"
	@echo "        - pyflakes-bin: check executables with pyflakes"
	@echo "        - pyflakes-lib: check library with pyflakes, exclude test files"
	@echo "        - pyflakes-lib-all: check library with pyflakes including test files"
	@echo "     = ${ORANGE}pylint${NC}: check project with pylint"
	@echo "        - pylint-bin: check executables with pylint"
	@echo "        - pylint-lib: check library with pylint, exclude test files"
	@echo "        - pylint-lib-all: check library with pylint including test files"
	@echo "     = ${ORANGE}test${NC}: run unit tests with nosetest"
	@echo ""
	@echo " ${GREEN}─────────────────────────────────────────────────${NC}"
	@echo ""


#-------------------------------------------------------------------------------


show-version: FORCE
	@PYTHONPATH=lib python3 -c "import mentat; print(mentat.__version__);"

#-------------------------------------------------------------------------------


deps: deps-python deps-geoip deps-negistry deps-postgresql

deps-python: FORCE
	@echo "\n${GREEN}*** Installing Python dependencies ***${NC}\n"
	@pip3 install -r conf/requirements.pip --upgrade

deps-geoip: FORCE
	@echo "\n${GREEN}*** Installing geolocation databases ***${NC}\n"
	@./scripts/fetch-geoipdb.sh

deps-negistry: FORCE
	@echo "\n${GREEN}*** Installing negistry whois database ***${NC}\n"
	@./scripts/fetch-negistry.sh --stub

deps-postgresql: FORCE
	@echo "\n${GREEN}*** Installing and configuring PostgreSQL database ***${NC}\n"
	@./scripts/sqldb-init.sh


#-------------------------------------------------------------------------------


docs: docs-sync docs-sphinx

docs-sync: FORCE
	@echo "\n${GREEN}*** Synchronizing documentation source code from submodules ***${NC}\n"
	@rsync -r --progress --archive --update --delete --force ./submodules/pyzenkit/doc/_doclib/api_*.rst ./doc/sphinx/_doclib/
	@rsync -r --progress --archive --update --delete --force ./submodules/pyzenkit/doc/_doclib/_inc*.rst ./doc/sphinx/_doclib/
	@rsync -r --progress --archive --update --delete --force ./submodules/pynspect/doc/_doclib/api_*.rst ./doc/sphinx/_doclib/
	@#find ./ -type f -name *.pyc -exec rm -f {} \;

docs-sphinx: FORCE
	@echo "\n${GREEN}*** Generating project documentation ***${NC}\n"
	@cd $(DIR_DOC)/sphinx && make html


#-------------------------------------------------------------------------------


#
# This patch solves following issue: https://github.com/python-babel/flask-babel/issues/43
#
pybabel-patch: FORCE
	@echo "\n${GREEN}*** Patching babel library ***${NC}\n"
	@cp util/babel.messages.frontend.py.patch /var/tmp/
	@cd / && patch -p0 -i /var/tmp/babel.messages.frontend.py.patch

pybabel-extract: FORCE
	@echo "\n${GREEN}*** Extracting babel translation for Hawat user interface ***${NC}\n"
	@cd $(DIR_LIB_HAWAT) && pybabel-python3 extract -F babel.cfg -o messages.pot -k lazy_gettext .
#pybabel-init: FORCE
#	@echo "\n${GREEN}*** Initializing translation for Hawat user interface ***${NC}\n"
#	@cd $(DIR_LIB_HAWAT) && pybabel-python3 init -i messages.pot -d translations -l cs

pybabel-update: FORCE
	@echo "\n${GREEN}*** Updating translations for Hawat user interface ***${NC}\n"
	@cd $(DIR_LIB_HAWAT) && pybabel-python3 update -i messages.pot -d translations -l cs

pybabel-pull: pybabel-extract pybabel-update

pybabel-compile: FORCE
	@echo "\n${GREEN}*** Compiling translations for Hawat user interface ***${NC}\n"
	@cd $(DIR_LIB_HAWAT) && pybabel-python3 compile -d translations

#-------------------------------------------------------------------------------


pyflakes: pyflakes-bin pyflakes-lib

pyflakes-bin:
	@echo "\n${GREEN}*** Checking executables with pyflakes ***${NC}\n"
	-@PYTHONPATH=$(DIR_LIB) python3 -m pyflakes $(DIR_BIN)

pyflakes-lib:
	@echo "\n${GREEN}*** Checking library with pyflakes - test files excluded ***${NC}\n"
	-@for l in ${LIB_FILES}; do\
		PYTHONPATH=$(DIR_LIB) python3 -m pyflakes $$l; \
	done

pyflakes-lib-all:
	@echo "\n${GREEN}*** Checking library with pyflakes - all files ***${NC}\n"
	-@PYTHONPATH=$(DIR_LIB) python3 -m pyflakes $(DIR_LIB)

pylint: pylint-bin pylint-lib

pylint-bin:
	@echo "\n${GREEN}*** Checking executables with pylint ***${NC}\n"
	-@PYTHONPATH=$(DIR_LIB) python3 -m pylint --rcfile .pylintrc-bin $(DIR_BIN)

pylint-lib:
	@echo "\n${GREEN}*** Checking library with pylint - test files excluded ***${NC}\n"
	-@for l in ${LIB_FILES}; do\
		PYTHONPATH=$(DIR_LIB) python3 -m pylint --rcfile .pylintrc-lib $$l; \
	done

pylint-lib-all:
	@echo "\n${GREEN}*** Checking library with pylint - all files ***${NC}\n"
	-@PYTHONPATH=$(DIR_LIB) python3 -m pylint --rcfile .pylintrc-lib $(DIR_LIB)

test:
	@echo "\n${GREEN}*** Checking code with nosetests ***${NC}\n"
	@PYTHONPATH=$(DIR_LIB) nosetests


#-------------------------------------------------------------------------------


# Empty rule as dependency will force make to always perform target
# Source: https://www.gnu.org/software/make/manual/html_node/Force-Targets.html
FORCE: