Merge pull request #995 from Vifon/pdf-previews
[ranger.git] / Makefile
blob99d3f53e05542cdd634cbd552858caffeed88266
1 # This file is part of ranger, the console file manager.
2 # License: GNU GPL version 3, see the file "AUTHORS" for details.
4 NAME = ranger
5 VERSION = $(shell grep -m 1 -o '[0-9][0-9.]\+\S*' README.md)
6 NAME_RIFLE = rifle
7 VERSION_RIFLE = $(VERSION)
8 SNAPSHOT_NAME ?= $(NAME)-$(VERSION)-$(shell git rev-parse HEAD | cut -b 1-8).tar.gz
9 # Find suitable python version (need python >= 2.6 or 3.1):
10 PYTHON ?= $(shell python -c 'import sys; sys.exit(sys.version < "2.6")' && \
11 which python || which python3.3 || which python3.2 || which python3.1 || \
12 which python3 || which python2.7 || which python2.6)
13 SETUPOPTS ?= '--record=install_log.txt'
14 DOCDIR ?= doc/pydoc
15 DESTDIR ?= /
16 PYOPTIMIZE ?= 1
17 FILTER ?= .
19 CWD = $(shell pwd)
21 default: test compile
22 @echo 'Run `make options` for a list of all options'
24 options: help
25 @echo
26 @echo 'Options:'
27 @echo 'PYTHON = $(PYTHON)'
28 @echo 'PYOPTIMIZE = $(PYOPTIMIZE)'
29 @echo 'DOCDIR = $(DOCDIR)'
30 @echo 'DESTDIR = $(DESTDIR)'
32 help:
33 @echo 'make: Test and compile ranger.'
34 @echo 'make install: Install $(NAME)'
35 @echo 'make pypi_sdist: Release a new sdist to PyPI'
36 @echo 'make clean: Remove the compiled files (*.pyc, *.pyo)'
37 @echo 'make doc: Create the pydoc documentation'
38 @echo 'make cleandoc: Remove the pydoc documentation'
39 @echo 'make man: Compile the manpage with "pod2man"'
40 @echo 'make manhtml: Compile the html manpage with "pod2html"'
41 @echo 'make snapshot: Create a tar.gz of the current git revision'
42 @echo 'make test: Test everything'
43 @echo 'make test_pylint: Test using pylint'
44 @echo 'make test_flake8: Test using flake8'
45 @echo 'make test_doctest: Test using doctest'
46 @echo 'make test_pytest: Test using pytest'
47 @echo 'make todo: Look for TODO and XXX markers in the source code'
49 install:
50 $(PYTHON) setup.py install $(SETUPOPTS) \
51 '--root=$(DESTDIR)' --optimize=$(PYOPTIMIZE)
53 compile: clean
54 PYTHONOPTIMIZE=$(PYOPTIMIZE) $(PYTHON) -m compileall -q ranger
56 clean:
57 find ranger -regex .\*\.py[co]\$$ -delete
58 find ranger -depth -name __pycache__ -type d -exec rm -r -- {} \;
60 doc: cleandoc
61 mkdir -p $(DOCDIR)
62 cd $(DOCDIR); \
63 $(PYTHON) -c 'import pydoc, sys; \
64 sys.path[0] = "$(CWD)"; \
65 pydoc.writedocs("$(CWD)")'
66 find . -name \*.html -exec sed -i 's|'"$(CWD)"'|../..|g' -- {} \;
68 TEST_PATHS_MAIN = \
69 $(shell find ./ranger -mindepth 1 -maxdepth 1 -type d \
70 -and -not -name '__pycache__' \
71 -and -not -path './ranger/config' \
72 -and -not -path './ranger/data' \
73 ) \
74 ./ranger/__init__.py \
75 $(shell find ./doc/tools ./examples -type f -name '*.py') \
76 ./ranger.py \
77 ./setup.py \
78 ./tests
79 TEST_PATH_CONFIG = ./ranger/config
81 test_pylint:
82 @echo "Running pylint..."
83 pylint $(TEST_PATHS_MAIN)
84 pylint --rcfile=$(TEST_PATH_CONFIG)/.pylintrc $(TEST_PATH_CONFIG)
86 test_flake8:
87 @echo "Running flake8..."
88 flake8 $(TEST_PATHS_MAIN) $(TEST_PATH_CONFIG)
90 test_doctest:
91 @echo "Running doctests..."
92 @for FILE in $(shell grep -IHm 1 doctest -r ranger | grep $(FILTER) | cut -d: -f1); do \
93 echo "Testing $$FILE..."; \
94 RANGER_DOCTEST=1 PYTHONPATH=".:"$$PYTHONPATH ${PYTHON} $$FILE; \
95 done
97 test_pytest:
98 @echo "Running py.test tests..."
99 py.test tests
101 test: test_pylint test_flake8 test_doctest test_pytest
102 @echo "Finished testing: All tests passed!"
104 man:
105 pod2man --stderr --center='ranger manual' --date='$(NAME)-$(VERSION)' \
106 --release=$(shell date +%x) doc/ranger.pod doc/ranger.1
107 pod2man --stderr --center='rifle manual' --date='$(NAME_RIFLE)-$(VERSION_RIFLE)' \
108 --release=$(shell date +%x) doc/rifle.pod doc/rifle.1
110 manhtml:
111 pod2html doc/ranger.pod --outfile=doc/ranger.1.html
113 cleandoc:
114 test -d $(DOCDIR) && rm -- $(DOCDIR)/*.html || true
116 snapshot:
117 git archive --prefix='$(NAME)-$(VERSION)/' --format=tar HEAD | gzip > $(SNAPSHOT_NAME)
119 dist: snapshot
121 todo:
122 @grep --color -Ion '\(TODO\|XXX\).*' -r ranger
124 .PHONY: clean cleandoc compile default dist doc help install man manhtml \
125 options snapshot test test_pylint test_flake8 test_doctest test_pytest todo pypi_sdist