1# -*- coding: utf-8 -*-
2# :Project:   pglast -- Development Makefile
3# :Created:   gio 03 ago 2017 14:52:45 CEST
4# :Author:    Lele Gaifax <lele@metapensiero.it>
5# :License:   GNU General Public License version 3 or later
6# :Copyright: © 2017, 2018 Lele Gaifax
7#
8
9export TOPDIR := $(CURDIR)
10export VENVDIR := $(TOPDIR)/env
11export PYTHON := $(VENVDIR)/bin/python
12export SHELL := /bin/bash
13export SYS_PYTHON := $(shell which python3.6 || which python3)
14
15all: virtualenv libpg_query/LICENSE help
16
17libpg_query/LICENSE:
18	git submodule update --init
19
20help::
21	@printf "\nBuild targets\n"
22	@printf   "=============\n\n"
23
24help::
25	@printf "build\n\tbuild the module\n"
26
27.PHONY: build
28build: virtualenv enums keywords libpg_query/libpg_query.a pglast/parser.c
29	$(PYTHON) setup.py build_ext --inplace
30
31libpg_query/libpg_query.a: libpg_query/LICENSE
32	$(MAKE) -C libpg_query build
33
34pglast/parser.c: pglast/parser.pyx
35	$(PYTHON) setup.py build_ext --inplace
36
37help::
38	@printf "recythonize\n\tforce retranslation of the pyx module\n"
39
40.PHONY: recythonize
41recythonize:
42	touch pglast/parser.pyx
43	$(MAKE) build
44
45help::
46	@printf "clean\n\tremove rebuildable stuff\n"
47
48.PHONY: clean
49clean:
50	$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) clean
51	$(MAKE) -C libpg_query clean
52	rm -f pglast/*.so
53
54help::
55	@printf "distclean\n\tremove anything superfluous\n"
56
57.PHONY: distclean
58distclean:: clean
59	rm -rf build dist
60	git submodule deinit --all
61
62help::
63	@printf "enums\n\textract Python enums from PG sources\n"
64
65PY_ENUMS_DIR := pglast/enums
66PY_ENUMS := $(PY_ENUMS_DIR)/lockoptions.py $(PY_ENUMS_DIR)/nodes.py \
67	    $(PY_ENUMS_DIR)/parsenodes.py $(PY_ENUMS_DIR)/primnodes.py \
68	    $(PY_ENUMS_DIR)/pg_class.py
69PG_INCLUDE_DIR := libpg_query/src/postgres/include
70
71.PHONY: enums
72enums: $(PY_ENUMS)
73
74$(PY_ENUMS): tools/extract_enums.py libpg_query/pg_query.h
75$(PY_ENUMS_DIR)/%.py: $(PG_INCLUDE_DIR)/nodes/%.h
76	$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
77$(PY_ENUMS_DIR)/pg_class.py: $(PG_INCLUDE_DIR)/catalog/pg_class.h
78	$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
79
80help::
81	@printf "keywords\n\textract Python keyword sets from PG sources\n"
82
83PY_KEYWORDS_DIR := pglast
84PY_KEYWORDS := $(PY_KEYWORDS_DIR)/keywords.py
85
86.PHONY: keywords
87keywords: $(PY_KEYWORDS)
88
89$(PY_KEYWORDS): tools/extract_keywords.py libpg_query/pg_query.h
90$(PY_KEYWORDS): $(PG_INCLUDE_DIR)/parser/kwlist.h
91	$(PYTHON) tools/extract_keywords.py $(PG_INCLUDE_DIR)/parser/kwlist.h $@
92
93help::
94	@printf "printers-doc\n\tupdate printers documentation\n"
95
96PG_NODES := $(PG_INCLUDE_DIR)/nodes/nodes.h $(PG_INCLUDE_DIR)/nodes/parsenodes.h \
97	    $(PG_INCLUDE_DIR)/nodes/primnodes.h $(PG_INCLUDE_DIR)/nodes/value.h
98
99.PHONY: printers-doc
100printers-doc: docs/ddl.rst docs/dml.rst
101
102docs/ddl.rst docs/dml.rst: $(PG_NODES) tools/extract_printers_doc.py
103docs/%.rst: pglast/printers/%.py
104	$(PYTHON) tools/extract_printers_doc.py $< $@ $(PG_NODES)
105
106help::
107	@printf "doc\n\tbuild Sphinx documentation\n"
108
109SPHINXBUILD := $(VENVDIR)/bin/sphinx-build
110
111.PHONY: doc
112doc:
113	$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) html
114
115help::
116	@printf "check\n\trun the test suite\n"
117
118PYTEST = $(VENVDIR)/bin/pytest $(PYTEST_OPTIONS)
119
120.PHONY: check
121check: build
122	$(PYTEST) tests/
123	$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) doctest
124
125include Makefile.virtualenv
126include Makefile.release
127