-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
166 lines (127 loc) · 4.91 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
##########################################################################
# CONFIGURATION
# Path to python binary
PYTHON ?= $(shell which python3)
COMMIT ?= $(shell git rev-parse HEAD)
PWD = $(shell pwd)
PYTHON_VERSION = $(shell python3 -c 'import sys; print("3_" + str(sys.version_info.minor))')
# Path to virtual environment(s)
VIRTUAL_ENV ?= .venv_$(PYTHON_VERSION)
ENV ?= .env_$(PYTHON_VERSION)
NODE_ENV ?= .nodeenv
PIPENV_PIPFILE ?= Pipfile_$(PYTHON_VERSION)
TP_SRC_PATH ?= typed_python
TP_BUILD_PATH ?= build/temp.linux-x86_64/typed_python
TP_LIB_PATH ?= build/lib.linux-x86_64/typed_python
TP_BUILD_OPT_LEVEL ?= 2
# location of python include paths
PYINCLUDE = $(shell python3 -c 'import sysconfig; print(sysconfig.get_paths()["include"])')
# location of numpy
NUMPYINCLUDE = $(shell python3 -c 'import pkg_resources; print(pkg_resources.resource_filename("numpy", "core/include"))')
# name of the _types binary, which we can infer from the name of the _ssl binary
TYPES_SO_NAME = $(shell python3 -c 'import _ssl; import os; print(os.path.split(_ssl.__file__)[1].replace("_ssl", "_types"))')
TYPES_O_NAME = $(shell python3 -c 'import _ssl; import os; print(os.path.split(_ssl.__file__)[1].replace("_ssl", "_types")[:-2] + "o")')
CPP_FLAGS = -std=c++14 -O$(TP_BUILD_OPT_LEVEL) -Wall -pthread -DNDEBUG -g -fwrapv \
-fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIC \
-Wno-terminate -Wno-bool-compare \
-Wno-cpp \
-Wformat -Werror=format-security -Wdate-time -Wno-reorder \
-Wno-sign-compare -Wno-narrowing -Wno-int-in-bool-context \
-I$(TP_SRC_PATH)/lz4 \
-I$(PYINCLUDE) \
-I$(NUMPYINCLUDE) \
LINKER_FLAGS = -Wl,-O1 \
-Wl,-Bsymbolic-functions \
-Wl,-z,relro
LINK_FLAGS_POST = -lssl -lcrypto
SHAREDLIB_FLAGS = -pthread -shared -g -fstack-protector-strong \
-Wformat -Werror=format-security -Wdate-time \
-D_FORTIFY_SOURCE=2
UNICODEPROPS = $(TP_SRC_PATH)/UnicodeProps.hpp
TP_O_FILES = $(TP_BUILD_PATH)/$(TYPES_O_NAME)
DT_SRC_PATH = $(TP_SRC_PATH)/direct_types
TESTTYPES = $(DT_SRC_PATH)/GeneratedTypes1.hpp
TESTTYPES2 = $(DT_SRC_PATH)/ClientToServer0.hpp
##########################################################################
# MAIN RULES
.PHONY: install
install: install-dependencies install-pre-commit
.PHONY: install-dependencies
.ONESHELL:
install-dependencies: $(VIRTUAL_ENV)
. $(VIRTUAL_ENV)/bin/activate; \
export PIPENV_PIPFILE=$(PIPENV_PIPFILE); \
pipenv install --dev --deploy
.PHONY: install-pre-commit
install-pre-commit:install-dependencies
. $(VIRTUAL_ENV)/bin/activate; \
pre-commit install
.PHONY: test
test: js-test
. $(VIRTUAL_ENV)/bin/activate; \
pytest
.PHONY: lint
lint:
flake8 --show-source
.PHONY: vlint
vlint: $(VIRTUAL_ENV)
. $(VIRTUAL_ENV)/bin/activate; \
make lint
.PHONY: lib
lib: typed_python/$(TYPES_SO_NAME)
.PHONY: unicodeprops
unicodeprops: ./unicodeprops.py
$(PYTHON) ./unicodeprops.py > $(UNICODEPROPS)
.PHONY: generatetesttypes
generatetesttypes: $(DT_SRC_PATH)/generate_types.py
. $(VIRTUAL_ENV)/bin/activate; \
python3 $(DT_SRC_PATH)/generate_types.py --testTypes3 $(TESTTYPES); \
python3 $(DT_SRC_PATH)/generate_types.py --testTypes2 $(TESTTYPES2)
.PHONY: clean
clean:
rm -rf build/
rm -rf typed_python.egg-info/
rm -f nose.*.log
rm -f typed_python/_types.cpython-*.so
rm -rf $(VIRTUAL_ENV) $(ENV)
rm -f .coverage*
rm -fr dist
##########################################################################
# HELPER RULES
$(ENV):
echo "# NOTICE: File Auto-generated by Makefile" > $@
echo "export COVERAGE_PROCESS_START=$(PWD)/tox.ini" >> $@
echo "export PYTHONPATH=$(PWD)" >> $@
.ONESHELL:
$(VIRTUAL_ENV): $(PYTHON) $(ENV)
$(PYTHON) -m venv $(VIRTUAL_ENV); \
. $(VIRTUAL_ENV)/bin/activate; \
export PIPENV_PIPFILE=$(PIPENV_PIPFILE); \
pip install -U pip; \
pip install pipenv; \
pip install wheel;
$(TP_BUILD_PATH)/$(TYPES_O_NAME): $(TP_SRC_PATH)/*.hpp $(TP_SRC_PATH)/*.cpp
$(CC) $(CPP_FLAGS) -c $(TP_SRC_PATH)/all.cpp $ -o $@
typed_python/$(TYPES_SO_NAME): $(TP_LIB_PATH)/$(TYPES_SO_NAME)
echo "python is " $(PYTHON)
cp $(TP_LIB_PATH)/$(TYPES_SO_NAME) typed_python
$(TP_LIB_PATH)/$(TYPES_SO_NAME): $(TP_LIB_PATH) $(TP_BUILD_PATH) $(TP_O_FILES)
$(CXX) $(SHAREDLIB_FLAGS) $(LINKER_FLAGS) \
$(TP_O_FILES) \
-o $(TP_LIB_PATH)/$(TYPES_SO_NAME) $(LINK_FLAGS_POST)
$(TP_BUILD_PATH):
mkdir -p $(TP_BUILD_PATH)
$(TP_LIB_PATH):
mkdir -p $(TP_LIB_PATH)
.PHONY: testpypi-upload
testpypi-upload: $(VIRTUAL_ENV)
. $(VIRTUAL_ENV)/bin/activate; \
rm -rf dist; \
python setup.py sdist; \
twine upload --repository-url https://test.pypi.org/legacy/ dist/*;
.PHONY: pypi-upload
pypi-upload: $(VIRTUAL_ENV)
. $(VIRTUAL_ENV)/bin/activate; \
rm -rf dist; \
python setup.py sdist; \
twine upload dist/*;