CHANGES: update version tag and add a blank line between versions
[git-cola.git] / Makefile
blob5f3cd3bceb34d3434e5d89d6ef9f69e19626b4c4
1 # The default target of this Makefile is...
2 all::
4 # Development
5 # -----------
6 # make V=1 # generate files; V=1 increases verbosity
7 # make test [flags=...] # run tests; flags=-x fails fast, --ff failed first
8 # make test V=2 # V=2 increases test verbosity
9 # make doc # build docs
10 # make flake8 # python style checks
11 # make pylint [color=1] # run pylint; color=1 colorizes output
12 # make pylint3k [color=1] # run python2+3 compatibility checks
13 # make format # run the black python formatter
14 # make check [color=1] # run test, doc, flake8, pylint3k, and pylint
15 # make check file=<filename> # run checks on <filename>
17 # Release Prep
18 # ------------
19 # make pot # update main translation template
20 # make po # merge translations
21 # make mo # generate message files
22 # make i18n # all three of the above
24 # Installation
25 # ------------
26 # make prefix=<path> install
27 # DESTDIR is also supported.
29 # To disable distutil's replacement of "#!/usr/bin/env python" with
30 # the path to the build environment's python, pass USE_ENV_PYTHON=1
31 # when invoking make.
33 # The external commands used by this Makefile are...
34 BLACK = black
35 CTAGS = ctags
36 CP = cp
37 FIND = find
38 FLAKE8 = flake8
39 GREP = grep
40 GIT = git
41 GZIP = gzip
42 LN = ln
43 LN_S = $(LN) -s -f
44 MARKDOWN = markdown
45 MKDIR_P = mkdir -p
46 PIP = pip
47 PYTHON ?= python
48 PYLINT = $(PYTHON) -B -m pylint
49 PYTEST = $(PYTHON) -B -m pytest
50 RM = rm -f
51 RM_R = rm -fr
52 RMDIR = rmdir
53 TAR = tar
54 TOX = tox
55 XARGS = xargs
57 # Flags
58 # -----
59 ifdef V
60 VERBOSE = --verbose
61 ifeq ($(V),2)
62 TEST_VERBOSE = --verbose
63 VERBOSE_SHORT = -vv
64 else
65 VERBOSE_SHORT = -v
66 endif
67 else
68 QUIET = --quiet
69 endif
71 FLAKE8_FLAGS = $(VERBOSE)
73 PYTEST_FLAGS = $(QUIET) $(TEST_VERBOSE)
74 uname_S := $(shell uname -s)
75 ifneq ($(uname_S),Linux)
76 PYTEST_FLAGS += --ignore=cola/inotify.py
77 endif
79 TOX_FLAGS = $(VERBOSE_SHORT) --develop --skip-missing-interpreters
80 TOX_ENVS ?= py{27,36,37,38,39,lint}
82 PYLINT_SCORE_FLAG := $(shell sh -c '$(PYLINT) --score=no --help >/dev/null 2>&1 && echo " --score=no" || true')
83 PYLINT_FLAGS = --rcfile=.pylintrc
84 ifdef color
85 PYLINT_FLAGS += --output-format=colorized
86 endif
87 ifneq ($(PYLINT_SCORE_FLAGSCORE),)
88 PYLINT_FLAGS += $(PYLINT_SCORE_FLAG)
89 endif
91 # These values can be overridden on the command-line or via config.mak
92 prefix = $(HOME)
93 bindir = $(prefix)/bin
94 datadir = $(prefix)/share/git-cola
95 python_lib := $(shell $(PYTHON) -c \
96 'import distutils.sysconfig as sc; print(sc.get_python_lib(prefix=""))')
97 pythondir = $(prefix)/$(python_lib)
98 hicolordir = $(prefix)/share/icons/hicolor/scalable/apps
99 # DESTDIR =
101 cola_base := git-cola
102 cola_app_base= $(cola_base).app
103 cola_app = $(CURDIR)/$(cola_app_base)
105 # Read $(VERSION) from cola/_version.py and strip quotes.
106 include cola/_version.py
107 cola_version := $(subst ',,$(VERSION))
108 cola_dist := $(cola_base)-$(cola_version)
110 SETUP ?= $(PYTHON) setup.py
112 build_args += build
113 ifdef USE_ENV_PYTHON
114 build_args += --use-env-python
115 endif
117 install_args += install
118 install_args += --prefix="$(prefix)"
119 install_args += --force
120 install_args += --install-scripts="$(bindir)"
121 install_args += --record=build/MANIFEST
122 ifdef DESTDIR
123 install_args += --root="$(DESTDIR)"
124 export DESTDIR
125 endif
126 export prefix
128 ifdef NO_PRIVATE_LIBS
129 install_args += --no-private-libs
130 endif
131 ifdef NO_VENDOR_LIBS
132 install_args += --no-vendor-libs
133 endif
135 PYTHON_DIRS = cola
136 PYTHON_DIRS += test
138 ALL_PYTHON_DIRS = $(PYTHON_DIRS)
139 ALL_PYTHON_DIRS += extras
141 PYTHON_SOURCES = bin/git-cola
142 PYTHON_SOURCES += bin/git-cola-sequence-editor
143 PYTHON_SOURCES += bin/git-dag
144 PYTHON_SOURCES += setup.py
146 # User customizations
147 -include config.mak
149 .PHONY: all
150 all:: build
152 .PHONY: build_version
153 build_version:
154 @GIT=$(GIT) ./extras/generate-build-version.sh 2>/dev/null || true
156 .PHONY: build
157 build: build_version
158 $(SETUP) $(QUIET) $(VERBOSE) $(build_args)
160 .PHONY: install
161 install: all
162 $(SETUP) $(QUIET) $(VERBOSE) $(install_args)
163 $(MKDIR_P) "$(DESTDIR)$(hicolordir)"
164 $(LN_S) "$(datadir)/icons/git-cola.svg" \
165 "$(DESTDIR)$(hicolordir)/git-cola.svg"
166 $(LN_S) git-cola "$(DESTDIR)$(bindir)/cola"
168 .PHONY: doc
169 doc:
170 $(MAKE) -C share/doc/git-cola all
172 .PHONY: html
173 html:
174 $(MAKE) -C share/doc/git-cola html
176 .PHONY: man
177 man:
178 $(MAKE) -C share/doc/git-cola man
180 .PHONY: install-doc
181 install-doc:
182 $(MAKE) -C share/doc/git-cola install
184 .PHONY: install-html
185 install-html:
186 $(MAKE) -C share/doc/git-cola install-html
188 .PHONY: install-man
189 install-man:
190 $(MAKE) -C share/doc/git-cola install-man
192 .PHONY: uninstall
193 uninstall:
194 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola
195 $(RM) "$(DESTDIR)$(prefix)"/bin/git-cola-sequence-editor
196 $(RM) "$(DESTDIR)$(prefix)"/bin/git-dag
197 $(RM) "$(DESTDIR)$(prefix)"/bin/cola
198 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola.desktop
199 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-cola-folder-handler.desktop
200 $(RM) "$(DESTDIR)$(prefix)"/share/applications/git-dag.desktop
201 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-dag.appdata.xml
202 $(RM) "$(DESTDIR)$(prefix)"/share/metainfo/git-cola.appdata.xml
203 $(RM) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps/git-cola.svg
204 $(RM_R) "$(DESTDIR)$(prefix)"/share/doc/git-cola
205 $(RM_R) "$(DESTDIR)$(prefix)"/share/git-cola
206 $(RM) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES/git-cola.mo
207 $(RM_R) "$(DESTDIR)$(pythondir)"/git_cola-*
208 $(RM_R) "$(DESTDIR)$(pythondir)"/cola
209 $(RMDIR) -p "$(DESTDIR)$(pythondir)" 2>/dev/null || true
210 $(RMDIR) "$(DESTDIR)$(prefix)"/share/applications 2>/dev/null || true
211 $(RMDIR) "$(DESTDIR)$(prefix)"/share/metainfo 2>/dev/null || true
212 $(RMDIR) "$(DESTDIR)$(prefix)"/share/doc 2>/dev/null || true
213 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/*/LC_MESSAGES 2>/dev/null || true
214 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale/* 2>/dev/null || true
215 $(RMDIR) "$(DESTDIR)$(prefix)"/share/locale 2>/dev/null || true
216 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable/apps 2>/dev/null || true
217 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor/scalable 2>/dev/null || true
218 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons/hicolor 2>/dev/null || true
219 $(RMDIR) "$(DESTDIR)$(prefix)"/share/icons 2>/dev/null || true
220 $(RMDIR) "$(DESTDIR)$(prefix)"/share 2>/dev/null || true
221 $(RMDIR) "$(DESTDIR)$(prefix)"/bin 2>/dev/null || true
222 $(RMDIR) "$(DESTDIR)$(prefix)" 2>/dev/null || true
224 .PHONY: test
225 test: all
226 $(PYTEST) $(PYTEST_FLAGS) $(flags) $(PYTHON_DIRS)
228 .PHONY: coverage
229 coverage:
230 $(PYTEST) $(PYTEST_FLAGS) --cov=cola $(flags) $(PYTHON_DIRS)
232 .PHONY: clean
233 clean:
234 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py[cod]' -print0 | $(XARGS) -0 $(RM)
235 $(FIND) $(ALL_PYTHON_DIRS) -name __pycache__ -print0 | $(XARGS) -0 $(RM_R)
236 $(RM_R) build dist tags git-cola.app
237 $(RM_R) share/locale
238 $(MAKE) -C share/doc/git-cola clean
240 .PHONY: tags
241 tags:
242 $(FIND) $(ALL_PYTHON_DIRS) -name '*.py' -print0 | $($XARGS) -0 $(CTAGS) -f tags
244 # Update i18n files
245 .PHONY: i18n
246 i18n:: pot
247 i18n:: po
248 i18n:: mo
250 .PHONY: pot
251 pot:
252 $(SETUP) build_pot --build-dir=po --no-lang
254 .PHONY: po
256 $(SETUP) build_pot --build-dir=po
258 .PHONY: mo
260 $(SETUP) build_mo --force
262 .PHONY: git-cola.app
263 git-cola.app:
264 $(MKDIR_P) $(cola_app)/Contents/MacOS
265 $(MKDIR_P) $(cola_app)/Contents/Resources
266 $(CP) contrib/darwin/Info.plist contrib/darwin/PkgInfo \
267 $(cola_app)/Contents
268 $(CP) contrib/darwin/git-cola $(cola_app)/Contents/MacOS
269 $(CP) contrib/darwin/git-cola.icns $(cola_app)/Contents/Resources
270 $(MAKE) prefix=$(cola_app)/Contents/Resources install install-doc
272 .PHONY: app-tarball
273 app-tarball: git-cola.app
274 $(TAR) czf $(cola_dist).app.tar.gz $(cola_app_base)
276 # Preview the markdown using "make README.html"
277 %.html: %.md
278 $(MARKDOWN) $< >$@
280 .PHONY: flake8
281 flake8:
282 $(FLAKE8) --version
283 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) \
284 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS) contrib
286 .PHONY: pylint3k
287 pylint3k:
288 $(PYLINT) --version
289 $(PYLINT) $(PYLINT_FLAGS) --py3k $(flags) \
290 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
292 .PHONY: pylint
293 pylint:
294 $(PYLINT) --version
295 $(PYLINT) $(PYLINT_FLAGS) $(flags) \
296 $(PYTHON_SOURCES) $(ALL_PYTHON_DIRS)
298 # Pre-commit checks
299 .PHONY: check
300 ifdef file
301 check:
302 $(FLAKE8) $(FLAKE8_FLAGS) $(flags) $(file)
303 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized $(flags) $(file)
304 $(PYLINT) $(PYLINT_FLAGS) --output-format=colorized --py3k $(flags) $(file)
305 else
306 # NOTE: flake8 is not part of "make check" because the pytest-flake8 plugin runs flake8
307 # checks during "make test" via pytest.
308 check:: all
309 check:: test
310 check:: doc
311 check:: pylint3k
312 check:: pylint
313 endif
315 .PHONY: format
316 format:
317 $(GIT) ls-files -- '*.py' | \
318 $(GREP) -v ^qtpy | \
319 $(XARGS) $(BLACK) --skip-string-normalization --target-version=py27
320 $(BLACK) --skip-string-normalization --target-version=py27 $(PYTHON_SOURCES)
322 .PHONY: requirements
323 requirements:
324 $(PIP) install --requirement requirements/requirements.txt
326 .PHONY: requirements-dev
327 requirements-dev:
328 $(PIP) install --requirement requirements/requirements-dev.txt
330 .PHONY: tox
331 tox:
332 $(TOX) $(TOX_FLAGS) $(flags)
334 .PHONY: tox-check
335 tox-check:
336 $(TOX) $(TOX_FLAGS) --parallel auto -e "$(TOX_ENVS)" $(flags)