forked from lelit/pglast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (115 loc) · 4.55 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
# :Project: pglast -- Development Makefile
# :Created: gio 03 ago 2017 14:52:45 CEST
# :Author: Lele Gaifax <[email protected]>
# :License: GNU General Public License version 3 or later
# :Copyright: © 2017, 2018, 2019, 2021 Lele Gaifax
#
export TOPDIR := $(CURDIR)
ifeq ($(VIRTUAL_ENV),)
export VENVDIR := $(TOPDIR)/env
else
export VENVDIR := $(VIRTUAL_ENV)
endif
export PYTHON := $(VENVDIR)/bin/python
export SHELL := /bin/bash
export SYS_PYTHON := $(shell command -v python3)
all: virtualenv libpg_query/Makefile help
libpg_query/Makefile:
git submodule update --init
help::
@printf "\nBuild targets\n"
@printf "=============\n\n"
help::
@printf "build\n\tbuild the module\n"
.PHONY: build
build: virtualenv $(VENVDIR)/extension.timestamp
$(VENVDIR)/extension.timestamp: libpg_query/libpg_query.a
$(VENVDIR)/extension.timestamp: pglast/ast.pyx pglast/parser.pyx
$(PYTHON) setup.py build_ext --inplace --force
@touch $@
libpg_query/libpg_query.a: libpg_query/Makefile
libpg_query/libpg_query.a: libpg_query/src/*.c libpg_query/src/*.h
$(MAKE) -C libpg_query build
help::
@printf "recythonize\n\tforce retranslation of the pyx module\n"
.PHONY: recythonize
recythonize:
touch pglast/parser.pyx
$(MAKE) build
help::
@printf "clean\n\tremove rebuildable stuff\n"
.PHONY: clean
clean:
$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) clean
$(MAKE) -C libpg_query clean
rm -f pglast/*.so
help::
@printf "distclean\n\tremove anything superfluous\n"
.PHONY: distclean
distclean:: clean
rm -rf build dist
git submodule deinit --all
help::
@printf "enums\n\textract Python enums from PG sources\n"
PY_ENUMS := pglast/enums/lockoptions.py pglast/enums/lockdefs.py \
pglast/enums/nodes.py pglast/enums/parsenodes.py \
pglast/enums/pg_attribute.py pglast/enums/pg_class.py \
pglast/enums/pg_trigger.py \
pglast/enums/primnodes.py pglast/enums/xml.py \
pglast/enums/pg_am.py
PG_INCLUDE_DIR := libpg_query/src/postgres/include
.PHONY: enums
enums: $(PY_ENUMS)
$(PY_ENUMS): tools/extract_enums.py libpg_query/libpg_query.a
pglast/enums/%.py: $(PG_INCLUDE_DIR)/nodes/%.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/lockdefs.py: $(PG_INCLUDE_DIR)/storage/lockdefs.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/pg_am.py: $(PG_INCLUDE_DIR)/catalog/pg_am.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/pg_attribute.py: $(PG_INCLUDE_DIR)/catalog/pg_attribute.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/pg_class.py: $(PG_INCLUDE_DIR)/catalog/pg_class.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/pg_trigger.py: $(PG_INCLUDE_DIR)/catalog/pg_trigger.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
pglast/enums/xml.py: $(PG_INCLUDE_DIR)/utils/xml.h
$(PYTHON) tools/extract_enums.py -I $(PG_INCLUDE_DIR) $< $@ docs/$(basename $(notdir $@)).rst
help::
@printf "keywords\n\textract Python keyword sets from PG sources\n"
PY_KEYWORDS := pglast/keywords.py
.PHONY: keywords
keywords: $(PY_KEYWORDS)
$(PY_KEYWORDS): tools/extract_keywords.py libpg_query/libpg_query.a
$(PY_KEYWORDS): $(PG_INCLUDE_DIR)/parser/kwlist.h
$(PYTHON) tools/extract_keywords.py $(PG_INCLUDE_DIR)/parser/kwlist.h $@
pglast/ast.pyx: tools/extract_ast.py libpg_query/srcdata/struct_defs.json
pglast/ast.pyx: $(PY_ENUMS)
$(PYTHON) tools/extract_ast.py pglast/ docs/ast.rst
help::
@printf "printers-doc\n\tupdate printers documentation\n"
PG_NODES := $(PG_INCLUDE_DIR)/nodes/nodes.h $(PG_INCLUDE_DIR)/nodes/parsenodes.h \
$(PG_INCLUDE_DIR)/nodes/primnodes.h $(PG_INCLUDE_DIR)/nodes/value.h
.PHONY: printers-doc
printers-doc: docs/ddl.rst docs/dml.rst
docs/ddl.rst docs/dml.rst: $(PG_NODES) tools/extract_printers_doc.py libpg_query/libpg_query.a
docs/%.rst: pglast/printers/%.py
$(PYTHON) tools/extract_printers_doc.py $< $@ $(PG_NODES)
help::
@printf "doc\n\tbuild Sphinx documentation\n"
SPHINXBUILD := $(VENVDIR)/bin/sphinx-build
.PHONY: doc
doc:
$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) html
help::
@printf "check\n\trun the test suite\n"
PYTEST = $(VENVDIR)/bin/pytest $(PYTEST_OPTIONS)
COVERAGE = $(VENVDIR)/bin/coverage
.PHONY: check
check: build
$(PYTEST) tests/
$(MAKE) -C docs SPHINXBUILD=$(SPHINXBUILD) doctest
$(COVERAGE) json -o $(TOPDIR)/coverage.json
include Makefile.virtualenv
include Makefile.release