-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
66 lines (51 loc) · 1.69 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
MD := $(shell command -v $(or $(MDBOOK),mdbook) 2>/dev/null)
OUT := $(abspath $(or $(DEST),book))
GUIDES := $(wildcard guides/*)
DESIGNS := $(wildcard design/*)
BOOKS := $(GUIDES) $(DESIGN)
.PHONY: all
all: book
.PHONY: dependencies
dependencies:
ifndef MD
$(info hint: try `cargo install mdbook --vers "^0.2.0"`)
$(error mdbook is required for building the docs)
endif
.PHONY: stubs
stubs:
@$(foreach book,$(GUIDES)$(DESIGN),mkdir -p home/src/$(book) && touch home/src/$(book)/index.html;)
$(BOOKS): dependencies
@$(MD) test $@ --dest-dir $(OUT)/$@
@$(MD) build $@ --dest-dir $(OUT)/$@
@echo ".content img { max-width: 100%; display:block; margin: 0 auto; }" >> $(OUT)/$@/css/general.css
.PHONY: sub-books
sub-books: $(BOOKS)
.PHONY: home
home: dependencies stubs
@$(MD) build home --dest-dir $(OUT)
.PHONY: book
book: home | sub-books
.PHONY: start
start: dependencies stubs
-@$(MD) serve home --dest-dir $(OUT) &
-@$(foreach book,$(GUIDES),$(MD) watch $(book) --dest-dir $(OUT)/guides/$(notdir $(book)) &)
-@$(foreach book,$(DESIGNS),$(MD) watch $(book) --dest-dir $(OUT)/design/$(notdir $(book)) &)
$(MAKE) sub-books
.PHONY: stop
stop: dependencies
@pkill $(notdir $(MD))
.PHONY: serve-naive
serve-naive: start
@read -p "Press enter to kill.." _
-@$(MAKE) stop
.PHONY: serve
serve:
-@bash -c "trap 'trap - SIGINT SIGQUIT ERR; echo \"Stopping server...\" && $(MAKE) stop >/dev/null 2>&1' SIGINT SIGQUIT ERR; $(MAKE) serve-naive"
.PHONY: serve-single
serve-single: dependencies
-@bash -c "select book in $(GUIDES) $(DESIGNS); do $(MD) serve \$$book ; break; done"
.PHONY: clean
clean: dependencies
-@$(MD) clean home --dest-dir $(OUT) 2>/dev/null
@rm -rf home/src/guides
@rm -rf home/src/design