-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
181 lines (128 loc) · 5.54 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# this Makefile snippet is stored as Makefile
.PHONY: clean clean-compiled clean-entangled test all entangle entangle-list py-deps test-cgi test-cli test-py start-redis stop-redis run-webservice test-webservice run-celery-worker run-celery-webapp run-webapp build-wasm host-webassembly-files host-react-files test-webassembly test-react init-git-hook check test-wasm-cli npm-fopenapi-deps npm-fastify npm-openapi run-js-webservice test-js-webservice test-js-webservice-invalid test-js-openapi run-js-openapi test-js-openapi npm-threaded run-js-threaded test-js-threaded
HOST_UID := $(shell id -u)
HOST_GID := $(shell id -g)
# Prevent suicide by excluding Makefile
ENTANGLED := $(shell perl -ne 'print $$1,"\n" if /^```\{.*file=(.*)\}/' *.md | grep -v Makefile | sort -u)
COMPILED := cli/newtonraphson.exe openapi/newtonraphsonpy.*.so flask/newtonraphsonpy.*.so cgi/apache2/cgi-bin/newtonraphson webassembly/newtonraphsonwasm.js webassembly/newtonraphsonwasm.wasm react/newtonraphsonwasm.js react/newtonraphsonwasm.wasm
entangle: *.md
docker run --rm --user ${HOST_UID}:${HOST_GID} -v ${PWD}:/data nlesc/pandoc-tangle:0.5.0 --preserve-tabs *.md
$(ENTANGLED): entangle
entangled-list:
@echo $(ENTANGLED)
flask-deps: pip-pybind11 pip-celery pip-flask
openapi-deps: pip-pybind11 pip-connexion
py-deps: flask-deps openapi-deps
pip-pybind11:
pip install pybind11
pip-flask:
pip install flask
pip-celery:
pip install celery[redis]
pip-connexion:
pip install connexion[swagger-ui]
cli/newtonraphson.exe:
g++ cli/cli-newtonraphson.cpp -o cli/newtonraphson.exe
test-cli: cli/newtonraphson.exe
./cli/newtonraphson.exe
cgi/apache2/cgi-bin/newtonraphson:
g++ -Icgi/deps/ -Icli/ cgi/cgi-newtonraphson.cpp -o cgi/apache2/cgi-bin/newtonraphson
test-cgi: cgi/apache2/cgi-bin/newtonraphson
echo '{"guess":-20, "epsilon":0.001}' | cgi/apache2/cgi-bin/newtonraphson
openapi/newtonraphsonpy.*.so:
g++ -O3 -Wall -shared -std=c++14 -fPIC -Icli/ `python3 -m pybind11 --includes` \
openapi/py-newtonraphson.cpp -o openapi/newtonraphsonpy`python3-config --extension-suffix`
flask/newtonraphsonpy.*.so: openapi/newtonraphsonpy.*.so
cd flask && ln -s ../openapi/newtonraphsonpy`python3-config --extension-suffix` . && cd -
test-py: openapi/newtonraphsonpy.*.so
python openapi/example.py
test: test-cli test-cgi test-py test-webservice
all: $(ENTANGLED) $(COMPILED)
clean: clean-compiled clean-entangled
# Removes the compiled files
clean-compiled:
$(RM) $(COMPILED)
# Removed the entangled files
clean-entangled:
$(RM) $(ENTANGLED)
start-redis:
docker run --rm -d -p 6379:6379 --name some-redis redis
stop-redis:
docker stop some-redis
run-webapp: flask/newtonraphsonpy.*.so
python flask/webapp.py
run-webservice: openapi/newtonraphsonpy.*.so
python openapi/webservice.py
test-webservice:
curl --request POST \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '{"epsilon":0.001,"guess":-20}' \
http://localhost:8080/api/newtonraphson
run-celery-worker: flask/newtonraphsonpy.*.so
PYTHONPATH=flask celery worker -A tasks
run-celery-webapp:
python flask/webapp-celery.py
build-wasm: webassembly/newtonraphsonwasm.js webassembly/newtonraphsonwasm.wasm
webassembly/newtonraphsonwasm.js webassembly/newtonraphsonwasm.wasm:
emcc -Icli/ -o webassembly/newtonraphsonwasm.js \
-s MODULARIZE=1 -s EXPORT_NAME=createModule \
--bind webassembly/wasm-newtonraphson.cpp
react/newtonraphsonwasm.wasm: webassembly/newtonraphsonwasm.wasm
cd react && ln -s ../webassembly/newtonraphsonwasm.wasm . && cd -
react/newtonraphsonwasm.js: webassembly/newtonraphsonwasm.js
cd react && ln -s ../webassembly/newtonraphsonwasm.js . && cd -
test-wasm-cli: build-wasm
node webassembly/cli.js 0.01 -20
host-webassembly-files: build-wasm
python3 -m http.server 8000
host-react-files: react/newtonraphsonwasm.js react/newtonraphsonwasm.wasm
python3 -m http.server 8000
test-webassembly:
npx cypress run --config-file false --spec 'cypress/integration/webassembly/*_spec.js'
js-deps: npm-fastify npm-openapi npm-threaded
npm-fastify:
npm install --no-save fastify
npm-openapi:
npm install --no-save fastify-oas
npm-threaded:
npm install --no-save node-worker-threads-pool
run-js-webservice: build-wasm
node webassembly/webservice.js
test-js-webservice:
curl --request POST \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '{"epsilon":0.001,"guess":-20}' \
http://localhost:3000/api/newtonraphson
test-js-webservice-invalid:
wget --content-on-error --quiet --output-document=- \
--header="accept: application/json" \
--header="Content-Type: application/json" \
--post-data '{"epilon":0.001,"guess":-20}' \
http://localhost:3000/api/newtonraphson
run-js-openapi: build-wasm
node webassembly/openapi.js
test-js-openapi:
curl --request POST \
--header "Content-Type: application/json" \
--header "accept: application/json" \
--data '{"guess":-20, "epsilon":0.001}' \
http://localhost:3001/api/newtonraphson
run-js-threaded: build-wasm
node webassembly/webservice-threaded.js
test-js-threaded:
curl --request POST \
--header "Content-Type: application/json" \
--header "accept: application/json" \
--data '{"guess":-20, "epsilon":0.001}' \
http://localhost:3002/api/newtonraphson
react/worker.js:
cd react && ln -s ../webassembly/worker.js . && cd -
test-react: react/worker.js
npx cypress run --config-file false --spec 'cypress/integration/react/*_spec.js'
init-git-hook:
chmod +x .githooks/pre-commit
git config --local core.hooksPath .githooks
check: entangle
git diff-index --quiet HEAD --