forked from swift-nav/libsbp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
435 lines (347 loc) · 18.9 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# Convenience Makefile for generating and releasing SBP client
# libraries. Please read and understand the contents of this file
# before using it to do Crazy Things.
SHELL := /bin/bash
SWIFTNAV_ROOT := $(CURDIR)
MAKEFLAGS += SWIFTNAV_ROOT=$(SWIFTNAV_ROOT)
SBP_SPEC_DIR := $(SWIFTNAV_ROOT)/spec/yaml/swiftnav/sbp/
SBP_TESTS_SPEC_DIR := $(SWIFTNAV_ROOT)/spec/tests/yaml/
GENENV ?= py # the system's default python version
SBP_GEN_BIN := tox -e $(GENENV) --
SBP_VERSION := $(shell git describe --always --tags)
SBP_VERSION_UNPREFIXED := $(shell echo $(SBP_VERSION) | sed 's/^v//')
CHANGELOG_MAX_ISSUES := 100
.PHONY: help test release dist clean all docs pdf html c deps-c gen-c test-c python deps-python gen-python test-python javascript deps-javascript gen-javascript test-javascript java deps-java gen-java test-java haskell deps-haskell gen-haskell test-haskell haskell deps-protobuf gen-protobuf test-protobuf verify-prereq-generator verify-prereq-c verify-prereq-javascript verify-prereq-python verify-prereq-java verify-prereq-haskell verify-prereq-protobuf mapping rust deps-rust gen-rust test-rust deps-jsonschema gen-jsonschema test-jsonschema verify-prereq-jsonschema deps-quicktype-typescript gen-quicktype-typescript test-quicktype-typescript verify-prereq-quicktype-typescript deps-quicktype-javascript gen-quicktype-javascript test-quicktype-javascript verify-prereq-quicktype-javascript deps-quicktype-elm gen-quicktype-elm test-quicktype-elm verify-prereq-quicktype-elm
# Functions
define announce-begin
@echo
@echo "$1 ..."
@echo
endef
define announce-end
@echo
@echo "$1"
@echo
endef
# Help!
help:
@echo
@echo "Helper for generating and releasing SBP client libraries."
@echo
@echo "(Please read before using!)"
@echo
@echo "Please use \`make <target>' where <target> is one of"
@echo " help to display this help message"
@echo " all to make SBP clients across all languages"
@echo " clean to remove any output files"
@echo " c to make C headers"
@echo " dist to distribute packages"
@echo " docs to make HTML and pdf documentation"
@echo " html to make all HTML language docs"
@echo " pdf to make SBP LaTeX datasheet"
@echo " python to make Python bindings"
@echo " haskell to make Haskell bindings"
@echo " java to make Java bindings"
@echo " rust to make Rust bindings"
@echo " protobuf to make Protocol Buffer bindings"
@echo " jsonschema to make JSON Schema definitions"
@echo " release to handle some release tasks"
@echo " test to run all tests"
@echo
@echo "JSON Schema specific targets:"
@echo " quicktype-typescript generate TypeScript module from JSON Schema"
@echo " quicktype-javascript generate JavaScript module from JSON Schema"
@echo " quicktype-elm generate Elm module from JSON Schema"
@echo
all: c python javascript java docs haskell protobuf rust jsonschema quicktype
clean:
@echo "Removing the ./c/build directory..."
rm -r $(SWIFTNAV_ROOT)/c/build
docs: verify-prereq-docs pdf html
c: deps-c gen-c test-c
python: deps-python gen-python test-python
javascript: deps-javascript gen-javascript test-javascript
java: deps-java gen-java test-java
haskell: deps-haskell gen-haskell test-haskell
rust: deps-rust gen-rust test-rust
protobuf: deps-protobuf gen-protobuf test-protobuf
jsonschema: deps-jsonschema gen-jsonschema test-jsonschema
quicktype-typescript: deps-quicktype-typescript gen-quicktype-typescript test-quicktype-typescript
quicktype-javascript: deps-quicktype-javascript gen-quicktype-javascript test-quicktype-javascript
quicktype-elm: deps-quicktype-elm gen-quicktype-elm test-quicktype-elm
quicktype: quicktype-typescript quicktype-javascript quicktype-elm
# Prerequisite verification
verify-prereq-generator:
ifeq ($(OS), Windows_NT)
@python --version 1> nul 2> nul || (echo I require `python` but it's not installed. Aborting. & echo. & echo. & echo Have you installed Python? & echo. & exit 1)
@pip --version 1> nul 2> nul || (echo I require `pip` but it's not installed. Aborting. & echo. & echo. & echo Have you installed pip? & echo. & exit 1)
else
@command -v python 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`python\` but it's not installed. Aborting.\n\nHave you installed Python?\n"; exit 1; }
@command -v pip 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pip\` but it's not installed. Aborting.\n\nHave you installed pip?\n"; exit 1; }
endif
verify-prereq-c: verify-prereq-generator
@command -v checkmk 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`checkmk\` but it's not installed. Aborting.\n\nHave you installed checkmk? See the C readme at \`c/README.md\` for setup instructions.\n"; exit 1; }
@command -v cmake 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`cmake\` but it's not installed. Aborting.\n\nHave you installed cmake? See the C readme at \`c/README.md\` for setup instructions.\n"; exit 1; }
@command -v pkg-config 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pkg-config\` but it's not installed. Aborting.\n\nHave you installed pkg-config? See the C readme at \`c/README.md\` for setup instructions.\n"; exit 1; }
@command -v doxygen 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`doxygen\` but it's not installed. Aborting.\n\nHave you installed doxygen? See the C readme at \`c/README.md\` for setup instructions.\n"; exit 1; }
verify-prereq-python: verify-prereq-generator
@command -v python 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`python\` but it's not installed. Aborting.\n\nHave you installed Python? See the Python readme at \`python/README.rst\` for setup instructions.\n"; exit 1; }
@command -v pip 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pip\` but it's not installed. Aborting.\n\nHave you installed pip? See the Python readme at \`python/README.rst\` for setup instructions.\n"; exit 1; }
@command -v tox 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`tox\` but it's not installed. Aborting.\n\nHave you installed tox? See the Python readme at \`python/README.rst\` for setup instructions.\n"; exit 1; }
@command -v pandoc 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pandoc\` but it's not installed. Aborting.\n\nHave you installed pandoc? See the Python readme at \`python/README.rst\` for setup instructions.\n"; exit 1; }
verify-prereq-javascript: verify-prereq-generator
@command -v node 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`node\` but it's not installed. Aborting.\n\nHave you installed Node.js? See the JavaScript readme at \`javascript/README.md\` for setup instructions.\n"; exit 1; }
@command -v npm 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`npm\` but it's not installed. Aborting.\n\nHave you installed NPM? See the JavaScript readme at \`javascript/README.md\` for setup instructions.\n"; exit 1; }
@command -v mocha 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`mocha\` but it's not installed. Aborting.\n\nHave you installed mocha? See the JavaScript readme at \`javascript/README.md\` for setup instructions.\n"; exit 1; }
verify-prereq-java: verify-prereq-generator
ifeq ($(OS), Windows_NT)
@gradle --version 1> nul 2> nul || (echo I require `gradle` but it's not installed. Aborting. & echo. & echo. & echo Have you installed gradle? See the Java readme at `java/README.rst` for setup instructions. & echo. & exit 1)
else
@command -v gradle 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`gradle\` but it's not installed. Aborting.\n\nHave you installed gradle? See the Java readme at \`java/README.rst\` for setup instructions.\n"; exit 1; }
endif
verify-prereq-haskell: verify-prereq-generator
verify-prereq-rust:
@command -v cargo 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`cargo\` but it's not installed. Aborting.\n\nHave you installed Rust? See the Rust readme at \`rust/README.md\` for setup instructions.\n"; exit 1; }
@command -v rustfmt 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`rustfmt\` but it's not installed. Aborting.\n\nHave you installed Rust? See the Rust readme at \`rust/README.md\` for setup instructions.\n"; exit 1; }
verify-prereq-protobuf: ;
verify-prereq-jsonschema: ;
verify-prereq-quicktype:
@command -v quicktype 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`quicktype\` but it's not installed. Aborting.\n\nHave you installed quicktype? See the generator README (Installing instructions) at \`generator/README.md\` for setup instructions.\n"; exit 1; }
verify-prereq-docs: verify-prereq-generator
@command -v pdflatex 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pdflatex\` but it's not installed. Aborting.\n\nHave you installed pdflatex? See the generator readme (Installing instructions) at \`generator/README.md\` for setup instructions.\n"; exit 1; }
@command -v sphinx-build 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`sphinx-build\` but it's not installed. Aborting.\n\nHave you installed sphinx-build? See the generator readme (Installing instructions) at \`generator/README.md\` for setup instructions.\n"; exit 1; }
# Dependencies
deps-c: verify-prereq-c
deps-python: verify-prereq-python
deps-javascript: verify-prereq-javascript
$(call announce-begin,"Installing Javascript dependencies")
cd $(SWIFTNAV_ROOT); npm install
cd $(SWIFTNAV_ROOT); npm run webpack
$(call announce-end,"Finished installing Javascript dependencies")
deps-java: verify-prereq-java
deps-haskell: verify-prereq-haskell
deps-rust: verify-prereq-rust
deps-protobuf: verify-prereq-protobuf
deps-jsonschema: verify-prereq-jsonschema
deps-quicktype-typescript: verify-prereq-quicktype
deps-quicktype-javascript: verify-prereq-quicktype
deps-quicktype-elm: verify-prereq-quicktype
# Generators
gen: gen-c gen-python gen-javascript gen-java gen-haskell gen-rust gen-protobuf gen-jsonschema gen-quicktype
gen-quicktype: gen-quicktype-typescript gen-quicktype-elm
gen-c:
$(call announce-begin,"Generating C headers")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/c/include/libsbp \
-r $(SBP_VERSION) \
--c
$(call announce-begin,"Generating C tests")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_TESTS_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/c/test \
-r $(SBP_VERSION) \
--test-c
$(call announce-end,"Finished generating C. Please check $(SWIFTNAV_ROOT)/c/include/libsbp.")
gen-python:
$(call announce-begin,"Generating Python bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/python/sbp/ \
-r $(SBP_VERSION) \
--python
$(call announce-end,"Finished generating Python bindings. Please check $(SWIFTNAV_ROOT)/python/sbp")
gen-javascript:
$(call announce-begin,"Generating JavaScript bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/javascript/sbp/ \
-r $(SBP_VERSION_UNPREFIXED) \
--javascript
cd $(SWIFTNAV_ROOT)
$(call announce-begin,"Bumping NPM version")
@- npm version "$(shell cat javascript/sbp/RELEASE-VERSION)" --no-git-tag-version >/dev/null 2>&1
@- npm run webpack >/dev/null 2>&1
$(call announce-end,"Finished generating JavaScript bindings. Please check $(SWIFTNAV_ROOT)/javascript/sbp")
gen-java:
$(call announce-begin,"Generating Java bindings")
cd $(SWIFTNAV_ROOT)/generator && \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/java/src/ \
-r $(SBP_VERSION) \
--java
$(call announce-end,"Finished generating Java bindings. Please check $(SWIFTNAV_ROOT)/java/src/sbp")
$(call announce-begin,"Generating Java tests")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_TESTS_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/java/test/ \
-r $(SBP_VERSION_UNPREFIXED) \
--test-java
$(call announce-end,"Finished generating Java tests")
gen-haskell:
$(call announce-begin,"Generating Haskell bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/haskell/ \
-r $(SBP_VERSION_UNPREFIXED) \
--haskell
$(call announce-begin,"Finished generating Haskell bindings")
gen-rust:
$(call announce-begin,"Generating Rust bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/rust/ \
-r $(SBP_VERSION_UNPREFIXED) \
--rust
$(call announce-end,"Finished generating Rust bindings")
$(call announce-begin,"Generating Rust tests")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_TESTS_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/rust/sbp/tests/ \
-r $(SBP_VERSION_UNPREFIXED) \
--test-rust
$(call announce-end,"Finished generating Rust tests")
$(call announce-begin,"Formatting Rust code")
cd $(SWIFTNAV_ROOT)/rust/sbp && cargo fmt
$(call announce-end,"Finished formatting Rust code")
$(call announce-end,"Finished generating Rust bindings")
gen-protobuf:
$(call announce-begin,"Generating Protocol Buffers bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/proto/ \
-r $(SBP_VERSION) \
--protobuf
$(call announce-begin,"Finished generating Protocol Buffers bindings")
gen-jsonschema:
$(call announce-begin,"Generating JSON Schema definitions")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/jsonschema/ \
-r $(SBP_VERSION) \
--jsonschema
$(call announce-begin,"Finished generating JSON Schema definitions")
gen-quicktype-typescript:
$(call announce-begin,"Generating TypeScript module from JSON Schema")
(cd jsonschema; quicktype -l typescript --src-lang schema *.json >../sbpjson/typescript/SbpJson.ts)
$(call announce-begin,"Finished generating TypeScript module from JSON Schema definitions")
gen-quicktype-javascript:
$(call announce-begin,"Generating JavaScript module from JSON Schema")
(cd jsonschema; quicktype -l javascript --src-lang schema *.json >../sbpjson/javascript/SbpJson.js)
$(call announce-begin,"Finished generating JavaScript module from JSON Schema definitions")
gen-quicktype-elm:
$(call announce-begin,"Generating Elm module from JSON Schema")
(cd jsonschema; quicktype -l elm --module SbpJson --src-lang schema *.json >../sbpjson/elm/SbpJson.elm)
$(call announce-begin,"Finished generating Elm module from JSON Schema definitions")
# Testers
test: test-all-begin test-c test-java test-python test-haskell test-javascript test-rust test-all-end
test-all-begin:
$(call announce-begin,"Running all tests")
test-all-end:
$(call announce-end,"Finished running all tests")
test-c:
$(call announce-begin,"Running C tests")
cd $(SWIFTNAV_ROOT)/c; \
mkdir -p build/ && cd build/; \
cmake $(CMAKEFLAGS) ../; \
$(MAKE); \
$(MAKE) do-all-tests
$(call announce-end,"Finished running C tests")
test-python:
$(call announce-begin,"Running Python tests")
cd $(SWIFTNAV_ROOT)/python/ && tox --skip-missing-interpreters
$(call announce-end,"Finished running Python tests")
test-javascript:
$(call announce-begin,"Running JavaScript tests")
npm install
npm test
$(call announce-end,"Finished running JavaScript tests")
test-java:
$(call announce-begin,"Running Java tests")
cd $(SWIFTNAV_ROOT)/java && gradle test -i
$(call announce-end,"Finished running Java tests")
test-haskell:
$(call announce-begin,"Running Haskell tests")
cd $(SWIFTNAV_ROOT)/haskell/ && stack build --test --allow-different-user
$(call announce-end,"Finished running Haskell tests")
test-rust:
$(call announce-begin,"Running Rust tests")
cargo test --verbose --all-features --all-targets
$(call announce-begin,"Building Rust examples")
cargo build --examples --verbose --all-features --all-targets
$(call announce-end,"Finished running Rust tests")
test-protobuf:
$(call announce-begin,"Running Protocol Buffer tests")
$(call announce-end,"Finished running Protocol Buffer tests")
test-jsonschema:
$(call announce-begin,"Running JSON Schema tests")
$(call announce-end,"Finished running JSON Schema tests")
test-quicktype-typescript:
$(call announce-begin,"Running TypeScript JSON Schema tests [not yet implemented]")
$(call announce-end,"Finished running TypeScript JSON Schema tests")
test-quicktype-javascript:
$(call announce-begin,"Running JavaScript JSON Schema tests [not yet implemented]")
$(call announce-end,"Finished running JavaScript JSON Schema tests")
test-quicktype-elm:
$(call announce-begin,"Running Elm JSON Schema tests [not yet implemented]")
$(call announce-end,"Finished running Elm JSON Schema tests")
dist-python:
$(call announce-begin,"Deploying Python package")
$(MAKE) -C $(SWIFTNAV_ROOT)/python SBP_VERSION="$(SBP_VERSION)" deploy
$(call announce-end,"Finished deploying Python package")
dist-javascript:
$(call announce-begin,"Deploying Javascript package")
npm publish
$(call announce-begin,"Finished deploying Javascript package")
dist-haskell:
$(call announce-begin,"Deploying Haskell package")
(cd $(SWIFTNAV_ROOT)/haskell; stack sdist; stack upload .)
$(call announce-begin,"Finished deploying Haskell package")
dist-pdf:
$(call announce-begin,"Deploying PDF documentation")
$(MAKE) pdf_dist
$(call announce-begin,"Finished deploying PDF documentation")
dist: dist-python dist-javascript dist-haskell dist-pdf
pdf:
$(call announce-begin,"Generating PDF datasheet documentation")
$(MAKE) pdf-for-real
# This is a big hack, but we do this twice to ensure that all tables
# within the PDF get generated correctly.
$(MAKE) pdf-for-real
$(call announce-end,"Finished! Please check $(SWIFTNAV_ROOT)/latex and $(SWIFTNAV_ROOT)/docs")
pdf-for-real:
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/latex/ \
-r $(SBP_VERSION) \
--latex
pdf_dist:
s3cmd put $(SWIFTNAV_ROOT)/docs/sbp.pdf s3://downloads.swiftnav.com/sbp/docs/sbp_$(SBP_VERSION).pdf
html:
$(call announce-begin,"Generating bindings documentation")
$(call announce-begin,"Generating C bindings documentation")
cd $(SWIFTNAV_ROOT)/c && \
mkdir -p build && \
cd build && \
cmake .. && \
$(MAKE) docs
$(call announce-begin,"Generating Python documentation")
$(MAKE) -C $(SWIFTNAV_ROOT)/python/docs html
$(call announce-end,"Finished generating documentation")
release:
$(call announce-begin,"Run release boilerplate")
docker run -it --rm -v $(PWD):/usr/local/src/your-app ferrarimarco/github-changelog-generator \
--max-issues $(CHANGELOG_MAX_ISSUES) \
-t $(CHANGELOG_GITHUB_TOKEN) \
--user swift-nav --project libsbp \
-o DRAFT_CHANGELOG.md \
swift-nav/libsbp
$(call announce-end,"Added CHANGELOG details to DRAFT_CHANGELOG.md!")
mapping:
@egrep -h '^( - MSG| id:)' spec/yaml/swiftnav/sbp/*.yaml |\
sed 'N;s/\n//' |\
awk '{printf("%s %5d %s\n", $$4, $$4, $$2)}' |\
sed 's/:$$//' |\
sort
benchmark:
@PYTHONPATH=$(PWD)/test_data ./test_data/benchmark_main.py