1PKG_NAME=$(shell grep name Cargo.toml | head -n 1 | awk -F \" '{print $$2}')
2DOCS_DEFAULT_MODULE=$(subst -,_,$(PKG_NAME))
3ifeq (, $(shell which cargo-check 2> /dev/null))
4DEFAULT_TARGET=build
5else
6DEFAULT_TARGET=build
7endif
8
9default: $(DEFAULT_TARGET)
10
11ALL_TARGETS += build $(EXAMPLES) test doc crates
12ifneq ($(RELEASE),)
13$(info RELEASE BUILD: $(PKG_NAME))
14CARGO_FLAGS += --release
15else
16$(info DEBUG BUILD: $(PKG_NAME); use `RELEASE=true make [args]` for release build)
17endif
18
19EXAMPLES = $(shell cd examples 2>/dev/null && ls *.rs 2>/dev/null | sed -e 's/.rs$$//g' )
20CRATES = $(shell cd crates 2>/dev/null && ls 2>/dev/null)
21
22all: $(ALL_TARGETS)
23
24.PHONY: run test build doc clean clippy
25run test build clean:
26	cargo $@ $(CARGO_FLAGS)
27
28test-all:
29	cargo test $(CARGO_FLAGS)
30
31check:
32	$(info Running check; use `make build` to actually build)
33	cargo $@ $(CARGO_FLAGS)
34
35clippy:
36	cargo build --features clippy
37
38.PHONY: bench
39bench:
40	cargo $@ $(filter-out --release,$(CARGO_FLAGS))
41
42.PHONY: travistest
43travistest: test-all
44
45.PHONY: longtest
46longtest:
47	@echo "Running longtest. Press Ctrl+C to stop at any time"
48	@sleep 2
49	@i=0; while i=$$((i + 1)) && echo "Iteration $$i" && make test ; do :; done
50
51.PHONY: $(EXAMPLES)
52$(EXAMPLES):
53	cargo build --example $@ $(CARGO_FLAGS)
54
55.PHONY: crates
56crates: $(CRATES)
57
58.PHONY: $(CRATES)
59$(CRATES):
60	cd "crates/$@"; cargo build $(CARGO_FLAGS)
61	cd "crates/$@"; cargo test $(CARGO_FLAGS)
62
63.PHONY: doc
64doc: FORCE
65	cargo doc
66
67.PHONY: publishdoc
68publishdoc:
69	rm -rf target/doc
70	make doc
71	echo '<meta http-equiv="refresh" content="0;url='${DOCS_DEFAULT_MODULE}'/index.html">' > target/doc/index.html
72	ghp-import -n target/doc
73	git push -f origin gh-pages
74
75.PHONY: docview
76docview: doc
77	xdg-open target/doc/$(PKG_NAME)/index.html
78
79.PHONY: FORCE
80FORCE:
81